import java.util.*;

public class C {

	public static void main(String[] args) {

		Scanner qwe = new Scanner(System.in);

		int N = qwe.nextInt();
		String[] cards = new String[N];
		for (int i = 0; i < cards.length; i++) {
			cards[i] =  qwe.next();
		}

		int min = 11;
		char[] colorsnums = {'R', 'G', 'B', 'Y', 'W','1','2','3','4','5'};

		for(int bm = 0; bm < (1 << 10); bm++){
			int bc = Integer.bitCount(bm);
			if(bc >= min) continue;

			int dex =0;
			HashSet<Character> cp = new HashSet<Character>();
			for(int i = 1; i <= bm; i <<= 1,dex++){
				if((i & bm) == i) cp.add(colorsnums[dex]);
			}

			boolean good = true;

			for(int i =0; i < cards.length; i++){
				for(int j = i+1; j < cards.length; j++){
					if(cards[i].equals(cards[j])) continue;
					boolean canTellApart = false;
					if(cards[i].charAt(0) != cards[j].charAt(0)
							&& (cp.contains(cards[i].charAt(0)) || cp.contains(cards[j].charAt(0))  ) )
						canTellApart = true;
					if(cards[i].charAt(1) != cards[j].charAt(1)
							&& (cp.contains(cards[i].charAt(1)) || cp.contains(cards[j].charAt(1))  ) )
						canTellApart = true;

					if(!canTellApart) good = false;
				}
			}

			if(good){
				//System.out.println(cp);
				min = bc;
			}

		}

		System.out.println(min);

		qwe.close();
	}

}


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

	void solve()
	{
		int[] dual = {
				8, -1, -1, 3, 6, 9, 4, 7, 0, 5
		};
		char[] s = ns().toCharArray();
		for(int i = 0, j = s.length-1;i <= j;i++,j--){
			if(dual[s[i]-'0'] != s[j]-'0'){
				out.println("No");
				return;
			}
		}
		out.println("Yes");
	}

	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 D().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(!oj)System.out.println(Arrays.deepToString(o)); }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
import java.util.Vector;

public class Test {

	static int n, m, k, t;
	static int[] deg = new int[501];
	static int[] w1 = new int[501];
	static int[] w2 = new int[501];
	static int[][] f = new int[50001][201];
	static int[][] index = new int[50001][201];
	static int[] color = new int[5001];
	static void alter(int y, int c1, int c2)
	{
		//swap f[y][c1] and f[y][c2]
		int temp = f[y][c1];
		f[y][c1] = f[y][c2];
		f[y][c2] = temp;
		temp = index[y][c1];
		index[y][c1] = index[y][c2];
		index[y][c2] = temp;
		color[index[y][c2]] = c2;
		if(f[y][c2] != 0) alter(f[y][c2], c2, c1);
	}

	public static void main(String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter writer = new PrintWriter(System.out);
		StringTokenizer st  = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		int t = Integer.parseInt(st.nextToken());
		int cnt = 0;
		for(int i = 1; i <= k; i++)
		{
			st = new StringTokenizer(br.readLine());
			int a = Integer.parseInt(st.nextToken());
			int b = Integer.parseInt(st.nextToken());
			if(deg[a]%t == 0) w1[a] = ++cnt;
			if(deg[n+b]%t == 0) w2[n+b] = ++cnt;
			++deg[a];
			++deg[n+b];
			int x = w1[a];
			int y = w2[n+b];
			int c1 = -1;
			int c2 = -1;
			for(int j = 1; j <= t; j++) if(f[x][j] == 0) { c1 = j; break; }
			for(int j = 1; j <= t; j++) if(f[y][j] == 0) { c2 = j; break; }

			if(f[y][c1] != 0) alter(y, c1, c2);
			f[x][c1] = y;
			f[y][c1] = x;
			index[x][c1] = i;
			index[y][c1] = i;
			color[i] = c1;
		}
		int uneven = 0;
		for(int i = 1; i <= n; i++) if(deg[i]%t != 0) uneven++;
		for(int i = n+1; i <= n+m; i++) if(deg[i]%t != 0) uneven++;
		writer.println(uneven);
		for(int i = 1; i <= k; i++) writer.print(color[i]+" ");
		br.close();
		writer.close();
	}

}


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

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

    static class TaskB {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            long n = in.nextLong();

            ArrayList<Long> primes = new ArrayList<>();
            int m = (int) 1e6;
            boolean notPrime[] = new boolean[m];
            for (int i = 2; i < m; i++) {
                if (!notPrime[i]) {
                    primes.add((long) i);
                    for (int j = 2 * i; j < m; j += i) {
                        notPrime[j] = true;
                    }
                }
            }

            long res = 1;

            for (Long l : primes) {
                if (n % l == 0) {
                    if (n % 2L != 0) {
                        n -= l;
                        res += (n / 2L);
                        break;
                    } else {
                        res = (n / l);
                        break;
                    }
                }
            }

            out.println(res);
        }

    }

    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 long nextLong() {
            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 c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

        }

    }
}


