import java.math.BigInteger;

public class Euler588 {
    static int[][][] nx = new int[2][2][32];

    static {
        for (int t = 0; t <= 1; ++t) {
            for (int outb = 0; outb <= 1; ++outb) {
                for (int mask = 0; mask < 32; ++mask) {
                    int nmask = 0;
                    for (int c = 0; c <= 4; ++c) {
                        if (((mask >> c) & 1) == 0)
                            continue;
                        int dmax = (t == 1) ? 4 : 0;
                        for (int d = 0; d <= dmax; ++d) {
                            int s = c + d;
                            if ((s & 1) != outb)
                                continue;
                            int cp = s >> 1;
                            nmask ^= (1 << cp);
                        }
                    }
                    nx[t][outb][mask] = nmask;
                }
            }
        }
    }

    static BigInteger Q(long k) {
        int L = 64 - Long.numberOfLeadingZeros(k) + 3;
        if (k == 0)
            L = 3;

        BigInteger[] cnt = new BigInteger[32];
        for (int i = 0; i < 32; i++) {
            cnt[i] = BigInteger.ZERO;
        }
        cnt[1] = BigInteger.ONE;

        for (int b = 0; b < L; ++b) {
            int t = (int) ((k >> b) & 1L);
            BigInteger[] nxt = new BigInteger[32];
            for (int i = 0; i < 32; i++) {
                nxt[i] = BigInteger.ZERO;
            }
            for (int mask = 0; mask < 32; ++mask) {
                BigInteger ways = cnt[mask];
                if (ways.equals(BigInteger.ZERO))
                    continue;
                nxt[nx[t][0][mask]] = nxt[nx[t][0][mask]].add(ways);
                nxt[nx[t][1][mask]] = nxt[nx[t][1][mask]].add(ways);
            }
            cnt = nxt;
        }

        BigInteger ans = BigInteger.ZERO;
        for (int mask = 0; mask < 32; ++mask) {
            if ((mask & 1) != 0) {
                ans = ans.add(cnt[mask]);
            }
        }
        return ans;
    }

    public static String solve() {
        BigInteger sum = BigInteger.ZERO;
        long k = 1;
        for (int e = 1; e <= 18; ++e) {
            k *= 10;
            sum = sum.add(Q(k));
        }
        return sum.toString();
    }

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