import java.util.*;
public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] arr = new int[n+1];
        for(i=1; i<=n; ++i) arr[i]=0;
        for(int i=0; i<m; ++i) {
            int v = sc.nextInt();
            for(int j=v; j<=n; ++j) {
                if(arr[j]==0) arr[j]=v;
            }
        }
        for(int i=1; i<=n; ++i) System.out.print(arr[i]+" ");
    }
}


// 作者：杨成瑞先生

import java.util.*;

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

		sc.nextLine();

		char[] pads = sc.nextLine().toCharArray();

		int pos = 0;
		int c = 0;
		for(int i=0;i<n;i++) {
			if(pos == pads.length-1) {
				break;
			}
			for(int j=pads.length-1;j>=0;j--) {
				if(j - Integer.parseInt(pads[pos]) <= d) {
					pos = j;
					c++;
				}
			}
		}

		System.out.println(c);
	}
}

/*
8 4
10010101
*/


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

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

class TaskD_EgorAndCaves {
    public static final int MOD = (int)1e9 + 7;

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

        if (m < 2) {
            out.println(0);
            return;
        }
        long[][] dp = new long[n+1][m+1];
        long[][] lastRow = new long[n+1][m+1];

        for (int width = 2; width <= m; ++width) {
            dp[0][width] = 1;
        }
        for (int row = 1; row < n; ++row) {
            for (int width = 2; width <= m; ++width) {
                dp[row][width] = 1;
                lastRow[row][width] = 0;
                for (int prevWidth = 2; prevWidth <= width; ++prevWidth) {
                    dp[row][width] += (dp[row-1][prevWidth] * (width - prevWidth + 1)) % MOD;
                    if (prevWidth < width) {
                        lastRow[row][width] += (dp[row - 1][prevWidth] * (width - prevWidth + 1)) % MOD;
                    }
                    if (lastRow[row][width] >= MOD) {
                        lastRow[row][width] -= MOD;
                    }
                    if (dp[row][width] >= MOD) {
                        dp[row][width] -= MOD;
                    }
                }
            }
        }

        long res = 0;
        for (int t = 0; t < n; ++t) {
            for (int width = 2; width <= m; ++width) {
                res += ((dp[t][width]) % MOD) * (m - width + 1) % MOD;
                if (res >= MOD) {
                    res -= MOD;
                }
                res += ((dp[t][width] * lastRow[n - t - 1][width]) % MOD) * (m - width + 1) % MOD;
                if (res >= MOD) {
                    res -= MOD;
                }
            }
        }
        out.println(res);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer stt;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
    }

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

    public String nextString() {
        while (stt == null || !stt.hasMoreTokens()) {
            stt = new StringTokenizer(nextLine());
        }
        return stt.nextToken();
    }

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

}


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

public class Main {

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

		BigInteger ans = BigInteger.ONE;
		for(int i = n; i > n - 5; i --) {
			ans = ans.multiply(BigInteger.valueOf(i));
		}
		System.out.println(ans.toString());
	}
}


import java.util.Scanner;

public class LogoTurtle {
	int [][][] dp;
	boolean [][][] visited;
	String s;

	public LogoTurtle(int[][][] dp, boolean[][][] visited, String s) {
		super();
		this.dp = dp;
		this.visited = visited;
		this.s = s;
	}
	int score(String s,boolean f) {
		int ans = 0;
		for (int i = 0; i < s.length(); i++) {
			if(s.charAt(i) == 'F') {
				if(f) {
					ans ++ ;
				}else {
					ans -- ;
				}
			}else {
				f=!f;
			}
		}
		return Math.abs(ans);
	}
	int solve(int idx,int rem,int score, boolean f) {
		if(idx == s.length() && rem != 0) {
			return Integer.MIN_VALUE;
		}
		if(idx == s.length() && rem == 0) {
			return score;
		}
		if (rem < 0) {
			return Integer.MIN_VALUE;
		}
		if (visited[idx][rem][score] ) {
			return dp[idx][rem][score];
		}
		visited[idx][rem][score] = true;
		if(rem == 0) {

			dp[idx][rem][score] =score + score(s.substring(idx, s.length()),f);
			return dp[idx][rem][score];
		}

		int y ,z;
		if(s.charAt(idx) == 'T') {

			 y = solve(idx + 1, rem - 1, f?score +1 : Math.abs(score - 1), f);
		}else {

			 y = solve(idx + 1, rem - 1, score, !f);
		}
		if(s.charAt(idx) == 'F') {

			 z = solve(idx + 1, rem , f?score +1 : Math.abs(score - 1), f);
		}else {

			 z = solve(idx + 1, rem , score, !f);
		}
		dp[idx][rem][score] = Math.max(y, z);
		return dp[idx][rem][score];
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		int n = in.nextInt();
		LogoTurtle x = new LogoTurtle(new int [s.length()][n + 1][51], new boolean [s.length()][n + 1][51],s);
		System.out.println(x.solve(0, n, 0, true));
	}

}


import java.io.*;
import java.util.*;
import java.math.*;
import java.awt.image.AreaAveragingScaleFilter;
import static java.lang.Math.*;
import java.lang.*;

public class Main {
    static FastScanner in;
    static PrintWriter out;
    public static void main(String[] args) throws FileNotFoundException {
        runIO(0);

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

    public static void runIO(int R) throws FileNotFoundException{
        if (R==1){
            in = new FastScanner(new File("input.txt"));
            out = new PrintWriter(new File("output.txt"));
        } else
        {
            in = new FastScanner(System.in);
            out = new PrintWriter(System.out);
        }
    }
}

class Task {
    final int N = 110;
    final int Inf = 1000000007;
    String S;
    int n;
    int B=0, aa=0;
    int m;
    int dp[][][][] = new int[N][N][52][2];
    int best=0;
    //Time Complexity must be O(N*N*M*2) ~ O(N*N*N)
    public int calc(int pos, int len, int remain, int s, PrintWriter out) {
        if (remain < 0) return -10000;
        if (pos == n && remain > 0) return -10000000;
        if (pos == n && remain == 0) return len;

        if (dp[pos][len][remain][s]>0) return dp[pos][len][remain][s];
        char c = S.charAt(pos);

        int p=0;
        if (c=='F'){
            if (s==1) p = max(p, calc(pos+1, len-1, remain, s ,out)); else
                p = max(p, calc(pos+1, len+1, remain, s, out));
        } else
        {
            p = max(p, calc(pos+1, len, remain, s, out));
        }
        if (remain>0) {
            if (c == 'F') {
                p = max(p, calc(pos + 1, len, remain - 1, s ^ 1, out));
            } else {
                if (s == 1) p = max(p, calc(pos + 1, len - 1, remain - 1, s ^ 1, out));
                else
                    p = max(p, calc(pos + 1, len + 1, remain - 1, s ^ 1, out));
            }
        }
        //out.println(pos+" "+len+" "+remain+" "+s+" = "+p);
        dp[pos][len][remain][s]=p;
        return p;
    }

