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

public class VK16_3F {

	static int B;
	static int P;
	static int Q;

	static long[] iFact;
	static long[] iFact2;

	public static void main0(String[] args) {
		System.out.println(Integer.toUnsignedString(inv(7)));
	}

	static int[] pCnt;
	static int[] cCnt;

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		B = Integer.parseInt(inputData.nextToken());
		P = Integer.parseInt(inputData.nextToken());
		P = Math.min(P, B);
		Q = Integer.parseInt(inputData.nextToken());

		pCnt = new int[P + 1];
		cCnt = new int[P + 1];

		Arrays.fill(pCnt, 1);// if there are no nights left, irrespective of number of sleeping places and as long as
								// there is at least one bear left, you can always get at most one barrel
		if (P == B) {
			pCnt[0] = 0;
		}

		int ans = 0;
		for (int n = 1; n <= Q; n++) {
			for (int p = 0; p <= P; p++) {
				calculate(p, n);
			}
			ans ^= n * cCnt[P];
			int[] temp = pCnt;
			pCnt = cCnt;
			cCnt = temp;
			Arrays.fill(temp, 0);
		}
		printer.println(ans);
		printer.close();
	}

	static void calculate(int p, int n) {
		int b = B - (P - p);
		int endI = Math.min(b, p);

		int sum = 0;
		for (int i = 0; i <= endI; i++) {
			sum += comb(b, i) * pCnt[p - i];
		}
		cCnt[p] = sum;
	}

	static int comb(int n, int k) {
		int num = 1;
		int den = 1;
		int pow2 = 0;

		if (n - k < k) {
			k = n - k;
		}

		for (int i = 1; i <= k; i++) {
			int cPow2 = Integer.numberOfTrailingZeros(i);
			pow2 -= cPow2;
			den = den * (i >> cPow2);

			cPow2 = Integer.numberOfTrailingZeros(n + 1 - i);
			pow2 += cPow2;
			num = num * ((n + 1 - i) >> cPow2);
		}
		return num * inv(den) << pow2;
	}

	static int inv(int n) {
		int x = 1;
		x = x * (2 - x * n); /* Newton's method */
		x = x * (2 - x * n); /* 5 steps enough for 32 bits */
		x = x * (2 - x * n);
		x = x * (2 - x * n);
		x = x * (2 - x * n);
		return x;
	}
}


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

public class VK16_3F {

	static int B;
	static int P;
	static int Q;

	static long[] iFact;
	static long[] iFact2;

	public static void main0(String[] args) {
		System.out.println(Integer.toUnsignedString(inv(7)));
	}

	static int[] pCnt;
	static int[] cCnt;

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		StringTokenizer inputData = new StringTokenizer(reader.readLine());
		B = Integer.parseInt(inputData.nextToken());
		P = Integer.parseInt(inputData.nextToken());
		P = Math.min(P, B);
		Q = Integer.parseInt(inputData.nextToken());

		pCnt = new int[P + 1];
		cCnt = new int[P + 1];

		Arrays.fill(pCnt, 1);// if there are no nights left, irrespective of number of sleeping places and as long as
								// there is at least one bear left, you can always get at most one barrel
		if (P == B) {
			pCnt[0] = 0;
		}

		long ans = 0;
		for (int n = 1; n <= Q; n++) {
			for (int p = 0; p <= P; p++) {
				calculate(p, n);
			}
			int res = n * cCnt[P];
			ans ^= Integer.toUnsignedLong(res);
			int[] temp = pCnt;
			pCnt = cCnt;
			cCnt = temp;
			Arrays.fill(temp, 0);
		}
		printer.println(ans);
		printer.close();
	}

	static void calculate(int p, int n) {
		int b = B - (P - p);
		int endI = Math.min(b, p);

		int sum = 0;
		for (int i = 0; i <= endI; i++) {
			sum += comb(b, i) * pCnt[p - i];
		}
		cCnt[p] = sum;
	}

	static int comb(int n, int k) {
		int num = 1;
		int den = 1;
		int pow2 = 0;

		if (n - k < k) {
			k = n - k;
		}

		for (int i = 1; i <= k; i++) {
			int cPow2 = Integer.numberOfTrailingZeros(i);
			pow2 -= cPow2;
			den = den * (i >> cPow2);

			cPow2 = Integer.numberOfTrailingZeros(n + 1 - i);
			pow2 += cPow2;
			num = num * ((n + 1 - i) >> cPow2);
		}
		return num * inv(den) << pow2;
	}

	static int inv(int n) {
		int x = 1;
		x = x * (2 - x * n); /* Newton's method */
		x = x * (2 - x * n); /* 5 steps enough for 32 bits */
		x = x * (2 - x * n);
		x = x * (2 - x * n);
		x = x * (2 - x * n);
		return x;
	}
}


