import java.io.*;
import java.util.*;

public class Tests {
    Random rnd = new Random(239);
    int tests = 1;
    int MAXN = 100000;
    int MAXP = 31;

    public void writeTest(int n, int[] a) {
        try {
            PrintWriter out = new PrintWriter(String.format("tests/%02d",
                    tests++));

            out.println(n);
            for (int i = 0; i < a.length; i++) {
                if (i != 0)
                    out.print(" ");
                out.print(a[i]);
            }
            out.println();
            out.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public int nextInt(int pow) {
        return rnd.nextInt() & ((1 << pow) - 1);
    }

    public int nextInt(int l, int r) {
        int bits = rnd.nextInt(r - l + 1) + l;

        ArrayList<Integer> toSet = new ArrayList<Integer>();
        for (int i = 0; i < MAXP; i++) {
            toSet.add(i);
        }

        Collections.shuffle(toSet, rnd);

        int x = 0;
        for (int i = 0; i < bits; i++) {
            x |= 1 << toSet.get(i);
        }

        return x;
    }

    public void genRandom(int n, int pow) {
        genRandom(n, 0, pow);
    }

    public void genRandom(int n, int l, int r) {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = nextInt(l, r);
        }
        writeTest(n, a);
    }

    public void genFixed(int n, int pow, int k) {
        int[] b = new int[k];
        for (int i = 0; i < b.length; i++) {
            b[i] = nextInt(pow);
        }

        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = b[rnd.nextInt(k)];
        }
        writeTest(n, a);
    }

    public void genFixedZero(int n, int pow, int k) {
        genFixedZero(n, 0, pow, k);
    }

