import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;

/**
 * @author Ivan Pryvalov (ivan.pryvalov@gmail.com)
 */
public class Codeforces_R168_Div2_A implements Runnable{

	private void solve() throws IOException {
		int[][] c = new int[3][3];
		for (int i = 0; i < c.length; i++) {
			c[i] = scanner.loadIntArray(3);
		}

		int[][] res = new int[3][3];
		for (int i = 0; i < res.length; i++) {
			for (int j = 0; j < res[i].length; j++) {
				res[i][j] = 1;
			}
		}

		for (int i = 0; i < c.length; i++) {
			for (int j = 0; j < c[i].length; j++) {
				if (c[i][j] % 2 !=0){
					for (int i2 = 0; i2 < 3; i2++) {
						res[i2][j] = 1-res[i2][j];
					}
					for (int j2 = 0; j2 < 3; j2++){
						res[i][j2] = 1-res[i][j2];
					}
					res[i][j] = 1-res[i][j];
				}
			}
		}

		for (int i = 0; i < res.length; i++) {
			for (int j = 0; j < res[i].length; j++) {
				out.print(res[i][j]);
			}
			out.println();
		}

	}

	/////////////////////////////////////////////////
	final int BUF_SIZE = 1024 * 1024 * 8;//important to read long-string tokens properly
	final int INPUT_BUFFER_SIZE = 1024 * 1024 * 8 ;
	final int BUF_SIZE_INPUT = 1024;

	final int BUF_SIZE_OUT = 1024;

	boolean inputFromFile = false;
	String filenamePrefix = "A-small-attempt0";
	String inSuffix = ".in";
	String outSuffix = ".out";

	PrintStream out;
	ByteScanner scanner;
	ByteWriter writer;