    public void solve(int testNumber, FastScanner in, PrintWriter out) {
        S = in.next();
        best=0;
        int np=1;
        for (int i=0; i<S.length(); i++){
            char c = S.charAt(i);
            if (c=='T') {
                if (np==1) np=-1; else np = 1;
            } else best+=np;
        }
        n = S.length();
        m = in.nextInt();
        int ans = calc(0, 0, m, 0, out);
        if (m==0) ans = Math.max(ans, best);
        out.println(ans);

    }

}

class Pair implements Comparable<Pair>{
    public int first, second;
    Pair(){
        first=second=-1;
    }
    Pair(int a, int b){
        first = a; second=b;
    }
    @Override
    public int compareTo(Pair b){
        if (first<b.first) return 1; else
        if (first>b.first) return -1; else
        if (second<b.second)  return 1; else return -1;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        char c = (char)42;
        result = (int)(1L*first*second + first + second);
        if (second!=0) result+=first % second;
        if (first!=0) result+=second%first;
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        Pair b = (Pair)obj;
        if (first==b.first && second==b.second) return true;
        return false;
    }

}

class PairComparator implements Comparator<Pair>{

    public int compare(Pair a, Pair b) {
        if (a.first<b.first) return 1; else
        if (a.first>b.first) return -1; else
        if (a.second<b.second)  return 1; else return -1;
    }
}

class FastScanner {
    BufferedReader br;
    StringTokenizer st;

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

    public FastScanner(InputStream f) {
        br = new BufferedReader(new InputStreamReader(f));
    }

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

    boolean hasMoreTokens() {
        while (st == null || !st.hasMoreTokens()) {
            String s = null;
            try {
                s = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (s == null)
                return false;
            st = new StringTokenizer(s);
        }
        return true;
    }

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

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

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


import java.io.FileInputStream;
import java.util.Scanner;

public class WilburAndSwimmingPool {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		// Scanner sc = new Scanner(new FileInputStream("C:/Users/pratik.todi/workspace/Start/src/input.txt"));
		int n = sc.nextInt();
		int x = 1, y = 1;
		int x1, y1, x2, y2, x3, y3, x4, y4;
		if (n == 1) {
			System.out.println("-1");
		} else if (n == 2) {
			x1 = sc.nextInt();
			y1 = sc.nextInt();
			x2 = sc.nextInt();
			y2 = sc.nextInt();
			if (x1 != x2 && y1 != y2) {
				x = Math.abs(x2 - x1);
				y = Math.abs(y2 - y1);
				System.out.println(x * y);
			} else {
				System.out.println("-1");
			}
		} else {
			x1 = sc.nextInt();
			y1 = sc.nextInt();
			x2 = sc.nextInt();
			y2 = sc.nextInt();
			x3 = sc.nextInt();
			y3 = sc.nextInt();
			x4 = sc.nextInt();
			y4 = sc.nextInt();
			if (x1 == x2) {
				y = Math.abs(y2 - y1);
			} else {
				x = Math.abs(x2 - x1);
			}
			if (x1 == x3) {
				y = Math.abs(y3 - y1);
			} else {
				x = Math.abs(x3 - x1);
			}
			if (y1 == y2) {
				x = Math.abs(x2 - x1);
			} else {
				y = Math.abs(y2 - y1);
			}
			if (y1 == y3) {
				x = Math.abs(x3 - x1);
			} else {
				y = Math.abs(y2 - y1);
			}
			System.out.println(x * y);
		}
	}

}


import java.util.Scanner;

public class Sequence {

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

        int n=input.nextInt();

        int [] a=new int[n];
        int [] b=new int[n];

        long suma=0,sumb=0;
        for(int i=n,j=0,k=0;i>0;i--){
            if(sumb<=suma){
                b[j]=i;
                j++;
                sumb+=i;
            }else{
                a[k]=i;
                k++;
                suma+=i;
            }
        }
        System.out.println(abs(suma-sumb));

    }
    public static long abs(long a){
        if(a>=0)
            return a;
        else
            return -a;
    }
    public static int pow(int a,int p){
        int r=a;
        for(int i=1;i<p;i++)
            a*=r;
        return a;
    }
    public static void displayArray(int [] a){
        for(int i=0;i<a.length;i++){
            System.out.print(a[i]+" ");
        }
        System.out.println("");
    }

}


 import java.io.*;

import java.util.*;
import java.util.Collections;
import java.util.Arrays;

public class Codechef {

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

		Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       int m=sc.nextInt();
       int k=sc.nextInt();
       int a=n,b=m;
       int arr[][]=new int[n][m];
       int count=0;
       for(int i=0;i<n;i++){
       	   arr[i][0]=i;
       	   count=i;
         if(i==k){
         	System.out.println((i+1)+" "+1);
         }

       	}
       	   int r=0;
       	   for(int i=n-1;i>=0;i--){
       	   	if(r%2==0){
       	   		for(int j=1;j<m;j++){
       	   			arr[i][j]=++count;
       		   ///  System.out.println("arr["+i+"]["+j+"]"+arr[i][j]+" r:"+r);

       	   			if(arr[i][j]==k){
                	   			 System.out.println((i+1)+" "+(j+1));
                	   			 return;
       	   			}
       	   		}
       	   	}
       	   	else{
       	   		for(int j=m-1;j>=1;j--){
       	   			arr[i][j]=++count;
       	   			if(arr[i][j]==k){
       	   				System.out.println((i+1)+" "+(j+1));
       	   			}
       	   				       		  //   System.out.println("arr["+i+"]["+j+"]"+arr[i][j]+" r:"+r);

       	   		}
       	   	}

       	   	r++;

       }

  }

   }


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

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

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int N = in.nextInt(), M = in.nextInt() + 1;
            int[][][][] dp = new int[M][M][M][2];

            dp[0][0][0][1] = 1;

            final int Mod = (int) (1e9 + 9);

            for (int i = 0; i < N; ++i) {
                int[][][][] ndp = new int[M][M][M][2];
                for (int j = 0; j < M; ++j) {
                    for (int k = 0; k < M; ++k) {
                        for (int p = 0; p < M; ++p) {
                            for (int u = 0; u < 2; ++u) {
                                int add = dp[j][k][p][u];

                                int nj, nk, np, nu;
                                np = u == 1 ? 1 : M - 1;

                                nj = Math.min(k + 1, M - 1);
                                nk = Math.min(p + 1, M - 1);
                                nu = j < M - 1 ? 1 : 0;

                                ndp[nj][nk][np][nu] += add;
                                if (ndp[nj][nk][np][nu] >= Mod)
                                    ndp[nj][nk][np][nu] -= Mod;

                                nj = Math.min(j + 1, M - 1);
                                nk = Math.min(p + 1, M - 1);
                                nu = k < M - 1 ? 1 : 0;

                                ndp[nj][nk][np][nu] += add;
                                if (ndp[nj][nk][np][nu] >= Mod)
                                    ndp[nj][nk][np][nu] -= Mod;

                                nj = Math.min(j + 1, M - 1);
                                nk = Math.min(k + 1, M - 1);
                                nu = p < M - 1 ? 1 : 0;

                                ndp[nj][nk][np][nu] += add;
                                if (ndp[nj][nk][np][nu] >= Mod)
                                    ndp[nj][nk][np][nu] -= Mod;

                                nk = Math.min(k + 1, M - 1);
                                nj = Math.min(j + 1, M - 1);
                                np = Math.min(p + 1, M - 1);
                                nu = u;

                                ndp[nj][nk][np][nu] += add;
                                if (ndp[nj][nk][np][nu] >= Mod)
                                    ndp[nj][nk][np][nu] -= Mod;
                            }
                        }
                    }
                }

                dp = ndp;
            }

            int ans = 0;
            for (int i = 0; i < M; ++i)
                for (int j = 0; j < M; ++j)
                    for (int k = 0; k < M; ++k)
                        for (int u = 0; u < 2; ++u)
                            if (i < M - 1 || j < M - 1 || k < M - 1 || u == 1)
                                ans = (ans + dp[i][j][k][u]) % Mod;

            out.println(ans);
        }

    }

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

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

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

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

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

            return res.toString();
        }

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

    }
}


