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

public class Main {

	public static void main(String[] args) throws IOException {
		try {
			if (new File("input.txt").exists())
				System.setIn(new FileInputStream("input.txt"));
		} catch (SecurityException e) {
		}
		new Thread(null, new Runnable() {
			public void run() {
				try {
					new Main().run();
				} catch (Throwable e) {
					e.printStackTrace();
					exit(999);
				}
			}
		}, "1", 1 << 23).start();
	}

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

	int n, T;
	boolean f[][];
	int start[][];
	int end[][];

	Q qu;

	void get(int m[][]) throws IOException{
		for(int i = 0; i < n; i++){
			char s[] = nextToken().toCharArray();
			for(int j = 0; j < n; j++){
				switch(s[j]){
				case 'Z' :
					if(qu.isEmpty())
						qu.push(i, j, 0);
					f[i][j] = false;
					break;
				case 'Y':
					f[i][j] = false;
					break;
				default:
					m[i][j] = s[j] - '0';
				}
			}
		}
	}
	int ttd[][]; //time to die
	boolean used[][];

	int dx[] = {-1, 0, 1 , 0};
	int dy[] = {0, 1, 0 , -1};

	int inf = -1;
	int cap[][];
	int fl[][];
	int m;

	void compute_ttd(){
		for(boolean i[] : used)
			fill(i, false);

		while(!qu.isEmpty()){
			P e = qu.pop();
			int x = e.x, y = e.y, t = e.t;
			ttd[x][y] = t;
			used[x][y] = true;
			for(int k = 0; k < 4; k++)
				if(valid(x + dx[k], y + dy[k]))
					qu.push(x + dx[k], y + dy[k], t + 1);
		}
	}

	boolean valid(int x, int y){
		if(x < 0 || y < 0 || x >= n || y >= n || !f[x][y] || used[x][y])
			return false;
		return true;
	}

	List<Integer> g[];
	void setG(int vert){
		for(boolean i[] : used)
			fill(i, false);

		while(!qu.isEmpty()){
			P e = qu.pop();
			int x = e.x, y = e.y, t = e.t;
			if(!valid(x,y))
				continue;
			used[x][y] = true;

			if(t <= ttd[x][y] && t <= T){
				cap[vert][m + 2 + x * n + y] = inf;
				g[vert].add(m + 2 + x * n + y);
			}
			if(t >= ttd[x][y] || t >= T)
				continue;
			for(int k = 0; k < 4; k++)
				if(valid(x + dx[k], y + dy[k]))
					qu.push(x + dx[k], y + dy[k], t + 1);
		}
	}
	int path[];
	boolean lu[];
	QL ql;
	int cp = 0;;
	boolean find_path(int start, int end){
		cp = 0;
		fill(lu, false);

//		System.err.println(start + " " + end);
		ql.clear();
		ql.push(start);
		lu[start] = true;
		while(!ql.isEmpty()){
			int v = ql.pop();
			if(v == end)
				return true;
//			System.err.println(v + " " + g[v]);
			for(int e : g[v]){
				if(lu[e])
					continue;
				if(cap[v][e] > fl[v][e]){
					lu[e] = true;
					path[e] = v;
					ql.push(e);
				}
			}
		}
		return false;
	}

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

		n = nextInt();
		T = nextInt();

		inf = n * n + n + 10;

		f = new boolean[n][n];
		start = new int[n][n];
		end = new int[n][n];
		for(boolean []i : f)
			fill(i, true);

		qu = new Q(n * n + 1);//

		get(start);
		get(end);

		ttd = new int[n][n];
		used = new boolean[n][n];

		for(int i[] : ttd)
			fill(i, inf << 1);

		compute_ttd();

		m = n * n;

		cap = new int[m + m + 2][m + m + 2];
		fl = new int[m + m + 2][m + m + 2];

		g = new ArrayList[m + m + 2];
		for(int i = 0; i < m + m + 2; i++)
			g[i] = new ArrayList<Integer>();

		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++){
				qu.clear();
				qu.push(i, j, 0);
				setG(n * i + j);
			}

//		for(int i = 0; i < n; i++)
//			System.err.println(Arrays.toString(ttd[i]));
//		for(int i = 0; i < m; i++)
//			System.err.println(Arrays.toString(cap[i]));
//
//		for(int ii = 0; ii < n; ii++)
//			for(int jj = 0; jj < n; jj++)
//		for(int i = 0; i < n; i++)
//			for(int j = 0; j < n; j++)
//						if(cap[ii * n + jj][i * n + j] != 0)
//							System.err.println(ii + " " + jj + " | " + i + " " + j);

		// m - from   m+1 - to
		for(int i = 0; i < n; i++)
			for(int j = 0; j < n; j++){
				if(start[i][j] != 0){
					cap[m][i * n + j] = start[i][j];
					g[m].add(i * n + j);
				}
				if(end[i][j] != 0){
					cap[m + 2 + i * n + j][m+1] = end[i][j];
					g[m + 2 + i * n + j].add(m + 1);
				}
			}

		path = new int[m + m + 2];
		lu = new boolean[m + m + 2];
		ql = new QL(m + m + 2);
		int ans = 0;

		while(true){
			if(!find_path(m , m + 1))
				break;

			int mf = inf;
			{
				int i = m + 1;
				do{
					int j = path[i];
					mf = min(mf, cap[j][i] - fl[j][i]);
					i = j;
				}while(i != m);
			}
			ans += mf;
			{
				int i = m + 1;
				do{
					int j = path[i];
					fl[j][i] += mf;
					i = j;
				}while(i != m);
			}
		}
		out.println(ans);
		in.close();
		out.close();
	}

	class Q{
		P m[];
		int h, t;
		Q(int size){
			m = new P[size];
			for(int i = 0; i < size; i++)
				m[i] = new P(0,0,0);
			h = t = 0;
		}
		void clear(){
			h = t = 0;
		}
		void push(int x, int y, int tt){
			m[t++].set(x, y, tt);
		}
		void push(P e){
			m[t++].set(e);
		}
		P pop(){
			return m[h++];
		}
		boolean isEmpty(){
			return h == t;
		}
	}
	class QL{
		int m[];
		int h, t;
		QL(int size){
			m = new int[size];
			h = t = 0;
		}
		void push(int x){
//			System.err.println(x);
			m[t++] = x;
		}
		int pop(){
			return m[h++];
		}
		boolean isEmpty(){
			return h == t;
		}
		void clear(){
			h = t = 0;
		}
	}
	class P{
		int x, y, t;
		P(int xx, int yy, int tt){
			x = xx;
			y = yy;
			t = tt;
		}
		void set(int xx, int yy, int tt){
			x = xx;
			y = yy;
			t = tt;
		}
		void set(P e){
			x = e.x;
			y = e.y;
			t = e.t;
		}
		public String toString(){
			return x + " " + y  + " " + t + " |";
		}
	}
	void chk(boolean b) {
		if (b)
			return;
		System.out.println(new Error().getStackTrace()[1]);
		exit(999);
	}
	void deb(String fmt, Object... args) {
		System.out.printf(Locale.US, fmt + "%n", args);
	}
	String nextToken() throws IOException {
		while (!st.hasMoreTokens())
			st = new StringTokenizer(in.readLine());
		return st.nextToken();
	}
	int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
	long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}
	double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}
	String nextLine() throws IOException {
		st = new StringTokenizer("");
		return in.readLine();
	}
	boolean EOF() throws IOException {
		while (!st.hasMoreTokens()) {
			String s = in.readLine();
			if (s == null)
				return true;
			st = new StringTokenizer(s);
		}
		return false;
	}
}


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

public class Main
{
	static Scanner input = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out, true);

    public static boolean pre_test(int n ,int m, StringBuilder S)
    {
    	for(int i =1; i < S.length(); i++)
    		if(S.charAt(i) != S.charAt(0)) return false;
    	return true;
    }

	public static void main(String[] args)
	{
		int n, k;
		n = input.nextInt();
		k = input.nextInt();

		StringBuilder S = new StringBuilder(input.next());

		ArrayDeque<StringBuilder> q = new ArrayDeque<>();
		Set<String> mySet = new TreeSet<>();
		q.add(S);
		int cost =0;

		if(pre_test(n, k, S) && k == n)
		{
			out.println((n*(n-1))/2 );
			return;
		}

		while(!q.isEmpty() && mySet.size() < k)
		{
			StringBuilder pa = q.pop();
			mySet.add(pa.toString());
			// out.println(mySet);

			for(int i =0; i < pa.length(); i++)
			{
				StringBuilder vois = new StringBuilder(pa);
				vois.deleteCharAt(i);
				q.add(vois);
			}

		}

		if(mySet.size() != k)
		{
			out.println("-1");
			return;
		}
		for(String s: mySet)
		{
			cost += (n - s.length());
		}

		out.println(cost);

	}

}


