import java.io.*;
import java.util.*;
public class SlimeCombining {
  private static InputReader in;
  private static PrintWriter out;
  public static double EPS = 1e-15;
  public static int maxp = 50;

  public static void main (String[] args) {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out, true);

    int n = in.nextInt();
    int p = in.nextInt();

    double p2 = p / 1000000000., p4 = 1 - p2;
    double[][] a = new double[maxp][maxp];
    double[][] b = new double[maxp][maxp];
    for (int len = 1; len < maxp; len++) {
      for (int pow = 1; pow < maxp; pow++) {
        if (pow == 1) a[len][pow] += p2;
        if (pow == 2) {
          a[len][pow] += p4;
          b[len][pow] += p4;
        }
        a[len][pow] += a[len-1][pow-1] * a[len][pow-1];
        b[len][pow] += a[len-1][pow-1] * b[len][pow-1];
      }
    }
    for (int len = maxp - 1; len >= 1; len--) {
      for (int pow = 1; pow < maxp; pow++) {
        a[len][pow] *= 1 - a[len-1][pow];
        b[len][pow] *= 1 - a[len-1][pow];
      }
    }

    // value of a slime that has been merged i times
    long[] vals = new long[maxp];
    for (int i = 0; i < maxp; i++) vals[i] = i;//1l << i;
    // manually do first few cases
    double[][] dp = new double[maxp][maxp];
    double[][] sum = new double[maxp][maxp];
    for (int cur = 1; cur < maxp; cur++)
      dp[maxp-1][cur] = vals[cur];

    // manual dp
    for (int i = maxp-2; i >= 0; i--) {
      for (int cur = 1; cur < maxp; cur++) {
        for (int next = 1; next < maxp; next++) {
          if (cur == next) continue;
          if (cur == 1) {
            dp[i][cur] += b[maxp-i-1][next] * dp[i+1][next];
            sum[i][cur] += b[maxp-i-1][next];
          } else {
            if (cur < next) continue;
            dp[i][cur] += a[maxp-i-1][next] * dp[i+1][next];
            sum[i][cur] += a[maxp-i-1][next];
          }
        }
      }
      for (int cur = 1; cur < maxp; cur++) {
        dp[i][cur] = vals[cur] + dp[i][cur] / sum[i][cur];
      }
    }
    if (n < maxp) {
      int k = (int)n;
      double exp = 0;
      for (int i = 1; i < maxp; i++) {
        exp += a[k][i] * dp[maxp-k][i];
      }
      out.printf("%.15f\n", exp);
      out.close();
      System.exit(0);
    }

    double[] vec = new double[maxp+1];
    System.arraycopy(dp[0], 0, vec, 0, maxp);
    vec[maxp] = 1;
    double[][] mat = new double[maxp+1][maxp+1];
    mat[maxp][maxp] = 1;
    for (int i = 1; i < maxp; i++) {
      for (int j = 1; j < maxp; j++) {
        if (i == j) continue;
        if (i == 1) {
          mat[i][j] += b[maxp-1][j] / sum[0][i];
        } else {
          if (i < j) continue;
          mat[i][j] += a[maxp-1][j] / sum[0][i];
        }
      }
      mat[i][maxp] += vals[i];
    }
    mat = mat_exp(mat, n - maxp);
    vec = vec_mult(mat, vec);
    double exp = 0;
    for (int i = 1; i < maxp; i++) {
      exp += a[maxp-1][i] * vec[i];
    }
    out.printf("%.15f\n", exp);
    out.close();
    System.exit(0);
  }

  public static double[] vec_mult(double[][] A, double[] B) {
    double[] C = new double[A.length];
    for (int i = 0; i < A.length; i++) {
      for (int j = 0; j < B.length; j++) {
        C[i] += A[i][j] * B[j];
      }
    }
    return C;
  }

  private static double[][] mat_exp(double[][] A, long e) {
    if (e == 0) {
      double[][] ret = new double[A.length][A.length];
      for (int i = 0; i < A.length; i++) ret[i][i] = 1.0;
      return ret;
    }
    if (e == 1)
      return A;
    else if (e % 2 == 0) {
      double[][] A1 = mat_exp(A, e / 2);
      return matrix_mult(A1, A1);
    } else
      return matrix_mult(A, mat_exp(A, e - 1));
  }

  private static double[][] matrix_mult(double[][] A, double[][] B) {
    double[][] C = new double[A.length][A.length];
    for (int i = 0; i < A.length; i++)
      for (int j = 0; j < A.length; j++)
        for (int k = 0; k < A.length; k++)
          C[i][k] += A[i][j] * B[j][k];
    return C;
  }

  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


import java.io.*;
import java.util.*;
public class SlimeCombiningLinear {
  private static InputReader in;
  private static PrintWriter out;
  public static double EPS = 1e-15;
  public static int maxp = 50;