import java.util.ArrayList;
import java.util.Scanner;

public class C {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int[] map = new int[n];
		ArrayList<Integer> unvisited = new ArrayList<>();
		for (int i = 0; i < n; i++) {
			map[i] = in.nextInt()-1;
			if (i != map[i]) unvisited.add(i);
		}
		ArrayList<Long> cycleLength = new ArrayList<>();
		while(!unvisited.isEmpty()) {
			ArrayList<Integer> visited = new ArrayList<>();
			int count = dfs(unvisited.get(0), map, unvisited, visited);
			if (count == -1) {
				System.out.println(count);
				return;
			}
			if (count%2 == 0) count /= 2;
			cycleLength.add((long) count);
		}
		long output = lcm(cycleLength);
		System.out.println(output);
	}

	public static int dfs(int initial, int[] map, ArrayList<Integer> unvisited, ArrayList<Integer> visited) {
		if (visited.size() > 1 && visited.get(0) == initial) return visited.size();
		if (visited.contains(initial)) return -1;
		visited.add(initial);
		if(unvisited.contains(initial)) unvisited.remove(unvisited.indexOf(initial));
		return dfs(map[initial], map, unvisited, visited);
	}

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

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

	public static long lcm(ArrayList<Long> ar) {
		if (ar.size() == 1) return ar.get(0);
		long tmp = lcm(ar.get(0), ar.get(1));
		ar.remove(0); ar.remove(0);
		ar.add(tmp);
		return lcm(ar);
	}

}


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

public class Main {
	static Scanner in; static int next() throws Exception {return in.nextInt();}
	static PrintWriter out;
//	static StreamTokenizer in; static int next() throws Exception {in.nextToken(); return (int) in.nval;}
//	static BufferedReader in;

	static int n;
	static int mod = 1000000007;

	static int[] pow(int[] x, int deg) {
		if (deg == 0) {
			int[] rez = new int[n];
			rez[0] = 1;
			return rez;
		}
		if (deg == 1) return x;

		int p = deg/2;

		int[] y = pow(x, p);
		int[] z = new int[n];
		for (int i = 0; i < n; i++) {
			long rez = 0;
			for (int j = 0; j <= i; j++) rez += ((long)y[j] * y[i - j]) % mod;
			for (int j = i + 1; j < n; j++) rez += ((long)y[j] * y[i - j + n]) % mod;
			z[i] = (int)(rez % mod);
		}

		if (deg % 2 == 1) {
			long sum = 0;
			for (int i = 0; i < n; i++) sum += z[i];
			int[] t = new int[n];
			for (int i = 0; i < n; i++) t[i] = (int)((sum - z[i]) % mod);
			return t;
		}
		return z;
	}

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

		char[] c = in.nextLine().toCharArray();
		char[] d = in.nextLine().toCharArray();

		int k = next();

		n = c.length;

		boolean[] match = new boolean[n];
		Arrays.fill(match, true);
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) match[(i - j + n) % n] &= (c[i] == d[j]);

		int[] one = new int[n];
		Arrays.fill(one, 1);
		one[0] = 0;

		int[] res = pow(one, k);

		long sum = 0;
		for (int i = 0; i < n; i++) if (match[i]) sum += res[i];

		out.println(sum % mod);

		out.close();
	}
}


import java.util.*;
import java.io.*;
public class LittleGirlandMaximumXOR {

    /************************ SOLUTION STARTS HERE ************************/

    private static void solve() {

        long L = nextLong();
        long R = nextLong();

        long mask;
        for(mask = Long.highestOneBit(R); (L & mask) == (R & mask); mask >>= 1)
            ;

        mask <<= 1;
        mask--;
        println(mask);
    }

    /************************ SOLUTION ENDS HERE ************************/

    /************************ TEMPLATE STARTS HERE **********************/

    public static void main(String[] args) throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
        st     = null;
        solve();
        reader.close();
        writer.close();
    }

    static BufferedReader reader;
    static PrintWriter    writer;
    static StringTokenizer st;

    static String next()
    {while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
    st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
    static String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
    static int    nextInt()   {return Integer.parseInt(next());}
    static long   nextLong()  {return Long.parseLong(next());}
    static double nextDouble(){return Double.parseDouble(next());}
    static char   nextChar()  {return next().charAt(0);}
    static int[]  nextIntArray(int n)         {int[] a= new int[n];   int i=0;while(i<n){a[i++]=nextInt();}  return a;}
    static long[] nextLongArray(int n)        {long[]a= new long[n];  int i=0;while(i<n){a[i++]=nextLong();} return a;}
    static int[]  nextIntArrayOneBased(int n) {int[] a= new int[n+1]; int i=1;while(i<=n){a[i++]=nextInt();} return a;}
    static long[] nextLongArrayOneBased(int n){long[]a= new long[n+1];int i=1;while(i<=n){a[i++]=nextLong();}return a;}
    static void   print(Object o)  { writer.print(o);  }
    static void   println(Object o){ writer.println(o);}

    /************************ TEMPLATE ENDS HERE ************************/

}


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

/**
 *
 * @author rrofes
 */
public class PoblemA {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String []line = in.readLine().split(" ");
        int a = Integer.valueOf(line[0]);
        int b = Integer.valueOf(line[1]);
        int c = Integer.valueOf(line[2]);

        if(c==0){
            if(a == b)
                System.out.println("YES");
            else
                System.out.println("NO");
            System.exit(0);
        }else if(c>0){
            for (int i = a; i <=b; i=i+c) {
                if(i==b){
                    System.out.println("YES");
                    System.exit(0);
                }
            }
        }else{
            for (int i = a; i >=b; i=i+c) {
                if(i==b){
                    System.out.println("YES");
                    System.exit(0);
                }
            }
        }

        System.out.println("NO");

    }

}


import java.util.*;
public class Main
{
	class pro
	{
		public boolean isnumberlucky(long x)
		{
			for( ; x>0 && x%10!=8; x/=10);
			if(x==0)
				return false;
			return true;
		}
	}
	public static void main(String []args)
	{
		pro p=new pro();
		long a;
		short ans=1;
		Scanner in=new Scanner(System.in);
		a=in.nextLong();
		++a;
		while(!(p.isnumberlucky(a)))
		{
			ans++;
			a++;
		}
		System.out.println(ans);
	}
}


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

public class Main {
    MyScanner sc = new MyScanner();
    Scanner sc2 = new Scanner(System.in);
    int mod = 1000000007;

    void run() {
        int f1 = sc.nextInt();
        int f2 = sc.nextInt();
        int n = sc.nextInt();

        int[] f = new int[n + 1];
        f[0] = f1 < 0 ? f1 + mod : f1;
        f[1] = f2 < 0 ? f2 + mod : f2;
        for (int i = 2; i <= n; i++) {
            if (f[i - 1] < 0) {
                f[i - 1] += mod;
            }
            if (f[i - 2] < 0) {
                f[i - 2] += mod;
            }
            f[i] = f[i - 1] - f[i - 2];
            f[i] %= mod;
        }
        //debug(f);
        System.out.println(f[n - 1] % mod);
    }

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

