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 UnavoidableDetourForHome {

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

    void solve() {
        int n = in.nextInt();
        int[] d = new int[n];
        for (int i = 0; i < n; i++) d[i] = in.nextInt();

        long[][][][][] dp = new long[2][N][N][N][N];

        int cur = 0;
        dp[cur][d[0] == 2 ? 1 : 0][d[0] == 3 ? 1 : 0][d[1] == 2 ? 1 : 0][d[1] == 3 ? 1 : 0] = 1;

        for (int i = 2; i < n; i++) {
            int nxt = cur ^ 1;
            for (int p1 = 0; p1 <= n; p1++) {
                for (int p2 = 0; p2 <= n; p2++) {
                    for (int c1 = 0; c1 <= n; c1++) {
                        for (int c2 = 0; c2 <= n; c2++) {
                            dp[nxt][p1][p2][c1][c2] = 0;
                        }
                    }
                }
            }
            for (int p1 = 0; p1 <= n; p1++) {
                for (int p2 = 0; p1 + p2 <= n; p2++) {
                    for (int c1 = 0; c1 + p1 + p2 <= n; c1++) {
                        for (int c2 = 0; c1 + c2 + p1 + p2 <= n; c2++) {
                            long v = dp[cur][p1][p2][c1][c2];
                            if (v > 0) {
                                if (p1 == 0 && p2 == 0) {
                                    dp[cur][c1][c2][0][0] = add(dp[cur][c1][c2][0][0], v);
                                    continue;
                                }

                                for (int t = 0; t < 2; t++) {
                                    int ways = t == 0 ? p1 : p2;
                                    if (ways == 0) continue;
                                    if (t == 0) {
                                        p1--;
                                    } else {
                                        p2--; p1++;
                                    }
                                    if (d[i] == 2) {
                                        dp[nxt][p1][p2][c1 + 1][c2] = add(dp[nxt][p1][p2][c1 + 1][c2], v * ways);
                                        if (c1 > 0)
                                            dp[nxt][p1][p2][c1 - 1][c2] = add(dp[nxt][p1][p2][c1 - 1][c2], v * ways * c1);
                                        if (c2 > 0)
                                            dp[nxt][p1][p2][c1 + 1][c2 - 1] = add(dp[nxt][p1][p2][c1 + 1][c2 - 1], v * ways * c2);
                                    } else {

                                        dp[nxt][p1][p2][c1][c2 + 1] = add(dp[nxt][p1][p2][c1][c2 + 1], v * ways);
                                        if (c1 > 0)
                                            dp[nxt][p1][p2][c1][c2] = add(dp[nxt][p1][p2][c1][c2], v * ways * c1);
                                        if (c2 > 0)
                                            dp[nxt][p1][p2][c1 + 2][c2 - 1] = add(dp[nxt][p1][p2][c1 + 2][c2 - 1], v * ways * c2);
                                        if (c1 > 1)
                                            dp[nxt][p1][p2][c1 - 2][c2] = add(dp[nxt][p1][p2][c1 - 2][c2], v * ways * c1 * (c1 - 1) / 2);
                                        if (c2 > 1)
                                            dp[nxt][p1][p2][c1 + 2][c2 - 2] = add(dp[nxt][p1][p2][c1 + 2][c2 - 2], v * ways * c2 * (c2 - 1) / 2);
                                        if (c1 > 0 && c2 > 0)
                                            dp[nxt][p1][p2][c1][c2 - 1] = add(dp[nxt][p1][p2][c1][c2 - 1], v * ways * c1 * c2);
                                    }
                                    if (t == 0) {
                                        p1++;
                                    } else {
                                        p2++; p1--;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            cur = nxt;
        }

        out.println(dp[cur][0][0][0][0]);
    }

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

    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new UnavoidableDetourForHome().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());
        }
    }
}


//package round243;
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 E4F2 {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	/*
[[1, 0, 0, 0, 0]]
[[0, 8, 48, 56, 15]]
[[0, 0, 32, 192, 256]]
[[0, 0, 0, 64, 288]]
[[0, 0, 0, 0, 64]]	 *
	 */
	void solve()
	{
		int n = ni(), K = ni();
		int mod = 1000000007;
		BarrettInt bi = new BarrettInt(mod);
		int[][] dp = new int[K+1][n+1];
		long[] twos = new long[n+1];
		twos[0] = 1;
		for(int i = 1;i <= n;i++){
			twos[i] = twos[i-1] * 2;
			if(twos[i] >= mod)twos[i] -= mod;
		}

		dp[0][0] = 1;
		long BIG = (long)mod<<32;
		for(int end = 1;end <= n;end++){
			for(int k = Math.min(K, end-1);k >= 0;k--){
				long lsum = 0;
				for(int l = 0;l <= end-1;l++){
					if(dp[k][l] != 0){
						lsum += dp[k][l] * (twos[end]-twos[l]+mod);
						if(lsum >= BIG)lsum -= BIG;
//						dp[k][l] = (int)(dp[k][l] * twos[l] % mod);
						dp[k][l] = (int)bi.modh(dp[k][l] * twos[l]);
					}
				}
				if(k+1 <= K)dp[k+1][end] = (int)(lsum % mod);
			}
		}
//		for(int i = 0;i <= K;i++){
//			tr(dp[i]);
//		}
		long ret = 0;
		for(int j = 0;j <= n;j++){
			ret += dp[K][j];
		}
		out.println((int)bi.modh(ret));
	}

	public static class BarrettInt {
		public int mod;
		public long M;
		public int h;

		public BarrettInt(int mod)
		{
			this.mod = mod;
			long K = Integer.highestOneBit(mod)<<1;
			h = Long.numberOfTrailingZeros(K)*2;
			M = K*K/mod;
		}

		public long mod(long a)
		{
			long v = M*(a&mask);
			long bl = v&mask;
			v = (v>>>31) + M*(a>>>31);
			bl |= (v&mask)<<31;

			long q = bl>>>h|v>>>31<<62-h;
			long r = a-q*mod;
			return r < mod ? r : r-mod;
		}

		public long modh(long a)
		{
			long r = a-((M*(a&mask)>>>31)+M*(a>>>31)>>>h-31)*mod;
			return r < mod ? r : r-mod;
		}

		public long modl(long a)
		{
			long r = a-(M*a>>>h)*mod;
			return r < mod ? r : r-mod;
		}

		private static final long mask = (1L<<31)-1;
	}

	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 E4F2().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.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;

public class problemA implements Runnable{

    public void solve() throws IOException{
        int[] x=intArr();

        int x1=x[1]*x[3]*x[5];
        int x2=x[0]*x[2]*x[4];

        boolean ron=false;

        if(x1>x2 || (x2==0 && x1!=0)){
            ron=true;
        }else if(x1==0 && x2!=0) {
            ron=false;
        } else if(x[2]==0 && x[3]!=0){
            ron=true;
        } else if(x[0]==0 && x[1]!=0 && x[3]!=0){
            ron=true;
        }

        if(ron){
            out.println("Ron");
        } else {
            out.println("Hermione");
        }
    }

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

    @Override
    public void run(){
//      System.out.println("trying to solve");
        try{
            in=new BufferedReader(new InputStreamReader(stdin));
            out=new PrintWriter(stdout);
            solve();
            in.close();
            out.close();
        } catch (Exception ex){
            ex.printStackTrace();
            System.exit(1);
        }
    }

    BufferedReader in;
    PrintWriter out;

    int[] intArr() throws IOException {
        String[] arr=nextLine().split("\\s");
        int[] res=new int[arr.length];
        for(int i=0;i<arr.length;i++) res[i]=Integer.parseInt(arr[i]);
        return res;
    }

    long[] longArr() throws IOException {
        String[] arr=nextLine().split("\\s");
        long[] res=new long[arr.length];
        for(int i=0;i<arr.length;i++) res[i]=Long.parseLong(arr[i]);
        return res;
    }

    double[] doubleArr() throws IOException {
        String[] arr=nextLine().split("\\s");
        double[] res=new double[arr.length];
        for(int i=0;i<arr.length;i++) res[i]=Double.parseDouble(arr[i]);
        return res;
    }

    String nextLine() throws IOException {
        return in.readLine();
    }

    InputStream stdin;
    OutputStream stdout;
    public problemA(){
        stdin=System.in;
        stdout=System.out;
    }

    public problemA(InputStream stdin, OutputStream stdout){
        this.stdin=stdin;
        this.stdout=stdout;
    }
}


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

public class Main {
    void solve() {
        long MX=(long)1e18;
        long l=nl(),r=nl();
        if(l==MX && r==MX){
            pw.println("1");
            return;
        }
        long rr=r;

        if(rr==MX) rr--;
        a=convert(l);
        b=convert(rr);
      //  for(int i=0;i<18;i++) System.out.print(a[i]+" ");

        cc=new int[10];
        c=new int[10];
        generate(18,0);

       // pw.println(id);
//
//        for(int i=0;i<id;i++){
//            for(int j=0;j<10;j++) cc[j]=c[i][j];
//
//            if(go(0,1,1)) {
//                ans++;
//
//            }
//        }
//        Arrays.fill(cc,0);
        //cc[7]=18;
      //  pw.println(go(0,1,1));

      //  if(r==MX) ans++;
        pw.println(ans);
    }
    int a[],b[];
    int c[];
    int cc[];
    int id=0;
    int ans=0;
    boolean go(int i,int t1,int t2){
        if(i>=18) return true;
        int st=0,ed=9;

        if(t1==1 && t2==1){
             st=a[i]; ed=b[i];
           //  if(i==16) pw.println("YES"+" "+st+" "+ed);
             for(int j=st+1;j<ed;j++){

                 if(cc[j]>0){

                     return true;
                 }
             }

             if(st==ed){

                 if(cc[st]>0){
                     cc[st]--;
                     if(go(i+1,1,1)) return true;
                     cc[st]++;

                 }
             }else {
                 if(cc[st]>0){
                     cc[st]--;
                     if(go(i+1,1,0)) return true;
                     cc[st]++;
                 }
                 if(cc[ed]>0){
                     cc[ed]--;
                     if(go(i+1,0,1)) return true;

                     cc[ed]++;
                 }
             }

        }else if(t1==1){
            st=a[i];
            for(int j=st+1;j<=ed;j++){
                if(cc[j]>0) return true;
            }
            if(cc[st]>0){
                cc[st]--;
                if(go(i+1,1,0)) return true;
                cc[st]++;
            }

        }else if(t2==1){
            ed=b[i];
            for(int j=st;j<ed;j++) if(cc[j]>0) return true;
            if(cc[ed]>0){
                cc[ed]--;
                if(go(i+1,0,1)) return true;
                cc[ed]++;
            }
        }else {
            return true;
        }
        return false;
    }

    void generate(int i,int digit){

        if(i==0){

            for(int j=0;j<10;j++) cc[j]=c[j];

            if(go(0,1,1)) ans++;
            return;
        }
        if(digit>9) return;
        for(int j=0;j<=i;j++){
            c[digit]=j;
            generate(i-j,digit+1);
            c[digit]=0;

        }

    }
    int []convert(long n){
        int a[]=new int[18];
        int id=17;
        while(n>0){

            a[id]=(int)(n%10);
           // if(a[id]<0) System.out.println("YES");
            id--;
            n/=10;
        }
        return a;
    }

    long M=(long)1e9+7;
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    void run() throws Exception {
        is = INPUT.isEmpty() ? System.in : new ByteArrayInputStream(INPUT.getBytes());
        pw = new PrintWriter(System.out);
        long s = System.currentTimeMillis();
        solve();
        pw.flush();
        if(!INPUT.isEmpty())tr(System.currentTimeMillis()-s+"ms");

    }

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

    private byte[] inbuf = new byte[1024];
    public 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(INPUT.length() > 0)System.out.println(Arrays.deepToString(o)); }
}


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

public class Main {
    private static FastReader sc;
    private static PrintWriter out;

    public static void main( String[] args ) throws IOException {
        Locale.setDefault( Locale.US );
        Scanner in = new Scanner( System.in );
        sc = new FastReader();
        out = new PrintWriter( new BufferedOutputStream( System.out ));

        int n = in.nextInt();
        if( n == 1 ) {
            System.out.println( 3 );
            return;
        }
        System.out.println( n + 4 + n / 3 - 1 );
    }
}

class FastReader {
    BufferedReader bufferedReader;
    StringTokenizer str;

    public FastReader() {
        bufferedReader = new BufferedReader( new InputStreamReader( System.in ));
    }

    String next() throws IOException {
        while( str == null || !str.hasMoreElements()){
            try {
                str = new StringTokenizer( bufferedReader.readLine());
            } catch( IOException Error ) {
                Error.printStackTrace();
            }

        }
        return str.nextToken();
    }

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

    public int[] nextIntArr( int n ) throws IOException {
        int[] arr = new int[n];
        for( int i = 0; i < n; ++i ) {
            arr[i] = nextInt();
        }
        return arr;
    }

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

    public long[] nextLongArr( int n )throws IOException {
        long[] arr = new long[n];
        for( int i = 0; i < n; ++i ) {
            arr[i] = nextLong();
        }
        return arr;
    }

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

    String nextLine() throws IOException {
        String str = "";
        try {
            str = bufferedReader.readLine();
        } catch( IOException Error ) {
            Error.printStackTrace();
        }

        return str;
    }

    public char[] nextCharArr() throws IOException {
        return next().toCharArray();
    }
}


import java.io.BufferedReader;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Stack;

public class A {
	static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

    public static void main(String[] args) throws IOException {
    	String info[] = br.readLine().split(" ");
    	int x = Integer.parseInt(info[0]);
    	int y = Integer.parseInt(info[1]);
    	int z = Integer.parseInt(info[2]);
    	int t1 = Integer.parseInt(info[3]);
    	int t2 = Integer.parseInt(info[4]);
    	int t3 = Integer.parseInt(info[5]);

    	int caminata = t1*Math.abs(x-y);
    	int acensor = t2*Math.abs(x-y)+3*t3+t2*Math.abs(x-z);

    	if(caminata >= acensor) {
    		System.out.println("YES");
    	}else {
    		System.out.println("NO");
    	}

    }
}


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.util.InputMismatchException;
import java.io.IOException;
import java.io.Writer;
import java.io.OutputStreamWriter;
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);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        int INF = (int) 1e9;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.readInt();
            String s = in.next();
            int[][] VMEM = new int[n][], KMEM = new int[n][], OMEM = new int[n][];
            int VS = 0, KS = 0, OS = 0;
            for (int i = 0; i < n; i++) {
                int[] counts = {VS, KS, OS};
                if (s.charAt(i) == 'V') {
                    VMEM[VS] = counts;
                    VS++;
                } else if (s.charAt(i) == 'K') {
                    KMEM[KS] = counts;
                    KS++;
                } else {
                    OMEM[OS] = counts;
                    OS++;
                }
            }
            int[][][][] mem = new int[VS + 1][KS + 1][OS + 1][2];
            ArrayUtils.fill(mem, INF);
            mem[0][0][0][0] = 0;
            for (int V = 0; V <= VS; V++) {
                for (int K = 0; K <= KS; K++) {
                    for (int O = 0; O <= OS; O++) {
                        for (int lastV = 0; lastV < 2; lastV++) {
                            if (mem[V][K][O][lastV] == INF) continue;
                            if (V < VS) {
                                int[] count = VMEM[V];
                                int penalty = Math.abs(V - count[0]) + Math.abs(K - count[1]) + Math.abs(O - count[2]);
                                mem[V + 1][K][O][1] = Math.min(mem[V + 1][K][O][1], penalty + mem[V][K][O][lastV]);
                            }
                            if (K < KS && lastV == 0) {
                                int[] count = KMEM[K];
                                int penalty = Math.abs(V - count[0]) + Math.abs(K - count[1]) + Math.abs(O - count[2]);
                                mem[V][K + 1][O][0] = Math.min(mem[V][K + 1][O][0], penalty + mem[V][K][O][lastV]);
                            }
                            if (O < OS) {
                                int[] count = OMEM[O];
                                int penalty = Math.abs(V - count[0]) + Math.abs(K - count[1]) + Math.abs(O - count[2]);
                                mem[V][K][O + 1][0] = Math.min(mem[V][K][O + 1][0], penalty + mem[V][K][O][lastV]);
                            }
                        }
                    }
                }
            }
            out.printLine(Math.min(mem[VS][KS][OS][0], mem[VS][KS][OS][1]) / 2);
        }
    }
    static class ArrayUtils {
        public static void fill(int[][] array, int value) {
            for (int[] row : array) {
                Arrays.fill(row, value);
            }
        }

        public static void fill(int[][][] array, int value) {
            for (int[][] subArray : array) {
                fill(subArray, value);
            }
        }

        public static void fill(int[][][][] array, int value) {
            for (int[][][] subArray : array) {
                fill(subArray, value);
            }
        }
    }
    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 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 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 String readString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

        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 String next() {
            return readString();
        }

        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 close() {
            writer.close();
        }

        public void printLine(int i) {
            writer.println(i);
        }
    }
}