/* 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 file
{
  public static void main (String[] args) throws java.lang.Exception
  {
    // your code goes here
  Scanner sc=new Scanner(System.in);
   int t=sc.nextInt();
    for(int k=0;k<t;k++)
    {
      long ans=Long.MAX_VALUE;
      long n=sc.nextLong();
      if(n%2==0)
        System.out.println((n/2)+" "+(n/2));
      else{
      for(long i=n-1;i>n/2;i--)
      {
        long x=lcm(i,n-i);
        ans=Math.min(ans,x);

      }

        System.out.println((n-ans)+" "+(ans));
    }
    }

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

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


import java.util.*;

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

        int num = Sc.nextInt();

        while(num > 0)
        {
            int d = num%10;
            if(d < 5)
            {
                System.out.print("O-|");
            }
            else
            {
                System.out.print("-O|");
                d -= 5;
            }
            while(d--)
            {
                System.out.print("O");
            }
            System.out.print("-");
            d = 4-d;
            while(d--)
            {
                System.out.print("O");
            }

            System.out.println();
            num = num/10;
        }

    }
}


import java.util.*;
public class MyClass {

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

        int move = 0;
        int i = 0;

        while(i < x)
        {
            if(str.indexOf(i + "") < 0)
                move++;

            i++;
        }

        while(true)
        {
            if(str.indexOf(i + "") >= 0)
                move++;
            else
                break;
        }

        System.out.println(move);
    }
}


/* 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
	{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String s[]=br.readLine().spllit(" ");
		int n=Integer.parseInt(s[0]);
		int m=Integer.parseInt(s[1]);
		int a=Math.min(a,b);
		int b=Math.max(a,b);
		int ans=(b-a)%a;
		System.out.println(ans);
	}
}


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

public class DataRecovery{
        public static void main(String[] argv) throws Exception{
                BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
                String[] words=br.readLine().trim().split(" ");
                int n=Integer.parseInt(words[0]), m=Integer.parseInt(words[1]), min=Integer.parseInt(words[2]), max=Integer.parseInt(words[3]);
                boolean maxFound=false, minFound=false;
                int cur;
                for(int i=0; i<m; i++){
                        cur=Integer.parseInt(br.readLine().trim());
                        if(cur==min){
                                minFound=true;
                        }else if(cur==max){
                                maxFound=true;
                        }
                }
                if(minFound && maxFound){
                        System.out.println("Correct");
                }else if((minFound || maxFound) && n-m>=1){
                        System.out.println("Correct");
                }else if(n-m>=2){
                        System.out.println("Correct");
                }else{
                        System.out.println("Incorrect");
                }
        }
}


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

public class Main implements Runnable {

    long MOD = 1000000009;
    public void solve() throws IOException {
        int n = nextInt();
        long[] ans = new long[n + 1];
        long[] q = new long[n + 1];
        q[0] = 1;
        for(int i = 1; i <= n; ++i)
            q[i] = (2 * (1 + q[i - 1]) + 1) % MOD;
        ans[2] = 2;
        for(int t = 4; t <= n; t += 2) {
            long qq = (q[(t - 4) / 2]);
            ans[t] = (ans[t - 2] + 4 * qq) % MOD;
        }
        long tmp = ans[n];
        //pw.println(tmp);
        long p = (tmp * tmp + 1) * 2 % MOD;
        pw.println(p);
    }

    static final String filename = "A";
    static final boolean fromConsole = true;

    public void run() {
        try {
            if (!fromConsole) {
                in = new BufferedReader(new FileReader(filename + ".in"));
                pw = new PrintWriter(filename + ".out");
            } else {
                in = new BufferedReader(new InputStreamReader(System.in));
                pw = new PrintWriter(System.out);
            }
            st = new StringTokenizer("");
            long st = System.currentTimeMillis();
            solve();
            //pw.printf("\nWorking time: %d ms\n", System.currentTimeMillis() - st);
            pw.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    private StringTokenizer st;
    private BufferedReader in;
    private PrintWriter pw;

    boolean hasNext() throws IOException {
        while (!st.hasMoreTokens()) {
            String line = in.readLine();
            if (line == null) {
                return false;
            }
            st = new StringTokenizer(line);
        }
        return st.hasMoreTokens();
    }

    String next() throws IOException {
        return hasNext() ? st.nextToken() : null;
    }

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

    BigInteger nextBigInteger() throws IOException {
        return new BigInteger(next());
    }

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

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

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


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

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

	void solve()
	{
		int n = ni();
		int mod = 1000000009;
		long[] dp = new long[n+1];
		if(6 <= n)dp[6] = 5;
		for(int i = 8;i <= n;i+=2){
			dp[i] = ((dp[i-2] + 1) * 2L + 1) % mod;
		}

		long ret = 1;
		for(int i = n;i >= 3;i--){
			if(dp[i-1] == 0){
				ret = ret + 2;
				if(ret >= mod)ret -= mod;
			}else{
				ret = ((ret+1)*dp[i-1]+1) % mod;
			}
		}
		ret = ((ret+1)*(ret+1)+1)%mod;
		out.println(ret*2%mod);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


import java.io.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.StringTokenizer;

public class ZeptA {

    private static Scanner in;
    private static Output out;
    static boolean isFile = false;

    static HashMap<Integer, Boolean> map = new HashMap<>();

    public static void solve() throws Exception {
        int n = in.nextInt();
        char[] c = in.nextLine().trim().toCharArray();

        ArrayList<Integer> l = new ArrayList<>();
        for (int i = 0; i < c.length; i++)
            if (c[i] == '*') l.add(i + 1);

        int index = 0;
        if (l.isEmpty()) {
            out.print(0);
            return;
        }
        while (true) {
            Integer elementIndex = l.get(index);
            if (l.size() - index < 5)
                break;

            outer:
            for (int i = index + 1; i < l.size(); i++) {
                int diff = l.get(i) - elementIndex;
                int current = elementIndex;
                int count = 1;
                while (true) {
                    if (count == 4) {
                        out.println("yes");
                        return;
                    }
                    int next = current + diff;
                    int foundIndex = Collections.binarySearch(l, next);
                    if (foundIndex < 0) {
                        continue outer;
                    }
                    current = next;
                    count++;
                }
            }
            index++;
        }

        out.println("no");

    }

    static Exception exception;

    public static void main(String[] args) throws Exception {
        Thread thread = new Thread(null, new Runnable() {
            @Override
            public void run() {
                try {
                    initReaderWriter();
                    solve();
                    out.close();
                } catch (Exception ex) {
                    exception = ex;
                }
            }
        }, "", 1 << 26);
        thread.start();
        thread.join();

        if (exception != null) {
            throw exception;
        }
    }

    private static void initReaderWriter() throws Exception {
        if (isFile) {
            in = new Scanner("input.txt");
            out = new Output(new File("output.txt"));
        } else {
            in = new Scanner();
            out = new Output(System.out);
        }
    }

    private static boolean log = false;

    public static void log(String msg) {
        if (log) {
            out.println(msg);
            out.flush();
        }
    }

    private static class Scanner {

        StringTokenizer st = null;
        BufferedReader bf;

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

        public Scanner(String fileName) throws FileNotFoundException {
            bf = new BufferedReader(new FileReader(fileName));
        }

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

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

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

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

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

    private static class Output extends PrintStream {

        public Output(OutputStream out) {
            super(new BufferedOutputStream(out));
        }

        public Output(File file) throws FileNotFoundException {
            super(new BufferedOutputStream(new FileOutputStream(file)));
        }
    }
}
33333


import java.util.Scanner;

public class ZEPTO{
   public static void main(String[] args){
       Scanner scanner = new Scanner(System.in);
       int n = scanner.nextInt();
       char c[] = new char[n];
       for(int i=0;i<n;i++){
           c[i] = scanner.next();
       }
       boolean b = false;
       for(int i=1;i<n/4;i++){
            int s = 0;
            for(int j=0;j<n/i;j++){
                if(c[i*j] == '*'){
                    s ++;
                    if(s > 4){
                        b = true;
                        break;
                    }
                }else{
                   s = 0;
                }
            }
           if(b){
               break;
           }
       }
      if(b){
         System.out.println("yes");
       }
   }
}


package x0001_aim_tech_round_div_1;

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

public class A_GraphAndString {
	public static final int A = 1, B = 2, C = 3, NOT_MARKED = 0;

	private final boolean isDebug;

	int n, m;
	boolean[][] g;
	int[] v;
	public A_GraphAndString(boolean isDebug) {
		this.isDebug = isDebug;
	}

	public void readInput() {
		Scanner sc = null;
		if (isDebug) {
			try {
				sc = new Scanner(new FileInputStream("src\\x0001_aim_tech_round_div_1\\A_input1.txt"));
			} catch (FileNotFoundException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		} else {
			sc =  new Scanner(System.in);
		}

		n = sc.nextInt();
		m = sc.nextInt();
		if (isDebug)
			System.out.format("n=%d m=%d%n", n, m);

		g = new boolean[n][n];
		for (int i = 0; i < m; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			if (isDebug)
				System.out.format("%d %d%n", u + 1, v + 1);
			g[u][v] = true;
		}

		v = new int[n];
	}

	public void solve() {
		if (m == 0) {
			switch (n) {
			case 1:
				System.out.println("Yes");
				System.out.print("a");
				break;
			case 2:
				System.out.println("Yes");
				System.out.print("ac");
				break;
			default:
				System.out.println("No");
				break;
			}

			return;
		}

		mark();
	}

	private void mark() {
		findAndMarkAllB();
		if (!findAndMarkAllA())
			return;
		if (!findAndMarkAllC())
			return;

		if (isGraphLegit()) {
			System.out.println("Yes");
			for (int i = 0; i < n; i++) {
				String letter;
				switch (v[i]) {
				case A: letter = "a"; break;
				case B: letter = "b"; break;
				case C: letter = "c"; break;
				default:
					throw new AssertionError();
				}
				System.out.print(letter);
			}
		} else {
			System.out.println("No");
		}
	}

	private void findAndMarkAllB() {
		for (int y = 0; y < n; y++) {
			boolean isB = true;
			for (int x = 0; x < n; x++) {
				if (y != x && !connected(y, x)) {
					isB = false;
					break;
				}
			}

			if (isB) {
				v[y] = B;
			}
		}
	}

	private boolean findAndMarkAllA() {
		int idxA = -1;
		for (int i = 0; i < n; i++) {
			if (v[i] == NOT_MARKED) {
				idxA = i;
				break;
			}
		}

		if (idxA == -1) {	// All B
			System.out.println("Yes");
			for (int i = 0; i < n; i++) {
				System.out.print("b");
			}

			return false;
		}

		v[idxA] = A;
		for (int i = idxA + 1; i < n; i++) {
			if (connected(idxA, i) && v[i] == NOT_MARKED) {
				v[i] = A;
			}
		}

		return true;
	}

	private boolean findAndMarkAllC() {
		int idxC = -1;
		for (int i = 0; i < n; i++) {
			if (v[i] == NOT_MARKED) {
				idxC = i;
				break;
			}
		}

		if (idxC == -1) {	// No C
			if (isGraphLegit()) {
				System.out.println("Yes");
				for (int i = 0; i < n; i++) {
					String letter = v[i] == B ? "b" : "a";
					System.out.print(letter);
				}
			} else {
				System.out.println("No");
			}

			return false;
		}

		v[idxC] = C;
		for (int i = idxC + 1; i < n; i++) {
			if (v[i] == NOT_MARKED) {
				if (connected(idxC, i)) {
					v[i] = C;
				} else {
					System.out.println("No");
					return false;
				}
			}
		}

		return true;
	}

	private boolean isGraphLegit() {
		for (int i = 0; i < n; i++) {
			if (v[i] == A || v[i] == C) {
				int letter = v[i] == A ? C : A;
				for (int j = 0; j < n; j++) {
					if (i != j) {
						if ((v[j] != letter && !connected(i, j))
								|| (v[j] == letter && connected(i, j))) {
							return false;
						}
					}
				}
			}
		}

		return true;
	}

	private boolean connected(int u, int v) {
		return g[u][v] || g[v][u];
	}

	public static void main(String[] args) {
		A_GraphAndString solver = new A_GraphAndString(false);
		solver.readInput();
		solver.solve();
	}
}


import java.util.*;
  public class Solution{
     public static void main(String args[]){
     Scanner s=new Scanner(System.in);
     String[] str=new String[21];
     int n=s.nextInt();
     str[0]="zero";
     str[1]="one";
     str[2]="two";
     str[3]="three";
     str[4]="four";
     str[5]="five";
     str[6]="six";
     str[7]="seven";
     str[8]="eight";
     str[9]="nine";

     str[10]="ten";
     str[11]="eleven";
     str[12]="twelve";
     str[13]="thirteen";

     str[14]="fourteen";
     str[15]="fifteen";
     str[16]="sixteen";

     str[17]="seventeen";
     str[18]="eighteen";
     str[19]="ninteen";
     str[20]="twenty";
     if(n<=20){
          System.out.println(str[n]);
     }
     else{
          int a=n/10;
          int b=n%10;
          Stirng str1="";
          if(a==2){
               str1+="twenty";
          }
          if(a==3){
               str1+="thirty";
          }
          if(a==4){
               str1+="forty";
          }
          if(a==5){
               str1+="fifty";
          }
          if(a==6){
               str1+="sixty";
          }
          if(a==7){
               str1+="seventy";
          }
          if(a==8){
               str1+="eighty";
          }
          if(a==9){
               str1+="ninty";
          }
          if(b!=0){
               str1+="-"+str[b];
          }

          System.out.println(str1);

     }

     }

   }


import java.util.*;

public class Pottert{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		float a = scan.nextFloat();
		float b = scan.nextFloat();
		float c = scan.nextFloat();
		float d = scan.nextFloat();
		float e = scan.nextFloat();
		float f = scan.nextFloat();

		if(b == 0 || d == 0 || f == 0){
			if(c == 0 && d != 0){
				System.out.println("Ron");
			}else{
				System.out.println("Hermione");
			}
		}else{
			float result = (a/b) * (c/d) * (e/f);
			if(result < 1){
				System.out.println("Ron");
			}else{
				System.out.println("Hermione");
			}
		}
	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.StringTokenizer;

public class CodeForce308C {

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

        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer token = new StringTokenizer(in.readLine());
        Long w = Long.parseLong(token.nextToken());
        Long m = Long.parseLong(token.nextToken());
        if(w==2) {
            System.out.println("YES");
        }
        Long start = System.currentTimeMillis();

        List<Long> combination = new ArrayList<Long>();
        for(int i=0;i<=100;i++) {
            long num = (long)Math.pow(w, i);
            if(num>(long)2*Integer.MAX_VALUE) {
//              if(num>(long)2*m) {
                break;
            }

            combination.add(num);
            int till=combination.size()-1;
            for(int j=0;j<till;j++) {
                combination.add(combination.get(j)+num);
            }
        }
//      System.out.println(System.currentTimeMillis()-start);
        Collections.sort(combination);
        if(Collections.binarySearch(combination, m)>=0) {
            System.out.println("YES");
            return;
        }
        for (Long element : combination) {
//          if(Collections.binarySearch(combination, element+m)>=0 || Collections.binarySearch(combination, Math.abs(element-m))>=0) {
                if(Collections.binarySearch(combination, element+m)>=0) {
                System.out.println("YES");
                return;
            }
        }
        System.out.println("NO");

    }

}


import java.util.Scanner;
public class Quiz337C {

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

        long kMinusResult = kMinusOneAssembler(questions, correct, multiplier);
        int bruteForceResult = bruteForce(questions, correct, multiplier);
        //System.out.printf("The k minus one result is: %d\n",kMinusResult);
        //System.out.printf("The brute force result is: %d\n",bruteForceResult);

        input.close();

        System.out.print(kMinusResult % 1000000009);

        return;

    }

    public static long kMinusOneAssembler(int questions, int correct, int multiplier)
    {
        boolean questionAnswers[] = new boolean[questions];
        int index = questions - 1;
        int remainingCorrects = correct;
        int remainingIncorrects = questions - correct;
        int untilMultiplier = multiplier;
        while(remainingCorrects != 0 || remainingIncorrects != 0)
        {
            if(untilMultiplier > 1)
            {
                if(remainingCorrects > 0)
                {
                    questionAnswers[index] = true;
                    untilMultiplier--;
                    remainingCorrects--;
                }
                else
                {
                    questionAnswers[index] = false;
                    untilMultiplier = multiplier;
                    remainingIncorrects--;
                }
            }
            else
            {
                if(remainingIncorrects > 0)
                {
                    questionAnswers[index] = false;
                    untilMultiplier = multiplier;
                    remainingIncorrects--;
                }
                else
                {
                    questionAnswers[index] = true;
                    untilMultiplier = multiplier;
                    remainingCorrects--;
                }
            }
            index--;
        }

        return arrayToScore(questionAnswers, questions, multiplier);
    }

    public static int bruteForce(int questions, int correct, int multiplier)
    {
        return 0;
    }

    public static long arrayToScore(boolean[] answers, int questions, int multiplier)
    {
        long total = 0;
        int index = 0;
        int untilMultiplier = multiplier;
        while(index < questions)
        {
            if(answers[index])
            {
                total++;
                untilMultiplier--;
                if(untilMultiplier == 0)
                {
                    total *= 2;
                    untilMultiplier = multiplier;
                }
            }
            else
            {
                untilMultiplier = multiplier;
            }
            total = total % 1000000009;
            index++;
        }
        return total;
    }

}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.*;
public class A {
	InputStream is;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
	   //out.println((Integer.toBinaryString(ni())).length());
	   String s = ns();
	   int a[][] = new int[10001][10001];
	   int x = 100, y = 100;
	   String ans = "OK";
	   a[x][y] = 1;
	   for(int i=0;i<s.length();i++){
	       char ch = s.charAt(i);
	       if(ch=='R') x++;
	       else if(ch=='U') y++;
	       else if(ch=='D') y--;
	       else x--;
	       if(a[x][y]==1) ans = "BUG";
	       a[x][y] = 1;
	   }
	   out.println(ans);
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

	private static void tr(Object... o) { System.out.println(Arrays.deepToString(o)); }
}


// Main Code at the Bottom
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.BigInteger;
public class Main {
	//Fast IO class
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
        public FastReader() {
        	boolean env=System.getProperty("ONLINE_JUDGE") != null;
        	if(!env) {
        		try {
					br=new BufferedReader(new FileReader("src\\input.txt"));
				} catch (FileNotFoundException e) {
					e.printStackTrace();
				}
        	}
        	else 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;
        }
    }
    static long MOD=1000000000+7;
    //Euclidean Algorithm
    static long gcd(long A,long B){
    	return (B==0)?A:gcd(B,A%B);
    }
    //Modular Exponentiation
    static long fastExpo(long x,long n){
        if(n==0) return 1;
        if((n&1)==0) return fastExpo((x*x)%MOD,n/2)%MOD;
        return ((x%MOD)*fastExpo((x*x)%MOD,(n-1)/2))%MOD;
    }
    //Modular Inverse
    static long inverse(long x) {
    	return fastExpo(x,MOD-2);
    }
    //Prime Number Algorithm
    static boolean isPrime(long n){
        if(n<=1) return false;
        if(n<=3) return true;
        if(n%2==0 || n%3==0) return false;
        for(int i=5;i*i<=n;i+=6) if(n%i==0 || n%(i+2)==0) return false;
        return true;
    }
    //Reverse an array
    static void reverse(char arr[],int l,int r){
    	while(l<r) {
    		char tmp=arr[l];
    		arr[l++]=arr[r];
    		arr[r--]=tmp;
    	}
    }
    //Print array
    static void print1d(int arr[]) {
    	out.println(Arrays.toString(arr));
    }
    static void print2d(long arr[][]) {
    	for(long a[]: arr) out.println(Arrays.toString(a));
    }
    // Pair
    static class pair{
    	int x,y;
    	pair(int a,int b){
    		this.x=a;
    		this.y=b;
    	}
    	public boolean equals(Object obj) {
    		if(obj == null || obj.getClass()!= this.getClass()) return false;
            pair p = (pair) obj;
            return (this.x==p.x && this.y==p.y);
        }
    	public int hashCode() {
            return Objects.hash(x,y);
        }
    }
    static FastReader sc=new FastReader();
    static PrintWriter out=new PrintWriter(System.out);
    //Main function(The main code starts from here
    public static void main (String[] args) throws java.lang.Exception {
    	int test=1;
    	//test=sc.nextInt();
    	while(test-->0){
    		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(),d=sc.nextInt();
    		int dp[]=new int[b+c+5];
    		for(int i=a;i<=b;i++) {
    			dp[i+b]++;
    			dp[i+c+1]--;
    		}
    		for(int i=1;i<b+c+5;i++) dp[i]+=dp[i-1];
    		for(int i=b+c+3;i>=0;i--) dp[i]+=dp[i+1];
    		long ans=0;
    		for(int i=c;i<=d;i++) ans+=dp[i+1];
    		out.println(ans);
    	}
        out.flush();
        out.close();
    }
}


import java.util.Scanner;
public class HQ9 {

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

String  s=sc.next();
int j=0;
char[] ch=s.toCharArray();
for(int i=0;i<ch.length;i++){
	System.out.print(ch[i]+" ");
	if(ch[i]=='H'||ch[i]=='Q'||ch[i]=='9')
		j++;

}if(j>0)
	System.out.println("YES");
else System.out.println("NO");

}
	}


//package com.codeforces.competitions.year2016.goodbye2016;

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

public final class TaskD
{
	public static void main(String[] args)
	{
		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		Solver solver = new Solver(in, out);

		solver.solve();
		in.close();
		out.flush();
		out.close();
	}

	static class Solver
	{
		int n;
		int[] steps, dx, dy;
		int[][][][][] dp;
		boolean[][] vis;
		InputReader in;
		PrintWriter out;

		void solve()
		{
//			long start = System.currentTimeMillis();
			n = in.nextInt();
			steps = in.nextIntArray(n);
			dx = new int[]{0, 1, 1, 1, 0, -1, -1, -1};
			dy = new int[]{1, 1, 0, -1, -1, -1, 0, 1};
			dp = new int[320][320][n + 1][6][8];
			vis = new boolean[320][320];

			for (int i = 0; i < 320; i++)
				for (int j = 0; j < 320; j++)
					for (int k = 0; k <= n; k++)
						for (int l = 0; l < 6; l++)
							Arrays.fill(dp[i][j][k][l], -1);

			mark(150, 150, 0, 1, 0);

			int cnt = 0;

			for (int i = 0; i < 320; i++)
				for (int j = 0; j < 320; j++)
					if (vis[i][j])
						cnt++;

			out.println(cnt);
//			System.out.println("time taken : " + (System.currentTimeMillis() - start));
		}

		void mark(int x, int y, int level, int stepsWalked, int dir)
		{
/*			System.out.println("x : " + x + ", y : " + y + ", level : " + level + ", stepsWalked : " + stepsWalked +
					", dir : " + dir);*/
			if (level == n)
				return;

			if (dp[x][y][level][stepsWalked][dir] != -1)
				return;

			if (stepsWalked == steps[level])
			{
				int left, right;

				left = (dir + 7) % 8;
				right = (dir + 1) % 8;
				mark(x + dx[left], y + dy[left], level + 1, 1, left);
				mark(x + dx[right], y + dy[right], level + 1, 1, right);
			}
			else
				mark(x + dx[dir], y + dy[dir], level, stepsWalked + 1, dir);

			vis[x][y] = true;
			dp[x][y][level][stepsWalked][dir] = 1;
		}

		public Solver(InputReader in, PrintWriter out)
		{
			this.in = in;
			this.out = out;
		}

	}

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

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

			return buf[curChar++];
		}

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

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

			int sgn = 1;

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

			int res = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();

				res *= 10;
				res += c & 15;

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

			return res * sgn;
		}

		public int[] nextIntArray(int arraySize)
		{
			int array[] = new int[arraySize];

			for (int i = 0; i < arraySize; i++)
				array[i] = nextInt();

			return array;
		}

		public long nextLong()
		{
			int c = read();

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

			int sign = 1;

			if (c == '-')
			{
				sign = -1;

				c = read();
			}

			long result = 0;

			do
			{
				if (c < '0' || c > '9')
					throw new InputMismatchException();

				result *= 10;
				result += c & 15;

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

			return result * sign;
		}

		public long[] nextLongArray(int arraySize)
		{
			long array[] = new long[arraySize];

			for (int i = 0; i < arraySize; i++)
				array[i] = nextLong();

			return array;
		}

		public float nextFloat()
		{
			float result, div;
			byte c;

			result = 0;
			div = 1;
			c = (byte) read();

			while (c <= ' ')
				c = (byte) read();

			boolean isNegative = (c == '-');

			if (isNegative)
				c = (byte) read();

			do
			{
				result = result * 10 + c - '0';
			} while ((c = (byte) read()) >= '0' && c <= '9');

			if (c == '.')
				while ((c = (byte) read()) >= '0' && c <= '9')
					result += (c - '0') / (div *= 10);

			if (isNegative)
				return -result;

			return result;
		}

		public double nextDouble()
		{
			double ret = 0, div = 1;
			byte c = (byte) read();

			while (c <= ' ')
				c = (byte) read();

			boolean neg = (c == '-');

			if (neg)
				c = (byte) read();

			do
			{
				ret = ret * 10 + c - '0';
			} while ((c = (byte) read()) >= '0' && c <= '9');

			if (c == '.')
				while ((c = (byte) read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);

			if (neg)
				return -ret;

			return ret;
		}

		public String next()
		{
			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)
		{
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		public String nextLine()
		{
			int c = read();

			StringBuilder result = new StringBuilder();

			do
			{
				result.appendCodePoint(c);

				c = read();
			} while (!isNewLine(c));

			return result.toString();
		}

		public boolean isNewLine(int c)
		{
			return c == '\n';
		}

		public void close()
		{
			try
			{
				stream.close();
			}
			catch (IOException e)
			{
				e.printStackTrace();
			}
		}

	}

	static class CMath
	{
		static long power(long number, long power)
		{
			if (number == 1 || number == 0 || power == 0)
				return 1;

			if (power == 1)
				return number;

			if (power % 2 == 0)
				return power(number * number, power / 2);
			else
				return power(number * number, power / 2) * number;
		}

		static long modPower(long number, long power, long mod)
		{
			if (number == 1 || number == 0 || power == 0)
				return 1;

			number = mod(number, mod);

			if (power == 1)
				return number;

			long square = mod(number * number, mod);

			if (power % 2 == 0)
				return modPower(square, power / 2, mod);
			else
				return mod(modPower(square, power / 2, mod) * number, mod);
		}

		static long moduloInverse(long number, long mod)
		{
			return modPower(number, mod - 2, mod);
		}

		static long mod(long number, long mod)
		{
			return number - (number / mod) * mod;
		}

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

		static long min(long... arr)
		{
			long min = arr[0];

			for (int i = 1; i < arr.length; i++)
				min = Math.min(min, arr[i]);

			return min;
		}

		static long max(long... arr)
		{
			long max = arr[0];

			for (int i = 1; i < arr.length; i++)
				max = Math.max(max, arr[i]);

			return max;
		}

		static int min(int... arr)
		{
			int min = arr[0];

			for (int i = 1; i < arr.length; i++)
				min = Math.min(min, arr[i]);

			return min;
		}

		static int max(int... arr)
		{
			int max = arr[0];

			for (int i = 1; i < arr.length; i++)
				max = Math.max(max, arr[i]);

			return max;
		}

	}

}

/*

30
5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5

*/


import java.io.*;
import java.util.*;
/*
 * CodeForces New Year and Rating
 * @derrick20
 *  Used hint unfortunately, was trying binary search  to no avail. The idea of upper and lower
 * bound is quite similar to binary search, should've considered the math of the inequalities earlier...!
 */

public class DRedone {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        // Store the time at which a given level will explode
        explode = new int[N];
        int max = 0;
        for (int i = 0; i < N; i++) {
            explode[i] = sc.nextInt();
            max += explode[i];
        }
        int bound = 2*max + 1;
        reached = new int[bound][bound];
        visited = new int[bound][bound][6][N][8];
        // Directions:
        // 3 2 1
        // 4   0
        // 5 6 7

        // A state is x, y, current time since explosion, recursive level, direction

        dfs(max, max, 2, 1, 0);
        /*for (int i = 160; i >= 140; i--) {
            for (int j = 140; j <= 160; j++) {
                System.out.print(reached[i][j] != 0 ? reached[i][j] : " ");
            }
            System.out.println();
        } //*/
        System.out.println(ct);
    }
    static int N;
    static int[] explode;
    static int[][][][][] visited;
    static int[][] reached;
    static int ct = 0;
    static int[] dx = {1, 1, 0, -1, -1, -1, 0, 1};
    static int[] dy = {0, 1, 1, 1, 0, -1, -1, -1};

    static void dfs(int col, int row, int dir, int covered, int level) {
        if (level == N) {
            // If we have visited it with the same velocity, or finished the recursion, then stop
            return;
        }
        // We need to watch out, since if we explode at a location, it's fine to visit with the same spot, since we'll
        // add new locations
        if (visited[row][col][covered][level][dir] == 1) {
            //System.out.println(col + " " + row + " " + covered);
            // reached[row][col]++;
            return;
        }
        else {
            // Now that we've reached here, mark it as visited with the velocity. Future calls that reach this
            // same state will terminate early
            visited[row][col][covered][level][dir] = 1;
            if (reached[row][col] == 0) {
                ct++; // Keep track of the total number of spots reached!
                reached[row][col] += 1;
            }

            // It's time + 1 because we cover one more tile than the current time
            if (explode[level] == covered) {
                // At the current level, if enough time has passed, we must explode into two parts
                int adjDir1 = (dir + 1) % 8;
                int adjDir2 = (dir - 1 + 8) % 8;
                dfs(col + dx[adjDir1], row + dy[adjDir1], adjDir1, 1, level + 1);
                dfs(col + dx[adjDir2], row + dy[adjDir2], adjDir2, 1, level + 1);
            }
            else {
                // Otherwise, continue in the direction with more time
                dfs(col + dx[dir], row + dy[dir], dir, covered + 1, level);
            }
        }
    }

    static class Scanner {
        BufferedReader br;
        StringTokenizer st;

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

        Scanner(FileReader s) {
            br = new BufferedReader(s);
        }

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

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


import java.util.Scanner;

public class Pixel {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int i,j,k,n,a,b,c,big,middle,small,sum;
        boolean is;
        while (input.hasNext()){
            a = input.nextInt(); b = input.nextInt(); c = input.nextInt(); sum = 0; is = false;

            big = (a>=b) ? ((a>=c)? a :c) : ((b>=c) ? b : c);
            small = (a>=b) ? ((b>=c) ? c : b) : ((a>=c) ? c : a);
            middle = a>b ? (c>a ? a :(b>c)? b:c) : (c>b ? b : a>c? a : c);

           // System.out.println(big+ " " + middle + " " + small);
            for (i=0; i<big; i++){
                if (big == middle || big == small || middle == small) break;
                if ((middle - small ) % 2 == 0){
                   // big--;middle--;small++;
                    j = (middle - small);
                   // sum += (j/2);
                    sum += (small + j);
                    is = true;
                    break;
                }
                else break;
            }
            if (!is) {
                if (big == middle) sum += big;
                else if (big == small) sum += big;
                else if (small == middle) sum += small;
                else sum += big; System.out.println(sum);
            }
            else
            System.out.println(sum);
        }
    }
}


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

public class R {

	public static void main(String[] args) {
		FastReader fr = new FastReader();
		int a[] = new int[3];
		a[0] = fr.nextInt();
		a[1] = fr.nextInt();
		a[2] = fr.nextInt();
		Arrays.parallelSort(a);
		int result = 0;
		if (a[0] == 0 && a[1] == 1) {
			System.out.println(a[2]);
		} else if (a[0] == a[1]) {
			System.out.println(a[0]);
		} else if (a[2] == a[1]) {
			System.out.println(a[2]);
		} else if ((a[1] - a[0]) % 2 == 1) {
			result += a[2] - a[1];
			result += a[1];
			System.out.println(result);
		} else {
			result += (a[1]-a[0])/2;
			result += (a[1]+a[0])/2;
			System.out.println(result);
		}
	}

	static class FastReader {
		BufferedReader bf;
		StringTokenizer st;

		public FastReader()  {
			bf = new BufferedReader(new InputStreamReader(System.in));
			//bf = new BufferedReader(new FileReader("p.txt"));
		}
		String next() {
			while(st == null || !st.hasMoreElements())
				try {
					st = new StringTokenizer(bf.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() throws IOException {
			return bf.readLine();
		}
		boolean ready() throws IOException {
			return bf.ready() || (st != null && st.hasMoreElements());
		}
	}
}


import java.io.*;
import java.util.*;
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);
        TaskE solver = new TaskE();
        solver.solve(in, out);
        out.close();
    }
}

class TaskE {

    private final int MOD = 1000000007;

    public void solve(InputReader in, OutputWriter out) {
        int n = in.nextInt();
        int a = in.nextInt();
        int b = in.nextInt();
        int k = in.nextInt();

        long DP[][] = new long[k+1][n];
        for(int i=0;i<n;i++) {
            DP[0][i] = 1;
        }
        DP[0][b-1] = 0;

        for(int i=1;i<=k;i++) {
            long partialSums[] = preparePartialSum(DP, i-1, n);
            for(int j=0;j<b-1;j++) {
                DP[i][j] = partialSums[b-2] - partialSums[j];
                if(j > 0) DP[i][j] += partialSums[j-1];
                if(j > 0 && 2*j-b+1 < n && 2*j-b+1 >= 0) DP[i][j] -= partialSums[2*j-b+1];

                DP[i][j] = mod(DP[i][j], MOD);
            }
            for(int j=b;j<n;j++) {
                DP[i][j] = partialSums[j-1] - partialSums[b-1];
                int diff = j - b-1+1;
                DP[i][j] += (partialSums[Math.min(j+diff,n-1)]);
                DP[i][j] -= partialSums[j];
                DP[i][j] = mod(DP[i][j], MOD);

            }

        }

        out.printLine(DP[k][a-1] % MOD);

    }

    private long mod(long number, int mod) {
        long result = number % mod;
        if(result < 0) result += mod;
        return result;
    }

    private long[] preparePartialSum(long[][] dp, int i, int n) {
        long sum = 0;
        long sums[] = new long[n];
        for(int j=0;j<n;j++) {
            sum += dp[i][j];
            sums[j] = sum;
        }
        return sums;
    }

}
class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public boolean hasNext() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                String line = reader.readLine();
                if ( line == null ) {
                    return false;
                }
                tokenizer = new StringTokenizer(line);
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return true;
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
    public long nextLong() {
        return Long.parseLong(next());
    }
}
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 printLine(Object... objects) {
        print(objects);
        writer.println();
    }
    public void close() {
        writer.close();
    }
}


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

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

    public static void main(String args[]) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;
        while (t-- > 0) {
            n = in.nextInt();
            a = in.nextInt() - 1;
            b = in.nextInt() - 1;
            k = in.nextInt();
            if (b > a) {
                n = b + 1;
            } else {
                a = n - a - 1;
                b = n - b - 1;
                n = b + 1;
            }
            dp = new long[b][k + 1];
            pre = new long[b][k + 1];

            for (int j = 0; j <= k; j++) {
                for (int i = 0; i < b; i++) {
                    if (j == 0) {
                        if (i == a)
                            dp[i][j] = 1;
                    } else {
                        dp[i][j] = pre[Math.min(b - 1, (b + i - 1) / 2)][j - 1] - pre[0][j - 1] + dp[0][j - 1] - dp[i][j - 1];
                        dp[i][j] += 2 * MOD;
                        dp[i][j] %= MOD;
                    }
                    if (i != 0)
                        pre[i][j] = pre[i - 1][j] + dp[i][j];

                    else {
                        pre[i][j] = dp[i][j];
                    }
                    pre[i][j] %= MOD;

                }
            }

            out.println(pre[b - 1][k]);
        }
        out.close();
    }

    static long dp[][];
    static long pre[][];
    static int n, k, a, b;

    static 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];
            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 boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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


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