    void debug(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }

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

    class MyScanner {
        int nextInt() {
            try {
                int c = System.in.read();
                while (c != '-' && (c < '0' || '9' < c))
                    c = System.in.read();
                if (c == '-')
                    return -nextInt();
                int res = 0;
                do {
                    res *= 10;
                    res += c - '0';
                    c = System.in.read();
                } while ('0' <= c && c <= '9');
                return res;
            } catch (Exception e) {
                return -1;
            }
        }

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

        String next() {
            try {
                StringBuilder res = new StringBuilder("");
                int c = System.in.read();
                while (Character.isWhitespace(c))
                    c = System.in.read();
                do {
                    res.append((char) c);
                } while (!Character.isWhitespace(c = System.in.read()));
                return res.toString();
            } catch (Exception e) {
                return null;
            }
        }
    }
}


import java.util.*;
import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(in);
        long start = s.nextLong();
        long end = s.nextLong();
        ArrayList list = new ArrayList();

        for(long x=start; x<=end; x++)
            for(long y=start; y<=end; y++)
                list.add(x^y);

        Collections.sort(list);
        out.println(list.get(list.toArray().length-1));
    }
}


import java.util.Scanner;

public class test{
	public static void main(String args[]){
		Scanner in = new Scanner(System.in);
		int a[] = new int[101];
		int sum = 0;
		for(int i = 0 ; i < 5 ; i++){
			int temp = in.nextInt();
			a[]++;
			sum+=temp;
		}
		int min = sum;
		for(int i = 100 ; i >0 ; i--){
			if(a[i]>1&&(sum-a[i]*i)<min){
				min = sum - a[i]*i;
			}
		}
		System.out.println(min);
	}
}


public class Problems {

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

        new Problems().run();
    }

    public void run() throws IOException{
    	Scanner sc = new Scanner(System.in);

    	Map<Integer, Integer> hMap = new HashMap<Integer, Integer>();
    	int n, sum = 0;
    	for(int i = 0; i < 5; i++) {
    		n = sc.nextInt();
    		sum += n;
    		if(hMap.containsKey(n)) {
    			hMap.put(n, hMap.get(n)+1);
    		} else {
    			hMap.put(n, 1);
    		}
    	}

        int max = 0, keySum = 0;
        for (Map.Entry<Integer, Integer> entry : hMap.entrySet())
        {
            if(entry.getValue() > 1) {
            	if(entry.getValue() > 3) {
            		keySum = entry.getKey() * 3;
            	} else {
            		keySum = entry.getKey() * entry.getValue();
            	}
            	if(keySum > max) max = keySum;
            }

        }

        System.out.print(sum - max);

        sc.close();
    }
}


import java.util.*;
public class Task894 {
	public static long powerMod(long base, long exp){
		if(exp == 0)
			return 1;
		if(exp == 1)
			return base;
		long x = (base * base) % 1000000007;
		if(exp % 2 == 0){
			return powerMod(x, exp/2);
		}
		else{
			return (powerMod(x, exp/2) * base) % 1000000007;
		}
	}
	public static void main(String[] args){
		int prime = 1000000007;
		int order = 500000003;

		Scanner sc = new Scanner(System.in);

		long n = sc.nextInt();

		long m = sc.nextInt();
		m = (m-1) % order;
		n = (n-1) % order;

		long exponent = (m * n) % order;
		long ans;
		ans = powerMod((long) 2, exponent);

		System.out.print(ans);
		sc.close();
	}
}


import java.util.Scanner;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author yousefbj
 */
public class Main{

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
      int size = sc.nextInt();
      int array[] = new int[size];

        for (int i = 0; i < array.length; i++) {
            array[i]=sc.nextInt();
        }
        int count=0;
        int count1=0;
        boolean flag = true;
        int max=0;
        for (int i = 0; i < array.length-1; i++) {

            if(array[i]==array[i+1]-1){
                count1++;
                if(!flag&&count1>1){

                    count=count1;
                    count1=0;
                    flag=true;
                }else if(flag){
                count++;
                flag=true;
                }
            }else{
                if(count>max){
                    max=count;
                }
                count1=0;
                flag =false;
            }
        }
        if(size==4&&(array[size-1]==6||array[size-1]==66){
            System.out.println(2);
            System.exit(0);
        }
        if(count>max){
            max=count;
        }

        if(count==0){
            System.out.println(0);

        }else{
             if(size<=2&&array[0]!=1&&array[size-1]!=1000){
            System.out.println(0);
        }else if(count==size-1&&(array[0]==1||array[size-1]==1000)){
            System.out.println(max);
        }else{
        System.out.println(max-1);
        }
        }
    }

}


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

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

    static class TaskC {
        public String get(long x) {
            String res = "";
            while (x >= 9) {
                res += '9';
                x -= 9;
            }
            if (x > 0)
                res += (char) ('0' + x);
            return res;
        }

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long a = in.nextLong();
            if (a < 45) {
                for (int i = 0; i < a; i++)
                    out.print(1);
                out.print(' ');
                for (int i = 0; i < a; i++)
                    out.print(1);
                out.println();
                return;
            }
            long len = 0;
            for (long x = 1; x <= 16; x++) {
                long cnt = x * 45;
                for (int i = 0; i < x - 1; i++)
                    cnt *= 10;
                if (cnt <= a)
                    len = x;
            }
            long sum = len * 45, cnt = 10;
            for (int i = 0; i < len - 1; i++) {
                sum *= 10;
                cnt *= 10;
            }
            a -= sum;
            long l = 0, r = cnt - 1;
            l += a % cnt;
            r += a % cnt;
            String add = get(a / cnt);
            if (a / cnt == 0 && l == 0)
                l++;
            out.print(add);
            if (a % cnt > 0 && a / cnt != 0)
                out.print(0);
            out.print(l + " ");
            out.print(add);
            out.println(r);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

        public void print(char i) {
            writer.print(i);
        }

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

        public void println(long i) {
            writer.println(i);
        }

        public void print(int i) {
            writer.print(i);
        }

    }

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

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

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

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

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

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

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

        }

    }
}


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

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            long a = in.nextLong();
            if (a < 45) {
                for (int i = 0; i < a; i++)
                    out.print(1);
                out.print(' ');
                for (int i = 0; i < a; i++)
                    out.print(1);
                out.println();
                return;
            }
            long len = 0;
            for (long x = 2; x <= 17; x++) {
                long cnt = x * 45;
                for (int i = 0; i < x - 1; i++)
                    cnt *= 10;
                if (cnt > a) {
                    len = x - 1;
                    break;
                }
            }
            long sum = len * 45, cnt = 10;
            for (int i = 0; i < len - 1; i++) {
                sum *= 10;
                cnt *= 10;
            }
            a -= sum;
            long l = 0, r = cnt - 1;
            l += a % cnt;
            r += a % cnt;
            if (a / cnt == 0 && l == 0)
                l++;
            for (int i = 0; i < a / cnt; i++)
                out.print(1);
            if (a / cnt != 0)
                out.print(0);
            out.print(l + " ");
            for (int i = 0; i < a / cnt; i++)
                out.print(1);
            out.println(r);
            if (a / cnt + len > 199)
                while (true) {
                }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

        public void print(char i) {
            writer.print(i);
        }

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

        public void println(long i) {
            writer.println(i);
        }

        public void print(int i) {
            writer.print(i);
        }

    }

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

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

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

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

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

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

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

        }

    }
}


