import java.util.*;

public class Euler84 {
    public static void main(String[] args) {
        Random rng = new Random(42);
        int[] visits = new int[40];
        int pos = 0, doubles = 0;
        int[] ccCards = new int[16];
        int[] chCards = new int[16];
        for (int i = 0; i < 16; i++) {
            ccCards[i] = i;
            chCards[i] = i;
        }
        shuffle(ccCards, rng);
        shuffle(chCards, rng);
        int ccIdx = 0, chIdx = 0;
        for (int t = 0; t < 1000000; t++) {
            int d1 = rng.nextInt(4) + 1, d2 = rng.nextInt(4) + 1;
            if (d1 == d2)
                doubles++;
            else
                doubles = 0;
            if (doubles >= 3) {
                pos = 10;
                doubles = 0;
            } else {
                pos = (pos + d1 + d2) % 40;
                if (pos == 30)
                    pos = 10;
                if (pos == 2 || pos == 17 || pos == 33) {
                    int c = ccCards[ccIdx];
                    ccIdx = (ccIdx + 1) % 16;
                    if (c == 0)
                        pos = 0;
                    else if (c == 1)
                        pos = 10;
                }
                if (pos == 7 || pos == 22 || pos == 36) {
                    int c = chCards[chIdx];
                    chIdx = (chIdx + 1) % 16;
                    if (c == 0)
                        pos = 0;
                    else if (c == 1)
                        pos = 10;
                    else if (c == 2)
                        pos = 11;
                    else if (c == 3)
                        pos = 24;
                    else if (c == 4)
                        pos = 39;
                    else if (c == 5)
                        pos = 5;
                    else if (c == 6 || c == 7) {
                        if (pos < 5 || pos >= 35)
                            pos = 5;
                        else if (pos < 15)
                            pos = 15;
                        else if (pos < 25)
                            pos = 25;
                        else
                            pos = 5;
                    } else if (c == 8) {
                        pos = pos < 12 || pos >= 28 ? 12 : 28;
                    } else if (c == 9)
                        pos = (pos + 37) % 40;
                }
            }
            visits[pos]++;
        }
        Integer[] idx = new Integer[40];
        for (int i = 0; i < 40; i++)
            idx[i] = i;
        Arrays.sort(idx, (a, b) -> visits[b] - visits[a]);
        System.out.printf("%02d%02d%02d%n", idx[0], idx[1], idx[2]);
    }

    static void shuffle(int[] a, Random r) {
        for (int i = a.length - 1; i > 0; i--) {
            int j = r.nextInt(i + 1);
            int t = a[i];
            a[i] = a[j];
            a[j] = t;
        }
    }
}