public class RidingInALift {

	static long dp[][];
	static long m = (long) (1e9 + 7);
	public static void main(String args[] ) throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	    PrintWriter w = new PrintWriter(System.out);

	    StringTokenizer st1 = new StringTokenizer(br.readLine());
	    int n = ip(st1.nextToken());
	    int a = ip(st1.nextToken());
	    int b = ip(st1.nextToken());
	    int K = ip(st1.nextToken());

	    if(a > b){
	    	a = n - a + 1;
	    	b = n - b + 1;
	    }

	    dp = new long[K+1][n+1];

	    for(int i=1;i<b;i++){
	    	int right = b-i-1;
	    	int left = Math.min(i-1, b-i-1);
	    	dp[1][i] = right + left;
	    }

	    for(int k=2;k<=K;k++){
	    	dp[k][1] = 0;
	    	for(int i=2;i<b-1;i++)
	    		dp[k][1] = (dp[k][1] + dp[k-1][i]);
	    	dp[k][1] %= m;

	    	for(int i=2;i<b-1;i++){
	    		long prev = dp[k][i-1] % m;
	    		long rem = dp[k-1][i];
	    		long t1= (i!=(b-1) ? dp[k-1][i-1] : 0) % m;
	    		long t2 = ((2*i-b>0) ? dp[k-1][2*i-b] : 0) % m;
	    		long t3 = (((2*i-b-1)>0 ? dp[k-1][2*i-b-1] : 0)) % m;
	    		dp[k][i] = (prev - rem + t1 - t2 - t3 + m + m + m + m ) % m;
	    	}
	    }

