import static java.lang.Math.max;
import static java.lang.System.arraycopy;

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

public class B {

    static final int MOD = 1000000007;

    static int[][] color;
    static int r, c;
    static int colors;

    static int[] possibleMask;

    static int[][] haveLater;

    static long answer;

    static long[] factorial = new long[15];
    static {
        factorial[0] = 1;
        for (int i = 0; i < factorial.length - 1; i++) {
            factorial[i + 1] = factorial[i] * (i + 1);
        }
    }

    static int[] BITCOUNT;
    static {
        BITCOUNT = new int[1 << 12];
        for (int i = 0; i < BITCOUNT.length; i++) {
            BITCOUNT[i] = Integer.bitCount(i);
        }
    }

    static int allEquivalent;

    static void go(int sum, int col) {
        if (sum == r + c - 1) {
            int leftE = BITCOUNT[equivalentColorsMask];
            answer += factorial[allEquivalent] / factorial[leftE];
            return;
        }
        if (col == sum + 1 || col == c) {
            if (col < c) {
                possibleMask[col] = (1 << colors) - 1;
            }
            int[] wasMask = possibleMask.clone();
            for (int i = c - 1; i > 0; --i) {
                possibleMask[i] &= possibleMask[i - 1];
            }

            for (int i = c - 1; i >= 0; --i) {
                int row = sum - i;
                if (row < 0 || row >= r) {
                    continue;
                }
                possibleMask[i] &= ~(1 << color[row][i]);
                if (i < c - 1) {
                    possibleMask[i + 1] &= ~(1 << color[row][i]);
                }
            }

            // if (col < c) {
            // possibleMask[col] = possibleMask[col - 1];
            // }
            go(sum + 1, max(0, sum + 1 - (r - 1)));
            arraycopy(wasMask, 0, possibleMask, 0, c);
            return;
            // possibleMask = t;
        }
        int good = possibleMask[col] & ~haveLater[sum - col][col];

        int checkEquivalent = possibleMask[col] & equivalentColorsMask;
        int okCheckEquivalent = checkEquivalent == 0 ? -1 : Integer
                .numberOfTrailingZeros(checkEquivalent);

        int wasEquivalent = equivalentColorsMask;
        for (int i = 0; i < colors; i++) {
            if ((good & (1 << i)) == 0) {
                continue;
            }
            if (color[sum - col][col] >= 0 && color[sum - col][col] != i) {
                continue;
            }

            if (((1 << i) & checkEquivalent) != 0 && i != okCheckEquivalent) {
                continue;
            }

            int was = color[sum - col][col];
            color[sum - col][col] = i;

            equivalentColorsMask &= ~(1 << i);

            if (BITCOUNT[possibleMask[col]] >= (r + c - 2 - sum)) {
                go(sum, col + 1);
            }
            equivalentColorsMask = wasEquivalent;

            color[sum - col][col] = was;
        }
    }

    private static boolean check() {
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                for (int a = i; a < r; a++) {
                    for (int b = j; b < c; b++) {
                        if (a == i && b == j) {
                            continue;
                        }
                        if (color[a][b] == color[i][j]) {
                            return false;
                        }
                    }
                }
            }
        }
        return true;
    }

    static int equivalentColorsMask;

    static void solve() throws IOException {
        r = nextInt();
        c = nextInt();
        colors = nextInt();
        int length = r + c - 1;
        if (length > colors) {
            out.println(0);
            return;
        }
        color = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                color[i][j] = nextInt() - 1;
            }
        }
        // long time = currentTimeMillis();
        if (r < c) {
            swapRC();
        }
        answer = 0;
        possibleMask = new int[c];
        possibleMask[0] = (1 << colors) - 1;
        haveLater = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                haveLater[i][j] = 0;
                for (int a = i; a < r; a++) {
                    for (int b = j; b < c; b++) {
                        if (a == i && b == j) {
                            continue;
                        }
                        if (color[a][b] >= 0) {
                            haveLater[i][j] |= (1 << color[a][b]);
                        }
                    }
                }
            }
        }
        equivalentColorsMask = ~(haveLater[0][0]);
        if (color[0][0] >= 0) {
            equivalentColorsMask &= ~(1 << color[0][0]);
        }
        equivalentColorsMask &= (1 << colors) - 1;
        allEquivalent = Integer.bitCount(equivalentColorsMask);
        go(0, 0);
        long ans = answer;
        out.println(ans % MOD);
    }

    private static void swapRC() {
        int t = r;
        r = c;
        c = t;
        int[][] newCol = new int[r][c];
        for (int i = 0; i < r; i++) {
            for (int j = 0; j < c; j++) {
                newCol[i][j] = color[j][i];
            }
        }
        color = newCol;
    }

    static BufferedReader br;
    static StringTokenizer st;
    static PrintWriter out;

    public static void main(String[] args) throws IOException {
        InputStream input = System.in;
        PrintStream output = System.out;
        File file = new File("b.in");
        if (file.exists() && file.canRead()) {
            input = new FileInputStream(file);
        }
        br = new BufferedReader(new InputStreamReader(input));
        out = new PrintWriter(output);
        solve();
        out.close();
    }

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

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

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

    static String nextToken() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            String line = br.readLine();
            if (line == null) {
                return null;
            }
            st = new StringTokenizer(line);
        }
        return st.nextToken();
    }
}


import java.io.*; import java.util.*;
public class Graph {
    public static class Pair{
        int vtx; int val;
        public Pair(int a, int b){
            this.vtx=a; this.val=b;
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st=new StringTokenizer(br.readLine());
        int N=Integer.parseInt(st.nextToken());
        int M=Integer.parseInt(st.nextToken());
        ArrayList<Pair> arl[]=new ArrayList[N];
        for (int i = 0; i < N; i++) {
            arl[i]=new ArrayList<>();
        }
        int a,b,vv;
        for (int i = 0; i < M; i++) {
            st=new StringTokenizer(br.readLine());
            a=Integer.parseInt(st.nextToken())-1;
            b=Integer.parseInt(st.nextToken())-1;
            vv=Integer.parseInt(st.nextToken());
            arl[a].add(new Pair(b,2*vv)); arl[b].add(new Pair(a,2*vv));
        }
        boolean[] vis=new boolean[N];

        int[] m=new int[N];
        int[] c=new int[N];
        int done=0; int pt=0;
        while(done<N){
            while(pt<N && vis[pt]){
                pt++;
            }

            //Start DFS at pt, finish the component
            m[pt]=1; //b[pt]=0
            Queue<Integer> qu=new LinkedList<>();
            qu.add(pt); vis[pt]=true; done++;
            Queue<Integer> qu2=new LinkedList<>();//Tracks all vertices in the queue
            qu2.add(pt); boolean fix=false;
            while(!qu.isEmpty()){
                int v=qu.poll();
                for (Pair p : arl[v]) {
                    if(!vis[p.vtx]){
                        vis[p.vtx]=true; qu.add(p.vtx);
                        if(!fix){
                            qu2.add(p.vtx);
                        }
                        m[p.vtx]=-m[v]; c[p.vtx]=p.val-c[v]; done++;
                    }else{
                        if(m[p.vtx]==m[v] && m[v]!=0){
                            //m[p.vtx]x+c[p.vtx]+m[v]x+c[v] is known
                            int x=(p.val-c[p.vtx]-c[v])/(2*m[p.vtx]); fix=true;

                            for(int vtx: qu2){

                                c[vtx]+=m[vtx]*x; m[vtx]=0;
                            }
                        }else if(m[p.vtx]+m[v]==0){//m[v]=0
                            if(c[p.vtx]+c[v]!=p.val){
                                System.out.println("NO"); return;
                            }
                        }
                    }
                }
                //System.out.println(Arrays.toString(m));
                //System.out.println(Arrays.toString(c));
            }

            if(m[pt]!=0){//This component is not fixed
                ArrayList<Integer> arl2=new ArrayList<>();
                Queue<Integer> qu3=new LinkedList<>();
                for (int i : qu2) {
                    if(m[i]<0){
                        m[i]=-m[i]; c[i]=-c[i]; qu3.add(i);
                    }
                    arl2.add(c[i]);
                }
                Collections.sort(arl2);
                int med=arl2.get(arl2.size()/2);
                for (int i : qu2) {
                    c[i]-=med;

                }
                while(!qu3.isEmpty()){
                    int i=qu3.poll();
                    c[i]=-c[i];
                }
            }

        }
        System.out.println("YES");
        StringBuilder sb=new StringBuilder();
        for (int i = 0; i < N; i++) {
             sb.append((double)c[i]/2).append(" ");
        }
        System.out.println(sb.toString());
    }

}


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

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 * 6
 * 1 0
 * 0 0
 * 0 0
 * 1 1
 * 0 1
 * 1 1
 *
 * @author pttrung
 */
public class B {

    public static long mod = 1000000007;
    public static long[][][] dp;
 static int[] x = {0, 0, 1, -1, 1, -1, 1, -1};
        static int[] y = {1, -1, 0, 0, 1, -1, -1, 1};
    public static void main(String[] args) throws FileNotFoundException {
        PrintWriter out;

        Scanner in = new Scanner();
        //out = new PrintWriter(new FileOutputStream(new File("output.txt")));
        out = new PrintWriter(System.out);
        int[][] r = new int[2][2];
        int[] wk = new int[2];
        int[] bk = new int[2];
        for (int i = 0; i < 2; i++) {
            String line = in.next();
            r[i][0] = line.charAt(0) - 'a';
            r[i][1] = line.charAt(1) - '1';
        }
        String a = in.next();
        wk[0] = a.charAt(0) - 'a';
        wk[1] = a.charAt(1) - '1';
        a = in.next();
        bk[0] = a.charAt(0) - 'a';
        bk[1] = a.charAt(1) - '1';

        int[][] map = new int[8][8];
        map[r[0][0]][r[0][1]] = -1;
        map[r[1][0]][r[1][1]] = -1;
        map[wk[0]][wk[1]] = -1;
        update(r[0][0], r[0][1], map);
        update(r[1][0], r[1][1], map);
        updateK(wk[0], wk[1], map);
        if (map[bk[0]][bk[1]] != 1) {
            out.println("OTHER");
        } else {
            boolean found = false;
            for(int k = 0; k < x.length; k++){
                int i = x[k] + bk[0];
                int j = y[k] + bk[1];
                if(map[i][j] != 1){
                    found = true;
                    break;
                }
            }
            if(!found){
                out.println("CHECKMATE");
            }else{
                out.println("OTHER");
            }
        }

        out.close();
    }