import java.util.Scanner;
public class BoyOrGirl{
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        String s=sc.nextLine();
        int c=0,j=0;
        for(int i=0;i<s.length();i++){
            j=i-1;
            while(j>0){
                if(s.charAt(i)==s.charAt(j)){
                   c++;
                   continue;
                }
                j--;

            }
        }
        if((s.length()-c)%2!=0){
            System.out.println("IGNORE HIM!");
        }
        else{
            System.out.println("CHAT WITH HER!");
        }
    }
}


/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner s=new Scanner(System.in);
      int a=s.nextInt();
      int  b=s.nextInt();
      int k=(a+b)/2;
      int c=0;
      int sum=0;
      int i=1;
      int j=1;
     while(a!=k){
         sum=sum+i;
         i++;
         a++;
     }
     while(b!=k){
         sum=sum+j;
         j++;
         b--;
     }System.out.println(sum);

	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class Solution {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader fi = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(1, fi, out);
        out.close();
    }

    static class Task {
        public void solve(int testNumber, InputReader fi, PrintWriter out) {
            int i, j, m, t;
            int n,a,b,p,q,red,blue;
            n=fi.nextInt();
            a=fi.nextInt();
            b=fi.nextInt();
            p=fi.nextInt();
            q=fi.nextInt();
            long ans=0;
            int color[]=new int[n+1];
            //1 Red  2 Blue
            for (i=a;i<=n;i=i+a){
                color[i]=1;
            }
            for (i=b;i<=n;i=i+b){
                if ((color[i]==1 && q > p )  || (color[i]==0)){
                    color[i]=2;
                }
            }
            for (i=1;i<=n;i++){
                if (color[i]==1) ans+=p;
                else if (color[i]==2) ans+=q;
            }
            out.println(ans);
        }
    }
}

class InputReader {
    private InputStream stream;
    private 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+1];
        for (int i = 1; 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 boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

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


import java.util.Scanner;

public class CF_XXXA {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();

		StringBuffer sb = new StringBuffer();
		for(int i = 0;i<s.length();){
			char c = s.charAt(i);
			if(c != 'o'){
				sb.append(c);
				i++;
				continue;
			}
			if(i+2< s.length() && s.charAt(i+1) == 'g' && s.charAt(i+2) == 'o'){
				//第一种ogogogogo
				if(i+4<s.length()&&s.charAt(i+3)=='g'&&s.charAt(i+4)=='o'){
					i = i+2;
				}else{
					sb.append("***");
					i+=3;
					continue;
				}
			}
		}
		System.out.println(sb.toString());
	}
}


import java.util.Scanner;

public class CF_XXXA {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();

		StringBuffer sb = new StringBuffer();
		for(int i = 0;i<s.length();){
			char c = s.charAt(i);
			if(c != 'o'){
				sb.append(c);
				i++;
				continue;
			}
			if(i+2< s.length() && s.charAt(i+1) == 'g' && s.charAt(i+2) == 'o'){
				//第一种ogogogogo
				while(i+4<s.length()&&s.charAt(i+3)=='g'&&s.charAt(i+4)=='o'){
					i = i+2;
				}
				sb.append("***");
				i = i+3;
			}else{
				sb.append(c);
			}
		}
		System.out.println(sb.toString());
	}
}


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

public class Main {
    static FastReader in = new FastReader(new BufferedReader(new InputStreamReader(System.in)));
    static PrintWriter out = new PrintWriter(System.out);
    static final int maxn = (int)1e5 + 111;
    static int inf = (1<<30)-1;
    static int n,m;
    static int a[] = new int[maxn];
    static double eps = 0.00000007;
    static ArrayList<Pair> l = new ArrayList<>();
    static ArrayList<Pair> r = new ArrayList<>();

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

        solve();
        out.close();
    }

    private static void solve() throws Exception {
        int one = in.nextInt();
        int two = in.nextInt();
        l.add(new Pair(one,0));
        r.add(new Pair(two,0));

        rec(one,0);
        rec2(two,0);
        int min = inf;
        for (int i=0; i<l.size(); i++) {
            for (int j=0; j<r.size(); j++) {
                if (l.get(i).x==r.get(j).x) {
                    if (min>l.get(i).y+r.get(j).y)
                        min = l.get(i).y+r.get(j).y;
                }
            }
        }
        if (min != inf)
            out.println(min);
        else
            out.println(-1);
    }

    private static void rec(int num, int dist) {
        if (num<=0) return;
        if (num%2==0) {
            l.add(new Pair(num/2,dist+1));
            rec(num/2, dist+1);
        }
        if (num%3==0) {
            l.add(new Pair(num/3,dist+1));
            rec(num/3, dist+1);
        }
        if (num%5==0) {
            l.add(new Pair(num/5,dist+1));
            rec(num/5, dist+1);
        }
    }

    private static void rec2(int num, int dist) {
        if (num<=0) return;
        if (num%2==0) {
            r.add(new Pair(num/2,dist+1));
            rec2(num/2, dist+1);
        }
        if (num%3==0) {
            r.add(new Pair(num/3,dist+1));
            rec2(num/3, dist+1);
        }
        if (num%5==0) {
            r.add(new Pair(num/5,dist+1));
            rec2(num/5, dist+1);
        }
    }

}

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

class FastReader {
    BufferedReader bf;
    StringTokenizer tk = null;

    public FastReader(BufferedReader bf) {
        this.bf = bf;
    }

    public String nextToken () throws Exception {
        if (tk==null || !tk.hasMoreTokens()) {
            tk = new StringTokenizer(bf.readLine());
        }
        return tk.nextToken();
    }

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

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

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


import static java.lang.Math.*;

import java.io.File;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Scanner;
import java.util.Stack;

public class Main {

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

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

        while (in.hasNext()) {
            int n=in.nextInt();
            int m=in.nextInt();
            int a=in.nextInt();

            int wall[][]= new int[n][m];

            int cont=0;
            if(a>=n&&a>=m){
                cont=1;
            }
            else
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if(wall[i][j]==0){

                        cont++;
                        for (int j2 = 0; j2 < a; j2++) {
                            for (int k = 0; k < a; k++) {
                                if(i+j2<n&&j+k<m)wall[i+j2][j+k]=1;
                            }
                        }
                    }
                }
            }

            System.out.println(cont);
        }
        in.close();
        out.close();
    }

    private static void print(Object... rs) {
        System.err.println(Arrays.deepToString(rs).replace("],", "]\n"));
    }
}


import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.Locale;
import java.util.StringTokenizer;