	    w.println(dp[K][a]);

	    w.close();
	}

	public static int ip(String s){
		return Integer.parseInt(s);
	}
}


//* codeforces
import java.io.*;
import java.util.*;
import static java.lang.Math.*;

public class Sqr {

    final boolean ONLINE_JUDGE = true;

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

    void init() throws IOException {
        if (ONLINE_JUDGE) {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
        } else {
            in = new BufferedReader(new FileReader("input.txt"));
            out = new PrintWriter("output.txt");
        }
    }

    String readString() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

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

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

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

    void debug(Object o) {
        System.err.println(o.toString());
    }

    void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            debug("Time = " + (t2 - t1));
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    int min(int x, int y) {
        if (x>=y)
        return y;
        else
        return x;
    }

    int max(int x, int y) {
        if (x>=y)
        return x;
        else
        return y;
    }

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

    void solve() throws IOException {
     int n = readInt();
     int x1 = readInt();
     int y1 = readInt();
     int x2 = readInt();
     int y2 = readInt();
     int s=0;
     if (abs(x1-x2)==n) s=3*n-(y1+y2);
     else
     if (abs(y1-y2)==n) s=3*n-(x1+x2);
     else
     s = max(x1,x2)-min(x1,x2)+max(y1,y2)-min(y1,y2);
     out.println(min(s,4*n-s);
    }

}


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

import static java.lang.Math.*;

// Solution is at the bottom of code

public class ProblemC_010 implements Runnable{

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