	public void run() {
		try{
			InputStream bis = null;
			OutputStream bos = null;
			//PrintStream out = null;
			if (inputFromFile){
				File baseFile = new File(getClass().getResource("/").getFile());
				bis = new BufferedInputStream(
						new FileInputStream(new File(
								baseFile, filenamePrefix+inSuffix)),
								INPUT_BUFFER_SIZE);
				bos = new BufferedOutputStream(
						new FileOutputStream(
								new File(baseFile, filenamePrefix+outSuffix)));
				out = new PrintStream(bos);
			}else{
				bis = new BufferedInputStream(System.in, INPUT_BUFFER_SIZE);
				bos = new BufferedOutputStream(System.out);
				out = new PrintStream(bos);
			}
			scanner = new ByteScanner(bis, BUF_SIZE_INPUT, BUF_SIZE);
			writer = new ByteWriter(bos, BUF_SIZE_OUT);

			solve();
			out.flush();
		}catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public interface Constants{
		final static byte ZERO = '0';//48 or 0x30
		final static byte NINE = '9';
		final static byte SPACEBAR = ' '; //32 or 0x20
		final static byte MINUS = '-'; //45 or 0x2d

		final static char FLOAT_POINT = '.';
	}

	public static class EofException extends IOException{
	}

	public static class ByteWriter implements Constants {

		int bufSize = 1024;
		byte[] byteBuf = new byte[bufSize];
		OutputStream os;

		public ByteWriter(OutputStream os, int bufSize){
			this.os = os;
			this.bufSize = bufSize;
		}

		public void writeInt(int num) throws IOException{
	         int byteWriteOffset = byteBuf.length;
	         if (num==0){
	        	 byteBuf[--byteWriteOffset] = ZERO;
	         }else{
	        	 int numAbs = Math.abs(num);
	        	 while (numAbs>0){
	        		 byteBuf[--byteWriteOffset] = (byte)((numAbs % 10) + ZERO);
	        		 numAbs /= 10;
	        	 }
	        	 if (num<0)
	        		 byteBuf[--byteWriteOffset] = MINUS;
	         }
	         os.write(byteBuf, byteWriteOffset, byteBuf.length - byteWriteOffset);
		}

		/**
		 * Please ensure ar.length <= byteBuf.length!
		 *
		 * @param ar
		 * @throws IOException
		 */
		public void writeByteAr(byte[] ar) throws IOException{
			for (int i = 0; i < ar.length; i++) {
				byteBuf[i] = ar[i];
			}
			os.write(byteBuf,0,ar.length);
		}

		public void writeSpaceBar() throws IOException{
			byteBuf[0] = SPACEBAR;
			os.write(byteBuf,0,1);
		}

	}

	public static class ByteScanner implements Constants{

		InputStream is;

		public ByteScanner(InputStream is, int bufSizeInput, int bufSize){
			this.is = is;
			this.bufSizeInput = bufSizeInput;
			this.bufSize = bufSize;

			byteBufInput = new byte[this.bufSizeInput];
			byteBuf = new byte[this.bufSize];
		}

		public ByteScanner(byte[] data){
			byteBufInput = data;
			bufSizeInput = data.length;
			bufSize = data.length;
			byteBuf = new byte[bufSize];
			byteRead = data.length;
			bytePos = 0;
		}

		private int bufSizeInput;
		private int bufSize;

		byte[] byteBufInput;
		byte by=-1;
		int byteRead=-1;
		int bytePos=-1;

		byte[] byteBuf;
		int totalBytes;

		boolean eofMet = false;

		private byte nextByte() throws IOException{

			if (bytePos<0 || bytePos>=byteRead){
				byteRead = is==null? -1: is.read(byteBufInput);
				bytePos=0;
				if (byteRead<0){
					byteBufInput[bytePos]=-1;//!!!
					if (eofMet)
						throw new EofException();
					eofMet = true;
				}
			}
			return byteBufInput[bytePos++];
		}

		/**
		 * Returns next meaningful character as a byte.

		 *
		 * @return
		 * @throws IOException
		 */
		public byte nextChar() throws IOException{
			while ((by=nextByte())<=0x20);
			return by;
		}

		/**
		 * Returns next meaningful character OR space as a byte.

		 *
		 * @return
		 * @throws IOException
		 */
		public byte nextCharOrSpacebar() throws IOException{
			while ((by=nextByte())<0x20);
			return by;
		}

	    /**
	     * Reads line.
	     *
	     * @return
	     * @throws IOException
	     */
	    public String nextLine() throws IOException {
            readToken((byte)0x20);
            return new String(byteBuf,0,totalBytes);
	    }

	    public byte[] nextLineAsArray() throws IOException {
            readToken((byte)0x20);
            byte[] out = new byte[totalBytes];
            System.arraycopy(byteBuf, 0, out, 0, totalBytes);
            return out;
	    }

	    /**
	     * Reads token. Spacebar is separator char.
	     *
	     * @return
	     * @throws IOException
	     */
	    public String nextToken() throws IOException {
            readToken((byte)0x21);
            return new String(byteBuf,0,totalBytes);
	    }

	    /**
	     * Spacebar is included as separator char
	     *
	     * @throws IOException
	     */
	    private void readToken() throws IOException {
            readToken((byte)0x21);
	    }

	    private void readToken(byte acceptFrom) throws IOException {
            totalBytes = 0;
            while ((by=nextByte())<acceptFrom);
            byteBuf[totalBytes++] = by;
            while ((by=nextByte())>=acceptFrom){
                byteBuf[totalBytes++] = by;
            }
	    }

	    public int nextInt() throws IOException{
			readToken();
			int num=0, i=0;
			boolean sign=false;
			if (byteBuf[i]==MINUS){
				sign = true;
				i++;
			}
			for (; i<totalBytes; i++){
				num*=10;
				num+=byteBuf[i]-ZERO;
			}
			return sign?-num:num;
		}

		public long nextLong() throws IOException{
			readToken();
			long num=0;
			int i=0;
			boolean sign=false;
			if (byteBuf[i]==MINUS){
				sign = true;
				i++;
			}
			for (; i<totalBytes; i++){
				num*=10;
				num+=byteBuf[i]-ZERO;
			}
			return sign?-num:num;
		}

		/*
		//TODO test Unix/Windows formats
		public void toNextLine() throws IOException{
			while ((ch=nextChar())!='\n');
		}
		*/

		public double nextDouble() throws IOException{
			readToken();
			char[] token = new char[totalBytes];
			for (int i = 0; i < totalBytes; i++) {
				token[i] = (char)byteBuf[i];
			}
			return Double.parseDouble(new String(token));
		}

		public int[] loadIntArray(int size) throws IOException{
			int[] a = new int[size];
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public long[] loadLongArray(int size) throws IOException{
			long[] a = new long[size];
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
			return a;
		}

	}

	public static abstract class Timing{
		private static int counter = 0;
		protected String name = "Timing"+(++counter);
		private boolean debug;

		public Timing(boolean debug) {
			super();
			this.debug = debug;
		}

		public abstract void run();
		public void start(){
			long time1 = System.currentTimeMillis();
			run();
			long time2 = System.currentTimeMillis();
			if (debug)
				System.out.println(name+" time = "+(time2-time1)/1000.0+" ms.");
		}

	}

	public static class Alg{
		public static interface BooleanChecker{
			public boolean check(long arg);
		}

		public static class BinarySearch{

			/**
			 * This check returns boolean value, result of function.
			 * It should be monotonic.
			 *
			 * @return
			 */
			public BooleanChecker bc;

			/**
			 * Returns following element:
 0 0 [1] 1 1

			 */
			public long search(long left, long right){
				while (left<=right){
					long mid = (left+right)/2;
					if (bc.check(mid)){
						right = mid-1;
					}else{
						left = mid+1;
					}
				}
				return left;
			}

			/**
			 * Optional.

			 * Returns following element:
 1 1 [1] 0 0

			 */
			public long searchInverted(long left, long right){
				while (left<=right){
					long mid = (left+right)/2;
					if (!bc.check(mid)){
						right = mid-1;
					}else{
						left = mid+1;
					}
				}
				return left - 1;
			}
		}
	}

	public static class Modulo{
		long mod = (long)1e9+7;

		public Modulo(long mod) {
			super();
			this.mod = mod;
		}

		public long inv(int a) {
			long res =  pow(a, mod-2);
			return res;
		}

		public long pow(long a, long x) {
			if (x==0)
				return 1;
			long part = 1;
			if ((x&1)!=0)
				part = a;
			return (part * pow((a*a)%mod, x>>1)) % mod;
		}

	}

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

}


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

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

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

    Map<Integer, Integer> map = new HashMap<>();

    int[] num = new int[N];
    List<Integer>[] G = new List[N];

    int tot = 0;
    boolean[] vis = new boolean[N];

    void solve() {
        int n = in.nextInt(), m = in.nextInt();
        int[] fr = new int[m], to = new int[m];
        for (int i = 0; i < m; i++) {
            fr[i] = in.nextInt();
            to[i] = in.nextInt();
        }

        int d = 0;
        while ((1 << d) <= n) d++;

        getId(1);
        for (int i = 0; i < m; i++) {
            int u = fr[i];
            while (u > 0) {
                getId(u);
                u >>= 1;
            }
            u = to[i];
            while (u > 0) {
                getId(u);
                u >>= 1;
            }
        }

        for (int i = 0; i < N; i++) G[i] = new ArrayList<>();
        for (int u : map.keySet()) {
            int id = map.get(u);
            if (u > 1) {
                addEdge(getId(u), getId(u >> 1));
            }
            num[id] = calcSize(u, n, d);
        }

        dfs(0, -1);

        for (int i = 0; i < m; i++) {
            addEdge(getId(fr[i]), getId(to[i]));
        }

        int res = 0;
        for (int i = 0; i < map.size(); i++) {
            tot = 0;
            dfs(i);
            res = (int) ((res + (long) tot * num[i] % MOD) % MOD);
        }
        out.println(res);
    }

    int getId(int x) {
        if (!map.containsKey(x)) map.put(x, map.size());
        return map.get(x);
    }

    void addEdge(int u, int v) {
        G[u].add(v);
        G[v].add(u);
    }

    int calcSize(int u, int n, int d) {
        int t = u, c = 0;
        while (t > 0) {
            c++;
            t >>= 1;
        }
        int sz = (1 << (d - c + 1)) - 1;
        t = c;
        while (t < d) {
            t++;
            u = u << 1 | 1;
        }
        return sz - Math.max(0, Math.min(u - n, 1 << (d - c)));
    }

    void dfs(int u, int p) {
        for (int v : G[u]) {
            if (v != p) {
                num[u] -= num[v];
                dfs(v, u);
            }
        }
    }

    void dfs(int u) {
        tot = (tot + num[u]) % MOD;
        vis[u] = true;
        for (int v : G[u]) {
            if (!vis[v]) dfs(v);
        }
        vis[u] = false;
    }

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

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

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

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

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

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

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


import java.util.Scanner;

public class Solution {
  public static void main(String... args) {
    Scanner ins = new Scanner(System.in);
    int v3 = ins.nextInt(),
      v2 = ins.nextInt(),
      v1 = ins.nextInt(),
      vm = ins.nextInt();

    int c1 = get_min_like(v1, vm);
    if(c1 == -1) {
      System.out.println(-1);
      return;
    }

    int c2 = get_min_dislike(v2, vm, c1 + 1);
    if(c2 == -1) {
      System.out.println(-1);
      return;
    }

    int c3 = get_min_dislike(v3, vm, c2 + 1);
    if(c3 == -1) {
      System.out.println(-1);
      return;
    }

    System.out.printf("%d%n%d%n%d%n", c3, c2, c1);
  }

  static int get_min_like(int v1, int v2) {
    int start = Math.max(v1, v2),
      end = Math.min(2 * v1, 2 * v2);
    if(end < start) return -1;
    return start;
  }

  static int get_min_dislike(int v1, int v2, int lower) {
    int start = Math.max(v1, Math.max(2 * v2 + 1, lower)),
      end = 2 * v1;
    if(end < start) return -1;
    return start;
  }
}


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

public class Main {
  Scanner sc;

  void run() {
    int n = ni();
    int[] mins = new int[3];
    int[] maxs = new int[3];

    for(int i = 0; i < 3; ++i) {
      mins[i] = ni();
      maxs[i] = ni();
    }

    int[] anss = new int[3];
    for(int i = mins[0]; i <= maxs[0]; ++i) {
      for(int j = mins[1]; j <= maxs[1]; ++j) {
        for(int k = mins[2]; k <= maxs[2]; ++k) {
          if(i + j + k == n) {
            if( anss[1] < j ) {
              anss[0] = i;
              anss[1] = j;
              anss[2] = k;
            } else if( anss[1] == j ) {
              if( anss[2] < k ) {
                anss[0] = i;
                anss[2] = k;
              }
            }
          }
        }
      }
    }

    for(int i = 0; i < 3; ++i) {
      if( i > 0 ) {
        System.out.print(" ");
      }
      System.out.print(anss[i]);
    }
    System.out.println();
  }

  Main() {
    sc = new Scanner(System.in);
  }

  int ni() {
    return sc.nextInt();
  }

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

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


import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int min1 = scanner.nextInt(), max1 = scanner.nextInt();
        int min2 = scanner.nextInt(), max2 = scanner.nextInt();
        int min3 = scanner.nextInt(), max3 = scanner.nextInt();
        String output = "";
        for (int z = max3; z >= min3; z--) {
            for (int y = max2; y >= min2; y--) {
                for (int x = max1; x >= min1; x--) {
                    if (x + y + z == n) {
                        output = "" + x + " " + y + " " + z;
                    }
                }
            }
        }
        System.out.print(output);
    }
}


package cf1;

import java.util.Scanner;

public class cf2 {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		 int a=s.nextInt();
			int b=s.nextInt();
			int c=s.nextInt();
			for(int j=b;j>0;j--) {
				if(j+1<=c&&j-1<=a) {
					System.out.println(j*3);
				}
				break;
			}

	}

}