import java.util.Scanner;
public class Main {

    public static void main(String[] args) {
	    Scanner s = new Scanner(System.in);
	    long a = s.nextLong();
	    long b = s.nextLong();
	    long g = gcd(a,b);
	    long mul =0;
	    mul = (long)(a*b)/g;
	    long dasha = 0;
	    long masha = 0;
	    dasha = (mul-1)/a;
	    masha = (mul-1)/b;
	    if(a>b){
	        dasha++;
        }
	    else{
	        masha++;
        }
	    if(dasha>masha){
            System.out.println("Dasha");
        }
	    else if(masha >dasha){
            System.out.println("Masha");
        }
	    else{
            System.out.println("Equal");
        }
    }
    public static long gcd(long a,long b){
    	if(b==0){
    		return a;
		}
    	else{
    		return gcd(b,a%b);
		}
	}
}


import java.awt.Point;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.ObjectInputStream.GetField;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Hashtable;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import javax.sound.sampled.ReverbType;

public class N717 {
	static PrintWriter out;
	static Scanner sc;
	static ArrayList<int[]>q,w,x;
	static ArrayList<Integer>adj[];
	static HashSet<Integer>primesH;
	static boolean prime[];
	//static ArrayList<Integer>a;
	static HashSet<Long>tmp;
	static boolean[]v;
	static int[]a,b,c,d;
	static Boolean[][]dp;
	static char[][]mp;
	static int A,B,n,m,h,ans,sum;
	//static String a,b;
	static long oo=(long)1e9+7;
	public static void main(String[]args) throws IOException {
		sc=new Scanner(System.in);
		out=new PrintWriter(System.out);
		//A();
		//B();
		C();
		//D();
		//E();
		//F();
		//G();
		out.close();
	}
	  private static void A() throws IOException {
		  int t=ni();
		  while(t-->0) {
				int n=ni(),k=ni();
				a=nai(n);
				int sum=0;
				for(int i=0;i<n;i++)sum+=a[i];
				int total=sum;
				for(int i=0;i<n&&k>0;i++) {
					int sub=Math.min(k, a[i]);
					a[i]-=sub;
					sum-=sub;
					k-=sub;
				}
				a[n-1]+=total-sum;
				for(int i=0;i<n;i++)out.print(a[i]+" ");
				ol("");
		  }

	   }
		static void B() throws IOException {
			int t=ni();
			while(t-->0) {
				int n=ni();
				a=nai(n);
				boolean can=false,z=false;
				int x=0;
				int[]pre=new int[n],suf=new int[n];
				for(int i=0;i<n;i++) {
					x^=a[i];
					pre[i]=i==0?0:pre[i-1];
					pre[i]^=a[i];
				}
				for(int i=n-1;i>=0;i--) {
					suf[i]=i==n-1?0:suf[i+1];
					suf[i]^=a[i];
				}
				if(x==0) {
					out.println("YES");continue;
				}
				int id1=-1	,id2=-1;
				for(int i=0;i<n;i++) {
					if(pre[i]==x) {
						id1=i;break;
					}
				}
				for(int i=n-1;i>=0;i--) {
					if(suf[i]==x) {
						id2=i;break;
					}
				}
				out.println(id1+1<id2?"YES":"NO");
			}
		}