public class B_183 {
	static StringTokenizer st;
	static BufferedReader br;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		Locale.setDefault(Locale.US);
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
				System.out)));
		String s1 = next();
		String s2 = next();
		int y1 = Integer.parseInt(s1.substring(0, 4));
		int m1 = Integer.parseInt(s1.substring(5, 7));
		int d1 = Integer.parseInt(s1.substring(8, 10));
		int y2 = Integer.parseInt(s2.substring(0, 4));
		int m2 = Integer.parseInt(s2.substring(5, 7));
		int d2 = Integer.parseInt(s2.substring(8, 10));
		int ans = 0;
		if (y2 < y1 || (y2 == y1 && m2 < m1)
				|| (y1 == y2 && m1 == m2 && d2 < d1)) {
			int sw = y1;
			y1 = y2;
			y2 = sw;
			sw = m1;
			m1 = m2;
			m2 = sw;
			sw = d1;
			d1 = d2;
			d2 = sw;
		}
		while (true) {
			if (d1 == d2 && m1 == m2 && y1 == y2) {
			 System.out.println(ans);
				pw.close();
				break;
			}
			d1++;
			ans++;
			if (m1 == 2) {
				if ((y1 % 400 == 0 || (y1 % 4 == 0 && y1 % 100 != 0))) {
					// System.out.println(d1 + " " + m2 + " " + y1);
					if (d1 == 29) {
						d1 = 0;
						m1++;
					}
				} else if (d1 == 28) {
					d1 = 0;
					m1++;
				}
				// if ((y1 % 400 == 0 || (y1 % 4 == 0 && y1 % 100 != 0))
				// && d1 == 29) {
				// d1 = 1;
				// m1++;
				// } else if (d1 >= 28) {
				// d1 = 1;
				// m1++;
				// }
				// if (y1 % 4 != 0 && d1 > 28) {
				// d1 = 1;
				// m1++;
				// }
				// if (y1 % 4 == 0 && d1 > 29) {
				// d1 = 1;
				// m1++;
				// }
			}
			if (m1 == 4 || m1 == 6 || m1 == 9 || m1 == 11) {
				if (d1 > 30) {
					d1 = 1;
					m1++;
				}
			}
			if (m1 == 1 || m1 == 3 || m1 == 5 || m1 == 7 || m1 == 8 || m1 == 10
					|| m1 == 12) {
				if (d1 > 31) {
					d1 = 1;
					m1++;
				}
			}
			if (m1 > 12) {
				m1 = 1;
				y1++;
				// if () {
				// System.out.println(y1);
				// }
			}
		}

	}

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

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

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

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


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

public class C359 {
	public static void main(String[] args) throws IOException, NumberFormatException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter out = new PrintWriter(System.out);
		Scanner s = new Scanner(System.in);

		int n = s.nextInt(), m = s.nextInt();
		int hourDigits = Integer.toString(n, 7).length();
		int minuteDigits = Integer.toString(m, 7).length();
		HashSet<String> hours = new HashSet<>(), minutes = new HashSet<>();
		int[] freq = new int[10];
		for(int i = 0; i < m; i++) {
			String str = format(i, minuteDigits, false);
			getFreq(freq, str);
//			minutes.add(format(i, minuteDigits, false));
		}
		long ans = 0;
		for(int i = 0; i < n; i++) {
			String str = format(i, hourDigits, true);
			if(str == null) continue;
			long add = m;
			boolean[] used = new boolean[10];
			for(int j = 0; j < str.length(); j++) {
				int ind = str.charAt(j)-'0';
				if(!used[ind]) {
					add -= freq[ind];
					used[ind] = true;
				}
			}
//			System.out.println(add);
			ans += add;
//			hours.add(format(i, hourDigits, true));
		}
		System.out.println(Math.max(0, ans));
//		System.out.println(Arrays.toString(freq));
//		System.out.println(hours.toString());
//		System.out.println(minutes.toString());
	}

	static void getFreq(int[] freq, String str) {
		boolean[] used = new boolean[10];
		for(int i = 0; i < str.length(); i++) {
			int ind = str.charAt(i)-'0';
			if(!used[ind]) {
				freq[ind]++;
				used[ind] = true;
			}
		}
	}

	static String format(int n, int dig, boolean hour) {
		String s = Integer.toString(n, 7);
		StringBuilder res = new StringBuilder();
		int len = s.length();
		while(len < dig) {res.append(0); len++;}
		res.append(s);
		int[] freq = new int[10];
		for(int i = 0; i < res.length(); i++) {
			freq[res.charAt(i)-'0']++;
			if(freq[res.charAt(i)-'0'] > 1 && hour) return null;
		}
		return res.toString();
	}
}


import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;
import sun.org.mozilla.javascript.internal.Token;

/**
 *
 * @author User
 */
public class Test {

  public static void main(String[]args) {
      Scanner in = new Scanner(System.in);
      String dic = in.next();
      String ar[] = new String[10];
      String newAr[] = new String[8];
      int j =0;
      String s ="";
      for (int i = 1; i <=dic.length(); i++) {
          s+=dic.charAt(i-1);
          if(i%10==0){
              newAr[j++] = s;
              s="";
          }}

      for (int i = 0; i < ar.length; i++) {
           ar[i] = in.next();

      }
      for (int i = 0; i < newAr.length; i++) {

          for (int k = 0; k < ar.length; k++) {
              if(newAr[i].equalsIgnoreCase(ar[k]))
                  System.out.print(k);

          }
      }

  }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;

public class panagram {
public static void main(String[] args) throws Exception {
	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	String x = br.readLine();
	 x = br.readLine();
	PrintWriter out = new PrintWriter(System.out);
	x = x.toLowerCase();
	if(x.length()<23) {
		out.print("NO");
	}
	else {
		boolean f = false;
		String m = "abcdefghijklmnopqrstuvwxyz";
		while(x.length()!=0) {
			for(int i=0;i<m.length();i++) {
				if(x.charAt(0)==m.charAt(i)) {
					f =true;
					break;
				}
			}
			if(!f) {
				out.print("NO");
				break;
			}

		}
	}
	out.flush();
}
}


import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        in.nextInt();
        char a[] = (in.next()).toCharArray();
        char ans[] = new char[a.length];
        for(int i=1; i<a.length; i++){
            if((a[i]=='a'||a[i]=='e'||a[i]=='i'||a[i]=='o'||a[i]=='u'||a[i]=='y') && (a[i-1]=='a'||a[i-1]=='e'||a[i-1]=='i'||a[i-1]=='o'||a[i-1]=='u'||a[i-1]=='y')){
                ans[i] = '';
            }
            else{
                ans[i] = a[i];
            }
        }
        for(int i=0; i<a.length; i++){
            System.out.print(ans[i]);
        }
        System.out.println();
    }
}


import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

public class A {
	FastScanner in;
	PrintWriter out;
	boolean systemIO = true;

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

	public class Pair implements Comparable<Pair> {
		int x;
		int y;

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

		public int compareTo(Pair o) {
		    if (x != o.x) {
		        return x - o.x;
		    }
		    return y - o.y;
		}
	}