import java.util.*;
public class B55 {
    int add;
    static int multy;
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);

        long ar [] = new long [4];
        for (int i = 0; i<4; i++){
            ar[i] = sc.nextLong();
        }
        int[]act = new int[3];
        int add = 0;
        int multy = 0;
        for (int i = 0; i<3; i++){
            String S = sc.next();
            if (S.equals("+")){act[i]=1; add++;}
            if (S.equals("*")){act[i]=2; multy++;}
        }
        System.out.println( count(act, ar[0], ar[1], ar[2], ar[3], multy) );
    }

    public static long count(int[]act, long A, long B, long C, long D, int multy){
        ArrayList<Long>f = new ArrayList<Long>();
        f.add(A);
        f.add(B);
        f.add(C);
        f.add(D);

        if (multy<=1){
            for (int i = 0; i<3; i++){
                if (act[i]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
                if (act[i]==2){Collections.sort(f);  f.set(0, f.get(0) * f.remove(1) );}
            }
        }
        if (act[0]==2 && act[1]==2){

                if (act[0]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
                if (act[0]==2){
                    Collections.sort(f);
                    f.set(0, f.get(0) * f.remove(f.size()-1));
                    //System.out.println(f.get(0));
                }

                if (act[1]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
                if (act[1]==2){
                    Collections.sort(f);
                    f.set(0, f.remove(0) * f.get(0));
                }

                if (act[2]==1){f.set(0, f.get(0) + f.remove(1) );}
                if (act[2]==2){
                    Collections.sort(f);
                    f.set(0, f.get(0) * f.remove(1));
                }
        }

        if (act[0]==2 && act[2]==2){

            Collections.sort(f);
            f.set(1, f.get(1) * f.remove(2));

            if (act[1]==1){f = mySort(f); f.set(0, f.remove(0) + f.get(0) );}
            if (act[1]==2){
                Collections.sort(f);
                f.set(0, f.remove(0) * f.get(0));
            }
            Collections.sort(f);
            f.set(0, f.get(0) * f.remove(1));
        }
        return f.get(0);
    }
    public static ArrayList<Long> mySort(ArrayList<Long>A){
        ArrayList<Long> G = new ArrayList<Long>();
        Collections.sort(A);
        while (A.size()!=0){
            G.add( A.remove(A.size()-1) );
        }
//      for (int i = 0; i<G.size(); i++){
//          System.out.println(G.get(i));
//      }
        return G;
    }
}
// by Ronex)


import java.util.*;
public class codecraftIII
{
  public static void main(String[] args)
  {
    Scanner sc = new Scanner(System.in);
    String month = sc.next();
    int n = sc.nextInt();
    String[] months = new String[] {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
    for(int i=0 ;i < months.length; i++)
    {
      if (month.equals(months[i]) && (n+i) <= (months.length-1))
      {
        System.out.println(months[i+n]);
        break;
      }
      else if (month.equals(months[i]) && (n+i) > (months.length))
      {
        while (n>12)
        {
          n = n -12;
        }
        System.out.println(months[n-(months.length-1-i)-1]);
        break;
      }
    }
  }
  //so hard much wow
}


import java.util.Scanner;
public class Demo
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int z = sc.nextInt();
		System.out.print(x > y+z ? "+" : (y > x+z ? "-" : x == y && x > z ? "0" : "?"));
	}
}


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

public class C {

    HashSet <Character> set = new HashSet<Character>();
    int ss;
    private void solve() throws IOException {
        int n = Integer.parseInt(stdin.readLine());
        this.ss = n;
        String s_ = stdin.readLine();
        this.s = s_;
        int q = countQuestions(s_);
        visited = new boolean[27];
        res_ = new char[q];
        int K = q;
        this.k = K;
        dfs(0 , K);
        Collections.sort(a);
        try{
        System.out.println(a.get(0));
        }catch(Exception e){
            System.out.println("IMPOSSIBLE");
        }
    }

    private boolean checkPalin(String s){
        int k = s.length();
        for (int i = 0; i < k; i++) {
            int a =(int)s.charAt(i);
            int b =(int)s.charAt( k - i -1);
            if (a != b)
                return false;
        }
        return true;
    }
    boolean [] visited;
    int k;
    String s;
    ArrayList <String> a = new ArrayList <String>();
    char [] res_;
    String result = "";
    private void dfs(int i ,int k){
        if (i == k){
            //System.out.println(res_);
            String changed = changeChar(s, res_);
            if (checkPalin(changed)){
                if (check(changed , ss)){
                        a.add(changed);
                }
            }
        }else{
            for (int j = 1; j <= 26; j++) {
                //if (visited[j])continue;
                res_[i] = (char)(j+'a' - 1);
                //visited[j] = true;
                dfs(i+1 , k);
                //visited[j] = false;
            }
        }
    }
    private String changeChar(String s , char [] a){
        int count = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i)=='?'){
                s = ChangeChars(s, i, a[count++]);
            }
        }
        return s;
    }
    private String ChangeChars(String s , int index , char NEW){
        return s.substring(0 , index )+NEW+s.substring(index+1);
    }
    private boolean check(String s , int n){
        for (int i = 0; i < s.length(); i++) {
            set.add(s.charAt(i));
        }
        if (n == set.size()){
            set.clear();
            return true;
        }
        set.clear();
        return false;
    }
    private int countQuestions(String s){
        int res = 0;
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i)=='?')
                res++;
        }
        return res;
    }
    public static void main(String[] args) throws IOException {
        new C().run1();
    }

    BufferedReader stdin;
    PrintWriter out;

    public void run1() throws IOException {
        stdin = new BufferedReader(new InputStreamReader(System.in));
        solve();
        stdin.close();
    }

    public void run2() throws IOException {
        stdin = new BufferedReader(new FileReader(".in"));
        out = new PrintWriter(new BufferedWriter(new FileWriter(".out")));
        solve();
        out.close();
        stdin.close();
    }
}


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

public class ProblemE {

	public static int[][][] dp = new int[65536][2][257];
	public static int n = -1;
	public static ArrayList<Card> modCards = new ArrayList<Card>();
	public static int goal = -1;

	public static void main(String[] args) throws Exception {
		for(int i=0; i<65536; i++) {
			for(int j=0; j<257; j++) {
				dp[i][0][j] = -1;
				dp[i][1][j] = -1;
			}
		}

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		n = Integer.parseInt(br.readLine());
		goal = (1 << n) - 1;

		String[][] cards = new String[n][3];
		for(int i=0; i<n; i++) {
			cards[i] = br.readLine().split(" ");
		}

		int minRedCost = 0;
		int minBlueCost = 0;

		for(int i=0; i<n; i++) {
			boolean isRed;
			int redCost;
			int blueCost;
			if(cards[i][0].equals("R"))
				isRed = true;
			else
				isRed = false;
			redCost = Integer.parseInt(cards[i][1]);
			blueCost = Integer.parseInt(cards[i][2]);

			if(redCost > n) {
				minRedCost += (redCost - n);
				redCost = n;
			}
			if(blueCost > n) {
				minBlueCost += (blueCost - n);
				blueCost = n;
			}

			modCards.add(new Card(isRed, redCost, blueCost));
		}

		long minTurns;
		long sol;

		if(minRedCost > minBlueCost) {
			minTurns = minRedCost;
			int otherAmount = Math.min(minRedCost - minBlueCost, 256);
			sol = solve(0, 1, otherAmount);
		} else {
			minTurns = minBlueCost;
			int otherAmount = Math.min(minBlueCost - minRedCost, 256);
			sol = solve(0, 0, otherAmount);
		}

		System.out.println(minTurns + sol);
	}

	public static int solve(int mask, int redIsZero, int otherCount) {
		if(dp[mask][redIsZero][otherCount] != -1)
			return dp[mask][redIsZero][otherCount];

		if(mask == goal)
			return 0;

		int selector = 1;
		int redDiscount = 0;
		int blueDiscount = 0;
		for(int i=0; i<n; i++) {
			if((mask & selector) > 0) {
				if(modCards.get(i).isRed)
					redDiscount++;
				else
					blueDiscount++;
			}
			selector = selector << 1;
		}

		int min = 1000000007;
		selector = 1;
		for(int i=0; i<n; i++) {
			if((mask & selector) == 0) {
				int cand;
				int redPrice = Math.max(modCards.get(i).redCost - redDiscount, 0);
				int bluePrice = Math.max(modCards.get(i).blueCost - blueDiscount, 0);
				int turns = 1;
				int curRed;
				int curBlue;
				if(redIsZero == 1) {
					curRed = 0;
					curBlue = otherCount;
				} else {
					curRed = otherCount;
					curBlue = 0;
				}

				if(redPrice - curRed > bluePrice - curBlue) {
					turns += redPrice - curRed;
					int remBlue = curBlue + redPrice - curRed - bluePrice;
					cand = turns + solve(mask | selector, 1, remBlue);
				} else {
					turns += bluePrice - curBlue;
					int remRed = curRed + bluePrice - curBlue - redPrice;
					cand = turns + solve(mask | selector, 0, remRed);
				}
				if(cand < min)
					min = cand;
			}
			selector = selector << 1;
		}
		dp[mask][redIsZero][otherCount] = min;
		return dp[mask][redIsZero][otherCount];
	}

}

class Card {
	public boolean isRed;
	public int redCost;
	public int blueCost;
	public Card(boolean col, int red, int blue) {
		isRed = col;
		redCost = red;
		blueCost = blue;
	}
}


import java.util.*;

public class PrviZadatak {