/*
Keep solving problems.
*/

import com.sun.org.apache.xml.internal.security.Init;

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

public class CFA {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    private static final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};
    private static final String yes = "Yes";
    private static final String no = "No";

    int n;
    int h;
    int m;
    void solve() throws IOException {
        n = nextInt();
        h = nextInt();
        m = nextInt();
        int[] res = new int[n];
        Arrays.fill(res, h);
        for (int i = 0; i < m; i++) {
            int l = nextInt() - 1;
            int r = nextInt() - 1;
            int x = nextInt();
            for (int j = l; j <= r; j++) {
                res[j] = Math.min(res[j], x);
            }
        }

        long sum = 0;
        for (int v : res) {
            sum += v * v;
        }

        outln(sum);
    }

    void shuffle(long[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            long tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    long gcd(long a, long b) {
        while(a != 0 && b != 0) {
            long c = b;
            b = a % b;
            a = c;
        }
        return a + b;
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    private void formatPrint(double val) {
        outln(String.format("%.9f%n", val));
    }
    public CFA() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new CFA();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


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

/*
 * The problem statement can be found at http://www.spoj.com/problems/AGGRCOW/
 *
 * The online judge gives TLE, but the sample test case works. Can you find the
 * bug?
 */
public class MultiplicationTable {

    public static void main(String[] args) throws IOException {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int m = scan.nextInt();
        int k = scan.nextInt();

            int[] multiplicationAnswers = new int[n * m]; // size 4
            int counter = 0;
            for (int z = 1; z <= n; z++)
            {
                for (int l = 1; l <= m; l++)
                {
                    multiplicationAnswers[counter] = z * l;
                    counter++;
                }
            }
            Arrays.sort(multiplicationAnswers);
            System.out.println(multiplicationAnswers[k - 1]);
        }
    }


import java.util.Scanner;

/**
 * Created by nursultan on 11/10/15.
 */
public class Test148 {

    static void solve(int[] a, int m) {
        // diapazon
        int n = a.length - 1;

        int mend = n - m;
        int mstart = m - 1;

        int apos = -1;

        if(mstart >= mend) {
            apos = m - 1;
        } else {
            apos = m + 1;
        }

        System.out.println(apos);

    }

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);

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

        int[] a = new int[n + 1];

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

        solve(a, m);

    }

}


import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class D {
    public static void main(String[] args) throws Exception {
        BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
        String s = bf.readLine();
        String t = bf.readLine();
        int[] max_a_s = new int[s.length()];
        int[] max_a_t = new int[t.length()];
        int[] b_c_count_s = new int[s.length()+1];
        int[] b_c_count_t = new int[t.length()+1];
        b_c_count_s[0] = 0;
        b_c_count_t[0] = 0;
        int cur = 0;
        for(int i=0; i<s.length(); i++) {
          if(s.charAt(i) == 'A') cur++;
          else cur = 0;
          max_a_s[i] = cur;

        }
        cur = 0;
        for(int i=0; i<t.length(); i++) {
          if(t.charAt(i) == 'A') cur++;
          else cur = 0;
          max_a_t[i] = cur;

        }
        for(int i=1; i<s.length()+1; i++)
          b_c_count_s[i] = b_c_count_s[i-1] + ((s.charAt(i-1) != 'A') ? 1 : 0);
        for(int i=1; i<t.length()+1; i++)
          b_c_count_t[i] = b_c_count_t[i-1] + ((t.charAt(i-1) != 'A') ? 1 : 0);

        //System.out.println(Arrays.toString(b_c_count_s));
        // Scanner scan = new Scanner(System.in);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        int q = Integer.parseInt(bf.readLine());
        StringBuilder ans = new StringBuilder();
        for(int x=0; x<q; x++) {
          StringTokenizer st = new StringTokenizer(bf.readLine());
          int a = Integer.parseInt(st.nextToken())-1;
          int b = Integer.parseInt(st.nextToken())-1;
          int c = Integer.parseInt(st.nextToken())-1;
          int d = Integer.parseInt(st.nextToken())-1;
          int b_c_count_begin = b_c_count_s[b+1]-b_c_count_s[a];
          int b_c_count_end = b_c_count_t[d+1]-b_c_count_t[c];
          int a_tail_begin = Math.min(max_a_s[b], b-a+1);
          int a_tail_end = Math.min(max_a_t[d], d-c+1);
          boolean works = true;
          int gained_b_c = b_c_count_end - b_c_count_begin;
          if(a_tail_begin < a_tail_end) works = false;
          else if(a_tail_begin > a_tail_end) {
            if(gained_b_c < 2) {
              if((a_tail_begin - a_tail_end) % 3 != 0)
                works = false;
            }
          }
          else {
            if(a_tail_begin == b-a+1) works = false;
          }
          if(gained_b_c < 0) works = false;
          if(gained_b_c % 2 == 1) works = false;
          if(works) ans.append('1');
          else ans.append('0');
        //  if(a_tail_begin > )

        }
        out.println(ans.toString());
        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n];
        // for(int i=0; i<n; i++) a[i] =  Integer.parseInt(st.nextToken());

        out.close(); System.exit(0);
    }

}


public class A {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        if(a==b) {
        System.out.println(a+b+((c/2)*2));
        }
        else
         {   int d=Math.min(a,b);
             int l=Math.max(a,b);
               while(d<=l && c!=0)
               {
                        d++;
                        c--;

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

    }

}


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

public class A {

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

        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();

        int[] x = {a,b,c};
        Arrays.sort(x);

        int cnt=0;

        int k1=n/x[0];
        for (int i=k1; i>=0; i--) {
            for (int j=(n-i*x[0])/x[1]; j>=0; j--) {
                for (int t=(n-i*x[0]-j*x[1])/x[2]; t>=0; t--) {
                    if (i*x[0]+j*x[1]+t*x[2]==n)
                        cnt = Math.max(cnt, i+j+t);
                }
            }
        }
        System.out.println(cnt);
    }

}


import java.util.*;

public class TaskF {
    private static final long MOD = 1_000_000_000 + 7;

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

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

        initFactorials(Math.max(n, m));
        System.out.println(solve(n, m));

