import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.time.Year;
import java.util.Scanner;

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

    static class TaskB {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            long y = in.nextLong();
            double count = 0;
            boolean isYearLeap = Year.isLeap(y);
            long next = y + 1;
            while (true) {
                boolean isCurrLeap = Year.isLeap(next);
                if (isCurrLeap) {
                    count += 2;
                } else {
                    count += 1;
                }
                next++;
                if (count % 7 == 0 && isCurrLeap == isYearLeap) {
                    break;
                }
            }
            out.print(next - 1);
        }

    }
}


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.PriorityQueue;

public class A {
	public static void main(String args[])throws Exception {
		BufferedReader input = new BufferedReader(
				new InputStreamReader(System.in));

		String[] tokens = input.readLine().split(" ");
		int n = Integer.parseInt(tokens[0]);

		tokens = input.readLine().split(" ");
		int orig = Integer.parseInt(tokens[0]);
		PriorityQueue<Integer> q = new PriorityQueue<Integer>(1,new A.reverseCompare());

		int bribes = 0;
		for(int i=1;i<n;i++)
			q.add(Integer.parseInt(tokens[i]));

		while(true) {
			int x = q.poll();

			if(x>=orig) {
				q.add(x-1);
				orig++;
			}
			else
				break;

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

	public static class reverseCompare implements Comparator<Integer>{

		@Override
		public int compare(Integer arg0, Integer arg1) {
			if(arg0 > arg1)
				return -1;
			if(arg0 < arg1)
				return 1;
			return 0;
		}
	}
}


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

public class Main {

    static final double eps = 1e-8;
    static int mod = 1000 * 1000 * 1000 + 9;
    static int n, m;

    public static void main(String[] args) throws IOException {
        try {
            String s = sc.next();
            String ans = "";
            if(s.charAt(0) == 'f')
            {
                ans += "ftp://";
                s = s.substring(3);
            }
            else
            {
                ans += "http://";
                s = s.substring(4);
            }
            int pos;
            if(s.charAt(0) == 'r')
            {
                pos = s.substring(1).indexOf("ru") + 1;

            }
            else
                pos = s.indexOf("ru");
            ans += s.substring(0, pos);
            ans += ".ru";
            if(pos + 2 < s.length())
                ans += "/" + s.substring(pos + 2);
            pw.println(ans);
        }
        finally {
            pw.close();
        }
    }

    static Scanner sc = new Scanner(System.in);
    static PrintWriter pw = new PrintWriter(System.out);
    static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
    static BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st ;
    static int nextInt() throws IOException {
        in.nextToken();
        return (int) in.nval;
    }
    static long nextLong() throws IOException {
        in.nextToken();
        return (long) in.nval;
    }
    static double nextDouble() throws IOException {
        in.nextToken();
        return in.nval;
    }
    static String next() throws IOException {
        in.nextToken();
        return in.sval;
    }
    static void outArray(int[] O) {
        for(int i = 0; i < O.length - 1; i++)
            pw.print(O[i] + " ");
        pw.println(O[O.length - 1]);
    }
    static void exit(Object arg)
    {
        pw.println(arg);
        pw.flush();
        System.exit(0);
    }
}


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

public class BearAndFiveCards {
	public static BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
	public static StringTokenizer st;

	public static void main(String[] args) throws IOException {
		int[] a = intArray(5);
		int sum = 0;
		for (int x : a)
			sum += x;
		int min = sum;
		for (int i = 0; i < 5; i++) {
			int count = 0;
			for (int j = 0; j < 5; j++)
				if (a[j] == a[i])
					count++;
			if (count > 3)
				count = 3;
			if (count != 1)
				min = Math.min(min, sum - count*a[i]);
		}

		System.out.println(min);
	}

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

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

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

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

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


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

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

class Pair {
	int first;
	int second;

	Pair(int first, int second) {
		this.first = first;
		this.second = second;
	}
}

class TaskB {

	public void solve(int testNumber, InputReader in, PrintWriter pw) {
		int x1 = in.nextInt();
		int y1 = in.nextInt();
		long sum = 0;
		for (int i = x1; i <= y1; i++) {
			long sum1 = 0;
			int temp = i;
			while (temp > 0) {
				int rem = temp % 10;
				temp /= 10;
				sum1 += getInt(rem);
			}
			sum += sum1;
		}
		pw.println(sum);
	}

	public int getInt(int num) {
		int ret = -1;
		switch (num) {
		case 0:
			ret = 6;
			break;
		case 1:
			ret = 2;
			break;
		case 2:
			ret = 5;
			break;
		case 3:
			ret = 5;
			break;
		case 4:
			ret = 4;
			break;
		case 5:
			ret = 5;
			break;
		case 6:
			ret = 6;
			break;
		case 7:
			ret = 3;
			break;
		case 8:
			ret = 7;
			break;
		case 9:
			ret = 6;
			break;
		}
		return ret;
	}

	public int isPow(long num) {
		int count = 0;
		while (num > 0) {
			num /= 2;
			count++;
		}
		return count;
	}
}

class InputReader {
	BufferedReader br;
	StringTokenizer st;

	public InputReader(InputStream in) {
		br = new BufferedReader(new InputStreamReader(in));
		st = null;
	}

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

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

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

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


import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class A106 {
	public static void main (String args[]){
		Scanner in = new Scanner(System.in);
		char hokm = in.next().charAt(0);
		char[] a = in.next().toCharArray();
		char[] b = in.next().toCharArray();
		Map<Character, Integer> m = new TreeMap<Character, Integer>();
		m.put('6', 6);m.put('7', 7);m.put('8', 8);m.put('9', 9);m.put('T',10);
		m.put('J', 11);m.put('Q', 12);m.put('K', 13);m.put('A', 14);
		if(a[1]==b[1]){
			if(m.get(a[0])>m.get(b[0]))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
		else {
			if(a[1]==hokm)
				System.out.println("YES");
			else if(b[1]==hokm)
				System.out.println("NO");
			else
				System.out.println("NO");
		}
	}
}


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

public class P2 {
	static int find (long x) {
		if (x < 2)
			return 0;
		int bc = 0, zc = 0, zp = -1;
		long b = x;
		while (b > 0) {
			bc++;
			if ((b & 1) == 0) {
				zc++;
				zp = bc;
			}
			b >>= 1;
		}
		long p = 0;
		if (zc == 0)
			p = x - 1;
		else if (zc == 1)
			p = x;
		else {
			for (int i = 1; i < bc - zp; i++) {
				p = p << 1;
				p = p | 1;
			}
			p = p << 1;
			for (int i = 0; i < zp; i++) {
				p = p << 1;
				p = p | 1;
			}
			if ((p & (p + 1)) == 0)
				p--;
		}
		bc = 0;
		zp = -1;
		b = p;
		while (b > 0) {
			bc++;
			if ((b & 1) == 0)
				zp = bc;
			b >>= 1;
		}
		int ans = 0;
		for (int i = 2; i < bc; i++)
			ans += (i - 1);
		ans += (bc - zp);
		return ans;
	}
	public static void main (String[] args) {
		Scanner sc = new Scanner (System.in);
		PrintStream op = System.out;
		long a = sc.nextLong();
		long b = sc.nextLong();
		if (a > b) {
			long t = a;
			a = b;
			b = t;
		}
		int av = find (a - 1);
		int bv = find (b);
		op.println(bv - av);
		sc.close();
		op.close();
	}
}


import java.util.*;
import java.io.*;
import java.math.*;
public class task
{
	public static void main(String[] Args)
	{
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt(),a[]=new int[7],i,sum=0,ze=6;
		for (i=0;i!=7;++i)
		{
			a[i]=sc.nextInt();
			sum+=a[i];
			if (a[i]!=0)
				ze=i;
		}
		n=n%sum;
		if (n!=0)
			for (i=0;i!=7 && n>0;++i)
				n-=a[i];
		else
			i=ze+1;
		System.out.println(i);
	}
}


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

public class A1 {

    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        sc = new StringTokenizer(br.readLine());
        char[] s = nxtCharArr();
        boolean[] a = new boolean[10];
        int q = 0;
        for (int i = 0; i < s.length; i++) {
            if (s[i] == '?')
                q++;
            else if (s[i] >= 'A' && s[i] <= 'J')
                a[s[i] - 'A'] = true;
        }
        long ans = 1;
        if (s[0] == '?') {
            ans *= 9;
            q--;
        }
        while (q-- > 0)
            ans *= 10;
        int c = 0;
        for (int i = 0; i < a.length; i++)
            c += a[i] ? 1 : 0;
        int st = 10;
        if (s[0] >= 'A' && s[0] <= 'J') {
            ans *= 9;
            c--;
            st--;
        }
        while (c-- > 0)
            ans *= st--;
        out.println(ans);
        br.close();
        out.close();
    }

    static BufferedReader br = new BufferedReader(new InputStreamReader(
            System.in));

    static StringTokenizer sc;

    static String nxtTok() throws IOException {
        while (!sc.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null)
                return null;
            sc = new StringTokenizer(s.trim());
        }
        return sc.nextToken();
    }

    static int nxtInt() throws IOException {
        return Integer.parseInt(nxtTok());
    }

    static long nxtLng() throws IOException {
        return Long.parseLong(nxtTok());
    }

    static double nxtDbl() throws IOException {
        return Double.parseDouble(nxtTok());
    }

    static int[] nxtIntArr(int n) throws IOException {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nxtInt();
        return a;
    }

    static long[] nxtLngArr(int n) throws IOException {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nxtLng();
        return a;
    }

    static char[] nxtCharArr() throws IOException {
        return nxtTok().toCharArray();
    }
}


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

public class Main implements Runnable
{
	public static void main(String [] args) throws IOException
	{
		new Thread(null, new Main(), "", 1 << 20).start();
	}

	String file = "input";
	BufferedReader input;
	PrintWriter out;

	public void run()
	{
		try
		{
			//input = new BufferedReader(new FileReader(file + ".in"));
			input = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(new BufferedOutputStream(System.out));
			solve();
			out.close();
		}
		catch(Exception e)
		{
			e.printStackTrace();
			System.exit(1);
		}
	}
	long[][][] dp = new long[36][36][36];
	void solve() throws IOException
	{
		StringTokenizer st = tokens();
		int n = nextInt(st), H = nextInt(st);
		this.H = H;
		for(long[][] t1 : dp) for(long[] t2 : t1) fill(t2, -1);
		long res = 0;
		for(int i = 1; i <= n; i++)
			for(int h = H; h <= n; h++)
			{
				res += get(i - 1, n - i, h - 1);
				//print(i - 1, n - i, h - 1, get(i - 1, n - i, h - 1));
			}
		out.println(res);
	}
	int H;
	long get(int left, int right, int h)
	{
		if(h == 0)
		{
			if(left == 0 && right == 0) return 1;
			return 0;
		}
		if(dp[left][right][h] != -1) return dp[left][right][h];

		if(h > max(left, right))
		{
			dp[left][right][h] = 0;
			return 0;
		}
		long res = 0;
		if(left > 0 && right > 0)
		{
			for(int i = 0; i < left; i++)
				for(int j = 0; j < right; j++)
				{
					for(int k = 0; k <= h - 2; k++)
					{
						res += get(i, left - i - 1, k) * get(j, right - j - 1, h - 1);
						res += get(i, left - i - 1, h - 1) * get(j, right - j - 1, k);
					}
					res += get(i, left - i - 1, h - 1) * get(j, right - j - 1, h - 1);
				}

		}
		if(left > 0 && right == 0)
		{
			for(int i = 0; i < left; i++) res += get(i, left - i - 1, h - 1);
		}
		if(right > 0 && left == 0)
		{
			for(int i = 0; i < right; i++) res += get(i, right - i - 1, h - 1);
		}
		//print(left, right, h, res);
		return dp[left][right][h] = res;
	}

	StringTokenizer tokens() throws IOException
	{
		return new StringTokenizer(input.readLine());
	}

	String next(StringTokenizer st)
	{
		return st.nextToken();
	}

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

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

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

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

	void print(Object... o)
	{
		out.println(deepToString(o));
	}
}


import java.lang.*;
import java.util.*;
import java.io.*;
public class test
{

  Scanner sc=new Scanner(System.in);
  PrintWriter pr=new PrintWriter(System.out,true);
  public static void main(String... args)
  {
       test c=new test();
       c.prop();
  }
  public void prop()
  {
    int n,a,x=0,b,c ;
     n=sc.nextInt();
     a=sc.nextInt();
          if(a>15)
            x=15 ;
        for (int i=1;i<n ;++i) {
            b=sc.nextInt();
            c=b-a ;
              if(c>15 && x==0)
                  x=a+15 ;
             a=b ;
          }

        c=90-a ;
          if(c>15 && x==0)
              x=a+15 ;
          else if(x==0)
                 x=90 ;
            pr.println(x);

  }

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Scanner;

public class CodeLab {

	public static void main(String[] args) {
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int m=sc.nextInt();
	int maxIndex=1;
	int max=(int) Math.ceil(sc.nextInt()*1.0/m);

	for(int i=1;i<n;i++) {
		int x=sc.nextInt();
		if(Math.ceil(x*1.0/m)>=max) {
			max=(int) Math.ceil(x*1.0/m);
			maxIndex=i+1;
		}
	}
	System.out.println(maxIndex);

	sc.close();
	}

}


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

public class Main implements Runnable {

	private void solve() throws IOException {
		char[] s = next().toCharArray();
		int n = s.length;
		int ans = 0;
		int k = 0;
		char last = '?';
		for (int i = 0; i < n; ++i) {
			if (last == '?' || s[i] == last) {
				++k;
				last = s[i];
				if (k == 5) {
					last = '?';
					k = 0;
					++ans;
				}
			} else {
				k = 1;
				last = s[i];
				++ans;
			}
		}
		if (k != 0) ++ans;
		out.println(ans);
	}

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

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

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

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) return null;
			eat(line);
		}
		return st.nextToken();
	}

	public static void main(String[] args) {
		new Thread(null, new Main(), "Main", 1 << 28).start();
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	@Override
	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			eat("");
			solve();
			in.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(566);
		}
	}

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

}


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

