import java.math.BigInteger;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Euler599 {

    static List<List<Integer>> getParts(int n, int maxVal) {
        List<List<Integer>> res = new ArrayList<>();
        if (n == 0) {
            res.add(new ArrayList<>());
            return res;
        }
        for (int i = Math.min(n, maxVal); i >= 1; i--) {
            for (List<Integer> p : getParts(n - i, i)) {
                List<Integer> lst = new ArrayList<>();
                lst.add(i);
                lst.addAll(p);
                res.add(lst);
            }
        }
        return res;
    }

    static long factorial(int n) {
        long r = 1;
        for (int i = 2; i <= n; i++)
            r *= i;
        return r;
    }

    static long countPerms(List<Integer> p) {
        long cnt = factorial(8);
        Map<Integer, Integer> counts = new HashMap<>();
        for (int x : p)
            counts.put(x, counts.getOrDefault(x, 0) + 1);
        for (Map.Entry<Integer, Integer> e : counts.entrySet()) {
            cnt /= (long) Math.pow(e.getKey(), e.getValue()) * factorial(e.getValue());
        }
        return cnt;
    }

    static BigInteger solveM(int m) {
        List<List<Integer>> parts = getParts(8, 8);
        BigInteger total = BigInteger.ZERO;
        BigInteger bigM = BigInteger.valueOf(m);

        for (List<Integer> p : parts) {
            long perms = countPerms(p);
            int k = p.size();
            long wInner = (long) Math.pow(3, 8 - k);

            int maxMask = (int) Math.pow(3, k);
            for (int mask = 0; mask < maxMask; mask++) {
                int t = mask;
                int sum = 0;
                int cG = 0;
                for (int i = 0; i < k; i++) {
                    int S = t % 3;
                    t /= 3;
                    sum += S;
                    if (S == 0)
                        cG += 3;
                    else
                        cG += 1;
                }
                if (sum % 3 != 0)
                    continue;

                BigInteger term = BigInteger.valueOf(perms).multiply(BigInteger.valueOf(wInner)).multiply(bigM.pow(cG));
                total = total.add(term);
            }
        }
        return total.divide(BigInteger.valueOf(88179840));
    }

    public static String solve() {
        return solveM(10).toString();
    }

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