        in.close();
    }

    private static long solve(int n, int m) {
        long sum = 0;
        for (int k = 1; k <= n - 1; k++) {
            long splits = splits(m, k);
            long perms = perms(n, k);
            long rest = rest(n, m, k);
            sum += (((splits * perms) % MOD) * rest) % MOD;
            sum = sum % MOD;
        }
        return sum;
    }

    private static long splits(int sum, int count) {
        return modCombinations(sum - 1, count - 1);
    }

    private static long perms(int n, int k) {
        return modKPermutations(n - 2, k - 1);
    }

    private static long rest(int n, int m, int k) {
        return (modNumberOfTrees(n, k + 1) * modPower(m, n - 1 - k)) % MOD;
    }

    private static long modNumberOfTrees(int n, int y) {
        if (n < y) {
            return 0;
        } else if (n == y) {
            return 1;
        } else {
            return (y * modPower(n, n - y - 1)) % MOD;
        }
    }

    private static long[] factorial;
    private static long[] inverse;
    private static long[] inverseFactorial;

    private static void initFactorials(int upTo) {
        factorial = new long[upTo + 1];
        inverse = new long[upTo + 1];
        inverseFactorial = new long[upTo + 1];
        factorial[0] = 1;
        factorial[1] = 1;
        for (int i = 2; i <= upTo; i++) {
            factorial[i] = (factorial[i - 1] * i) % MOD;
        }
        inverse[0] = 1;
        inverse[1] = 1;
        for (int i = 2; i <= upTo; i++) {
            inverse[i] = (MOD - (MOD / i) * inverse[(int)MOD % i] % MOD) % MOD;
        }
        inverseFactorial[0] = inverse[0];
        for (int i = 1; i <= upTo; i++) {
            inverseFactorial[i] = (inverseFactorial[i - 1] * inverse[i]) % MOD;
        }
    }

    private static long modKPermutations(int n, int k) {
        return (factorial[n] * inverseFactorial[n - k]) % MOD;
    }

    private static long modCombinations(int n, int k) {
        return (((factorial[n] * inverseFactorial[k]) % MOD) * inverseFactorial[n - k]) % MOD;
    }

    private static long modPower(int n, int p) {
        if (p == 0) {
            return 1;
        } else if (p % 2 == 1) {
            return (n * modPower(n, p - 1)) % MOD;
        } else {
            long halfPower = modPower(n, p / 2);
            return (halfPower * halfPower) % MOD;
        }
    }

    private static long modRestoreFactorMapToNumber(Map<Integer, Integer> factorMap) {
        long result = 1;
        for (int prime : factorMap.keySet()) {
            result = (result * modPower(prime, factorMap.get(prime))) % MOD;
        }
        return result;
    }

    private static class MapTools {
        public Map<Integer, Integer> subtractCounts(
                Map<Integer, Integer> a, Map<Integer, Integer> b) {

            Map<Integer, Integer> result = new HashMap<>(a);

            for (int bKey : b.keySet()) {
                if (!result.containsKey(bKey)) {
                    throw new RuntimeException("No such key: " + bKey);
                }
                result.put(bKey, result.get(bKey) - b.get(bKey));
            }

            return result;
        }
    }

    private static class Primes {
        private final List<Integer> primes = new ArrayList<>();
        private int primesLimit;

        private final Map<Integer, Map<Integer, Integer>> factorialFactorizationCache = new HashMap<>();
        public Map<Integer, Integer> factorFactorial(int n) {
            return factorialFactorizationCache.computeIfAbsent(n, $ -> {
                calculatePrimesUpTo(n);
                Map<Integer, Integer> result = new HashMap<>();
                for (int p : primes) {
                    if (p > n) break;
                    int count = 0;
                    int pPower = p;
                    while (pPower <= n) {
                        count += n / pPower;
                        pPower *= p;
                    }
                    result.put(p, count);
                }
                return result;
            });
        }

        private void calculatePrimesUpTo(int newLimit) {
            if (newLimit <= primesLimit) return;

            int start = primesLimit + 1;
            if (start <= 2) {
                start = 2;
            }
            for (int i = start; i <= newLimit; i++) {
                if (isPrime(i)) {
                    primes.add(i);
                }
            }

            primesLimit = newLimit;
        }

        private boolean isPrime(int n) {
            for (int p : primes) {
                if (p * p > n) break;
                if (n % p == 0) return false;
            }
            return true;
        }
    }
}


import java.util.*;

public class test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String str = scanner.next(); char a[] = str.toCharArray(); int num = 0;
        for (int i = 0; i < str.length()/2; i ++) if (a[i] != a[str.length() - i - 1]) num++;
        System.out.println((num <= 1)?"YES":"NO");

    }

}


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

public class C {
	static InputStreamReader isr = new InputStreamReader(System.in);
	static BufferedReader br = new BufferedReader(isr);

	static int[] readIntArray() throws IOException {
		String[] v = br.readLine().split(" ");
		int[] ans = new int[v.length];

		for (int i = 0; i < ans.length; i++) {
			ans[i] = Integer.valueOf(v[i]);
		}

		return ans;
	}

	static long c, hr, hb, wr, wb;

	public static void main(String[] args) throws IOException {
		int[] l = readIntArray();
		c = l[0];
		hr = l[1];
		hb = l[2];
		wr = l[3];
		wb = l[4];

		long start = System.currentTimeMillis();

		long ans = 0;
		double rpg = ((double) hr) / wr;
		double bpg = ((double) hb) / wb;
		double maxPerGram = Math.max(rpg, bpg);
		double minPerGram = Math.min(rpg, bpg);
		long maxH = hr;
		long minH = hb;
		long maxW = wr;
		long minW = wb;
		if (rpg < bpg || (hb*wr == hr*wb && wr > wb)) {
			maxH = hb;
			minH = hr;
			maxW = wb;
			minW = wr;
		}

		// 1000000000 3 10 3 11
		// c = 1000, 30/30, 29/29
		ans = (c / maxW) * maxH + ((c % maxW) / minW) * minH;

		if (hb*wr == hr*wb && wr == wb) {
			System.out.println(ans);
			return;
		}

		long usedBetter = (c / maxW);
		long imp = 0;
		double theory = (usedBetter * maxH + (c - usedBetter * maxW) * minPerGram);
		for (long i = usedBetter - 1; i >= 0 && theory > ans; i-=Math.max(((minW - ((c-i*maxW)%minW))/maxW), 1)) {
			theory -= maxH;
			theory += minPerGram * maxW;
			if (theory <= ans) {
				break;
			}

			imp = i * maxH + ((c - i * maxW) / minW) * minH;
			ans = Math.max(ans, imp);
		}

		System.out.println(ans);
//		System.out.println("Time: " + (System.currentTimeMillis() - start));

//		int c = 0;
//		int m = 13;
//		int add = 1325;
//		for (int i = 0; i < 10; i++) {
//			c+=add;
//			System.out.println(c%m);
//		}
	}
}


package com.company;

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int f = sc.nextInt();
        // a + d
        // b + c + d
        int result = 0;

        if (e > f) {
            while (a > 0 && d > 0) {
                a--;
                d--;
                result += e;
            }
            while (b > 0 && c > 0 && d > 0) {
                b--;
                c--;
                d--;
                result += f;
            }
            System.out.println(result);
        } else {
            while (b > 0 && c > 0 && d > 0) {
                b--;
                c--;
                d--;
                result += f;
            }
            while (a > 0 && d > 0) {
                a--;
                d--;
                result += e;
            }
            System.out.println(result);
        }
    }
}


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

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner scan=new Scanner(System.in);
		long n=scan.nextLong();
		long k=scan.nextLong();
		long MOD=1000000007;
		if(n==0){System.out.println(0);}
		long a=(new Num()).pow(2L,k+1);
		long b=(new Num()).pow(2L,k);
		long res=(a*n)%MOD-b+1;
		if(res<0){res+=MOD;}
		System.out.println(res%MOD);
	}
}

class Num{
	long MOD=1000000007;
	long power(long x,long k){
		long base=x;
		long res=1;
		while(k>0){
			if((k&1)==1){
				res=(res*base)%MOD;
			}
			base=(base*base)%MOD;
			k>>=1;
		}
		return res;
	}
}


/**
 * @author Kunal
 *
 */

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

public class D392 {
	public static void main(String[] args) {
		InputReader in = new InputReader();
		PrintWriter out = new PrintWriter(System.out);
		final long start = System.currentTimeMillis();
		new Task1().solve(in, out);
		@SuppressWarnings("unused")
		final long duration = System.currentTimeMillis() - start;
		out.close();
	}

	static class Task1 {
		public void solve(InputReader in, PrintWriter out) {
			long base  = in.nextLong();
			String s = in.next();

			long ans=0, k=0;
			int i=s.length()-1;
			while(i>=0){
				String nums=s.charAt(i)+"";
				Long num=Long.parseLong(s.charAt(i)+""), temp=num;
				//out.print(num+" ");
				int start = i;
				for(int j=--i; j>=0; j--){
					nums=s.charAt(j)+nums;
					temp = Long.parseLong(nums);
					if(temp<base){
						num = temp;
						i--;
					} else {
						break;
					}
				}
				//out.print(num+" ");

				if(i>=0) nums = nums.substring(1);
				//out.println(nums);
				while(nums.length()>0 && nums.charAt(0)=='0'){
					i++;
					nums = nums.substring(1, nums.length());
				}

				ans += expo(base, k++, Long.MAX_VALUE)*num;
			}

			out.println(ans);
		}

		long expo(long a, long b, long MOD){
			long result = 1;
			while (b>0){
				if (b%2==1) result=(result*a)%MOD;
				b>>=1;
				a=(a*a)%MOD;
			}
			return result%MOD;
		}
	}

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

		public InputReader() {
			reader = new BufferedReader(new InputStreamReader(System.in));
			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());
		}

		public String nextLine() {
			String s = null;
			try {
				s = reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return s;
		}

		public String nextParagraph() {
			String line = null;
			String ans = "";
			try {
				while ((line = reader.readLine()) != null) {
					ans += line;
				}
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			return ans;
		}

	}
}


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

