public class Euler435 {
    private static final long MOD = 1307674368000L;
    private static final long N_VAL = 1000000000000000L;
    private static final int X_MAX = 100;

    private static long[][] matMul(long[][] a, long[][] b) {
        long[][] c = new long[3][3];
        for (int i = 0; i < 3; i++) {
            for (int k = 0; k < 3; k++) {
                if (a[i][k] == 0)
                    continue;
                // Since multiplication can exceed long capacity before modulo,
                // we'll carefully handle it using big decimal or a safe multiplier,
                // but MOD is ~10^12, so a[i][k] * b[k][j] can be ~10^24 which overflows long
                // (max ~9*10^18).
                // Use a safe multiply mod function or split math.
                for (int j = 0; j < 3; j++) {
                    if (b[k][j] == 0)
                        continue;
                    long add = mulMod(a[i][k], b[k][j]);
                    c[i][j] = (c[i][j] + add) % MOD;
                }
            }
        }
        return c;
    }

    private static long mulMod(long a, long b) {
        long q = (long) ((double) a * b / MOD);
        long r = a * b - q * MOD;
        while (r >= MOD)
            r -= MOD;
        while (r < 0)
            r += MOD;
        return r;
    }

    private static long[] matVecMul(long[][] a, long[] v) {
        long[] out = new long[3];
        for (int i = 0; i < 3; i++) {
            long sum = 0;
            for (int j = 0; j < 3; j++) {
                if (a[i][j] == 0 || v[j] == 0)
                    continue;
                sum = (sum + mulMod(a[i][j], v[j])) % MOD;
            }
            out[i] = sum;
        }
        return out;
    }

    private static long[][] matPow(long[][] base, long exp) {
        long[][] result = new long[3][3];
        for (int i = 0; i < 3; i++) {
            result[i][i] = 1;
        }
        long e = exp;
        while (e > 0) {
            if ((e & 1) != 0) {
                result = matMul(base, result);
            }
            e >>= 1;
            if (e > 0) {
                base = matMul(base, base);
            }
        }
        return result;
    }

    private static long fValue(long xRaw) {
        if (N_VAL == 0)
            return 0;
        long x = xRaw % MOD;
        long x2 = mulMod(x, x);
        long[][] t = {
                { x, x2, 0 },
                { 1, 0, 0 },
                { x, x2, 1 }
        };
        long[] v1 = { x, 0, x };
        long[][] p = matPow(t, N_VAL - 1);
        long[] vn = matVecMul(p, v1);
        return vn[2];
    }

    public static String solve() {
        long ans = 0;
        for (int x = 0; x <= X_MAX; x++) {
            ans = (ans + fValue(x)) % MOD;
        }
        return String.valueOf(ans);
    }

    public static void main(String[] args) {
        System.out.println(solve());
    }
}