	BufferedReader in;
	OutputWriter out;
	StringTokenizer tok = new StringTokenizer("");

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

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

	void init() throws FileNotFoundException{
		Locale.setDefault(Locale.US);

		if (ONLINE_JUDGE){
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new OutputWriter(System.out);
		}else{
			in = new BufferedReader(new FileReader("input.txt"));
			out = new OutputWriter("output.txt");
		}
	}

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

	long timeBegin, timeEnd;

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

	void debug(Object... objects){
		if (ONLINE_JUDGE){
			for (Object o: objects){
				System.err.println(o.toString());
			}
		}
	}

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

	public void run(){
		try{
			timeBegin = System.currentTimeMillis();
			Locale.setDefault(Locale.US);

			init();
			solve();

			out.close();
			time();
		}catch (Exception e){
			e.printStackTrace(System.err);
			System.exit(-1);
		}
	}

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

	String delim = " ";

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

		return tok.nextToken(delim);
	}

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

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

	final char NOT_A_SYMBOL = '\0';

	char readChar() throws IOException{
		int intValue = in.read();

		if (intValue == -1){
			return NOT_A_SYMBOL;
		}

		return (char) intValue;
	}

	char[] readCharArray() throws IOException{
		return readLine().toCharArray();
	}

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

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

	int[] readIntArray(int size) throws IOException{
		int[] array = new int[size];

		for (int index = 0; index < size; ++index){
			array[index] = readInt();
		}

		return array;
	}

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

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

	long[] readLongArray(int size) throws IOException{
		long[] array = new long[size];

		for (int index = 0; index < size; ++index){
			array[index] = readLong();
		}

		return array;
	}

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

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

	double[] readDoubleArray(int size) throws IOException{
		double[] array = new double[size];

		for (int index = 0; index < size; ++index){
			array[index] = readDouble();
		}

		return array;
	}

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

	Point readPoint() throws IOException{
		return new Point(readInt(), readInt());
	}

	Point[] readPointArray(int size) throws IOException{
		Point[] array = new Point[size];

		for (int index = 0; index < size; ++index){
			array[index] = readPoint();
		}

		return array;
	}

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

	List<Integer>[] readGraph(int vertexNumber, int edgeNumber)
	throws IOException{
		List<Integer>[] graph = new List[vertexNumber];

		for (int index = 0; index < vertexNumber; ++index){
			graph[index] = new ArrayList<Integer>();
		}

		while (edgeNumber-- > 0){
			int from = readInt() - 1;
			int to = readInt() - 1;

			graph[from].add(to);
			graph[to].add(from);
		}

		return graph;
	}

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