		static void C() throws IOException{
			 int t=1;
			 while(t-->0) {
				 int n=ni();
				 a=nai(n);
				 sum=0;
				 for(int i=0;i<n;i++)sum+=a[i];
				 if(sum%2==1) {
					 ol(0);
				 }else {
					 x=new ArrayList<int[]>();
					 for(int i=0;i<n;i++) {
						 x.add(new int[] {a[i],i});
					 }
					// Collections.sort(x,(u,v)->u[0]-v[0]);
					 ArrayList<Integer>ans=new ArrayList<Integer>();
					// while(x.size()>1) {
						 dp=new Boolean[x.size()][(sum/2) +1];
						 boolean can=dp(0,0);
						// if(!can)break;
						 if(!can) {
							 ol(0);continue;
						 }
						 int i=0;
						 for(;i<x.size();i++) {
							 if(x.get(i)[0]%2==1) {
								 break;
							 }
						 }
						 if(i<x.size()) {
							 ans.add(x.get(i)[1]);
						 }

						 for(i=0;i<x.size()&&ans.size()==0;i++) {
							 if((sum-x.get(i)[0])%2==1) {
								 ans.add(x.get(i)[1]);
								 can=false;
								 break;
							 }
						 }
						 if(ans.size()==0) {
							 i=0;
							 while(true) {
								 a[i]/=2;
								 if(a[i]%2==1) {
									 ans.add(i);break;
								 }
								 i=(i+1)%n;
							 }
						 }

					 //}
					 out.println(ans.size());
					 for(int x:ans)out.print((x+1)+" ");
					 ol("");
				 }

			 }
		}
		private static Boolean dp(int i, int j) {
			if(j>sum/2)return false;
			if(i==x.size()) {
				return sum/2==j;
			}
			if(dp[i][j]!=null)return dp[i][j];

			return dp[i][j]=dp(i+1,j+x.get(i)[0])||dp(i+1,j);
		}
		static boolean isPrime(long n) {
			if(n==2)return true;
			if(n<2||n%2==0)return false;

			for(long i=3L;i*i<n;i+=2l) {
				long rem=(n%i);
				if(rem==0)return false;
			}
			return true;
		}
		static void D() throws IOException {
			int t=ni();
			while(t-->0) {

			}
		}
		static int gcd (int a, int b) {
		    return b==0?a:gcd (b, a % b);
		}

	static void E() throws IOException {
		int t=ni();
		while(t-->0) {

		}

	}

	static void F() throws IOException {
		int t=ni();
		while(t-->0) {

		}
	}
	static void CC() throws IOException {
		for(int kk=2;kk<21;kk++) {
			ol(kk+"   -------");
		int n=kk;
		int k=n-2;
		int msk=1<<k;
		int[]a=new int[k];
		for(int i=0;i<a.length;i++)a[i]=i+2;
		int mx=1;
		int ms=0;
		for(int i=1;i<msk;i++) {
			long prod=1;
			int cnt=0;
			for(int j=0;j<a.length;j++) {
				if(((i>>j)&1)!=0) {
					prod*=a[j];
					cnt++;
				}
			}
			if(cnt>=mx&&prod%n==1) {
				mx=cnt;
				ms=i;
			}

		}
		ol(mx==1?mx:mx+1);
		out.print(1+" ");
		long pr=1;
		for(int j=0;j<a.length;j++) {
			if(((ms>>j)&1)!=0) {
				out.print(a[j]+" ");
				pr*=a[j];
			}
		}
		ol("");
		ol("Prod: "+pr);
		ol(n+"*"+((pr-1)/n)+" + "+1);
		}
	}
	static int ni() throws IOException {
		return sc.nextInt();
	}
	static double nd() throws IOException {
		return sc.nextDouble();
	}
	static long nl() throws IOException {
		return  sc.nextLong();
	}
	static String ns() throws IOException {
		return sc.next();
	}
	static int[] nai(int n) throws IOException {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextInt();
		return a;
	}
	static long[] nal(int n) throws IOException {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = sc.nextLong();
		return a;
	}
	static int[][] nmi(int n,int m) throws IOException{
		int[][]a=new int[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextInt();
			}
		}
		return a;
	}

	static long[][] nml(int n,int m) throws IOException{
		long[][]a=new long[n][m];
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				a[i][j]=sc.nextLong();
			}
		}
		return a;
	}
	static void o(String x) {
		out.print(x);
	}
	static void ol(String x) {
		out.println(x);
	}
	static void ol(int x) {
		out.println(x);
	}
	static void disp1(int []a) {
		for(int i=0;i<a.length;i++) {
			out.print(a[i]+" ");
		}
		out.println();
	}

	static class Scanner
	{
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}

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

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

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

		public String nextLine() throws IOException {return br.readLine();}

		public boolean ready() throws IOException {return br.ready(); }

	}
}


import java.util.Scanner;

public class Problem1042A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int m = in.nextInt();
        int maxK = 0, minK = 0;
        for (int i = 0; i < n; i++) {
            int temp = in.nextInt();
            if (maxK < temp) maxK = temp;
            minK += temp;
        }
        minK = (minK + m) % n == 0 ? (minK + m) / n : (minK + m) / n + 1;
        if (minK < maxK) minK = maxK;
        System.out.println(minK + " " + (maxK + m));
    }
}


import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
	    Scanner scanner = new Scanner(System.in);
        long a1 = scanner.nextLong();
        long b1 = scanner.nextLong();
        long a2 = scanner.nextLong();
        long b2 = scanner.nextLong();

        long twosCount1 = 0, threesCount1 = 0;
        long twosCount2 = 0, threesCount2 = 0;
        long x = a1 * b1;
        while (x % 2 == 0) {
            ++twosCount1;
            x /= 2;
        }
        while (x % 3 == 0) {
            ++threesCount1;
            x /= 3;
        }
        long remainder1 = x;

        x = a2 * b2;
        while (x % 2 == 0) {
            ++twosCount2;
            x /= 2;
        }
        while (x % 3 == 0) {
            ++threesCount2;
            x /= 3;
        }
        long remainder2 = x;

        if (remainder1 != remainder2) {
            System.out.println("-1");
            return;
        }

        long d2 = twosCount1 - twosCount2;
        long d3 = threesCount1 - threesCount2;

        long n = 0;
        n += Math.abs(d3);
        d2 += d3;
        n += Math.abs(d2);
        System.out.println(n);

        if (d3 > 0) {
            while (d3-- > 0) {
                if (a1 % 3 == 0)
                    a1 -= a1 / 3;
                else
                    b1 -= b1 / 3;
            }
        } else {
            d3 *= -1;
            while (d3-- > 0) {
                if (a2 % 3 == 0)
                    a2 -= a2 / 3;
                else
                    b2 -= b2 / 3;
            }
        }

        if (d2 > 0) {
            while (d2-- > 0) {
                if (a1 % 2 == 0)
                    a1 /= 2;
                else
                    b1 /= 2;
            }
        } else {
            d2 *= -1;
            while (d2-- > 0) {
                if (a2 % 2 == 0)
                    a2 /= 2;
                else
                    b2 /= 2;
            }
        }

        System.out.println(a1 + " " + b1);
        System.out.println(a2 + " " + b2);
    }
}


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

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

	Scanner in = new Scanner(System.in);
	PrintWriter out = new PrintWriter(System.out);
	void run(){
	    work();
	    out.flush();
	}
	void work() {
	    long r=in.nextLong();
	    long b=0;
	    for(;;b++){
	        long num=9*(long)Math.pow(10,(double)b)*(b+1);
	        if(r-num<=0){
	            break;
	        }
	        r-=num;
	    }
	    long base=(long)Math.pow(10,(double)b);
	    long c=(r-1)/(b+1);
	    int m=(int)((r-1)%(b+1));
	    base+=c;

	    String str=base+"";
	    out.println(str.charAt(m));
	}
}


import java.math.BigInteger;
import java.util.Scanner;

public class c_189 {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		long a=1;
		for (int i = 0; i < s.length()-1; i++)
			a=(a*2)%1000000007;
		BigInteger mod=new BigInteger("1000000007");
		BigInteger b=new BigInteger(s, 2);
		b=b.multiply(new BigInteger(a+""));
		b=b.mod(mod);
		System.out.println(b);
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Solution {
    public static void main(String[] args) throws IOException {
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        String[] input;
        char[][] board = new char[11][11];
        input = bufferedReader.readLine().split(" ");
        int rows = Integer.parseInt(input[0]);
        int columns = Integer.parseInt(input[1]);
        for(int i=0;i<rows;i++){
            String currentInput = bufferedReader.readLine();
            for(int j=0;j<currentInput.length();j++){
                board[i][j] = currentInput.charAt(j);
            }
        }
        Solver solver = new Solver();
        System.out.println(solver.solve(rows,columns,board));
        bufferedReader.close();
    }
}

class Solver {