    public static void updateK(int a, int b, int[][] map) {

        for (int k = 0; k < x.length; k++) {
            int i = a + x[k];
            int j = b + y[k];
            if (i >= 0 && i < 8 && j >= 0 && j < 8) {
                if (map[i][j] == 0) {
                    map[i][j] = 1;
                }
            }
        }
    }

    public static void update(int a, int b, int[][] map) {
        for (int i = b + 1; i < 8; i++) {
            if (map[a][i] == 0) {
                map[a][i] = 1;
            } else {
                break;
            }
        }
        for (int i = b - 1; i >= 0; i--) {
            if (map[a][i] == 0) {
                map[a][i] = 1;
            } else {
                break;
            }
        }
        for (int i = a + 1; i < 8; i++) {
            if (map[i][b] == 0) {
                map[i][b] = 1;
            } else {
                break;
            }
        }
        for (int i = a - 1; i >= 0; i--) {
            if (map[i][b] == 0) {
                map[i][b] = 1;
            } else {
                break;
            }
        }

    }

    public static long gcd(long a, long b) {
        if (b == 0) {
            return a;
        }
        return gcd(b, a % b);
    }

    public static Line getLine(Point a, Point b) {
        int c = (a.x - b.x);
        int d = (a.y - b.y);
        if (c == 0) {
            return new Line(1, 0, -a.x);
        } else if (d == 0) {
            return new Line(0, 1, -a.y);
        } else {
            double rate = (double) (-d) / c;

            double other = ((double) rate * a.x) + a.y;
            //System.out.println(a + "|" + b + ": " + rate + " " + other);
            return new Line(rate, 1, -other);
        }
    }

    public static class Line {

        double a, b, c;

        public Line(double a, double b, double c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

        @Override
        public int hashCode() {
            int hash = 7;
            hash = 47 * hash + (int) (Double.doubleToLongBits(this.a) ^ (Double.doubleToLongBits(this.a) >>> 32));
            hash = 47 * hash + (int) (Double.doubleToLongBits(this.b) ^ (Double.doubleToLongBits(this.b) >>> 32));
            hash = 47 * hash + (int) (Double.doubleToLongBits(this.c) ^ (Double.doubleToLongBits(this.c) >>> 32));
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Line other = (Line) obj;
            if (Double.doubleToLongBits(this.a) != Double.doubleToLongBits(other.a)) {
                return false;
            }
            if (Double.doubleToLongBits(this.b) != Double.doubleToLongBits(other.b)) {
                return false;
            }
            if (Double.doubleToLongBits(this.c) != Double.doubleToLongBits(other.c)) {
                return false;
            }
            return true;
        }

        @Override
        public String toString() {
            return a + " " + b + " " + c;
        }
    }

    static class FT {

        int[] data;

        FT(int n) {
            data = new int[n];
        }

        void update(int index, int val) {
            // System.out.println("UPDATE INDEX " + index);
            while (index < data.length) {
                data[index] += val;
                index += index & (-index);

                //    System.out.println("NEXT " +index);
            }
        }

        int get(int index) {
            //  System.out.println("GET INDEX " + index);
            int result = 0;
            while (index > 0) {
                result += data[index];
                index -= index & (-index);
                // System.out.println("BACK " + index);
            }
            return result;
        }
    }

    public static double dist(Point a, Point b) {
        double val = (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
        return Math.sqrt(val);
    }

    public static class Point {

        int x, y;

        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return x + " " + y;
        }
    }

    public static boolean nextPer(int[] data) {
        int i = data.length - 1;
        while (i > 0 && data[i] < data[i - 1]) {
            i--;
        }
        if (i == 0) {
            return false;
        }
        int j = data.length - 1;
        while (data[j] < data[i - 1]) {
            j--;
        }
        int temp = data[i - 1];
        data[i - 1] = data[j];
        data[j] = temp;
        Arrays.sort(data, i, data.length);
        return true;
    }

    public static long pow(int a, int b) {
        if (b == 0) {
            return 1;
        }
        if (b == 1) {
            return a;
        }
        long val = pow(a, b / 2);
        if (b % 2 == 0) {
            return val * val;
        } else {
            return val * val * a;
        }
    }

    public static long lcm(long a, long b) {
        return a * b / gcd(a, b);
    }

    static class Scanner {

        BufferedReader br;
        StringTokenizer st;

        public Scanner() throws FileNotFoundException {
            // System.setOut(new PrintStream(new BufferedOutputStream(System.out), true));
            br = new BufferedReader(new InputStreamReader(System.in));
            //  br = new BufferedReader(new FileReader(new File("output.txt")));
        }

        public String next() {

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

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

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

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

        public String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }

        public boolean endLine() {
            try {
                String next = br.readLine();
                while (next != null && next.trim().isEmpty()) {
                    next = br.readLine();
                }
                if (next == null) {
                    return true;
                }
                st = new StringTokenizer(next);
                return st.hasMoreTokens();
            } catch (Exception e) {
                throw new RuntimeException();
            }
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskF {
        public void solve(int testNumber, MyScan in, PrintWriter out) {
            int n = in.nextInt();
            String pos = in.next();
            int[][] auto = toAuto(pos);

            long[][][] state = new long[2 * n + 1][2 * n + 1][pos.length() + 1];
            long[][] ansFull = new long[2 * n + 1][2 * n + 1];

            for (int s = 0; s < n; s++) {
                long[][] starts = new long[2 * n + 1][2 * n + 1];
                starts[0][s] = 1;
                for (int len = 0; len < 2 * n; len++) {
                    for (int gand = 0; gand <= n; gand++) {
                        if (gand > 0) {
                            starts[len + 1][gand - 1] = (starts[len + 1][gand - 1] + starts[len][gand]) % Util._m;
                        }
                        starts[len + 1][gand + 1] = (starts[len + 1][gand + 1] + starts[len][gand]) % Util._m;
                    }
                }
                for (int r = 0; r <= 2 * n; r++) {
                    ansFull[r][s] = starts[r][0];
                }

            }

            state[0][0][0] = 1;
            long res = 0;
            for (int px = 0; px < 2 * n; px++) {
                for (int l = 0; l < 2 * n; l++) {
                    for (int s = 0; s < pos.length(); s++) {
                        int next0 = auto[s][0];
                        int next1 = auto[s][1];
                        // (
                        state[px + 1][l + 1][next0] = (state[px + 1][l + 1][next0] + state[px][l][s]) % Util._m;
                        // )
                        if (l > 0)
                            state[px + 1][l - 1][next1] = (state[px + 1][l - 1][next1] + state[px][l][s]) % Util._m;
                    }
                }
                for (int l = 0; l < 2 * n; l++) {
                    int l2 = 2 * n - px - 1;
                    int n2 = l;
                    if (state[px + 1][l][pos.length()] == 0 || n2 > l2) continue;
                    res += state[px + 1][l][pos.length()] * ansFull[l2][n2] % Util._m;
                }
            }
            out.println(res % Util._m);
        }

        private int[][] toAuto(String pos) {
            int[][] r = new int[pos.length()][2];

            String chars = "()";
            for (int t = 0; t < pos.length(); t++) {
                for (int i = 0; i < chars.length(); i++) {
                    char ch = chars.charAt(i);
                    if (pos.charAt(t) == ch) {
                        r[t][i] = t + 1;
                    } else {
                        String tar = pos.substring(0, t) + ch;
                        for (int l = t; l > 0; l--) {
                            if (tar.endsWith(pos.substring(0, l))) {
                                r[t][i] = l;
                                break;
                            }
                        }
                    }
                }
            }

            return r;
        }

    }

    static class MyScan {
        private final InputStream in;
        private byte[] inbuf = new byte[1024];
        public int lenbuf = 0;
        public int ptrbuf = 0;

        public MyScan(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (lenbuf == -1) throw new InputMismatchException();
            if (ptrbuf >= lenbuf) {
                ptrbuf = 0;
                try {
                    lenbuf = in.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (lenbuf <= 0) return -1;
            }
            return inbuf[ptrbuf++];
        }

        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }

        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }

        public String next() {
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while (!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }

        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }

            while (true) {
                if (b >= '0' && b <= '9') {
                    num = num * 10 + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }

    }

    static class Util {
        public static final long M07 = 1000_000_007;
        public static final long _m = M07;

    }
}


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

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

class TaskC {
    static final int BUBEN = 30;

    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        for (int i = 0; i < n; ++i) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < n; ++i) {
            b[i] = in.nextInt();
        }
        int[][] matr = new int[BUBEN][BUBEN];
        for (int[] x : matr)
            Arrays.fill(x, Integer.MAX_VALUE);
        for (int i = 0; i < BUBEN; ++i) matr[i][i] = 0;
        for (int j = 0; j < 2; ++j) {
            int[][] cm = new int[BUBEN][BUBEN];
            for (int[] x : cm)
                Arrays.fill(x, Integer.MAX_VALUE);
            for (int i = 0; i + 1 < BUBEN; ++i) {
                cm[i + 1][i] = b[j];
                cm[i][i + 1] = a[j];
            }
            matr = mul(matr, cm);
        }
        matr = pow(matr, m*n/2);
        out.println(matr[0][0]);
    }