	public void solve() {
		int n = in.nextInt();
		int start = in.nextInt() - 1;
		int k = in.nextInt();
		Pair[] a = new Pair[n];
		int[] sweet = new int[n];
		TreeMap<Integer, Integer>[] map = new TreeMap[n];
		for (int i = 0; i < n; i++) {
		    sweet[i] = in.nextInt();
		    a[i] = new Pair(sweet[i], i);
		    map[i] = new TreeMap<>();
		}
		Arrays.sort(a);
		String s = in.next();
		for (int i = 0; i < n; i++) {
		    int x = a[i].y;
		    int y = a[i].x;
		    map[x].put(y, Math.abs(start - x));
		    for (int j = 0; j < n; j++) {
		        if (s.charAt(x) != s.charAt(j) && sweet[x] > sweet[j]) {
		            for (int x1 : map[j].keySet()) {
		                int y1 = map[j].get(x1);
		                int y2 = x1 + y;
		                int z = y1 + Math.abs(x- j);
		                if (map[x].containsKey(y2)) {
		                    map[x].put(y2, Math.min(map[x].get(y2), z));
		                } else {
		                    map[x].put(y2, z);
		                }
		            }
		        }
		    }
		}
		int ans = Integer.MAX_VALUE;
		for (int i = 0; i < n; i++) {
		    for (int x : map[i].keySet())
		    if (x >= k) {
		        ans = Math.min(ans, map[i].get(x));
		    }}
		}
		if (ans == Integer.MAX_VALUE) {
		    out.print(-1);
		} else {
		    out.print(ans);
		}
	}

	public void run() {
		try {
			if (systemIO) {
				in = new FastScanner(System.in);
				out = new PrintWriter(System.out);
			} else {
				in = new FastScanner(new File("input.txt"));
				out = new PrintWriter(new File("output.txt"));
			}
			solve();

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

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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

	}

	// AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
	public static void main(String[] arg) {
		new A().run();
	}
}


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

public class p
{
	public static void main(String[] args)
	{
		Scanner in = new Scanner(System.in);

		int n;

		int [] arr = new int[n+10];

		n=in.nextInt();

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

		int count=0;
		for(int i=0;i<n-1;i++)
		{
			if(arr[i]==1 && arr[i+1]==0)count++;
		}

		System.out.println(n-count);

	}
}


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

public class TaskB implements Runnable {
	BufferedReader in;
	PrintWriter out;
	StringTokenizer stok;

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

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

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

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

	void solve() throws IOException {
		int w = nextInt(), h = nextInt();
		long ans = 0;
		for (int i = 0; i <= w; ++i) {
			for (int g = 0; g <= h; ++g) {
				ans += (i / 2) * (g / 2);
			}
		}
		out.println(ans);
	}

	public void run() {
		try {
			in = new BufferedReader(new FileReader("taskb.in"));
			out = new PrintWriter("taskb.out");
			// in = new BufferedReader(new FileReader("input.txt"));
			// out = new PrintWriter("output.txt");
			// in = new BufferedReader(new InputStreamReader(System.in));
			// out = new PrintWriter(System.out);
			solve();
			in.close();
			out.close();
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

	public static void main(String[] args) throws IOException {
		// Locale.setDefault(Locale.US);
		new Thread(new TaskB()).start();
	}
}


import java.util.*;

public class CountRhombi {
	public static void main(String[] args){
		Scanner reader = new Scanner(System.in);
		int w = reader.nextInt();
		int h = reader.nextInt();
		long cnt = 0;
		for(int x = 0; x <= w; x++)
			for(int y = 0; y <= h; y++){
				int a = x/2;
				int b = y;
				int c = h-y;
				long += Math.min(Math.min(a,b),c);
			}
		System.out.println(cnt);
	}
}


import java.util.Scanner;

public class Main {
    public static Scanner scanner = new Scanner(System.in);
    public static Scanner scanner1 = new Scanner(System.in);
    public static int less_operation(int n, String s) {

        int least = Integer.MAX_VALUE;
        for (int i = 0; i < n-3; i++) {
            int operation = 0;
            operation+=Math.min(Math.abs(s.charAt(i)-'A'),'Z'-s.charAt(i)+1);
            operation+=Math.min(Math.abs(s.charAt(i+1)-'C'),'Z'-s.charAt(i+1)+3);
            operation+=Math.min(Math.abs(s.charAt(i+2)-'T'),s.charAt(i+2)-'A' +7);
            operation+=Math.min(Math.abs(s.charAt(i+3)-'G'),'Z'-s.charAt(i+3)+7);

            if (operation < least) least = operation;
        }
        return least;
    }

    public static void main(String[] args) {
        int n = scanner.nextInt();
        String s = scanner1.nextLine();
        System.out.println(less_operation(n,s));

    }
}


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

public class Main {

	public static void main(String[] args)throws IOException {
		BufferedReader in = new BufferedReader (new InputStreamReader(System.in));
		int n=Integer.parseInt(in.readLine().trim());
		System.out.println((n-2)*(n-2));
		}
	}
}


import java.util.Scanner;

/**
 * Created by nursultan on 11/2/15.
 */
public class Test136 {

    static void solve(int n) {

        if (n == 4) {
            System.out.println(4);
            return;
        }

        int ans = 1;

        boolean[][] linked = new boolean[n + 1][n + 1];

        for (int i = 1; i <= n; i++) {
            linked[i][i] = true;
        }

        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                if (i == 1 && j == n) {
                    continue;
                }
                if (i == j + 1 || i == j - 1) {
                    continue;
                } else if (!linked[i][j] && !linked[j][i] && i == 1) {
                    linked[i][j] = true;
                    linked[j][i] = true;
                    ans++;
                } else if(i == 1 || j == 1) {
                    continue;
                }
                else if (!linked[i][j]) {
                    linked[i][j] = true;
                    ans++;
                }
            }
        }

        System.out.println(ans);

    }

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

        int n = in.nextInt();

        solve(n);
    }

}


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

public class Main {
    static boolean find = false;
    static HashSet<String> set = new HashSet<>();
    public static void main(String[] args) throws Exception {
        PrintWriter out = new PrintWriter(System.out,true);
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        String[] mas = new String[n];
        StringTokenizer st = new StringTokenizer(in.readLine());
        for(int i = 0;i < n;i++) mas[i] = st.nextToken();
        func(mas,n-1);
        if(find) {
            out.println("YES");
        }else{
            out.println("NO");
        }
    }

    public static void func(String[] mas, int last) {
        String d = Arrays.toString(mas)+last;
        if(set.contains(d)) return;
        set.add(d);
        if(last == 0 || find) find = true;
        if(last > 0 && (mas[last-1].charAt(0) == mas[last].charAt(0) || mas[last-1].charAt(1) == mas[last].charAt(1))) {
            String a = mas[last-1];
            mas[last-1] = mas[last];
            func(mas,last-1);
            mas[last-1] = a;
        }
        if(last > 2 && (mas[last-3].charAt(0) == mas[last].charAt(0) || mas[last-3].charAt(1) == mas[last].charAt(1))) {
            String a = mas[last-3];
            mas[last-3] = mas[last];
            func(mas,last-1);
            mas[last-3] = a;
        }
    }
}


package codeforces;

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

public class CapsLock {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String input = br.readLine();

		String org = input;
		input = input.toUpperCase();

		String orgSub = org.substring(1);
		String inputSub = input.substring(1);

		System.out.println(orgSub + " " + inputSub);
		StringBuilder output = new StringBuilder();

		if(orgSub.equals(inputSub)) {
			if(org.charAt(0) >= 'a') {
				char ch = (char) (org.charAt(0) - 32);
				output.append(ch);
			} else {
				output.append(org.charAt(0));
			}

			output.append(inputSub.toLowerCase());
			System.out.println(output);
		} else {
			System.out.println(org);
		}

	}

}


import java.util.*;

public class A62 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int al = in.nextInt();
        int ar = in.nextInt();
        int bl = in.nextInt();
        int br = in.nextInt();
        if(Math.abs(al - br) <= 1 || Math.abs(ar - bl) <= 1) {
            System.out.println("YES");
            return;
        }
        if(al - br >= 2 || ar - bl >= 2) {
            System.out.println("NO");
            return;
        }
        if(bl - ar >= 3 || br - al >= 3) {
            System.out.println("NO");
            return;
        }
        System.out.println("YES");
    }
}