import java.io.*;
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Locale;
import java.util.StringTokenizer;

public class A implements Runnable {

    private static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;

    private BufferedReader in;
    private PrintWriter out;
    private StringTokenizer tok = new StringTokenizer("");

    private void init() throws FileNotFoundException {
        Locale.setDefault(Locale.US);
        String fileName = "";
        if (ONLINE_JUDGE && fileName.isEmpty()) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            if (fileName.isEmpty()) {
                in = new BufferedReader(new FileReader("input.txt"));
                out = new PrintWriter("output.txt");
            } else {
                in = new BufferedReader(new FileReader(fileName + ".in"));
                out = new PrintWriter(fileName + ".out");
            }
        }
    }

    String readString() {
        while (!tok.hasMoreTokens()) {
            try {
                tok = new StringTokenizer(in.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return tok.nextToken();
    }

    int readInt() {
        return Integer.parseInt(readString());
    }

    long readLong() {
        return Long.parseLong(readString());
    }

    double readDouble() {
        return Double.parseDouble(readString());
    }

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

    public static void main(String[] args) {
        //new Thread(null, new _Solution(), "", 128 * (1L << 20)).start();
        new A().run();
    }

    long timeBegin, timeEnd;

    void time() {
        timeEnd = System.currentTimeMillis();
        System.err.println("Time = " + (timeEnd - timeBegin));
    }

    @Override
    public void run() {
        try {
            timeBegin = System.currentTimeMillis();
            init();
            solve();
            out.close();
            time();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    boolean[][] a;
    int[] color;
    int n;

    boolean foundError = false;

    void dfs(int v, int c) {
        color[v] = c;
        for (int to = 0; to < n; to++) {
            if (a[v][to]) {
                if (color[to] == -1) {
                    dfs(to, 1 - c);
                } else {
                    if (color[to] != 1 - c) {
                        foundError = true;
                        return;
                    }
                }
            }
        }
    }

    private void solve() {
        n = readInt();
        int m = readInt();
        a = new boolean[n][n];
        for (int i = 0; i < n; i++) {
            Arrays.fill(a[i], true);
            a[i][i] = false;
        }
        while (m-->0) {
            int x = readInt() - 1;
            int y = readInt() - 1;
            a[x][y] = false;
            a[y][x] = false;
        }

        boolean[] used = new boolean[n];
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                used[i] |= a[i][j];
            }
        }

        color = new int[n];
        Arrays.fill(color, -1);

        for (int i = 0; i < n; i++) {
            if (color[i] == -1) {
                if (!used[i]) {
                    color[i] = 2;
                    continue;
                }
                dfs(i, 0);
                if (foundError) {
                    out.println("No");
                    return;
                }
            }
        }
        if (foundError) {
            out.println("No");
            return;
        }

        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                if (i != j && !a[i][j]) {
                    if (color[i] == 1 - color[j]) {
                        foundError = true;
                        break;
                    }
                }
            }
        }
        if (foundError) {
            out.println("No");
            return;
        }

        out.println("Yes");
        for (int i = 0; i < n; i++) {
            out.print(color[i] == 0 ? 'a' : (color[i] == 1 ? 'c' : 'b'));
        }
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Iterator;
import java.util.Collection;
import java.util.Set;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.HashSet;
import java.util.Queue;
import java.util.LinkedList;
import java.io.InputStream;

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

    static class DNavigationSystem {
        public void solve(int testNumber, FastReader s, PrintWriter out) {
            int n = s.nextInt();
            int m = s.nextInt();
            DNavigationSystem.Graph g = new DNavigationSystem.Graph(n, true, false);
            g.takeInput(m, s);
//        out.println(g.neighbours);
            int size = s.nextInt();
            int[] arr = s.nextIntArray(size);
            int src = arr[size - 1];
            int dest = arr[0];
//        g.neighbours.remove(dest);
            HashMap<Integer, HashSet<Integer>> parent = new HashMap<>();
            HashMap<Integer, Integer> distance = new HashMap<>();
            HashSet<Integer> visited = new HashSet<>();
            Queue<Integer> q = new LinkedList<>();
            q.add(src);
            visited.add(src);
            distance.put(src, 0);
            HashMap<Integer, HashMap<Integer, Long>> neighbours = g.neighbours;
            while (!q.isEmpty()) {
                int curr = q.poll();
                HashMap<Integer, Long> neighb = neighbours.getOrDefault(curr, new HashMap<>());
                Iterator<Integer> iter = neighb.keySet().iterator();
                int currD = distance.get(curr);
                while (iter.hasNext()) {
                    int next = iter.next();
                    if (!visited.contains(next)) {
                        distance.put(next, currD + 1);
                        visited.add(next);
                        HashSet<Integer> list = new HashSet<>();
                        list.add(curr);
                        parent.put(next, list);
                        q.add(next);
                    } else {
                        if (distance.get(next) == currD + 1) {
                            HashSet<Integer> list = parent.get(next);
                            list.add(curr);
                            parent.put(next, list);
                        } else if (distance.get(next) > currD + 1) {
                            HashSet<Integer> list = parent.get(next);
                            list.clear();
                            list.add(curr);
                            distance.put(next, currD + 1);
                            parent.put(next, list);
                        }
                    }
                }

            }

//        out.println(parent);

            int worst = 0;
            int best = 0;
            for (int i = 0; i < size - 1; i++) {
                int next = arr[i + 1];
                int curr = arr[i];

                HashSet<Integer> set = parent.get(curr);
                if (set.contains(next)) {
                    if (set.size() != 1) {
                        best++;
                    }
                } else {
                    worst++;
                    best++;
                }
            }
            out.println(worst + " " + best);
        }

        private static class Graph {
            HashMap<Integer, HashMap<Integer, Long>> neighbours;
            int numVertices;
            boolean isDirected;
            boolean isWeighted;

            public Graph(int numVertices, boolean isDirected, boolean isWeighted) {
                neighbours = new HashMap<>();
                this.numVertices = numVertices;
                this.isDirected = isDirected;
                this.isWeighted = isWeighted;
            }

            public void takeInput(int n, FastReader s) {
                for (int i = 0; i < n; i++) {
                    int dest = s.nextInt();
                    int src = s.nextInt();

//                if (dest == )
                    long wt;
                    if (isWeighted) {
                        wt = s.nextLong();
                    } else {
                        wt = 1;
                    }
                    HashMap<Integer, Long> list = neighbours.getOrDefault(src, new HashMap<>());
                    list.put(dest, wt);
                    neighbours.put(src, list);
                    if (!isDirected) {
                        list = neighbours.getOrDefault(dest, new HashMap<>());
                        list.put(src, wt);
                        neighbours.put(dest, list);
                    }
                }
            }

        }

    }

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

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

        public long nextLong() {
            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 int[] nextIntArray(int n) {
            int[] array = new int[n];
            for (int i = 0; i < n; ++i) array[i] = nextInt();
            return array;
        }

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

        }

    }
}


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