    public int solve(int rows,int columns, char[][] board) {
        int allowedRows = rows;
        int allowedColumns = columns;
        for(int i=0;i<rows;i++){
            for(int j=0;j<columns;j++){
                if('S' == board[i][j]){
                    allowedRows--;
                    break;
                }
            }
        }
        for(int i=0;i<columns;i++){
            for(int j=0;j<rows;j++){
                if('S' == board[j][i]){
                    allowedColumns--;
                    break;
                }
            }
        }
        return allowedColumns*rows+allowedRows*columns-allowedColumns*allowedRows;
    }
}


import java.util.*;
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;

public class Main {
	public static int maxn = (int) (1e6 + 5);
	public static double PI = Math.acos(-1.0);
	public static double eps = 1e-6;
	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());
        }
    }
	public static int[] lf = new int[505];
	public static int[] rt = new int[505];
	public static int[] dt = new int[505];
	public static void main(String[] args) {
		InputStream inputStream = System.in;
        InputReader in = new InputReader(inputStream);
		int n = in.nextInt();
		String s = in.next();

		int mi = n, cnt = 0;
		for(int k = 0; k < n; ++k) {
			char chk = s.charAt(k);
			lf[k + 1] = lf[k];
			rt[k + 1] = rt[k];
			if(chk == '(') ++lf[k + 1];
			else ++rt[k + 1];
			dt[k + 1] = lf[k + 1] - rt[k + 1];
			if(dt[k + 1] < mi) {
				mi = dt[k + 1];
				cnt = 1;
			} else if(dt[k + 1] == mi) {
				++cnt;
			}
		}
		int ans = 0, l = 1, r = 1;
		if(lf[n] != rt[n]) {
			System.out.println(0);
			System.out.println(1 + " " + 1);
			return ;
		}
		if(cnt > ans) ans = cnt;
		for(int i = 0; i < n; ++i) {
			for(int j = i; j < n; ++j) {
				char chi = s.charAt(i);
				char chj = s.charAt(j);
				if(chi == chj) continue;
				lf[0] = 0; rt[0] = 0;
				mi = n; cnt = 0;
				for(int k = 0; k < n; ++k) {
					char chk = s.charAt(k);
					if(k == i || k == j) {
						if(chk == '(') chk = ')';
						else chk = '(';
					}
					lf[k + 1] = lf[k];
					rt[k + 1] = rt[k];
					if(chk == '(') ++lf[k + 1];
					else ++rt[k + 1];
					dt[k + 1] = lf[k + 1] - rt[k + 1];
					if(dt[k + 1] < mi) {
						mi = dt[k + 1];
						cnt = 1;
					} else if(dt[k + 1] == mi) {
						++cnt;
					}
				}
				if(cnt > ans) {
					ans = cnt;
					l = i + 1; r = j + 1;
				}
			}
		}
		System.out.println(ans);
		System.out.println(l + " " + r);
	}
}


    import java.util.*;
    public class div573{
    	public static void main(String sp[]){
    		Scanner sc = new Scanner(System.in);

    		String s1 = sc.next();
    		String s2 = sc.next();
    		String s3 = sc.next();

    		boolean a=false;
    		boolean b=false;
    		int s=0;
    		int m=0;
    		int p=0;
    		int arr[] =  new int[10];

    		int val1 = (int)s1.charAt(0)-48;
    		int val2 = (int)s2.charAt(0)-48;
    		int val3 = (int)s3.charAt(0)-48;
    		if(s1.charAt(1)=='s')
    			s++;
    		if(s1.charAt(1)=='m')
    			m++;
    		if(s1.charAt(1)=='p')
    			p++;
    		if(s2.charAt(1)=='s')
    			s++;
    		if(s2.charAt(1)=='m')
    			m++;
    		if(s2.charAt(1)=='p')
    			p++;
    		if(s3.charAt(1)=='s')
    			s++;
    		if(s3.charAt(1)=='m')
    			m++;
    		if(s3.charAt(1)=='p')
    			p++;
    		if((s==3 || m==3 || p==3) && ((val1==val2) && (val2==val3))){
    			System.out.println("0");
    			return;
    		}
    		ArrayList<Integer> al = new ArrayList<>();
    		al.add(val1);
    		al.add(val2);
    		al.add(val3);
    		Collections.sort(al);
    		if(((al.get(0)+1)==al.get(1) && (al.get(1)+1)==al.get(2)) &&(s==3 || p==3 || m==3)){
    			System.out.println("0");
    			return;
    		}

    		HashMap<String,Integer> hm = new HashMap<>();
    		if(!hm.containsKey(s1))
    			hm.put(s1,1);
    		else hm.put(s1,hm.get(s1)+1);

    		if(!hm.containsKey(s2))
    			hm.put(s2,1);
    		else hm.put(s2,hm.get(s2)+1);

    		if(!hm.containsKey(s3))
    			hm.put(s3,1);
    		else hm.put(s3,hm.get(s3)+1);

    		int ans1 = 3-(Math.max(hm.get(s1),Math.max(hm.get(s2),hm.get(s3))));
    		int p1[] = new int[11];
    		if(s1.charAt(1)=='p')
    		p1[val1]=1;
    		if(s2.charAt(1)=='p')
    		p1[val2]=1;
    		if(s3.charAt(1)=='p')
    		p1[val3]=1;
    		int ansa1 = 3;
    		for(int i=1;i<=7;i++){
    			int count=0;
    			for(int j=i;j<=i+2;j++){
    				if(p1[j]==1)
    					count++;
    			}
    			ansa1 = Math.min(ansa1,3-count);
    		}

    		int m1[] = new int[11];
    		if(s1.charAt(1)=='m')
    		m1[val1]=1;
    		if(s2.charAt(1)=='m')
    		m1[val2]=1;
    		if(s3.charAt(1)=='m')
    		m1[val3]=1;
    		int ansa2 = 3;
    		for(int i=1;i<=7;i++){
    			int count=0;
    			for(int j=i;j<=i+2;j++){
    				if(m1[j]==1)
    					count++;
    			}
    			ansa2 = Math.min(ansa2,3-count);
    		}

    		int d1[] = new int[11];
    		if(s1.charAt(1)=='s')
    		d1[val1]=1;
    		if(s2.charAt(1)=='s')
    		d1[val2]=1;
    		if(s3.charAt(1)=='s')
    		d1[val3]=1;
    		int ansa3 = 3;
    		for(int i=1;i<=7;i++){
    			int count=0;
    			for(int j=i;j<=i+2;j++){
    				if(d1[j]==1)
    					count++;
    			}
    			ansa3 = Math.min(ansa3,3-count);
    		}
    		int ans2=0;
    		ans2 = Math.min(ansa1,Math.min(ansa2,ansa3));
    		System.out.println(Math.min(ans2,ans1));

    	}
    }


import java.util.Arrays;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.List;
import java.math.BigInteger;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Comparator;
import java.io.IOException;
import java.util.StringTokenizer;

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

class TaskA {
    Scanner in;
    PrintWriter out;

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        this.in = in;
        this.out = out;
        run();
    }

    void run() {
        int m = in.nextInt();
        int h1 = in.nextInt();
        int a1 = in.nextInt();
        int x1 = in.nextInt();
        int y1 = in.nextInt();
        int h2 = in.nextInt();
        int a2 = in.nextInt();
        int x2 = in.nextInt();
        int y2 = in.nextInt();
        int s0 = get0(m, h1, a1, x1, y1);
        int s1 = get1(m, a1, x1, y1);
        int t0 = get0(m, h2, a2, x2, y2);
        int t1 = get1(m, a2, x2, y2);
        Algo.debug(s0, s1, t0, t1);
        if (s0 == -1 || t0 == -1) {
            out.println(-1);
            return ;
        }
        if (s1 == -1 && t1 == -1) {
            out.println(s0 == t0 ? s0 : -1);
            return ;
        }
        if (s1 == -1 || t1 == -1) {
            if (s1 == -1) {
                out.println(s0 >= t0 && (s0 - t0) % t1 == 0 ? s0 : -1);
            } else {
                out.println(t0 >= s0 && (t0 - s0) % s1 == 0 ? t0 : -1);
            }
            return ;
        }
//        long[] res = Num.congruence(new long[] { 1, 1 }, new long[] { s0, t0 }, new long[] { s1, t1 });
//        if (res == null) {
//            out.println(-1);
//        } else {
//            out.println(res[0]);
//        }
        if (s1 < t1) {
            { int t = s0; s0 = t0; t0 = t; }
            { int t = s1; s1 = t1; t1 = t; }
        }
        for (long i = 0; i < 5000000; i++) {
            if (i * s1 + s0 >= t0 && (i * s1 + s0 - t0) % t1 == 0) {
                out.println(i * s1 + s0);
                return ;
            }
        }
        out.println(-1);
    }

    private int get1(int m, int a1, int x1, int y1) {
        boolean[] vis = new boolean[m + 1];
        for (int i = 1, a2 = (int) ((long) a1 * x1 % m + y1) % m; ; i++) {
            if (a2 == a1) return i;
            if (vis[a2]) return -1;
            vis[a2] = true;
            a2 = (int) ((long) x1 * a2 % m + y1) % m;
        }
    }

    private int get0(int m, int h1, int a1, int x1, int y1) {
        boolean[] vis = new boolean[m + 1];
        for (int i = 0; ; i++) {
            if (h1 == a1) return i;
            if (vis[h1]) return -1;
            vis[h1] = true;
            h1 = (int) ((long) x1 * h1 % m + y1) % m;
        }
    }
}

class Scanner {
    BufferedReader br;
    StringTokenizer st;

    public Scanner(InputStream in) {
        br = new BufferedReader(new InputStreamReader(in));
        eat("");
    }

    private void eat(String s) {
        st = new StringTokenizer(s);
    }

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

    public boolean hasNext() {
        while (!st.hasMoreTokens()) {
            String s = nextLine();
            if (s == null)
                return false;
            eat(s);
        }
        return true;
    }

    public String next() {
        hasNext();
        return st.nextToken();
    }

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

}

class Algo {

    public static void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.StringTokenizer;

public class B {
	static boolean visited[][];

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

		int count = 0;

		visited = new boolean[n + 1][n + 1];
		int z;
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if(check(i,j)) {
					z=i^j;
					if(z>Math.max(i, j)&&z<=n&&z < i+j) {
						visited[i][j] = true;

						visited[j][i] = true;
						count++;
					}
				}
			}
		}
		System.out.println(count);
	}

	static boolean check(int i, int j) {
		if (!visited[i][j]&&!visited[j][i] )
			return true;
		return false;
	}

	static int log(int x, int base) {
		return (int) (Math.log(x) / Math.log(base));
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		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 String nextLine() throws IOException {
			return br.readLine();
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}


import java.util.List;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.InputMismatchException;
import java.util.ArrayList;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.math.BigInteger;
import java.util.Collection;
import java.util.Collections;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Turaev Timur
 */
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);
		TaskB solver = new TaskB();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        long n = in.readLong(), m = in.readLong();

        long maxAnswer = Combinatorics.binomial(n - m + 1, 2);

        long ceil = IntegerUtils.ceil(n, m);
        long floor = n / m;
        long minAnswer = (n % m) * Combinatorics.binomial(ceil, 2) + (m - n % m) * Combinatorics.binomial(floor, 2);

        out.printFormat("%d %d", minAnswer, maxAnswer);
    }
}

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

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

    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 long readLong() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        long 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);
    }
}

class OutputWriter {
    private final PrintWriter writer;

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

    public void printFormat(String format, Object... objects) {
        writer.printf(format, objects);
    }

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

}

class Combinatorics {

    public static long binomial(long n, long k) {
        long ans = 1;
        for (int i = 0; i < k; i++) {
            ans *= (n - i);
        }
        for (int i = 2; i <= k; i++) {
            ans /= i;
        }
        return ans;
    }
}

class IntegerUtils {

    public static long ceil(long n, long d) {
        return (n + d - 1) / d;
    }

}


//package codeforces.practice.div2c;

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