    public static void main(String[] args) {
        String rec,test;
        int provera1,provera2,provera3;
        char prvo;
        Scanner unos = new Scanner(System.in);
        rec = unos.nextLine();
        provera1 = cekiranjeVelikoSve(rec);
        provera2 = cekiranjePrvoMalo(rec);
        provera3 = cekiranjeJednoSlovo(rec);
        if(provera1 == 1 || provera2 == 1 || provera3 == 1)
            sredjenIspis(rec);
        else
            ispis(rec);

}

public static int cekiranjeVelikoSve(String rec){
    int resenje=0,pitanje,duzina;
    char slovo;
    duzina = rec.length();
    if(duzina!=1){
        loops:
        for(int i=0;i<=duzina;i++){
            slovo = rec.charAt(0);
            pitanje=slovo;
            rec = rec.substring(1);
            if(pitanje >= 65 && pitanje <=90){
                resenje=1;
            }else{
                resenje=0;
                break loops;
            }
        }
    }else
        resenje=0;
    return resenje;
}

public static int cekiranjePrvoMalo(String rec){
    int resenje=0,pitanje,duzina;
    char slovo;
    duzina = rec.length();
    if(duzina!=1){
        slovo = rec.charAt(0);
        rec = rec.substring(1);
        pitanje = slovo;
        if(pitanje >= 97 && pitanje <= 122){
            resenje = cekiranjeVelikoSve(rec);
        }else
            resenje = 0;
    }else
        resenje = 0;
    return resenje;
}

public static void ispis(String rec){
    System.out.println(rec);
}

public static void sredjenIspis(String rec){
    char slovo;
    int duzina;
    duzina = rec.length();
    if(duzina!=1){
        rec = rec.toUpperCase();
        slovo = rec.charAt(0);
        rec = rec.substring(1);
        rec = rec.toLowerCase();
        System.out.println(slovo + rec);
    }else{
        rec = rec.toUpperCase();
        System.out.println(rec);
    }
}
public static int cekiranjeJednoSlovo(String rec){
    int resenje=0,duzina;
    duzina = rec.length();
    if (duzina == 1)
        resenje = 1;
    else
        resenje = 0;
    return resenje;
}
}


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

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        int[] fib = new int[n + 1];
        fib[1] = 1;
        fib[2] = 1;
        for (int i = 3; i <= n; i++)
            fib[i] = add(fib[i - 1], fib[i - 2]);
        int den = modPow(2, n);
        out.println(mult(fib[n], modPow(den, mod - 2)));
        out.flush();
        out.close();
    }

    static final int mod = 998244353;

    static int add(int a, int b) {
        long c = a + b;
        if (c >= mod) c -= mod;
        if (c < 0) c += mod;
        return (int) c;
    }

    static int mult(long a, int b) {
        return (int) ((a * b) % mod);
    }

    static int modPow(int b, int e) {
        int res = 1;
        while (e > 0) {
            if ((e & 1) == 1) res = mult(res, b);
            b = mult(b, b);
            e >>= 1;
        }
        return res;
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

        public Scanner(String s) throws FileNotFoundException {
            br = new BufferedReader(new FileReader(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 int[] nextIntArray(int n) throws IOException {
            int[] ans = new int[n];
            for (int i = 0; i < n; i++)
                ans[i] = nextInt();
            return ans;
        }

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

    }
}


//package codeforces;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;

public class A implements Closeable {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

    A() throws IOException {
//        reader = new BufferedReader(new FileReader("input.txt"));
//        writer = new PrintWriter(new FileWriter("output.txt"));
    }

    StringTokenizer stringTokenizer;

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

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

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

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

    private int MOD = 1000 * 1000 * 1000 + 7;

    int sum(int a, int b) {
        a += b;
        return a >= MOD ? a - MOD : a;
    }

    int product(int a, int b) {
        return (int) (1l * a * b % MOD);
    }

    int pow(int x, int k) {
        int result = 1;
        while (k > 0) {
            if (k % 2 == 1) {
                result = product(result, x);
            }
            x = product(x, x);
            k /= 2;
        }
        return result;
    }

    int inv(int x) {
        return pow(x, MOD - 2);
    }

    void solve() throws IOException {
        final int x = nextInt(), y = nextInt(), n = nextInt();
        class Fraction implements Comparable<Fraction> {
            BigInteger a, b;

            public Fraction(long a, long b) {
                this.a = BigInteger.valueOf(a);
                this.b = BigInteger.valueOf(b);
            }

            public Fraction(BigInteger a, BigInteger b) {
                this.a = a;
                this.b = b;
            }

            Fraction distTo(Fraction other) {
                return new Fraction(other.a.multiply(b).subtract(other.b.multiply(a)).abs(), other.b.multiply(b));
            }

            @Override
            public int compareTo(Fraction o) {
                return a.multiply(o.b).compareTo(b.multiply(o.a));
            }

            @Override
            public String toString() {
                return a + "/" + b;
            }
        }
        List<Fraction> fractions = new ArrayList<>(2 * n);
        for(int b = 1; b <= n; b++) {
            long a = 1l * x * b / y;
            fractions.add(new Fraction(a, b));
            fractions.add(new Fraction(a + 1, b));
        }
        final Fraction foo = new Fraction(x, y);
        Collections.sort(fractions, new Comparator<Fraction>() {
            @Override
            public int compare(Fraction o1, Fraction o2) {
                Fraction dist1 = o1.distTo(foo);
                Fraction dist2 = o2.distTo(foo);
                int cmp = dist1.compareTo(dist2);
                if(cmp == 0) {
                    cmp = o1.b.compareTo(o2.b);
                    if(cmp == 0) {
                        return o1.a.compareTo(o2.a);
                    }
                    return cmp;
                }
                return cmp;
            }
        });
        writer.println(fractions.get(0));
    }

    public static void main(String[] args) throws IOException {
        try (A a = new A()) {
            a.solve();
        }
    }

    @Override
    public void close() throws IOException {
        reader.close();
        writer.close();
    }
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author captainTurtle
 */
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();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int gün = 0;
            in.nextLine();
            int[] an = new int[n];
            for (int i = 0; i < n; i++) {
                an[i] = in.nextInt();
            }
            for (int x = 0; x < n; x++) {
                if (an[x] >= 8 && n * 8 >= k) {
                    k = k - 8;
                    gün = gün + 1;
                    an[x + 1] = an[x + 1] + an[x] - 8;
                    if (k <= 0) {
                        System.out.print(gün);
                        break;
                    }
                } else if (an[x] < 8) {
                    k = k - an[x];
                    gün = gün + 1;
                    if (k <= 0) {
                        System.out.print(gün);
                        break;
                    }
                } else if (n * 8 < k) {
                    System.out.print(-1);
                    break;
                }
            }

        }

    }
}


package com.company;

import java.io.*;
import java.lang.reflect.Array;
import java.nio.Buffer;
import java.util.*;

public class Pair {

    public static  void main (String[] args) throws Exception{
        try {
            Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
            int n = sc.nextInt();
            int k = sc.nextInt();
            int a = 0;
            int b = 0;
            for(int i=1;i<=n;i++){
                a+=sc.nextInt();
                int can = Math.min(a,8);
                b+=can;
                a-=can;
                if(b>=k){
                    System.out.println(i);
                    sc.close();
                    return;
                }
            }
            System.out.println("-1");
        }
        catch(Exception e){

        }
    }
}


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

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

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            for (int test = 1; ; test++) {
                int n = in.nextInt();
                int D = in.nextInt();
                if (n == 0 && D == 0) {
                    break;
                }
                out.println("@" + test);
                final double r = 1;
                Point pl = new Point(-D, 0);
                Point pr = new Point(+D, 0);
                for (int i = 0; i < n; i++) {
                    int sl = in.nextInt();
                    int sr = in.nextInt();
                    double vl = sl / 180.0 * Math.PI * r;
                    double vr = sr / 180.0 * Math.PI * r;
                    int t = in.nextInt();
                    if (sl == sr) {
                        Point v = pr.sub(pl).rotate(Math.PI / 2).norm().scale((vl + vr) * 0.5 * t);
                        pl = pl.add(v);
                        pr = pr.add(v);
                        continue;
                    }
                    double x = D * (vl + vr) / (vl - vr);
//                double x = D * (vl + vr) / (vr - vl);
                    Point o = pl.add(pr).scale(0.5);
                    Point ox = o.add(pr.sub(o).norm().scale(x));
//                out.println("!" + cross(ox,pr.sub(pl)));

                    Point nl = pl.sub(ox);
                    Point nr = pr.sub(ox);
//                nl=nl.scale(-1);
//                nr=nr.scale(-1);
                    double wl = vl / nl.length();
                    double wr = vr / nr.length();
//                if (x < D && x > -D) {
//                    wr = -wr;
//                }
//                out.println(wl + " " + wr);
                    nl = nl.rotate(wl * t);
                    nr = nr.rotate(wr * t);

                    pl = nl.add(ox);
                    pr = nr.add(ox);
                }
                Point p = pl.add(pr).scale(0.5);
                out.printf("%.10f\n", p.x);
                out.printf("%.10f\n", p.y);
            }
        }

        class Point {
            double x;
            double y;

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

            Point add(Point o) {
                return new Point(x + o.x, y + o.y);
            }

            Point sub(Point o) {
                return new Point(x - o.x, y - o.y);
            }

            Point rotate(double alpha) {
                double c = Math.cos(alpha);
                double s = Math.sin(alpha);
                double nx = x * c - y * s;
                double ny = x * s + y * c;
                return new Point(nx, ny);
            }

            Point norm() {
                double len = length();
                return scale(1.0 / len);
            }

            Point scale(double f) {
                return new Point(f * x, f * y);
            }

            double length() {
                return Math.sqrt(x * x + y * y);
            }

            public String toString() {
                return String.format("%.2f %.2f", x, y);
            }

        }

    }

    static class FastScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public FastScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

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

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

    }
}