import java.math.*;
import java.lang.*;

import static java.lang.Math.*;

public class Cf131 implements Runnable
{
    static class InputReader
    {
        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 InputReader(InputStream stream)
        {
            this.stream = stream;
        }

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

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

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

        public String nextLine()
        {
            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);
        }
    }
    public static void main(String args[]) throws Exception
    {
        new Thread(null, new Cf131(),"Main",1<<27).start();
    }

    static class Pair{
		int nod;
		int ucn;

		Pair(int nod,int ucn){
			this.nod=nod;
			this.ucn=ucn;
		}

	public static Comparator<Pair> wcompr = new Comparator<Pair>(){
		public int compare(Pair e1,Pair e2){
            //reverse order
			if (e1.ucn < e2.ucn)
                return 1;
            else if (e1.ucn > e2.ucn)
                return -1;
            return 0;
		}
	};
	}

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

    public void run()
    {
        InputReader sc = new InputReader(System.in);
        PrintWriter w = new PrintWriter(System.out);

       // int t= sc.nextInt();
       // while(t-->0){
            int x = sc.nextInt();
            int y = sc.nextInt();
            int n = sc.nextInt();
            int m = 1000000007;
            Integer[] a = new Integer[Math.max(3,n+1)]; a[0] = 0; a[1] = x; a[2] = y;
            for(int i=3;i<=n;i++){
                a[i] = a[i-1] - a[i-2];
            }
            w.print((a[n]+m)%m);

       // }
        w.flush();
        w.close();
    }

}


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

public class Main {

    private  static void solver(InputReader sc, PrintWriter out){
        int mod = 1000000007;
        int x = sc.nextInt();
        int y = sc.nextInt();
        int n = sc.nextInt();
        int arr[] = new int[n];
        arr[0] = x;
        arr[1] = y;
        for(int i=2;i<n; i++){
            arr[i] = arr[i-1] - arr[i-2];
            int x1 = arr[i] % mod;
            if(x1 < 0)
                x1 = mod+x1;
            arr[i] = x1;
        }
        int x2 = arr[0] % mod;
        if(x2 < 0)
            x2 = mod+x2;
        arr[0] = x2;
        int y2 = arr[1] % mod;
        if(y2 < 0)
            y2 = mod+y2;
        arr[1] = y2;
        out.println(arr[n-1]);
    }

    public static void main(String[] args) throws Exception{
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);

        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong(){
            return Long.parseLong(next());
        }

        public long[] readLongArr(int n){
            long arr[] = new long[n];
            for(int i=0; i<n; i++){
                arr[i] = nextLong();
            }
            return arr;
        }
        public int[] readIntArr(int n){
            int arr[] = new int[n];
            for(int i=0; i<n; i++){
                arr[i] = nextInt();
            }
            return arr;
        }
    }
}
class Pair{
    long x;
    boolean bool;
    Pair(long x, boolean bool){
        this.x = x;
        this.bool = bool;
    }
}


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

public class A {
    public static void main(String[] args) throws Exception {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        String s=br.readLine();
        String t=br.readLine();
        int si=0,sj=0;
        int ma=0,ct=0;
        while((si<s.length()) && (ti<t.length())) {
            if(s.charAt(si)==t.charAt(ti)) {
                ma=Math.max(ma,ct);
                ti++;
                ct=0;
            }
            else
                ct++;
            si++;
        }
        pw.println(Math.max(ma,ct));
        br.close();
        pw.close();
    }
}


package com.yermak.myclass;

/*
 * Copyright (c) 2015. Vlad Yermakov
 */

import java.util.Scanner;

public class cf426A {

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

    public static void main(String[] args) {

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

        int mx = 0;
        int sum = 0;

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

            int a = in.nextInt();
            if (a > mx) mx = a;
            sum += a;

        }

        if (sum - mx > s) System.out.println("NO\n");
        else System.out.println("YES");

    }

}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStreamWriter;
import java.math.BigDecimal;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.TreeSet;

public final class CF_114_E{
	static boolean verb=true;
	static void log(Object X){if (verb) System.err.println(X);}
	static void log(Object[] X){if (verb) {for (Object U:X) System.err.print(U+" ");System.err.println("");}}
	static void log(int[] X){if (verb) {for (int U:X) System.err.print(U+" ");System.err.println("");}}
	static void logWln(Object X){if (verb) System.err.print(X);}
	static void info(Object o){	System.out.println(o);}
	static void output(Object o){outputWln(""+o+"\n");	}
	static void outputWln(Object o){try {out.write(""+ o);} catch (Exception e) {}}

	static int MX=Integer.MAX_VALUE;

	static boolean solve(long a,long b){
		//log("a:"+a+" b:"+b);
		if (a==0 || b==0)
			return false;
		if (a==b)
			return true;
		if (a>b){
			long c=a;
			a=b;
			b=c;
		}

		long ob=b;
		if (a+1<b/a)
			ob=b%(a*(a+1));
		if (ob!=b) {
			if (ob>0)
			return solve(a,ob);
			ob=a*(a+1);
			return solve(a,ob);
		}
		if (b%a==0)
			return true;
		long aa=1;
		loop:while (aa<=b/a){
			aa*=a;

			if (!solve(b-aa,a))
				return true;
		}
		return false;

	}

	static void check(){
		log("checking");
		for (int x=1;x<100;x++)
			for (int y=3;y<x;y++){
				boolean b=solve(x,y);
				int xx=x%(y*(y+1));
				if (xx!=0){
				boolean c=solve(x%(y*(y+1)),y);
				if (b!=c){
					log("Error "+x+" "+y);
					log(b);
					log(c);
					log(x+" "+y);
					log(x%(y*(y+1))+" "+y);
					return;
				}
				}
			}
		log("done");
	}

	static void test(){
		int y=10;
		for (int x=1;x<200;x++) {
			boolean b=solve(x,y);
			if (!b)
				log(x+" "+y);

		}
		//for (int x=1;x<20;x++)
		//	for (int y=1;y<x;y++)
		//		log(x+" "+y+" >> "+solve(x,y));
	}

	// Global vars
	static BufferedWriter out;
	static InputReader reader;

	static int MAX=201;