public class CF1105C {
    private static int UNVISITED = 0;
    private static int VISITING = -1;
    private static int VISITED = 1;

    public static void main(String[] args) {
//        try {
//            FastScanner in = new FastScanner(new FileInputStream("src/input.in"));
//            PrintWriter out = new PrintWriter(new FileOutputStream("src/output.out"));

        FastScanner in = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

            solve(1, in, out);

//        } catch (IOException e) {
//            e.printStackTrace();
//        }
    }

    private static void solve(int q, FastScanner in, PrintWriter out) {
        for (int qq = 0; qq < q; qq++) {
            int n = in.nextInt(), l = in.nextInt(), r = in.nextInt();
            int mod = (int)1e9 + 7;
            long[] cnt = new long[3];
            while(l % 3 != 0 && l <= r) {
                cnt[l % 3]++;
                l++;
            }
            while(r % 3 != 2 && l <= r) {
                cnt[r % 3]++;
                r--;
            }
            for(int i = 0; i < 3; i++) {
                cnt[i] += (r - l + 1) / 3;
            }

            long[][] dp = new long[n + 1][3];   //dp[i][j]: the number of ways to get an array of length i whose sum is j after % 3
            //dp[i][0] = number of ways to pick 0 * dp[i - 1][0] + number of ways to pick 1 * dp[i - 1][2] + numbers of ways to
            //pick 2 * dp[i - 1][1]

            dp[1][0] = cnt[0];
            dp[1][1] = cnt[1];
            dp[1][2] = cnt[2];

            for(int i = 2; i <= n; i++) {
                dp[i][0] = (dp[i - 1][0] * cnt[0] + dp[i - 1][1] * cnt[2] + dp[i - 1][2] * cnt[1]) % mod;
                dp[i][1] = (dp[i - 1][0] * cnt[1] + dp[i - 1][1] * cnt[0] + dp[i - 1][2] * cnt[2]) % mod;
                dp[i][2] = (dp[i - 1][0] * cnt[2] + dp[i - 1][1] * cnt[1] + dp[i - 1][2] * cnt[0]) % mod;
            }

            out.println(dp[n][0]);
        }
        out.close();
    }

    private static long modularAdd(long a, long b, int mod) {
        long sum = a + b;
        if (sum >= mod) {
            sum -= mod;
        }
        return sum;
    }

    private static long modularSubtract(long a, long b, int mod) {
        long diff = a - b;
        if (diff < 0) {
            diff += mod;
        }
        return diff;
    }

    private static Stack<Integer> topologicalSort(Set<Integer>[] g) {
        Stack<Integer> stack = new Stack<>();
        int[] state = new int[g.length];

        for (int node = 0; node < g.length; node++) {
            if (!topoSortHelper(g, stack, state, node)) {
                return null;
            }
        }
        return stack;
    }