public class MainB {

	public static void B () throws IOException {
		MyScanner sc = new MyScanner(System.in);
		PrintWriter pw = new PrintWriter(System.out);
		StringTokenizer st;

		st = new StringTokenizer(sc.nextLine(),":");
		int h = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());

		int inc = sc.nextInt();
		int incH = (inc/60)%24;
		int incM = inc%60;

		if (incM + m >= 60){
			m = incM + m - 60;
			//if(incH == 0)
				incH += 1;
			if (h + incH > 23){
				h = incH + h - 24;
			}
			else {
				h = h + incH;
			}
		}

		else {
			m = incM + m;
			if (h + incH > 23){
				h = incH + h - 24;
			}
			else
				h = h + incH;
		}
		//System.out.println(m%100);
		String hour = "";
		String min = "";
		if ( (h / 10)%10 == 0)
			hour = "0" + h % 10;
		else
			hour = "" + h;

		if ( (m / 10)% 10 == 0)
			min = "0" + m;
		else
			min = "" + m;
		pw.println(hour + ":" +min);
		pw.close();
	}

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

		B();

	}

	static class MyScanner {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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

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

	}
}


import java.util.Scanner;

public class a {
	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long value = input.nextLong();
		int ans = 0;
		for(int i = 1; i <= 100 ; i++){
			ans = i;

			value++;
			String a = value + "";
			if((a).toString().contains("8"))
				break;
		}

		System.out.println(ans);

	}
}


import java.util.Scanner;

public class test011 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		if (y == 1 && x != 0 || y == 0) {
			System.out.println("NO");
			return;
		}
		int tmp = x - y + 1;
		if (tmp >= 0 && tmp % 2 == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}
}


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

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

	static class TaskA {
		public void solve(int testNumber, FastScanner in, PrintWriter out) {
			int n = in.nextInt();
			int m = in.nextInt();
			int sz1 = getDigits(n - 1, -1).length;
			int sz2 = getDigits(m - 1, -1).length;
			if (sz1 + sz2 > 7) {
				out.println(0);
				return;
			}
			int ans = 0;
			for (int i = 0; i < n; i++) {
				int[] c = new int[7];
				for (int d : getDigits(i, sz1)) {
					++c[d];
				}
				for (int j = 0; j < m; j++) {
					int[] tmp = getDigits(j, sz2);
					for (int d : tmp) {
						++c[d];
					}
					boolean ok = true;
					for (int k = 0; k < c.length; k++) {
						if (c[k] > 1) {
							ok = false;
							break;
						}
					}
					if (ok) {
						++ans;
					}
					for (int d : tmp) {
						--c[d];
					}
				}
			}
			out.println(ans);
		}

		private int[] getDigits(int x, int sz) {
			if (sz < 0 && x == 0) {
				return new int[]{0};
			}
			List<Integer> res = new ArrayList<>();
			while (x > 0) {
				res.add(x % 7);
				x /= 7;
			}
			while (res.size() < sz) {
				res.add(0);
			}
			int[] r = new int[res.size()];
			for (int i = 0; i < res.size(); i++) {
				r[i] = res.get(i);
			}
			return r;
		}

	}

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

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

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

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

	}
}


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

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