	class OutputWriter extends PrintWriter{

		final int DEFAULT_PRECISION = 12;

		int precision;
		String format, formatWithSpace;

		{
			precision = DEFAULT_PRECISION;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		public OutputWriter(OutputStream out) {
			super(out);
		}

		public OutputWriter(String fileName) throws FileNotFoundException {
			super(fileName);
		}

		public int getPrecision() {
			return precision;
		}

		public void setPrecision(int precision) {
			this.precision = precision;

			format = createFormat(precision);
			formatWithSpace = format + " ";
		}

		private String createFormat(int precision){
			return "%." + precision + "f";
		}

		@Override
		public void print(double d){
			printf(format, d);
		}

		public void printWithSpace(double d){
			printf(formatWithSpace, d);
		}

		public void printAll(double...d){
			for (int i = 0; i < d.length - 1; ++i){
				printWithSpace(d[i]);
			}

			print(d[d.length - 1]);
		}

		@Override
		public void println(double d){
			printlnAll(d);
		}

		public void printlnAll(double... d){
			printAll(d);
			println();
		}
	}

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

	int[][] steps = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};

	boolean check(int index, int lim){
		return (0 <= index && index < lim);
	}

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

	void solve() throws IOException{
		int n = readInt();

		long[] count = new long[10];
		for (int i = 1; i <= 9; ++i){
			count[i] = count(i, n);
		}

		int[][] d = new int[10][10];
		for (int i = 1; i <= 9; ++i){
			for (int j = 1; j <= 9; ++j){
				d[i][j] = (i * j) % 9;
				if (d[i][j] == 0) d[i][j] = 9;
			}
		}

		long ans = 0;
		for (int a = 1, s = 1; a <= n; ++a, s = (s == 9? 1: s + 1)){
			int k = n / a;

			for (int b = 1; b <= 9; ++b){
				int c = d[s][b];

				long res = count[b] * count[c] - count(b, k);

				long resStress = stress(a, b, c, n);

				if (res != resStress){
					System.err.println(a + " " + b + " " + res + " " + resStress);
				}

				ans += res;
			}
		}

		out.println(ans);
	}

	int d(int x){
		int res = x % 9;

		return (res == 0? 9: res);
	}

	long count(int d, int n){
		long res = n / 9;

		int md = n % 9;
		if (md > 0 && md >= d) ++res;

		return res;
	}

	long stress(int a, int b, int c, int n){
		long res = 0;

		for (int i = b; i <= n; i += 9){
			for (int j = c; j <= n; j += 9){
				if (a * i != j){
					++res;
				}
			}
		}

		return res;
	}
}


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.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Map.Entry;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Techno19_2F {

	static int MODE = -1;

	static final Comparator<int[]> COMP_ARR = new Comparator<int[]>() {
		public int compare(int[] a1, int[] a2) {
			if (MODE != -1 && (a1.length == 32 || a2.length == 32)) {
				if (a1.length == 32) {
					if (MODE < a2.length) {
						return -1;
					}
					if (MODE > a2.length) {
						return 1;
					}
				} else {
					if (a1.length < MODE) {
						return -1;
					}
					if (a1.length > MODE) {
						return 1;
					}
				}

				for (int i = 0; i < MODE; i++) {
					if (a1[i] < a2[i]) {
						return -1;
					}
					if (a1[i] > a2[i]) {
						return 1;
					}
				}
				return 0;
			} else {
				if (a1.length < a2.length) {
					return -1;
				}
				if (a1.length > a2.length) {
					return 1;
				}

				for (int i = 0; i < a2.length; i++) {
					if (a1[i] < a2[i]) {
						return -1;
					}
					if (a1[i] > a2[i]) {
						return 1;
					}
				}
				return 0;
			}
		}
	};

	static TreeMap<int[], Integer> index = new TreeMap<>(COMP_ARR);
	static int[][] states;

	static ArrayList<int[]> start = new ArrayList<>();

	static int[] numD;

	static int[] pFact = new int[1_000_001];

	static TreeMap<int[], Integer> divCostInd = new TreeMap<>(COMP_ARR);

	public static void main(String[] args) throws IOException {
		cGen = new int[23];
		numD = new int[6000];
		states = new int[6000][];
		genAll(0, 23, 23, 1);

		divCost = new int[400][301];
		for (int[] a : divCost) {
			Arrays.fill(a, Integer.MAX_VALUE / 2);
		}
		cost = new int[index.size()];

		Arrays.fill(pFact, 1);
		for (int i = 2; i <= 1_000_000; i++) {
			if (pFact[i] == 1) {
				for (int m = i; m <= 1_000_000; m += i) {
					pFact[m] = i;
				}
			}
		}

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));

		int nT = Integer.parseInt(reader.readLine());

		while (nT-- > 0) {
			StringTokenizer inputData = new StringTokenizer(reader.readLine());
			int a = Integer.parseInt(inputData.nextToken());
			int b = Integer.parseInt(inputData.nextToken());

			int[] aA = toArray(a);
			int[] bA = toArray(b);

			Integer aRes = divCostInd.get(aA);
			if (aRes == null) {
				aRes = divCostInd.size();
				bfs(aA, divCostInd.size());
				divCostInd.put(aA, divCostInd.size());
			}
			Integer bRes = divCostInd.get(bA);
			if (bRes == null) {
				bRes = divCostInd.size();
				bfs(bA, divCostInd.size());
				divCostInd.put(bA, divCostInd.size());
			}

			int minA = Integer.MAX_VALUE / 4;
			for (int nD = 1; nD <= 300; nD++) {
				minA = Math.min(minA, divCost[aRes][nD] + divCost[bRes][nD]);
			}
			printer.println(minA);
		}
		printer.close();
	}

	static int[] toArray(int a) {
		ArrayList<Integer> cnts = new ArrayList<Integer>();
		int last = -1;
		int cCnt = 0;

		while (a > 1) {
			int cPFact = pFact[a];
			if (cPFact == last) {
				cCnt++;
			} else {
				if (cCnt != 0) {
					cnts.add(cCnt);
				}
				last = cPFact;
				cCnt = 1;
			}
			a /= pFact[a];
		}
		if (cCnt != 0) {
			cnts.add(cCnt);
		}
		Collections.sort(cnts, Comparator.reverseOrder());
		int[] res = new int[cnts.size()];
		for (int i = 0; i < cnts.size(); i++) {
			res[i] = cnts.get(i);
		}
		return res;
	}

	static int[] cost;

	static int[][] divCost;

	static void bfs(int[] sState, int searchI) {
		int sInd = index.get(sState);
		ArrayDeque<Integer> stInds = new ArrayDeque<>();

		stInds.add(index.get(sState));

		Arrays.fill(cost, -1);
		cost[sInd] = 0;

		int[] cState = new int[32];

		while (!stInds.isEmpty()) {
			int cStInd = stInds.remove();
			int cLen = states[cStInd].length;
			for (int i = 0; i < cLen; i++) {
				cState[i] = states[cStInd][i];
			}
			MODE = cLen;

			for (int i = 0; i < cLen; i++) {
				if (i == 0 || cState[i - 1] > cState[i]) {
					cState[i]++;
					Integer nStInd = index.get(cState);
					cState[i]--;

					if (nStInd == null) {
						continue;
					}
					if (cost[nStInd] == -1) {
						cost[nStInd] = cost[cStInd] + 1;
						stInds.add(nStInd);
					}
				}

				if (i == cLen - 1) {
					if (cState[i] == 1) {
						MODE--;
						Integer nStInd = index.get(cState);
						MODE++;
						if (nStInd == null) {
							continue;
						}
						if (cost[nStInd] == -1) {
							cost[nStInd] = cost[cStInd] + 1;
							stInds.add(nStInd);
						}
					} else {
						cState[i]--;
						Integer nStInd = index.get(cState);
						cState[i]++;
						if (nStInd == null) {
							continue;
						}
						if (cost[nStInd] == -1) {
							cost[nStInd] = cost[cStInd] + 1;
							stInds.add(nStInd);
						}
					}
				} else if (cState[i] > cState[i + 1]) {
					cState[i]--;
					Integer nStInd = index.get(cState);
					cState[i]++;
					if (nStInd == null) {
						continue;
					}
					if (cost[nStInd] == -1) {
						cost[nStInd] = cost[cStInd] + 1;
						stInds.add(nStInd);
					}
				}
			}
			cState[cLen] = 1;

			MODE++;
			Integer nStInd = index.get(cState);
			MODE--;
			if (nStInd == null) {
				continue;
			}
			if (cost[nStInd] == -1) {
				cost[nStInd] = cost[cStInd] + 1;
				stInds.add(nStInd);
			}
		}

		for (Entry<int[], Integer> cE : index.entrySet()) {
			int cNumD = numD[cE.getValue()];
			if (cNumD <= 300) {
				divCost[searchI][cNumD] = Math.min(divCost[searchI][cNumD], cost[cE.getValue()]);
			}
		}
	}

	static int[] cGen;

	static void genAll(int i, int max, int rem, int cProd) {
		numD[index.size()] = cProd;

		int[] cKey = Arrays.copyOf(cGen, i);
		states[index.size()] = cKey;
		index.put(cKey, index.size());

		if (rem > 0) {
			for (int nV = Math.min(max, rem); nV >= 1; nV--) {
				cGen[i] = nV;
				genAll(i + 1, nV, rem - nV, cProd * (nV + 1));
			}
		}
	}
}


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

    public class main {
        static BufferedReader in;
        static PrintWriter out;
        static StringTokenizer tok;

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

        static String nextLine() throws IOException{
        tok = new StringTokenizer("");
        return in.readLine();
        }

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

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        in = new BufferedReader(new InputStreamReader(System.in));
        int n = nextInt();
        int i;
        int ar[] = new int[100];
        int sum  = n;
        int nulcount = 0;

        for (i=0; i<n; i++){
            ar[i] = nextInt();
        }
        if (n==1){
            if (ar[0]==0) System.out.println(0);
            if (ar[0]==1) System.out.println(1);
        }
        else
        {
            i=1;
            if(ar[0]==0 & ar[1]==1) nulcount++;
            if(ar[n-1]==0 & ar[n-2]==1) nulcount++;
            while(i<n){
            if(ar[i]==0 & ar[i-1]==0){
                nulcount++;
                while (ar[i]==0 & i<n){
                    nulcount++;
                    i++;
                }
            }else {
                i++;
            }
            }
            System.out.println(sum - nulcount);
        }

    }

}