    private static boolean topoSortHelper(Set<Integer>[] g, Stack<Integer> stack, int[] state, int currNode) {
        if (state[currNode] == VISITED) {
            return true;
        } else if (state[currNode] == VISITING) {
            return false;
        }
        state[currNode] = VISITING;
        for (int neighbor : g[currNode]) {
            if (!topoSortHelper(g, stack, state, neighbor)) {
                return false;
            }
        }
        state[currNode] = VISITED;
        stack.push(currNode);
        return true;
    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream stream) {
            try {
                br = new BufferedReader(new InputStreamReader(stream));
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


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

public class A {

    //public static PrintWriter pw;
    public static PrintWriter pw = new PrintWriter(System.out);

    public static void solve() throws IOException {
//	pw=new PrintWriter(new FileWriter("C:\\Users\\shree\\Downloads\\small_output_in"));
        FastReader sc = new FastReader();
        int n=sc.I();
        int a[]=new int[n+1];
        int dp[]=new int[n+1];
        int ans=0;
        for(int i=1;i<=n;i++){
            a[i]=sc.I();
            dp[i]=1;
            for(int j=1;j<i;j++){
                if(a[j]<=a[i]) dp[i]=Math.max(dp[i],1+dp[j]);
            }
            ans=Math.max(ans,dp[i]);
        }
        pw.println(ans);

        pw.close();

    }

    public static void main(String[] args) {
        new Thread(null, new Runnable() {
            public void run() {
                try {

                    solve();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }, "1", 1 << 26).start();

    }

    static BufferedReader br;
    static long M = (long) 1e9 + 7;

    static class FastReader {

        StringTokenizer st;

        public FastReader() throws FileNotFoundException {
            //br=new BufferedReader(new FileReader("C:\\Users\\shree\\Downloads\\B-small-practice.in"));
            br = new BufferedReader(new InputStreamReader(System.in));

        }

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

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public boolean hasNext() throws IOException {
            while (st == null || !st.hasMoreTokens()) {
                String s = br.readLine();
                if (s == null) {
                    return false;
                }
                st = new StringTokenizer(s);
            }
            return true;
        }

    }
}


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

public class Main {

    public static void main(String[] args) throws IOException {

        new Main().go();
    }

    PrintWriter out;
    Reader in;
    BufferedReader br;

    Main() throws IOException {

        try {

            //br = new BufferedReader( new FileReader("input.txt") );
            in = new Reader("input.txt");
            out = new PrintWriter( new BufferedWriter(new FileWriter("output.txt")) );
        }
        catch (Exception e) {

            //br = new BufferedReader( new InputStreamReader( System.in ) );
            in = new Reader();
            out = new PrintWriter( new BufferedWriter(new OutputStreamWriter(System.out)) );
        }
    }

    void go() throws IOException {

        int t = 1;
        while (t > 0) {
            solve();
            //out.println();
            t--;
        }

        out.flush();
        out.close();
    }

    int inf = 2000000000;
    int mod = 1000000007;
    double eps = 0.000000001;

    int n;
    int m;

    //ArrayList<Integer>[] g = new ArrayList[200010];

    void solve() throws IOException {

        int n = in.nextInt();
        int k = in.nextInt();
        int m = in.nextInt();
        int a = in.nextInt();

        Pair[] cands = new Pair[n];
        for (int i = 0; i < n; i++)
            cands[i] = new Pair(0, i);
        for (int i = 0; i < a; i++) {
            int x = in.nextInt()-1;
            cands[x].a++;
            cands[x].t = i;
        }

        Arrays.sort(cands);
        int[] pos = new int[n];
        for (int i = 0; i < n; i++)
            pos[cands[i].b] = i;

        int[] same = new int[n];
        int[] sum = new int[n];
        sum[0] = cands[0].a;
        for (int i = 1; i < n; i++) {
            if (cands[i].a == cands[i - 1].a) {
                same[i] = same[i - 1] + 1;
            }
            sum[i] += sum[i-1] + cands[i].a;
        }

        m -= a;
        int[] ans = new int[n];
        for (int i = 0; i < n; i++) {
            int p = pos[i];
            boolean ok = false;
            int x = k - (n-p) + 1;
            if (p >= n - k && !(cands[p].a == 0 && n > 1)) {
                if (p - x < 0) {
                    if (m > 0 || cands[p].a > 0) {
                        ok = true;
                        ans[i] = 1;
                    }
                }
                else {
                    int r = p - 1;
                    int l = p - x;
                    int need = x * (cands[p].a + 1);
                    need -= sum[r];
                    if (l > 0)
                        need += sum[l-1];

                    //System.err.println(need+" "+i);

                    if (need > m) {
                        ok = true;
                        ans[i] = 1;
                    }
                }
            }

            if (!ok) {

                int v = cands[n-k].a;
                if (cands[p].a + m > v) {
                    ans[i] = 2;
                }
                else {
                    ans[i] = 3;
                }
            }
        }

        for (int i = 0; i < n; i++)
            out.print(ans[i]+" ");

    }

    class Pair implements Comparable<Pair>{

        int a;
        int b;
        int t = 0;
        Pair(int a, int b) {

            this.a = a;
            this.b = b;
        }

        public int compareTo(Pair p) {

            if (a > p.a) return 1;
            if (a < p.a) return -1;
            if (t > p.t) return -1;
            if (t < p.t) return 1;
            return 0;
        }
    }

    class Item {

        int a;
        int b;
        int c;

        Item(int a, int b, int c) {
            this.a = a;
            this.b = b;
            this.c = c;
        }

    }

    class Reader {

        BufferedReader  br;
        StringTokenizer tok;

        Reader(String file) throws IOException {
            br = new BufferedReader( new FileReader(file) );
        }

        Reader() throws IOException {
            br = new BufferedReader( new InputStreamReader(System.in) );
        }

        String next() throws IOException {

            while (tok == null || !tok.hasMoreElements())
                tok = new StringTokenizer(br.readLine());
            return tok.nextToken();
        }

        int nextInt() throws NumberFormatException, IOException {
            return Integer.valueOf(next());
        }

        long nextLong() throws NumberFormatException, IOException {
            return Long.valueOf(next());
        }

        double nextDouble() throws NumberFormatException, IOException {
            return Double.valueOf(next());
        }

        String nextLine() throws IOException {
            return br.readLine();
        }

    }

}


import java.util.Scanner;

public class Pipeline {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		Long n = sc.nextLong(), k = sc.nextLong();
		sc.close();

		k--;
		n--;

		Long limit = (k * (k + 1)) / 2 ;

		if (n > limit) {
			System.out.println(-1);

		} else if ( n == 0 ) {
			System.out.println(0);

		} else if (n <= k) {
			System.out.println(1);

		} else {

			Long count = 0L;
			Long end = k;

			Long sk = BS(end,n); //findMaxRange(n,end);

			count += end - sk + 1 ;

			Long cur = ( end * (end+1) / 2 ) -  ( sk * (sk-1) / 2 ) ;

			n = n - cur ;

			if ( n != 0 ) {
				count++;
			}

			System.out.println(count);
		}

		// erke

	}

	public static Boolean valid(Long mid,Long e,Long n){

		Long cur = ( e * (e+1) / 2 ) -  ( mid * (mid-1) / 2 ) ;

		if (cur <= n )
			return true;
		return false;
	}

	public static Long BS(Long x, Long n){
		Long s=1L,e=x,m=0L;
		while(s<e){
			m=(s+e+1)/2-1;
			if(!valid(m,x,n))
				s=m+1;
			else
				e=m;
		}
		return s;
	}

}


import java.util.Scanner;
public class Hexagons
{
public static void main(String []args)
{
Scanner s = new Scanner(System.in);
int a = s.nextInt();
int b = s.nextInt();
int c  = s.nextInt();
System.out.println(a * b + b * c + c * a - a - b  - c + 1);
}
}


		import java.awt.List;
		import java.io.*;
		import java.util.*;

		/*
		 *
		 * daiict
		 *
		 *
		 *
		 */

		public class Main {
			FastScanner in;
			PrintWriter out;

			static ArrayList[] adj;

			static int n;
			static int m;
			static int visited[][];
			static int[][] arr;
			static int[][] brr;
			static int[][] ans;
			static int array[];
			static int pref[];
			static int sum = 0;
		//for dfs do not delete
			static int dir[][] ={{1,0},{0,1},{0,-1}};

			static long an = 0;
			static long bn = 0;
			static int p = 0;
			static int ta = -1;
			static int tb = -1;
			static Stack<Integer> st;
			static int k;
			static long mod = (long)1e9 + 7;
			static long[] seg;

			static class Pair implements Comparable<Pair>
		    {
				int x;
				boolean y;
				String s = "";
				String val;
		        Pair(int l, boolean b, String p,String q) {

		        	this.x = l;
		            this.y = b;
		           this.s = p;
		           this.val = q;
		        }
		        @Override
		        public int compareTo(Pair p) {

		        	String arr[] = val.split(" ");
		        	String brr[] = p.val.split(" ");

		        	if(s.equals("numeric")){
		        		int aa = Integer.parseInt(arr[x]);
						int bb = Integer.parseInt(brr[x]);

						if(aa>bb && this.y){
							return 1;
						}else if(this.y){
							return -1;
						}else if(aa >= bb && ! this.y){
							return -1;
						}else{
							return 1;
						}
		        	}else{
		        		if(this.y){
		        			return arr[x].compareTo(brr[x]);
		        		}else{
		        			return brr[x].compareTo(arr[x]);
		        		}
		        	}

		        }

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

		        public boolean equals(Object o){
		        	if(o instanceof Pair){
		        		Pair a = (Pair)o;

		        		return this.x == a.x;
		        	}

		        	return false;
		        }

//		        public int hashCode(){
//		        	return new Long(x).hashCode()*31 + new Long(y).hashCode();
//		        }

		    }

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

			void build(int n) {  // build the tree
				  for (int i = n - 1; i > 0; --i) seg[i] = Math.min(seg[i<<1],seg[i<<1|1]);
				}

			public static void modify(int p, long val,int n) {  // set value at position p
				  for (seg[p += n] = val; p > 1; p >>= 1) seg[p>>1] = Math.min(seg[p],seg[p^1]);
				}

				long query(int l, int r,int n) {  // sum on interval [l, r)
				  long res = Long.MAX_VALUE;
				  for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
				    if ((l&1) == 1) res = (long) Math.min(res,seg[l++]);
				    if ((r&1) == 1) res = (long)Math.min(res,seg[--r]);
				  }
				  return res;
				}

				 static long bC(int n, int k)
				    {
				    long C[][] = new long[n+1][k+1];
				    int i, j;

				        // Calculate  value of Binomial Coefficient in bottom up manner
				    for (i = 0; i <= n; i++)
				    {
				        for (j = 0; j <= Math.min(i, k); j++)
				        {
				            // Base Cases
				            if (j == 0 || j == i)
				                C[i][j] = 1;

				            // Calculate value using previosly stored values
				            else
				                C[i][j] = C[i-1][j-1] + C[i-1][j];
				          }
				     }

				    return C[n][k];
				    }

		    void solve() throws NumberFormatException, IOException {

		    	Scanner in = new Scanner(System.in);

		    	//HashSet<Long> set = new HashSet();
		    	long a = in.nextLong();
		    	long b = in.nextLong();
		    	long c = in.nextLong();
		    	long k = 0;

		    	while(k<=1000000){
		    		a *=10;
		    		k++;

		    		if(a/b == c){
		    			out.println(k);
		    			return;
		    		}
		    		a%=b;
		    	}

		    	out.println(-1);
		    }

		    public static void dfs(int i,int j,int d){

		    	System.out.println(i + " " + j + " " +d);

		    	if(d <= ans[i][j]){
		    		return;
		    	}

		    	if(i == n-1 && j == m-1){
		    		p = Math.max(p,d);
		    		ans[i][j] = p;
		    		arr = brr;
		    		return;
		    	}

		    	ans[i][j] = d;
		    	int temp = arr[i][j];
		    	arr[i][j] = 0;

		    	for(int p= 0;p<3;p++){
		    		int x = i + dir[p][0];
		    		int y = j + dir[p][1];

		    		if(x < 0 || x >=n || y < 0 || y >=m){
		    			continue;
		    		}else{

		    			dfs(x,y,d+arr[x][y]);

		    		}
		    	}
		    	//arr[i][j] = temp;

		    }

		    public static int Floor(int[] dp, int low, int high, long x)
		    {
		        // If low and high cross each other
		        if (low > high)
		            return -1;

		        // If last element is smaller than x
		        if (x >= dp[high])
		            return high;

		        // Find the middle point
		        int mid = (low+high)/2;

		        // If middle point is floor.
		        if (dp[mid] == x)
		            return mid;

		        // If x lies between mid-1 and mid
		        if (mid > 0 && dp[mid-1] <= x && x < dp[mid])
		            return mid-1;

		        // If x is smaller than mid, floor must be in
		        // left half.
		        if (x < dp[mid])
		            return Floor(dp, low, mid-1, x);

		        // If mid-1 is not floor and x is greater than
		        // arr[mid],
		        return Floor(dp, mid+1, high, x);
		    }

		    public static String[] reverse(String arr[]){

		    	for(int i = 0;i<arr.length/2;i++){
		    		String temp = arr[i];
		    		arr[i] = arr[arr.length-i-1];
		    		arr[arr.length-1-i] = temp;
		    	}

		    	return arr;

		    }

		    static long inv(long x , long mod)
			{
				long r,y;
				for(r=1,y=mod-2;y!=0;x=x*x%mod,y>>=1)
				{
					if((y&1)==1)
						r=r*x%mod;

				}
				return r;
			}

		    public static long sum(long x){
		    	return x<10?x:x%10 + sum(x/10);
		    }

			public static long gcd(long x, long y) {
				if (x == 0)
					return y;
				else
					return gcd( y % x,x);
			}

			public static long pow(long x,long y,long n){
				if(y==0)
					return 1%n;
				if(y%2==0){
					long z=pow(x,y/2,n);
					return (z*z)%n;
				}
				return ((x%n)*pow(x,y-1,n))%n;
			}

			public static boolean isPrime(int n) {
				// Corner cases
				if (n <= 1)
					return false;
				if (n <= 3)
					return true;

				// This is checked so that we can skip
				// middle five numbers in below loop
				if (n % 2 == 0 || n % 3 == 0)
					return false;

				for (int i = 5; i * i <= n; i = i + 6)
					if (n % i == 0 || n % (i + 2) == 0)
						return false;

				return true;
			}

			void run() throws NumberFormatException, IOException {
				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());
				}
			}

			class Tri{

				Tri[] arr;

				public Tri(){
					arr = new Tri[27];
				}

			}

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

		class Node{
			int a;
			int b;

		}

		class MyComp implements Comparator<String>{

			int c = 0;

			MyComp(int d){
				c = d;
			}

			@Override
			public int compare(String a,String b) {

				// < == -1

				String arr[] = a.split(" ");
				String brr[] = b.split(" ");

				return arr[c].compareTo(brr[c]);

			}

		}

		class MyComp2 implements Comparator<String>{

			int c = 0;

			MyComp2(int d){
				c = d;
			}

			@Override
			public int compare(String a,String b) {

				// < == -1

				String arr[] = a.split(" ");
				String brr[] = b.split(" ");

				int aa = Integer.parseInt(arr[c]);
				int bb = Integer.parseInt(brr[c]);

				if(aa>bb){
					return 1;
				}else{
					return -1;
				}

			}

		}


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

public class A723 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int[] array = new int[3];
        for (int i = 0; i < array.length; i++)
            array[i] = in.nextInt();
        Arrays.sort(array);
        int length1 = Math.abs(array[1] - array[0]);
        int length2 = Math.abs(array[1] - array[2]);
        System.out.println(length1 + length2);

    }
}


import java.util.Scanner;

public class FirstProg {

    public static void main(String[] args)
    {
        Scanner b = new Scanner(System.in);
        String a=b.nextLine();
        for(int i=0;i<a.length();i++)
        {
            if(a.charAt(i)=='H'|| a.charAt(i)=='Q'|| a.charAt(i)=='9')
            {
                System.out.println("YES") ;break;
            }
            else
                if(i==a.length()-1)
     System.out.println("NO");
    }

    }
}


    import java.io.*;