class TaskA {
//    class values{
//        double val;
//        long x1;
//        long x2;
//
//        values(double val, long x1, long x2) {
//            this.val = val;
//            this.x1 = x1;
//            this.x2 = x2;
//        }
//    }
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long t1 = in.nextInt();
        long t2 = in.nextInt();
        long x1 = in.nextInt(),x2 = in.nextInt();
        long t0 = in.nextInt();
        if (t1 == t2){
            out.print(x1+" "+x2);return;
        }
        double res = Double.MAX_VALUE;
        long y2 = 0,y1 = 0;

//        ArrayList<values> arrayList = new ArrayList<>();
        here: for (long i = x1; i > -1; --i) {
            long left = -1;
            long right = x2 + 1;
            while (right - left > 1){
                long mid = right + left;
                mid >>= 1L;
                long mul = t2*mid + t1*i;
                double d = (double)mul;
                d /= (mid + i);
                if (mid + i == 0)d = 0;

                if (Double.valueOf(d).compareTo(Double.valueOf(t0)) >= 0)right = mid;
                else left = mid;
            }
            double pk = t2*right + t1*i;
            pk /= (right + i);
            if (Double.compare(pk,t0) < 0 || right > x2)continue here;
//            while (right + 1 <= x2){
//                double gk = t2*(right + 1) + t1*i;
//                gk /= (right + 1 + i);
//                if (Double.compare(pk,gk) == 0)right++;
//                else{
//                    arrayList.add(new values(pk,i,right));
//                    continue here;
//                }
//            }
            if (i == 0)right = x2;
//            arrayList.add(new values(pk,i,right));
            if (Double.compare(pk,res) <= 0){
                if (Double.compare(pk,res) == 0){
                    if (right + i > y1 + y2){
                        y1 = i;
                        y2 = right;
                    }
                    continue;
                }
                else {
                    res = pk;
                    y1 = i;
                    y2 = right;
                }
            }
        }
        out.print(y1+" "+y2+"\n");
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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

}


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

public class pBinary {
    InputStream is;
    PrintWriter pw;
    String INPUT = "";
    long L_INF = (1L << 60L);

    void solve() {
        int n = ni(), p = ni(), m;
        int x = 1;
        for (int i = 1; i < 32; i++) {
            n = n - p;
            if (n <= 0)
                break;
            if (check(n, i)) {
                pw.println(i);
                return;
            }
        }
        pw.println(-1);
    }

    private boolean check(int n, int x) {
        int c = 0,nn=n;
        while (n > 0) {
            int p = (int) (Math.log(n) /
                    Math.log(2));
            n -= (int) Math.pow(2, p);
            c++;
        }
        return c <= x && x<=nn;
    }

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

        long s = System.currentTimeMillis();
        //        int t = ni();
        //        while (t-- > 0)
        solve();
        pw.flush();
        tr(System.currentTimeMillis() - s + "ms");
    }

    public static void main(String[] args) throws Exception {
        new pBinary().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.util.Scanner;
public class slime
{
    public static void main(String args[])
    {
        Scanner s= new Scanner(System.in);
        int n= s.nextInt();
        int c=2;
        int i=1, k=0, j;
        int a[]= new int[n];
        a[0]= 1;
        while(c<=n)
        {
            a[i]=1;
            j=i;
            while(j>0)
            {
                if(a[j]==a[j-1])
                {
                    a[j-1]++;
                    if(j!=i)
                    i--;
                    j--;
                }
                else
                {
                    if(j==i)
                    i++;
                    break;
                }
            }
            c++;

        }
        for(k=0; k<i; k++)
        {
            System.out.print(a[k]);
            System.out.print(" ");
        }
    }
}


import java.util.Scanner;

public class JavaApplication34 {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        System.out.println(n/2*3);
            }}


import java.util.*;
public class Homgo
{
public static void main(String[] args)
{
String s1=new String();
String s2=new String();
Scanner in=new Scanner(System.in);

HashMap <String,Integer> a = new HashMap <String,Integer> ();
s1=in.next();
int i;
for (i=0;i<10;i++)
{
s2=in.next();
a.put(s2,i);
}

for (i=0;i<s1.length();i=i+10)
System.out.print(a.get(s1.substring(i,i+10)));

}
}


import java.util.Scanner;
import java.io.BufferedInputStream;
import java.util.Set;
import java.util.HashSet;

public class A { //Codeforces Round #44 - X
	public static void main(String[] args) {
		Scanner sc = new Scanner(new BufferedInputStream(System.in));

		int num = sc.nextInt();
		Set<Integer> trigNumbers = new HashSet<Integer>();
		for (int i = 1; i <= 1000 ; i++) {
			int newNum = (i * (i + 1)) / 2;
			trigNumbers.add(newNum);
		}

		if(trigNumbers.contains(num)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}
}


//package SBU_ACM;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

import javax.management.modelmbean.ModelMBean;

public class eleven {
	public static ArrayList<Long> nums = new ArrayList<Long>();
	public static long MOD = 1000000007;
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);

		long x = input.nextLong();
		long y = input.nextLong();

		long n = input.nextLong();

		if(n % 6 == 1)
			System.out.println((x + MOD) % MOD);
		if(n % 6 == 2)
			System.out.println((y + MOD) % MOD);
		if(n % 6 == 3)
			System.out.println((y - x + 3 * MOD) % MOD);
		if(n % 6 == 4)
			System.out.println((-x + MOD) % MOD);
		if(n % 6 == 5)
			System.out.println((-y + MOD) % MOD);
		if(n % 6 == 0)
			System.out.println((-y + x + 3 * MOD) % MOD);

	}
}


import java.util.Scanner;

/**
 ** Created by Alik on 10/23/2015.
 */
public class Problem_546A {
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int price = in.nextInt();
        int money = in.nextInt();
        int amount = in.nextInt();
        int sum = 0, result;

        for (int i = 1; i <= amount; i++){
            sum += price*i;
        }
        result = sum-money;
        if (result <= 0)
            result = 0;
        System.out.print(result);
    }
}


//package javaapplication1;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(new PrintStream(System.out));
        String zero=br.readLine();
        String x=br.readLine();
        List<String>L=new ArrayList<>();
        String res="o";
        for (int i = 0; i < 51; i++) {
            res+="go";
            L.add(res);
        }
        for (int i = L.size()-1; i >-1; --i) {
           x=x.replaceAll(L.get(i), "***");
        }
        System.out.println(x);
    }

}


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

public class Main implements Runnable {

	private void solve() throws IOException {
		long n = nextLong();
		long h = (long) Math.sqrt(n)+1;
		long l = (long) (Math.sqrt(n+6561)-81)-1;
		long ans = -1;
		for( long i = l ; i <= h; ++i){
			if( f(i) == n ){
				ans = i;
				break;
			}
		}
		out.println(ans);
	}

	private long f(long i) {
		return i*i+sum(i)*i;
	}

	private long sum(long i) {
		long ret = 0;
		while( i >0  ){
			ret += i%10;
			i/=10;
		}
		return ret;
	}

	// private long f(long m) {
	//
	// return m * m + sum(m) - n;
	// }
	//
	// private long sum(long m) {
	// long ret = 0;
	// while (m > 0) {
	// ret += m % 10;
	// m /= 10;
	// }
	// return ret;
	// }

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

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

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

	String next() throws IOException {
		while (!st.hasMoreTokens()) {
			String line = in.readLine();
			if (line == null) {
				return null;
			}
			eat(line);
		}
		return st.nextToken();
	}

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

	public static void main(String[] args) {
		new Thread(null, new Main(), "Main", 1 << 26).start();
	}

	private BufferedReader in;
	private PrintWriter out;
	private StringTokenizer st;