import java.io.OutputStreamWriter;
import java.io.BufferedWriter;
import java.util.Comparator;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.io.IOException;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigInteger;
import java.io.InputStream;

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

class TaskD {
	private static final long MOD = 1000000007;
	long[][][] answer;
	private int upTo;

	public void solve(int testNumber, InputReader in, OutputWriter out) {
		upTo = in.readInt();
		answer = new long[2][30][31];
		ArrayUtils.fill(answer, -1);
		long result = go(1, 29, 0);
		out.printLine(result);
    }

	private long go(int full, int bit, int groups) {
		if (groups < 0)
			return 0;
		if (bit == -1)
			return 1;
		long result;
		if (full == 0 || (upTo >> bit & 1) == 1) {
			if (groups != 0)
				result = go(0, bit - 1, groups) * (1 << (groups - 1)) + go(full, bit - 1, groups) * (1 << (groups - 1)) + go(full, bit - 1, groups + 1);
			else
				result = go(full, bit - 1, 1) + go(0, bit - 1, groups);
		} else if ((upTo >> bit & 1) == 0 && groups != 0)
			result = go(full, bit - 1, groups) * (1 << (groups - 1));
		else
			result = go(full, bit - 1, groups);
		return result % MOD;
	}
}

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

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

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

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

class OutputWriter {
	private final PrintWriter writer;

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

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

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

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

	}

class ArrayUtils {

	public static void fill(long[][] array, long value) {
		for (long[] row : array)
			Arrays.fill(row, value);
	}

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

	}


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

public class Main {
	public static void main(String[] args) throws Exception {
		PrintWriter pr = new PrintWriter(System.out,true);
		//BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Scanner s = new Scanner(System.in);
		double vasya[]	= {s.nextInt(),s.nextInt()};
		double petya1[]	= {s.nextInt(),s.nextInt()};
		double petya2[] = new double[2];
		double stena[]		= {s.nextInt(),s.nextInt(),s.nextInt(),s.nextInt()};
		double zerkalo[]	= {s.nextInt(),s.nextInt(),s.nextInt(),s.nextInt()};

		Line l1 = new Line(zerkalo[0]-zerkalo[2],zerkalo[1]-zerkalo[3],zerkalo[0],zerkalo[1]);
		Line l2 = new Line(zerkalo[1]-zerkalo[3],-(zerkalo[0]-zerkalo[2]),petya1[0],petya1[1]);
		double x = (l2.c*l1.b-l1.c*l2.b)/(l1.a*l2.b-l2.a*l1.b);
		double y = (l2.c*l1.a-l1.c*l2.a)/(l1.b*l2.a-l2.b*l1.a);
		Vector v = new Vector(x-petya1[0],y-petya1[1]);
		petya2[0] = v.a+x;
		petya2[1] = v.b+y;
		/*pr.println(l1.a+" "+l1.b+" "+l1.c);
		pr.println(l2.a+" "+l2.b+" "+l2.c);
		pr.println(x+" "+y);
		pr.println(petya2[0]+" "+petya2[1]);*/

		if(!isIntersect(vasya[0],vasya[1],petya1[0],petya1[1],stena[0],stena[1],stena[2],stena[3]) && !isIntersect(vasya[0],vasya[1],petya1[0],petya1[1],zerkalo[0],zerkalo[1],zerkalo[2],zerkalo[3])) {
			pr.println("YES");
			return;
		}
		if(!isIntersectZerk(vasya[0],vasya[1],petya1[0],petya1[1],zerkalo[0],zerkalo[1],zerkalo[2],zerkalo[3])) {
			if(!isIntersect(vasya[0],vasya[1],petya2[0],petya2[1],stena[0],stena[1],stena[2],stena[3]) && isIntersect(vasya[0],vasya[1],petya2[0],petya2[1],zerkalo[0],zerkalo[1],zerkalo[2],zerkalo[3]) && !isIntersect(petya1[0],petya1[1],petya2[0],petya2[1],stena[0],stena[1],stena[2],stena[3])) {
				pr.println("YES");
				return;
			}
		}
		pr.println("NO");
	}

	public static boolean isIntersect(double x11,double y11,double x12,double y12,double x21,double y21,double x22,double y22) {
		Line l1 = new Line(x11-x12,y11-y12,x11,y11);
		Line l2 = new Line(x21-x22,y21-y22,x21,y21);
		if(l1.a*l2.b != l1.b*l2.a) {
			double x = (l2.c*l1.b-l1.c*l2.b)/(l1.a*l2.b-l2.a*l1.b);
			double y = (l2.c*l1.a-l1.c*l2.a)/(l1.b*l2.a-l2.b*l1.a);
			Vector v11 = new Vector(x11-x,y11-y);
			Vector v12 = new Vector(x12-x,y12-y);
			Vector v21 = new Vector(x21-x,y21-y);
			Vector v22 = new Vector(x22-x,y22-y);
			if(v11.a*v12.a+v11.b*v12.b <= 0 && v21.a*v22.a+v21.b*v22.b <= 0) {
				return true;
			}
			return false;
		}
		if(l1.a*l2.b == l1.b*l2.a && l1.a*l2.c == l1.c*l2.a) {
			Vector v11 = new Vector(x11-x21,y11-y21);
			Vector v12 = new Vector(x12-x21,y12-y21);
			Vector v21 = new Vector(x11-x22,y11-y22);
			Vector v22 = new Vector(x12-x22,y12-y22);
			if(v11.a*v12.a+v11.b*v12.b <= 0 && v21.a*v22.a+v21.b*v22.b <= 0) {
				return true;
			}
			return false;
		}
		return false;
	}

	public static boolean isIntersectZerk(double x11,double y11,double x12,double y12,double x21,double y21,double x22,double y22) {
		Line l1 = new Line(x11-x12,y11-y12,x11,y11);
		Line l2 = new Line(x21-x22,y21-y22,x21,y21);
		if(l1.a/l2.a != l1.b/l2.b) {
			double x = (l2.c*l1.b-l1.c*l2.b)/(l1.a*l2.b-l2.a*l1.b);
			double y = (l2.c*l1.a-l1.c*l2.a)/(l1.b*l2.a-l2.b*l1.a);
			Vector v11 = new Vector(x11-x,y11-y);
			Vector v12 = new Vector(x12-x,y12-y);
			if(v11.a*v12.a+v11.b*v12.b <= 0) {
				return true;
			}
			return false;
		}
		return false;
	}
}
class Vector {
	double a,b;
	Vector(double a,double b) {
		this.a = a;
		this.b = b;
	}
}
class Line {
	double a,b,c;
	Line(double va,double vb,double x,double y) {
		a = vb;
		b = -va;
		c = -a*x - b*y;
	}
}


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

public class Main {

	public static void main(String[] args) throws Exception {
		PrintWriter pr = new PrintWriter(System.out,true);
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		//Scanner s = new Scanner(System.in);
		int n = Integer.parseInt(in.readLine());
		long sum = 0;
		Pair mas[] = new Pair[n];
		for(int i = 0;i < n;i++) {
			mas[i] = new Pair(Integer.parseInt(in.readLine()),i+1);
			sum += mas[i].value;
		}

		Arrays.sort(mas,new Comp());

		if(n  == 1) {
			pr.println("Exemplary pages.");
			return;
		}

		if(mas[0].value == mas[mas.length-1].value) {
			pr.println("Exemplary pages.");
			return;
		}

		if(sum % n != 0 || (mas[mas.length-2].value != sum / n && n > 2) || (mas[1].value != sum / n && n > 2)) {
			pr.println("Unrecoverable configuration.");
			return;
		}

		pr.println(((mas[0].value - mas[mas.length-1].value)/2)+" ml. from cup #"+mas[mas.length-1].index+" to cup #"+mas[0].index+".");

	}
}
class Pair {
	int value;
	int index;
	Pair(int value,int index) {
		this.value = value;
		this.index = index;
	}
}

class Comp implements Comparator<Pair> {

	@Override
	public int compare(Pair a, Pair b) {
		return b.value - a.value;
	}

}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author da_201612051
 */
