contract SafeMath {
    function safeMul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        assert(c / a == b);
        return c;
    }

    function safeDiv(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a / b;
        return c;
    }

    function safeSub(uint256 a, uint256 b) internal pure returns (uint256) {
        assert(b <= a);
        return a - b;
    }

    function safeAdd(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        assert(c >= a);
        return c;
    }

    function safeExponent(uint256 a, uint256 b)
        internal
        pure
        returns (uint256)
    {
        uint256 result;
        assembly {
            result := exp(a, b)
        }
        return result;
    }

    // calculates a^(1/n) to dp decimal places
    // maxIts bounds the number of iterations performed
    function nthRoot(
        uint256 _a,
        uint256 _n,
        uint256 _dp,
        uint256 _maxIts
    ) internal pure returns (uint256) {
        assert(_n > 1);

        // The scale factor is a crude way to turn everything into integer calcs.
        // Actually do (a * (10 ^ ((dp + 1) * n))) ^ (1/n)
        // We calculate to one extra dp and round at the end
        uint256 one = 10**(1 + _dp);
        uint256 a0 = one**_n * _a;

        // Initial guess: 1.0
        uint256 xNew = one;
        uint256 x;

        uint256 iter = 0;
        while (xNew != x && iter < _maxIts) {
            x = xNew;
            uint256 t0 = x**(_n - 1);
            if (x * t0 > a0) {
                xNew = x - (x - a0 / t0) / _n;
            } else {
                xNew = x + (a0 / t0 - x) / _n;
            }
            ++iter;
        }

        // Round to nearest in the last dp.
        return (xNew + 5) / 10;
    }
}
function nthRoot(
    uint256 _a,
    uint256 _n,
    uint256 _dp,
    uint256 _maxIts
) internal pure returns (uint256) {
    assert(_n > 1);

    // The scale factor is a crude way to turn everything into integer calcs.
    // Actually do (a * (10 ^ ((dp + 1) * n))) ^ (1/n)
    // We calculate to one extra dp and round at the end
    uint256 one = 10**(1 + _dp);
    uint256 a0 = one**_n * _a;

    // Initial guess: 1.0
    uint256 xNew = one;
    uint256 x;

    uint256 iter = 0;
    while (xNew != x && iter < _maxIts) {
        x = xNew;
        uint256 t0 = x**(_n - 1);
        if (x * t0 > a0) {
            xNew = x - (x - a0 / t0) / _n;
        } else {
            xNew = x + (a0 / t0 - x) / _n;
        }
        ++iter;
    }

    // Round to nearest in the last dp.
    return (xNew + 5) / 10;
}

// calculates a^(1/n) to dp decimal places
// maxIts bounds the number of iterations performed