	public void run() {
		try {
			Locale.setDefault(Locale.ENGLISH);
			in = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(System.out);
			// in = new BufferedReader(new FileReader(file + ".in"));
			// out = new PrintWriter(file + ".out");
			eat("");
			solve();
			in.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}


import java.util.Scanner;

public class MikePalindrome {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String s;
		Scanner sc = new Scanner(System.in);
		s= sc.next();
		if(s.length()==1) {
			System.out.println("YES");
			return;
		}
		boolean palindrome = true;
		  int cnt = 1;
		  for (int i = 0; i < s.length() / 2; i++) {
		    if (s.charAt(i) != s.charAt(s.length() - 1 - i)) {
		      if (cnt > 0) {
		        cnt--;
		      } else {
		        palindrome = false;
		        break;
		      }
		    }
		  }
		  if (s.length() % 2 == 1 && cnt == 1) {
		    cnt--;
		  }
		  if (palindrome && cnt == 0) {
		    System.out.println("YES");
		  } else {
			  System.out.println("NO");
		  }

	}

}


import java.util.*;

public class AlexRhombus{

	public static void main(String[] args) {

		Scanner input = new Scanner(System.in);

		int n = input.nextInt();
		int sum = 1 ;

		for (int i = 0 ; i<n ; i++){

			sum = sum + 4*i ;
		}
		System.out.println(sum);

	}
}


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

public class MainA {

	public static int mod = 20000;
	public static long[] val;
	public static long[] arr;
	static int max = (int) 1e9 + 7;

	public static void main(String[] args) {

		InputReader in = new InputReader(System.in);
		PrintWriter out = new PrintWriter(System.out);
		long n=in.nextLong();
		long l=in.nextLong();
		long r=in.nextLong();
		long ans=0;
		int log=0;
		long c[]=new long[52];
		c[0]=1;
		for(int i=1;i< 52;i++)
		{
			c[i]=2*c[i-1];
			if(n < c[i])
			{
				log=i-1;
				break;
			}

		}

		long a[]=new long[log+1];
		long f=n,la=0;
		for(int i=log;i>=0;i--)
		{

			a[i]=n%2;
			if(i==0)
			{
				f=n;
				la=n;

			}
			n=n/2;
			//out.println(n);
		}
		//debug(a);
		//out.println(f+" "+la);
		for(long i=l;i<=r;i++)
		{
			if(i%4==0)
			{
				long b=4;
				for(int j=2;j<=log;j++)
				{

					if((i/b)%2==1)
					{
						ans+=a[j];
						break;
					}
					b=b*2;
				}
			}
			else if(i%4==1)
			{
				if(f==1)ans+=1;
			}
			else if(i%4==2)
			{
				if(a[1]==1)ans+=1;
			}
			else if(i%4==3)
			{
				if(la==1)ans+=1;
			}
		}

		out.println(ans);
		out.close();
	}

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

	public static boolean isPal(String s) {
		for (int i = 0, j = s.length() - 1; i <= j; i++, j--) {
			if (s.charAt(i) != s.charAt(j))
				return false;
		}
		return true;
	}

	public static String rev(String s) {
		StringBuilder sb = new StringBuilder(s);
		sb.reverse();
		return sb.toString();
	}

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

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

	public static long gcdExtended(long a, long b, long[] x) {

		if (a == 0) {
			x[0] = 0;
			x[1] = 1;
			return b;
		}
		long[] y = new long[2];
		long gcd = gcdExtended(b % a, a, y);

		x[0] = y[1] - (b / a) * y[0];
		x[1] = y[0];

		return gcd;
	}

	public static int abs(int a, int b) {
		return (int) Math.abs(a - b);
	}

	public static long abs(long a, long b) {
		return (long) Math.abs(a - b);
	}

	public static int max(int a, int b) {
		if (a > b)
			return a;
		else
			return b;
	}

	public static int min(int a, int b) {
		if (a > b)
			return b;
		else
			return a;
	}

	public static long max(long a, long b) {
		if (a > b)
			return a;
		else
			return b;
	}

	public static long min(long a, long b) {
		if (a > b)
			return b;
		else
			return a;
	}

	public static long[][] mul(long a[][], long b[][]) {
		long c[][] = new long[2][2];
		c[0][0] = a[0][0] * b[0][0] + a[0][1] * b[1][0];
		c[0][1] = a[0][0] * b[0][1] + a[0][1] * b[1][1];
		c[1][0] = a[1][0] * b[0][0] + a[1][1] * b[1][0];
		c[1][1] = a[1][0] * b[0][1] + a[1][1] * b[1][1];

		return c;
	}

	public static long[][] pow(long n[][], long p, long m) {
		long result[][] = new long[2][2];
		result[0][0] = 1;
		result[0][1] = 0;
		result[1][0] = 0;
		result[1][1] = 1;

		if (p == 0)
			return result;
		if (p == 1)
			return n;
		while (p != 0) {
			if (p % 2 == 1)
				result = mul(result, n);
			//System.out.println(result[0][0]);
			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < 2; j++) {
					if (result[i][j] >= m)
						result[i][j] %= m;
				}
			}

			p >>= 1;
			n = mul(n, n);
			// System.out.println(1+" "+n[0][0]+" "+n[0][1]+" "+n[1][0]+" "+n[1][1]);
			for (int i = 0; i < 2; i++) {
				for (int j = 0; j < 2; j++) {
					if (n[i][j] >= m)
						n[i][j] %= m;
				}
			}
		}
		return result;
	}

	public static long pow(long n, long p) {
		long result = 1;
		if (p == 0)
			return 1;
		if (p == 1)
			return n;
		while (p != 0) {
			if (p % 2 == 1)
				result *= n;
			p >>= 1;
			n *= n;
		}
		return result;
	}

	static class InputReader {

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

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

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

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

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

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

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

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

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

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

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

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


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class ImBoredWithLife {
    public static void main(String[]args) {
        Scanner s = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int n=s.nextInt();
        int m=s.nextInt();
        int mi=Math.min(n,m);
        System.out.println(factorial(mi));
    }

    private static int factorial(int n) {
        if(n==1)
            return 1;
        else
            return n*factorial(n-1);
    }

}


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

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        ConsoleIO io = new ConsoleIO(new InputStreamReader(System.in), new PrintWriter(System.out));

//        String fileName = "C-small-attempt0";
//        ConsoleIO io = new ConsoleIO(new FileReader("D:\\Dropbox\\code\\practice\\jb\\src\\" + fileName + ".in"), new PrintWriter(new File("D:\\Dropbox\\code\\practice\\jb\\src\\" + fileName + ".out")));

        new Main(io).solve();
//        new Main(io).solveLocal();

        io.close();
    }

    ConsoleIO io;

    Main(ConsoleIO io) {
        this.io = io;
    }

    ConsoleIO opt;

    Main(ConsoleIO io, ConsoleIO opt) {
        this.io = io;
        this.opt = opt;
    }

    List<List<Integer>> gr = new ArrayList<>();

    long MOD = 1_000_000_007;

    class Box{
        public Box(char color, int count, int idx){
            this.color = color == 'R' ? 0 : (color == 'G' ? 1 : 2);
            this.count = count;
            this.idx = idx;
        }
        public int color;
        public int count;
        public int idx;
    }

    public void solve() {
        int[] l = io.readIntArray();
        int n = l[0];
        int s = l[1] - 1;
        int k = l[2];
        int[] num = io.readIntArray();
        char[] col = io.readLine().toCharArray();
        Box[] all = new Box[n];
        int sum = 0;
        for(int i = 0;i<n;i++){
            all[i] = new Box(col[i], num[i], i);
            sum += num[i];
        }
        int maxCount = Math.max(k, sum);
        Arrays.sort(all, Comparator.comparingInt(a -> a.count));
        int[][] min = new int[n][maxCount+1];
        for(int i = 0;i<n;i++)
            for(int j = 0;j<=maxCount;j++)
                min[i][j] = Integer.MAX_VALUE / 3;
        for(int i = 0;i<n;i++) {
            Box b = all[i];
            min[i][b.count] = Math.min(min[i][b.count], Math.abs(s - b.idx));
            for (int j = 0; j < i; j++)
                if (b.count > all[j].count && b.color != all[j].color) {
                    for (int c = b.count; c <= maxCount; c++) {
                        min[i][c] = Math.min(min[i][c], min[j][c - b.count] + Math.abs(b.idx - all[j].idx));
                    }
                }
        }
        int res = Integer.MAX_VALUE/3;
        for(int i = 0;i<n;i++)
            for(int j = k; j<=maxCount;j++)
                res = Math.min(res, min[i][j]);
        io.writeLine((res==Integer.MAX_VALUE/3?-1:res)+"");
    }

}

