import java.util.*;

public class Euler140 {
    public static void main(String[] args) {
        int count = 30;
        long[][] seeds = { { 7, 1 }, { 8, 2 }, { 13, 5 }, { 17, 7 }, { 32, 14 }, { 43, 19 } };
        Set<Long> nuggets = new TreeSet<>();
        for (long[] s : seeds) {
            long x = s[0], y = s[1];
            for (int i = 0; i < 50; i++) {
                if (x > 7 && (x - 7) % 5 == 0)
                    nuggets.add((x - 7) / 5);
                long nx = 9 * x + 20 * y, ny = 4 * x + 9 * y;
                x = nx;
                y = ny;
            }
        }
        long sum = 0;
        int c = 0;
        for (long v : nuggets) {
            if (c >= count)
                break;
            sum += v;
            c++;
        }
        System.out.println(sum);
    }
}