	static void process() throws Exception {

		//check();
		//test();

		out = new BufferedWriter(new OutputStreamWriter(System.out));
		reader=new InputReader(System.in);

		int T=reader.readInt();
		for (int t=0;t<T;t++){
		long a=reader.readLong();
		long b=reader.readLong();
		boolean w=solve(a,b);
		String res="Second";
		if (w)
			res="First";
		output(res);
		}

		try {
			out.close();
		}
		catch (Exception e){}

	}

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

	}

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

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

		private int read() throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read(buf);
				if (numChars <= 0) {
					return -1;
				}
			}
			return buf[curChar++];
		}

		public final String readString() throws IOException {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res=new StringBuilder();
			do {
				res.append((char)c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public final int readInt() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

		public final long readLong() throws IOException {
			int c = read();
			boolean neg=false;
			while (isSpaceChar(c)) {
				c = read();
			}
			char d=(char)c;
			//log("d:"+d);
			if (d=='-') {
				neg=true;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			//log("res:"+res);
			if (neg)
				return -res;
			return res;

		}

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

}


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

public class popo {

    public static boolean prime[];
    public static ArrayList[] ad=new ArrayList[2555];
    public static ArrayList<Long> xor1,xor2;
    static int []min;
    static char [][]grid;
    static int []dx = {0,0,-1,1};
    static int []dy = {-1,1,0,0};
    static int []dx8 = {1,1,1,0,-1,-1,-1,0};
    static int []dy8 = {1,0,-1,-1,-1,0,1,1};
    static ArrayList<Point> aa;

    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int t = in.nextInt();
        while (t-->0)
          {
              int a = in.nextInt();
              int b = in.nextInt();
              boolean k =winner(a,b);
              if(k)
                  out.println("First");
              else
                  out.println("Second");

        }

        out.close();
    }
    static boolean winner(int a  ,int b)
    {
        if(a==0 || b==0)
            return false;
        if(a>b)
        {
            int t = a;
            a = b;
            b = t;
        }
        if(!winner(a,b%a))return true;
        int  l =0;
        if(a!=0) {
             l = b / a;
        }
        a = a+1;
        return ((l)%2 == 0);
    }

    public static long modPow(long base, long exp, long mod) {
        base = base % mod;
        long result = 1;
        while(exp > 0)
        {
            if(exp % 2== 1)
            {
                result = (result * base) % mod;
                exp --;
            }
            else
            {
                base = (base * base) % mod;
                exp = exp >> 1;
            }

        }
        return result;
    }

    public static long mod = 1000000007, inf = 100000000000000000l;
    public static long fac[],inv[];
    public static void cal()
    {
        fac = new long[100001];
        inv = new long[100001];
        fac[0]=1;
        inv[0]=1;
        for(int i=1; i<=100000; i++)
        {
            fac[i]=(fac[i-1]*i)%mod;
            //  inv[i]=(inv[i-1]*modPow(i,mod-2,mod))%mod;

        }
    }
    public static long combination(long n, long r)
    {
        long k = (fac[(int) n]%mod*inv[(int) r]%mod)%mod;
        long p = inv[(int) (n-r)]%mod;
        long m = (k*p)%mod;
        return m;
    }

    public static class Point implements Comparable<Point> {

        long x, y;

        public Point(long start, long end) {
            this.x = start;
            this.y = end;
        }

        @Override
        public int hashCode() {
            int hash = 5;
            hash = (int) (47 * hash + this.x);
            hash = (int) (47 * hash + this.y);
            return hash;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final Point other = (Point) obj;
            if (this.x != other.x) {
                return false;
            }
            if (this.y != other.y) {
                return false;
            }
            return true;
        }

        @Override
        public int compareTo(Point o) {
            return Long.compare(x, o.x);
        }
    }
    static long setbits(long i)
    {
        long count = 0;
        while (i>0)
        {
            count += i & 1;
            i >>= 1;
        }
        return count;

    }

    static ArrayList<Long> sieveOfEratosthenes(int n)
    {
        // Create a boolean array "prime[0..n]" and initialize
        // all entries it as true. A value in prime[i] will
        // finally be false if i is Not a prime, else true.

        prime=new boolean[1000001];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(long p = 2; p*p <=n; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if(prime[(int)p] == true)
            {
                // Update all multiples of p
                for(long i = p*2; i <= n; i += p) {
                    prime[(int) i] = false;
                }
            }
        }
        ArrayList<Long> aa=new ArrayList<>();
        for (long i=0;i<n;i++)
        {
            if(prime[(int)i])
                aa.add(i);
        }
        return aa;

        // Print all prime numbers
      /*  for(int i = 2; i <= n; i++)
        {
            if(prime[i] == true)
                System.out.print(i + " ");
        }
       */
    }

    static class InputReader {

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

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

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

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

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

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

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

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

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


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

public class A421 {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        OutputWriter out = new OutputWriter(System.out);
        int c = in.nextInt();
        int v0 = in.nextInt();
        int v1 = in.nextInt();
        int a = in.nextInt();
        int l = in.nextInt();
        int read = 0;
        //process first day
        int days = 1;
        read += v0;
        v0 -= l;
        v1 -= l;
        v0 += a;
        //days with increasing number of pages
        if(a > 0) {
            while(v0 <= v1 && read < c) {
                days++;
                read += v0;
                v0 += a;
            }
        }
        //days with v1 per day
        if(a > 0) v0 = v1;
        if(read < c) {
            days += (c - read - 1) / v0 + 1;
        }
        out.print(days);
        out.close();
    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void println(Object... objects) {
            print(objects);
            writer.println();
        }

        public void printf(String format, Object... objects) {
            writer.printf(format, objects);
        }

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

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

    }

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

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

        public int read() {
            if (this.numChars == -1) {
                throw new InputMismatchException();
            } else {
                if (this.curChar >= this.numChars) {
                    this.curChar = 0;

                    try {
                        this.numChars = this.stream.read(this.buf);
                    } catch (IOException var2) {
                        throw new InputMismatchException();
                    }

                    if (this.numChars <= 0) {
                        return -1;
                    }
                }

                return this.buf[this.curChar++];
            }
        }

        public int nextInt() {
            int c;
            for (c = this.read(); isSpaceChar(c); c = this.read()) {
                ;
            }

            byte sgn = 1;
            if (c == 45) {
                sgn = -1;
                c = this.read();
            }

            int res = 0;

            while (c >= 48 && c <= 57) {
                res *= 10;
                res += c - 48;
                c = this.read();
                if (isSpaceChar(c)) {
                    return res * sgn;
                }
            }

            throw new InputMismatchException();
        }

        public static boolean isSpaceChar(int c) {
            return c == 32 || c == 10 || c == 13 || c == 9 || c == -1;
        }

    }
}


	import java.util.Scanner;

	public class stairs {

		public static void main(String[] args) {
			// banger of all bangers
			Scanner scan = new Scanner(System.in);
			int a = scan.nextInt();
			int b = scan.nextInt();
			if (a+b==0){System.out.print("NO");}
			while(a+b!=0){if(a == b - 1 || 1 == a - b || a == b){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}

		}
	}
}


import java.io.*;
import java.util.Scanner;
import java.util.Arrays;
import java.util.Collections;
import java.lang.Math;
import java.util.ArrayList;
import java.util.*;
import java.math.*;

public class funky{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		ArrayList<Integer> arr = new ArrayList<Integer>(100000000);

		for(int i = 1;i < 100000000;i++){
			int s = i*(i+1) / 2;
			if(s < 1000000000){
				arr.add(s);
			}
			else{
				break;
			}
		}

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

			if(arr.get(i) > n){
				break;
			}

			else{
				int r = n - arr.get(i);
				if(Collections.binarySearch(arr, r) > 0){
					System.out.println("YES");
					System.exit(0);
				}
			}
		}

		System.out.println("NO");

	}
}


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

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

    static class TaskD {
        int[] primes;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int a = in.nextInt(), b = in.nextInt(), k = in.nextInt();
            primes = PrimesAndDivisors.generatePrimes(k - 1);
            int ans = PrimesAndDivisors.isPrime(k) ? f(b, k) - f(a - 1, k) : 0;
            out.println(ans);
        }

        int f(int n, int k) {
            if (k > n) return 0;
            if ((long) k * k > n) return 1;
            int ans = generate(0, 1, n / k);
            return ans;
        }

        int generate(int pos, int now, int lim) {
            long ans = lim / now;
            for (int i = pos; i < primes.length && (long) Math.abs(now) * primes[i] <= lim; i++)
                ans += generate(i + 1, -now * primes[i], lim);
            return (int) ans;
        }

    }

    static class PrimesAndDivisors {
        public static int[] generatePrimes(int n) {
            boolean[] sieve = new boolean[n + 1];
            Arrays.fill(sieve, 2, n + 1, true);
            for (int i = 2; i * i <= n; i++)
                if (sieve[i])
                    for (int j = i * i; j <= n; j += i)
                        sieve[j] = false;
            int[] primes = new int[n + 1];
            int cnt = 0;
            for (int i = 0; i < sieve.length; i++)
                if (sieve[i])
                    primes[cnt++] = i;

            return Arrays.copyOf(primes, cnt);
        }

        public static boolean isPrime(long n) {
            if (n <= 1)
                return false;
            for (long i = 2; i * i <= n; i++)
                if (n % i == 0)
                    return false;
            return true;
        }

    }

    static class OutputWriter extends PrintWriter {
        public OutputWriter(OutputStream outputStream) {
            super(new BufferedOutputStream(outputStream));
        }

        public OutputWriter(Writer writer) {
            super(writer);
        }

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

    }

    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader(InputStream inputStream) {
            br = new BufferedReader(new InputStreamReader(inputStream));
        }

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

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

        public String nextLine() {
            try {
                return br.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

    }
}