import static java.lang.Math.*;
import static java.lang.System.currentTimeMillis;
import static java.lang.System.exit;
import static java.lang.System.arraycopy;
import static java.util.Arrays.sort;
import static java.util.Arrays.binarySearch;
import static java.util.Arrays.fill;
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Main().run();
	}

	BufferedReader in;
	PrintWriter out;
	StringTokenizer st = new StringTokenizer("");
	char[][] grid;
	boolean[][] used;
	int n, m;
	int[] dx = { -1, 0, 1, 0 };
	int[] dy = { 0, 1, 0, -1 };
	int ans = 0;

	private void run() throws IOException {
		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);

		n = nextInt();
		m = nextInt();
		grid = new char[n][m];
		used = new boolean[n][m];
		for (int i = 0; i < n; i++)
			grid[i] = nextLine().toCharArray();
		dfs(0);
		out.println(ans);

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

	private void dfs(int c) {
		if (c == n * m) {
			int num = 0;
			for (int j = 0; j < n; j++)
				for (int k = 0; k < m; k++)
					if (grid[j][k] == 'P' && used[j][k])
						num++;
			ans = max(ans, num);
			return;
		}
		for (int i = c; i < n * m; i++) {
			if (grid[i / m][i % m] == 'W') {
				int i1 = i / m;
				int j1 = i % m;
				for (int j = 0; j < 4; j++) {
					i1 += dx[j];
					j1 += dy[j];
					if (i1 >= 0 && i1 < n && j1 >= 0 && j1 < m && !used[i1][j1] && grid[i1][j1] == 'P') {
						used[i1][j1] = true;
						dfs((i1 - dx[j]) * m + j1 - dy[j] + 1);
						used[i1][j1] = false;
					}
					i1 -= dx[j];
					j1 -= dy[j];
				}
			}
			if (i == n * m - 1) {
				int num = 0;
				for (int j = 0; j < n; j++)
					for (int k = 0; k < m; k++)
						if (grid[j][k] == 'P' && used[j][k])
							num++;
				ans = max(ans, num);
				return;
			}
		}
	}

	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


import java.util.Scanner;

public class New_Year_Candles {
	public static void main(String[]args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();

		int rem=0;

		int out = a;
		while(a>1) {
			out+=(a/b);
			rem=a%b;

			a/=b;
			a+=rem;

		}
		System.out.println(out+rem);
	}
}


import java.util.*;

public class CODE {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int n = sc.nextInt();
        int m = sc.nextInt();
        int sum = 0;
        while (n != 0) {
            sum += n;
            n = n / m + n % m;
        }
        System.out.println(sum);

    }
}


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

public  class abcd
{
	public static void main (String[] args) throws java.lang.Exception
	{

        Scanner s=new Scanner(System.in);
        long n=s.nextLong();

 long k=s.nextLong();
 StringBuffer sb=new StringBuffer();
 for(int i=1;i<=n;i++){
     if(i%2!=0){
         sb.append(i);
     }
 }for(int i=2;i<=n;i++){
     if(i%2==0){
         sb.append(i);
     }
 }System.out.println(sb.charAt((int)(k-1)));

}}


import java.util.Scanner;

public class JavaApplication191 {

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

        int sum=0;
        int i = 1;
        int height = 1;
         boolean flag = false;
         boolean decrease=false;
        while (true)
        {

            for ( ;i<=height;i++)
            {

                for (int j =i ; j>=0;j--)
                {
                    sum+=j;
                    if (sum==input)
                    {
                        if(j-1>0)decrease=true;
                        flag=true;
                        break;
                    }

                }
             if (flag)break;
            }
            if (flag)break;
            height++;
        }
        if (decrease){height=height-1;}
        System.out.println(height);

}
}


import java.util.Scanner;
import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;
import static java.lang.Math.*;

public class Main implements Runnable{

    static LinkedList <Integer> adj[];
    static int co=0;

    static void Check2(int n){
        adj=new LinkedList[n+1];
        for(int i=0;i<=n;i++){
            adj[i]=new LinkedList();
        }

    }
    static void add(int i,int j){
        adj[i].add(j);

    }
    public static void main(String[] args) throws Exception {
        new Thread(null, new Main(), "Check2", 1<<26).start();// to increse stack size in java
    }
    public void run(){
        /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution. */
        //Scanner in=new Scanner(System.in);
        InputReader in=new InputReader(System.in);
        PrintWriter w=new PrintWriter(System.out);

        long pr[]=new long[50000001];

        for(int i=2;i<=5000000;i++){
            if(pr[i]==0){
                pr[i]=i;
                for(int j=2*i;j<=5000000;j+=i){
                   if(pr[j]==0)pr[j]=i;

                }
            }

        }

        long ans[]=new long[5000001];
        long mod=(long)(1e9+7);

        for(int i=2;i<=5000000;i++){
            if(pr[i]==i){
                long p=(long)(i)*(long)(i-1);
                p=p/2;
                p%=mod;
                ans[i]=p;
            }
            else{
                long r=i/(pr[i]);

                long tp=(long)(pr[i])*(long)(pr[i]-1);

                tp/=2;
                tp=tp*r;
                tp=(tp%mod+ans[(int)r]%mod)%mod;
                ans[i]=tp;

            }
        }
        long t=in.nextLong();
        int l=in.nextInt();
        int r=in.nextInt();
        long mul=1l;
        long sum=0;
        for(int i=l;i<=r;i++){
            sum=sum%mod+(mul*(long)ans[i])%mod;
            sum%=mod;
      //      w.println(sum);
            mul=(mul*t)%mod;
        }
        w.println(sum);

        w.close();

    }
    static int bs(ArrayList <Integer> list,int x){

        int l=0;
        int r=list.size()-1;

        int ans=0;
        while(l<=r){
            int mid=(l+r)/2;

            if(list.get(mid)>=x){
                ans=mid;
                r=mid-1;
            }
            else
                l=mid+1;

        }

        return ans;

    }

static  long dp[][];
    static long mod=(long)(1e9+7);
    static long rec(int i,long m,int n,long a[]){

        if(i>n)return 0;
            if(i==n){
                if(m==0)return 1;
                else
                    return 0;
            }

        long ans=0;

        ans=ans+rec(i+1,(m*10+a[i])%8,n,a);

        ans=ans+rec(i+1,m,n,a);
        ans%=mod;
        return dp[i][(int)m]=ans;

    }

static int flag=0;
    static  ArrayList <Integer> flist;
    static void dfs(int i,int v[],ArrayList <Integer> list){

        if(v[i]==0){

            v[i]=1;
            list.add(i);
            Iterator <Integer>p=adj[i].iterator();
            while(p.hasNext()){
                Integer ne=p.next();
                if(list.contains(ne)){

                    for(Integer pq:list){
                       // System.out.println(i+" "+pq+" "+ne);
                        flist.add(pq);
                    }
                    flag=1;
                }
       dfs(ne,v,list);

           }

           list.remove(new Integer(i));

 }

    }
    static class node{

        int y;
        int val;

        node(int a,int b){

            y=a;
            val=b;

        }

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

}


import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.util.*;

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);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
}

class Task {

    //    static int MAX = 1000001;
//    List<List<Integer>> g = new ArrayList<>();
//    int n;
//    char[] s;

    public void solve(Scanner in, PrintWriter out) {
        int t = in.nextInt();
        int l = in.nextInt();
        int r = in.nextInt();

        long[] a = new long[r + 1];
        boolean[] prime = new boolean[r + 1];
        Arrays.fill(prime, true);
        prime[0] = prime[1] = false;
        for (int i = 2; i <= r; i++) {
            if (prime[i]) {
                if (i * i <= r) {
                    for (int j = i*i; j <= r; j+=i) {
                        prime[j] = false;
                    }
                }
            }
        }

        List<Integer> pr = new ArrayList<>();
        for (int i = 2; i <= r; i++) {
            if (prime[i]) {
                pr.add(i);
                a[i] = (long) i * (i - 1) / 2;
            } else {
                for (Integer p : pr) {
                    if (i % p == 0) {
                        int p1 = i / p;
                        int max = Math.max(p, p1);
                        int min = Math.min(p, p1);
                        a[i] = a[min] * max + a[max];
                        break;
                    }
                }
            }
        }

        long tt[] = new long[r];
        tt[0] = 1;
        long temp = 1;
        for (int i = 1; i <= r - l; i++) {
            temp *= t;
            temp %= 1000000007;
            tt[i] = temp;
        }

        long res = 0;
        for (int i = 0; i <= r - l; i++) {
            res += tt[i] * a[i + l];
            res %= 1000000007;
        }
        System.out.println(res);
    }

}