class ConsoleIO {

    BufferedReader br;
    PrintWriter out;
    public ConsoleIO(Reader reader, PrintWriter writer){br = new BufferedReader(reader);out = writer;}
    public void flush(){this.out.flush();}
    public void close(){this.out.close();}
    public void writeLine(String s) {this.out.println(s);}
    public void writeInt(int a) {this.out.print(a);this.out.print(' ');}
    public void writeWord(String s){
        this.out.print(s);
    }
    public void writeIntArray(int[] a, int k, String separator) {
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < k; i++) {
            if (i > 0) sb.append(separator);
            sb.append(a[i]);
        }
        this.writeLine(sb.toString());
    }
    public int read(char[] buf, int len){try {return br.read(buf,0,len);}catch (Exception ex){ return -1; }}
    public String readLine() {try {return br.readLine();}catch (Exception ex){ return "";}}
    public long[] readLongArray() {
        String[]n=this.readLine().trim().split("\\s+");long[]r=new long[n.length];
        for(int i=0;i<n.length;i++)r[i]=Long.parseLong(n[i]);
        return r;
    }
    public int[] readIntArray() {
        String[]n=this.readLine().trim().split("\\s+");int[]r=new int[n.length];
        for(int i=0;i<n.length;i++)r[i]=Integer.parseInt(n[i]);
        return r;
    }
    public int[] readIntArray(int n) {
        int[] res = new int[n];
        char[] all = this.readLine().toCharArray();
        int cur = 0;boolean have = false;
        int k = 0;
        boolean neg = false;
        for(int i = 0;i<all.length;i++){
            if(all[i]>='0' && all[i]<='9'){
                cur = cur*10+all[i]-'0';
                have = true;
            }else if(all[i]=='-') {
                neg = true;
            }
            else if(have){
                res[k++] = neg?-cur:cur;
                cur = 0;
                have = false;
                neg = false;
            }
        }
        if(have)res[k++] = neg?-cur:cur;
        return res;
    }
    public int ri() {
        try {
            int r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public long readLong() {
        try {
            long r = 0;
            boolean start = false;
            boolean neg = false;
            while (true) {
                int c = br.read();
                if (c >= '0' && c <= '9') {
                    r = r * 10 + c - '0';
                    start = true;
                } else if (!start && c == '-') {
                    start = true;
                    neg = true;
                } else if (start || c == -1) return neg ? -r : r;
            }
        } catch (Exception ex) {
            return -1;
        }
    }
    public String readWord() {
        try {
            boolean start = false;
            StringBuilder sb = new StringBuilder();
            while (true) {
                int c = br.read();
                if (c!= ' ' && c!= '\r' && c!='\n' && c!='\t') {
                    sb.append((char)c);
                    start = true;
                } else if (start || c == -1) return sb.toString();
            }
        } catch (Exception ex) {
            return "";
        }
    }
    public char readSymbol() {
        try {
            while (true) {
                int c = br.read();
                if (c != ' ' && c != '\r' && c != '\n' && c != '\t') {
                    return (char) c;
                }
            }
        } catch (Exception ex) {
            return 0;
        }
    }
//public char readChar(){try {return (char)br.read();}catch (Exception ex){ return 0; }}
}
class Pair {
    public Pair(int a, int b) {this.a = a;this.b = b;}
    public int a;
    public int b;
}
class PairLL {
    public PairLL(long a, long b) {this.a = a;this.b = b;}
    public long a;
    public long b;
}
class Triple {
    public Triple(int a, int b, int c) {this.a = a;this.b = b;this.c = c;}
    public int a;
    public int b;
    public int c;
}


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

public class B {

    int gcd(int x,int y){
        if(x==0)return y;
        return gcd(y%x,x);
    }

    void solve() throws IOException {
        int n=nextInt();
        int[] a=new int[n];
        int[] b=new int[n];
        for(int i=0;i<n;i++){
            a[i]=nextInt();
        }
        for(int i=0;i<n;i++)b[i]=nextInt();
        int t=a[0];
        for(int i=1;i<n;i++)t=t*a[i]/gcd(t,a[i]);
        int count=0;
        for(int i=0;i<t;i++){
            boolean good=false;
            for(int j=0;j<n;j++)if(i%a[j]==b[j]){
                good=true;
                break;
            }
            if(good)count++;
        }
        out.printf(Locale.CANADA,"%.9f",count*1./t);
    }

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

    void run() throws IOException {
        reader = new BufferedReader(new InputStreamReader(System.in));
//		reader = new BufferedReader(new FileReader("input.txt"));
        tokenizer = null;
        out = new PrintWriter(new OutputStreamWriter(System.out));
//		out = new PrintWriter(new FileWriter("output.txt"));
        solve();
        reader.close();
        out.flush();

    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter out;

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

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

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

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


import java.util.*;
import java.lang.Math;
public class AbstractionInJava{
    public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int m=sc.nextInt();
    int o=sc.nextInt();

    double a=Math.sqrt((n*m)/o);
        double b=Math.sqrt((n*o)/m);

    double c=Math.sqrt((m*o)/n);

    System.out.print((int)(a+b+c)*4);

    }}


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

/**
 * Created by IntelliJ IDEA.
 * User: mihai
 * Date: 2/3/12
 * Time: 10:46 PM
 */
public class problemD {
    private static final long MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N, M, K;
        N = sc.nextInt();
        M = sc.nextInt();
        K = sc.nextInt();

        if (K == 1 || K > N) System.out.println(pow(M, N));
        else if (K == N) System.out.println(pow(M, (N + 1) / 2));
        else if (K % 2 == 0) System.out.println(M);
        else System.out.println(M * M);

        }

    private static int pow(long x, long y) {
        int[] put = new int[128];
        int k = 0;
        while (y != 0) {
            put[k++] = (int)y % 2;
            y /= 2;
        }

        long res = x;
        for (int i = k - 2; i >= 0; i--) {
            if (put[i] == 1) {
                res *= res;
                res %= MOD;
                res *= x;
                res %= MOD;
            } else {
                res *= res;
                res %= MOD;
            }
        }

        return (int)res;
    }
}


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

public class TvSet {
    public static long gcd(long a, long b) {
        if (a == 1 || b == 1)
            return 1;
        if (a % b == 0)
            return b;
        return gcd(b, a % b);
    }

    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        long a = sc.nl(), b = sc.nl(), x = sc.nl(), y = sc.nl();
        long hcf = gcd(x, y);
        x /= hcf;
        y /= hcf;
        long v1 = a / x;
        long v2 = b / y;
        System.out.println(Math.min(v1, v2));
    }

    /////////// TEMPLATE FROM HERE /////////////////
    private static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            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 ni() {
            return Integer.parseInt(next());
        }

        float nf() {
            return Float.parseFloat(next());
        }

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

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

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


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.util.*;

public class Main {

    public static boolean common2 = false;
    public static long total = 0, v2 = 0, d = 0, t = 0;
    public static long[][] dp = new long[1000][2000];

    public static void main(String[] args) throws IOException {
        Map<Integer, String> map = new HashMap<Integer, String>();
        map.put(0, "zero");
        map.put(1, "one");
        map.put(2, "two");
        map.put(3, "three");
        map.put(4, "four");
        map.put(5, "five");
        map.put(6, "six");
        map.put(7, "seven");
        map.put(8, "eight");
        map.put(9, "nine");
        map.put(10, "ten");
        map.put(11, "eleven");
        map.put(12, "twelve");
        map.put(13, "thirteen");
        map.put(14, "fourteen");
        map.put(15, "fifteen");
        map.put(16, "sixteen");
        map.put(17, "seventeen");
        map.put(18, "eighteen");
        map.put(19, "nineteen");
        map.put(20, "twenty");
        map.put(30, "thirty");
        map.put(40, "forty");
        map.put(50, "fifty");
        map.put(60, "sixty");
        map.put(70, "seventy");
        map.put(80, "eighty");
        map.put(90, "ninety");
        int i, j;
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        if (n <= 20) {
            System.out.println(map.get(n));
        } else {
            int m = n % 10;
            int n1 = n - m;
            StringBuilder strB = new StringBuilder("");
            if (m != 0) {
            System.out.println(map.get(n1) + "-" + map.get(m));
            } else {
                System.out.println(map.get(n1));
            }
        }
    }
}


import jdk.swing.interop.SwingInterOpUtils;

import java.util.Scanner;

public class cp {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int k = 0, l = 0, count = 0;

        int ar[][] = new int[5][5];

        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                ar[i][j] = scan.nextInt();
                if (ar[i][j] == 1) {
                    k = i;
                    l = j;
                }
            }
        }

        for (int i = 0; i < 5; i++) {
            if (k != 2) {

                if (k > 2) {
                    k--;
                } else {
                    k++;
                }

                count = count + 1;

            }
            if (l != 2) {
                {
                    if (l > 2) {
                        l--;
                    } else {
                        l++;
                    }
                }
                count = count + 1;
            }

           else if (k == 2 && l == 2)
            break;

    }

        System.out.println(count);

}
}