import java.io.*;
import java.util.*;
public class D83 {
	static int max;
	static int[][] grid;
	static int[] primes;
	static int gridLength = 10000;
	static int numPrimes = 5000;
	public static void main(String[] args) throws IOException	{
		primes = new int[numPrimes];
		int c = 1;
		primes[0] = 2;
		for(int i = 3; c < primes.length; i += 2)
			if(prime(i))
				primes[c++] = i;
		System.out.print(primes[numPrimes-1]);
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		max = Integer.parseInt(st.nextToken());
		grid = new int[gridLength][numPrimes];
		for(int i = 0; i < grid.length; i++)
			Arrays.fill(grid[i], -1);
		if(!prime(max))	{
			System.out.println(0);
			return;
		}
		System.out.println(compute(b/max, 0) - compute((a-1)/max, 0));
	}
	public static boolean prime(int x)	{
		if(x==1)
			return false;
		if(x<=3)
			return true;
		if(x%2==0 || x%3==0)
			return false;
		for(int d = 5; d * d <= x; d += 6)
			if(x%d==0)
				return false;
		for(int d = 7; d * d <= x; d += 6)
			if(x%d==0)
				return false;
		return true;
	}
	public static int compute(int num, int p)	{
		if(primes[p] >= max || num <= 1)
			return num;
		if(num / primes[p] == 0)
			return num;
		if(num < gridLength && p < numPrimes && grid[num][p] != -1)
			return grid[num][p];
		int ret = compute(num,p+1) - compute(num/primes[p],p+1);
		if(num < gridLength && p < numPrimes)
			grid[num][p] = ret;
		return ret;
	}
}


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

public class D {

	long go1(long n, long s, long k) {

		// no overeating
		long ans1 = -1;
		for (long c2 = n; c2 >= 0; c2--) {
			long full = n + c2;

			long last = k % full;
			if (last == 0) {
				last = full;
			}

			long last2 = last - s;
			long rest2 = c2 - last2;

			if (!(0 <= last2 && last2 <= s && 0 <= rest2 && rest2 <= n - s)) {
				continue;
			}

			ans1 = c2;
			break;
		}

		long ans2 = -1;
		// overeating!
		for (long c2 = n; c2 > 0; c2--) {
			long full = n + c2;

			long last = (k + 1) % full;
			if (last == 0) {
				last = full;
			}

			long last2 = last - s;
			long rest2 = c2 - last2;

			if (!(0 <= last2 && last2 <= s && 0 <= rest2 && rest2 <= n - s)) {
				continue;
			}

			if (last2 == 0) {
				continue;
			}

			ans2 = c2;
			break;
		}

		return Math.max(ans1, ans2);
	}

	void submit() {
		long n = nextLong();
		long l = nextLong();
		long r = nextLong();
		long k = nextLong();

		long s;
		if (l <= r) {
			s = r - l + 1;
		} else {
			s = r - l + 1 + n;
		}

		out.println(go1(n, s, k));

//		if (n <= C) {
//			out.println(go1(n, s, k));
//		} else {
//			out.println(go2(n, s, k));
//		}
	}

	void test() {

	}

	void stress() {
		for (int tst = 0;; tst++) {
			if (false) {
				throw new AssertionError();
			}
			System.err.println(tst);
		}
	}

	D() throws IOException {
		is = System.in;
		out = new PrintWriter(System.out);
		submit();
		// stress();
		// test();
		out.close();
	}

	static final Random rng = new Random();
	static final int C = 10_000_000;

	static int rand(int l, int r) {
		return l + rng.nextInt(r - l + 1);
	}

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

	private InputStream is;
	PrintWriter out;

	private byte[] buf = new byte[1 << 14];
	private int bufSz = 0, bufPtr = 0;