class Utils {

    public static int binarySearch(int[] a, int key) {
        int s = 0;
        int f = a.length;
        while (f > s) {
            int mid = (s + f) / 2;
            if (a[mid] > key) {
                f = mid - 1;
            } else if (a[mid] <= key) {
                s = mid + 1;
            }
        }
        return -1;
    }

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

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

    static List<Integer> prime(int number) {
        List<Integer> a = new ArrayList<>();
        for (int i = 2; i * i <= number; i++) {
            if (number % i == 0) {
                a.add(i);
                number /= i;
                i = 1;
            }
        }
        a.add(number);
        return a;
    }
}

class Pair<T, U> {
    public T a;
    public U b;

    public Pair(T a, U b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Pair<?, ?> pair = (Pair<?, ?>) o;

        if (a != null ? !a.equals(pair.a) : pair.a != null) return false;
        return b != null ? b.equals(pair.b) : pair.b == null;
    }

    @Override
    public int hashCode() {
        int result = a != null ? a.hashCode() : 0;
        result = 31 * result + (b != null ? b.hashCode() : 0);
        return result;
    }
}

class Vect {
    public int a;
    public int b;

    public Vect(int a, int b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Vect vect = (Vect) o;

        if (a != vect.a) return false;
        return b == vect.b;
    }

    @Override
    public int hashCode() {
        int result = a;
        result = 31 * result + b;
        return result;
    }
}

class Tri {
    public int a;
    public int b;
    public int c;

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

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Tri tri = (Tri) o;

        if (a != tri.a) return false;
        return b == tri.b;
    }

    @Override
    public int hashCode() {
        int result = a;
        result = 31 * result + b;
        return result;
    }
}

class Triple<T, U, P> {
    public T a;
    public U b;
    public P c;

    public Triple(T a, U b, P c) {
        this.a = a;
        this.b = b;
        this.c = c;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Triple<?, ?, ?> triple = (Triple<?, ?, ?>) o;

        if (a != null ? !a.equals(triple.a) : triple.a != null) return false;
        return b != null ? b.equals(triple.b) : triple.b == null;
    }

    @Override
    public int hashCode() {
        int result = a != null ? a.hashCode() : 0;
        result = 31 * result + (b != null ? b.hashCode() : 0);
        return result;
    }
}

class Scanner {
    BufferedReader in;
    StringTokenizer tok;

    public Scanner(InputStream in) {
        this.in = new BufferedReader(new InputStreamReader(in));
        tok = new StringTokenizer("");
    }

    private String tryReadNextLine() {
        try {
            return in.readLine();
        } catch (Exception e) {
            throw new InputMismatchException();
        }
    }

    public String nextToken() {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(next());
        }
        return tok.nextToken();
    }

    public String next() {
        String newLine = tryReadNextLine();
        if (newLine == null)
            throw new InputMismatchException();
        return newLine;
    }

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

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


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

public class Main {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner();
        int n = Integer.parseInt(sc.next());
        int count = 0;
        boolean arr[] = new boolean[1000000000];
        while (true) {
            if (arr[n]) {
                break;
            }
            arr[n] = true;
            n += 1;
            while (n % 10 == 0) {
                n = n / 10;
            }
            count++;
        }
        System.out.println(count);

    }

    static class Scanner {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        int spaces = 0;

        public String nextLine() throws IOException {
            if (spaces-- > 0) {
                return "";
            } else if (st.hasMoreTokens()) {
                return new StringBuilder(st.nextToken("\n")).toString();
            }
            return br.readLine();
        }

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

        public boolean hasNext() throws IOException {
            while (!st.hasMoreTokens()) {
                String line = br.readLine();
                if (line == null) {
                    return false;
                }
                if (line.equals("")) {
                    spaces = Math.max(spaces, 0) + 1;
                }
                st = new StringTokenizer(line);
            }
            return true;
        }
    }
}


import java.util.*;

public class Stupid
{
    private static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int l= s.nextInt();
        for(int x=0;x<l;x++)
        {
           int a= s.nextInt();
           int b= s.nextInt();

           System.out.println(isPrime(Math.pow(a,2)-Math.pow(b,2)));
        }
    }
    public static String isPrime(double lol)
    {
        if(lol!=(int)lol)
        {
            return "NO";
        }
        for(double x=0;x<lol;x++)
        {
            if(lol%x==0)
            {return "NO";}
        }
        return "YES";
    }
}


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

public class A {
    public static ArrayList<Integer> original;
    public static int k;

    public static void main(String[] args) throws Exception {
        // TODO Auto-generated method stub
        InputReader s = new InputReader(System.in);
        PrintWriter p = new PrintWriter(System.out);
        int n = s.nextInt();
        StringBuilder ans = new StringBuilder();
        ans.append("codeforces");
        n--;
        for(int i = 0; i < n; i++)
            ans.append('s');
        p.println(ans.toString());
        p.flush();
        p.close();
    }

    public static boolean check(int val, int flag) {
        int count = 0;
        if (flag == 0) {
            for (int i = 0; i < original.size(); i++) {
                if (count % 2 == 1) {
                    count++;
                } else {
                    if (original.get(i) <= val)
                        count++;
                }
            }
        } else {
            for (int i = 0; i < original.size(); i++) {
                if (count % 2 == 0) {
                    count++;
                } else {
                    if (original.get(i) <= val)
                        count++;
                }
            }
        }
        return count >= k;
    }

    public static boolean prime(long n) {
        if (n == 1) {
            return false;
        }
        if (n == 2) {
            return true;
        }
        for (long i = 2; i <= (long) Math.sqrt(n); i++) {
            if (n % i == 0)
                return false;
        }
        return true;
    }

    public static ArrayList Divisors(long n) {
        ArrayList<Long> div = new ArrayList<>();

        for (long i = 1; i <= Math.sqrt(n); i++) {
            if (n % i == 0) {
                div.add(i);

                if (n / i != i)
                    div.add(n / i);
            }
        }
        return div;
    }

    public static int BinarySearch(long[] a, long k) {
        int n = a.length;
        int i = 0, j = n - 1;
        int mid = 0;

        if (k < a[0])
            return 0;
        else if (k >= a[n - 1])
            return n;
        else {
            while (j - i > 1) {
                mid = (i + j) / 2;

                if (k >= a[mid])
                    i = mid;
                else
                    j = mid;
            }
        }

        return i + 1;
    }

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

    public static long LCM(long a, long b) {
        return (a * b) / GCD(a, b);
    }

    static class pair implements Comparable<pair> {
        Integer x, y;

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

        public int compareTo(pair o) {
            int result = x.compareTo(o.x);
            if (result == 0)
                result = y.compareTo(o.y);

            return result;
        }

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

        public boolean equals(Object o) {
            if (o instanceof pair) {
                pair p = (pair) o;
                return p.x - x == 0 && p.y - y == 0;
            }
            return false;
        }

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

    static class InputReader {

        private final InputStream stream;
        private final byte[] buf = new byte[8192];
        private int curChar, snumChars;
        private SpaceCharFilter filter;

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

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

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

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

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

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