public class Main {

  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    FastIO in = new FastIO(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskA1 solver = new TaskA1();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskA1 {

    public void solve(int testNumber, FastIO in, PrintWriter out) throws IOException {
      int n = in.nextInt();
      int k = in.nextInt();
      int[] query = in.nextIntArray(n);
      int cost = 0;
      Set<Integer> avaialbleBooks = new HashSet<>(k);
      int[] access = new int[81];
      Arrays.stream(query).forEach(book -> access[book]++);
      for (int i = 0; i < n; i++) {
        if (!avaialbleBooks.contains(query[i])) {
          cost++;
        }
        if (avaialbleBooks.size() < k && --access[query[i]] > 0) {
          avaialbleBooks.add(query[i]);
        } else if (access[query[i]] == 0) {
          avaialbleBooks.remove(query[i]);
        }
      }
      System.out.println(cost);
    }

  }

  static class FastIO {

    final private int BUFFER_SIZE = 1 << 16;
    private InputStream din;
    private byte[] buffer;
    private int bufferPointer;
    private int bytesRead;

    public FastIO() {
      buffer = new byte[BUFFER_SIZE];
      bufferPointer = bytesRead = 0;
    }

    public FastIO(InputStream inputStream) {
      this();
      din = new DataInputStream(inputStream);
    }

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

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

      if (neg) {
        return -ret;
      }
      return ret;
    }

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

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

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

  }
}


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

public class B {
  static Scanner sc = new Scanner(System.in);

  public static void main(String[] args) {
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] A = new int[N];
    ArrayList<ArrayList<Integer>> next = new ArrayList<>();
    for (int i = 0; i < N; i++) {
      A[i] = Integer.parseInt(sc.next());
      next.add(new ArrayList<>());
      next.get(i).add(1 << 29);
    }
    for (int i = N - 1; i >= 0; i--) {
      next.get(A[i]).add(i);
    }
    PriorityQueue<Integer> q = new PriorityQueue<>((Integer i1, Integer i2) -> {
      ArrayList<Integer> l1 = next.get(i1);
      ArrayList<Integer> l2 = next.get(i2);
      return -Integer.compare(l1.get(l1.size() - 1), l2.get(l2.size() - 1));
    });

    int ans = 0;
    for (int i = 0; i < N; i++) {
      if (q.contains(A[i])) {
        q.remove(A[i]);
        next.get(A[i]).remove(next.get(A[i]).size() - 1);
        q.add(A[i]);
      } else {
        ++ans;
        next.get(A[i]).remove(next.get(A[i]).size() - 1);
        if (q.size() == K) {
          q.poll();
        }
        q.add(A[i]);
      }
    }
    System.out.println(ans);
  }

  static int solve() {
    return 0;
  }

}


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

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		 //int t = fs.nextInt();

		for (int tt = 1; tt <= 1; tt++) {
			//int n=fs.nextInt();
			String s=fs.next();
			int n=s.length();
			HashMap<Character, Integer> map=new HashMap<>();
			for(int i=0;i<n;i++){
				map.put(s.charAt(i),map.getOrDefault(s.charAt(i), 0)+1);
			}

			//out.println(map);
			if(map.containsKey('7')&&map.get('7')>map.get('4')){
				out.println(7);
			}
			else if(map.containsKey('4')){
				out.println(4);
			}
			else{
				out.println(-1);
			}
		}

		out.close();
	}
	public static boolean fermit_check(int n){
        if(n<4){
            return n==2||n==3?true:false;
        }
        for (int i = 0; i < 5; i++) {
            long random =   (long) (Math.random() * (n));

            long a = 2L + random % ((long)n - 3L);
            if ((long)Math.pow(a, n - 1)% n != 1)
                return false;

        }
        return true;
    }

	public static boolean solve(int n, int arr[][]){
		return true;
	}
	public static void prime_seive(int n, int[] b) {

        Arrays.fill(b,1);
		for(int i=2;i<n;i++){
			if(b[i]==1){
				for(long j=i*(long)i;j<n;j=j+i)
					b[(int)j] = 0;
				//p.add((long)i);

			}
		}
		b[0]=b[1]=0;

    }
	public static int binarySearch(int arr[], int num) {
		if (num < arr[0]) {
			return 0;
		}
		int low = 0;
		int high = arr.length - 1;
		int index = -1;
		while (low <= high) {
			int mid = low + (high - low) / 2;

			if (arr[mid] <= num) {
				if (arr[mid] == num) {
					// System.out.println(arr[mid]+" "+mid+" "+index);
					index = Math.max(index, mid + 1);
				}
				low = mid + 1;
			}

			else {
				high = mid - 1;
			}
		}
		if (index == -1) {
			index = low;
		}
		return index;
	}

	public static int noOfonesBinary(int a) {
		int count = 0;

		int orig = a;

		while (a > 0) {
			a = a >> 1 << 1;
			if (orig - a == 1)
				count++;
			orig = a >> 1;
			a = orig;
		}
		return count;

	}

	public void swap(int[] arr, int i, int j) {
		int temp = arr[i];
		arr[i] = arr[j];
		arr[j] = temp;
	}

	public static long nCr(int n, int r) {
		long result = 1L;
		for (int i = 0; i < r; i++) {
			result *= (long) (n - i); // n * n-1 * n-2 * .... * n-(r-1)
			result /= (long) (i + 1); // r * r-1 * ... * 1
		}
		return result;
	}

	int pow(int x, int y) {
		// Initialize diff
		int res = 1;

		while (y > 0) {
			// If y is odd,
			// multiply
			// x with diff
			if ((y & 1) == 1)
				res = res * x;

			// n must be even now
			y = y >> 1; // y = y/2
			x = x * x; // Change x to x^2
		}
		return res;
	}

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

		return gcd(b % a, a);
	}

	static int gcdCoeff(int a, int b, int arr[])// euclidean gcd + extended euclidean
	{
		if (b == 0)
			return a;
		int tmp[] = { 1, 1 };// must be 1,1, because at base step b=0, a=anything, 1.0+ 1.a=a
		int diff = gcdCoeff(b, a % b, tmp);
		arr[0] = tmp[1];// x=y1
		arr[1] = (tmp[0] - (a / b) * tmp[1]);// y=(x1-(a/b)*y1)
		return diff;
	}

	static class Pair {
		int a;
		int b;

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

		}

	}

	static class FastScanner {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");

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

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

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

		Long[] readLongArray(int n) {
			Long[] a = new Long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

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


import java.util.Scanner;
public class DigitalSequence{

    public static void print(String s){
        System.out.println(s);
    }
    public static void main(String[] args) {
        long k = new Scanner(System.in).nextLong();
        long i = 1,t=0, c = 9,digits = 0,l=0,k2=k;
        while(t<k){
            l = t;
            t += i*c;
            i++;
            c*=10;
            digits++;
        }
        k = k-l;
        long lastNumber = (long)Math.pow(10,digits-1)-1;
        long p = k/digits,q=k%digits;
        long finalNumber =lastNumber+p;
        if(q!=0){
            finalNumber++;
        }
        while(k-digits>0)
            k = k-digits;
        String ans = ""+finalNumber;
        int index = (int)(k-1);
        print(""+ans.charAt((int)index));
    }
}


import java.util.*;

public class Solver {
    public static int count(int a[]){
        int c=0;
        for(int i=0;i<14;i++){
            if(a[i]%2==0){
                c+=a[i];
            }
        }
        return c;
    }

    public static int[] distribute(int a[],int x){
        int p=a[x];
        int q=a[x]/14;
        int t=a[x]%14;
        int aa[]=new int[14];
        for(int i=0;i<14;i++){
            aa[i]=a[i];
        }
        if(x+t> 14) {
            for (int i = x + 1; i < 14; i++) {
                aa[i] += 1;
            }
            int c = t - (14 - x);
            for (int i = 0; i <=c; i++) {
                aa[i] += 1;
            }
        }else{
            for (int i = x + 1; i <=x+t; i++) {
                aa[i] += 1;
            }
        }
        for(int i=0;i<14;i++){
            aa[i]+=q;
        }
        return aa;
    }

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);
        int n=14;
        int a[]=new int[n];
        for(int i=0;i<n;i++){
            a[i]=sc.nextInt();
        }
        int c[]=new int[n];
        for(int i=0;i<n;i++){

            c[i]=count(distribute(a,i));

        }
        //System.out.println(3%14);
        int max=Integer.MIN_VALUE;
        for(int i=0;i<n;i++){
          //  System.out.print(c[i]+" ");
            if(c[i]>=max){
                max=c[i];
            }
        }
        System.out.print(max);

    }

}


//package Round_140;

import java.util.*;

public class c {

	void run(){
		Scanner in = new Scanner(System.in);
		int n= in.nextInt();
		int m = in.nextInt();
		long sum = 0;
		long f[] = new long[n+1];
		f[1] = 2;
		if (n == 1){
			System.out.println(2 % m);
			return;
		}
		f[2] = 3*f[1] + 2;
		if (n >= 2) sum += f[2];
		//sum = 2;
		for (int i = 3; i<=n; i++){
			f[i] = (2*sum + 2) % m;
			//f[i] %= m;
			sum += f[i];
			sum %= m;
		}

		//sum = (f[n-1] + sum);

		System.out.println(sum);
	}

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

}


import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class C922 {
    public static void main(String args[]){
        Scanner in=new Scanner(System.in);
        long n=in.nextLong();
        long k=in.nextLong();
        int a[]=new int[999999999];
        for(long i=1;i<=k;i++){
            int c=(int)(n%i);
            a[c]=a[c]+1;

        }
        Set<Integer>set=new HashSet<>();
        for(int i=0;i<a.length;i++){
            set.add(a[i]);
        }
        if (Collections.max(set)==1){
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }
    }
}