import java.text.DecimalFormat;
import java.util.*;
    public class main2 {
    	static ArrayList<pair> factors;
    	static boolean isComposite[];
    	static ArrayList<Integer> primes;
    	public static boolean isprime(long n){
    		if(n<=10001){
    			return !isComposite[(int)n];
    		}
    		for(int i=0;i<primes.size();i++){
    			if(primes.get(i)*primes.get(i)*1l>n){
    				break;
    			}
    			if(n%primes.get(i)==0){
    				return false;
    			}

    		}
    		return true;
    	}
    	static int[] res;

    	public static void sieve(int n){
    		isComposite=new boolean[n+1];
    		primes =new ArrayList<Integer>();
    		isComposite[0]=true;
    		isComposite[1]=true;
    		for(int i=2;i<=n;i++){
    			if(!isComposite[i]){
    				for(int j=2*i;j<=n;j=j+i){
    					isComposite[j]=true;
    				}
    			}
    			primes.add(i);
    		}

    	}
    	public static void primefactors(long n){
    		 factors=new ArrayList<pair>();
    		for(int x:primes){
    			if(x*x*1l>n){
    				break;
    			}

    			if(n%x==0){

    					pair p=new pair(x,0);
    					 factors.add(p);
    				while(n%x==0){
    				n/=x;
    				p.y++;}

    			}
    		}
    		if(n!=1){
    			factors.add(new pair((int)n,1));
    		}

    	}
    	public static long powfact(long n,long p){
    		int res=0;
    		for(long i=p;i*1l<=n;i=i*p*1l){
    			res+=(n/i);
    		}
    		return res;
    	}

    	public static long GCD(long i, long j){
    	if (i==0){
    		return j;
    	}
    	return GCD(j%i,i);
    	}
    	public static long LCM(long i, long j){
    		return(i*j)/GCD(i,j);
    	}

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

long  n=sc.nextLong();
long ra=sc.nextLong();
long sa=sc.nextLong();
long pa=sc.nextLong();
long rb=sc.nextLong();
long sb=sc.nextLong();
long pb=sc.nextLong();
long ra1=ra;
long sa1=sa;
long pa1=pa;
long rb1=rb;
long sb1=sb;
long pb1=pb;
long min=0;
long max=0;

ra=pb-ra;
ra+=rb;
if(ra<0){

	min+=(-ra);
}
sa=rb-sa;
sa+=sb;
if(sa<0){
	min+=(-sa);
}
pa=sb-pa;
pa+=pb;
	if(pa<0){
		min+=(-pa);
}

if(sb>=ra1){
	max+=ra1;

}
else{
	max+=(sb);
}
if(pb>=sa1){
	max+=sa1;
}
else{
	max+=(pb);
}
if(rb>=pa1){
	max+=pa1;

}
else{
	max+=(rb);
}
System.out.println(min+" "+max);
}

    	static class matrix{
    		int a, b,c, d;
    		public matrix(int x,int y, int z,int w){
    			a=x;
    			b=y;
    			c=z;
    			d=w;
    		}

    		public boolean issSem(){
    			return b==c ;
    		}
    	}
    	public static int p(long x){
    		int t=0;
    		while(x>1){
    			t++;
    			x=x/2;
    		}
    		return t;
    	}
     static long[] fact;
     public static long fact(int x){
long y=(int)Math.pow(2,x)-1;
return((y+1)*(y/2)+(y/2+1));
}

    	static ArrayList<Integer > [] adjlist;
    	static int [] leaves;
    	static PriorityQueue<pair> centroid;

    	public static void dfs1(int u,int p){
    		leaves[u]=1;
    		if(adjlist[u].size()==1&&u!=0){

    			return;
    		}
    		for( int x:adjlist[u]){
    			if(x!=p){
    				dfs1(x,u);
    				leaves[u]+=leaves[x];
    			}
    		}
    	}

    	static class pair implements Comparable<pair>{
    		int x;
    		int y;
    		public pair(int x, int y){
    			this.x=x;
    					this.y=y;
    		}
			@Override
			public int compareTo(pair o) {
				// TODO Auto-generated method stub
				return x-o.x;
			}
    	}

    	  	 	static class SegmentTree{
    	   	 		int[] arr , sTree;
    	   	 	static	int N;
    	   	 		public SegmentTree(int[] in){
    	   	 			arr=in;
    	   	 		N=arr.length-1;
    	   	 			sTree=new int[2*N];

    	   	 			build(1,1,N);
    	   	 		}
    	   	 		public void build(int node, int l, int r){
    	   	 			if(l==r){
    	   	 				sTree[node]=arr[l];
    	   	 			}
    	   	 			else{
    	   	 				int leftchild=node*2;
    	   	 				int rightchild=node*2+1;
    	   	 				int mid =(l+r)/2;
    	   	 				build(leftchild,l,mid);
    	   	 				build(rightchild,mid+1,r);
    	   	 				sTree[node]=Math.min(sTree[leftchild],sTree[rightchild]);
    	   	 			}
    	   	 		}
    	   	 		public  void update(int i, int val){
    	   	 			int node =i+N-1;
    	   	 			arr[i]=val;
    	   	 			sTree[node]=val;
    	   	 			node=node/2;
    	   	 			while(node>0){
    	   	 			int leftchild=node *2;
       	 				int rightchild=node*2+1;
       	 			sTree[node]=sTree[leftchild]&sTree[rightchild];
       	 			node=node/2;
    	   	 			}
    	   	 			return;

    	   	 		}
    	   	 		public int query(int i, int j){
    	   	 			 return query(1,1, N,  i, j);
    	   	 		}
    	   	 		public int query(int node,int l, int r, int i , int j){
    	   	 			if(i>r||j<l){
    	   	 				return Integer.MAX_VALUE;
    	   	 			}
    	   	 			if(i<=l&&r<=j){
    	   	 				return sTree[node];
    	   	 			}
    	   	 		int leftchild=node*2;
    	 				int rightchild=node*2+1;
    	 				int mid =(l+r)/2;

    	 			return	Math.min(query(leftchild,l,mid,i,j),query(rightchild,mid+1,r,i,j));

    	   	 		}
    	   	 	}

    	static class Scanner {
    		StringTokenizer st;
    		BufferedReader br;

    		public Scanner(InputStream s) {
    			br = new BufferedReader(new InputStreamReader(s));
    		}

    		public boolean hasNext() {
    			// TODO Auto-generated method stub
    			return false;
    		}

    		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 String nextLine() throws IOException {
    			return br.readLine();
    		}

    		public double nextDouble() throws IOException {
    			String x = next();
    			StringBuilder sb = new StringBuilder("0");
    			double res = 0, f = 1;
    			boolean dec = false, neg = false;
    			int start = 0;
    			if (x.charAt(0) == '-') {
    				neg = true;
    				start++;
    			}
    			for (int i = start; i < x.length(); i++)
    				if (x.charAt(i) == '.') {
    					res = Long.parseLong(sb.toString());
    					sb = new StringBuilder("0");
    					dec = true;
    				} else {
    					sb.append(x.charAt(i));
    					if (dec)
    						f *= 10;
    				}
    			res += Long.parseLong(sb.toString()) / f;
    			return res * (neg ? -1 : 1);
    		}

    		public boolean ready() throws IOException {
    			return br.ready();
    		}

    	}}


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

public class GuessTheTree {

	BufferedReader br;
	PrintWriter out;
	StringTokenizer st;
	boolean eof;

	boolean solve() throws IOException {
		int n = nextInt();
		int initN = n;
		List<Integer> szList = new ArrayList<>();
		int leaves = 0;

		for (int i = 0; i < n; i++) {
			int x = nextInt();
			if (x == 1) {
				leaves++;
			} else {
				szList.add(x);
			}
		}

		n = szList.size();

		if (leaves <= n) {
			return false;
		}

		if (n == 0) {
			return true;
		}

		Collections.sort(szList);
		Collections.reverse(szList);

		int[] sz = new int[n];
		for (int i = 0; i < sz.length; i++) {
			sz[i] = szList.get(i);
		}

		if (sz[0] != initN) {
			return false;
		}

		int[] maskCnt = new int[1 << n];
		int[] maskSum = new int[1 << n];
		for (int i = 0; i < n; i++) {
			maskCnt[1 << i] = 1;
			maskSum[1 << i] = sz[i];
		}

		for (int mask = 1; mask < (1 << n); mask++) {
			int low = Integer.lowestOneBit(mask);
			maskCnt[mask] = maskCnt[low] + maskCnt[mask ^ low];
			maskSum[mask] = maskSum[low] + maskSum[mask ^ low];
		}

		boolean[][][] dp = new boolean[n + 1][leaves + 1][1 << n];
		// current node, unassigned leaves, unassigned nodes

		final int ALL = (1 << n) - 1;

		dp[0][leaves][ALL ^ 1] = true;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= leaves; j++) {
				for (int mask = 0; mask < (1 << n); mask++) {
					if (!dp[i][j][mask] || test(mask, i)) {
						continue;
					}
					for (int sub = mask; ; sub = (sub - 1) & mask) {
						int leavesHere = sz[i] - 1 - maskSum[sub];
						if (leavesHere >= 0 && leavesHere <= j
								&& leavesHere + maskCnt[sub] >= 2) {
							dp[i + 1][j - leavesHere][mask ^ sub] = true;
						}
						if (sub == 0) {
							break;
						}
					}
				}
			}
		}

		return dp[n][0][0];

	}

	static boolean test(int mask, int i) {
		return ((mask >> i) & 1) == 1;
	}

	void inp() throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		out.println(solve() ? "YES" : "NO");
		out.close();
	}

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

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

	String nextString() {
		try {
			return br.readLine();
		} catch (IOException e) {
			eof = true;
			return null;
		}
	}

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

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

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


import java.util.Scanner;

public class E {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        if (k > n) {
            System.out.println(0);
            System.exit(0);
        }
        long[][] F = new long[n + 1][n + 1];
        long[][] G = new long[n + 1][n + 1];
        long[][] C = new long[n + 1][n + 1];
        int mod = (int) 1e9 + 7;
        for (int i = 0; i <= n; i++)
            for (int j = 0; j <= i; j++)
                if (i == j || j == 0)
                    C[i][j] = 1;
                else
                    C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % mod;
        F[0][0] = 1;
        G[0][0] = G[1][0] = 1;
        for (int i = 2; i <= n; i++)
            for (int j = 0; j <= n; j++)
                for (int left = 1; left < i; left++) {
                    int right = i - left - 1;
                    long mul = (C[i - 2][left - 1] * left * Math.max(right, 1))
                            % mod;
                    // Need root
                    for (int kLeft = 0; kLeft < j; kLeft++) {
                        int kRight = j - kLeft - 1;
                        long notLeft = (G[left][kLeft] * (right == 0
                                && kRight == 0 ? 1
                                    : (F[right][kRight] + G[right][kRight])))
                                % mod;
                        long notRight = right == 0 ? 0
                                : (F[left][kLeft] * G[right][j - kLeft - 1])
                                        % mod;
                        F[i][j] = (F[i][j] + mul * (notLeft + notRight)) % mod;
                    }
                    // No need root
                    for (int kLeft = 0; kLeft <= j; kLeft++)
                        G[i][j] = (G[i][j] + mul
                                * ((F[left][kLeft] * F[right][j - kLeft]) % mod))
                                % mod;
                }
        System.out.println((G[n][k] + F[n][k]) % mod);
    }
}


// practice with rainboy
import java.io.*;
import java.util.*;