import java.io.*;
import java.util.*;
import java.math.*;
public class Main
{
	public static void main (String[]args) throws IOException
	{
		Scanner read = new Scanner (System.in);
		String x = read.next();
		String ans="";
		for (int i=0;i<x.length();i++)
		{
			if (x.charAt(i)=='.')
				ans+="1100";
			if (x.charAt(i)==',')
				ans+="1101";
			if (x.charAt(i)=='>')
				ans+="1000";
			if (x.charAt(i)=='<')
				ans+="1001";
			if (x.charAt(i)=='[')
				ans+="1110";
			if (x.charAt(i)==']')
				ans+="1111";
			if (x.charAt(i)=='+')
				ans+="1010";
			if (x.charAt(i)=='-')
				ans+="1011";

		}
		BigInteger br = new BigInteger(ans,2);
		System.out.println(br.mod(new BigInteger("1000003")));
	}
}


import java.util.Scanner;

/**
 *
 * @author arabtech
 */
public class PetyaAndSquare {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int x,y,size;
        size=sc.nextInt();
        x=sc.nextInt();
        y=sc.nextInt();
        if(((2*x)==size||(2*(x-1)==size))&&((2*y)==size||(2*(y-1)==size))){
            System.out.println("NO");
        }
        else{
          System.out.println("YES");
        }
    }

}


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

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

    static class TaskB {
        public void solve(int testNumber, MyReader in, PrintWriter out) {
            String str = in.next();
            long n = Long.parseLong(str.substring(0, str.length() - 1));
            char ch = str.charAt(str.length() - 1);
            int poz = getPoz(ch);
            BigInteger time = BigInteger.ZERO;
            if (n % 4 != 0) time = BigInteger.valueOf(n / 4).multiply(BigInteger.valueOf(16));
            else time = BigInteger.valueOf((n - 1) / 4).multiply(BigInteger.valueOf(16));

            if (n % 4 == 0) {
                time = time.add(BigInteger.valueOf(poz + 7));
            } else if (n % 4 == 1) {
                time = time.add(BigInteger.valueOf(poz));
            } else if (n % 4 == 2) {
                time = time.add(BigInteger.valueOf(poz + 7));
            } else if (n % 4 == 3) {
                time = time.add(BigInteger.valueOf(poz));
            }
            out.println(time);
        }

        int getPoz(char ch) {
            switch (ch) {
                case 'a':
                    return 4;
                case 'b':
                    return 5;
                case 'c':
                    return 6;
                case 'd':
                    return 3;
                case 'e':
                    return 2;
                case 'f':
                    return 1;
            }
            return -1;
        }

    }

    static class MyReader {
        private BufferedReader buffReader;
        private StringTokenizer strTokenizer;
        private static final int SIZE = 32768;

        public MyReader(InputStream inputStream) {
            buffReader = new BufferedReader(new InputStreamReader(inputStream), SIZE);
        }

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

    }
}


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

public class Main
	{
	/*
	 * Simple bitmask code for boolean isset, int set and int clr
	 */
	public static boolean isset(int n,int i) //returns 1 if the ith bit (from left) of n is set
		{
		return ((n>>i)&1)==1;
		}
	public static void main(String args[]) throws IOException
		{
		InputReader in=new InputReader(System.in);
		PrintWriter out=new PrintWriter(System.out);
		int n=in.readInt();
		Rectangle R[]=new Rectangle[n];
		for(int i=0;i<n;i++)
			R[i]=new Rectangle(in.readInt(),in.readInt(),in.readInt(),in.readInt());

		for(int i=(1<<n)-1;i<(1<<n);i++)
			{
			LinkedList<Rectangle> L=new LinkedList<Rectangle>();
			for(int j=0;j<n;j++)
				{
				if(isset(i,j))
					L.add(R[j]);
				}
			int num=L.size();
			Rectangle RT[]=new Rectangle[num];
			for(int j=0;j<num;j++)
				RT[j]=L.pollFirst();
			if(check(RT))
				{
				System.out.println("YES");
				return;
				}
			}
		System.out.println("NO");
		out.close();
		}

	private static boolean check(Rectangle[] RT)
		{
		/*System.out.println("For ");
		for(Rectangle r:RT)
			System.out.println("\t"+r.x1+" "+r.y1+" "+r.x2+" "+r.y2);*/
		long totArea=0;
		for(Rectangle r:RT)
			totArea+=(r.x2-r.x1)*(r.y2-r.y1);
		int upperCornerIndex=-1,lowerCornerIndex=-1;
		int N=RT.length;

		//upper right
		for(int i=0;i<N;i++)
			{
			boolean valid=true;
			for(int j=0;j<N;j++)
				{
				if(RT[i].x2>=RT[j].x2&&RT[i].y2>=RT[j].y2)
					continue;
				else
					valid=false;
				}
			if(valid)
				upperCornerIndex=i;
			}

		//bottom left
		for(int i=0;i<N;i++)
			{
			boolean valid=true;
			for(int j=0;j<N;j++)
				{
				if(RT[i].x1<=RT[j].x1&&RT[i].y1<=RT[j].y1)
					continue;
				else
					valid=false;
				}
			if(valid)
				lowerCornerIndex=i;
			}
		if(upperCornerIndex==-1||lowerCornerIndex==-1)
			return false;
		//System.out.println("\tIndices: "+upperCornerIndex+" "+lowerCornerIndex);
		long yLen=RT[upperCornerIndex].y2-RT[lowerCornerIndex].y1;
		long xLen=RT[upperCornerIndex].x2-RT[lowerCornerIndex].x1;
		if(xLen != yLen)
			return false;
		if(xLen*yLen!=totArea)
			return false;
		/*System.out.println("True for ");
		for(Rectangle r:RT)
			System.out.println("\t"+r.x1+" "+r.y1+" "+r.x2+" "+r.y2);*/
		return true;
		}
	}

class Rectangle
	{
	long x1,y1,x2,y2;

	public Rectangle(int x1,int y1,int x2,int y2)
		{
		this.x1=x1;
		this.y1=y1;
		this.x2=x2;
		this.y2=y2;
		}

	}
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 char readCharacter()
		{
		int c=read();
		while (isSpaceChar(c))
			c=read();
		return (char) c;
		}

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


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

public class Main {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
//        InputReader in = new InputReader(new FileInputStream("/home/ahmad/Desktop/input.txt"));
        PrintWriter out = new PrintWriter(outputStream);
        Main m = new Main();
        m.solve(in, out);
        out.close();
    }

    public void solve(InputReader in, PrintWriter out) {

        long n = in.nextLong();
        if (n == 0) {
            System.out.println(0);
            return;
        }
        ++n;
        if (n % 2 == 0) {
            System.out.println((n) / 2);
        } else {
            System.out.println(n);
        }

    }

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

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

        public InputReader(File stream) throws Exception {
            reader = new BufferedReader(new FileReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}


import java.util.Scanner;

public class GoldenPlate {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int width = sc.nextInt();
        int length = sc.nextInt();
        int glidedRings = sc.nextInt();
        int totalGlidedRings = 0;

        for(int i = 1; i <= glidedRings; i++) {
            totalGlidedRings += 2 * (width - 4 * (i - 1) - 2) + 2 * (length - 4 * (i - 1));
        }

        System.out.print(totalGlidedRings);
    }
}