    public void genFixedZero(int n, int l, int r, int k) {
        int[] b = new int[k];
        for (int i = 1; i < b.length; i++) {
            b[i] = nextInt(l, r);
        }

        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            a[i] = b[rnd.nextInt(k)];
        }
        writeTest(n, a);
    }

    public void genLogicRandom(int n, int pow) {
        int[] a = new int[n];
        for (int i = 0; i < a.length; i++) {
            int xor = 0;
            int and = a[i];
            a[i] = nextInt(pow);
            for (int j = i; j >= 0; j--) {
                xor ^= a[j];
                and &= a[j];
                if ((xor & and) == 0) {
                    a[i] = xor | and;
                }
            }
        }
        writeTest(n, a);
    }

    private int[] permutation(int n) {
        int[] permutation = new int[n];
        for (int i = 0; i < n; i++) {
            int j = rnd.nextInt(i + 1);
            permutation[i] = permutation[j];
            permutation[j] = i;
        }
        return permutation;
    }

    private void genSteps(int n, int p) {
        int[] a = new int[n];
        Arrays.fill(a, (1 << p) - 1);

        int[] p1 = permutation(p);
        a[0] = 0;
        for (int i = 0; i < p; i++) {
            a[i + 1] = a[i] | (1 << p1[i]);
        }

        int[] p2 = permutation(p);
        a[n - 1] = 0;
        for (int i = 0; i < p; i++) {
            a[n - 2 - i] = a[n - 1 - i] | (1 << p2[i]);
        }

        writeTest(n, a);
    }

    private void genAntiSteps(int n, int p) {
        int[] a = new int[n];
        Arrays.fill(a, 0);

        int[] p1 = permutation(p);
        a[0] = (1 << p) - 1;
        for (int i = 0; i < p; i++) {
            a[i + 1] = a[i] & ~(1 << p1[i]);
        }

        int[] p2 = permutation(p);
        a[n - 1] = (1 << p) - 1;
        for (int i = 0; i < p; i++) {
            a[n - 2 - i] = a[n - 1 - i] & ~(1 << p2[i]);
        }
        writeTest(n, a);
    }

    public void gen() {
        if (!new File("tests").exists()) {
            new File("tests").mkdir();
        }

        writeTest(4, new int[] { 1, 2, 3, 3 });

        writeTest(2, new int[] { 0, 0 });
        writeTest(2, new int[] { 0, 10 });
        writeTest(1, new int[] { 0 });
        writeTest(1, new int[] { 3 });

        genFixed(rnd.nextInt(10) + 1, 3, 2);
        genFixedZero(rnd.nextInt(10) + 1, 3, 2);
        genFixedZero(rnd.nextInt(10) + 1, 3, 1);
        for (int i = 0; i < 2; i++)
            genLogicRandom(rnd.nextInt(20) + 1, 2);
        for (int i = 0; i < 2; i++)
            genRandom(rnd.nextInt(10) + 1, 3);

        genFixedZero(rnd.nextInt(100) + 1, rnd.nextInt(5) + 1, 1);
        for (int i = 0; i < 2; i++) {
            genFixed(rnd.nextInt(100) + 1, rnd.nextInt(5) + 1,
                    rnd.nextInt(10) + 1);
            genFixedZero(rnd.nextInt(100) + 1, rnd.nextInt(5) + 1,
                    rnd.nextInt(10) + 1);
            genLogicRandom(rnd.nextInt(100) + 1, rnd.nextInt(5) + 1);
            genRandom(rnd.nextInt(100) + 1, rnd.nextInt(5) + 1);
        }

        for (int i = 0; i < 2; i++) {
            int r = rnd.nextInt(10) + 1;
            int l = rnd.nextInt(r);
            genFixedZero(rnd.nextInt(100) + 1, l, r, rnd.nextInt(5) + 1);
            r = rnd.nextInt(10) + 1;
            l = rnd.nextInt(r);
            genRandom(rnd.nextInt(100) + 1, l, r);
        }

        for (int i = 0; i < 3; i++) {
            genLogicRandom(500, rnd.nextInt(7) + 1);
        }

        genFixedZero(10, MAXP, MAXP, 2);

        genFixedZero(100, MAXP, MAXP, 2);

        genFixedZero(500, MAXP, MAXP, 2);

        genFixedZero(rnd.nextInt(MAXN), MAXP, MAXP, 2);

        genFixedZero(rnd.nextInt(MAXN) + 1, rnd.nextInt(10) + 1, 1);
        for (int i = 0; i < 2; i++) {
            genFixed(rnd.nextInt(MAXN) + 1, rnd.nextInt(10) + 1,
                    rnd.nextInt(10) + 1);
            genFixedZero(rnd.nextInt(MAXN) + 1, rnd.nextInt(10) + 1,
                    rnd.nextInt(10) + 1);
            genRandom(rnd.nextInt(MAXN) + 1, rnd.nextInt(10) + 1);
        }

        for (int i = 0; i < 2; i++) {
            int r = rnd.nextInt(32) + 1;
            int l = r - rnd.nextInt(3);
            genFixedZero(rnd.nextInt(MAXN) + 1, l, r, rnd.nextInt(10) + 1);
            r = rnd.nextInt(32) + 1;
            l = r - rnd.nextInt(3);
            genRandom(rnd.nextInt(MAXN) + 1, l, r);
        }

        genFixed(MAXN, 10, 1);
        genFixed(MAXN, 10, 2);
        genFixed(MAXN, 10, 5);
        genFixed(MAXN, 10, 8);
        genFixed(MAXN, 10, 15);

        genFixedZero(MAXN, 10, 1);
        genFixedZero(MAXN, 10, 2);
        genFixedZero(MAXN, 10, 3);
        genFixedZero(MAXN, 10, 5);
        genFixedZero(MAXN, 10, 8);

        for (int i = 0; i < 3; i++) {
            genRandom(MAXN, 3);
            genRandom(MAXN, 5);
            genRandom(MAXN, 7);
        }
        genRandom(MAXN, 8);
        genRandom(MAXN, 10);
        genRandom(MAXN, 15);

        for (int i = 0; i < 3; i++) {
            genRandom(MAXN, rnd.nextInt(MAXP) + 1);
            genRandom(MAXN, MAXP);
        }

        genFixedZero(MAXN, 1, 1, rnd.nextInt(20) + 1);
        for (int i = 1; i < 4; i++) {
            int x = rnd.nextInt(32) + 1;
            genFixedZero(MAXN, x, x, rnd.nextInt(20) + 1);
        }
        genFixedZero(MAXN, MAXP, MAXP, 2);
        genSteps(MAXN, MAXP);
        genAntiSteps(MAXN, MAXP);
    }

    public static void main(String[] args) {
        new Tests().gen();
    }
}