public class CF884F extends PrintWriter {
	CF884F() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		CF884F o = new CF884F(); o.main(); o.flush();
	}

	static final int A = 26, INF = 0x3f3f3f3f;
	int[] oo, oh; int __ = 1;
	int link(int o, int h) {
		oo[__] = o; oh[__] = h;
		return __++;
	}
	int[] ii, jj, cc, cost, cost_; int m_;
	int[] ae, pi, dd, ff; int n_;
	int[] pq, iq; int cnt;
	void init() {
		oo = new int[1 + m_ * 2]; oh = new int[1 + m_ * 2];
		ii = new int[m_]; jj = new int[m_]; cc = new int[m_ << 1];
		cost = new int[m_]; cost_ = new int[m_];
		pi = new int[n_]; dd = new int[n_]; ff = new int[n_];
		ae = new int[n_];
		pq = new int[1 + n_]; iq = new int[n_];
		m_ = 0;
	}
	void link_(int i, int j, int c, int co) {
		int h = m_++;
		ii[h] = i; jj[h] = j; cc[h << 1] = c;
		cost[h] = co;
		ae[i] = link(ae[i], h << 1);
		ae[j] = link(ae[j], h << 1 | 1);
	}
	boolean less(int u, int v) {
		return pi[u] < pi[v] || pi[u] == pi[v] && dd[u] < dd[v];
	}
	int i2(int i) {
		return (i *= 2) > cnt ? 0 : i < cnt && less(pq[i + 1], pq[i]) ? i + 1 : i;
	}
	void pq_up(int u) {
		int i, j, v;
		for (i = iq[u]; (j = i / 2) > 0 && less(u, v = pq[j]); i = j)
			pq[iq[v] = i] = v;
		pq[iq[u] = i] = u;
	}
	void pq_dn(int u) {
		int i, j, v;
		for (i = iq[u]; (j = i2(i)) > 0 && less(v = pq[j], u); i = j)
			pq[iq[v] = i] = v;
		pq[iq[u] = i] = u;
	}
	void pq_add_last(int u) {
		pq[iq[u] = ++cnt] = u;
	}
	int pq_remove_first() {
		int u = pq[1], v = pq[cnt--];
		if (v != u) {
			iq[v] = 1; pq_dn(v);
		}
		iq[u] = 0;
		return u;
	}
	boolean dijkstra(int s, int t) {
		Arrays.fill(pi, INF);
		pi[s] = 0; pq_add_last(s);
		while (cnt > 0) {
			int i = pq_remove_first();
			int d = dd[i] + 1;
			for (int o = ae[i]; o != 0; o = oo[o]) {
				int h_ = oh[o];
				if (cc[h_] > 0) {
					int h = h_ >> 1;
					int j = i ^ ii[h] ^ jj[h];
					int p = pi[i] + ((h_ & 1) == 0 ? cost_[h] : -cost_[h]);
					if (pi[j] > p || pi[j] == p && dd[j] > d) {
						if (pi[j] == INF)
							pq_add_last(j);
						pi[j] = p; dd[j] = d; ff[j] = h_;
						pq_up(j);
					}
				}
			}
		}
		return pi[t] != INF;
	}
	int trace(int s, int t) {
		while (t != s) {
			int h_ = ff[t], h = h_ >> 1;
			cc[h_]--; cc[h_ ^ 1]++;
			t ^= ii[h] ^ jj[h];
		}
		return 1;
	}
	int edmonds_karp(int s, int t) {
		for (int h = 0; h < m_; h++) {
			int i = ii[h], j = jj[h];
			pi[j] = Math.min(pi[j], pi[i] + cost[h]);
		}
		for (int h = 0; h < m_; h++) {
			int i = ii[h], j = jj[h];
			cost_[h] = cost[h] + pi[i] - pi[j];
		}
		int f = 0;
		while (dijkstra(s, t)) {
			f += trace(s, t);
			for (int h = 0; h < m_; h++) {
				int i = ii[h], j = jj[h];
				if (pi[i] != INF && pi[j] != INF) {
					// pi[j] <= pi[i] + cost_[h]
					// cost_[h] + pi[i] - pi[j] >= 0
					cost_[h] += pi[i] - pi[j];
				}
			}
		}
		int ans = 0;
		for (int h = 0; h < m_; h++)
			ans += cc[h << 1 | 1] * cost[h];
		return ans;
	}
	void main() {
		int n = sc.nextInt() / 2;
		n_ = 1 + n + A + 1;
		m_ = n + n * A + A;
		init();
		byte[] cc = sc.next().getBytes();
		int[] bb = new int[n * 2];
		for (int i = 0; i < n * 2; i++)
			bb[i] = sc.nextInt();
		for (int i = 0; i < n; i++)
			link_(0, 1 + i, 2, 0);
		for (int i = 0; i < n; i++) {
			int j = n * 2 - 1 - i;
			int ai = cc[i] - 'a';
			int aj = cc[j] - 'a';
			for (int a = 0; a < A; a++) {
				int b;
				if (a == ai && a == aj)
					b = Math.max(bb[i], bb[j]);
				else if (a == ai)
					b = bb[i];
				else if (a == aj)
					b = bb[j];
				else
					b = 0;
				link_(1 + i, 1 + n + a, 1, -b);
			}
		}
		int[] kk = new int[A];
		for (int i = 0; i < n * 2; i++) {
			int a = cc[i] - 'a';
			kk[a]++;
		}
		for (int a = 0; a < A; a++)
			link_(1 + n + a, n_ - 1, kk[a], 0);
		println(-edmonds_karp(0, n_ - 1));
	}
}


import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);
        long x=sc.nextLong();
        String stx=x+"";
        long y=sc.nextLong();

        int sumx=0;

        for(int i=0;i<stx.length();i++){
        sumx+=Integer.parseInt(stx.charAt(i)+"");
        }

   sumx=Math.max(sumx, ((Integer.parseInt(stx.charAt(0)+"")-1)+(9*(stx.length()-1))));

      int count=0;

    if(x<y){System.out.println("0");}
      else{
         for(long i =y;i<=x;i++){
         String st_temp=i+"";
     int sub_temp=0;
     for(int j=0;j<st_temp.length();j++){
        sub_temp+=Integer.parseInt(st_temp.charAt(j)+"");
        }
     if((i-sub_temp)<y){count++;}
     else{break;}

     }
        System.out.println(x-(count+y)+1);
    }

   }

}


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

public class Main {

    public static void main(String[] args) {

        Scanner input=new Scanner(System.in);

        long n=input.nextLong();

        boolean f;
        long p=n;
        while(p>1){

            f=false;
            for(long i=2;(i*i)<=p && !f;i++){
                if(p%(i*i)==0){
                    p=p/i;
                    //System.out.println(i);
                    f=true;
                }
            }

            if(!f)
                break;
        }

        System.out.println(p);
    }
}


import java.util.Scanner;

/**
 *
 * @author Pc
 */
public class TEST {

    public static String reverse(String s) {
        String reverse = "";
        for (int i = s.length() - 1; i >= 0; i--) {
            reverse += s.charAt(i);
        }
        return reverse;
    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();
        String s1, s2;

        for (int i = 1; i <= n/2; i++) {

            if (n % i == 0) {
                s1 = s.substring(0, i);
                s2 = s.substring(i);
                s1 = reverse(s1);
                s = s1 + s2;

            }
        }
         s = reverse(s);
        System.out.println(s);
    }
}


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

public class towerhanoi {
  private static Reader in;
  private static PrintWriter out;
  public static int[][] cost = new int[3][3];

  public static void main(String[] args) throws IOException {
    in = new Reader();
    out = new PrintWriter(System.out, true);
    for (int i = 0; i < 3; i++) for (int j = 0; j < 3; j++)
      cost[i][j] = in.nextInt();
    int N = in.nextInt();
    dp = new long[N+1][3][3];
    for (int i = 0; i <= N; i++)
      for (int j = 0; j < 3; j++)
        for (int k = 0; k < 3; k++)
          dp[i][j][k] = -1;
    out.println(solve(N, 0, 2));
  }

  public static long[][][] dp;
  public static long solve (int disks, int from, int to) {
    if (disks == 0) return 0;
    if (dp[disks][from][to] != -1) return dp[disks][from][to];
    int other = 3 - from - to;
    return dp[disks][from][to] = Math.min(
        solve(disks-1, from, other) + cost[from][to] + solve(disks-1, other, to),
        solve(disks-1, from, to) + cost[from][other] + solve(disks-1, to, from)
        + cost[other][to] + solve(disks-1, from, to));
  }

  static class Reader {
    final private int BUFFER_SIZE = 1 << 16;
    private DataInputStream din;
    private byte[] buffer;
    private int bufferPointer, bytesRead;

    public Reader() {
      din = new DataInputStream(System.in);
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public Reader(String file_name) throws IOException {
      din = new DataInputStream(new FileInputStream(file_name));
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public String readLine() throws IOException {
      byte[] buf = new byte[1024];
      int cnt = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      do {
        buf[cnt++] = c;
      } while ((c = read()) != '\n');
      return new String(buf, 0, cnt);
    }

    public String next() throws IOException {
      byte[] buf = new byte[1024];
      int cnt = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      do {
        buf[cnt++] = c;
      } while ((c = read()) > ' ');
      return new String(buf, 0, cnt);
    }

    public int nextInt() throws IOException {
      int ret = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      boolean neg = (c == '-');
      if (neg)
        c = read();
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');
      if (neg)
        return -ret;
      return ret;
    }

    public long nextLong() throws IOException {
      long ret = 0;
      byte c = read();
      while (c <= ' ')
        c = read();
      boolean neg = (c == '-');
      if (neg)
        c = read();
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');
      if (neg)
        return -ret;
      return ret;
    }

    public double nextDouble() throws IOException {
      double ret = 0, div = 1;
      byte c = read();
      while (c <= ' ')
        c = read();
      boolean neg = (c == '-');
      if (neg)
        c = read();
      do {
        ret = ret * 10 + c - '0';
      } while ((c = read()) >= '0' && c <= '9');
      if (c == '.')
        while ((c = read()) >= '0' && c <= '9')
          ret += (c - '0') / (div *= 10);
      if (neg)
        return -ret;
      return ret;
    }

    private void fillBuffer() throws IOException {
      bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
      if (bytesRead == -1)
        buffer[0] = -1;
    }

    private byte read() throws IOException {
      if (bufferPointer == bytesRead)
        fillBuffer();
      return buffer[bufferPointer++];
    }

    public void close() throws IOException {
      if (din == null)
        return;
      din.close();
    }
  }

}