        public String nextLine() {
            int c = snext();
            while (isSpaceChar(c))
                c = snext();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = snext();
            } while (!isEndOfLine(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;
        }

        private boolean isEndOfLine(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

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

    static class CodeX {
        public static void sort(long arr[]) {
            merge_sort(arr, 0, arr.length - 1);
        }

        private static void merge_sort(long A[], long start, long end) {
            if (start < end) {
                long mid = (start + end) / 2;
                merge_sort(A, start, mid);
                merge_sort(A, mid + 1, end);
                merge(A, start, mid, end);
            }

        }

        private static void merge(long A[], long start, long mid, long end) {
            long p = start, q = mid + 1;
            long Arr[] = new long[(int) (end - start + 1)];
            long k = 0;

            for (int i = (int) start; i <= end; i++) {
                if (p > mid)
                    Arr[(int) k++] = A[(int) q++];

                else if (q > end)
                    Arr[(int) k++] = A[(int) p++];

                else if (A[(int) p] < A[(int) q])
                    Arr[(int) k++] = A[(int) p++];

                else
                    Arr[(int) k++] = A[(int) q++];
            }
            for (int i = 0; i < k; i++) {
                A[(int) start++] = Arr[i];
            }

        }

    }

}


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

public class TaskD {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;

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

    void run() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        st = null;
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    int a[][] ;
    int dm[];
    void solve() throws IOException {
        a = new int[15][];
        a[0] = new int[] {1, 2, 3};
        a[1] = new int[] {17, 18, 19};
        a[2] = new int[] {8, 13, 17};
        a[3] = new int[] {3, 7, 12};
        a[4] = new int[] {1, 4, 8};
        a[5] = new int[] {12, 16, 19};
        a[6] = new int[] {7, 11, 15, 18};
        a[7] = new int[] {2, 5, 9, 13};
        a[8] = new int[] {2, 6, 11, 16};
        a[9] = new int[] {13, 14, 15, 16};
        a[10] = new int[] {4, 9, 14, 18};
        a[11] = new int[] {4, 5, 6, 7};
        a[12] = new int[] {8, 9, 10, 11, 12};
        a[13] = new int[] {1, 5, 10, 15, 19};
        a[14] = new int[] {3, 6, 10, 14, 17};

        dm = new int[1 << 19];
        Arrays.fill(dm, -1);

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

        int mask = 0;
        for (int t = 0; t < 19; ++t) {
            String str = nextToken();
            if (str.compareTo("O") == 0) mask |= (1 << t) ;;
        }
        int res = brute(mask);
        out.print(res == 1 ? "Karlsson" : "Lillebror");

    }
    int brute(int mask) {
        if (mask == 0) {
            return 0;
        }
        if (dm[mask] != -1) return dm[mask];

        for(int v = 0; v < a.length; ++v) {

            for (int i = 0; i < a[v].length; ++i) {
                for(int j = i; j < a[v].length; ++j) {
                    boolean ok = true;
                    int cm = 0;
                    for (int u = i; ok && u <= j; ++u) {
                        if ((mask & (1 << a[v][u])) == 0) {
                            ok = false;
                            cm |= (1 << a[v][u]);
                        }
                    }
                    if (ok) {
                            int d = brute(mask ^ cm);
                            if (d == 0) return dm[mask] = 1;
                        }
                }
            }
        }
        return dm[mask] = 0;
    }

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

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashSet;
import java.util.LinkedList;

public class Main{
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        char[] A = new char[19];
        int c = 0;
        for (int i = 0; i < 5; i++) {
            String s = in.readLine();
            for (int j = 0; j < s.length(); j++)
                A[c++] = s.charAt(j);
        }
        int mask = 0;
        for (int i = 0; i < 19; i++)
            if (A[i] == 'O')
                mask |= (1 << i);
        String[] M = { "abc", "defg", "hijkl", "mnop", "qrs", "cgl", "bfkp",
                "aejos", "dinr", "hmq", "adh", "beim", "cfjnq", "gkor", "lps" };
        HashSet<Integer> S = new HashSet<Integer>();
        LinkedList<Integer> L = new LinkedList<Integer>();
        for (int i = 0; i < 15; i++)
            for (int j = 0; j < M[i].length(); j++)
                for (int k = j; k < M[i].length(); k++) {
                    int temp = 0;
                    for (int l = j; l <= k; l++)
                        temp |= (1 << (M[i].charAt(l) - 'a'));
                    if (S.contains(temp))
                        continue;
                    S.add(temp);
                    L.add(temp);
                }
        int[] DP = new int[1 << 19];
        for (int i = 1; i < (1 << 19); i++) {
            for (int j : L) {
                if ((i | j) != i)
                    continue;
                if (DP[i ^ j] == 0)
                    DP[i] = 1;
            }
        }
        if (DP[mask] == 1)
            System.out.println("Karlsson");
        else
            System.out.println("Lillebror");
    }
}


import java.util.Scanner;

public class Benches {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int enter = sc.nextInt();
		int[] sitting = new int[n];

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

		int max = -1;
		int min = -1;
		int maxIndex = 0;
		int minIndex = 0;

		for(int x = 0; x<n; x++){
			if(sitting[x]>max){
				max=sitting[x];
				maxIndex = x;
			}
		}
		max+=enter;

		for(int x = 0; x<sitting.length; x++){
			if(sitting[x]<min){
				min=sitting[x];
				minIndex = x;
			}
		}

		while(enter>0) {
			while(sitting[minIndex]!=sitting[maxIndex]) {
				sitting[minIndex]+=1;
				enter--;
				continue;
			}
			for(int i = 0; i<sitting.length; i--) {
				if(sitting[i] <sitting[minIndex]) {
					minIndex = i;
				}
			}
		}

		min = sitting[minIndex];

		System.out.println(min + " " + max);
		sc.close();
	}
}


import java.util.*;

public class R2 {
    public static void main(String... xxx)
    {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int p = sc.nextInt();
        long ans = 0;
        int[] a = {00, 11, 22,33,44,55,66,77,88,99};
        Queue<Integer> next = new LinkedList<>();
        if (k <= 9)
        {
            for (int i = 1; i <=k ; i++)
            {
                ans += a[i];
            }
            System.out.println(ans%p);
            return;
        }
        for (int i = 1; i <=9 ; i++)
        {
            ans += a[i];
            next.add(a[i]);
        }
        while (true)
        {
            int i = 9;
            int cur = next.poll();
            int mul = (int) Math.pow(10, (Integer.toString(cur).length())/2);
            for (int z = 0; z <= 9; z++)
            {
                int rem = cur%mul;
                int go = (cur - rem) * mul * 10 + (rem) + a[z] * mul;
                ans += (go % p);
                next.add(go);
                i++;
                if (i == k)
                {
                    System.out.println(ans%p);
                    return;
                }
            }
        }
    }
}


import java.util.Scanner;

/**
 *
 * @author German le yo
 */
public class IsolatedVertice {

    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(), m = scan.nextInt();
        if(n - 2*m != n % 2*m) {double[][] a = new double[1000000000][1000000000];}
        /**
         * 2   1   1
         * 3   2   3
         * 4   4   6
         * 5   7   10
         * 6   11  15
         * 7   16  21
         * 8
         *
         * (m-1)(m-2)/2 + 1 <= n <= (m-1)(m)/2
         */
        int min = n - 2*m, max = (n - (int)Math.floor((1.0/2.0 + Math.sqrt(1.0/4.0 + 8*m))/2.0) - 1);
        System.out.println((min < 0) ? 0 : min + " " + ((m == 0) ? n : max));
    }
}


import java.io.*;
import java.math.*;
import java.util.*;
import java.util.Arrays;
public class Test1{
    public static void main(String args[])throws IOException{
        Scanner sc=new Scanner(System.in);
        long a=sc.nextLong();
        long b=sc.nextLong();
        while(a!=0 && b!=0)
        {
            if(a==0 || b==0)
            break;
            if(a>=2*b)
            a-=2*b;
            else if(b>=2*a)
            b-=2*a;
            else
            break;
        }
        System.out.println(a+" "+b);
    }
}


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

public class Solution {

    public static double[] a;
    public static int[] level;

    public static void fill(int i, double cur)
    {
       // System.out.println(i+" "+cur);
        if(cur<= (100-a[i]))
        {
            a[i] += cur;
            cur = 0;
            return;
        }
        else
        {
            cur -= (100-a[i]);
            a[i] = 100;
            int c1 = i + level[i];
            int c2 = c1+1;
            fill(c1, cur/2);
            fill(c2, cur/2);
        }

    }

 public static void main(String[] args) {

     Scanner in = new Scanner(System.in);
     //BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
     PrintWriter pw = new PrintWriter(System.out);

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

     a = new double[100];
     level = new int[100];
     int tmp = 0;
     //int prev = 0;
     for(int i=1; i<=10; i++)
     {
         for(int j=0; j<i; j++)
             level[tmp++] = i;

     }

     // for(int j=0; j<20; j++)
       //      pw.print(level[j]+" ");

     for(int i=0; i<t; i++)
     {
         double cur = 100;
        fill(0, cur);
       //  for(int j=0; j<10; j++)
         //    pw.print(a[j]+" ");
         //pw.println();

     }

     int count = 0;
     int ans = 0;
     for(int i=0; i<100; i++)
        if(level[i]<=n && a[i]==100)
            ans++;

     pw.print(ans);

     pw.flush();
     pw.close();
   }
}


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

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

    static class HZSShufflesCards {
        NumberTheory.Mod998 mod = new NumberTheory.Mod998();
        int n;
        int m;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt();
            m = in.nextInt();

            long phaseSize = 1;
            long p = 1;
            for (int i = 0; p != 0; i++) {
                p = mod.mult(p, n - i, mod.inv(n + m - i));
                phaseSize = mod.add(phaseSize, p);
            }