import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	static final long mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	public static void main(String[] args) throws IOException
	{
		long fibo[]=new long[100];
		fibo[0]=1;
		fibo[1]=2;
		for(int i=2; i<100;i++)
			fibo[i]=fibo[i-1]+fibo[i-2];
		int x=ni(),y=ni();
		int j=0;
		for(;j<100; j++)
			if(x<=fibo[j]*(y-1)+1)
				break;
		pr(j+2);
		System.out.println(ans);
	}
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static int ni(){return in.nextInt();}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}


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

public class C {
	FastReader scn;
	PrintWriter out;
	String INPUT = "";

	void solve() {
		int n = scn.nextInt();
		char[] arr = scn.next().toCharArray();
		int sum = 0;
		boolean allZero = true;
		for(char ch : arr) {
			sum += ch - '0';
			if(ch != '0') {
				allZero = false;
			}
		}
		if(allZero) {
			out.println("YES");
			return;
		}
		boolean yes = false;
		for (int i = 0; i < sum; i++) {
			boolean fail = false;
			int curr = 0;
			for (int j = 0; j < n; j++) {
				int val = curr + arr[j] - '0';
				if (val > i) {
					fail = true;
					break;
				} else {
					curr += arr[j] - '0';
					j++;
					while(j < n && arr[j] == '0') {
						j++;
					}
					j--;
					if(curr == i) {
						curr = 0;
					} else if(j == n - 1) {
						fail = true;
					}
				}
			}
			if (!fail) {
				yes = true;
				break;
			}
		}

		if (yes) {
			out.println("YES");
		} else {
			out.println("NO");
		}
	}

	void run() throws Exception {
		long time = System.currentTimeMillis();
		boolean oj = System.getProperty("ONLINE_JUDGE") != null;
		out = new PrintWriter(System.out);
		scn = new FastReader(oj);
		solve();
		out.flush();
		if (!oj) {
			System.out.println(Arrays.deepToString(new Object[] { System.currentTimeMillis() - time + " ms" }));
		}
	}

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

	class FastReader {
		InputStream is;

		public FastReader(boolean onlineJudge) {
			is = onlineJudge ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		}

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

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

		boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		int skip() {
			int b;
			while ((b = readByte()) != -1 && isSpaceChar(b))
				;
			return b;
		}

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

		char nextChar() {
			return (char) skip();
		}

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

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

		char[] next(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);
		}

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

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

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

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

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

		int[][] next2DInt(int n, int m) {
			int[][] arr = new int[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextIntArray(m);
			}
			return arr;
		}

		long[][] next2DLong(int n, int m) {
			long[][] arr = new long[n][];
			for (int i = 0; i < n; i++) {
				arr[i] = nextLongArray(m);
			}
			return arr;
		}

		int[] shuffle(int[] arr) {
			Random r = new Random();
			for (int i = 1, j; i < arr.length; i++) {
				j = r.nextInt(i);
				arr[i] = arr[i] ^ arr[j];
				arr[j] = arr[i] ^ arr[j];
				arr[i] = arr[i] ^ arr[j];
			}
			return arr;
		}
	}
}


import java.util.Scanner;

/**
 * @author artyom
 */
public class Tetrahedron {
	private static final int MOD = 1_000_000_007;

	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] dp = new int[]{1, 1, 1, 0};
		for (int i = 1; i < n; i++) {
			int t0 = (dp[1] + dp[2]) % MOD + dp[3];
			int t1 = (dp[0] + dp[2]) % MOD + dp[3];
			int t2 = (dp[0] + dp[1]) % MOD + dp[3];
			int t3 = (dp[0] + dp[1]) % MOD + dp[2];
			dp[0] = t0 % MOD;
			dp[1] = t1 % MOD;
			dp[2] = t2 % MOD;
			dp[3] = t3 % MOD;
		}
		System.out.println(dp[3]);
	}
}


import java.util.*;
public class Tshirt_Hunt {
	public static void main(String a[]){
		Scanner s = new Scanner(System.in);
		int p = s.nextInt();
		int x = s.nextInt();
		int y = s.nextInt();
		int successful_hack = 0;
		boolean found = false;
		int k =0;
		int x1 = x;
		while(x1 >= y){
			found = got_Tshirt(x1,p);
			if(found){
				break;
			}
			x1 = x1-50;
		}
		if(found == false){
			while(true){
				x = x+50;
				k++;
				found = got_Tshirt(x,p);
				if(found){
					break;
				}
			}
			if(k%2 !=0){
				k = k+1;
				successful_hack = k/2;
			}else{
				successful_hack = k/2;
			}
		}
		System.out.println(successful_hack);
	}

	public static boolean got_Tshirt(int s,int p){
		boolean lucky = false;
		List<Integer> store = new ArrayList();
		int i = (s/50) % 475;
		for(int j=1;j<26;j++){
			i = (i * 96 + 42) % 475;
			store.add(26 + i);
		}

		lucky = store.contains(p);
		return lucky;
	}

}


import java.util.Scanner;

public class Main
{
   public static void main(String args[])
   {
	 Scanner s=new Scanner(System.in);
	 int n=s.nextInt(),k=n;
	 int m=s.nextInt();

	 if(n>=m)
	 {
		 while(k>=m)
		 {
			 int x= k/m;
			 k=k-x*m+x;
			 n=n+x;
		 }
		 System.out.print(n);
	 }
	 else
	 {
		 System.out.print(n);
	 }

   }

}


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

public class A {
    private static BufferedReader in;
    private static StringTokenizer st;
    private static PrintWriter out;

    public static void main(String[] args) throws NumberFormatException, IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        st = new StringTokenizer("");
        out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        int n = nextInt();
        int k = nextInt();
        int cnt = 0;
        while(k >= n){
            cnt++;
            if(k % n == 0) {
//              System.out.println(n + " " + k);
                k/=n;
            }else{
                System.out.println("NO");
                return;
            }
        }
        if(k != 1){
            System.out.println("NO");
        }else{
            System.out.println("YES");
            System.out.println(cnt-1);
        }
    }

    static String next() throws IOException{
        while(!st.hasMoreTokens()){
            st = new StringTokenizer(in.readLine());
        }
        return st.nextToken();
    }
    static int nextInt() throws NumberFormatException, IOException{
        return Integer.parseInt(next());
    }
    static long nextLong() throws NumberFormatException, IOException{
        return Long.parseLong(next());
    }

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

}


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

public class Main
{
	BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer tokenizer=null;

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

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

	int ni() throws IOException
	{
		return Integer.parseInt(ns());
	}

	long nl() throws IOException
	{
		return Long.parseLong(ns());
	}

	double nd() throws IOException
	{
		return Double.parseDouble(ns());
	}

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

	String nline() throws IOException
	{
		tokenizer=null;
		return br.readLine();
	}

	//Main Code starts Here
	int totalCases, testNum;

	void execute() throws IOException
	{
		totalCases = 1;
		for(testNum = 1; testNum <= totalCases; testNum++)
		{
			if(!input())
				break;
			solve();
		}
	}

	void solve() throws IOException
	{
		int a = ni();
		int b = ni();
		int ans = a;
		for(int i = a+1;;i++)
		{
			if(lucky(i) == b)
			{
				ans = i;
				break;
			}
		}
		System.out.println(ans);

	}

	int lucky(int a)
	{
		String s = String.valueOf(a);
		String f = "0";
		int n = s.length();
		for(int i = 0;i<n;i++)
		{
			char temp = s.charAt(i);
			if(temp == '4' || temp == '7')
			{
				f = f+temp;
			}
		}
		return Integer.valueOf(f);
	}

	boolean input() throws IOException
	{

		return true;
	}

}


// https://codeforces.com/problemset/problem/893/A

import java.util.Scanner;

public class Solution {

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

		int n = read.nextInt();

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

		if (a[0] == 3) {
			System.out.println("NO");
		}
		else if (n == 1) {
			System.out.println("YES");
		}
		else {
			int playerOne = a[0];
			int playerTwo = 3;
			int spectator = (a[0] == 1) ? 2 : 1;

			String result = "YES";
			for (int i = 1; i < n; ++i) {
				if (spectator == a[i]) {
					result = "NO";
					break;
				}

				playerOne = a[i];
				playerTwo = spectator;
				spectator = 6 - playerOne - playerTwo;
			}

			System.out.println(result);
		}

		// Close scanner
		read.close();
	}

}


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

public class Main {

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