    private int[][] pow(int[][] a, int k) {
        if (k == 0) {
            int[][] matr = new int[BUBEN][BUBEN];
            for (int[] x : matr)
                Arrays.fill(x, Integer.MAX_VALUE);
            for (int i = 0; i < BUBEN; ++i) matr[i][i] = 0;
            return matr;
        }
        if (k % 2 == 0)
            return pow(mul(a, a), k / 2);
        return mul(a, pow(a, k - 1));
    }

    private int[][] mul(int[][] a, int[][] b) {
        int[][] c = new int[BUBEN][BUBEN];
        for (int i = 0; i < BUBEN; ++i)
            for (int j = 0; j < BUBEN; ++j) {
                int mx = Integer.MAX_VALUE;
                for (int k = 0; k < BUBEN; ++k)
                    if (a[i][k] < Integer.MAX_VALUE && b[k][j] < Integer.MAX_VALUE) {
                        mx = Math.min(mx, a[i][k] + b[k][j]);
                    }
                c[i][j] = mx;
            }
        return c;
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        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.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.TreeSet;

public class myFile
{
	public static void main(String args[])
	{
	   Scanner sc = new Scanner(System.in);
	   int i,n,k,count=1;
	   TreeMap<Character,Integer> treeMap = new TreeMap<Character,Integer>();
	   for(char ch ='1';ch<='9';ch++)
	   {
		   treeMap.put(ch, count++);
	   }
	   while(sc.hasNextInt())
	   {
		   n = sc.nextInt();
		   k = sc.nextInt();
		   sc.nextLine();
		   String str = sc.nextLine();
		   if(n==1 && k==1)
		   {
			   System.out.println("0");
			   continue;
		   }
		   int index=0;
		   String ans="";
		   for(i=0;i<str.length();i++)
		   {
			   if(i==0 && str.charAt(i)>'1' && k>0)
			   {
				   index=i;
				   ans = ans+'1';
				   k--;
			   }
			   else if(i>0 && str.charAt(i)>'0' && k>0)
			   {
				   index=i;
				   ans = ans+'0';
				   k--;
			   }
			   else
				   ans=ans+str.charAt(i);
		   }

		   System.out.println(ans);
	   }

	}

}


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

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

    static class TaskE1 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int r = in.nextInt();
            int b = in.nextInt();

            TaskE1.Point[] ships = new TaskE1.Point[r];
            TaskE1.Point[] bases = new TaskE1.Point[b];
            for (int i = 0; i < r; i++) ships[i] = new TaskE1.Point(in.nextInt(), in.nextInt());
            for (int i = 0; i < b; i++) bases[i] = new TaskE1.Point(in.nextInt(), in.nextInt());

            if (r != b) {
                out.println("No");
                return;
            }

            //Arrays.sort(bases);
            //Arrays.sort(ships);

            for (int i = 1; i < r; i++) {
                if (doIntersect(ships[i - 1], bases[i - 1], ships[i], bases[i])) {
                    out.println("No");
                    return;
                }
            }

            out.println("Yes");
        }

        boolean onSegment(TaskE1.Point p, TaskE1.Point q, TaskE1.Point r) {
            if (q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) &&
                    q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y))
                return true;

            return false;
        }

        int orientation(TaskE1.Point p, TaskE1.Point q, TaskE1.Point r) {
            int val = (q.y - p.y) * (r.x - q.x) -
                    (q.x - p.x) * (r.y - q.y);

            if (val == 0) return 0;

            return (val > 0) ? 1 : 2;
        }

        boolean doIntersect(TaskE1.Point p1, TaskE1.Point q1, TaskE1.Point p2, TaskE1.Point q2) {
            int o1 = orientation(p1, q1, p2);
            int o2 = orientation(p1, q1, q2);
            int o3 = orientation(p2, q2, p1);
            int o4 = orientation(p2, q2, q1);

            if (o1 != o2 && o3 != o4)
                return true;

            if (o1 == 0 && onSegment(p1, p2, q1)) return true;

            if (o2 == 0 && onSegment(p1, q2, q1)) return true;

            if (o3 == 0 && onSegment(p2, p1, q2)) return true;

            if (o4 == 0 && onSegment(p2, q1, q2)) return true;

            return false;
        }

        static class Point implements Comparable<TaskE1.Point> {
            int x;
            int y;

            public Point(int x, int y) {
                this.x = x;
                this.y = y;
            }

            public int compareTo(TaskE1.Point o) {
                if (this.x != o.x)
                    return this.x - o.x;

                return this.y - o.y;
            }

        }

    }

    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.*;
import java.math.BigInteger;
import java.util.Collections.*;
import static java.lang.Math.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.util.Arrays.*;
import static java.math.BigInteger.*;

public class Main{

    void run(){
        Locale.setDefault(Locale.US);
        boolean my;
        try {
            my = System.getProperty("MY_LOCAL") != null;
        } catch (Exception e) {

            my = false;

        }
        try{
            err = System.err;
            if( my ){
                sc  = new FastScanner(new BufferedReader(new FileReader("input.txt")));
//                sc  = new FastScanner(new BufferedReader(new FileReader("C:\\myTest.txt")));
                out = new PrintWriter   (new FileWriter("output.txt"));
            }
            else {
                sc = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
                out = new PrintWriter(new OutputStreamWriter(System.out));
            }
//            out = new PrintWriter(new OutputStreamWriter(System.out));
        }catch(Exception e){
            MLE();
        }
        if( my )
            tBeg = System.currentTimeMillis();
        solve();
        if( my )
            err.println( "TIME: " + (System.currentTimeMillis() - tBeg ) / 1e3 );
        exit(0);
    }

    void exit( int val ){
        err.flush();
        out.flush();
        System.exit(val);
    }

    double tBeg;
    FastScanner sc;
    PrintWriter out;
    PrintStream err;

    class FastScanner{

        StringTokenizer st;
        BufferedReader br;

        FastScanner( BufferedReader _br ){
            br = _br;
        }

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

        String next(){
            while( st==null || !st.hasMoreElements() )
                st = new StringTokenizer(readLine());
            return st.nextToken();
        }

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

    void MLE(){
        int[][] arr = new int[1024*1024][]; for( int i = 0; i < 1024*1024; ++i ) arr[i] = new int[1024*1024];
    }

    void MLE( boolean doNotMLE ){ if( !doNotMLE ) MLE(); }

    void TLE(){
        for(;;);
    }

    public static void main(String[] args) {
        new Main().run();
//        new Thread( null, new Runnable() {
//            @Override
//            public void run() {
//                new Main().run();
//            }
//        }, "Lolka", 256_000_000L ).run();
    }

    ////////////////////////////////////////////////////////////////

    final int mod = (int)1e9 + 7;
    int n, k;
    Long[][] dp0, dp1;
    long[] pow2 = new long[1000];
    {
        pow2[0] = 1;
        for (int i = 1; i < pow2.length; i++) {
            pow2[i] = (pow2[i-1] * 2) % mod;
        }
    }

    void solve(){
        n = sc.nextInt();
        k = sc.nextInt();
        dp0 = new Long[k+1][n+1];
        for (Long[] val : dp0) fill(val, 0L);

        for (int sz = 1; sz <= n; sz++) {
            dp1  = new Long[k+1][n+1];

            for (int cnt  = 0; cnt <= k; cnt++) {
            for (int last = 0; last <= sz; last++) {
                if( cnt == 0 ){
                    if( last == 0 ) dp1[cnt][last] = 1L;
                    else dp1[cnt][last] = 0L;
                }
                else if( sz == last ){
                    if( cnt == 1 ){
                        dp1[cnt][last] = (pow2[last]-1);
                    }
                    else{
                        dp1[cnt][last] = 0L;
                        for (int l = 1; l <= sz - 1; l++) {
                            dp1[cnt][last] += dp1[cnt-1][l] * (pow2[sz-l]-1);
                        }
                    }
                }
                else{
                    dp1[cnt][last] = dp0[cnt][last] * pow2[last];
                }
                dp1[cnt][last] = ( dp1[cnt][last]%mod + mod ) % mod;
            }
            }
            //
            dp0 = dp1;
        }
        long ans = 0;
        for (int last = 0; last <= n; last++) {
            ans += dp0[k][last];
        }
        ans %= mod;
        out.println( ans );
    }

}


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

public class Main {

	static long[][][][] arr;
	static boolean[][][][] check;
	static int[] beads;

	public static void main(String[] args) throws java.lang.Exception {
		BufferedReader kek = new BufferedReader(new InputStreamReader(System.in));
		//Scanner skek = new Scanner(System.in);
		PrintWriter outkek = new PrintWriter(System.out);

		String[] input = kek.readLine().split(" ");
		int N = Integer.parseInt(input[0]);
		long M = Long.parseLong(input[1]);
		M++;

		beads = new int[N];
		arr = new long[N][N][2][2];
		check = new boolean[N][N][2][2];

		Arrays.fill(beads, -1);
		long temp1 = compute(0, N - 1, 0, 0);
		if(temp1 < M){
			//System.out.println(temp1);
			outkek.println(-1);
			outkek.close();
			return;
		}
		//System.out.println(temp1);

		beads[0] = 0;
		long temp;
		for(int i = 1; i < N; i++){
			//Arrays.fill(check, false); Default boolean value is false
			check = new boolean[50][50][2][2];
			beads[i] = 0;
			temp = compute(0, N - 1, 0, 0);
			if(temp < M){
				M -= temp;
				beads[i] = 1;
			}
		}

		for(int i = 0; i < N; i++){
			outkek.print(beads[i]);
		}

		kek.close();
		outkek.close();
	}

