public class Euler94 {
    public static void main(String[] args) {
        long limit = 1000000000L, total = 0, x = 2, y = 1;
        while (true) {
            boolean any = false;
            for (int sign : new int[] { 1, -1 }) {
                long num = 2 * x + sign;
                if (num % 3 != 0)
                    continue;
                long a = num / 3;
                if (a <= 1)
                    continue;
                long peri = 3 * a + sign;
                if (peri <= limit) {
                    total += peri;
                    any = true;
                }
            }
            long nx = 2 * x + 3 * y, ny = x + 2 * y;
            x = nx;
            y = ny;
            if (!any && (2 * x - 1) / 3 > limit)
                break;
        }
        System.out.println(total);
    }
}