	public Main(){

		Scanner sc = new Scanner(System.in);

		sc.nextLine();
		String line = sc.nextLine();

		ArrayList<Integer> temp = new ArrayList<Integer>();

		for(int i = 0; i < line.length(); i++){
			int digit = Integer.parseInt(Character.toString(line.charAt(i)));

			int[] a = getSpecial(digit);
			for(int q : a){
				temp.add(q);
			}

		}

		Collections.sort(temp);

		String lol = "";
		for(int i = temp.size()-1; i > -1; i--){
			lol += Integer.toString(temp.get(i));
		}

		System.out.println(lol);

	}

	public int[] getSpecial(int i) {
		switch (i) {
		case 0:
		case 1:
			return new int[] {};
		case 2:
			return new int[] { 2 };
		case 3:
			return new int[] { 3 };
		case 4:
			return new int[] { 3, 2, 2 };
		case 5:
			return new int[] { 5 };
		case 6:
			return new int[] { 5, 3 };
		case 7:
			return new int[] { 7 };
		case 8:
			return new int[] { 7, 2, 2, 2 };
		case 9:
			return new int[] { 7, 3, 3, 2 };
		default:
			return null;
		}
	}

}


import java.io.*;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.OptionalInt;
/* * */

public class _127_A implements Runnable{
    public static void main(String[] args) {
	    new Thread(null, new _127_A(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        FastReader fd = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String data = fd.next();
        int maxAscii = data.chars().max().getAsInt();
        for(int i = 0; i < data.length(); i++){
            if(data.charAt(i) == maxAscii){ out.print((char) maxAscii); }
        }
        out.println();
        out.close();
    }

    //Helper functions
    static void getArray(int[] data, boolean isSorted, FastReader fd){
        for(int i = 0; i < data.length; i++){ data[i] = fd.nextInt(); }
        if(isSorted) Arrays.sort(data);
    }
    static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

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

    static boolean checkDistinct(int next){// check all digits are distinct.

        String process = String.valueOf(next);
        for(int i = 0;i < process.length()-1; i++){
            String character = String.valueOf(process.charAt(i));
            if(process.substring(i+1).contains(character)){ return false; }
        }
        return true;
    }

    static int limit = (int) 1e7 + 1;
    static int[] facts = new int[limit];
    static void sieve() {  // Store the minimum prime factors of 1 to LIMIT
        facts[1] = 1;
        for (int i = 2; i < limit; i++) {
            if (i % 2 == 0 && i > 2) {
                facts[i] = 2;
            } else {
                facts[i] = i;
            }
        }
        for (int i = 3; i * i < limit; i++) {
            if (facts[i] == i) {
                for (int j = i * i; j < limit; j += i)
                    if (facts[j] == j)
                        facts[j] = i;
            }
        }
    }
    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

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

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

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

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

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

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

            int sgn = 1;

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

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

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

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

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

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

            return res.toString();
        }

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

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

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


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

@SuppressWarnings("unchecked")
public class P887B {

  public void run() throws Exception {
    int n = nextInt(), c [][] = new int [n][];
    for (int i = 0; i < n; c[i] = readInt(6), i++);

    BitSet nums = new BitSet();
    for (int i = 0; i < n; i++) {
      for (int ii = 0; ii < 6; ii++) {
        nums.set(c[i][ii]);

        if (n >= 2) {
          for (int j = 0; j < n; j++) {
            if (j != i) {
              for (int jj = 0; jj < 6; jj++) {
                nums.set(c[i][ii] * 10 + c[j][jj]);

                if (n >= 3) {
                  for (int k = 0; k < n; k++) {
                    if ((k != i) && (k != j)) {
                      for (int kk = 0; kk < 6; kk++) {
                        nums.set(c[i][ii] * 100 + c[j][jj] * 10 + c[k][kk]);
                      }
                    }
                  }
                }
              }
            }
          }
        }
      }
    }

    println(nums.nextClearBit(1) - 1);
  }

  public static void main(String... args) throws Exception {
    br = new BufferedReader(new InputStreamReader(System.in));
    pw = new PrintWriter(new BufferedOutputStream(System.out));
    new P887B().run();
    br.close();
    pw.close();
    System.err.println("\n[Time : " + (System.currentTimeMillis() - startTime) + " ms]");
  }

  static long startTime = System.currentTimeMillis();
  static BufferedReader br;
  static PrintWriter pw;
  StringTokenizer stok;

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

  void print(byte b) { print("" + b); }
  void print(int i) { print("" + i); }
  void print(long l) { print("" + l); }
  void print(double d) { print("" + d); }
  void print(char c) { print("" + c); }
  void print(Object o) {
    if (o instanceof int[]) { print(Arrays.toString((int [])o));
    } else if (o instanceof long[]) { print(Arrays.toString((long [])o));
    } else if (o instanceof char[]) { print(Arrays.toString((char [])o));
    } else if (o instanceof byte[]) { print(Arrays.toString((byte [])o));
    } else if (o instanceof short[]) { print(Arrays.toString((short [])o));
    } else if (o instanceof boolean[]) { print(Arrays.toString((boolean [])o));
    } else if (o instanceof float[]) { print(Arrays.toString((float [])o));
    } else if (o instanceof double[]) { print(Arrays.toString((double [])o));
    } else if (o instanceof Object[]) { print(Arrays.toString((Object [])o));
    } else { print("" + o); }
  }
  void print(String s) { pw.print(s); }
  void println() { println(""); }
  void println(byte b) { println("" + b); }
  void println(int i) { println("" + i); }
  void println(long l) { println("" + l); }
  void println(double d) { println("" + d); }
  void println(char c) { println("" + c); }
  void println(Object o) { print(o); println(); }
  void println(String s) { pw.println(s); }
  int nextInt() throws IOException { return Integer.parseInt(nextToken()); }
  long nextLong() throws IOException { return Long.parseLong(nextToken()); }
  double nextDouble() throws IOException { return Double.parseDouble(nextToken()); }
  char nextChar() throws IOException { return (char) (br.read()); }
  String next() throws IOException { return nextToken(); }
  String nextLine() throws IOException { return br.readLine(); }
  int [] readInt(int size) throws IOException {
    int [] array = new int [size];
    for (int i = 0; i < size; i++) { array[i] = nextInt(); }
    return array;
  }
  long [] readLong(int size) throws IOException {
    long [] array = new long [size];
    for (int i = 0; i < size; i++) { array[i] = nextLong(); }
    return array;
  }
  double [] readDouble(int size) throws IOException {
    double [] array = new double [size];
    for (int i = 0; i < size; i++) { array[i] = nextDouble(); }
    return array;
  }
  String [] readLines(int size) throws IOException {
    String [] array = new String [size];
    for (int i = 0; i < size; i++) { array[i] = nextLine(); }
    return array;
  }

  int gcd(int a, int b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Integer.numberOfTrailingZeros(a), bz = Integer.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Integer.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Integer.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }

  long gcd(long a, long b) {
    if (a == 0) return Math.abs(b); if (b == 0) return Math.abs(a);
    a = Math.abs(a); b = Math.abs(b);
    int az = Long.numberOfTrailingZeros(a), bz = Long.numberOfTrailingZeros(b);
    a >>>= az; b >>>= bz;
    while (a != b) {
      if (a > b) { a -= b; a >>>= Long.numberOfTrailingZeros(a); }
            else { b -= a; b >>>= Long.numberOfTrailingZeros(b); }
    }
    return (a << Math.min(az, bz));
  }
}


import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		PrintWriter pw=new PrintWriter(System.out);
		while(sc.hasNext()){
			long n=sc.nextLong();
			long m=sc.nextLong();
			long k=sc.nextLong();
			long mod=1000000007;
			long res=1;
			long a=n-1;
			long base=2;
			while(a>0){
				if(a%2!=0)res=(res%mod*base)%mod;
				a/=2;
				base=(base*base)%mod;
			}
			a=m-1;
			base=res;
			res=1;
			while(a>0){
				if(a%2!=0)res=(res%mod*base)%mod;
				a/=2;
				base=(base*base)%mod;
			}
			if((n&1)!=(m&1)&&k==-1)res=0;
			pw.println(res);
			pw.flush();
		}

	}
}

class FastScanner {
	BufferedReader br;
	StringTokenizer st;

	public FastScanner() {
		try {
			br = new BufferedReader(new InputStreamReader(System.in),32768);
			st = new StringTokenizer("");
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

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

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

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

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

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

	public String nextLine() {
		String line = "";
		try {
			line = br.readLine();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return line;
	}
}