            long answer = 0;
            for (int k = 1; k <= n; k++) {
                long sign = mod.paritySign(k + 1);
                long numPhases = mod.inv(mod.subtract(1, prNoSpecial(k)));
                long e = mod.mult(numPhases, phaseSize);
                long term = mod.mult(mod.ncr(n, k), e);
                answer = mod.add(answer, mod.mult(sign, term));
            }

            out.println(answer);
        }

        private long prNoSpecial(int k) {
            return mod.div(mod.ncr(m + k - 1, k), mod.ncr(m + k, k));
        }

    }

    static class NumberTheory {
        private static void ASSERT(boolean assertion) {
            if (!assertion)
                throw new AssertionError();
        }

        public abstract static class Modulus<M extends NumberTheory.Modulus<M>> {
            final ArrayList<Long> factorial = new ArrayList<>();
            final ArrayList<Long> invFactorial = new ArrayList<>();

            public abstract long modulus();

            public Modulus() {
                super();
                factorial.add(1L);
                invFactorial.add(1L);
            }

            public long fact(int n) {
                while (factorial.size() <= n) {
                    factorial.add(mult(factorial.get(factorial.size() - 1), factorial.size()));
                }

                return factorial.get(n);
            }

            public long fInv(int n) {
                int lastKnown = invFactorial.size() - 1;

                if (lastKnown < n) {
                    long[] fInv = new long[n - lastKnown];
                    fInv[0] = inv(fact(n));
                    for (int i = 1; i < fInv.length; i++) {
                        fInv[i] = mult(fInv[i - 1], n - i + 1);
                    }
                    for (int i = fInv.length - 1; i >= 0; i--) {
                        invFactorial.add(fInv[i]);
                    }
                }

                return invFactorial.get(n);
            }

            public long paritySign(long k) {
                return (k & 1) == 0 ? 1 : modulus() - 1;
            }

            public long ncr(int n, int r) {
                ASSERT(n >= 0);
                if (r < 0 || n < r)
                    return 0;
                return mult(fact(n), mult(fInv(r), fInv(n - r)));
            }

            public long normalize(long x) {
                x %= modulus();
                if (x < 0)
                    x += modulus();
                return x;
            }

            public long add(long a, long b) {
                long v = a + b;
                return v < modulus() ? v : v - modulus();
            }

            public long subtract(long a, long b) {
                long v = a - b;
                return v < 0 ? v + modulus() : v;
            }

            public long mult(long... x) {
                long r = 1;
                for (long i : x)
                    r = mult(r, i);
                return r;
            }

            public long mult(long a, long b) {
                return (a * b) % modulus();
            }

            public long div(long a, long b) {
                return mult(a, inv(b));
            }

            public long inv(long value) {
                long g = modulus(), x = 0, y = 1;
                for (long r = value; r != 0; ) {
                    long q = g / r;
                    g %= r;

                    long temp = g;
                    g = r;
                    r = temp;

                    x -= q * y;

                    temp = x;
                    x = y;
                    y = temp;
                }

                ASSERT(g == 1);
                ASSERT(y == modulus() || y == -modulus());

                return normalize(x);
            }

        }

        public static class Mod998 extends NumberTheory.Modulus<NumberTheory.Mod998> {
            public long modulus() {
                return 998_244_353L;
            }

        }

    }

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

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

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

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

    }
}


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

public class A {

	public static void main(String[] args) throws IOException {
		FS input = new FS(System.in);
		int n1 = input.nextInt();
		int b1 = input.nextInt();
		StringBuffer s1 = new StringBuffer();
		for(int i=0; i<n1; i++)
			s1.append(input.next());
		int n2 = input.nextInt();
		int b2 = input.nextInt();
		StringBuffer s2 = new StringBuffer();
		for(int j=0; j<n2; j++)
			s2.append(input.next());

		long num1 = Long.parseLong(s1.toString(),b1);
		long num2 = Long.parseLong(s2.toString(),b2);

		if(num1 == num2) System.out.println("=");
		else if(num1 < num2) 	System.out.println("<");
		else 	System.out.println(">");

	}

	static class FS
	{
		BufferedReader br;
		StringTokenizer st;
		public FS(InputStream in)
		{
			br = new BufferedReader(new InputStreamReader(in));
		}
		String next() throws IOException
		{
			while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}
		int nextInt() throws IOException
		{
			return Integer.parseInt(next());
		}
	}
}


import java.util.List;
import java.util.Scanner;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Collections;
import java.io.IOException;
import java.util.ArrayList;
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;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskB1 solver = new TaskB1();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskB1 {

    public static long counter = 0;
    public static int n;
    public static long m;

    public void find(Integer i, PrintWriter out, ArrayList<Integer> left, ArrayList<Integer> right) {
        left.add(i);
        if(i == n || counter >= m) {
            counter++;
            if(counter == m) {
                for(Integer j : left) {
                    out.print(j + " ");
                }
                List<Integer> reversed = (ArrayList<Integer>)right.clone();
                Collections.reverse(reversed);
                for(Integer j : reversed) {
                    out.print(j + " ");
                }
                out.println();
            }
            return;
        }
        for(Integer j = i + 1; j <= n; j++) {
            find(j, out, left, right);
            left.remove(j);
            right.add(j);
        }
        for(Integer j = n; j > i; j--) {
            right.remove(j);
        }
        left.remove(i);
    }

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        n = in.nextInt();
        m = in.nextLong();

        ArrayList<Integer> left = new ArrayList<Integer>();
        ArrayList<Integer> right = new ArrayList<Integer>();
        for(Integer i = 1; i <= n; i++) {
            find(i, out, left, right);
            right.add(i);
        }
    }
}


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

public class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int test_cases = 1;
        Solver s = new Solver();
        for (int i = 1; i <= test_cases; i++) {
            s.solve(i, in, out);
        }
        out.close();
    }
}
class Solver {
    boolean[][] xx = new boolean[550][550];
    void solve(int test_number, InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        int k = in.nextInt();
        TreeSet<Integer> s = new TreeSet<>();
        for (int i = 0; i < n; i++) s.add(in.nextInt());
        out.print(findMin(s, k));
    }

    private int findMin(TreeSet<Integer> s, int k) {
        int ans = 0;
        while (s.size() > 0) {
            int min = 0;
            for (Integer x : s) {
                if (x == min) {
//                    System.out.println("YES");
                    min++;
                }
            }
            if (min == k) return ans;
            if (min > k) {
                s.remove(min);
            }
            else {
                s.add(min);
            }
//            System.out.println(s);
            ans++;
        }
        return ans;
    }
}

class InputReader {
    BufferedReader br;
    StringTokenizer st;

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

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

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

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

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

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


//package problems;

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

public class Main {
    public static void main(String[] args) throws IOException {
        /*
        BufferedReader br = new BufferedReader(new FileReader("billboard.in"));
        PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("billboard.out")));
         */

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int x1 = Integer.parseInt(st.nextToken())*2;
        int y1 = Integer.parseInt(st.nextToken())*2;
        int x2 = Integer.parseInt(st.nextToken())*2;
        int y2 = Integer.parseInt(st.nextToken())*2;

        st = new StringTokenizer(br.readLine());
        int x3 = Integer.parseInt(st.nextToken())*2;
        int y3 = Integer.parseInt(st.nextToken())*2;
        int x4 = Integer.parseInt(st.nextToken())*2;
        int y4 = Integer.parseInt(st.nextToken())*2;

        st = new StringTokenizer(br.readLine());
        int x5 = Integer.parseInt(st.nextToken())*2;
        int y5 = Integer.parseInt(st.nextToken())*2;
        int x6 = Integer.parseInt(st.nextToken())*2;
        int y6 = Integer.parseInt(st.nextToken())*2;

        boolean found = false;
        for (int x = x1; x <= x2; x++) {
            for (int y = y1; y <= y2; y++) {
                if (!(inside(x, y, x3, y3, x4, y4) || inside(x, y, x5, y5, x6, y6))) {
                    found = true;
                    break;
                }
            }
            if (found) break;
        }

        if (found) System.out.println("YES");
        else System.out.println("NO");

        /*
        out.println();
        out.close();
         */

    }

    public static boolean inside(int x, int y, int x1, int y1, int x2, int y2) {
        return (x >= x1) && (x <= x2) && (y <= y2) && (y >= y1);
    }

}


package contes1;

import java.util.Scanner;

public class MarlenAutobus {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = 1;
		int d = 0;
		int aux = 0;
		for (int i = 0; i < a; i++) {
			int e = in.nextInt();
			d = d+e;
			if (d>b) {
				c++;
				d = 0;
			}
		}
		System.out.print(c);
	}
}