	static long compute(int L, int R, int reverse, int flip){
		if(L > R){
			return 1;
		}
		if(check[L][R][reverse][flip]){
			return arr[L][R][reverse][flip];
		}

		check[L][R][reverse][flip] = true;
		arr[L][R][reverse][flip] = 0;

		for(int i = 0; i < 2; i++)
			if(beads[L] == -1 || beads[L] == i)
				for(int j = 0; j < 2; j++)
					if(beads[R] == -1 || beads[R] == j)
						if((L < R || i == j) && (reverse == 1 || i <= j) && (flip == 1 || i <= 1 - j)){
							arr[L][R][reverse][flip] += compute(L + 1, R - 1, reverse == 1 || i < j ? 1 : 0, flip == 1 || i < 1 - j ? 1 : 0);
						}
		return arr[L][R][reverse][flip];
	}

}


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

public class Main {

    FastScanner in;
    PrintWriter out;

    Main () {
        in = new FastScanner(IO_Type.CONSOLE).getScanner();
        out = new FastWriter(IO_Type.CONSOLE).getWriter();

        //in = new FastScanner(IO_Type.TEST, "test.txt").getScanner();
        //out = new FastWriter(IO_Type.TEST, "result.txt").getWriter();

        //in = new FastScanner(IO_Type.FILE, "input.txt").getScanner();
        //out = new FastWriter(IO_Type.TEST, "output.txt").getWriter();
    }

    public static void main (String[]args) {
        Main task = new Main();
        task.solve();
        task.close();
    }

    public void close () {
        in.close();
        out.close();
    }

    public void solve () {
        int n = in.nextInt();
        System.out.println((int)(2*Math.pow(n + 1, 3) - 3));
    }

    public String getText(String s, int q) {
        String ss = "";
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) >= 'а' && s.charAt(i) <= 'я') {
                ss += (char)(s.charAt(i) + q);
            }
            else {
                ss += s.charAt(i);
            }
        }
        return ss;
    }

}

class Algebra {
    /****
     *       Number of co-prime numbers on [1, n].
     *       Number a is Co-prime if gcd (a, n) == 1
     *       O (sqrt(n))
     ****/
    public static int phi(int n) {
        int result = n;
        for (int i = 2; i*i <= n; ++i) {
            if (n % i == 0) {
                while (n % i == 0) {
                    n /= i;
                }
                result -= result / i;
            }
        }
        if (n > 1) {
            result -= result / n;
        }
        return result;
    }

    /****
     *       Raise number a to power of n.
     *       O (log n)
     ****/
    public static int binpow (int a, int n) {
        int res = 1;
        while (n != 0) {
            if ((n & 1) == 1)
                res *= a;
            a *= a;
            n >>= 1;
        }
        return res;
    }

    /****
     *       Finding the greatest common divisor of two numbers.
     *       O (log min(a, b))
     ****/
    public static int gcd (int a, int b) {
        return (b != 0) ? gcd (b, a % b) : a;
    }

    /****
     *       Finding the lowest common multiple of two numbers.
     *       O (log min(a, b))
     ****/
    public static int lcm (int a, int b) {
        return a / gcd (a, b) * b;
    }

    /****
     *       Eratosthenes Sieve of numbers - [0..n]. True - simple, False - not simple.
     *       O (n log log n)
     ****/
    public static boolean[] sieveOfEratosthenes (int n) {
        boolean [] prime = new boolean[n + 1];
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;
        for (int i=2; i<=n; ++i) {
            if (prime[i]) {
                if (i * 1L * i <= n) {
                    for (int j=i*i; j<=n; j+=i) {
                        prime[j] = false;
                    }
                }
            }
        }
        return prime;
    }
}

class IO_Type {

    public static String CONSOLE = "console";
    public static String FILE = "file";
    public static String TEST = "test";

}

class FastScanner {

    BufferedReader br;
    StringTokenizer st;

    FastScanner getScanner() {
        return this;
    }

    FastScanner(String type) {
        if (type.equals("console")) {
            FastScanner(System.in);
        }
    }

    FastScanner(String type, String inFileName) {
         if (type.equals("file")) {
             File f = new File(inFileName);
             try {
                 FastScanner(new FileInputStream(f));
             } catch (FileNotFoundException e) {
                 e.printStackTrace();
             }
         }
        else if (type.equals("test")) {
             File f = new File(inFileName);
             try {
                 FastScanner(new FileInputStream(f));
             } catch (FileNotFoundException e) {
                 e.printStackTrace();
             }
         }
    }

    void FastScanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(in));
    }

    String next() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                System.err.println(e);
                return "";
            }
        }
        return st.nextToken();
    }

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

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

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

    float nextFloat() {
        return Float.parseFloat(next());
    }
    BigInteger nextBigInt() {
        return new BigInteger(next());
    }

    void close() {
        try {
            br.close();
        }
        catch (IOException e) {
        }
    }
}

class FastWriter {

    PrintWriter pw;

    PrintWriter getWriter() {
        return pw;
    }

    FastWriter(String type) {
        FastWriter(type);
    }

    FastWriter (String type, String outFileName) {
        FastWriter(type, outFileName);
    }

    PrintWriter FastWriter(String type) {
        if (type.equals("console")) {
            pw = new PrintWriter(System.out);
        }
        return pw;
    }