  public static void main (String[] args) {
    in = new InputReader(System.in);
    out = new PrintWriter(System.out, true);

    int n = in.nextInt();
    int p = in.nextInt();

    double p2 = p / 1000000000., p4 = 1 - p2;
    double[][] a = new double[maxp][maxp];
    double[][] b = new double[maxp][maxp];
    for (int len = 1; len < maxp; len++) {
      for (int pow = 1; pow < maxp; pow++) {
        if (pow == 1) a[len][pow] += p2;
        if (pow == 2) {
          a[len][pow] += p4;
          b[len][pow] += p4;
        }
        a[len][pow] += a[len-1][pow-1] * a[len][pow-1];
        b[len][pow] += a[len-1][pow-1] * b[len][pow-1];
      }
    }
    for (int len = maxp - 1; len >= 1; len--) {
      for (int pow = 1; pow < maxp; pow++) {
        a[len][pow] *= 1 - a[len-1][pow];
        b[len][pow] *= 1 - a[len-1][pow];
      }
    }

    // value of a slime that has been merged i times
    long[] vals = new long[maxp];
    for (int i = 0; i < maxp; i++) vals[i] = i;//1l << i;
    // manually do first few cases
    int maxn = 1000;
    double[][] dp = new double[maxn][maxp];
    double[][] sum = new double[maxn][maxp];
    for (int cur = 1; cur < maxp; cur++)
      dp[maxn-1][cur] = vals[cur];

    // manual dp
    for (int i = maxn-2; i >= 0; i--) {
      for (int cur = 1; cur < maxp; cur++) {
        for (int next = 1; next < maxp; next++) {
          if (cur == next) continue;
          if (cur == 1) {
            int id = Math.min(maxp-1, maxn-i-1);
            dp[i][cur] += b[id][next] * dp[i+1][next];
            sum[i][cur] += b[id][next];
          } else {
            if (cur < next) continue;
            int id = Math.min(maxp-1, maxn-i-1);
            dp[i][cur] += a[id][next] * dp[i+1][next];
            sum[i][cur] += a[id][next];
          }
        }
      }
      for (int cur = 1; cur < maxp; cur++) {
        dp[i][cur] = vals[cur] + dp[i][cur] / sum[i][cur];
      }
    }
    if (n <= maxn) {
      int k = (int)n;
      int w = Math.min(maxp-1, k);
      double exp = 0;
      for (int i = 1; i < maxp; i++) {
        exp += a[w][i] * dp[maxn-k][i];
      }
      out.printf("%.15f\n", exp);
      out.close();
      System.exit(0);
    }

    double exp1 = 0;
    double exp2 = 0;
    for (int i = 1; i < maxp; i++) {
      exp1 += a[maxp-1][i] * dp[0][i];
      exp2 += a[maxp-1][i] * dp[1][i];
    }
    out.printf("%.15f\n", exp2 + (exp1 - exp2) * (long)(n - maxn + 1));
    out.close();
    System.exit(0);
  }
  static class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
      reader = new BufferedReader(new InputStreamReader(stream), 32768);
      tokenizer = null;
    }

    public String next() {
      while (tokenizer == null || !tokenizer.hasMoreTokens()) {
        try {
          tokenizer = new StringTokenizer(reader.readLine());
        } catch (IOException e) {
          throw new RuntimeException(e);
        }
      }
      return tokenizer.nextToken();
    }

    public int nextInt() {
      return Integer.parseInt(next());
    }
  }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Niyaz Nigmatullin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, FastScanner in, FastPrinter out) {
//        Random rng = new Random(12323L);
//        for (int tt = 0; tt < 7; tt++) {
//            int n = rng.nextInt(2) + 77;
//            HeroesSmart a = new HeroesSmart(n);
//            HeroesStupid b = new HeroesStupid(n);
//            for (int it = 0; it < 10000; it++) {
//                if (rng.nextBoolean()) {
//                    int add = rng.nextInt(10) + 1;
//                    int l = rng.nextInt(n);
//                    int r = rng.nextInt(n - l) + l + 1;
//                    a.add(l, r, add);
//                    b.add(l, r, add);
//                    System.out.println(l + " " + r + " " + add);
//                } else {
//                    int l = rng.nextInt(n - 1) / 2 * 2 + 1;
//                    int r = rng.nextInt(n - l) + l + 1;
//                    boolean ans1 = a.canBeat(l, r);
//                    boolean ans2 = b.canBeat(l, r);
//                    if (ans1 != ans2) {
//                        throw new AssertionError();
//                    }
//                }
//            }
//        }
            int n = in.nextInt();
//        HeroesStupid real = new HeroesStupid(n);
//        HeroesStupid plusOne = new HeroesStupid(n + 1);
            TaskF.HeroesSmart real = new TaskF.HeroesSmart(n);
            TaskF.HeroesSmart plusOne = new TaskF.HeroesSmart(n + 1);
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                real.add(i, i + 1, x);
                plusOne.add(i + 1, i + 2, x);
            }
            int m = in.nextInt();
            for (int i = 0; i < m; i++) {
                int op = in.nextInt();
                if (op == 2) {
                    int l = in.nextInt();
                    int r = in.nextInt() + 1;
                    boolean ans;
                    if ((l & 1) == 1) {
                        ans = real.canBeat(l, r);
                    } else {
                        ans = plusOne.canBeat(l + 1, r + 1);
                    }
                    out.println(ans ? 1 : 0);
                } else {
                    int l = in.nextInt();
                    int r = in.nextInt() + 1;
                    int k = in.nextInt();
                    real.add(l, r, k);
                    plusOne.add(l + 1, r + 1, k);
                }
            }
        }

        static class HeroesSmart {
            MultiSegmentTree all;
            MultiSegmentTree even;
            MultiSegmentTree odd;
            int pairs;

            HeroesSmart(int n) {
                all = new MultiSegmentTree(n + 1);
                pairs = (n + 1) / 2 + 1;
                even = new MultiSegmentTree(pairs);
                odd = new MultiSegmentTree(pairs);
            }

            void add(int l, int r, int k) {
                all.add(l, r, k);
                if ((l & 1) == 1) {
                    odd.add(l / 2, pairs, k);
                } else {
                    even.add(l / 2, pairs, k);
                }
                if ((r & 1) == 1) {
                    odd.add(r / 2, pairs, -k);
                } else {
                    even.add(r / 2, pairs, -k);
                }
            }

            boolean canBeat(int l, int r) { // [l, r)
                if ((l & 1) == 1) {
                    long evenMin = even.getMin((l + 1) / 2, (r - 1) / 2 + 1);
                    if (l > 0) {
                        evenMin -= even.getSum((l - 1) / 2, (l - 1) / 2 + 1);
                    }
                    long oddMin = odd.getMin(l / 2, (r - 2) / 2 + 1) - odd.getSum(l / 2, l / 2 + 1) + all.getSum(l, l + 1) - 1;
                    if (evenMin < 0 || oddMin < 0) {
                        return false;
                    }
                    if ((r & 1) == 0) {
                        return odd.getSum((r - 2) / 2, (r - 2) / 2 + 1) - odd.getSum(l / 2, l / 2 + 1) + all.getSum(l, l + 1) - 1 == 0;
                    } else {
                        return even.getSum((r - 1) / 2, (r - 1) / 2 + 1) - (l > 0 ? even.getSum((l - 1) / 2, (l - 1) / 2 + 1) : 0) == 0;
                    }
                }
                throw new AssertionError();
            }

        }

    }

    static class FastScanner extends BufferedReader {
        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public int read() {
            try {
                int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        static boolean isWhiteSpace(int c) {
            return c >= 0 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

    }

    static class MultiSegmentTree {
        private long[] min;
        private long[] max;
        private long[] sum;
        private long[] add;
        private long[] set;
        private boolean[] toSet;
        private int[] count;
        final int n;

        public MultiSegmentTree(int n) {
            this.n = Integer.highestOneBit(n) << 1;
            min = new long[this.n << 1];
            max = new long[this.n << 1];
            sum = new long[this.n << 1];
            add = new long[this.n << 1];
            set = new long[this.n << 1];
            count = new int[this.n << 1];
            toSet = new boolean[this.n << 1];
            count(0, 0, this.n);
        }

        private int count(int node, int l, int r) {
            if (l == r - 1) {
                count[node] = 1;
                return 1;
            }
            int m = (l + r) >> 1;
            return count[node] = count((node << 1) | 1, l, m)
                    + count((node << 1) + 2, m, r);
        }

        private void add(int node, long x) {
            if (toSet[node]) {
                set[node] += x;
            } else {
                add[node] += x;
            }
        }

        private void set(int node, long x) {
            add[node] = 0;
            set[node] = x;
            toSet[node] = true;
        }

        private void relax(int node) {
            if (!toSet[node] && add[node] == 0) {
                return;
            }
            min[node] = getMin(node);
            max[node] = getMax(node);
            sum[node] = getSum(node);
            if (toSet[node]) {
                set((node << 1) | 1, set[node]);
                set((node << 1) + 2, set[node]);
                toSet[node] = false;
            } else {
                add((node << 1) | 1, add[node]);
                add((node << 1) + 2, add[node]);
                add[node] = 0;
            }
        }

        private long getSum(int node) {
            return toSet[node] ? set[node] * count(node) : sum[node]
                    + add[node] * count(node);
        }

        private long count(int node) {
            return count[node];
        }

        private long getMax(int node) {
            return toSet[node] ? set[node] : max[node] + add[node];
        }

        private long getMin(int node) {
            return toSet[node] ? set[node] : min[node] + add[node];
        }

        private void add(int node, int l, int r, int left, int right, long x) {
            if (right <= l || r <= left) {
                return;
            }
            if (left <= l && r <= right) {
                add(node, x);
                return;
            }
            relax(node);
            int m = (l + r) >> 1;
            add((node << 1) | 1, l, m, left, right, x);
            add((node << 1) + 2, m, r, left, right, x);
            min[node] = Math.min(getMin((node << 1) | 1),
                    getMin((node << 1) + 2));
            max[node] = Math.max(getMax((node << 1) | 1),
                    getMax((node << 1) + 2));
            sum[node] = getSum((node << 1) | 1) + getSum((node << 1) + 2);
        }

        private long getMin(int node, int l, int r, int left, int right) {
            if (right <= l || r <= left) {
                return Long.MAX_VALUE;
            }
            if (left <= l && r <= right) {
                return getMin(node);
            }
            relax(node);
            int m = (l + r) >> 1;
            return Math.min(getMin((node << 1) | 1, l, m, left, right),
                    getMin((node << 1) + 2, m, r, left, right));
        }

        private long getSum(int node, int l, int r, int left, int right) {
            if (right <= l || r <= left) {
                return 0;
            }
            if (left <= l && r <= right) {
                return getSum(node);
            }
            relax(node);
            int m = (l + r) >> 1;
            return getSum((node << 1) | 1, l, m, left, right)
                    + getSum((node << 1) + 2, m, r, left, right);
        }

        public void add(int l, int r, long x) {
            if (l >= r) {
                return;
            }
            add(0, 0, n, l, r, x);
        }

        public long getSum(int l, int r) {
            if (l >= r) {
                return 0;
            }
            return getSum(0, 0, n, l, r);
        }

        public long getMin(int l, int r) {
            if (l >= r) {
                return Long.MAX_VALUE;
            }
            return getMin(0, 0, n, l, r);
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(OutputStream out) {
            super(out);
        }

        public FastPrinter(Writer out) {
            super(out);
        }

    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.OutputStream;
import java.io.IOException;
import java.util.InputMismatchException;
import java.io.InputStreamReader;
import java.io.Writer;
import java.io.BufferedReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Niyaz Nigmatullin
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        FastPrinter out = new FastPrinter(outputStream);
        TaskF solver = new TaskF();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskF {
        public void solve(int testNumber, FastScanner in, FastPrinter out) {
//        Random rng = new Random(12323L);
//        for (int tt = 0; tt < 7; tt++) {
//            int n = rng.nextInt(2) + 77;
//            HeroesSmart a = new HeroesSmart(n);
//            HeroesStupid b = new HeroesStupid(n);
//            for (int it = 0; it < 10000; it++) {
//                if (rng.nextBoolean()) {
//                    int add = rng.nextInt(10) + 1;
//                    int l = rng.nextInt(n);
//                    int r = rng.nextInt(n - l) + l + 1;
//                    a.add(l, r, add);
//                    b.add(l, r, add);
//                    System.out.println(l + " " + r + " " + add);
//                } else {
//                    int l = rng.nextInt(n - 1) / 2 * 2 + 1;
//                    int r = rng.nextInt(n - l) + l + 1;
//                    boolean ans1 = a.canBeat(l, r);
//                    boolean ans2 = b.canBeat(l, r);
//                    if (ans1 != ans2) {
//                        System.out.println(l + " " + r);
//                        throw new AssertionError();
//                    }
//                }
//            }
//        }
            int n = in.nextInt();
//        HeroesStupid real = new HeroesStupid(n);
//        HeroesStupid plusOne = new HeroesStupid(n + 1);
            TaskF.HeroesSmart real = new TaskF.HeroesSmart(n);
            TaskF.HeroesSmart plusOne = new TaskF.HeroesSmart(n + 1);
            for (int i = 0; i < n; i++) {
                int x = in.nextInt();
                real.add(i, i + 1, x);
                plusOne.add(i + 1, i + 2, x);
            }
            int m = in.nextInt();
            for (int i = 0; i < m; i++) {
                int op = in.nextInt();
                if (op == 2) {
                    int l = in.nextInt();
                    int r = in.nextInt() + 1;
                    boolean ans;
                    if ((l & 1) == 1) {
                        ans = real.canBeat(l, r);
                    } else {
                        ans = plusOne.canBeat(l + 1, r + 1);
                    }
                    out.println(ans ? 1 : 0);
                } else {
                    int l = in.nextInt();
                    int r = in.nextInt() + 1;
                    int k = in.nextInt();
                    real.add(l, r, k);
                    plusOne.add(l + 1, r + 1, k);
                }
            }
        }

        static class HeroesSmart {
            FenwickRev all;
            TaskF.MultiSegmentTree even;
            TaskF.MultiSegmentTree odd;
            int pairs;

            HeroesSmart(int n) {
                all = new FenwickRev(n);
                pairs = (n + 1) / 2 + 1;
                even = new TaskF.MultiSegmentTree(pairs);
                odd = new TaskF.MultiSegmentTree(pairs);
            }

            void add(int l, int r, int k) {
                all.add(l, r, k);
                if ((l & 1) == 1) {
                    odd.add(l / 2, pairs, k);
                } else {
                    even.add(l / 2, pairs, k);
                }
                if ((r & 1) == 1) {
                    odd.add(r / 2, pairs, -k);
                } else {
                    even.add(r / 2, pairs, -k);
                }
            }

            boolean canBeat(int l, int r) { // [l, r)
                if ((l & 1) == 1) {
                    long evenMin = even.getMin((l + 1) / 2, (r - 1) / 2 + 1);
                    long sumEvenFirst = l == 0 ? 0 : even.getMin((l - 1) / 2, (l - 1) / 2 + 1);
                    evenMin -= sumEvenFirst;
                    long sumFirst = odd.getMin(l / 2, l / 2 + 1);
                    int valFirst = all.getElement(l);
                    long oddMin = odd.getMin(l / 2, (r - 2) / 2 + 1) - sumFirst + valFirst - 1;
                    if (evenMin < 0 || oddMin < 0) {
                        return false;
                    }
                    if ((r & 1) == 0) {
                        return odd.getMin((r - 2) / 2, (r - 2) / 2 + 1) - sumFirst + valFirst - 1 == 0;
                    } else {
                        return even.getMin((r - 1) / 2, (r - 1) / 2 + 1) - sumEvenFirst == 0;
                    }
                }
                throw new AssertionError();
            }

        }

        static class MultiSegmentTree {
            private long[] min;
            private long[] add;
            final int n;

            public MultiSegmentTree(int n) {
                this.n = Integer.highestOneBit(n) << 1;
                min = new long[this.n << 1];
                add = new long[this.n << 1];
            }

            private void add(int node, long x) {
                add[node] += x;
            }

            private void relax(int node) {
                if (add[node] == 0) {
                    return;
                }
                min[node] = getMin(node);
                add((node << 1) | 1, add[node]);
                add((node << 1) + 2, add[node]);
                add[node] = 0;
            }

            private long getMin(int node) {
                return min[node] + add[node];
            }

            private void add(int node, int l, int r, int left, int right, long x) {
                if (right <= l || r <= left) {
                    return;
                }
                if (left <= l && r <= right) {
                    add(node, x);
                    return;
                }
                relax(node);
                int m = (l + r) >> 1;
                add((node << 1) | 1, l, m, left, right, x);
                add((node << 1) + 2, m, r, left, right, x);
                min[node] = Math.min(getMin((node << 1) | 1),
                        getMin((node << 1) + 2));
            }

            private long getMin(int node, int l, int r, int left, int right) {
                if (right <= l || r <= left) {
                    return Long.MAX_VALUE;
                }
                if (left <= l && r <= right) {
                    return getMin(node);
                }
                relax(node);
                int m = (l + r) >> 1;
                return Math.min(getMin((node << 1) | 1, l, m, left, right),
                        getMin((node << 1) + 2, m, r, left, right));
            }

            public void add(int l, int r, long x) {
                if (l >= r) {
                    return;
                }
                add(0, 0, n, l, r, x);
            }

            public long getMin(int l, int r) {
                if (l >= r) {
                    return Long.MAX_VALUE;
                }
                return getMin(0, 0, n, l, r);
            }

        }

    }

    static class FastScanner extends BufferedReader {
        public FastScanner(InputStream is) {
            super(new InputStreamReader(is));
        }

        public int read() {
            try {
                int ret = super.read();
//            if (isEOF && ret < 0) {
//                throw new InputMismatchException();
//            }
//            isEOF = ret == -1;
                return ret;
            } catch (IOException e) {
                throw new InputMismatchException();
            }
        }

        static boolean isWhiteSpace(int c) {
            return c >= 0 && c <= 32;
        }

        public int nextInt() {
            int c = read();
            while (isWhiteSpace(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int ret = 0;
            while (c >= 0 && !isWhiteSpace(c)) {
                if (c < '0' || c > '9') {
                    throw new NumberFormatException("digit expected " + (char) c
                            + " found");
                }
                ret = ret * 10 + c - '0';
                c = read();
            }
            return ret * sgn;
        }

        public String readLine() {
            try {
                return super.readLine();
            } catch (IOException e) {
                return null;
            }
        }

    }

    static class FenwickRev {
        int[] a;

        public FenwickRev(int n) {
            a = new int[n];
        }

        public void add(int x, int y) {
            for (int i = x; i >= 0; i = (i & (i + 1)) - 1) {
                a[i] += y;
            }
        }

        public int getElement(int x) {
            int ret = 0;
            for (int i = x; i < a.length; i |= i + 1) {
                ret += a[i];
            }
            return ret;
        }

        public void add(int left, int right, int y) {
            add(left - 1, -y);
            add(right - 1, y);
        }

    }

    static class FastPrinter extends PrintWriter {
        public FastPrinter(OutputStream out) {
            super(out);
        }

        public FastPrinter(Writer out) {
            super(out);
        }

    }
}


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;
import java.io.InputStream;

public class Solution {
    public static void main(String[] args) throws IOException {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        Task solver = new Task();
        solver.solve(in, out);

        out.close();
    }
}

/*
 *     Solution
 */

class Task {

    private final static int N = 20;

    public void solve(InputReader in, PrintWriter out) {

        int n = in.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = new String(in.next());
        }

        int m = s[0].length();
        long[] d = new long[(1 << N)];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if(i == j) continue;

                int mask = 0;
                for (int pos = 0; pos < m; pos++) {
                    if(s[i].charAt(pos) == s[j].charAt(pos)) {
                        mask |= (1 << pos);
                    }
                }
                d[mask] |=  (1L << i);
            }
        }

        for(int i = 0; i < m; i++){
            for(int pos = 0; pos < (1 << m) ; pos++){
                d[pos] |= d[pos|(1 << i)];
            }
        }

        int[] sum = new int[(1 << m)];
        for(int k = 0;k < (1 << m); k++){
            sum[k] = Long.bitCount(d[k]);
        }

        double[] f = new double[60];
        f[0] = 1;
        for(int i = 1;i < 60;i++)
            f[i] = f[i-1] * i;

        double[] ps = new double[m];
        for(int k = 0;k < m;k++){
            ps[k] = f[k] * f[m-1-k] / f[m];
        }

        double ans = 0;
        for(int i = 0; i < (1 << m); i++) {
            int k = Integer.bitCount(i);
            for(int j = 0; j < m; j++){
                if( i << ~j < 0){
                    ans += k * ps[k-1] * (sum[i^1<<j] - sum[i]);
                }
            }
        }

        out.printf(Locale.US, "%.12f\n", ans/n);

        return;
    }

}

/*
 *      Reading
 */

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader (InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


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

import static java.lang.Math.*;

public class Main extends PrintWriter {
    BufferedReader in;
    StringTokenizer stok;
    final Random rand = new Random(31);
    final int inf = (int) 1e9;
    final long linf = (long) 1e18;

    public void solve() throws IOException {
        int n = nextInt();
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        int m = a[0].length;
        long[] d1 = new long[1 << m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    int x = 0;
                    for (int k = 0; k < m; k++) {
                        if (a[i][k] == a[j][k]) {
                            x |= (1 << k);
                        }
                    }
                    d1[x] |= (1L << i);
                    d1[x] |= (1L << j);
                }
            }
        }
        for (int i = (1 << m) - 1; i >= 0; i--) {
            for (int j = 0; j < m; j++) {
                d1[i] |= d1[i | (1 << j)];
            }
        }
        double[] d = new double[1 << m];
        d[0] = 1;
        for (int mask = 0; mask < (1 << m); mask++) {
            double bc = Integer.bitCount(mask);
            int bc1 = Long.bitCount(d1[mask]);
            if (bc1 == 0) {
                continue;
            }
            for (int i = 0; i < m; i++) {
                if ((mask & (1 << i)) == 0) {
                    int nmask = mask | (1 << i);
                    double nbc1 = Long.bitCount(d1[nmask]);
                    d[nmask] += d[mask] * (nbc1 / bc1) / (m - bc);
                }
            }
        }
        double ans = 0;
        for (int mask = 0; mask < (1 << m); mask++) {
            double finish = 0;
            int bc1 = Long.bitCount(d1[mask]);
            int bc = Long.bitCount(mask);
            for (int i = 0; i < m; i++) {
                if ((mask & (1 << i)) > 0) {
                    int nmask = mask & ~(1 << i);
                    int nbc1 = Long.bitCount(d1[nmask]);
                    if (nbc1 == 0) {
                        continue;
                    }
                    int nbc = Long.bitCount(nmask);
                    finish += d[nmask] * (nbc1 - bc1) / nbc1 / (m - nbc);
                }
            }
            ans += bc * finish;
        }
        printf("%.11f", ans);
    }

    public void run() {
        try {
            solve();
            close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(abs(-1));
        }
    }

    Main() throws IOException {
        super(System.out);
        in = new BufferedReader(new InputStreamReader(System.in));
    }

    Main(String s) throws IOException {
        super("".equals(s) ? "output.txt" : (s + ".out"));
        in = new BufferedReader(new FileReader("".equals(s) ? "input.txt" : (s + ".in")));
    }

    public static void main(String[] args) throws IOException {
        try {
            Locale.setDefault(Locale.US);
        } catch (Exception ignored) {
        }
        new Main().run();
    }

    String next() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    int[] nextIntArray(int len) throws IOException {
        int[] a = new int[len];
        for (int i = 0; i < len; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    void shuffle(int[] a) {
        for (int i = 1; i < a.length; i++) {
            int x = rand.nextInt(i + 1);
            int t = a[i];
            a[i] = a[x];
            a[x] = t;
        }
    }

    boolean nextPerm(int[] p) {
        for (int a = p.length - 2; a >= 0; --a)
            if (p[a] < p[a + 1])
                for (int b = p.length - 1; ; --b)
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
        return false;
    }

    <T> List<T>[] createAdjacencyList(int countVertex) {
        List<T>[] res = new List[countVertex];
        for (int i = 0; i < countVertex; i++) {
            res[i] = new ArrayList<T>();
        }
        return res;
    }
}


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

import static java.lang.Math.*;

public class Main extends PrintWriter {
    BufferedReader in;
    StringTokenizer stok;
    final Random rand = new Random(31);
    final int inf = (int) 1e9;
    final long linf = (long) 1e18;

    public void solve() throws IOException {
        int n = nextInt();
        char[][] a = new char[n][];
        for (int i = 0; i < n; i++) {
            a[i] = next().toCharArray();
        }
        int m = a[0].length;
        long[] d1 = new long[1 << m];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    int x = 0;
                    for (int k = 0; k < m; k++) {
                        if (a[i][k] == a[j][k]) {
                            x |= (1 << k);
                        }
                    }
                    d1[x] |= (1 << i);
                    d1[x] |= (1 << j);
                }
            }
        }
        for (int i = (1 << m) - 1; i >= 0; i--) {
            for (int j = 0; j < m; j++) {
                d1[i] |= d1[i | (1 << j)];
            }
        }
        double[] d = new double[1 << m];
        d[0] = 1;
        for (int mask = 0; mask < (1 << m); mask++) {
            double bc = Integer.bitCount(mask);
            double bc1 = Long.bitCount(d1[mask]);
            for (int i = 0; i < m; i++) {
                if ((mask & (1 << i)) == 0) {
                    int nmask = mask | (1 << i);
                    d[nmask] += d[mask] * (bc1 / n) / (m - bc);
                }
            }
        }
        double ans = 0;
        for (int mask = 0; mask < (1 << m); mask++) {
            int t = n - Long.bitCount(d1[mask]);
            ans += Integer.bitCount(mask) * d[mask] * t / n;
        }
        printf("%.11f", ans);
    }

    public void run() {
        try {
            solve();
            close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(abs(-1));
        }
    }

    Main() throws IOException {
        super(System.out);
        in = new BufferedReader(new InputStreamReader(System.in));
    }

    Main(String s) throws IOException {
        super("".equals(s) ? "output.txt" : (s + ".out"));
        in = new BufferedReader(new FileReader("".equals(s) ? "input.txt" : (s + ".in")));
    }

    public static void main(String[] args) throws IOException {
        try {
            Locale.setDefault(Locale.US);
        } catch (Exception ignored) {
        }
        new Main().run();
    }

    String next() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = in.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(next());
    }

    int[] nextIntArray(int len) throws IOException {
        int[] a = new int[len];
        for (int i = 0; i < len; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    void shuffle(int[] a) {
        for (int i = 1; i < a.length; i++) {
            int x = rand.nextInt(i + 1);
            int t = a[i];
            a[i] = a[x];
            a[x] = t;
        }
    }

    boolean nextPerm(int[] p) {
        for (int a = p.length - 2; a >= 0; --a)
            if (p[a] < p[a + 1])
                for (int b = p.length - 1; ; --b)
                    if (p[b] > p[a]) {
                        int t = p[a];
                        p[a] = p[b];
                        p[b] = t;
                        for (++a, b = p.length - 1; a < b; ++a, --b) {
                            t = p[a];
                            p[a] = p[b];
                            p[b] = t;
                        }
                        return true;
                    }
        return false;
    }

    <T> List<T>[] createAdjacencyList(int countVertex) {
        List<T>[] res = new List[countVertex];
        for (int i = 0; i < countVertex; i++) {
            res[i] = new ArrayList<T>();
        }
        return res;
    }
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;

public class Main {
	static int mod = (int)1e9+7;
	static int N = 20;
	int n, y, m;
	int[] seat = new int[N], u = new int[N], v = new int[N];
	long[] num = new long[1<<16];
	int pos(int state,int k){
	    return (state >> k) & 1;
	}
	int find(int state){
	    for(int i = 0;i < n;i++)
	        if(pos(state,i) != 0) return i + 1;
	    return -1;
	}
	long dfs(int state, int k){
	    int i;
	    if(num[state] > -1) return num[state];
	    if(k == n) return num[state] = 1;
	    num[state] = 0;
	    for(i = 0;i < n;i++)
	        if(pos(state,i) == 0 && (state & seat[i]) == 0 && pos(v[k],i) != 0 && pos(u[i],k) != 0)
	            num[state] += dfs(state | (1 << i),k + 1);
	    return num[state];
	}
    void work() throws Exception {
    	//in = new BufferedReader(new InputStreamReader(System.in));
    	out = new PrintWriter(System.out);
    	//
    	Scanner cin = new Scanner(System.in);
    	/////////////////////////////////////////
    	while(cin.hasNext()) {
    		n = cin.nextInt();
    		y = cin.nextInt();
    		m = cin.nextInt();

    		Arrays.fill(seat, 0);
    		for(int i = 1; i <= m; i ++) {
    			int a = cin.nextInt();
    			int b = cin.nextInt();
    			seat[a-1] |= 1<<(b-1);
    		}

    		m = (1<<n)-1;
    		for(int i = 0; i < n; i ++) {
    			u[i] = v[i] = m;
    		}
    		Arrays.fill(num, -1);

    		dfs(0, 0);
    		y -= 2000;
    		if(num[0] < y) out.println("The times have changed");
    		else {
    			for(int i = 0; i < n; i ++) {
    				for(int j = 0; j < n; j ++) {
    					if(v[j] == m) {
    						u[i] = 1<<j;
    						v[j] = 1<<i;
    						dfs(0, 0);
    						if(num[0] < y) {
    							y -= num[0];
    							u[i] = v[i] = m;
    						} else break;
    					}
    				}
    			}
    			for(int i = 0; i < n; i ++) {
    				out.print(find(u[i]));
    				if(i == n-1) out.println();
    				else out.print(" ");
    			}
    		}
    	}

    }
  //  BufferedReader in;
  //  StringTokenizer str = null;
    static PrintWriter out;
//    private String next() throws Exception{
//    	while (str == null || !str.hasMoreElements())
//    	    str = new StringTokenizer(in.readLine());
//    	return str.nextToken();
//    }
//    private int nextInt() throws Exception{
//    	return Integer.parseInt(next());
//    }
//    private long nextLong() throws Exception{
//    	return Long.parseLong(next());
//    }
    static int dx[] = {0,1,0,-1};
    static int dy[] = {1,0,-1,0};
    class pair implements Comparable<pair>{
    	int first, second;
    	pair(int x, int y) {
    		first = x;
    		second = y;
    	}
		public int compareTo(pair o) {
			// TODO auto-generated method stub
			if(first != o.first) return ((Integer)first).compareTo(o.first);
			else return ((Integer)second).compareTo(o.second);
		}
    }
    DecimalFormat df=new DecimalFormat("0.000000");
    public static void main(String[] args) throws Exception{
        Main wo = new Main();
        wo.work();
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.Writer;
import java.util.Arrays;
import java.util.Scanner;
/**
 * Date     : 02.01.2012
 * Time     : 21:00:42
 * Email    : denys.astanin@gmail.com
 */

public class s83_e {
	public static void main(String[] args) throws IOException {
		new s83_e().run();
	}

	Writer writer;
	Reader reader;
	Scanner sc;
	void run() throws IOException {
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		reader = oj ? new InputStreamReader(System.in, "ISO-8859-1")
				: new FileReader("input/is83_e.txt");
		writer = new OutputStreamWriter(System.out, "ISO-8859-1");

		sc = new Scanner(new BufferedReader(reader));
		PrintWriter out = new PrintWriter(writer);
		int n = sc.nextInt() ;
		long y = sc.nextLong() - 2001;
		int m = sc.nextInt();

		int[] restrictions = new int[n];
		for (int i = 0; i < m; i++) {
			int a = sc.nextInt() - 1;
			int b = sc.nextInt() - 1;
			restrictions[b] |= 1 << a;
		}

		int[] prefix = new int[n];
		Arrays.fill(prefix, Integer.MIN_VALUE);

		boolean halt = false;
		cycle : for (int k = 0; k < n; k++) {
			while (true) {
				if (prefix[k] == Integer.MIN_VALUE) {
					prefix[k] = 0;
				} else {
					prefix[k]++;
				}
				if (prefix[k] == n) {
					halt = true;
					out.println("The times have changed");
					break cycle;
				}
				long[] dp = new long[1 << (prefix.length)];
				dp[0] = 1;
				for (int i = 0; i < 1 << (prefix.length); i++) {
					int count = Integer.bitCount(i);
					for (int j = 0; j < (prefix.length); j++) {
						if ((prefix[j] == Integer.MIN_VALUE || prefix[j] == count)
								&& (i & (1 << j)) == 0
								&& (i & restrictions[j]) == restrictions[j]) {
							dp[i | (1 << j)] += dp[i];
						}
					}
				}
				if (dp[(1 << (prefix.length)) - 1] > y) {
					break;
				} else {
					y -= dp[(1 << (prefix.length)) - 1];
				}
			}
		}
		if (!halt) {
			for (int i = 0; i < prefix.length; i++) {
				out.print((prefix[i] + 1) + " ");
			}
			out.println();
		}
		out.flush();
		out.close();
	}
}


import java.io.*;
import java.text.DecimalFormat;
import java.util.*;

public class Main {
    static int mod = (int)1e9+7;
    static int N = 20;
    int n, m;
    long y;
    int[] seat = new int[N], u = new int[N], v = new int[N];
    long[] num = new long[1<<16];
    int pos(int state,int k){
        return (state >> k) & 1;
    }
    int find(int state){
        for(int i = 0;i < n;i++)
            if(pos(state,i) != 0) return i + 1;
        return -1;
    }
    long dfs(int state, int k){
        int i;
        if(num[state] > -1) return num[state];
        if(k == n) return num[state] = 1;
        num[state] = 0;
        for(i = 0;i < n;i++)
            if(pos(state,i) == 0 && (state & seat[i]) == 0 && pos(v[k],i) != 0 && pos(u[i],k) != 0)
                num[state] += dfs(state | (1 << i),k + 1);
        return num[state];
    }
    void work() throws Exception {
        //in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        //
        Scanner cin = new Scanner(System.in);
        /////////////////////////////////////////
        while(cin.hasNext()) {
            n = cin.nextInt();
            y = cin.nextLong();
            m = cin.nextInt();

            Arrays.fill(seat, 0);
            for(int i = 1; i <= m; i ++) {
                int a = cin.nextInt();
                int b = cin.nextInt();
                seat[a-1] |= 1<<(b-1);
            }

            m = (1<<n)-1;
            for(int i = 0; i < n; i ++) {
                u[i] = v[i] = m;
            }
            Arrays.fill(num, -1);

            dfs(0, 0);
            y -= 2000;
            if(num[0] < y) out.println("The times have changed");
            else {
                for(int i = 0; i < n; i ++) {
                    for(int j = 0; j < n; j ++) {
                        if(v[j] == m) {
                            u[i] = 1<<j;
                            v[j] = 1<<i;
                            Arrays.fill(num, -1);
                            dfs(0, 0);
                            if(num[0] < y) {
                                y -= num[0];
                                u[i] = v[j] = m;
                            } else break;
                        }
                    }
                }
                for(int i = 0; i < n; i ++) {
                    out.print(find(u[i]));
                    if(i == n-1) out.println();
                    else out.print(" ");
                }
            }
        }

    }
  //  BufferedReader in;
  //  StringTokenizer str = null;
    static PrintWriter out;
//    private String next() throws Exception{
//      while (str == null || !str.hasMoreElements())
//          str = new StringTokenizer(in.readLine());
//      return str.nextToken();
//    }
//    private int nextInt() throws Exception{
//      return Integer.parseInt(next());
//    }
//    private long nextLong() throws Exception{
//      return Long.parseLong(next());
//    }
    static int dx[] = {0,1,0,-1};
    static int dy[] = {1,0,-1,0};
    class pair implements Comparable<pair>{
        int first, second;
        pair(int x, int y) {
            first = x;
            second = y;
        }
        public int compareTo(pair o) {
            // TODO auto-generated method stub
            if(first != o.first) return ((Integer)first).compareTo(o.first);
            else return ((Integer)second).compareTo(o.second);
        }
    }
    DecimalFormat df=new DecimalFormat("0.000000");
    public static void main(String[] args) throws Exception{
        Main wo = new Main();
        wo.work();
        out.close();
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;

public class ProblemE {
    static int N;
    static long Y;
    static long ycnt;
    static int[] place;
    static boolean[][] invalidGraph;
    static boolean[][] rules;

    private static long cnt2(int now) {
        int[] parray = new int[N];
        int[] map = new int[N];
        Arrays.fill(map, -1);
        int pidx = 0;
        for (int i = 0 ; i < N ; i++) {
            if (place[i] != -1) {
                map[place[i]] = i;
            } else {
                parray[pidx++] = i;
            }
        }

        for (int i = 0 ; i < now ; i++) {
            for (int j = i+1 ; j < now ; j++) {
                int young = -1;
                int old = -1;
                if (map[i] < map[j]) {
                    young = j;
                    old = i;
                } else {
                    old = j;
                    young = i;
                }
                if (invalidGraph[young][old]) {
                    return 0;
                }
            }
        }

        long[][] dp = new long[pidx+1][1<<N];
        dp[0][(1<<now)-1] = 1;
        for (int i = 0 ; i < pidx ; i++) {
            for (int ptn = 0 ; ptn < (1<<N) ; ptn++) {
                if (dp[i][ptn] <= 0) {
                    continue;
                }
                // next, we'll use parray[i] !
                // then, where to place parray[i] ?
                for (int next = now ; next < N ; next++) {
                    if ((ptn & (1<<next)) >= 1) {
                        continue;
                    }

                    boolean isok = true;

                    // check one : with already placed
                    for (int prev = 0 ; prev < now ; prev++) {
                        int young = -1;
                        int old = -1;
                        if (map[prev] < parray[i]) {
                            young = next;
                            old = prev;
                        } else {
                            young = prev;
                            old = next;
                        }
                        if (invalidGraph[young][old]) {
                            isok = false;
                            break;
                        }
                    }

                    // check two : with dp placed
                    for (int prev = now ; prev < N ; prev++) {
                        if ((ptn & (1<<prev)) >= 1) {
                            int old = prev;
                            int young = next;
                            if (invalidGraph[young][old]) {
                                isok = false;
                                break;
                            }
                        }
                    }

                    if (isok) {
                        int nptn = ptn | (1<<next);
                        dp[i+1][nptn] += dp[i][ptn];
                    }
                }
            }
        }
        return dp[pidx][(1<<N)-1];
    }

    private static void dfs(int now) {
        for (int i = 0 ; i < N ; i++) {
            if (place[i] == -1) {
                place[i] = now;

                long dcnt = cnt2(now+1);

                if (ycnt + dcnt >= Y) {
                    dfs(now+1);
                    break;
                }
                ycnt += dcnt;
                place[i] = -1;
            }
        }
    }

    public static void main(String[] args) throws IOException {
        BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
        String[] line = s.readLine().split(" ");
        int n = Integer.valueOf(line[0]);
        long y = Long.valueOf(line[1]) - 2000;
        int m = Integer.valueOf(line[2]);

        invalidGraph = new boolean[n][n];
        for (int i = 0 ; i < m ; i++) {
            String[] data = s.readLine().split(" ");
            int senior = Integer.valueOf(data[0])-1;
            int junior = Integer.valueOf(data[1])-1;
            invalidGraph[senior][junior] = true;
        }

        N = n;
        Y = y;
        ycnt = 0;
        place = new int[N];
        Arrays.fill(place, -1);

        dfs(0);

        if (place[0] == -1) {
            System.out.println("The times have changed");
            return;
        } else {
            int[] map = new int[N];
            for (int i = 0 ; i < n ; i++) {
                map[place[i]] = i;
            }

            StringBuffer b = new StringBuffer();
            for (int i = 0 ; i < n ; i++) {
                b.append(map[i]+1).append(" ");
            }
            System.out.println(b.substring(0, b.length()-1));
        }
    }
}


public class Main{
    public static void main(String[] args)
    {
        System.out.println("0
1
1
0
1
1
0
1
1
1
1
1
0
1
0
1
1
1
0
1
1
1
1
1
0
1
0
1
1
1");
    }
}


public class CodeForces1April2019E {
    public static void main(String[] args) {
        for (int i = 21; i < 51; i++) {
            System.out.println(((Math.min(i, 25) + i) % (2 + i % 3)) > 0 ? 1 : 0);
        }
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class CFD {

	public static void main(String[] args) throws IOException {
		FastScanner5 in = new FastScanner5();
		PrintWriter out = new PrintWriter(System.out);
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i<n; i++){
			a[i] = in.nextInt();
		}
		ArrayList<Block> b = new ArrayList<Block>();
		b.add(new Block(a[0], 1));
		for (int i = 1; i<n; i++){
			if (a[i]!=b.get(b.size()-1).col){
				if (a[i]==0){
					b.add(new Block(0, 1));
				} else {
					if (b.get(b.size()-1).col!=0) b.add(new Block(0, 0));
					b.add(new Block(a[i], 1));
				}
			} else {
				b.get(b.size()-1).cou++;
			}
		}
		b.add(new Block(0, 0));
		long ans = 0;
		for (int i = 1; i<b.size(); i++){
			if (b.get(i).col!=0&&b.get(i-1).col==0){
				b.get(i+1).cou+=b.get(i-1).cou;
				ans+=Math.min(b.get(i-1).cou, b.get(i).cou);
			}
		}
		System.out.println(ans);

	}
}

class Block{
	int col;
	int cou;
	public Block(int col, int cou) {
		this.col = col;
		this.cou = cou;
	}
	@Override
	public String toString() {
		return "Block [col=" + col + ", cou=" + cou + "]";
	}

}

class FastScanner5{

	BufferedReader reader;
	StringTokenizer tokenizer;

	FastScanner5() throws IOException{
		reader = new BufferedReader(new InputStreamReader(System.in));
		tokenizer = null;
	}

	String next() throws IOException{
		while (tokenizer == null||!tokenizer.hasMoreTokens()){
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	int nextInt() throws IOException{
		return Integer.parseInt(next());
	}

	long nextLong() throws IOException{
		return Long.parseLong(next());
	}

	double nextDouble() throws IOException{
		return Double.parseDouble(next());
	}

}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int length = in.nextInt();
		int[] proc = new int[length];
		int[] copy = new int[length];
		for (int i = 0; i < length; i++){
			proc[i] = in.nextInt();
		    copy[i] = proc[i];
		}

		proc = sort(proc, length);

        System.out.println(srav(proc,copy, length));

	}

	private static int[] sort(int[] proc, int length){

		for (int i = 0; i < length - 1; i++){
			if ((proc[i] == 0) && (proc[i + 1] != 0)){
			  proc[i] = proc[i+1];
			  proc[i + 1] = 0;
			  i = 0;
			}
		}

		return proc;
	}

	private static int srav(int[] proc, int[] copy, int length){
		int count = 0;
		for(int i = 0; i < length; i++){
			if ((copy[i] != 0) && (copy[i] != proc[i]) ){
				count++;
			}
		}
		return count;
	}

}


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

public class d1 {
	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public static void main(String[] args) throws IOException {
		new d1().run();
	}

	public void solve() throws IOException {
		int n = nextInt();

		int a[] = new int[n];

		int cnt[] = new int[n + 1];

		ArrayList<Integer> last = new ArrayList();

		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
			cnt[a[i]]++;

			if (!(last.size() > 0 && last.get(last.size() - 1) == a[i])){
				if (a[i] != 0){
					last.add(a[i]);
				}
			}
		}

		int cur = 0;
		long ans = 0;

		for (int i : last) {
			cur += cnt[i];

			int open = 0;

			for (int j = cur - cnt[i]; j < cur; j++) {
				if (a[j] == 0){
					open++;
				}
				a[j] = i;
			}

			ans += open;

			for (int j = cur; j < cur + open; j++) {
				a[j] = 0;
			}
		}

		out.println(ans);
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}


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

public class d1 {
	BufferedReader br;
	StringTokenizer in;
	PrintWriter out;

	public String nextToken() throws IOException {
		while (in == null || !in.hasMoreTokens()) {
			in = new StringTokenizer(br.readLine());
		}
		return in.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public static void main(String[] args) throws IOException {
		new d1().run();
	}

	public void solve() throws IOException {
		int n = nextInt();

		int a[] = new int[n];

		int cnt[] = new int[n + 1];

		for (int i = 0; i < n; i++) {
			a[i] = nextInt();
			cnt[a[i]]++;
		}

		int cur = 0;
		int ans = 0;

		for (int i = 1; i <= n; i++) {
			cur += cnt[i];

			int open = 0;

			for (int j = cur - cnt[i]; j < cur; j++) {
				if (a[j] == 0){
					open++;
				}
				a[j] = i;
			}

			ans += open;

			for (int j = cur; j < cur + open; j++) {
				a[j] = 0;
			}
		}

		out.println(ans);
	}

	public void run() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);

			solve();

			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class JeffAndBrackets {
	static BufferedReader in;
	static PrintWriter out;
	static StringTokenizer tk;
	static long MAX = Long.MAX_VALUE / 3;
	static int MAXBALANCE;
	public static void main(String[] args) throws Exception {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		tk = tk(in.readLine());

		int N = Integer.parseInt(tk.nextToken());
		int M = Integer.parseInt(tk.nextToken());

		int[] open = new int[N];
		int[] close = new int[N];

		tk = tk(in.readLine());
		for(int i=0;i<N;i++){
			open[i] = Integer.parseInt(tk.nextToken());

		}
		tk = tk(in.readLine());
		for(int i=0;i<N;i++){
			close[i] = Integer.parseInt(tk.nextToken());
		}

		MAXBALANCE = 2 * N;
		// min cost to convert from balance k to l in j moves if starting with ith modulo index
		long[][][][] init = new long[N][N+1][MAXBALANCE+1][MAXBALANCE+1];
		for(long[][][] i: init) {
			for(long[][] j : i) {
				for(long[] k : j) {
					Arrays.fill(k, MAX);
				}
			}
		}

		for(int mod = 0; mod < N; mod++) {
			for(int from = 0; from <= MAXBALANCE; from++) {
				init[mod][0][from][from] = 0;
			}
		}

		for(int move = 0; move < N; move++) {
			for(int mod = 0; mod < N; mod++) {
				for(int from = 0; from <= MAXBALANCE; from++) {
					for(int to = 0; to <= MAXBALANCE; to++) {
						if(to + 1 <= MAXBALANCE)
							init[(mod+1) % N][move+1][from][to+1] = Math.min(init[(mod+1) % N][move+1][from][to+1],
									init[mod][move][from][to] + open[mod]);
						if(to - 1 >= 0)
							init[(mod+1) % N][move+1][from][to-1] = Math.min(init[(mod+1) % N][move+1][from][to-1],
									init[mod][move][from][to] + close[mod]);
					}
				}
			}
		}

		// min cost to convert from balance i to j in N moves
		long[][] mat = init[0][N];
		long[][] result = new long[2*N+1][2*N+1];
		long[][] temp = new long[2*N+1][2*N+1];

		// mat ^ k = min cost... in Nk moves
		exp(mat, result,  temp, M);
		System.out.println(result[0][0]);
	}

	static void exp(long[][] mat, long[][] result, long[][] temp, int pow) {
		if(pow == 1) {
			for(int i=0;i<result.length;i++) {
				result[i] = mat[i].clone();
			}
		} else if(pow % 2 == 0){
			exp(mat, temp, result, pow / 2);
			for(long[] i : result) {
				Arrays.fill(i, MAX);
			}
			mul(temp, temp, result);
		} else {
			exp(mat, temp, result, pow -1);
			for(long[] i : result) {
				Arrays.fill(i, MAX);
			}
			mul(mat, temp, result);
		}
	}

	static void mul(long[][] a, long[][] b, long[][] res) {
		for(int i = 0; i < a.length; i++) {
			for(int j = 0; j < a.length; j++) {
				for(int k = 0; k < a.length; k++) {
					res[i][k] = Math.min(res[i][k], a[i][j] + b[j][k]);
				}
			}
		}
	}

	/*
	 exist soln <= N+1 balance
	 if there is a soln with N+1 left brackets
	 */

	static StringTokenizer tk (String s) {return new StringTokenizer(s);}
}


import java.util.Arrays;
import java.util.Scanner;

public class Main {
    private static long VERYLARGE = 2000000000L;

    private static void mul(long[][] a, long[][] b) {
        long[][] c = new long[a.length][a[0].length];

        for (int i = 0; i < a.length; i++) {
            Arrays.fill(c[i], VERYLARGE);
            for (int j = 0; j < b[0].length; j++) {
                for (int k = 0; k < a[0].length; k++) {
                    c[i][j] = Math.min(c[i][j], a[i][k] + b[k][j]);
                }
            }
        }

        for (int i = 0; i < a.length; i++)
            for (int j = 0; j < a[0].length; j++)
                a[i][j] = c[i][j];
    }

    private static void plus(long[][] a, long[][] b) {
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j < a[0].length; j++) {
                if (a[i][j] < VERYLARGE && b[i][j] < VERYLARGE)
                    a[i][j] += b[i][j];
            }
        }
    }

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();

        int[] as = new int[n];
        int[] bs = new int[n];

        for (int i = 0; i < n; i++) {
            as[i] = scan.nextInt();
        }

        for (int i = 0; i < n; i++) {
            bs[i] = scan.nextInt();
        }

        long[][] aa = new long[n + 1][n + 1];
        long[][] dp = new long[n + 1][n + 2];

        for (int x = 0; x <= n; x++) {
            for (int i = 0; i <= n; i++) Arrays.fill(dp[i], VERYLARGE);
            dp[0][x] = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j <= n; j++) {
                    if (j < n) dp[i+1][j+1] = Math.min(dp[i+1][j+1], as[i] + dp[i][j]);
                    if (j > 0) dp[i+1][j-1] = Math.min(dp[i+1][j-1], bs[i] + dp[i][j]);
                }
            }
            /*
            if (x == 0) {
                for (int i = 0; i <= n; i++) {
                    System.out.println(Arrays.toString(dp[i]));
                }
            }
            */
            for (int y = 0; y <= n; y++) aa[x][y] = dp[n][y];
        }
        /*
        for (int i = 0; i <= n; i++) {
            System.out.println(Arrays.toString(aa[i]));
        }
        System.out.println();
        */

        long b[][] = new long[n + 1][n + 1];
        for (int i = 0; i < n+1; i++) {
            for (int j = 0; j < n+1; j++) {
                if (i == j) b[i][j] = 0;
                else b[i][j] = VERYLARGE;
            }
        }

        while (m > 0) {
            if ((m & 1) != 0) {
                mul(b, aa);
            }
            mul(aa, aa);
            m = m >> 1;
            /*
            for (int i = 0; i <=n; i++) {
                System.out.println(Arrays.toString(aa[i]));
            }
            System.out.println();
            */
        }

        System.out.println(b[0][0]);
    }
}


//package codeforces;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class E {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(System.out);
    StringTokenizer stringTokenizer;

    String next() throws IOException {
        while (stringTokenizer == null || !stringTokenizer.hasMoreTokens()) {
            stringTokenizer = new StringTokenizer(reader.readLine());
        }
        return stringTokenizer.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    @SuppressWarnings("unchecked")
    void solve() throws IOException {
        int n = nextInt(), m = nextInt();
        int[] a = new int[n];
        for(int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        int[] b = new int[n];
        for(int i = 0; i < n; i++) {
            b[i] = nextInt();
        }
        int[][] f = new int[n + 1][n + 1];
        for(int i = 0; i <= n; i++) {
            int[][] dp = new int[n + 1][n + 1];
            for (int[] ints : dp) {
                Arrays.fill(ints, Integer.MAX_VALUE);
            }
            dp[0][i] = 0;
            for(int k = 0; k < n; k++) {
                for(int j = 0; j <= n; j++) {
                    if(dp[k][j] == Integer.MAX_VALUE) continue;
                    if(j - 1 >= 0) {
                        dp[k + 1][j - 1] = Math.min(dp[k + 1][j - 1], dp[k][j] + b[k]);
                    }
                    if(j + 1 <= n) {
                        dp[k + 1][j + 1] = Math.min(dp[k + 1][j + 1], dp[k][j] + a[k]);
                    }
                }
            }
            System.arraycopy(dp[n], 0, f[i], 0, dp[n].length);
        }
        final int[][] pow = pow(f, m);
        int ans = pow[0][0];
        writer.println(ans);
        writer.close();
    }

    int[][] mul(int[][] a, int[][] b) {
        int n = a.length;
        int[][] c = new int[n][n];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < n; j++) {
                c[i][j] = Integer.MAX_VALUE;
                for(int k = 0; k < n; k++) {
                    c[i][j] = (int)Math.min((long)c[i][j], (long)a[i][k] + b[k][j]);
                }
            }
        }
        return c;
    }

    int[][] pow(int[][] a, int k) {
        int n = a.length;
        int[][] result = new int[n][n];
        for (int[] ints : result) {
            Arrays.fill(ints, Integer.MAX_VALUE);
        }
        for(int i = 0; i < n; i++) {
            result[i][i] = 0;
        }
        while(k > 0) {
            if(k % 2 == 1) {
                result = mul(result, a);
            }
            a = mul(a, a);
            k /= 2;
        }
        return result;
    }

    public static void main(String[] args) throws IOException {
        new E().solve();
    }
}


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

public class CF {

	int MAX = 50;

	long[][] power(long n) {
		if (n == 0) {
			long[][] res = new long[MAX][MAX];
			for (int i = 0; i < MAX; i++)
				for (int j = 0; j < MAX; j++)
					if (i != j)
						res[i][j] = Long.MAX_VALUE / 3;
					else
						res[i][j] = 0;
			return res;
		} else {
			if (n == 1) {
				return resOne;
			} else {
				long[][] r1 = power(n / 2);
				long[][] r2 = mul(r1, r1);
				if (n % 2 == 1) {
					r2 = mul(r2, resOne);
				}
				return r2;
			}
		}
	}

	long[][] mul(long[][] a, long[][] b) {
		long[][] res = new long[MAX][MAX];
		for (int i = 0; i < MAX; i++)
			Arrays.fill(res[i], Long.MAX_VALUE / 3);
		for (int i = 0; i < MAX; i++)
			for (int j = 0; j < MAX; j++)
				for (int k = 0; k < MAX; k++)
					res[i][k] = Math.min(res[i][k], a[i][j] + b[j][k]);
		return res;
	}

	long[][] resOne = new long[MAX][MAX];

	void solve() {
		int n = in.nextInt();
		int m = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		int[] b = new int[n];
		for (int i = 0; i < n; i++)
			b[i] = in.nextInt();
		int cntHave = m;
		long[][] dx = new long[MAX][MAX];
		for (int i = 0; i < dx.length; i++)
			Arrays.fill(dx[i], Long.MAX_VALUE / 2);
		for (int st = 0; st < 1 << n; st++) {
			int curB = 0;
			int minB = 0;
			int cost = 0;
			for (int i = 0; i < n; i++)
				if (((1 << i) & st) == 0) {
					curB++;
					cost += a[i];
				} else {
					curB--;
					minB = Math.min(minB, curB);
					cost += b[i];
				}
			dx[25 + minB][25 + curB] = Math.min(dx[25 + minB][25 + curB], cost);
		}
		for (int i = 0; i < MAX; i++)
			Arrays.fill(resOne[i], Long.MAX_VALUE / 3);
		for (int i = 0; i < MAX; i++)
			for (int j = 0; j < MAX; j++) {
				int curB = 25 + (j - i);
				if (curB < 0 || curB >= MAX)
					continue;
				for (int sub = Math.max(0, 25 - i); sub < MAX; sub++)
					resOne[i][j] = Math.min(resOne[i][j], dx[sub][curB]);
			}

		long[][] res = power(cntHave);
		out.println(res[0][0]);
	}

	FastScaner in;
	PrintWriter out;

	void run() {
		in = new FastScaner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	void runWithFiles() {
		in = new FastScaner(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}

		solve();

		out.close();
	}

	public static void main(String[] args) {
		Locale.setDefault(Locale.US);
		new CF().run();
	}

	class FastScaner {
		BufferedReader br;
		StringTokenizer st;

		FastScaner(InputStream is) {
			br = new BufferedReader(new InputStreamReader(is));
		}

		FastScaner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class E {

	int pow(int a, int b, int p) {
		int ret = 1;
		for (; b > 0; b >>= 1) {
			if ((b & 1) == 1) {
				ret = (int) ((long) ret * a % p);
			}
			a = (int) ((long) a * a % p);
		}
		return ret;
	}

	int primitiveRoot(int p) {
		loop: for (int i = 2;; i++) {
			for (int j = 2; j * j <= p - 1; j++) {
				if ((p - 1) % j != 0) {
					continue;
				}
				if (pow(i, (p - 1) / j, p) == 1) {
					continue loop;
				}
				if (pow(i, j, p) == 1) {
					continue loop;
				}
			}
			return i;
		}
	}

	static final int C = 1000;

	int[] chirp(int[] a, int[] pz, int p) {
		int n = a.length;
		// pz[1] has order 2 * n modulo prime p

		a = a.clone();
		for (int i = 0; i < n; i++) {
			a[i] %= p;
		}

		int[] one = new int[n];
		for (int i = 0; i < n; i++) {
			one[i] = (int) ((long) a[i] * pz[(int) ((long)i * i % (2 * n))] % p);
		}

		int[] two = new int[2 * n - 1];
		for (int i = 0; i <= 2 * n - 2; i++) {
			two[i] = pz[(int) Math.floorMod(-(long)(n - 1 - i) * (n - 1 - i), 2 * n)];
		}

		int[] prod = mult(one, two, p);

		prod = Arrays.copyOfRange(prod, n - 1, 2 * n - 1);
		for (int i = 0; i < n; i++) {
			prod[i] = (int) ((long) prod[i] * pz[(int) ((long)i * i % (2 * n))] % p);
		}

		return prod;
		// returns polynomial a modulo p at points 1, rootZ^2, rootZ^4, ...
	}

	void submit() {
		int n = nextInt();
		int[] b = new int[n];
		int[] c = new int[n];

		for (int i = 0; i < n; i++) {
			b[i] = nextInt();
		}

		int[] initB = b.clone();

		b = makeInvPows(b);

		for (int i = 0; i < n; i++) {
			c[i] = nextInt();
		}

		int z, p;
		int[] pz;

		int[] fb;

		for (int i = 1;; i++) {
			p = 2 * n * i + 1;
			if (p < C) {
				continue;
			}
			if (!BigInteger.valueOf(p).isProbablePrime(30)) {
				continue;
			}
			z = pow(primitiveRoot(p), (p - 1) / (2 * n), p);
			pz = new int[2 * n];
			pz[0] = 1;
			for (int j = 1; j < pz.length; j++) {
				pz[j] = (int) ((long) pz[j - 1] * z % p);
			}

			fb = chirp(b, pz, p);
			boolean allGood = true;
			for (int coef : fb) {
				allGood &= coef != 0;
			}

			if (allGood) {
				break;
			}
		}

		int[] cc = new int[n];
		int inv2 = (p + 1) / 2;
		for (int i = 0; i < n; i++) {
			cc[i] = (c[(i + n - 1) % n] - c[i]) % p;
			if (cc[i] < 0) {
				cc[i] += p;
			}
			cc[i] = (int)((long)cc[i] * inv2 % p);
		}

		int[] fc = chirp(cc, pz, p);

		int[] fa = new int[n];
		for (int i = 0; i < n; i++) {
			fa[i] = (int)((long)fc[i] * pow(fb[i], p - 2, p) % p);
		}

		int[] aa = chirp(fa, makeInvPows(pz), p);
		int invN = pow(n, p - 2, p);
		for (int i = 0; i < n; i++) {
			aa[i] = (int)((long)aa[i] * invN % p);
		}

		long[] d = new long[n];
		for (int i = 1; i < n; i++) {
			d[i] = d[i - 1] + makeInt(aa[i], p);
		}

//		System.err.println(Arrays.toString(realAa));

		long A = n;
		long B = 0;
		long C = -c[0];
		for (int i = 0; i < n; i++) {
			long diff = initB[i] - d[i];
			B -= diff;
			C += diff * diff;
		}

//		System.err.println(A + " " + B + " " + C);

		List<Long> x0s = new ArrayList<>();

		long D = B * B - A * C;
		if (D < 0) {
		} else if (D == 0) {
			if ((-B % A) == 0) {
				x0s.add((-B) / A);
			}
		} else {
			long rd = (long) Math.sqrt(D);
			if (rd * rd == D) {
				if ((-B - rd) % A == 0) {
					x0s.add((-B - rd) / A);
				}
				if ((-B + rd) % A == 0) {
					x0s.add((-B + rd) / A);
				}
			}
		}

		out.println(x0s.size());
		for (long x0 : x0s) {
			for(int i = 0; i < n; i++) {
				out.print(d[i] + x0 + " ");
			}
			out.println();
		}

	}

	int makeInt(int x, int p) {
		return x < p / 2 ? x : x - p;
	}

	int[] makeInvPows(int[] a) {
		int[] b = new int[a.length];
		b[0] = a[0];
		for (int i = 1, j = a.length - 1; i < a.length; i++, j--) {
			b[i] = a[j];
		}
		return b;
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	E() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	// this version is more precise
	// but looks like it might be a bit slower
	// I should profile and optimize it some day...

	static int nextPowerOf2(int x) {
		return x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;
	}

	static class CompV {
		double[] re, im;

		void add(CompV o) {
			for (int i = 0; i < re.length; i++) {
				re[i] += o.re[i];
				im[i] += o.im[i];
			}
		}

		static CompV times(CompV a, CompV b) {
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			double[] re = new double[aRe.length];
			double[] im = new double[aRe.length];

			for (int i = 0; i < aRe.length; i++) {
				re[i] = aRe[i] * bRe[i] - aIm[i] * bIm[i];
				im[i] = aRe[i] * bIm[i] + aIm[i] * bRe[i];
			}

			return new CompV(re, im);
		}

		static CompV plus(CompV a, CompV b) {
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			double[] re = new double[aRe.length];
			double[] im = new double[aRe.length];

			for (int i = 0; i < aRe.length; i++) {
				re[i] = aRe[i] + bRe[i];
				im[i] = aIm[i] + bIm[i];
			}

			return new CompV(re, im);
		}

		/**
		 * @return a + bi
		 */
		static CompV packFFT(CompV a, CompV b) {
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			double[] re = new double[aRe.length];
			double[] im = new double[aRe.length];
			for (int i = 0; i < aRe.length; i++) {
				re[i] = aRe[i] - bIm[i];
				im[i] = aIm[i] + bRe[i];
			}
			return new CompV(re, im);
		}

		/**
		 * for real-valued a and b restores FFT(a) and FFT(b) from FFT(a + bi)
		 */
		void unpackFFT(CompV a, CompV b) {
			int n = re.length;
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			for (int i = 0; i < n; i++) {
				int j = i == 0 ? 0 : n - i;
				aRe[i] = (re[i] + re[j]) * 0.5;
				aIm[i] = (im[i] - im[j]) * 0.5;
				bRe[i] = (im[i] + im[j]) * 0.5;
				bIm[i] = (re[j] - re[i]) * 0.5;
			}
		}

		public CompV(double[] re, double[] im) {
			this.re = re;
			this.im = im;
		}

		public CompV(int len) {
			re = new double[len];
			im = new double[len];
		}
	}

	// !!!!
	// TEST WITH JUST ONE MULTIPLICATION
	public static int[] mult(int[] a, int[] b, int p) {
		int len = nextPowerOf2(a.length + b.length - 1);

		int k = (int) (Math.sqrt(p) + 1);
		int k2 = k * k % p;

		double[] p1 = new double[len];
		double[] q1 = new double[len];
		for (int i = 0; i < a.length; i++) {
			p1[i] = a[i] % k;
			q1[i] = a[i] / k;
		}

		double[] p2 = new double[len];
		double[] q2 = new double[len];
		for (int i = 0; i < b.length; i++) {
			p2[i] = b[i] % k;
			q2[i] = b[i] / k;
		}

		CompV p1p2Pack = new CompV(p1, p2);
		CompV q1q2Pack = new CompV(q1, q2);

		fft(p1p2Pack, false);
		fft(q1q2Pack, false);

		CompV fp1 = new CompV(len);
		CompV fp2 = new CompV(len);
		p1p2Pack.unpackFFT(fp1, fp2);

		CompV fq1 = new CompV(len);
		CompV fq2 = new CompV(len);
		q1q2Pack.unpackFFT(fq1, fq2);

		CompV back0 = CompV.times(fp1, fp2);

		CompV back1 = CompV.times(fp1, fq2);
		back1.add(CompV.times(fq1, fp2));

		CompV back2 = CompV.times(fq1, fq2);

		CompV back01 = CompV.packFFT(back0, back1);

		fft(back01, true);
		fft(back2, true);

		int[] ret = new int[len];

		for (int i = 0; i < len; i++) {
			long v0 = Math.round(back01.re[i]) % p;
			long v1 = Math.round(back01.im[i]) % p * k % p;
			long v2 = Math.round(back2.re[i]) % p * k2 % p;
			ret[i] = (int) ((v0 + v1 + v2) % p);
		}

		return ret;
	}

	public static void fft(CompV v, boolean invert) {
		double[] a = v.re;
		double[] b = v.im;
		int n = a.length;
		int shift = 32 - Integer.numberOfTrailingZeros(n);
		prepareArrays(32 - shift);
		int[] rev = rev2D[32 - shift];
		// System.err.println(n + " " + shift);
		for (int i = 1; i < n; i++) {
			int j = rev[i];
			if (i < j) {
				double temp = a[i];
				a[i] = a[j];
				a[j] = temp;
				temp = b[i];
				b[i] = b[j];
				b[j] = temp;
			}
		}

		// this shit looks awkward
		double multInv = invert ? -1 : 1;

		for (int len = 2, row = 0; len <= n; len <<= 1, row++) {
			int halfLen = len >> 1;
			double[] multReArr = powRe[row];
			double[] multImArr = powIm[row];
			for (int i = 0; i < n; i += len) {
				int toJ = i + halfLen;

				for (int j1 = i, j2 = toJ, k = 0; k < halfLen; j1++, j2++, k++) {
					double uA = a[j1];
					double uB = b[j1];

					double multRe = multReArr[k];
					double multIm = multImArr[k] * multInv;

					double vA = a[j2] * multRe - b[j2] * multIm;
					double vB = a[j2] * multIm + b[j2] * multRe;
					a[j1] = uA + vA;
					b[j1] = uB + vB;
					a[j2] = uA - vA;
					b[j2] = uB - vB;
				}
			}
		}
		if (invert) {
			for (int i = 0; i < n; i++) {
				a[i] /= n;
				b[i] /= n;
			}
		}
	}

	static double[][] powRe = { { 1 } };
	static double[][] powIm = { { 0 } };
	static int[][] rev2D = {};

	static void prepareArrays(int n) {

		if (rev2D.length < n + 1) {
			rev2D = Arrays.copyOf(rev2D, n + 1);
		}

		if (rev2D[n] == null) {
			int[] tmp = rev2D[n] = new int[1 << n];
			for (int i = 0; i < (1 << n); i++) {
				tmp[i] = tmp[i >> 1] >> 1;
				if ((i & 1) == 1) {
					tmp[i] |= 1 << (n - 1);
				}
			}
		}

		int oldN = powRe.length;

		if (oldN >= n) {
			return;
		}

		powRe = Arrays.copyOf(powRe, n);
		powIm = Arrays.copyOf(powIm, n);

		for (int i = oldN; i < n; i++) {

			double angle = Math.PI / (1 << i);

			double multRe = Math.cos(angle);
			double multIm = Math.sin(angle);

			double[] toRe = powRe[i] = new double[1 << i];
			double[] toIm = powIm[i] = new double[1 << i];

			double[] fromRe = powRe[i - 1];
			double[] fromIm = powIm[i - 1];

			for (int j = 0; j < 1 << (i - 1); j++) {

				double re = fromRe[j];
				double im = fromIm[j];

				toRe[j << 1] = re;
				toIm[j << 1] = im;
				toRe[(j << 1) | 1] = re * multRe - im * multIm;
				toIm[(j << 1) | 1] = re * multIm + im * multRe;
			}

			// System.err.println(Arrays.toString(toRe));
			// System.err.println(Arrays.toString(toIm));
		}
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new E();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class E_faster {

	int pow(int a, int b, int p) {
		int ret = 1;
		for (; b > 0; b >>= 1) {
			if ((b & 1) == 1) {
				ret = (int) ((long) ret * a % p);
			}
			a = (int) ((long) a * a % p);
		}
		return ret;
	}

	int primitiveRoot(int p) {
		loop: for (int i = 2;; i++) {
			for (int j = 2; j * j <= p - 1; j++) {
				if ((p - 1) % j != 0) {
					continue;
				}
				if (pow(i, (p - 1) / j, p) == 1) {
					continue loop;
				}
				if (pow(i, j, p) == 1) {
					continue loop;
				}
			}
			return i;
		}
	}

	static final int C = 5000;

	int[] chirp(int[] a, int[] pz, int p) {
		int n = a.length;
		// pz[1] has order 2 * n modulo prime p

		a = a.clone();
		for (int i = 0; i < n; i++) {
			a[i] %= p;
		}

		int[] one = new int[n];
		for (int i = 0; i < n; i++) {
			one[i] = (int) ((long) a[i] * pz[(int) ((long) i * i % (2 * n))] % p);
		}

		int[] two = new int[2 * n - 1];
		for (int i = 0; i <= 2 * n - 2; i++) {
			two[i] = pz[(int) Math.floorMod(-(long) (n - 1 - i) * (n - 1 - i),
					2 * n)];
		}

		int[] prod = mult(one, two, p);

		prod = Arrays.copyOfRange(prod, n - 1, 2 * n - 1);
		for (int i = 0; i < n; i++) {
			prod[i] = (int) ((long) prod[i]
					* pz[(int) ((long) i * i % (2 * n))] % p);
		}

		return prod;
		// returns polynomial a modulo p at points 1, rootZ^2, rootZ^4, ...
	}

	void submit() {
		int n = nextInt();
		int[] b = new int[n];
		int[] c = new int[n];

		for (int i = 0; i < n; i++) {
			b[i] = nextInt();
		}

		int[] initB = b.clone();

		b = makeInvPows(b);

		for (int i = 0; i < n; i++) {
			c[i] = nextInt();
		}

		int z, p;
		int[] pz;

		int[] fb;

		for (int i = 1;; i++) {
			p = 2 * n * i + 1;
			if (p < C) {
				continue;
			}
			if (!BigInteger.valueOf(p).isProbablePrime(30)) {
				continue;
			}
			z = pow(primitiveRoot(p), (p - 1) / (2 * n), p);
			pz = new int[2 * n];
			pz[0] = 1;
			for (int j = 1; j < pz.length; j++) {
				pz[j] = (int) ((long) pz[j - 1] * z % p);
			}

			fb = chirp(b, pz, p);
			boolean allGood = true;
			for (int coef : fb) {
				allGood &= coef != 0;
			}

			if (allGood) {
				break;
			}
		}

		int[] cc = new int[n];
		int inv2 = (p + 1) / 2;
		for (int i = 0; i < n; i++) {
			cc[i] = (c[(i + n - 1) % n] - c[i]) % p;
			if (cc[i] < 0) {
				cc[i] += p;
			}
			cc[i] = (int) ((long) cc[i] * inv2 % p);
		}

		int[] fc = chirp(cc, pz, p);

		int[] fa = new int[n];
		for (int i = 0; i < n; i++) {
			fa[i] = (int) ((long) fc[i] * pow(fb[i], p - 2, p) % p);
		}

		int[] aa = chirp(fa, makeInvPows(pz), p);
		int invN = pow(n, p - 2, p);
		for (int i = 0; i < n; i++) {
			aa[i] = (int) ((long) aa[i] * invN % p);
		}

		long[] d = new long[n];
		for (int i = 1; i < n; i++) {
			d[i] = d[i - 1] + makeInt(aa[i], p);
		}

		// System.err.println(Arrays.toString(realAa));

		long A = n;
		long B = 0;
		long C = -c[0];
		for (int i = 0; i < n; i++) {
			long diff = initB[i] - d[i];
			B -= diff;
			C += diff * diff;
		}

		// System.err.println(A + " " + B + " " + C);

		List<Long> x0s = new ArrayList<>();

		long D = B * B - A * C;
		if (D < 0) {
		} else if (D == 0) {
			if ((-B % A) == 0) {
				x0s.add((-B) / A);
			}
		} else {
			long rd = (long) Math.sqrt(D);
			if (rd * rd == D) {
				if ((-B - rd) % A == 0) {
					x0s.add((-B - rd) / A);
				}
				if ((-B + rd) % A == 0) {
					x0s.add((-B + rd) / A);
				}
			}
		}

		out.println(x0s.size());
		for (long x0 : x0s) {
			for (int i = 0; i < n; i++) {
				out.print(d[i] + x0 + " ");
			}
			out.println();
		}

	}

	int makeInt(int x, int p) {
		return x < p / 2 ? x : x - p;
	}

	int[] makeInvPows(int[] a) {
		int[] b = new int[a.length];
		b[0] = a[0];
		for (int i = 1, j = a.length - 1; i < a.length; i++, j--) {
			b[i] = a[j];
		}
		return b;
	}

	void preCalc() {

	}

	void stress() {

	}

	void test() {

	}

	E_faster() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		preCalc();
		submit();
		// stress();
		// test();
		out.close();
	}

	// this version is more precise
	// but looks like it might be a bit slower
	// I should profile and optimize it some day...

	static int nextPowerOf2(int x) {
		return x == 1 ? 1 : Integer.highestOneBit(x - 1) << 1;
	}

	static class CompV {
		double[] re, im;

		void add(CompV o) {
			for (int i = 0; i < re.length; i++) {
				re[i] += o.re[i];
				im[i] += o.im[i];
			}
		}

		static CompV times(CompV a, CompV b) {
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			double[] re = new double[aRe.length];
			double[] im = new double[aRe.length];

			for (int i = 0; i < aRe.length; i++) {
				re[i] = aRe[i] * bRe[i] - aIm[i] * bIm[i];
				im[i] = aRe[i] * bIm[i] + aIm[i] * bRe[i];
			}

			return new CompV(re, im);
		}

		static CompV plus(CompV a, CompV b) {
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			double[] re = new double[aRe.length];
			double[] im = new double[aRe.length];

			for (int i = 0; i < aRe.length; i++) {
				re[i] = aRe[i] + bRe[i];
				im[i] = aIm[i] + bIm[i];
			}

			return new CompV(re, im);
		}

		/**
		 * @return a + bi
		 */
		static CompV packFFT(CompV a, CompV b) {
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			double[] re = new double[aRe.length];
			double[] im = new double[aRe.length];
			for (int i = 0; i < aRe.length; i++) {
				re[i] = aRe[i] - bIm[i];
				im[i] = aIm[i] + bRe[i];
			}
			return new CompV(re, im);
		}

		/**
		 * for real-valued a and b restores FFT(a) and FFT(b) from FFT(a + bi)
		 */
		void unpackFFT(CompV a, CompV b) {
			int n = re.length;
			double[] aRe = a.re;
			double[] aIm = a.im;
			double[] bRe = b.re;
			double[] bIm = b.im;
			for (int i = 0; i < n; i++) {
				int j = i == 0 ? 0 : n - i;
				aRe[i] = (re[i] + re[j]) * 0.5;
				aIm[i] = (im[i] - im[j]) * 0.5;
				bRe[i] = (im[i] + im[j]) * 0.5;
				bIm[i] = (re[j] - re[i]) * 0.5;
			}
		}

		public CompV(double[] re, double[] im) {
			this.re = re;
			this.im = im;
		}

		public CompV(int len) {
			re = new double[len];
			im = new double[len];
		}
	}

	public static int[] mult(int[] a, int[] b, int p) {
		int len = nextPowerOf2(a.length + b.length - 1);

		double[] p1 = new double[len];
		for (int i = 0; i < a.length; i++) {
			p1[i] = a[i] % p;
		}

		double[] p2 = new double[len];
		for (int i = 0; i < b.length; i++) {
			p2[i] = b[i] % p;
		}

		CompV p1p2Pack = new CompV(p1, p2);

		fft(p1p2Pack, false);

		CompV fp1 = new CompV(len);
		CompV fp2 = new CompV(len);
		p1p2Pack.unpackFFT(fp1, fp2);

		CompV back0 = CompV.times(fp1, fp2);

		fft(back0, true);

		int[] ret = new int[len];

		for (int i = 0; i < len; i++) {
			long v0 = Math.round(back0.re[i]) % p;
			ret[i] = (int) (v0);
		}

		return ret;
	}

	public static void fft(CompV v, boolean invert) {
		double[] a = v.re;
		double[] b = v.im;
		int n = a.length;
		int shift = 32 - Integer.numberOfTrailingZeros(n);
		prepareArrays(32 - shift);
		int[] rev = rev2D[32 - shift];
		// System.err.println(n + " " + shift);
		for (int i = 1; i < n; i++) {
			int j = rev[i];
			if (i < j) {
				double temp = a[i];
				a[i] = a[j];
				a[j] = temp;
				temp = b[i];
				b[i] = b[j];
				b[j] = temp;
			}
		}

		// this shit looks awkward
		double multInv = invert ? -1 : 1;

		for (int len = 2, row = 0; len <= n; len <<= 1, row++) {
			int halfLen = len >> 1;
			double[] multReArr = powRe[row];
			double[] multImArr = powIm[row];
			for (int i = 0; i < n; i += len) {
				int toJ = i + halfLen;

				for (int j1 = i, j2 = toJ, k = 0; k < halfLen; j1++, j2++, k++) {
					double uA = a[j1];
					double uB = b[j1];

					double multRe = multReArr[k];
					double multIm = multImArr[k] * multInv;

					double vA = a[j2] * multRe - b[j2] * multIm;
					double vB = a[j2] * multIm + b[j2] * multRe;
					a[j1] = uA + vA;
					b[j1] = uB + vB;
					a[j2] = uA - vA;
					b[j2] = uB - vB;
				}
			}
		}
		if (invert) {
			for (int i = 0; i < n; i++) {
				a[i] /= n;
				b[i] /= n;
			}
		}
	}

	static double[][] powRe = { { 1 } };
	static double[][] powIm = { { 0 } };
	static int[][] rev2D = {};

	static void prepareArrays(int n) {

		if (rev2D.length < n + 1) {
			rev2D = Arrays.copyOf(rev2D, n + 1);
		}

		if (rev2D[n] == null) {
			int[] tmp = rev2D[n] = new int[1 << n];
			for (int i = 0; i < (1 << n); i++) {
				tmp[i] = tmp[i >> 1] >> 1;
				if ((i & 1) == 1) {
					tmp[i] |= 1 << (n - 1);
				}
			}
		}

		int oldN = powRe.length;

		if (oldN >= n) {
			return;
		}

		powRe = Arrays.copyOf(powRe, n);
		powIm = Arrays.copyOf(powIm, n);

		for (int i = oldN; i < n; i++) {

			double angle = Math.PI / (1 << i);

			double multRe = Math.cos(angle);
			double multIm = Math.sin(angle);

			double[] toRe = powRe[i] = new double[1 << i];
			double[] toIm = powIm[i] = new double[1 << i];

			double[] fromRe = powRe[i - 1];
			double[] fromIm = powIm[i - 1];

			for (int j = 0; j < 1 << (i - 1); j++) {

				double re = fromRe[j];
				double im = fromIm[j];

				toRe[j << 1] = re;
				toIm[j << 1] = im;
				toRe[(j << 1) | 1] = re * multRe - im * multIm;
				toIm[(j << 1) | 1] = re * multIm + im * multRe;
			}

			// System.err.println(Arrays.toString(toRe));
			// System.err.println(Arrays.toString(toIm));
		}
	}

	static final Random rng = new Random();

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

	public static void main(String[] args) throws IOException {
		new E_faster();
	}

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;

	String nextToken() {
		while (st == null || !st.hasMoreTokens()) {
			try {
				st = new StringTokenizer(br.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return st.nextToken();
	}

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	int nextInt() {
		return Integer.parseInt(nextToken());
	}

	long nextLong() {
		return Long.parseLong(nextToken());
	}

	double nextDouble() {
		return Double.parseDouble(nextToken());
	}
}