import java.util.Scanner;
// 527 A for long range not working
public class Main {
	static double ans=0;
	public static void main(String []args){
		Scanner scan=new Scanner(System.in);
		double a=scan.nextDouble();
		double b=scan.nextDouble();
		for(int i=0; ;i++){
			if(a<=0||b<=0) {
				System.out.println((int)ans);
				return ;
			}
			if (a-b>b) {
				a=a-b;
			}
			else{
				a=a+b;
				b=a-b;
				a=a-b;
				b=b-a;
			}
			ans++;
		}

	}

/*	public static void papergame(double a,double b){
		if(a<=0||b<=0) {
			System.out.println(ans);
			return ;
		}
		if (a-b>b) {
			a=a-b;
		}
		else{
			a=a+b;
			b=a-b;
			a=a-b;
			b=b-a;
		}
		ans++;
		papergame(a,b);

	}*/
}


import java.util.Scanner;

public class Enter {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int n = scanner.nextInt();

        int d[] = new int[n + 1];
        d[1] = x;
        d[2] = y;
        for (int i = 3; i <= n; i++) {
            d[i] = d[i - 1] - d[i - 2];
        }
        if (d[n] >= 0) {
            System.out.print(d[n] % 1000000007);
        } else {
            System.out.print(d[n] + 1000000007);
        }
    }
}


import java.util.*;
import java.io.*;
public class Cf257b {
    public static void main(String[] args) throws IOException {
        InputStreamReader fin = new InputStreamReader(System.in);
        Scanner scr = new Scanner(fin);
        int x = scr.nextInt();
        int y = scr.nextInt();
        int n = scr.nextInt();
        PrintWriter fout = new PrintWriter(System.out);
        if (n == 1) {
            fout.print((1000000007+x%1000000007)%1000000007);
        } else if (n == 2) {
            fout.print((1000000007+y%1000000007)%1000000007);
        } else {
            int [] a = new int [n];
            a[0] = x;
            a[1] = y;
            for (int i = 2; i < n; i++) {
                a[i] = a[i-1] - a[i-2];
            }
            fout.print((1000000007+a[n-1]%1000000007)%1000000007);
        }
        fout.flush();
        fout.close();
    }
    /*
    public static void main(String[] args) throws IOException {
        InputStreamReader fin = new InputStreamReader(System.in);
        Scanner scr = new Scanner(fin);
        int x = scr.nextInt();
        int y = scr.nextInt();
        int n = scr.nextInt();
        PrintWriter fout = new PrintWriter(System.out);
        if (n == 1) {
            fout.print((1000000007+x%1000000007)%1000000007);
        } else if (n == 2) {
            fout.print((1000000007+y%1000000007)%1000000007);
        } else {
            fout.print((1000000007+fib(n,x,y)%1000000007)%1000000007);
        }
        fout.flush();
        fout.close();
    }
    static int fib(int n, int x, int y) {
        if (n == 1){
            return x;
        } if (n == 2) {
            return y;
        }
        return fib(n-1, x, y) - fib(n-2, x, y);
    }
    *
    */
}


import java.util.Scanner;

/**
 *
 * @author MOI-I$EN
 */
public class Jzzhu_and_Sequences {
    public static void main(String args[]){
            Scanner in = new Scanner(System.in);
            int x,y ;
            x = in.nextInt();
            y = in.nextInt();
            int enter ;
            enter = in.nextInt();
            int temp [] = new int [enter];
            temp[0]=x;
            temp[1]=y;
            enter--;
            if(enter<=1){
                if(temp[enter]<0){
                    while(temp[enter]<0)
                        temp[enter]+=1000000007;
                    while(temp[enter]>1000000007)
                        temp[enter]-=1000000007;
                    System.out.println(temp[enter]);
                    return;
                }
            }else{
                    for(int i=2;i<enter+1;i++)
                        temp[i]=temp[i-1]-temp[i-2];
                    while(temp[enter]<0)
                        temp[enter]+=1000000007;
                    while(temp[enter]>1000000007)
                        temp[enter]-=1000000007;
                    System.out.println(temp[enter]);
                }
    }
}


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

public class First {
    private static final Scanner sc = new Scanner(System.in);
    private static final PrintWriter pw = new PrintWriter(System.out);
    private static StringBuffer ans = new StringBuffer();

    public static void main(String[] args) throws Exception {
        long t = sc.nextLong(), max = 0;
        for (long n = t; n > 0L; n--) max = Math.max(max, lcm(n, lcm(n, n)));
        ans.append(max);
        pw.print(ans);
        sc.close();
        pw.close();
    }

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

    private static long lcm(long n, long res) {
        long num = 1L, max = 0, val = 1;
        for (long i = n; i > 1L; i--) {
            long t = gcd(i, res);
            if (max < (i * res) / t) {
                max = (i * res) / t;
                num = i;
                val = t;
            }
        }
        res *= num;
        res /= val;
        return res;
    }

}

class Scanner {
    private final BufferedReader br;
    private StringTokenizer st;

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

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

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

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

class PrintWriter {
    private final BufferedOutputStream pw;

    public PrintWriter(OutputStream out) {
        pw = new BufferedOutputStream(out);
    }

    public void print(Object o) throws IOException {
        pw.write(o.toString().getBytes());
        pw.flush();
    }

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


public class A {
    public void run() {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int n = s.length();
        String[] ss = new String[n];
        for (int i = 0; i < n; i++)
            ss[i] = s.substring(i);
        sort(ss);
        int res = 0;
        for (int i = 1; i < n; i++)
            res = max(res, count(ss[i - 1], ss[i]));
        System.out.println(res);
    }

    int count(String s, String t) {
        int ret = 0;
        for (int i = 0; i < min(s.length(), t.length()); i++)
            if (s.charAt(i) != t.charAt(i))
                return ret;
            else
                ret++;
        return ret;
    }

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

    public static void main(String... args) {
        new A().run();
    }
}


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

public class Main {
    public static void main(String ...args) throws Throwable {
        Scanner in = new Scanner(System.in);
        String init = in.nextLine();
        HashSet<String> h = new HashSet<String>();
        for (int len = init.length() - 1; len >= 1; --len)  {
            h.clear();
            for (int pos = 0; pos + len <= init.length(); ++pos) {
                String now = init.substring(pos, pos + len);
                if (h.contains(now)) {
                    System.out.println(len);
                    return;
                }
                h.put(now);
            }

        }

        System.out.println(0);
    }
}


import java.util.Scanner;
import java.util.Vector;

public class DoubleCola {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int turn = scan.nextInt();
        int max = 0;
        int loop=0;
        String[] names = {"Sheldon", "Leonard", "Penny", "Rajesh", "Howard"};
        Vector<String> dc = new Vector<String>();

        iExit:
        for(int i=1; i<=turn; i*=2) {
            for(int j=0; j<names.length; ) {
                if(loop<i) {
                    dc.add(names[j]);
                    max++;
                    if(max==turn) {break iExit;}
                    loop++;
                    continue;
                }
                loop = 0;
                j++;
            }
        }

        System.out.println(dc.get(turn-1));
    }
}