    PrintWriter FastWriter(String type, String outFileName) {
        if (type.equals("console")) {
            pw = new PrintWriter(System.out);
        }
        else if (type.equals("test")) {
            try {
                pw = new PrintWriter(new File(outFileName));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        else if (type.equals("file")) {
            try {
                pw = new PrintWriter(new File(outFileName));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }
        return pw;
    }

}


import java.util.Scanner;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author teacher
 */
public class Color {
    public static void main(String[] args){
        Scanner  in = new Scanner(System.in);
        int x = in.nextInt();
        int y = in.nextInt();
        double dist = Math.sqrt(x*x+y*y);
        int r = (int)dist;
        if(Math.abs(r-dist)<0.0000001 || x==0 || y==0){
            System.out.println("black");
        } else{
            if((r%2+quadr(x,y))%2==1){
                System.out.println("black");
            }else {
                System.out.println("white");
            }
        }

    }

    static int quadr(int x,int y){
        if((x>0 && y>0)||(x<0 && y<0)){
            return 1;
        } else {
            return 0;
        }
    }

}


//package round302;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class E2FF {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		int n = ni();
		int m = ni();
		int[] a = na(n);
		long[] as = new long[n];
		for(int i = 0;i < n;i++){
			as[i] = (long)a[i]<<32|i;
		}
		Arrays.sort(as);

		int s = (int)Math.sqrt(n);
		// time split
		int[][] minblock = new int[n/s+1][];
		int[] imos = new int[n/s+2];
		for(int i = 0;i <= n;i++){
			if(i % s == 0){
				minblock[i/s] = Arrays.copyOf(imos, n/s+2);
				for(int j = 1;j <= n/s;j++){
					minblock[i/s][j] += minblock[i/s][j-1];
				}
			}

			if(i == n)break;
			if(0 > (int)as[i]-m+1){
				int l = Math.max(0, (int)as[i]-m+1);
				int r = (int)as[i];
				if(l/s <= r/s){
					imos[l/s]++;
					imos[r/s]--;
				}
			}else{
				int l = Math.max(0, (int)as[i]-m+1);
				int r = (int)as[i];
				if(l/s+1 <= r/s){
					imos[l/s+1]++;
					imos[r/s]--;
				}
			}
		}

		int[][] mininblock = new int[n/s+1][];
		int[][] wheninblock = new int[n/s+1][];
		for(int i = 0;i < n/s+1;i++){
			mininblock[i] = new int[2*s+1];
			wheninblock[i] = new int[2*s+1];
		}

		int[] map = new int[n];
		int[] ps = new int[n/s+1];
		for(int i = 0;i < n;i++){
			int l = Math.max(0, (int)as[i]-m+1);
			int r = (int)as[i];
			if(l/s == r/s){
				for(int j = l;j <= r;j++)map[j]++;

				int lmin = Integer.MAX_VALUE;
				for(int j = l/s*s;j < l/s*s+s && j < n;j++){
					if(map[j] < lmin){
						lmin = map[j];
					}
				}
				int clus = l/s;
				mininblock[clus][ps[clus]] = lmin;
				wheninblock[clus][ps[clus]] = i;
				ps[clus]++;
			}else{
				{
					for(int j = r/s*s;j <= r;j++)map[j]++;

					int lmin = Integer.MAX_VALUE;
					for(int j = r/s*s;j < r/s*s+s && j < n;j++){
						if(map[j] < lmin){
							lmin = map[j];
						}
					}
					int clus = r/s;
					mininblock[clus][ps[clus]] = lmin;
					wheninblock[clus][ps[clus]] = i;
					ps[clus]++;
				}
				if(0 <= (int)as[i]-m+1){
					for(int j = l;j < l/s*s+s;j++)map[j]++;

					int lmin = Integer.MAX_VALUE;
					for(int j = l/s*s;j < l/s*s+s && j < n;j++){
						if(map[j] < lmin){
							lmin = map[j];
						}
					}
					int clus = l/s;
					mininblock[clus][ps[clus]] = lmin;
					wheninblock[clus][ps[clus]] = i;
					ps[clus]++;
				}
			}
		}
		for(int i = 0;i <= n/s;i++){
			wheninblock[i] = Arrays.copyOf(wheninblock[i], ps[i]);
		}
		int[][][] bb = prepareFractionalCascading(wheninblock);

//		for(int i = 0;i < n/s+1;i++){
//			tr(i);
//			tr(Arrays.copyOf(mininblock[i], ps[i]));
//			tr(Arrays.copyOf(wheninblock[i], ps[i]));
//		}

		int ans = 0;
		int[] llimos = new int[s+1];
		int[] limos = new int[n/s+2];
		for(int Q = ni(); Q >= 1;Q--){
			int ql = ni()-1, qr = ni()-1, qx = ni()^ans;
			int time = -Arrays.binarySearch(as, ((long)qx<<32)-1)-1;
			Arrays.fill(limos, 0);
			for(int i = time/s*s;i < time;i++){
				if(0 > (int)as[i]-m+1){
					int l = Math.max(0, (int)as[i]-m+1);
					int r = (int)as[i];
					if(l/s <= r/s){
						limos[l/s]++;
						limos[r/s]--;
					}
				}else{
					int l = Math.max(0, (int)as[i]-m+1);
					int r = (int)as[i];
					if(l/s+1 <= r/s){
						limos[l/s+1]++;
						limos[r/s]--;
					}
				}
			}
			for(int i = 1;i < n/s+1;i++){
				limos[i] += limos[i-1];
			}
			for(int i = 0;i < n/s+1;i++){
				limos[i] += minblock[time/s][i];
			}
			ans = 999999999;

			if(ql/s == qr/s){
				Arrays.fill(llimos, 0);
				int clus = ql/s;
				for(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){
					int l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);
					int r = Math.min(s-1, (int)as[wheninblock[clus][j]]-clus*s);
					llimos[l]++;
					llimos[r+1]--;
				}
				for(int j = 1;j <= s;j++){
					llimos[j] += llimos[j-1];
				}
				for(int j = ql-clus*s;j <= qr-clus*s;j++){
					ans = Math.min(ans, limos[clus] + llimos[j]);
				}
			}else{
//				int[] mins = doFractionalCascading(bb[0], bb[1], ql/s+1, qr/s-1, time-1);

//				if(l > r)return new int[0];
//				int[] inds = new int[r-l+1];
//				int ub = upperBound(b[l], v);
//				inds[0] = ub == -1 ? -1 : bind[l][ub];
//				for(int i = l+1;i <= r;i++){
//					int ind = ub == -1 ? -1 : 2*(ub-bind[i-1][ub])-1;
//					ub = ind+1 < b[i].length && v >= b[i][ind+1] ? ind+1 : ind;
//					inds[i-l] = ub == -1 ? -1 : bind[i][ub];
//				}
//				return inds;
				if(ql/s+1 <= qr/s-1){
					int ub = upperBound(bb[0][ql/s+1], time-1);
					for(int i = ql/s+1;i < qr/s;i++){
	//					int xind = Arrays.binarySearch(wheninblock[i], time-1);
	//					if(xind < 0)xind = -xind-2;
						int lind = ub == -1 ? -1 : bb[1][i][ub];
						int xind = 2*(ub-lind)-1;
						ub = xind+1 < bb[0][i+1].length && time-1 >= bb[0][i+1][xind+1] ? xind+1 : xind;
//						int lind = mins[j];
						if(lind >= 0){
							ans = Math.min(ans, limos[i] + mininblock[i][lind]);
						}else{
							ans = Math.min(ans, limos[i]);
						}
					}
				}

				{
					int clus = ql/s;
					Arrays.fill(llimos, 0);
					for(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){
						int l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);
						int r = Math.min((int)as[wheninblock[clus][j]]-clus*s, s-1);
						llimos[l]++;
						llimos[r+1]--;
					}
					for(int j = 1;j <= s;j++){
						llimos[j] += llimos[j-1];
					}
					for(int j = ql-clus*s;j < s && j < n-clus*s;j++){
						ans = Math.min(ans, limos[clus] + llimos[j]);
					}
				}
				{
					int clus = qr/s;
					Arrays.fill(llimos, 0);
					for(int j = 0;j < ps[clus] && wheninblock[clus][j] < time;j++){
						int l = Math.max((int)as[wheninblock[clus][j]]-m+1-clus*s, 0);
						int r = Math.min((int)as[wheninblock[clus][j]]-clus*s, s-1);
						llimos[l]++;
						llimos[r+1]--;
					}
					for(int j = 1;j <= s;j++){
						llimos[j] += llimos[j-1];
					}
					for(int j = 0;j <= qr-clus*s;j++){
						ans = Math.min(ans, limos[clus] + llimos[j]);
					}
				}
			}

			out.println(ans);
		}
	}

	int[] doFractionalCascading(int[][] b, int[][] bind, int l, int r, int v)
	{
		if(l > r)return new int[0];
		int[] inds = new int[r-l+1];
		int ub = upperBound(b[l], v);
		inds[0] = ub == -1 ? -1 : bind[l][ub];
		for(int i = l+1;i <= r;i++){
			int ind = ub == -1 ? -1 : 2*(ub-bind[i-1][ub])-1;
			ub = ind+1 < b[i].length && v >= b[i][ind+1] ? ind+1 : ind;
			inds[i-l] = ub == -1 ? -1 : bind[i][ub];
		}
		return inds;
	}

	public static int upperBound(int[] a, int v)
	{
		int low = -1, high = a.length;
		while(high-low > 1){
			int h = high+low>>>1;
			if(a[h] <= v){
				low = h;
			}else{
				high = h;
			}
		}
		return low;
	}

	public int[][][] prepareFractionalCascading(int[][] a)
	{
		int n = a.length;
		int[][] b = new int[n][];
		int[][] bind = new int[n][];
		b[n-1] = a[n-1];
		bind[n-1] = new int[a[n-1].length];
		for(int i = 0;i < bind[n-1].length;i++)bind[n-1][i] = i;
		for(int i = n-2;i >= 0;i--){
			b[i] = new int[a[i].length + b[i+1].length/2];
			bind[i] = new int[a[i].length + b[i+1].length/2];
			int q = 1, r = 0;
			for(int p = 0;p < a[i].length;p++){
				while(q < b[i+1].length && b[i+1][q] < a[i][p]){
					b[i][r] = b[i+1][q];
					bind[i][r] = r-1 >= 0 ? bind[i][r-1] : -1;
					r++; q+=2;
				}
				b[i][r] = a[i][p];
				bind[i][r] = p;
				r++;
			}
			while(q < b[i+1].length){
				b[i][r] = b[i+1][q];
				bind[i][r] = r-1 >= 0 ? bind[i][r-1] : -1;
				r++; q+=2;
			}
			assert r == b[i].length;
		}
		return new int[][][]{b, bind};
	}

	void run() throws Exception
	{
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		tr(System.currentTimeMillis()-s+"ms");
	}

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

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte()
	{
		if(lenbuf == -1)throw new InputMismatchException();
		if(ptrbuf >= lenbuf){
			ptrbuf = 0;
			try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
			if(lenbuf <= 0)return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
	private int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }

	private double nd() { return Double.parseDouble(ns()); }
	private char nc() { return (char)skip(); }

	private String ns()
	{
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	private char[] ns(int n)
	{
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while(p < n && !(isSpaceChar(b))){
			buf[p++] = (char)b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	private char[][] nm(int n, int m)
	{
		char[][] map = new char[n][];
		for(int i = 0;i < n;i++)map[i] = ns(m);
		return map;
	}

	private int[] na(int n)
	{
		int[] a = new int[n];
		for(int i = 0;i < n;i++)a[i] = ni();
		return a;
	}

	private int ni()
	{
		int num = 0, b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private long nl()
	{
		long num = 0;
		int b;
		boolean minus = false;
		while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
		if(b == '-'){
			minus = true;
			b = readByte();
		}

		while(true){
			if(b >= '0' && b <= '9'){
				num = num * 10 + (b - '0');
			}else{
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	private boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	private void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.*;
import java.util.StringTokenizer;
import java.util.*;
import java.math.*;
import java.lang.Integer;

public class Solution {
	public static int max_sort(int arr[], int start, int end) {
		// System.out.println(start+" start "+end+" end");

		if (start >= end)
			return 1;
		boolean check_full = true;
		int m = start + (end - start) / 2;
		for (int i = start; i < end - 1; i++) {
			if (arr[i] <= arr[i + 1])
				check_full = true;
			else {
				check_full = false;
				break;
			}
		}
		if (check_full) {
			return end - start;
		} else {
			return Math.max(max_sort(arr, start, m), max_sort(arr, m, end));
		}
	}

	public static void useful_methods(int n, int arr[]) {

		Arrays.sort(arr);

		char charrr[] = new char[n];
		for (int i = 0; i < n; i++) {
			charrr[i] = '1';
		}
		String str = String.valueOf(charrr);

		String strr = str.substring(0, 1);

		char[] chs = str.toCharArray();

		char character = str.charAt(0);
		int ascii = (int) character;

		// Example: the max in an array among all elements divisible by 6.
		Arrays.stream(arr).filter(i -> i % 6 == 0).max();

		Integer.toString(65535, 2);

		BigInteger bigInt = BigInteger.valueOf(65535);
		bigInt.toByteArray();

		Integer.parseInt(number);
	}

	public static void main(String[] args) throws Exception {
		FastScanner cin = new FastScanner(System.in);

		int integer = cin.nextInt();

		String str = String.valueOf(integer);

		int n = Integer.parseInt(str.substring(0, str.length() - 3));
		int m = Integer.parseInt(str.substring(str.length() - 3, str.length()));

		int doubleF = 1;

		// int arr[] = new int[n];
		for (int i = n; i > 1; i = i - 2) {
			doubleF = doubleF * i;
		}

		System.out.println(doubleF % m);
	}

	public static void main(String[] args) throws Exception {
		FastScanner cin = new FastScanner(System.in);
		int n = cin.nextInt();
		int arr[]= new int[6];

		for (int i=0; i<6; i++){
			arr[i]=n%2;
			n=n/2;
		}

		int arrnew[]= new int[6];

		arrnew[0]=arr[1];
		arrnew[1]=arr[4];
		arrnew[2]=arr[2];
		arrnew[3]=arr[3];
		arrnew[4]=arr[5];
		arrnew[5]=arr[0];

		int nnew=0;
		for (int i=0; i<6; i++){
			nnew=nnew+arrnew[i]*(2^i);
		}

		System.out.println(nnew);
	}

	static class FastScanner {
		private BufferedReader reader = null;
		private StringTokenizer tokenizer = null;

		public FastScanner(InputStream in) {
			reader = new BufferedReader(new InputStreamReader(in));
			tokenizer = null;
		}

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

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

			return tokenizer.nextToken("\n");
		}

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

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

	}
}


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

public class E {
	FastScanner in;
	PrintWriter out;

	int[] cx = new int[] { 2, 1, -1, -2, -1, 1 };
	int[] cy = new int[] { 0, 2, 2, 0, -2, -2 };

	int[] dirx = new int[] { -1, -2, -1, 1, 2, 1 };
	int[] diry = new int[] { 2, 0, -2, -2, 0, 2 };

	long calc(long i) {
		return 3 * (i + 1) * i;
	}

	void solve() {
		long n = in.nextLong();
		if (n == 0) {
			out.println("0 0");
			return;
		}
		long l = 0, r = 1000 * 1000 * 1000;
		while (r - l > 1) {
			long m = (l + r) / 2;
			if (calc(m) < n) {
				l = m;
			} else {
				r = m;
			}
		}
		long i = l + 1;
		long cnt = calc(l);
	//	System.err.println("circle " + i);
		for (int j = 0; j < 6; j++) {
			if (cnt + i >= n) {
				long stx = cx[j] * i, sty = cy[j] * i;
				// System.out.println(stx + " " + sty);
				long num = n - cnt;
				long rx = stx + num * dirx[j], ry = sty + num * diry[j];
				out.println(rx + " " + ry);
				// System.out.println(num);
				return;
			}
			cnt += i;
		}
		return;
	}

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

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(in.br.readLine());
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class A {

	public static final int MOD = 1000000007;

	public static int poo(long b, int p) {
		long rt = 1;
		for(;p>0;p=p/2,b=b*b%MOD) if(p % 2 == 1) {
			rt = rt * b % MOD;
		}
		return (int) rt;
	}

	public static int calc(int x, int y) {
		if (y % x > 0) {
			return 0;
		} else {
			int sum = y / x;
			if(sum == 0) return 0;
			int ans = poo(2, sum - 1);
			//for(int i=2;i<=sum;i++) ans -= calc(i, sum);

			for(int i=2;((long) i) * i <= sum;i++) if(sum % i == 0){
				int lo = sum / i; int hi = i;
				ans -= calc(lo, sum);
				if(lo != hi) ans -= calc(hi, sum);
			}

			if(sum > 1) ans -= calc(sum, sum);

			return ans;
		}
	}

	public static void main(String[] args) throws IOException {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);

		int x = sc.nextInt();
		int y = sc.nextInt();

		pw.println(calc(x, y));

		pw.close();
		sc.close();
	}

}

class FastScanner {
	BufferedReader br;
	StringTokenizer st;

	public FastScanner(InputStream is) {
		br = new BufferedReader(new InputStreamReader(is));
		st = null;
	}

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

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

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

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

	public void close() throws IOException {
		br.close();
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.Arrays;
import java.util.List;
import java.util.StringTokenizer;
import java.util.function.*;
import java.util.stream.*;

public class E {

    private static final FastReader in = new FastReader();
    private static final FastWriter out = new FastWriter();

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

    private void run() {
        var t = 1;
        while (t-- > 0) {
            solve();
        }

        out.flush();
    }

    int n;
    int k;
    int mod = 998244353;

    private void solve() {
        n = in.nextInt();
        k = in.nextInt();

        if (k >= n) {
            out.println(0);
            return;
        }

        var f = new long[2][k + 1];
        f[1][0] = n;
        for (var i = 2; i <= n; i++) {
            var now = i % 2;
            var pre = (i - 1) % 2;
            for (var j = 0; j <= k; j++) {
                f[now][j] = (n - (i - 1) + j) * f[pre][j];
                if (j > 0) f[now][j] += (i - 1 - (j - 1)) * f[pre][j - 1];
                f[now][j] %= mod;
            }
        }

        var ans = f[n % 2][k];
        if (k > 0) ans = ans * 2 % mod;
        out.println(ans);

    }

}

class FastReader {

    private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer in;

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

    public BigDecimal nextBigDecimal() {
        return new BigDecimal(next());
    }

    public BigInteger nextBigInteger() {
        return new BigInteger(next());
    }

    public boolean nextBoolean() {
        return Boolean.valueOf(next());
    }

    public byte nextByte() {
        return Byte.valueOf(next());
    }

    public double nextDouble() {
        return Double.valueOf(next());
    }

    public double[] nextDoubleArray(int length) {
        var a = new double[length];
        for (var i = 0; i < length; i++) {
            a[i] = nextDouble();
        }
        return a;
    }

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

    public int[] nextIntArray(int length) {
        var a = new int[length];
        for (var i = 0; i < length; i++) {
            a[i] = nextInt();
        }
        return a;
    }

    public long nextLong() {
        return Long.valueOf(next());
    }

    public long[] nextLongArray(int length) {
        var a = new long[length];
        for (var i = 0; i < length; i++) {
            a[i] = nextLong();
        }
        return a;
    }

}

class FastWriter extends PrintWriter {

    public FastWriter() {
        super(System.out);
    }

    public void println(boolean[] a) {
        for (var i = 0; i < a.length; i++) {
            print(a[i]);
            print(i + 1 < a.length ? ' ' : '\n');
        }
    }

    public void println(double[] a) {
        for (var i = 0; i < a.length; i++) {
            print(a[i]);
            print(i + 1 < a.length ? ' ' : '\n');
        }
    }

    public void println(int[] a) {
        for (var i = 0; i < a.length; i++) {
            print(a[i]);
            print(i + 1 < a.length ? ' ' : '\n');
        }
    }

    public void println(long[] a) {
        for (var i = 0; i < a.length; i++) {
            print(a[i]);
            print(i + 1 < a.length ? ' ' : '\n');
        }
    }

    public void println(Object... a) {
        for (var i = 0; i < a.length; i++) {
            print(a[i]);
            print(i + 1 < a.length ? ' ' : '\n');
        }
    }

    public <T> void println(List<T> l) {
        println(l.toArray());
    }

    public void debug(String name, Object o) {
        String value = Arrays.deepToString(new Object[] { o });
        value = value.substring(1, value.length() - 1);
        System.err.println(name + " => " + value);
    }

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class FNezzarAndChocolateBars {
        static final int MAXN = 2048;
        static final int modulo = 998244353;

        public int add(int x, int y) {
            x += y;
            if (x >= modulo) x -= modulo;
            return x;
        }

        public int subtract(int x, int y) {
            x -= y;
            if (x < 0) x += modulo;
            return x;
        }

        public int multiply(int x, int y) {
            return (int) ((x * 1L * y) % modulo);
        }

        public int power(int x, long y) {
            int ans = 1;
            for (; y > 0; y >>= 1, x = (int) ((x * 1L * x) % modulo))
                if (y % 2 == 1) ans = (int) ((ans * 1L * x) % modulo);
            return ans;
        }

        public int inverse(int x) {
            return power(x, modulo - 2);
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int[] fact = new int[MAXN];
            int[] ifact = new int[MAXN];
            fact[0] = ifact[0] = 1;
            for (int i = 1; i < MAXN; i++) {
                fact[i] = multiply(fact[i - 1], i);
                ifact[i] = inverse(fact[i]);
            }
            int n = in.nextInt(), k = in.nextInt();
            int[] l = in.readIntArray(n);
            int[][][] dp = new int[2][MAXN / k][n + 1];
            dp[1][0][0] = 1;
            int s = 0;

            for (int p = 0; p < n; p++) {
                int L = l[p];
                int invL = inverse(L);
                int[] coeffs = new int[L / k + 1];
                int[] coeffs2 = new int[L / k + 1];
                for (int i = 0; i <= L / k; i++) {
                    if (k * i == L) continue;
                    int z = ifact[i];
                    if (i % 2 == 1) z = subtract(0, z);
                    coeffs[i] = multiply(z, power(L - k * i, i));

                    if (i >= 1) {
                        coeffs2[i] = multiply(z, multiply(i, power(L - k * i, i - 1)));
                    }
                }
                int r = p & 1;
                int h = r ^ 1;
                for (int i = 0; i <= s / k; i++) Arrays.fill(dp[r][i], 0);
                for (int i = 0; i <= s / k; i++)
                    for (int j = 0; j <= p; j++)
                        if (dp[h][i][j] != 0) {
                            int value = dp[h][i][j];
                            for (int t = 0; t <= L / k; t++) {
                                dp[r][i + t][j] = add(dp[r][i + t][j], multiply(value, coeffs[t]));
                                if (t > 0) {
                                    dp[r][i + t - 1][j + 1] = add(dp[r][i + t - 1][j + 1], multiply(value, coeffs2[t]));
                                }
                            }
                        }
                s += L;
            }
            int answer = 0;
            for (int i = 0; i <= s / k; i++)
                for (int r = 0; r <= n; r++) {
                    int value = dp[(n - 1) & 1][i][r];
                    int j = i + r;
                    if (j == 0) continue;
                    int temp = multiply(fact[i], inverse(power(k * j, i + 1)));
                    answer = add(answer, multiply(value, temp));
                }
            out.println(multiply(subtract(0, s), answer));
        }

    }

    static class InputReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private InputReader.SpaceCharFilter filter;

        public InputReader(InputStream stream) {
            this.stream = stream;
        }

        public int[] readIntArray(int size) {
            int[] array = new int[size];
            for (int i = 0; i < size; i++) {
                array[i] = readInt();
            }
            return array;
        }

        public int read() {
            if (numChars == -1) {
                throw new InputMismatchException();
            }
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if (numChars <= 0) {
                    return -1;
                }
            }
            return buf[curChar++];
        }

        public int nextInt() {
            int c = read();
            while (isSpaceChar(c)) c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public int readInt() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            int res = 0;
            do {
                if (c < '0' || c > '9') {
                    throw new InputMismatchException();
                }
                res *= 10;
                res += c - '0';
                c = read();
            } while (!isSpaceChar(c));
            return res * sgn;
        }

        public boolean isSpaceChar(int c) {
            if (filter != null) {
                return filter.isSpaceChar(c);
            }
            return isWhitespace(c);
        }

        public static boolean isWhitespace(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);

        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

        public OutputWriter(OutputStream outputStream) {
            writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
        }

        public OutputWriter(Writer writer) {
            this.writer = new PrintWriter(writer);
        }

        public void println(Object... objects) {
            for (int i = 0; i < objects.length; i++) {
                if (i != 0) {
                    writer.print(' ');
                }
                writer.print(objects[i]);
            }
            writer.print('\n');
        }

        public void close() {
            writer.close();
        }

    }
}


/*
    https://codeforces.com/contest/1146/problem/B
 */

import java.util.Scanner;

public class ForethoughtFutureCup2019ERD {
    private static long gcd = 1;
    private static long delta = 0;

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long m = scanner.nextLong();
        long a = scanner.nextLong();
        long b = scanner.nextLong();
        gcd = gcd(a, b);

        long sum = 0;

        for (long i = 0; i <= a + b - 1 && i <= m; i++) {
            sum += f(i, a, b);
        }
        if (m > a + b - 1) {
            if (gcd == 1) {
                sum += (a + b + m) * (m - a - b + 1) / 2;
            } else {
                for (long i = a + b; i <= m; i++) {
                    sum += i / gcd;
                }
            }
            sum += m - a - b + 1;
        }
        System.out.println(sum);
    }

    private static long f(long x, long a, long b) {
        if (x >= a + b - 1) {
            return 1 + x / gcd;
        } else {
            long result = 1;
            long pos = 0;
            while (true) {
                if (pos + a > x) {
                    pos -= b;
                    if (pos <= 0) {
                        return result;
                    } else {
                        result++;
                    }
                } else {
                    pos += a;
                    result++;
                }
            }
        }
    }

    private static long gcd(long a, long b) {
        while (b != 0) {
            long tmp = a % b;
            a = b;
            b = tmp;
        }
        return a;
    }

}


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

public class Main {

    BufferedReader reader;
    StreamTokenizer tokenizer;

    int nextInt() throws IOException {
        tokenizer.nextToken();
        return (int) tokenizer.nval;
    }

    String next() throws IOException {
        tokenizer.nextToken();
        return tokenizer.sval;
    }

    class Pair {
        int first;
        int second;

        Pair(int first, int second) {
            this.first = first;
            this.second = second;
        }
    }

    void run(boolean local) throws IOException {
        Scanner in = local ? new Scanner(new FileReader("input.txt")) : new Scanner(System.in);
        reader = local ? new BufferedReader(new FileReader("input.txt")) : new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(System.out);
        ArrayList<Integer> varIds = new ArrayList<>();
        String s = in.nextLine();
        int idx = s.indexOf(':');
        String s1 = s.substring(2, idx);
        while (s1.length() > 0 && s1.charAt(0)=='_') {
            int i = 0;
            int len = 0;
            while (i < s1.length() && s1.charAt(i)=='_') {
                len++;
                i++;
            }
            varIds.add(len);
            if (i!=s1.length())i++;
            s1 = s1.substring(i);
        }

        ArrayList<Pair> rels = new ArrayList<>();
        String s2 = s.substring(idx+2, s.length()-1);
        String []ar=s2.split(",");
        for(String rel : ar) {
            if (rel.contains("<")) {
                idx = rel.indexOf('<');
                int l = idx;
                int r = rel.length()-idx-1;
                rels.add(new Pair(l, r));
            } else {
                idx = rel.indexOf('>');
                int l = idx;
                int r = rel.length()-idx-1;
                rels.add(new Pair(r, l));
            }
        }

        boolean ok = true;
        int []res = new int[Collections.max(varIds)+1];
        while (true) {
            boolean changed = false;
            for(Pair p : rels) {
                if (res[p.first] >= res[p.second]) {
                    res[p.second]++;
                    if (res[p.second]==10) {
                        ok = false;
                    }
                    changed = true;
                    break;
                }
            }
            if (!changed) {
                break;
            }
            if (!ok) {
                break;
            }
        }
        if (!ok) {
            System.out.println("false");
        } else {
            for(int t : varIds) {
                out.print(res[t]);
            }
        }

        in.close();
        reader.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        new Main().run(args.length > 0 && args[0].equals("pqlocal"));
    }
}


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

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

    static class TaskF {
        int LEN;
        static final int DIGIT = 17;
        static int[] cnt = new int[DIGIT - 1];
        char[] res;
        int k;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            k = in.nextInt();
            int T = in.nextInt();
            Arrays.fill(cnt, T);

            if (k < 16) {
                out.println(getChar(k));
                return;
            }

            long[] counts = dp(13);
            LEN = getLength(counts, k);

            res = new char[LEN];

            int startIndex = brute();

            int[] curCount = new int[]{0};
            for (int i = 1; i <= LEN - startIndex; i++) {
                bruteForce(startIndex, cnt, res, i + startIndex, k, curCount);
            }

            out.println(res);
        }

        private int getLength(long[] counts, int k) {
            int LEN = 1;
            for (; LEN <= 13; LEN++) {
                if (LEN <= cnt[0] && k > counts[LEN] - 1) continue;
                else if (LEN > cnt[0] && k > counts[LEN]) continue;
                else break;
            }
            return LEN;
        }

        private int brute() {
            k -= dp(LEN)[LEN - 1];
            if (LEN - 1 <= cnt[0]) k++;
            for (int i = 0; i < LEN; i++) {
                int digit = getNextDigit(i == 0 ? 0 : -1);
                for (; digit < DIGIT - 1 && k > 0; digit = getNextDigit(digit)) {
                    cnt[digit]--;
                    int temp = (int) dp(LEN - i)[LEN - i - 1];
                    if (k > temp) {
                        k -= temp;
                        cnt[digit]++;
                        res[i] = getChar(digit);
                        continue;
                    } else if (k == temp) {
                        res[i++] = getChar(digit);
                        for (; i < LEN; i++) {
                            res[i] = getChar(getLastDigit());
                        }
                        return i;
                    } else {
                        res[i] = getChar(digit);
                        break;
                    }
                }
            }
            return LEN;
        }

        private void bruteForce(int index, int[] cnt, char[] res, int len, int max, int[] cur) {
            if (index == len) {
                cur[0]++;
                return;
            }
            for (int i = getNextDigit(index == 0 ? 0 : -1); i != 16; i = getNextDigit(i)) {
                cnt[i]--;
                if (cur[0] < max) {
                    res[index] = getChar(i);
                    bruteForce(index + 1, cnt, res, len, max, cur);
                    cnt[i]++;
                } else return;
            }
        }

        private int getNextDigit(int startDigit) {
            int i = startDigit + 1;
            for (; i < cnt.length && cnt[i] == 0; i++) ;
            return i;
        }

        private long[] dp(int len) {
            long[][] dp = new long[DIGIT][++len];
            dp[0][0] = 1;

            for (int i = 1; i < DIGIT; ++i) {
                for (int j = 0; j < len; ++j) {
                    for (int c = 0; c <= Math.min(j, cnt[i - 1]); c++) {
                        for (int k = i - 1; k < i; k++) {
                            dp[i][j] += dp[k][j - c] * comb(j, c);
                        }
                    }
                }
            }

//        System.out.printf("dp[15][%d]: ", len);   print(dp[DIGIT - 1]);

            return dp[DIGIT - 1];
        }

        private char getChar(int digit) {
            return (char) (digit < 10 ? '0' + digit : 'a' + digit - 10);
        }

        private int getLastDigit() {
            int i;
            for (i = cnt.length - 1; i >= 0 && cnt[i] == 0; i--) ;
            cnt[i]--;
            return i;
        }

        private long comb(int n, int k) {
            long res = 1L;
            if (k < n)
                for (int i = 1; i <= k; i++) {
                    res = res * (n - k + i) / i;
                }
            return res;
        }

    }

    static class InputReader extends BufferedReader {
        StringTokenizer tokenizer;

        public InputReader(InputStream inputStream) {
            super(new InputStreamReader(inputStream), 32768);
        }

        public InputReader(String filename) {
            super(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResourceAsStream(filename)));
        }

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

        public Integer nextInt() {
            return Integer.valueOf(next());
        }

    }
}


import java.io.*;
import java.lang.Math;
import java.util.*;

public class Main
{
	public BufferedReader in;
	public PrintStream out;

	public boolean log_enabled = false;

	static long[] primes;
	static int p_count;

	public static void get_primes(int n)
	{
		primes = new long[80000];

		boolean[] v = new boolean[n+1];
		int i,j;
		for (i=2; i<=n;i++)
		{
			v[i] = true;
		}

		for (i=2; i*i<=n;i++)
		{
			if (v[i])
			{
				for (j=i; i*j<=n; j++)
				{
					v[i*j]=false;
				}
			}
		}

		p_count = 0;
		for (i=2; i<=n; i++)
		{
			if (v[i])
			{
				primes[p_count++] = i;
			}
		}
	}

	int d_count;
	int[] d_index;
	long A;

	public int d_index(long x)
	{
		if ( (x<1000000) && (x*x<=A))
		{
			return d_index[(int)x];
		}
		else
		{
			return d_count - d_index[(int)(A/x)] - 1;
		}
	}

	public void test()
	{
		A = readLong();

		if (A==1)
		{
			out.println(1);
			return;
		}

		get_primes(1000000);

		long[] dividers = new long[10000];
		d_count = 0;

		d_index = new int[1000000];

		long[] use_primes = new long[10000];
		int use_p_count = 0;

		boolean[] p_used = new boolean[1000000];
		Arrays.fill(p_used, false);

		int i;
		for (i=1; i*i<=A; i++)
		{
			if (A % i == 0)
			{
				d_index[i] = d_count;
				dividers[d_count++] = i;
			}
		}

		for (i=0; i<d_count; i++)
		{
			dividers[2*d_count-i-1] = A / dividers[i];
		}

		d_count *= 2;

		long d;
		int p;
		boolean is_prime;

		for (i=1; i<d_count; i++)
		{
			is_prime = true;
			d = dividers[i]-1;

			if (d==1) continue;

			for ( p=0; p<p_count; p++)
			{
				if (primes[p]*primes[p] > d)
				{
					break;
				}

				if (d % primes[p] == 0)
				{
					is_prime = false;
					while (d % primes[p] == 0)
					{
						d /= primes[p];
					}
					if (d==1)
					{
						if (!p_used[(int)primes[p]])
						{
							p_used[(int)primes[p]] = true;
							use_primes[use_p_count++] = primes[p];
						}
					}
				}
			}

			if (is_prime)
			{
				if ((d > 1000000) || !p_used[(int)d])
				{
					if (d<1000000)
					{
						p_used[(int)d] = true;
					}
					use_primes[use_p_count++] = d;
				}
			}
		}

		logWrite("use_p_count = %d\n", use_p_count);

		long[] D = new long[d_count];
		long[] D1 = new long[d_count];

		Arrays.fill(D, 0);
		D[0] = 1;

		for (p=0; p<use_p_count; p++)
		{
			logWrite("P = %d\n", use_primes[p]);
			for (i=1; i<d_count; i++)
			{
				D1[i] = D[i];
				d = use_primes[p];
				while (d<dividers[i])
				{
					if (dividers[i] % (d+1) == 0)
					{

						//logWrite("D1[%d] += D[%d] = %d + %d  \n", i,  d_index(dividers[i] / (d+1)), D1[i], D[d_index(dividers[i] / (d+1))]);

						D1[i] += D[d_index(dividers[i] / (d+1))];
					}

					d *= use_primes[p];
				}
			}

			for (i=1; i<d_count; i++) D[i] = D1[i];
		}

		out.println(D[d_count-1]);
	}

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

			//in = new BufferedReader(new FileReader("in.txt"));
			//out = new PrintStream(new File("out.txt"));

		}
		catch (Exception e)
		{
			return;
		}

		//while (true)
		{
			//int t = readInt(); for (int i=0; i<t; i++)
			{
				test();
			}
		}
	}

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

	private StringTokenizer tokenizer = null;

	public int readInt()
	{
        return Integer.parseInt(readToken());
    }

    public long readLong()
	{
        return Long.parseLong(readToken());
    }

    public double readDouble()
	{
        return Double.parseDouble(readToken());
    }

	public String readLn()
	{
		try
		{
			String s;
			while ((s = in.readLine()).length()==0);
			return s;
		}
		catch (Exception e)
		{
			return "";
		}
	}

    public String readToken()
	{
		try
		{
			while (tokenizer == null || !tokenizer.hasMoreTokens())
			{
				tokenizer = new StringTokenizer(in.readLine());
			}
			return tokenizer.nextToken();
		}
		catch (Exception e)
		{
			return "";
		}
    }

	public int[] readIntArray(int n)
	{
		int[] x = new int[n];
		readIntArray(x, n);
		return x;
	}

	public void readIntArray(int[] x, int n)
	{
		for (int i=0; i<n; i++)
		{
			x[i] = readInt();
		}
	}

	public void logWrite(String format, Object... args)
	{
		if (!log_enabled)
		{
			return;
		}

		out.printf(format, args);
	}
}


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

/**
 * @author Don Li
 */
public class FindACar2 {

    int N = 31;
    int MOD = (int) 1e9 + 7;

    void solve() {
        int q = in.nextInt();
        while (q-- > 0) {
            int x1 = in.nextInt() - 1, y1 = in.nextInt() - 1, x2 = in.nextInt() - 1, y2 = in.nextInt() - 1, k = in.nextInt() - 1;

            long ans = 0;
            ans = add(ans, calc(x2, y2, k));
            ans = sub(ans, calc(x1 - 1, y2, k));
            ans = sub(ans, calc(x2, y1 - 1, k));
            ans = add(ans, calc(x1 - 1, y1 - 1, k));

            out.println(ans);
        }
    }

    int calc(int x, int y, int k) {
        if (x < 0 || y < 0) return 0;

        int[][][][] cnt = new int[N + 1][2][2][2];
        int[][][][] sum = new int[N + 1][2][2][2];

        int[] a = new int[N], b = new int[N], c = new int[N];
        for (int i = 0; i < N; i++) {
            a[i] = (x >> i) & 1;
            b[i] = (y >> i) & 1;
            c[i] = (k >> i) & 1;
        }
        reverse(a);
        reverse(b);
        reverse(c);

        cnt[0][1][1][1] = 1;
        for (int i = 0; i < N; i++) {
            for (int p = 0; p < 2; p++) for (int q = 0; q < 2; q++) for (int r = 0; r < 2; r++) {
                for (int u = 0; u < 2; u++) for (int v = 0; v < 2; v++) {
                    int w = u ^ v;
                    if (p == 1 && u == 1 && a[i] == 0) continue;
                    if (q == 1 && v == 1 && b[i] == 0) continue;
                    if (r == 1 && w == 1 && c[i] == 0) continue;
                    int np = p == 1 && a[i] == u ? 1 : 0;
                    int nq = q == 1 && b[i] == v ? 1 : 0;
                    int nr = r == 1 && c[i] == w ? 1 : 0;
                    cnt[i + 1][np][nq][nr] = add(cnt[i + 1][np][nq][nr], cnt[i][p][q][r]);
                    sum[i + 1][np][nq][nr] = add(sum[i + 1][np][nq][nr], sum[i][p][q][r]);
                    sum[i + 1][np][nq][nr] = add(sum[i + 1][np][nq][nr], mul(w << (30 - i), cnt[i][p][q][r]));
                }
            }
        }

        long res = 0;
        for (int p = 0; p < 2; p++) for (int q = 0; q < 2; q++) for (int r = 0; r < 2; r++) {
            res = add(res, sum[N][p][q][r]);
            res = add(res, cnt[N][p][q][r]);
        }
        return (int) res;
    }

    void reverse(int[] a) {
        int l = 0, r = a.length - 1;
        while (l < r) {
            int tmp = a[l];
            a[l] = a[r];
            a[r] = tmp;
            l++;
            r--;
        }
    }

    int add(long a, long b) {
        return (int) ((a + b) % MOD);
    }

    int sub(long a, long b) {
        return (int) ((a - b + MOD) % MOD);
    }

    int mul(long a, long b) {
        return (int) (a * b % MOD);
    }

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new FindACar2().solve();
        out.close();
    }

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

        public FastScanner(BufferedReader in) {
            this.in = in;
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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


import java.io.IOException;
import java.io.FilterInputStream;
import java.util.Iterator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;
import java.io.BufferedInputStream;
import java.io.InputStream;

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

class MagicTrick {
    public void solve(int testNumber, InputUtil in, PrintWriter out) {
        double n = in.nextInt();
        double m = in.nextInt();
        if (n * m == 1) {
            out.printf("%.1df\n", 1);
            return;
        }
        out.printf("%.12f\n", 1 / n + (n - 1) / n * (m - 1) / (n * m - 1));
    }
}

class InputUtil {

    JoltyScanner in;

    public InputUtil(InputStream istream) {
        in = new JoltyScanner(istream);
    }

    public String next() {
        return in.nextOrNull();
    }

    public int nextInt() {
        String s = next();
        if (s == null) {
            throw new NoSuchElementException("Attempted to read integer that is not there.");
        }
        return Integer.parseInt(s);
    }

}

class JoltyScanner {
    public static final int BUFFER_SIZE = 1 << 16;
	public static final char NULL_CHAR = (char) -1;

    BufferedInputStream in;
	StringBuilder str = new StringBuilder();
	byte[] buffer = new byte[BUFFER_SIZE];
	boolean EOF_FLAG = false;

    char c = NULL_CHAR;
	int bufferIdx = 0;
    int size = 0;

	public JoltyScanner(InputStream in) {
		this.in = new BufferedInputStream(in, BUFFER_SIZE);
	}

    public String next() {
		checkEOF();
		for (c = c == NULL_CHAR ? nextChar() : c; Character.isWhitespace(c); checkEOF()) {
			c = nextChar();
		}
		str.setLength(0);
		for (; !EOF_FLAG && !Character.isWhitespace(c); c = nextChar()) {
			str.append(c);
		}
		return str.toString();
	}

	public String nextOrNull() {
		try {
			return next();
		} catch (EndOfFileException e) {
			return null;
		}
	}

    public char nextChar() {
		if (EOF_FLAG) {
			return NULL_CHAR;
		}
		while (bufferIdx == size) {
			try {
				size = in.read(buffer);
				if (size == -1) {
					throw new Exception();
				}
			} catch (Exception e) {
				EOF_FLAG = true;
				return NULL_CHAR;
			}
			if (size == -1) {
				size = BUFFER_SIZE;
			}
			bufferIdx = 0;
		}
		return (char) buffer[bufferIdx++];
	}

    public void checkEOF() {
		if (EOF_FLAG) {
			throw new EndOfFileException();
		}
	}

	public class EndOfFileException extends RuntimeException {
	}
}