	private int readByte() {
		if (bufSz == -1)
			throw new RuntimeException("Reading past EOF");
		if (bufPtr >= bufSz) {
			bufPtr = 0;
			try {
				bufSz = is.read(buf);
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
			if (bufSz <= 0)
				return -1;
		}
		return buf[bufPtr++];
	}

	private boolean isTrash(int c) {
		return c < 33 || c > 126;
	}

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

	String nextToken() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	String nextString() {
		int b = readByte();
		StringBuilder sb = new StringBuilder();
		while (!isTrash(b) || b == ' ') {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

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

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

	int nextInt() {
		int ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}

	long nextLong() {
		long ret = 0;
		int b = skip();
		if (b != '-' && (b < '0' || b > '9')) {
			throw new InputMismatchException();
		}
		boolean neg = false;
		if (b == '-') {
			neg = true;
			b = readByte();
		}
		while (true) {
			if (b >= '0' && b <= '9') {
				ret = ret * 10 + (b - '0');
			} else {
				if (b != -1 && !isTrash(b)) {
					throw new InputMismatchException();
				}
				return neg ? -ret : ret;
			}
			b = readByte();
		}
	}
}


import java.util.*;

public class Main
{
  public static void main(String args[])
  {
    Scanner s=new Scanner(System.in);
    int n=s.nextInt();
    int a=s.nextInt();
    int b=s.nextInt();
    int c=s.nextInt();
    int i,j,k;
    int res=0;
    for (i = 0; i <= c; i++) {
        for (j = 0; j <= b; j++) {
            int k = 2*n - 4*i - 2*j;
            if (0 <= k && k <= a) res++;
        }
        }
    System.out.println(res);
    }
}


// -*- coding: utf-8 -*-
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.StringTokenizer;

public class Main {
  public static void main(String[] args) {
    InputStream inputStream;
    if (args.length > 0 && args[0].equals("devTesting")) {
      try {
        inputStream = new FileInputStream(args[1]);
      } catch(FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      inputStream = System.in;
    }
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    PrintWriter out = new PrintWriter(outputStream);
    TaskD solver = new TaskD();
    solver.solve(1, in, out);
    out.close();
  }

  static class TaskD {
    final int ring = (int) 1e9 + 7;
    final int limit = 20;
    int n;
    String s;
    int[][][] state;
    boolean[] ss;

    void solve(int testNumber, InputReader in, PrintWriter out) {
        n = in.nextInt();
        s = in.next();
        ss = new boolean[n];
        for (int i = 0; i < n; ++i) {
          ss[i] = s.charAt(i) == '0' ? false : true;
        }
        state = new int[2][n + 1][1 << limit];
        for (int[][] i : state) {
          for (int[] j : i) {
            Arrays.fill(j, -1);
          }
        }
        long ans = 0;
        for (int j = 0; j < n; ++j) {
          ans = add(ans, go(0, j, 0));
        }
        out.println(ans);
    }

    long go(int k, int p, int m) {
        if (state[k][p][m] != -1) {
            return state[k][p][m];
        }
        if (p >= n) {
            return 0;
        }
        if (k == 1) {
          return 0;
        }
        long ans = 0;
        for (int i = p; i <= n - 1; ++i) {
            int x;
            int newm = m;
            int inc = 0;
            x = read(p, i);
            if (x > limit) {
                break;
            }
            if (x == 0) {
                continue;
            }
            newm |= 1 << (x - 1);
            if (Integer.bitCount(newm + 1) == 1) {
              ++inc;
            }
            ans = add(ans, go(k, i + 1, newm) + inc);
        }
        state[k][p][m] = (int) ans;
        return ans;
    }

    long add(long a, long b) {
        long ans = (a + b) % ring;
        if (ans < 0) {
            ans += ring;
        }
        return ans;
    }

    int read(int l, int r) {
      int ans = 0;
      for (int i = l; i <= r; ++i) {
        ans |= (ss[i] ? 1 : 0) << (r - i);
      }
      return ans;
    }

    int i(long x) {
      return (int) x;
    }

    <T> void heapsort(T[] a, int s, int e) {
      Queue<T> queue = new PriorityQueue<>();
      for (int i = s; i <= e; ++i)
        queue.add(a[i]);
      for (int i = s; i <= e; ++i)
        a[i] = queue.poll();
    }

  }

  static 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 String nextLine() {
      try {
        return reader.readLine();
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

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

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

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

    public boolean hasInput() {
      try {
        if (tokenizer != null && tokenizer.hasMoreTokens()) {
          return true;
        }
        reader.mark(1);
        int ch = reader.read();
        if (ch != -1) {
          reader.reset();
          return true;
        }
        return false;
      } catch(IOException e) {
        throw new RuntimeException(e);
      }
    }

  }
}


import java.io.BufferedReader;
import java.io.FileReader;
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 D {
	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		s = sc.nextLine().toCharArray();

		dp = new long[n][(1 << 20) + 1];
		for(int i = 0; i < n; i++)
			Arrays.fill(dp[i], -1);
		long ans = 0;
		for(int i = 0; i < n; i++)
			ans = (ans + solve(i, 0)) % mod;
		System.out.println(ans);

		PrintWriter out = new PrintWriter(System.out);

		out.flush();
		out.close();
	}
	static int n;
	static char[] s;
	static int mod = (int) 1e9 + 7;

	static long dp[][];
	static long solve(int i, int mask) {
		if(i == n) {
			return (mask & (mask + 1)) == 0 && mask != 0? 1 : 0;
		}

		if(dp[i][mask] != -1)
			return dp[i][mask];

		long result = (mask & (mask + 1)) == 0 && mask != 0? 1 : 0;

		int num = 0;
		for(int j = i; j < n; j++) {
			num *= 2;
			num += s[j] - '0';
			if(num > 20)
				break;
			if(num > 0)
				result += solve(j + 1, mask | (1 << (num - 1)));
			result %= mod;
		}

		return dp[i][mask] = result;
	}
	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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


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

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

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

    void solve() {
        int n = in.nextInt();
        char[] s = in.nextToken().toCharArray();
        int[] b = new int[n];
        for (int i = 0; i < n; i++) b[i] = s[i] - '0';

        long[][] dp = new long[n + 1][1 << 20];

        for (int i = 0; i < n; i++) dp[i][0] = 1;

        long ans = 0;
        for (int i = 0; i <= n; i++) {
            for (int mask = 0; mask < 1 << 20; mask++) {
                if (dp[i][mask] > 0) {
                    int x = mask + 1;
                    if (mask > 0 && x - (x & -x) == 0) ans = (ans + dp[i][mask]) % MOD;
                    int v = 0;
                    for (int j = i + 1; j <= n; j++) {
                        v <<= 1;
                        v += b[j - 1];
                        if (v > 20) break;
                        if (v > 0) {
                            int nmask = mask | 1 << (v - 1);
                            dp[j][nmask] = (dp[j][nmask] + dp[i][mask]) % MOD;
                        }
                    }
                }
            }
        }

        out.println(ans);
    }

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

    static FastScanner in;
    static PrintWriter out;

    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;

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

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

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

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

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


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

public class Problem {

    public static int mod = (int) (1e9+7);
    public static long[][] dp;
    public static int max=20;
    public static char[] s;
    public static int n;
    public static int k;

    public static long solve(int n,int mask){

        if(n<0) return (mask>0 && ((mask&(mask+1))==0))?1:0;
        if(dp[n][mask]!=-1) return dp[n][mask];
        long ans=0;
        int p=1;
        int num=0;
        if(mask>0 && ((mask&(mask+1))==0)) ans++;

        for(int i=1;i<=n+1;i++){
            num+=p*((int)(s[n-i+1]-'0'));
            if(num>max) break;
            p*=2;
            if(num>0 && num<=max){
                ans=(ans+solve(n-i, mask|(1<<(num-1))))%mod;
            }
        }
        //debug(ans,mask,n);
        return dp[n][mask]=ans;
    }

    public static void main(String[] args) {

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

        n=in.nextInt();
        s=in.readString().toCharArray();
        dp=new long[n][(1<<max)];
        for(int i=0;i<n;i++) Arrays.fill(dp[i], -1);
        long ans=0;

        for(int i=0;i<n;i++){
            ans=(ans+solve(i, 0))%mod;
        }
        out.println(ans);

        out.close();
    }

    static class Pair implements Comparable<Pair>{

        String s;
        String x;
        int i;

        public Pair(String s,String x,int i) {
            this.s=s;
            this.x=x;
            this.i=i;
        }

	public int compareTo(Pair o) {
            return this.s.compareTo(o.s);
        }

    }

    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(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 pow(long n,long p,long m){
	 long  result = 1;
	  if(p==0)
	    return 1;
	if (p==1)
	    return n;
	while(p!=0)
	{
	    if(p%2==1)
	        result *= n;
	    if(result>=m)
	    result%=m;
	    p >>=1;
	    n*=n;
	    if(n>=m)
	    n%=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;
    }
    public static void debug(Object... o) {
		System.out.println(Arrays.deepToString(o));
	}
	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] = nextLong();
			}
			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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static int n ;
    static int arr [];
    static int num [][]; // num[i][j] = number from arr[i] - > arr[j]
    static int mod = (int)1e9 + 7;
    static int memo [][][];
    static int dp (int last_cut_idx , int cur_idx , int done) { // dp[i][k][j] = number of ways to get a valid set if the last cut was at last and cur is at idx i and numbers done are done
        if (cur_idx == n + 1) {
            int cnt_done = Integer.bitCount(done);
            if (cnt_done != 0 && (1 << cnt_done) - 1 == done)
                return 1;
            else
                return 0;
        }

        if (memo[last_cut_idx][cur_idx][done] != - 1) return memo[last_cut_idx][cur_idx][done];

        int cut_here = 0;
        if (num[last_cut_idx][cur_idx - 1] != 0 && num[last_cut_idx][cur_idx - 1] <= 20)
            cut_here = dp(cur_idx , cur_idx + 1 , done | (1 << (num[last_cut_idx][cur_idx - 1] - 1)));

        int dont = dp(last_cut_idx , cur_idx + 1 , done);
        return memo[last_cut_idx][cur_idx][done] = (cut_here + dont) % mod;
    }
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);

        n = sc.nextInt();
        char [] a = sc.next().toCharArray();
        arr = new int[n];
        for (int i = 0 ; i < n ; ++ i)
            arr[i] = a[i] - '0';

        num = new int[n][n];
        for (int i = 0 ; i < n ; ++ i)
            for (int j = i ; j < n ; ++ j) {
                String curNum = "" ;
                for (int k = i ; k <= j ; ++ k)
                    curNum += arr[k];
                num[i][j] = Integer.parseInt(curNum , 2);
            }

        memo = new int[n][n + 1][(1 << 20) + 1];
        for (int i = 0 ; i < n ; ++ i)
            for (int j = i + 1 ; j <= n ; ++ j)
                Arrays.fill(memo[i][j] , - 1);

        int res = 0 ;
        for (int i = 0 ; i < n ; ++ i)
            res = (res + dp(i , i + 1 , 0)) % mod;

        out.println(res);
        out.flush();
        out.close();
    }

    static class Scanner {
        StringTokenizer st;
        BufferedReader br;

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

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

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

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

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

        public double nextDouble() throws IOException {
            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.*;
import java.io.*;

public class Main {
	static InputReader in = new InputReader(System.in);
	static long powers[] = new long[22];
	public static void main(String args[]) {
		int n = in.readInt();
		String s=in.readString();
		long dp[][]=new long[n][1<<20];
		for(int i=0;i<n;i++) {
			int b=0;
			for(int j=i;j>=0;j--) {
				b+=(s.charAt(j)-'0')<<(i-j);
				if(b>20) break;
				if(b>0)
					dp[i][1<<(b-1)]++;
			}
		}
		for(int i=0;i<n;i++) {
			int b=0;
			for(int j=i;j>=0;j--) {
				b+=(s.charAt(j)-'0')<<(i-j);
				if(b>20) break;
				if(b==0) continue;
				for(int k=0;k<1<<20;k++) {
					if(j==0);
					else {
						int o=1<<(b-1);
						dp[i][k|o]+=dp[j-1][k];
						if(dp[i][k|o]>=1000000007)
							dp[i][k|o]-=1000000007;
					}
				}
			}
		}
		long ans=0;
		for(int i=0;i<n;i++) {
			for(int k=0;k<1<<20;k++) {
				if(((k+1)&k)==0) {
					ans+=dp[i][k];
					if(ans>=1000000007)
						ans-=1000000007;

				}
			}
		}
		System.out.println(ans);
	}
}
	/*
class dir{
	boolean l,r,u,d;
}
class Node extends ArrayList<Node>{

	private static final long serialVersionUID = 1L;
	double x,y;
	int i;
	boolean visited=false;
	Node(int x,int y,int i){
		this.x = x;
		this.y = y;
		this.i=i;
	}
	void reset(){
		visited = false;
	}
	boolean dfs(dir d,double mid,double w,double h,double [][]dists,double cmpr){
		visited = true;
		if(x+mid>=w)
			d.r=true;
		if(x-mid<=0.0)
			d.l=true;
		if(y+mid>=h)
			d.u=true;
		if(y-mid<=0.0)
			d.d=true;
		if((d.l && d.d) || (d.u && d.r)
				|| (d.l && d.r) || (d.u && d.d)) {
			return true;
		}
		for(Node n : this) {
			if(!n.visited) {
				boolean fl=false;
				if(dists[i][n.i]<=cmpr)
					fl|=n.dfs(d,mid,w,h,dists,cmpr);
				if(fl) return fl;
			}
		}
		return false;
	}
	double dist(Node n1,Node n2) {
		return sq(n1.x-n2.x)+sq(n1.y-n2.y);
	}
	double sq(double a) {
		return a*a;
	}
}
class ChristmasBinaryTree{
    public int count(long d, int[] left, int[] right) {
    	int n = left.length;
    	int dp[][][]=new int[120][120][64];
    	for(int i=0;i<n;i++) {
    		dp[i][left[i]][0]=1;
    		dp[i][right[i]][0]=1;
    	}
    	while(d>0) {
    		long k=0;
    		for(;1<<k<=d;k++) {
    			for(int i=0;i<n;i++) {
    				for(int j=0;j<n;j++) {
    					for(int l=0;l<n;l++) {
    						dp[i][l][(int)k+1]+=
    								dp[i][j][(int)k]*dp[j][l][(int)k];

    					}
    				}
    			}
    		}
        	int ndp[][][]=new int[120][120][64];
    		for(int i=0;i<n;i++) {
    			for(int j=0;j<n;j++) {
    				ndp[i][j][0]=dp[i][j][(int)k];
    			}
    		}
    		dp=ndp;
    		d-=1<<(k-1);
    	}
    	int cn=0;
    	for(int i=0;i<n;i++) {
    		for(int j=0;j<n;j++) {
    			cn+=dp[i][j][0]*dp[i][j][0];
    		}
    	}
    	return cn;
    }
}
/*
public class Main {
	private static InputReader in = new InputReader(System.in);
	public static void main(String args[]) {
		StringBuilder s = new StringBuilder();
		int t = in.readInt();
		while(t>0) {

			t--;
		}
		System.out.println(s);
	}

	/*public static int solve(String s, int i,int j,
    		int dp[][],boolean visited[][]) {
    	if(i>j) return 0;
    	if(i==j) return dp[i][j]=1;
    	if(visited[i][j]) return dp[i][j];
    	visited[i][j]=true;
    	solve(s,i+1,j,dp,visited);
    	solve(s,i,j-1,dp,visited);
    	if(s.charAt(i)==s.charAt(j)) {
    		if(i+1==j)
    			return dp[i][j]=2;
    		else {
    			return dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1]+1;
    		}
    	}else {
    		if(i+1==j) return dp[i][j]=1;
    		return dp[i][j]=dp[i+1][j]+dp[i][j-1]-dp[i+1][j-1];
    	}
    }*/
	/*
    public static void main(String args[]) {
    	int t = in.nextInt();
    	while(t>0) {
    		int m = in.nextInt(), n = in.nextInt();
    		long p = in.nextLong();
    		long dp[][][]=new long[11][300][300];

    		for(int i=1;i<=m;i++)
    			dp[1][i][i]=1;
    		for(int i=1;i<n;i++) {
    			for(int j=1;j<m;j++) {
    				for(int k=1;k<=j;k++) {
    					for(int l=k;l>=1;l--) {
    						if(j+l<=m)
    							dp[i+1][j+l][l]+=dp[i][j][k];
    					}
    				}
    			}
    		}
    		System.out.println(dp[n][m-1][2]);
    		for(int i=n;i>0;i--) {
    			for(int j=1;j<=m;j++) {
    				if(dp[i][m-j][j]>=p) {
    					//System.out.print(j+" ");
    					m-=j;
    					break;
    				}else {
    					p-=dp[i][m-j][j];
    					System.out.print(p+" ");
    				}
    			}
    		}
    		System.out.println();
    		t--;
    	}

    }*/

class sh implements Comparable<sh>{
	int h,w,i;
	sh(int a,int b,int c){
		w=a;
		h=b;
		i=c;
	}
	@Override
	public int compareTo(sh o) {
		if(w==o.w) return h-o.h;
		return w-o.w;
	}

}

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 byte read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

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

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			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);
	}
}

class IOUtils {

	public static int[] readIntArray(InputReader in, int size) {
		int[] array = new int[size];
		for (int i = 0; i < size; i++)
			array[i] = in.readInt();
		return array;
	}
}


import com.sun.deploy.util.ArrayUtil;

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

public class Main {
    static int  n;
    static int m;
    static int[]a;
    static int start;
    static int end;
    static int ans;
    public static void main(String[] args) throws Exception
    {
        Scanner in = new Scanner(System.in);
        OutputWriter out = new OutputWriter(System.out);
         n  = in.nextInt();
        a = new int[n];
         m = in.nextInt();
        for (int i =0;i<n;i++)
            a[i]=in.nextInt();
       Arrays.sort(a);
      reverse(a);
       ans=-1;
       binarySearch();
       out.printLine(ans);
        out.flush();
    }
    static void reverse(int[]array)
    {
        for(int i=0; i<array.length/2; i++){ int temp = array[i]; array[i] = array[array.length -i -1]; array[array.length -i -1] = temp; }

    }
    static void binarySearch()
    {
         start = 1;
         end = n;
        while (end>start)
        {
            int mid = (end+start)/2;
            if (f(mid))
            {
                ans=mid;
                end=mid-1;
            }
            else
                start=mid+1;
        }

    }
    static boolean f(int y)
    {
        int ans=0;
        for (int i=0;i<n;i++)
            ans+=Math.max(0,a[i]-i/y);
        if (ans>=m)
            return true;
        return false;
    }
    static void MergeSort(int[] a, int p, int r)
    {
        if (p < r)
        {
            int q = (r + p) / 2;
            MergeSort(a,   p, q);
            MergeSort(a,  q + 1, r);
            Merge(a,  p, q, r);
        }
    }
    static void Merge(int[] a,int p, int q, int r)
    {
        int n1 = q - p + 1;
        int n2 = r - q;
        int[] R = new int[n1 + 1];
        int[] L = new int[n2 + 1];

        for (int i = 0; i < n1; i++)
        {
            R[i] = a[p + i];

        }
        R[n1] = Integer.MAX_VALUE;
        for (int i = 0; i < n2; i++)
        {
            L[i] = a[q + i + 1];

        }
        L[n2] =Integer.MAX_VALUE;
        int n = a.length;
        int j = 0;
        int k = 0;
        for (int i = p; i <= r; i++)
        {
            if (L[j] < R[k])
            {
                a[i] = L[j];

                j++;
            }
            else
            {
                a[i] = R[k];

                k++;
            }

        }
    }
}
class Graph {

    int n;
    ArrayList<Integer>[] adjList;

    public Graph(int n) {
        this.n = n;
        adjList = new ArrayList[n];
        for (int i = 0; i < n; i++)
            adjList[i] = new ArrayList<>();
    }

}
class pair  implements Comparable
{

    int key;
    int value;
    int id;
    public pair(Object key, Object value,Object id) {

        this.key = (int)key;
        this.value=(int)value;
        this.id=(int)id;
    }

    @Override
    public int compareTo(Object o) {
        pair temp =(pair)o;
        if (key!=temp.key)
            return  key-temp.key;
        else return id-temp.id;
    }
}
class Scanner {

    StringTokenizer st;
    BufferedReader br;

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

    public Scanner (FileReader f) {
        br = new BufferedReader(f);
    }

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

    public boolean nextEmpty() throws IOException {
        String s = nextLine();
        st = new StringTokenizer(s);
        return s.isEmpty();
    }
}
class OutputWriter {
    private final PrintWriter writer;

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

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

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

    public void printLine(Object... objects) {
        print(objects);
        writer.println();
    }

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

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

}


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

public class DoubleCola {

    public static void main(String[] args) {
           ArrayList<String> names = new ArrayList<String>();
           Scanner in = new Scanner(System.in);
           int n = in.nextInt();
           String s = "Sheldon";
           String l = "Leonard";
           String p= "Penny";
           String r ="Rajesh";
           String h = "Howard";
           names.add(s);
           names.add(l);
           names.add(p);
           names.add(r);
           names.add(h);
           for(int i=0;i<n;i++){
               names.add(names.get(i));
               names.add(names.get(i));
           }

           System.out.print(names.get(n-1));

    }

}