public class intro{
	public static void main(String[] args) throws IOException{
		BufferedReader vod=new BufferedReader(new InputStreamReader(System.in));
		int n=Integer.parseInt(vod.readLine());
		char[] mas=vod.readLine().toCharArray();
		int ans=0;
		for (int i=0; i<n; i++){
			int a=0,b=0;
			for (int j=i; j<n; j++){
				if (mas[j]=='U') a++;
				if (mas[j]=='D') a--;
				if (mas[j]=='L') b--;
				if (mas[j]=='R') b++;
				if ((a==0)&(b==0)) ans++;
			}
		}
		System.out.println(ans);
	}
}


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

public class A {

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter pr = new PrintWriter(System.out);
		int n = sc.nextInt();
		int k = sc.nextInt();
		double f = (double) (Math.floor((n * 1.0) / k)) + 1;
		System.out.println((int) f * k);

	}

	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 double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

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

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.io.UncheckedIOException;
import java.util.List;
import java.io.Closeable;
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) throws Exception {
        Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 27);
        thread.start();
        thread.join();
    }

    static class TaskAdapter implements Runnable {
        @Override
        public void run() {
            InputStream inputStream = System.in;
            OutputStream outputStream = System.out;
            FastInput in = new FastInput(inputStream);
            FastOutput out = new FastOutput(outputStream);
            CUpgradingTree solver = new CUpgradingTree();
            solver.solve(1, in, out);
            out.close();
        }
    }

    static class CUpgradingTree {
        List<int[]> seq = new ArrayList<>(200000);
        List<Node> centers = new ArrayList<>();
        Node top;
        Node target;
        Node last;

        public void solve(int testNumber, FastInput in, FastOutput out) {
            int n = in.readInt();
            Node[] nodes = new Node[n];
            for (int i = 0; i < n; i++) {
                nodes[i] = new Node();
                nodes[i].id = i;
            }
            for (int i = 0; i < n - 1; i++) {
                Node a = nodes[in.readInt() - 1];
                Node b = nodes[in.readInt() - 1];
                a.adj.add(b);
                b.adj.add(a);
            }

            dfsForSize(nodes[0], null);
            dfsForCenter(nodes[0], null, nodes[0].size);
            if (centers.size() == 2) {
                Node a = centers.get(0);
                Node b = centers.get(1);
                a.adj.remove(b);
                b.adj.remove(a);
            }

            for (Node center : centers) {
                for (Node node : center.adj) {
                    top = center;
                    target = node;
                    last = node;
                    dfs(node, center);
                    focus(target);
                }
            }

            out.println(seq.size());
            for (int[] s : seq) {
                for (int x : s) {
                    out.append(x + 1).append(' ');
                }
                out.println();
            }
        }

        public void dfsForSize(Node root, Node p) {
            root.size = 1;
            for (Node node : root.adj) {
                if (node == p) {
                    continue;
                }
                dfsForSize(node, root);
                root.size += node.size;
            }
        }

        public void dfsForCenter(Node root, Node p, int total) {
            int max = total - root.size;
            for (Node node : root.adj) {
                if (node == p) {
                    continue;
                }
                max = Math.max(node.size, max);
                dfsForCenter(node, root, total);
            }
            if (max * 2 <= total) {
                centers.add(root);
            }
        }

        public void add(Node x, Node y, Node yy) {
            seq.add(new int[]{x.id, y.id, yy.id});
        }

        public void focus(Node next) {
            if (next == last) {
                return;
            }
            add(top, last, next);
            last = next;
        }

        public void dfs(Node root, Node p) {
            for (Node node : root.adj) {
                if (node == p) {
                    continue;
                }
                dfs(node, root);
            }

            if (root != target && p != target) {
                focus(root);
                add(root, p, target);
            }
        }

    }

    static class FastInput {
        private final InputStream is;
        private byte[] buf = new byte[1 << 13];
        private int bufLen;
        private int bufOffset;
        private int next;

        public FastInput(InputStream is) {
            this.is = is;
        }

        private int read() {
            while (bufLen == bufOffset) {
                bufOffset = 0;
                try {
                    bufLen = is.read(buf);
                } catch (IOException e) {
                    bufLen = -1;
                }
                if (bufLen == -1) {
                    return -1;
                }
            }
            return buf[bufOffset++];
        }

        public void skipBlank() {
            while (next >= 0 && next <= 32) {
                next = read();
            }
        }

        public int readInt() {
            int sign = 1;

            skipBlank();
            if (next == '+' || next == '-') {
                sign = next == '+' ? 1 : -1;
                next = read();
            }

            int val = 0;
            if (sign == 1) {
                while (next >= '0' && next <= '9') {
                    val = val * 10 + next - '0';
                    next = read();
                }
            } else {
                while (next >= '0' && next <= '9') {
                    val = val * 10 - next + '0';
                    next = read();
                }
            }

            return val;
        }

    }

    static class FastOutput implements AutoCloseable, Closeable, Appendable {
        private StringBuilder cache = new StringBuilder(10 << 20);
        private final Writer os;

        public FastOutput append(CharSequence csq) {
            cache.append(csq);
            return this;
        }

        public FastOutput append(CharSequence csq, int start, int end) {
            cache.append(csq, start, end);
            return this;
        }

        public FastOutput(Writer os) {
            this.os = os;
        }

        public FastOutput(OutputStream os) {
            this(new OutputStreamWriter(os));
        }

        public FastOutput append(char c) {
            cache.append(c);
            return this;
        }

        public FastOutput append(int c) {
            cache.append(c);
            return this;
        }

        public FastOutput println(int c) {
            return append(c).println();
        }

        public FastOutput println() {
            cache.append(System.lineSeparator());
            return this;
        }

        public FastOutput flush() {
            try {
                os.append(cache);
                os.flush();
                cache.setLength(0);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
            return this;
        }

        public void close() {
            flush();
            try {
                os.close();
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }

        public String toString() {
            return cache.toString();
        }

    }

    static class Node {
        List<Node> adj = new ArrayList<>();
        int id;
        int size;

        public String toString() {
            return "" + id;
        }

    }
}


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

/**
 *
 * @author brown
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.List;

public class Missbo {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] papu = (br.readLine()).split(" ");
        long limit = Long.parseLong(papu[0]);
        long counter = Long.parseLong(papu[1]);

        if (counter <= (limit + 1) / 2)
	    {
        	System.out.println(counter*2 - 1);
        }
    	else
    	{
    		System.out.println((counter - (limit + 1) / 2) * 2 );
     	}
    }
}


import java.util.Scanner;

public class Polyline {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x1 = sc.nextInt(), y1 = sc.nextInt(),
                x2 = sc.nextInt(), y2 = sc.nextInt(),
                x3 = sc.nextInt(), y3 = sc.nextInt();
        sc.close();
        int result = 1;
        if ((x1 == x2 && x2 == x3) || (y1 == y2 && y2 == y3)) result = 1;
        else
            if ((x1 == x2 && !between(y3, y1, y2)) ||
                (x2 == x3 && !between(y1, y3, y2)) ||
                (x1 == x3 && !between(y2, y1, y3)) ||
                (y1 == y2 && !between(x3, x1, x2)) ||
                (y2 == y3 && !between(x1, x2, x3)) ||
                (y3 == y1 && !between(x2, x1, x3))) result = 2;
        else result = 3;
        System.out.println(result);
    }

    static boolean between(int a, int b, int c) {
        int min = Math.min(b, c), max = Math.max(b, c);
        return a > min && a < max;
    }

}


// Author @ BlackRise :) //
// Birla Institute of Technology, Mesra//
import java.io.*;
import java.util.*;

public class ehabAndCounstructionProblem {
    static Calendar ts, te;                                                  //For time calculation
    static int mod9 = (int) 1e9 + 7;
    static Lelo input = new Lelo(System.in);
    static PrintWriter pw = new PrintWriter(System.out, true);

    public static void main(String[] args) {                                 //threading has been used to increase the stack size.

        new Thread(null, null, "BlackRise", 1<<25)  //the last parameter is stack size which is desired,
        {
            public void run() {

                try {
                    Blackrise();
                } catch (Exception e) {
                    e.printStackTrace();
                    System.exit(1);
                }
            }
        }.start();
    }

    static void Blackrise() {                                                //The name Blackrise is my pen name... you can change the name according to your wish

        tsc();                                                               //calculates the starting time of execution

        int n=ni();
        int a=n+1;
        int flag=0;
        while(a-->0 && flag==0)
        for(int i=1;i<=n && flag==0;i++)
        {
            if(a%i==0 && (a*i)>n && (i/a)<n){pl(a+ " "+i);flag=1;}

        }
        if(flag==0)pl(-1);

        tec();                  //calculates the ending time of execution
        //pwt();                //prints the time taken to execute the program
    }

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

    static class Lelo {                                              //Lelo class for fast input
        private InputStream ayega;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;

        public Lelo(InputStream ayega) {
            this.ayega = ayega;
        }

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = ayega.read(buf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

        public int nextInt() {
            int c = read();

            while (isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

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

            return res * sgn;
        }

        public long nextLong() {
            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 double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

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

    // functions to take input//
    static int ni() {
        return input.nextInt();
    }

    static long nl() {
        return input.nextLong();
    }

    static double nd() {
        return input.nextDouble();
    }

    static String ns() {
        return input.readString();
    }

    //functions to give output
    static void pl() {
        pw.println();
    }

    static void p(Object o) {
        pw.print(o + " ");
    }

    static void pws(Object o){
        pw.print(o+"");
    }

    static void pl(Object o) {
        pw.println(o);
    }

    static void tsc()                                          //calculates the starting time of execution
    {
        ts = Calendar.getInstance();
        ts.setTime(new Date());
    }

    static void tec()                                          //calculates the ending time of execution
    {
        te = Calendar.getInstance();
        te.setTime(new Date());
    }

    static void pwt()                                          //prints the time taken for execution
    {
        pw.printf("\nExecution time was :- %f s\n", (te.getTimeInMillis() - ts.getTimeInMillis()) / 1000.00);
    }
}


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;
    }

}