import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;

import ak.goodstuff.NestedLoops;
import ak.goodstuff.NestedLoops.Callback;

public class E {

    static int MAX_BITS=24;

    static int bit_cnt(int i) {
        int ret=0;
        while(i>0) {
            ret++;
            i-=Integer.highestOneBit(i);
        }
        return ret;
    }

    String to_key(int[] q) {
        StringBuilder sb=new StringBuilder();
        for (int i=0; i<q.length; i++) {
            sb.append("/"+(ccnt[i]+"-"+q[i]));
        }
        return sb.toString();
    }

    int max(int[] q) {
        for (int i=q.length-1; i>=0; i--) {
            if(q[i]>0) {
                return i;
            }
        }
        return -1;
    }

    int cnt(int[] q) {
        int ret=0;
        for (int i=0; i<q.length; i++) {
            if(q[i]>0) {
                ret++;
            }
        }
        return ret;
    }

    int sum(int[] q) {
        int ret=0;
        for (int i=0; i<q.length; i++) {
            ret+=q[i];
        }
        return ret;
    }

    int N;
    int[] ccnt;
    HashMap<String, Integer> memo=new HashMap<String, Integer>();

    int max_trees(final int[] q) {
        String key=to_key(q);
        if(memo.containsKey(key)) {
            return memo.get(key);
        }

        int set_size=cnt(q);
        if(set_size==0) {
            return 0;
        } else if (set_size==1) {
            int i=max(q);
            int ret=ccnt[i]==1? q[i]: 0;
            return ret;
        }

        final int root=max(q);
        if(ccnt[root]>sum(q)) {
            return 0;
        }
        q[root]--;

        int[] from=new int[N], to=new int[N];
        final int[] new_q1=new int[N], new_q2=new int[N];

        for (int i=0; i<N; i++) {
            to[i]=q[i];
        }

        final int[] ret=new int[1];
        NestedLoops.loop(from, to, new Callback() {
            @Override
            public boolean callback(int[] values) {
                if(sum(values)==ccnt[root]-1) {
                    for (int i=0; i<N; i++) {
                        new_q1[i]=values[i];
                        new_q2[i]=q[i]-values[i];
                    }
                    int tcnt1=max_trees(new_q1);
                    int tcnt2=max_trees(new_q2);
                    if((sum(new_q1)==0||tcnt1>1)&&(sum(new_q2)==0||tcnt2>0)/*valid subtree?*/) {
                        if(ret[0]<tcnt2+1) {
                            ret[0]=tcnt2+1;
                            if(ret[0]>1) {
                                return false;
                            }
                        }
                    }
                }
                return true;
            }
        });
        memo.put(key, ret[0]);
        return ret[0];
    }

    boolean solve(int[] ccnt) {
        Arrays.sort(ccnt);
        HashMap<Integer, Integer> remap=new HashMap<Integer, Integer>();
        for (int i=0; i<ccnt.length; i++) {
            if(!remap.containsKey(ccnt[i])) {
                remap.put(ccnt[i], remap.size());
            }
        }
        N=remap.size();

        this.ccnt=new int[N];
        for (int i=0; i<ccnt.length; i++) {
            this.ccnt[remap.get(ccnt[i])]=ccnt[i];
        }
        int[] q=new int[N];
        for (int i=0; i<ccnt.length; i++) {
            int j=remap.get(ccnt[i]);
            q[j]++;
        }

        //System.out.println(Arrays.toString(ccnt));
        if(sum(q)!=this.ccnt[N-1]) {
            return false;
        } else {
            q[N-1]--;
            boolean ret=max_trees(q)>=2;
            return ret;
        }
    }

    static StringBuilder sb=new StringBuilder();
    static void parse(String l, int[] here) {
        sb.setLength(0);
        int len=l.length(), j=0;
        for (int i=0; i<len; i++) {
            char c=l.charAt(i);
            if(c==' ') {
                here[j++]=Integer.parseInt(sb.toString());
                sb.setLength(0);
            } else {
                sb.append(c);
            }
        }
        if(sb.length()>0) {
            here[j++]=Integer.parseInt(sb.toString());
        }
    }

    static void run_stream(InputStream ins) throws IOException {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        int N=Integer.parseInt(br.readLine());
        int[] ccnt=new int[N];
        parse(br.readLine(), ccnt);

        E e=new E();
        long t0=System.currentTimeMillis();
        boolean ret=e.solve(ccnt);
        System.out.println(ret? "YES": "NO");
        //System.out.println(System.currentTimeMillis()-t0);
    }

    public static void main(String[] args) throws IOException {
        run_stream(System.in);
    }

}


package NumberGame;
import java.util.Scanner;
import java.lang.Math;
public class NumberGame {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner input = new Scanner(System.in);
		int [] n = new int[3];
		int m;
		m = input.nextInt();
		for (int i=0;i<m;i++)
			n[i] = input.nextInt();
		if (m==1){
			if(n[0]>0)
				System.out.println("BitLGM");
			else
				System.out.println("BitAryo");
		}
		else if (m==3){
			if ((n[0] ^ n[1] ^ n[2] )!= 0)
				System.out.println("BitLGM");
			else
				System.out.println("BitAryo");

		}
		else{
			int [][] result = new int[300][300];
			for (int i=0;i<=n[0];i++)
				for(int j=0;j<=n[1];j++){
					result[i][j]=2;
					for (int k=0;k<i;k++)
						if (result[k][j]==2)
							result[i][j]=1;
					for (int k=0;k<j;k++)
						if (result[i][k]==2)
							result[i][j]=1;
					for (int k=1;k<=Math.min(i, j);k++)
						if (result[i-k][j-k]==2)
							result[i][k]=1;

				}
			if ( result[n[0]][n[1]] ==1)
				System.out.println("BitLGM");
			else
				System.out.println("BitAryo");
		}

	}

}


import java.util.*;

public class Difference {
  public static void main(String[] args) {
    Scanner in = new Scanner(System.in);
    int n = in.nextInt();
    ArrayList<Integer> list = new ArrayList();
    for(int i = 0; i < n; i++) {
      list.add(in.nextInt());
    }
    Collections.sort(list);
    System.out.print(list.get(n-1)+ " ");
    for(int i = 1; i < n - 1 0; i++) System.out.print(list.get(i) + " ");
    System.out.print(list.get(0));
  }
}


import java.util.Scanner;

public class ChessForThree {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(); //number of games

        // 0 -> spectator
        // 1 -> player/loser
        // 2 -> winner

        int alex = 1;
        int bob = 1;
        int carl = 0;

        int winner = 0;

        for (int i = 0; i < n; i++) {
            winner = sc.nextInt();
            switch (winner) {
                case 1:
                    if (alex == 0) {    //alex was spectator
                        System.out.println("NO");
                        System.exit(1);
                    } else {
                        alex = 2;        //alex is winner
                        if (bob == 0) {  //switch players
                            bob = 1;
                            carl = 0;
                        } else if (carl == 0) {
                            bob = 0;
                            carl = 1;
                        }
                    }
                    break;
                case 2:
                    if (bob == 0) {
                        System.out.println("NO");
                        System.exit(1);
                    } else {
                        bob = 2;
                        if (alex == 0) {
                            alex = 1;
                            carl = 0;
                        } else if (carl == 0) {
                            alex = 0;
                            carl = 1;
                        }
                    }
                    break;
                case 3:
                    if (carl == 0) {
                        System.out.println("NO");
                        System.exit(1);
                    } else {
                        carl = 2;
                        if (alex == 0) {
                            alex = 1;
                            bob = 0;
                        } else if (bob == 0) {
                            alex = 0;
                            bob = 1;
                        }
                    }
                    break;
            }
        }
        System.out.println("YES");
        sc.close();
    }
}


import java.util.Scanner;

public class solution{
    public static void main(String argc[]){
        Scanner sc = new Scanner(System.in);
        int x = sc.nextInt();
        int n = sc.nextInt();

        System.out.println((x-n)%2==1)?"No":"Yes");
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;

public class Worms_Evolution {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		Scanner scn = new Scanner(System.in);
		int l=scn.nextInt();
		int b=scn.nextInt();
		int r=scn.nextInt();

		if(2*r>l && 2*r>b){
			System.out.println("Second");
		}
		else{
			System.out.println("First");
		}
	}
}


import java.awt.*;
import java.io.*;
import java.io.IOException;
import java.util.*;
import java.text.DecimalFormat;

public class Exam {
	public static long mod = (long)Math.pow(10, 9)+7 ;
	public static double epsilon=0.00000000008854;//value of epsilon
	public static InputReader sc = new InputReader(System.in);
	public static PrintWriter pw = new PrintWriter(System.out);
	public static long gcd(long a,long b){
		while(b>0){
			long t=b;
			b=a%b;
			a=t;
		}
		return a;
    }

	static void dfs(Point p[],int v,boolean vis[]){
        if (vis[v])return;
        vis[v]=true;
        for (int i=0;i<p.length;i++){
            if (p[i].x==p[v].x || p[i].y==p[v].y){
                dfs(p,i,vis);
            }
        }
	}
	public static long bSearch(Pair[]d, int l, int r, int a) {
		if(d[l].d > a)
			return 0;
		if(l == r)
			return d[l].g;
		int m = (l + r + 1) / 2;
		if(d[m].d > a)
			return bSearch(d, l, m - 1, a);
		return bSearch(d, m, r, a);
	}
	static class Pair implements Comparable<Pair> {
		int d, i;
		long g;
		public Pair(int D, long G, int I) {
			d = D;
			g = G;
			i = I;
		}
		public int compareTo(Pair p) {
			if(d == p.d)
				return i - p.i;
			return d - p.d;
		}
	 }

	 public static void dfs(int s,int a[][],boolean vis[],boolean tvis[]){
		int n=a.length;
		for(int i=0;i<n;i++){
			if(a[s][i]==1&&!vis[i]){
				vis[i]=true;
				if(tvis[i]){
					for(int j=0;j<n;j++){
						if(a[i][j]==1)
						vis[j]=true;
					}
				}
				else
				dfs(i, a, vis,tvis);
			}
		}
	 }
	public static int dp[][][][]=new int [101][101][101][2];
	public static int fun(int a[],int n,int odd,int even,int p){
		//pw.println(c);
		if(n<0){
			return 0;
		}
		if(dp[n][odd][even][p]>0)
		return dp[n][odd][even][p];
		if(a[n]==-1){
			//pw.println(odd+" "+even);
			if(odd>0&&even>0){
				if(p==1){
					dp[n][odd][even][p]= Math.min(fun(a, n-1, odd-1, even, 1), fun(a, n-1, odd, even-1, 0)+1);
				}
				else dp[n][odd][even][p]= Math.min(fun(a, n-1, odd-1, even, 1)+1, fun(a, n-1, odd, even-1, 0));
			}
			else if(odd<=0){
				if(p==1)
				dp[n][odd][even][p]= fun(a, n-1, odd, even-1, 0)+1;
				else dp[n][odd][even][p]= fun(a, n-1, odd, even-1, 0);
			}
			else{
				if(p==1)
				dp[n][odd][even][p]= fun(a, n-1, odd-1, even, 1);
				else dp[n][odd][even][p]= fun(a, n-1, odd-1, even, 1)+1;
			}
		}
		else if(a[n]>-1){
			if(a[n]!=p){
				//pw.print(" "+a[n]+" ");
				dp[n][odd][even][p]= fun(a, n-1, odd, even, a[n])+1;
			}
			else
			dp[n][odd][even][p]= fun(a, n-1, odd, even, a[n]);
		}
		else return -1;
		return dp[n][odd][even][p];
	}
	public static int eq(int a,int b){
		if(a==b)
		return 1;
		else
		return 0;
	}

	public static void main(String[] args) {
		// code starts..
		int n=sc.nextInt();
		int a[]=scanArray(n);
		int odd=n-n/2;
		int even=n/2;
		for(int i=0;i<n;i++){
			if(a[i]>0){
				a[i]=a[i]%2;
			}
			else a[i]=-1;
			odd-=eq(a[i], 1);
			even-=eq(a[i], 0);
		}
		//pw.println(Arrays.toString(a));
		int ans=0;
		if(a[n-1]==-1){
			if(odd>0&&even>0)
			ans=Math.min(fun(a, n-2, odd, even-1, 0), fun(a, n-2, odd-1, even,  1));
			else if(odd>0)
			ans=fun(a, n-2, odd-1, even, 1);
			else{
				ans=fun(a, n-1, odd, even-1, 0);
			}
		}
		else{
			ans=fun(a, n-2, odd, even, a[n-1]);
		}
		pw.println(ans);

		// Code ends...
		pw.flush();
		pw.close();
	}
	static class tripletL implements Comparable<tripletL> {
		Long x, y, z;

		tripletL(long x, long y, long z) {
			this.x = x;
			this.y = y;
			this.z = z;
		}

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

			return result;
		}

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

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

		public int hashCode() {
			return new Long(x).hashCode() * 31 + new Long(y).hashCode() + new Long(z).hashCode();
		}
	}
	public static String Doubleformate(double a,int n){
		String s="";
		while(n-->0){
			s+='0';
		}
		DecimalFormat f =new DecimalFormat("#0."+s);
		return f.format(a);
	}

	public static Comparator<Integer[]> column(int i){
		return
		new Comparator<Integer[]>() {
			@Override
			public int compare(Integer[] o1, Integer[] o2) {
				//return o1[i].compareTo(o2[i]);//for ascending
				return o2[i].compareTo(o1[i]);//for descending
			}
		};
	}
	public static Comparator<Integer[]> pair(){
		return
		new Comparator<Integer[]>() {
			@Override
			public int compare(Integer[] o1, Integer[] o2) {
				int result=o1[0].compareTo(o2[0]);
				if(result==0)
				result=o1[1].compareTo(o2[1]);
				return result;
			}
		};
	}
	public static Comparator<Integer[]> Triplet(){
		return
		new Comparator<Integer[]>() {
			@Override
			public int compare(Integer[] o1, Integer[] o2) {

					for(int i=0;i<3;i++){
						for(int j=i+1;j<3;j++){
							for(int k=0;k<3;k++){
								for(int p=k+1;p<3;p++){
									if((o1[i]==o2[k]&&o1[j]==o2[p])||(o1[j]==o2[k]&&o1[i]==o2[p])){

									}
								}
							}
						}
					}
					int result=o1[0].compareTo(o2[0]);
					if(result==0)
					result=o1[1].compareTo(o2[1]);
					if(result==0)
					result=o1[2].compareTo(o2[2]);
					return result;
			}
		};
	}

	public static String reverseString(String s){
		StringBuilder input1 = new StringBuilder();
        input1.append(s);
		input1 = input1.reverse();
		return input1.toString();
	}
	public static int[] scanArray(int n){
		int a[]=new int [n];
		for(int i=0;i<n;i++)
		a[i]=sc.nextInt();

		return a;
	}
	public static long[] scanLongArray(int n){
		long a[]=new long [n];
		for(int i=0;i<n;i++)
		a[i]=sc.nextLong();

		return a;
	}
	public static String [] scanStrings(int n){
		String a[]=new String [n];
		for(int i=0;i<n;i++)
		a[i]=sc.nextLine();

		return a;
	}
	static class InputReader {

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

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

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

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

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

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

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

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

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

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

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

}
class pfactor{
	long p=0,c=0;
	pfactor(long p1,long c1){
		p=p1;
		c=c1;
	}
}


import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.InputMismatchException;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
import java.util.Stack;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;

import project.Knapsack.Pair;

import java.util.BitSet;

public class Main {
	private static InputStream stream;
	private static byte[] buf = new byte[1024];
	private static int curChar;
	private static int numChars;
	private static SpaceCharFilter filter;
	private static PrintWriter pw;
	private static long mod = 1000000000 + 7;
	private static int MAX=1000001;
	private static int block;
	private static void soln(){
		int c=nextInt();
		int v0=nextInt();
		int v1=nextInt();
		int a=nextInt();
		int l=nextInt();
		if(c<=v0){
			pw.println(1);
		}else{
			c=c-v0;
			int cnt=1;
			int prev=v0;
			while(c>0){
				int curr=Math.min(prev+a,v1);
				int page=curr-l;
				c-=page;
				cnt++;
			}
			pw.println(cnt);
		}

	}
	private static class Pair1 implements Comparable<Pair1>{
		int i;
		int li;
		public Pair1(int a,int b){
			i=a;li=i+b;
		}
		@Override
		public int compareTo(Pair1 o) {
			return (this.li)-(o.li);
		}
	}
	private static int[] buildSuffix(String s,int n){
		Integer[] order=new Integer[n];
		for(int i=0;i<n;i++) order[i]=n-i-1;
		Arrays.sort(order,(a,b) -> Character.compare(s.charAt(a),s.charAt(b)));
		int[] sa=new int[n];
		int[] m_tmp=new int[n];
		for(int i=0;i<n;i++){
			sa[i]=order[i];
			m_tmp[i]=s.charAt(i);
		}
		for(int len=1;len<n;len<<=1){
			int[] tmp=m_tmp.clone();
			m_tmp[sa[0]]=0;
			for(int i=1;i<n;i++){
				m_tmp[sa[i]] = (tmp[sa[i-1]]==tmp[sa[i]] && tmp[(sa[i-1]+len>>1)%n]==tmp[(sa[i]+len>>1)%n]) ? m_tmp[sa[i-1]]:i;
			}
			int[] cnt=new int[n];
			for(int i=0;i<n;i++) cnt[i]=i;
			int[] sa_tmp=sa.clone();
			for(int i=0;i<n;i++){
				int s1=(sa_tmp[i]-len+n)%n;
				sa[cnt[m_tmp[s1]]++]=s1;
			}
		}
		return sa;
	}
	private static int[] buildLCP(int[] sa,String s,int n){
		int[] ind=new int[n];
		for(int i=0;i<n;i++)
			ind[sa[i]]=i;
		int[] lcp=new int[n];
		for(int i=0, k=0; i<n; i++)
			if(ind[i] < n-1){
				for(int j=sa[ind[i]+1]; Math.max(i,j)+k < n && s.charAt(i+k)==s.charAt(j+k);) k++;
				lcp[ind[i]]=k;
				if(k>0) k--;
			}
		return lcp;
	}
	private static int[] buildLCP1(int[] sa,String s,int n){
		int[] ind=new int[n+1];
		for(int i=1;i<=n;i++)
			ind[sa[i]]=i;
		int[] lcp=new int[n+1];
		for(int i=1, k=0; i<=n; i++)
			if(ind[i] < n){
				for(int j=sa[ind[i]+1]; Math.max(i,j)+k <= n && s.charAt(i+k-1)==s.charAt(j+k-1);) k++;
				lcp[ind[i]]=k;
				if(k>0) k--;
			}
		return lcp;
	}
	static class Pair implements Comparable<Pair>{
		int i;
		int j;
		int ind;
		public Pair(int a,int b,int c){
			i=a;
			j=b;
			ind=c;
		}
		@Override
		public int compareTo(Pair arg0) {
			return this.i-arg0.i;
		}
	}
	public static class Segment {
	    private int[][] tree;
	    //private int[] cnt2;
	    private int size;
	    private int n;
	    private class node{
	        private int a;
	        private int b;
	        private int c;
	        public node(int x,int y,int z){
	            a=x;
	            b=y;
	            c=z;
	        }
	    }
	    public Segment(int n){
	        //this.base=arr;
	        int x = (int) (Math.ceil(Math.log(n) / Math.log(2)));
	        size = 2 * (int) Math.pow(2, x) - 1;
	        tree=new int[size][2];
	        //cnt2=new int[size];
	        this.n=n;
	        //build(0,0,n-1);
	    }
	    /*private void build(int id,int l,int r){
	        //pw.println(1);
	        if(r==l){
	            tree[id]=1;
	            return;
	        }
	        int mid=l+(r-l)/2;
	        //System.out.println(2*id+1+" "+l+" "+mid);
	        build(2*id+1,l,mid);
	        //System.out.println(2*id+2+" "+(mid+1)+" "+r);
	        build(2*id+2,mid+1,r);
	        tree[id]=tree[2*id+1]+tree[2*id+2];
	    }*/
	    public String query(int j,int i){
	        return queryUtil(j,i,0,0,n-1);
	    }
	    private String queryUtil(int j,int i,int id,int l,int r){
	        int mid=l+(r-l)/2;
	        if(l==r){
	        	return l+" "+j;
	        }
	        long val1=((long)tree[(id<<1)|1][0])*((long)i)+(long)tree[2*id+1][1];
	        //System.out.println(val1+" "+j+" "+l+" "+r);
	        if(val1>=j)
	        	return queryUtil(j,i,(id<<1)|1,l,mid);
	        else
	        	return queryUtil(j-(int)val1,i,2*id+2,mid+1,r);
	    }
	    /*private void cnt(int id,int l,int r,HashSet<Integer> set){
	        if(tree[id]!=0){
	            set.add(tree[id]);
	            return;
	        }
	        if(r==l)
	            return;
	        int mid=l+(r-l)/2;
	        cnt(2*id+1,l,mid,set);
	        cnt(2*id+2,mid+1,r,set);
	    }*/
	    public void update(int i,int f,int val){
	    	updateUtil(i,f,val,0,0,n-1);
	    }
	    public void updateUtil(int i,int f,int val,int id,int l,int r){
	        if(l==r){
	        	tree[id][f]=val;
	        	return;
	        }
	        int mid=l+(r-l)/2;
	        //shift(id);
	        if(l<=i && i<=mid)
	        	updateUtil(i,f,val,2*id+1,l,mid);
	        else
	        	updateUtil(i,f,val,2*id+2,mid+1,r);
	        tree[id][f]=tree[2*id+1][f]+tree[2*id+2][f];
	        //tree[id][1]=tree[(id<<1)|1][1]+tree[(id<<1)+2][0];
	    }
	   /* private void shift(int id){
	        if(tree[id]!=0){
	            tree[2*id+1]=tree[2*id+2]=tree[id];
	        }
	        tree[id]=0;
	    }*/
	}
	private static class DSU{
		int[] parent;
		public DSU(int n){
			parent=new int[n];
			for(int i=0;i<n;i++)
				parent[i]=i;
		}
		int find(int i){
	        while(parent[i] !=i){
	        	parent[i]=parent[parent[i]];
	        	i=parent[i];
	        }
	        return i;
	    }
		void Union(int x, int y){
	        int xset = find(x);
	        int yset = find(y);
	        parent[yset]=yset;
	        parent[xset] = yset;
	    }
	}
	public static class Merge {
	    public static void sort(long inputArr[]) {
	        int length = inputArr.length;
	        doMergeSort(inputArr,0, length - 1);
	    }
	    private static void doMergeSort(long[] arr,int lowerIndex, int higherIndex) {
	        if (lowerIndex < higherIndex) {
	            int middle = lowerIndex + (higherIndex - lowerIndex) / 2;
	            doMergeSort(arr,lowerIndex, middle);
	            doMergeSort(arr,middle + 1, higherIndex);
	            mergeParts(arr,lowerIndex, middle, higherIndex);
	        }
	    }
	    private static void mergeParts(long[]array,int lowerIndex, int middle, int higherIndex) {
	        long[] temp=new long[higherIndex-lowerIndex+1];
	        for (int i = lowerIndex; i <= higherIndex; i++) {
	            temp[i-lowerIndex] = array[i];
	        }
	        int i = lowerIndex;
	        int j = middle + 1;
	        int k = lowerIndex;
	        while (i <= middle && j <= higherIndex) {
	            if (temp[i-lowerIndex] < temp[j-lowerIndex]) {
	                array[k] = temp[i-lowerIndex];
	                i++;
	            } else {
	                array[k] = temp[j-lowerIndex];
	                j++;
	                //cnt+=(middle+1-i);
	            }
	            k++;
	        }
	        while (i <= middle) {
	            array[k] = temp[i-lowerIndex];
	            k++;
	            i++;
	        }
	        while(j<=higherIndex){
	            array[k]=temp[j-lowerIndex];
	            k++;
	            j++;
	        }
	        /*pw.println(lowerIndex+" "+higherIndex);
	        for(int m=lowerIndex;m<=higherIndex;m++)
	            pw.print(array[m]+" ");
	        pw.println();*/
	    }

	}

	private static class Edge{
		int x;
		int y;
		int i;
		public Edge(int a,int b,int c){
			x=a; y=b;i=c;
		}
	}
	private static long pow(long a, long b, long c) {
		if (b == 0)
			return 1;
		long p = pow(a, b / 2, c);
		p = (p * p) % c;
		return (b % 2 == 0) ? p : (a * p) % c;
	}

	private static class Mo implements Comparable<Mo>{
		int l;
		int r;
		int i;
		int val;
		public Mo(int a,int b,int ind,int d) {
			l=a;r=b;i=ind;val=d;
		}
		@Override
		public int compareTo(Mo arg0) {
			int b1=this.l/block;
			int b2=arg0.l/block;
			return (b1!=b2)?(b1-b2):(this.r-arg0.r);
		}
	}

	private static long gcd(long n, long l) {
		if (l == 0)
			return n;
		return gcd(l, n % l);
	}

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

	private static long min(long a, long b) {
		if (a < b)
			return a;
		return b;
	}

	public static void main(String[] args) throws Exception {
		new Thread(null,new Runnable(){
			@Override
			public void run() {
				/*try {
					InputReader(new FileInputStream("C:\\Users\\hardik\\Desktop\\C-small-1-attempt1.in"));
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				/*try {
				InputReader(new FileInputStream("/root/codes/in.txt"));
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				InputReader(System.in);
				pw = new PrintWriter(System.out);
				/*try {
					pw=new PrintWriter(new FileOutputStream("C:\\Users\\hardik\\Desktop\\out.txt"));
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				/*try {
					pw=new PrintWriter(new FileOutputStream("/root/codes/out.txt"));
				} catch (FileNotFoundException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}*/
				soln();
				pw.close();
			}
		},"1",1<<26).start();
	}

	public static void InputReader(InputStream stream1) {
		stream = stream1;
	}

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

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

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

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

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

	private static String nextToken() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

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

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

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

	private static void pArray(int[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static void pArray(long[] arr) {
		for (int i = 0; i < arr.length; i++) {
			System.out.print(arr[i] + " ");
		}
		System.out.println();
		return;
	}

	private static boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return isWhitespace(c);
	}
	private static char nextChar() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		char c1=(char)c;
		while(!isSpaceChar(c))
			c=read();
		return c1;
}
	private interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author sheep
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream;
		try {
			inputStream = new FileInputStream("taska.in");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		OutputStream outputStream;
		try {
			outputStream = new FileOutputStream("taska.out");
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    final int MOD = 1000000007;
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        long ans = 0;
        char[] s = in.next().toCharArray();
        int n = s.length;
        int[] pow2 = new int[10 * n + 1];
        pow2[0] = 1;
        for (int i = 1; i < pow2.length; ++i) pow2[i] = pow2[i - 1] * 2 % MOD;

        for (int i = 0; i < n; ++i) {
            if (s[i] == '1') {
                ans = (ans + pow2[i] * (long)pow2[(n - i - 1) * 2]) % MOD;
            }
        }

        out.println(ans);
    }
}

class InputReader {
    BufferedReader reader;
    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 (Exception e) {
                throw new UnknownError();
            }
        }
        return tokenizer.nextToken();
    }

    }


import java.util.*;
public class home9{
  public static boolean check(int x){
    for(int a=0;a<100;a++){
      for(int b=0;b<100;b++){
        if(3*a+7*b==x){
          return true;
        }
      }
    }
    return false;
  }

  public static void main(String[] args){
    Scanner in = new Scanner(System.in);
    int n, big, small, small1, test;
    test = 0;
    big = 0;
    n = in.nextInt();
    int []num = new int[n];
    for(int e = 0;e<n;e++){
      num[e] = in.nextInt();
    }
    for(int i = 0;i<n;i++){
      if(check(num[i]) == 0){
        System.out.println("YES");
      }else{
        System.out.println("NO");
      }
    }
  }
}


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

public class check {

    /**
     * @param args
     * @throws IOException
     */
    public static long Mod =  1000000007;
    public static boolean ok = true;
    public static int[][]dp = new int[10002][10002];
    public static int solve(int index , int sum){

        if (index < 0 || (index == 0 && sum % Mod != 0)) {
            return 100000000;
        }
        else if(index == 0){
            ok = false;
            return 0;
        }
        if(dp[index][sum] != -1){
            return dp[index][sum];
        }
        int res = Math.min(solve(index-1, sum+1)+1, solve(index-2, sum+1)+1);

        return dp[index][sum] = res;
    }

    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub

        BufferedReader k=new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer str=new StringTokenizer(k.readLine());
        int steps = Integer.parseInt(str.nextToken());
        Mod = Integer.parseInt(str.nextToken());
        for (int i = 0; i < dp.length; i++) {
            Arrays.fill(dp[i], -1);
        }
        int res = solve(steps, 0);
        if(!ok)
        System.out.println(res);

        else{
            System.out.println(-1);
        }

    }

}


import java.util.Scanner;

public class Main {

    public static void main (){
        Scanner input = new Scanner(System.in);
        int numberOfTeams = Integer.parseInt(input.nextLine());
        int [][] colorsTeams= new int[numberOfTeams][numberOfTeams];
        String[] line;
        for (int i = 0; i < numberOfTeams; i++) {
            line = input.nextLine().split(" ");
            colorsTeams[i][0] = Integer.parseInt(line[0]);
            colorsTeams[i][1] = Integer.parseInt(line[1]);
        }

        int counter = 0;
        for (int i = 0; i < numberOfTeams; i++) {
            for (int j = 0; j < numberOfTeams; j++) {
                if(i != j){
                    if(colorsTeams[i][0] == colorsTeams[j][1])
                        counter++;
                }
            }
        }
        System.out.println(counter);
    }
}


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

import java.util.*;
import java.lang.*;
import java.io.*;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;

/* Name of the class has to be "Main" only if the class is public. */
public class bbg
{
	public static int result;

public static ArrayList<Integer> [] graph;

public static int[]cats;

public static int vizitat[];
public static int x;
//public static HashMap<String, Integer> map2;

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

Scanner input=new Scanner(System.in);

HashMap<Integer, Integer> contor1= new HashMap<Integer, Integer>();
HashMap<Integer, Integer> contor2= new HashMap<Integer, Integer>();

HashMap<Integer, Integer> map= new HashMap<Integer, Integer>();
HashMap<String, Integer> stringuri= new HashMap<String, Integer>();
HashMap<String, Integer> combinari= new HashMap<String, Integer>();

		String str=input.next();

		int links=0;
		int pearls=0;
		for(int j=0;j<str.length();j++) if(str.charAt(j)=='-') links++;
			else pearls++;

		if(links%pearls==0) System.out.println("YES");
		else System.out.println("NO");

	}

	}


import java.util.*;
import java.io.*;
public class posperm{
public static int op[] = {0,1,2,4,6,8,9,16,17,18};
public static long dp[][][];
//public static long bf[][];
public static long mod =0;
public static void bf(int pos,int vec,int llevo,int tot,int prop){
if(pos==0){
bf[vec][prop]=(bf[vec][prop]+1)%mod;
return;
}
for(int n = 1;n<=tot;n++){
int prop2 = prop;
if(((1<<n)&llevo)!=0)continue;
if(pos==1){
if(n==tot)prop2|=1;
if(n==tot-1)prop2|=2;
}
if(pos==2){
if(n==tot)prop2|=(1<<2);
if(n==tot-1)prop2|=(1<<3);
if(n==tot-2)prop2|=(1<<4);
}
bf(pos-1,vec+((Math.abs((tot-pos+1)-n)==1)?1:0),llevo|(1<<n),tot,prop2);
}
}
public static long sum(int a,int b,String c[],long voy){
long tal =0;
if(a<0 || a>=dp.length || b<0 || b>=dp.length) return 0;
for(int n= 0;n<c.length;n++)
tal = (tal+dp[a][b][Integer.parseInt(c[n],2)])%mod;
return tal%mod;
}
public static long sum2(int a,int b,String c,long voy){
long tal =0;
if(a<0 || a>=dp.length || b<0 || b>=dp.length) return 0;
int y = 0;
for(int n =0;n<c.length();n++){
if(y>1)return 0;
if(n==3)y =0;
if(c.charAt(n)=='1')y++;
}

int d = c.indexOf("*");
if(d==-1)return dp[a][b][Integer.parseInt(c,2)];
for(int n = 0;n<2;n++)
tal=(tal+sum2(a,b,c.substring(0,d)+n+c.substring(d+1),0))%mod;
return tal%mod;
}
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
String tmp = lector.readLine();
int a = Integer.parseInt(tmp.substring(0,tmp.indexOf(" ")));
int b = Integer.parseInt(tmp.substring(tmp.indexOf(" ")+1));
mod = 1000000007;
long res = 0;
//bf = new long[Math.max(a+2,4)][33];
dp= new long[Math.max(a+2,4)][Math.max(a+2,4)][33];
dp[1][0][1]=1;
dp[2][0][9]=1;
dp[2][2][6]=1;
dp[3][0][9]=1;
dp[3][0][8]=1;
dp[3][2][6]=1;
dp[3][2][17]=1;
dp[3][2][4]=1;
dp[3][2][18]=1;
String rejoder[] = {"00010","10010","01010","00110"};
String joder[] ={"00000","10000","01000","00100"};
String joder1[] = {"00001","01001","10001"};
String joder2[] = {"00010","10010","00110"};
String joder3[] = {"00000","01000","10000"};
String joder4[] = {"00010","10010"};
for(int n = 4;n<a+1;n++){
for(int m = 0;m<=n;m++){
//dp[n][m][0]=(((m+1)*sum(n-1,m+1,joder,0))%mod+((n-1-m-1)*sum(n-1,m,joder,0))%mod)%mod;
dp[n][m][0]=((m*dp[n-1][m+1][4])%mod+((n-m-2<0?0:n-m-2)*dp[n-1][m][4])%mod+((m+1)*dp[n-1][m+1][8])%mod+
((n-m-3<0?0:n-m-3)*dp[n-1][m][8])%mod +((m+1)*dp[n-1][m+1][16])%mod+((n-m-3<0?0:n-m-3)*dp[n-1][m][16])%mod+
((m+1)*dp[n-1][m+1][0])%mod+((n-m-3<0?0:n-m-3)*dp[n-1][m][0])%mod)%mod;//ta loco
dp[n][m][1]=sum(n-1,m,joder,0)%mod;
dp[n][m][9]=sum(n-1,m,joder1,0)%mod;
dp[n][m][17]=sum(n-1,m,joder2,0)%mod;
dp[n][m][2]=(dp[n-1][m][4]+sum(n-1,m-1,joder3,0))%mod;
//dp[n][m][16]=((m+1)*sum(n-1,m+1,joder2,0)%mod+((n-1-m-1)*sum(n-1,m,joder2,0))%mod)%mod;
dp[n][m][16]=(((m-1<0?0:m-1)*dp[n-1][m+1][6])%mod+((n-m-1<0?0:n-m-1)*dp[n-1][m][6])%mod+(m*dp[n-1][m+1][18])%mod+
((n-m-2<0?0:n-m-2)*dp[n-1][m][18])%mod+(m*dp[n-1][m+1][2])%mod+((n-m-2<0?0:n-m-2)*dp[n-1][m][2])%mod)%mod;//ta loco
dp[n][m][18]=(dp[n-1][m][6]+sum(n-1,m-1,joder4,0))%mod;
dp[n][m][6] = sum(n-1,m-2,joder1,0);
dp[n][m][4] = (sum(n-1,m-1,joder,0)+sum(n-1,m,rejoder,0))%mod;//ta loco
dp[n][m][8] = ((m+1)*sum(n-1,m+1,joder1,0)%mod+((n-1-m-1)*sum(n-1,m,joder1,0))%mod)%mod;
}

}
//bf(a,0,0,a,0);
//long res2 = 0;
for(int k = 0;k<op.length;k++){
//System.out.println(a+" "+b+" "+op[k]+" "+dp[a][b][op[k]]+" "+bf[b][op[k]]);
res=(res+dp[a][b][op[k]])%mod;
//res2 = (res2+bf[b][op[k]])%mod;
}
System.out.println(res%mod);//+" "+res2%mod);
}
}


import java.util.*;
import java.io.*;
public class posperm{
public static int op[] = {0,1,2,4,6,8,9,16,17,18};
public static int dp[][][];
//public static long bf[][];
public static int mod =0;
/*public static void bf(int pos,int vec,int llevo,int tot,int prop){
if(pos==0){
bf[vec][prop]=(bf[vec][prop]+1)%mod;
return;
}
for(int n = 1;n<=tot;n++){
int prop2 = prop;
if(((1<<n)&llevo)!=0)continue;
if(pos==1){
if(n==tot)prop2|=1;
if(n==tot-1)prop2|=2;
}
if(pos==2){
if(n==tot)prop2|=(1<<2);
if(n==tot-1)prop2|=(1<<3);
if(n==tot-2)prop2|=(1<<4);
}
bf(pos-1,vec+((Math.abs((tot-pos+1)-n)==1)?1:0),llevo|(1<<n),tot,prop2);
}
}*/
public static int sum(int a,int b,String c[],long voy){
int tal =0;
if(a<0 || a>=dp.length || b<0 || b>=dp.length) return 0;
for(int n= 0;n<c.length;n++)
tal = (tal+dp[a][b][Integer.parseInt(c[n],2)])%mod;
return tal%mod;
}
public static int sum2(int a,int b,String c,long voy){
int tal =0;
if(a<0 || a>=dp.length || b<0 || b>=dp.length) return 0;
int y = 0;
for(int n =0;n<c.length();n++){
if(y>1)return 0;
if(n==3)y =0;
if(c.charAt(n)=='1')y++;
}

int d = c.indexOf("*");
if(d==-1)return dp[a][b][Integer.parseInt(c,2)];
for(int n = 0;n<2;n++)
tal=(tal+sum2(a,b,c.substring(0,d)+n+c.substring(d+1),0))%mod;
return tal%mod;
}
public static void main(String args[]) throws IOException{
BufferedReader lector = new BufferedReader(new InputStreamReader(System.in));
String tmp = lector.readLine();
int a = Integer.parseInt(tmp.substring(0,tmp.indexOf(" ")));
int b = Integer.parseInt(tmp.substring(tmp.indexOf(" ")+1));
mod = 1000000007;
long res = 0;
//bf = new long[Math.max(a+2,4)][33];
dp= new int[Math.max(a+2,4)][Math.max(a+2,4)][33];
dp[1][0][1]=1;
dp[2][0][9]=1;
dp[2][2][6]=1;
dp[3][0][9]=1;
dp[3][0][8]=1;
dp[3][2][6]=1;
dp[3][2][17]=1;
dp[3][2][4]=1;
dp[3][2][18]=1;
String rejoder[] = {"00010","10010","01010","00110"};
String joder[] ={"00000","10000","01000","00100"};
String joder1[] = {"00001","01001","10001"};
String joder2[] = {"00010","10010","00110"};
String joder3[] = {"00000","01000","10000"};
String joder4[] = {"00010","10010"};
for(int n = 4;n<a+1;n++){
for(int m = 0;m<=n;m++){
//dp[n][m][0]=(((m+1)*sum(n-1,m+1,joder,0))%mod+((n-1-m-1)*sum(n-1,m,joder,0))%mod)%mod;
dp[n][m][0]=((m*dp[n-1][m+1][4])%mod+((n-m-2<0?0:n-m-2)*dp[n-1][m][4])%mod+((m+1)*dp[n-1][m+1][8])%mod+
((n-m-3<0?0:n-m-3)*dp[n-1][m][8])%mod +((m+1)*dp[n-1][m+1][16])%mod+((n-m-3<0?0:n-m-3)*dp[n-1][m][16])%mod+
((m+1)*dp[n-1][m+1][0])%mod+((n-m-3<0?0:n-m-3)*dp[n-1][m][0])%mod)%mod;//ta loco
dp[n][m][1]=sum(n-1,m,joder,0)%mod;
dp[n][m][9]=sum(n-1,m,joder1,0)%mod;
dp[n][m][17]=sum(n-1,m,joder2,0)%mod;
dp[n][m][2]=(dp[n-1][m][4]+sum(n-1,m-1,joder3,0))%mod;
//dp[n][m][16]=((m+1)*sum(n-1,m+1,joder2,0)%mod+((n-1-m-1)*sum(n-1,m,joder2,0))%mod)%mod;
dp[n][m][16]=(((m-1<0?0:m-1)*dp[n-1][m+1][6])%mod+((n-m-1<0?0:n-m-1)*dp[n-1][m][6])%mod+(m*dp[n-1][m+1][18])%mod+
((n-m-2<0?0:n-m-2)*dp[n-1][m][18])%mod+(m*dp[n-1][m+1][2])%mod+((n-m-2<0?0:n-m-2)*dp[n-1][m][2])%mod)%mod;//ta loco
dp[n][m][18]=(dp[n-1][m][6]+sum(n-1,m-1,joder4,0))%mod;
dp[n][m][6] = sum(n-1,m-2,joder1,0);
dp[n][m][4] = (sum(n-1,m-1,joder,0)+sum(n-1,m,rejoder,0))%mod;//ta loco
dp[n][m][8] = ((m+1)*sum(n-1,m+1,joder1,0)%mod+((n-1-m-1)*sum(n-1,m,joder1,0))%mod)%mod;
}

}
//bf(a,0,0,a,0);
//long res2 = 0;
for(int k = 0;k<op.length;k++){
//System.out.println(a+" "+b+" "+op[k]+" "+dp[a][b][op[k]]+" "+bf[b][op[k]]);
res=(res+dp[a][b][op[k]])%mod;
//res2 = (res2+bf[b][op[k]])%mod;
}
System.out.println(res%mod);//+" "+res2%mod);
}
}


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

import java.util.Scanner;

/**
 *
 * @author abdallah
 */
public class Problems {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args)
    {
        // TODO code application logic here

        Scanner in=new Scanner(System.in);

        int book,sum=0;
        book=in.nextInt();
        int []page=new int[7];
        for(int i=0 ; i<7 ; i++)
            page[i]=in.nextInt();
        int index=0;
        int day=1;
        while(index<7)
        {
            sum+=page[index];
            if(sum>=book)
            {
                System.out.println(day);
                break;
            }
            if(day==7)
            {
                day=1;
                index=0;
                continue;
            }
            index++;
            day++;
        }

    }

}


import java.util.Scanner;

public class tuoicay {
	public static int ktchia(int[] a, int n){
		int max=a[0];
		for (int i =0; i<a.length;i++){
			if (n%a[i]==0)
			{
				if (a[i]>max) max=a[i];
			}
		}
		return (n/max);
	}
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n=in.nextInt();
		int k=in.nextInt();
		int[] a= new int[n];
		for (int i=0;i<n;i++)
			a[i]=in.nextInt();
		System.out.println(ktchia(a,k));
	}
}


//package Test;

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

public class Test {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n, k;
		n = sc.nextInt();
		k = sc.nextInt();
		int[] arr = new int[n];
		for(int i=0;i<n;i++){
			arr[i]=sc.nextInt();
		}
		Arrays.sort(arr);
//		System.out.println(Arrays.toString(arr));
		int index = n-1;
		while(index>-1){

				if(k%arr[index]==0){
					System.out.println(k/arr[index]);
					break;
				}
		}
		sc.close();
	}

}


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

public class _LiftLevel5E {

	static boolean[][] locked;
	static int[][] board;
	static int[][] solved;
	static int w, h;
	static ArrayList<String> answer=new ArrayList<>();

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		h=fs.nextInt(); w=fs.nextInt();
		board=new int[w][h];
		solved=new int[w][h];
		locked=new boolean[w][h];
		for (int y=0; y<h; y++) {
			for (int x=0; x<w; x++) {
				board[x][y]=fs.nextInt();
				solved[x][y]=x+y*w+1;
			}
		}
		//solve ys [0, h-2)
		for (int yToSolveFor=0; yToSolveFor<h-2; yToSolveFor++) {
			for (int xToSolveFor=0; xToSolveFor<w-1; xToSolveFor++) {
				naiveMoveToXFirst(solved[xToSolveFor][yToSolveFor], xToSolveFor, yToSolveFor);
				locked[xToSolveFor][yToSolveFor]=true;
			}
			//now handle the rightmost position
			if (board[w-1][yToSolveFor]==solved[w-1][yToSolveFor]) {
				locked[w-1][yToSolveFor]=true;
				continue;
			}
			naiveMoveToXFirst(solved[w-1][yToSolveFor], w-1, h-1);
			hardCW4(w-2, yToSolveFor);
			naiveMoveToXFirst(solved[w-1][yToSolveFor], w-1, yToSolveFor+1);
			hardCCW4(w-2, yToSolveFor);
			locked[w-2][yToSolveFor]=locked[w-1][yToSolveFor]=true;
		}
//		print(board);

		//now we only have the last two ys left
		for (int x=0; x<w-2; x++) {
//			print(board);
			naiveMoveToXFirst(solved[x][h-1], x, h-1);
			if (solved[x][h-2]==board[x][h-2]) {
				locked[x][h-1] = locked[x][h-2]=true;
				continue;
			}
			locked[x][h-2] = true;
			naiveMoveToXFirst(solved[x][h-2], w-1, h-1);
			hardCW4(x, h-2);
			naiveMoveToXFirst(solved[x][h-2], x+1, h-2);
			hardCCW4(x, h-2);
			locked[x][h-1]=true;
		}

		//TODO: handle the last 4 spaces
		while (board[w-2][h-2]!=solved[w-2][h-2]) {
			hardCW4(w-2, h-2);
		}
		int target=solved[w-1][h-2];
		if (board[w-1][h-2]==target) {

		}
		else if (board[w-2][h-1]==target) {
			swapBottom2();
			swapRight2();
		}
		else {
			swapRight2();
		}
		target=board[w-2][h-1];
		if (board[w-2][h-1]==target) {

		}
		else {
			swapBottom2();
		}
		System.out.println(answer.size());
		for (String s:answer) {
			System.out.println(s);
		}
	}

	static void sixCycle() {
		hardCCW4(w-2, h-2);
		hardCCW4(w-3, h-2);
		moveNoWarnings(w-3, h-2, w-2, h-2, w-1, h-2,
				w-1, h-1, w-2, h-1, w-3, h-1);
	}

	static void swapRight2() {
		hardCCW4(w-2, h-2);
		sixCycle();
		hardCW4(w-2, h-2);
	}

	static void swapLeft2() {
		hardCW4(w-2, h-2);
		sixCycle();
		hardCCW4(w-2, h-2);
	}

	static void swaptTop2() {
		sixCycle();
	}

	static void swapBottom2() {
		hardCW4(w-2, h-2);
		hardCW4(w-2, h-2);
		sixCycle();
		hardCCW4(w-2, h-2);
		hardCCW4(w-2, h-2);
	}

	static boolean movable(int x, int y) {
		if (x< 0 || x>=locked.length || y<0 || y>=locked[x].length) return false;
		return !locked[x][y];
	}

	//moves x first then y
	static void naiveMoveToXFirst(int toMove, int targetX, int targetY) {
		Point curPos=locationOf(toMove);
		int curX=curPos.x;
		int curY=curPos.y;
		while (curX<targetX) {
			moveRight(curX, curY);
			curX++;
		}
		while (curX>targetX) {
			moveLeft(curX, curY);
			curX--;
		}
		while (curY<targetY) {
			moveDown(curX, curY);;
			curY++;
		}
		while (curY>targetY) {
			moveUp(curX, curY);
			curY--;
		}
	}

	static void moveLeft(int x, int y) {
		if (!movable(x, y) || !movable(x-1, y)) {
			throw null;
		}
		if (movable(x-1, y+1) && movable(x, y+1)) {
			move(x, y, x-1, y, x-1, y+1, x, y+1);
			return;
		}
		if (movable(x-1, y-1) && movable(x-1, y-1)) {
			move(x, y, x-1, y, x-1, y-1, x, y-1);
			return;
		}
		throw null;
	}

	static void moveRight(int x, int y) {
		if (!movable(x, y) || !movable(x+1, y)) {
			throw null;
		}
		if (movable(x+1, y+1) && movable(x, y+1)) {
			move(x, y, x+1, y, x+1, y+1, x, y+1);
			return;
		}
		if (movable(x+1, y-1) && movable(x, y-1)) {
			move(x, y, x+1, y, x+1, y-1, x, y-1);
			return;
		}
//		System.out.println("Trying to move right on pos: "+x+" "+y+" but it is impossible");
//		print(locked);
		throw null;
	}

	static void moveDown(int x, int y) {
		if (!movable(x, y) || !movable(x, y+1)) {
			throw null;
		}
		if (movable(x-1, y+1) && movable(x-1, y)) {
			move(x, y, x, y+1, x-1, y+1, x-1, y);
			return;
		}
		if (movable(x+1, y+1) && movable(x+1, y)) {
			move(x, y, x, y+1, x+1, y+1, x+1, y);
			return;
		}
		throw null;
	}

	static void moveUp(int x, int y) {
		if (!movable(x, y) || !movable(x, y-1)) {
			throw null;
		}
		if (movable(x-1, y-1) && movable(x-1, y)) {
			move(x, y, x, y-1, x-1, y-1, x-1, y);
			return;
		}
		if (movable(x+1, y-1) && movable(x+1, y)) {
			move(x, y, x, y-1, x+1, y-1, x+1, y);
			return;
		}
		throw null;
	}

	static void move(int ...input) {
		if (input.length%2!=0) throw null;
		int[] xs=new int[input.length/2], ys=new int[input.length/2];
		for (int i=0; i<input.length; i+=2) {
			xs[i/2]=input[i];
			ys[i/2]=input[i+1];
		}
		int nPoints=input.length/2;
		for (int i=0; i<nPoints; i++) {
			if (!movable(xs[i], ys[i])) throw null;
		}
		int[] old=new int[nPoints];
		for (int i=0; i<nPoints; i++) old[i]=board[xs[i]][ys[i]];
		for (int i=0; i<nPoints; i++) board[xs[i]][ys[i]] = old[(i-1+nPoints)%nPoints];
		StringBuilder sb=new StringBuilder(nPoints+" ");
		for (int i:old) {
			sb.append(i+" ");
		}
		answer.add(sb.toString());
	}

	static void moveNoWarnings(int ...input) {
		if (input.length%2!=0) throw null;
		int[] xs=new int[input.length/2], ys=new int[input.length/2];
		for (int i=0; i<input.length; i+=2) {
			xs[i/2]=input[i];
			ys[i/2]=input[i+1];
		}
		int nPoints=input.length/2;
		int[] old=new int[nPoints];
		for (int i=0; i<nPoints; i++) old[i]=board[xs[i]][ys[i]];
		for (int i=0; i<nPoints; i++) board[xs[i]][ys[i]] = old[(i-1+nPoints)%nPoints];
		StringBuilder sb=new StringBuilder(nPoints+" ");
		for (int i:old) {
			sb.append(i+" ");
		}
		answer.add(sb.toString());
	}

	static void hardCW4(int topLeftX, int topLeftY) {
		moveNoWarnings(topLeftX, topLeftY, topLeftX+1, topLeftY, topLeftX+1, topLeftY+1, topLeftX, topLeftY+1);
	}

	static void hardCCW4(int topLeftX, int topLeftY) {
		moveNoWarnings(topLeftX, topLeftY, topLeftX, topLeftY+1, topLeftX+1, topLeftY+1, topLeftX+1, topLeftY);
	}

	static Point locationOf(int i) {
		for(int x=0; x<w; x++) {
			for (int y=0; y<h; y++) {
				if (board[x][y]==i) return new Point(x, y);
			}
		}
//		System.out.println("Couldn't find location of "+i+" in ");
//		print(board);
		throw null;
	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreElements()) {
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

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

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

	static void print(int[][] board) {
		for (int y=0; y<board[0].length; y++) {
			for (int x=0; x<board.length; x++) System.out.print(board[x][y]+" ");
			System.out.println();
		}
		System.out.println();
	}
	static void print(boolean[][] board) {
		for (int y=0; y<board[0].length; y++) {
			for (int x=0; x<board.length; x++) System.out.print((board[x][y]?"*":"_")+" ");
			System.out.println();
		}
		System.out.println();
	}
}


public class TaskA {
    private static PrintWriter pw = new PrintWriter(new BufferedOutputStream(System.out, 500000));
    static class MyScanner {
        /**
         * Buffered reader
         */
        private static BufferedReader br = new BufferedReader(
                new InputStreamReader(System.in));

        private static StringTokenizer st;

        /**
         * Read integer
         *
         * @return
         * @throws Exception
         */
        public static int readInt() throws Exception {
            try {
                if (st != null && st.hasMoreTokens()) {
                    return parseInt(st.nextToken());
                }
                String str = br.readLine();
                if(str == null) return -2;
                if (!str.trim().equals("")) {
                    st = new StringTokenizer(str);
                    return parseInt(st.nextToken());
                }
            } catch (IOException e) {
                close();
                return -1;
            }
            return -1;
        }

        /**
         * Read integer
         *
         * @return
         * @throws Exception
         */
        public static long readLong() throws Exception {
            try {
                if (st != null && st.hasMoreTokens()) {
                    return Long.parseLong(st.nextToken());
                }
                String str = br.readLine();
                if (str != null && !str.trim().equals("")) {
                    st = new StringTokenizer(str);
                    return Long.parseLong(st.nextToken());
                }
            } catch (IOException e) {
                close();
                return -1;
            }
            return -1;
        }

        /**
         * Read line
         * @return
         * @throws Exception
         */
        public static String readLine() throws Exception
        {
            return br.readLine();
        }

        /**
         * Parse to integer
         * @param in
         * @return integer value
         */
        public static int parseInt(String in)
        {
            // Check for a sign.
            int num  = 0, sign = -1, i = 0;
            final int len  = in.length( );
            final char ch  = in.charAt( 0 );
            if ( ch == '-' )
                sign = 1;
            else
                num = '0' - ch;

            // Build the number.
            i+=1;
            while ( i < len )
                num = num*10 + '0' - in.charAt( i++ );
            return sign * num;
        }

        /**
         * Close BufferedReader
         *
         * @throws Exception
         */
        public static void close() throws Exception {
            br.close();
        }
    }

    public static void main(String[] args) throws Exception{
        List<int[]> numbers = new ArrayList<>();
        int n = MyScanner.readInt();
        int h = MyScanner.readInt();
        int m = MyScanner.readInt();
        for(int i = 0; i < m; i ++){
            int[] A = new int[3];
            A[0] = MyScanner.readInt();
            A[1] = MyScanner.readInt();
            A[2] = MyScanner.readInt();
            numbers.add(A);
        }

        long ans = 0;
        for(int i = 1; i <= n; i ++){
            int min = h;
            for(int[] A : numbers){
                if(i >= A[0] && i <= A[1]){
                    min = Math.min(min, A[2]);
                }
            }
            ans += (min * min);
        }
        pw.println(ans);
        pw.flush();
        pw.close();
        MyScanner.close();
    }
}


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

public class Main {

    public static void main(String[] args) {
        // write your code here
        Scanner in=new Scanner(System.in);
        long n=in.nextLong();
        int k=in.nextInt();
        int []ap=new int[n];
        long ans=1;
        if(k>=2)
        {
           ans+=n*(n-1)/2;
        }
        if(k>=3)
        {
            ans+=n*(n-1)*(n-2)/3;
        }
        if(k>=4)
        {
            ans+=3*n*(n-1)*(n-2)*(n-3)/8;
        }
        System.out.println(ans);
    }
}


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

public class Solver {

	public static void main(String[] Args) throws NumberFormatException,
			IOException {
		new Solver().Run();
	}

	PrintWriter pw;
	StringTokenizer Stok;
	BufferedReader br;

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

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

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

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

	long n;

	public long findResult(long zn, int maxpor, int acursum){
		zn++;
		zn+=9;
		int por=1;
		int cursum=9+1+acursum;
		long mn=1;
		boolean found=false;
		while (zn*(zn+cursum)<n){
			mn*=10;
			zn+=mn*9;
			por++;
			cursum+=9;
		}
		if (zn*(zn+cursum)==n){
			return zn;
		}
		if (por>maxpor)
			return -1;
		long buf=zn;
		int bufpor=por;
		int kolmade;
		while (!found && por>0){
			kolmade=0;
			while (zn*(zn+cursum)>n){
				zn-=mn;
				cursum--;
				kolmade++;
				if (kolmade>9)
					return -1;
			}
			if (zn*(zn+cursum)==n)
				found=true;
			else
			{
				zn+=mn;
				cursum++;
				mn/=10;
				por--;
			}
		}
		if (zn*(zn+cursum)==n)
			return zn;
		else
			return findResult(buf, bufpor, acursum+1);
	}

	public int countsum(long zn){
		int result=0;
		while (zn>0){
			result+=(zn%10);
			zn/=10;
		}
		return result;
	}

	public void Run() throws NumberFormatException, IOException {
		br = new BufferedReader(new FileReader("input.txt")); pw = new PrintWriter("output.txt");
		//br=new BufferedReader(new InputStreamReader(System.in));  pw=new PrintWriter(new OutputStreamWriter(System.out));

		n=nextLong();
		long result=9;
		int por=1;
		int cursum=9;
		long mn=1;
		boolean found=false;
		while (result*(result+cursum)<n){
			mn*=10;
			result+=mn*9;
			por++;
			cursum+=9;
		}
		if (result*(result+cursum)==n){
			pw.println(result);
			pw.flush();
			pw.close();
			return;
		}
		long buf=result/10;
		int bufpor=por;
		while (!found && por>0){
			while (result*(result+cursum)>n){
				result-=mn;
				cursum--;
			}
			if (result*(result+cursum)==n)
				found=true;
			else
			{
				result+=mn;
				cursum++;
				mn/=10;
				por--;
			}
		}

		if (por==0){
			result=buf;
			long zn;
			for (int i=0; i<1000; i++){
				zn=result*(result+countsum(result));
				if (Math.abs(zn-n)<0.000001)
				{
					pw.println(result);
					pw.flush();
					pw.close();
					return;
				}
				result++;
			}
			pw.println(findResult(buf, bufpor, 0));
		}
		else
			pw.println(result);

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

}


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

public class blocktowers {

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

        String[] inputs = r.readLine().split(" ");
        int two = Integer.parseInt(inputs[0]);
        int three = Integer.parseInt(inputs[1]);

        //always use 2's to make room for the smallest number of 3s
        /*
        int min2 = two * 2;
        int min3 = three * 3;

        //CustomBitSet chosen = new CustomBitSet();

        long answer = 0;
        if (min2 > min3) {
            //accomodate for min2, when choosing from potential 3's always skip the multiples of 2

            long mult2 = 0;
            long mult3 = 0;

            for (int i = 0; i < three; i++) {
                mult3 += 3;
                if (mult3 % 2 == 0 && mult3 <= min2) mult3 += 3;
                //chosen.set(mult3);
            }

            mult2 = min2;

            answer = Math.max(mult3, mult2);
        } else if (min2 <= min3) {
            //accomodate for min3, when choosing form potential 2's always skip them ultibles of 3
            long mult2 = 0;
            long mult3 = 0;

            for (int i = 0; i < two; i++) {
                mult2 += 2;
                if (mult2 % 3 == 0 && mult2 <= min3) mult2 += 2;
            }

            mult3 = min3;

            answer = Math.max(mult3, mult2);
        }

        w.println(answer);
        w.close();
        */

        long twoHighest = 2;
        long threeHighest = 3;
        two--;
        three--;
        long min2 = two * 2;
        long min3 = three * 3;

        CustomBitSet chosen = new CustomBitSet();

        while (two > 0 || three > 0) {
            //find the one that results in the lower sum

            min2 = twoHighest + two * 2;
            min3 = threeHighest + three * 3;
            if (twoHighest % 3 == 0 && two > 0 && three > 0) {
                //check if min2 or min3 is greater
                if (min2 < min3) {
                    //increase 2
                    twoHighest += 2;
                    two--;
                    if (chosen.get(twoHighest)) {
                        twoHighest += 2;
                        two--;
                    }
                    chosen.set(twoHighest);
                }
            } else if (two > 0) {
                twoHighest += 2;
                two--;
                if (chosen.get(twoHighest)) {
                    twoHighest += 2;
                    two--;
                }
                chosen.set(twoHighest);
            }

            if (threeHighest % 2 == 0 && three > 0 && two > 0) {
                if (min2 > min3) {
                    //increase 3
                    threeHighest += 3;
                    three--;
                    if (chosen.get(threeHighest)) {
                        threeHighest += 3;
                        three--;
                    }
                    chosen.set(threeHighest);
                }
            } else if (three > 0) {
                threeHighest += 3;
                three--;
                if (chosen.get(threeHighest)) {
                    threeHighest += 3;
                    three--;
                }
                chosen.set(threeHighest);
            }
        }

        w.println(Math.max(twoHighest, threeHighest));
        w.close();
    }

    public static class CustomBitSet {
        //Use 3 bitsets
        BitSet one = new BitSet(2000000000);
        BitSet two = new BitSet(2000000000);
        BitSet three = new BitSet(2000000000);

        public void set(long number) {
            //check if it's in 1 or 2 or 3

            if (number >= 4000000000L) {
                //third set
                three.set((int) (number - 4000000000L));
            } else if (number >= 2000000000) {
                two.set((int) (number - 2000000000));
            } else {
                one.set((int) number);
            }
        }

        public boolean get(long number) {
            if (number >= 4000000000L) {
                //third set
                return three.get((int) (number - 4000000000L));
            } else if (number >= 2000000000) {
                return two.get((int) (number - 2000000000));
            } else {
                return one.get((int) number);
            }
        }
    }

}


import java.io.*;
import java.util.*;
public class Pa{
	public static void main(String[] args) throws IOException{
		FastReader sc = new FastReader();
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out),"ASCII"),512);
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] b = new int[n];
		for(int i=0;i<n;i++) a[i] = sc.nextInt();
		for(int i=0;i<n;i++) b[i] = sc.nextInt();
		int counta = 0;
		int countb = 0;
		for(int i=0;i<n;i++){
			if(a[i] == 0 && b[i] == 1) countb++;
			else if(a[i] == 1 && b[i] == 0) counta++;
		}
		if(counta == countb) out.write(-1 + "");
		else{
			int op = 0;
			if(countb%counta == 0) op = 1 + (countb/counta);
			else op = (int)Math.ceil(countb/counta);
			out.write(op + "");
		}
		out.flush();
	}
}
class FastReader{
	BufferedReader br;
	StringTokenizer st;
	public FastReader(){
		br = new BufferedReader(new InputStreamReader(System.in));
	}
	String next(){
		while(st == null || !st.hasMoreElements()){
			try{
				st = new StringTokenizer(br.readLine());
			}
			catch (IOException  e){
				e.printStackTrace();
			}
		}
		return st.nextToken();
	}
	int nextInt(){
        return Integer.parseInt(next());
	}
    long nextLong(){
        return Long.parseLong(next());
    }
    double nextDouble(){
        return Double.parseDouble(next());
    }
    String nextLine(){
        String str = "";
        try{
            str = br.readLine();
        }
		catch (IOException e){
            e.printStackTrace();
        }
        return str;
    }
}


package edu.juniv.cse;

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        int n=scanner.nextInt();
        int a[]=new int [n];
        int b[]=new int [n];
        for(int i=0;i<n;i++)a[i]=scanner.nextInt();
        for(int i=0;i<n;i++)b[i]=scanner.nextInt();
        int s1=0,s2=0,res=1;
        for(int i=0;i<n;i++)
        {
            if(a[i]==0&&b[i]==1)s2++;
            if(a[i]==1&&b[i]==0)s1++;
        }
        int x=s1;
        if(s1==0)res=-1;
        if(s1<=s2) {
            while (s1 <= s2 && s1 != 0) {
                s1 = x * res;
                res++;
            }
            res--;
        }
        System.out.println(res);

    }
}


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

public class CodeD
{
	static int n;

	@SuppressWarnings("unchecked")
	static HashMap <Integer, Long> [] dp = new HashMap[1 << 16];
	static long MOD = 1000000007;

	static HashMap <Integer, Long> dp(int mascara)
	{
		if(dp[mascara] != null)
			return dp[mascara];
		int indiceActual = Integer.bitCount(mascara);
		if(indiceActual == n)
		{
			HashMap <Integer, Long> ans = new HashMap <Integer, Long> ();
			ans.put(0, 1L);
			return dp[mascara] = ans;
		}
		else
		{
			HashMap <Integer, Long> answers = new HashMap <Integer, Long> ();
			for(int i = 0; i < n; i++)
			{
				if((mascara & (1 << i)) == 0)
				{
					int indiceC = (i + indiceActual) % n;
					int mascaraSig = 1 << indiceC;
					for(Map.Entry<Integer, Long> e : dp(mascara ^ (1 << i)).entrySet())
					{
						int v = e.getKey();
						if((v & mascaraSig) == 0)
						{
							int n = v ^ mascaraSig;
							if(!answers.containsKey(n))
								answers.put(n, 0L);
							answers.put(n, (answers.get(n) + e.getValue()) % MOD);
						}
					}
				}
			}
			return dp[mascara] = answers;
		}
	}

	int[] ans = {0, 1, 0, 18, 0, 1800, 0, 670320, 0, 734832000, 0, 890786230, 0, 695720788, 0, 150347555, 0}
	@SuppressWarnings("unchecked")
	public static void main(String[] args)
	{
//		long[] factorial = new long[17];
//		factorial[0] = 1L;
//		for(int i = 1; i < 17; i++)
//			factorial[i] = (factorial[i - 1] * i) % MOD;
//		for(int i = 0; i <= 16; i++)
//		{
//			if((i & 1) == 0)
//				System.out.print("0, ");
//			else
//			{
//				n = i;
//				dp = new HashMap[1 << n];
//				long ans = 0;
//				for(long v : dp(0).values())
//				{
//					ans += v;
//					ans %= MOD;
//				}
//				ans *= factorial[n];
//				ans %= MOD;
//				System.out.print(ans + ", ");
//			}
//		}
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		System.out.println(ans[n]);
	}
}


import java.util.*;

public class laddering {

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

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

System.out.println(Math.max(a,b)-1 + " " + Math.min(a,b);

}
}


//package codeforce;

import java.util.Scanner;

public class Div2R386C {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int s = scan.nextInt();
		int x1 = scan.nextInt(), x2 = scan.nextInt();
		double v1 = (double)1/(scan.nextInt()), v2 = (double)1/(scan.nextInt());
		//System.out.println(v1 + " " + v2);

		int p = scan.nextInt(), d = scan.nextInt();
		int i_d = -1, end = 0;
		if(x1 < x2) {i_d = 1;}
		if(d == 1) end = s;
		int path = 0;
		while(Math.signum((double)x1 - p) != Math.signum((double)i_d) || i_d != d){
			path += Math.abs(p - end);
			p = end;
			end = s - end;
			d = -d;
		}
		path += Math.abs(x1-p);
		double distance = Math.abs(x1- x2);
		double time_to_catch = path/Math.abs(v1- v2);
		long ans = 0;
		if(time_to_catch * v2 >= distance || v1 <= v2){
			ans = Math.round(distance/v2);
		} else {
			ans = Math.round(time_to_catch + (distance - time_to_catch*v2)/v1);
		}
		System.out.println(ans);
	}
}


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

public class AEdu7 {
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		long n = s.nextLong();
		long num = 1, count = 1;
		ArrayList<Long> nums = new ArrayList<Long>();
		for(int i = 0; i < n; i++) {
			if(count == num) {
				nums.add((long) count);
				num++;
				count = 1;
			}
			else {
				nums.add((long) count);
				count++;
			}
		}
		System.out.println(nums.get(nums.size()-1));
	}
}


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

public class Solution {
    private BufferedReader in;
    private StringTokenizer line;
    private PrintWriter out;
    private boolean isDebug;

    public Solution(boolean isDebug) {
        this.isDebug = isDebug;
    }

    public void solve() throws IOException {
        int n = nextInt();
        char[] s = nextToken().toCharArray();
        for (int i = 0; i < n; i++) {
            s[i] -= '0';
        }
        int MX = 20;
        int[] eta = new int[MX];
        eta[0] = 1;
        for (int i = 1; i < MX; i++) {
            eta[i] = eta[i - 1] + (1 << i);
        }
        long res = 0;
        int MX_SZ = (1 << MX);
        long[][] dp = new long[n + 1][MX_SZ + 13];
        for (int i = 0; i <= n; i++) {
            dp[i][0] = 1L;
            if (i > 0) {
                for (int j = 1; j <= i; j++) {
                    int num = 0;
                    for (int k = j; k <= i; k++) {
                        num = num * 2 + s[k - 1];
                    }
                    if (num >= 1 && num <= MX) {
                        long[] dpi = dp[i];
                        long[] dpj1 = dp[j - 1];
                        for (int k = 0; k < MX_SZ; k++) {
                            int nw = k | (1 << (num - 1));
                            dpi[nw] = (dpi[nw] + dpj1[k]) % mm;
                        }
                    }
                }
                for (int aa : eta) {
                    res = (res + dp[i][aa]) % mm;
                }
            }
        }
        out.println(res);
    }

    private int min(int... a) {
        int res = a[0];
        for (int i : a) {
            res = Math.min(res, i);
        }
        return res;
    }

    private static final int mm = 1000000007;

    private long mult(long a, long b) {
        return a * b % mm;
    }

    private long pow(long a, int n) {
        if (n == 0) return 1;
        long t = pow(a, n / 2);
        t = mult(t, t);
        if (n % 2 != 0) t = mult(a, t);
        return t;
    }

    public static void main(String[] args) throws IOException {
        new Solution(args.length > 0 && "DEBUG_MODE".equals(args[0])).run(args);
    }

    public void run(String[] args) throws IOException {
        if (isDebug) {
            in = new BufferedReader(new InputStreamReader(new FileInputStream("input.txt")));
//            in = new BufferedReader(new InputStreamReader(System.in));
        } else {
            in = new BufferedReader(new InputStreamReader(System.in));
        }
        out = new PrintWriter(System.out);
//        out = new PrintWriter("output.txt");

//        int t = nextInt();
        int t = 1;
        for (int i = 0; i < t; i++) {
//            out.print("Case #" + (i + 1) + ": ");
            solve();
        }

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

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

    private long[] nextLongArray(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nextInt();
        }
        return res;
    }

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

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

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

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

    private static class Pll {
        private long key;
        private long value;

        public Pll(long key, long value) {
            this.key = key;
            this.value = value;
        }

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

            Pll pll = (Pll) o;

            if (key != pll.key) return false;
            return value == pll.value;

        }

        @Override
        public int hashCode() {
            int result = (int) (key ^ (key >>> 32));
            result = 31 * result + (int) (value ^ (value >>> 32));
            return result;
        }
    }

    private static class Pii {
        private int key;
        private int value;

        public Pii(int key, int value) {
            this.key = key;
            this.value = value;
        }

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

            Pii pii = (Pii) o;

            if (key != pii.key) return false;
            return value == pii.value;

        }

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

        @Override
        public String toString() {
            return "Pii{" +
                    "key=" + key +
                    ", value=" + value +
                    '}';
        }
    }

    private static class Pair<K, V> {
        private K key;
        private V value;

        public Pair(K key, V value) {
            this.key = key;
            this.value = value;
        }

        public K getKey() {
            return key;
        }

        public V getValue() {
            return value;
        }

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

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

            if (key != null ? !key.equals(pair.key) : pair.key != null) return false;
            return !(value != null ? !value.equals(pair.value) : pair.value != null);

        }

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

        @Override
        public String toString() {
            return "Pair{" +
                    "key=" + key +
                    ", value=" + value +
                    '}';
        }
    }
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
What do you think? What do you think?
1st on Billboard, what do you think of it
Next is a Grammy, what do you think of it
However you think, I’m sorry, but shit, I have no fcking interest
*******************************
I'm standing on top of my Monopoly board
That means I'm on top of my game and it don't stop
til my hip don't hop anymore
https://www.a2oj.com/Ladder16.html
*******************************
Shining through the city with a little funk and soul
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x757D
   {
      static final int MOD = 1000000007;
      static final int MAX = 21;
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         String input = infile.readLine();
         int[] arr = new int[N+1];
         for(int i=0; i < N; i++)
            arr[i+1] = input.charAt(i)-'0';
         int[][] dp = new int[N+1][1<<MAX];
         for(int i=0; i < N; i++)
            dp[i][0] = 1;
         for(int i=0; i < N; i++)
            for(int mask=0; mask < (1<<MAX); mask++)
               if(dp[i][mask] > 0)
               {
                  int val = 0;
                  for(int a=i+1; a <= N; a++)
                  {
                     val <<= 1;
                     val += arr[a];
                     if(val > MAX)
                        break;
                     if(val > 0)
                     {
                        int nextmask = mask|(1<<(val-1));
                        dp[a][nextmask] += dp[i][mask];
                        if(dp[a][nextmask] >= MOD)
                           dp[a][nextmask] -= MOD;
                     }
                  }
               }
         int res = 0;
         for(int i=1; i <= N; i++)
            for(int b=1; b < MAX; b++)
            {
               res += dp[i][(1<<b)-1];
               if(res >= MOD)
                  res -= MOD;
            }
         System.out.println(res);
      }
   }


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

public class Div2_391D {

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

	int numE;
	boolean[] elements;

	long MOD = 1_000_000_007;

	void execute() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

		numE = Integer.parseInt(reader.readLine());
		elements = new boolean[numE + 1];

		String inputLine = reader.readLine();
		for (int i = 1; i <= numE; i++) {
			elements[i] = inputLine.charAt(i - 1) == '1';
		}
		reader.close();

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

		for (int i = 0; i <= numE; i++) {
			dp[i][0] = 1;
		}

		for (int cI = 0; cI <= numE; cI++) {
			for (int cS = 0; cS < (1 << 20); cS++) {
				if (dp[cI][cS] == 0) {
					continue;
				}
				int cNum = 0;
				for (int nI = cI + 1; nI <= numE; nI++) {
					cNum <<= 1;
					if (elements[nI]) {
						cNum |= 1;
					}
					if (cNum == 0 || cNum > 20) {
						// invalid cut, as all cuts must form positive integers or there is no point in counting
						continue;
					}
					// bitsets are zero-indexed
					dp[nI][cS | (1 << (cNum - 1))] = (dp[nI][cS | (1 << (cNum - 1))] + dp[cI][cS]) % MOD;
				}
			}
		}

		long total = 0;
		for (int cI = 1; cI <= numE; cI++) {
			for (int cM = 1; cM < (1 << 20); cM <<= 1, cM |= 1) {
				if (dp[cI][cM] != 0) {
					total += dp[cI][cM];
					total %= MOD;
				}
			}
		}
		System.out.println((total + MOD) % MOD);
	}

}


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

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(System.out);
        //Scanner sc = new Scanner();
        Reader in = new Reader();
        Main solver = new Main();
        solver.solve(out, in);
        out.flush();
        out.close();

    }

    static int maxn = 1<<20;
    static long mod=998244353 ;
    static int n,m,k;

    static int INF = (int)-1e9;

    void solve(PrintWriter out, Reader in) throws IOException{
       n = in.nextInt();
       String str = in.next();

       long[][] cal = new long[n+1][n+1];

       for(int i=0;i<n;i++){
           long temp=0;
           for(int j=i;j<n;j++){
               if(temp>20) {cal[i+1][j+1]=21;continue;}
               temp*=2;
               if(str.charAt(j)=='1') temp++;
               cal[i+1][j+1]=temp;
           }
       }

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

       for(int i=0;i<n;i++){
           for(int mask=0;mask<maxn;mask++){
               if(dp[i][mask]==0) continue;
               for(int j=i+1;j<=n;j++){
                   if(cal[i+1][j]>20) break;
                   if(cal[i+1][j]==0) continue;

                   if((mask&(1<<(cal[i+1][j]-1)))!=0) dp[j][mask] += dp[i][mask];
                   else dp[j][mask^(1<<(cal[i+1][j]-1))] += dp[i][mask];
               }
           }
       }

       long ans = 0;
       for(int i=1;i<=n;i++)
           for(int j=1;j<=20;j++)
            ans+= dp[i][(1<<j)-1];
       out.println(ans);
    }

        static class Reader {

        private InputStream mIs;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public Reader() {
            this(System.in);
        }

        public Reader(InputStream is) {
            mIs = is;
        }

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

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

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

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

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

        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 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 boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

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

    }
}


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

public class PracticeProblem
{
    public static FastReader in = new FastReader();
    public static PrintWriter out = new PrintWriter(System.out);
    public static final int MOD = (int)1e9 + 7;

    public static void main(String[] args)
    {
        int r = in.nextInt(), g = in.nextInt();
        int n = levels(r + g);

        // dp[i][j] represents the amount of combinations that can be made assuming we are at level i and have used j red blocks
        long[][] dp = new long[n + 1][r + 1];
        Arrays.fill(dp[0], 1);

        for (int level = 1; level <= n; level++)
        {
            for (int redUsed = 0; redUsed <= r; redUsed++)
            {
                int redLeft = r - redUsed;
                int greenLeft = g - ((n * (n + 1) / 2) - ((level) * (level + 1) / 2) - redUsed);
                if (redLeft >= level)
                    dp[level][redUsed] = (dp[level][redUsed] + dp[level - 1][redUsed + level]) % MOD;
                if (greenLeft >= level)
                    dp[level][redUsed] = (dp[level][redUsed] + dp[level - 1][redUsed]) % MOD;
            }
        }

        out.println(dp[n][0]);

        out.close();
    }

    private static int levels(int blocks)
    {
        int answer = 1;

        while (answer * (answer + 1) / 2 <= blocks)
            answer++;

        return --answer;
    }

    /*
     * This FastReader code is taken from GeeksForGeeks.com
     * https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
     *
     * The article was written by Rishabh Mahrsee
     */
    public static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

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


import static java.util.Arrays.deepToString;

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

public class Main {

    static long count = 0;

    static void solve() {
        long n = nextLong();
        while (n > 0) {
            n = go(n);
        }
        System.out.println(count);
    }

    private static long go(long n) {
        long t = 3;
        while (n % t == 0) {
            t = t * 3;
        }
        count++;
        return n - t;
    }

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

        setTime();
        solve();
        printTime();
        printMemory();

        writer.close();
    }

    static BufferedReader reader;
    static PrintWriter writer;
    static StringTokenizer tok = new StringTokenizer("");
    static long systemTime;

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

    static void setTime() {
        systemTime = System.currentTimeMillis();
    }

    static void printTime() {
        System.err.println("Time consumed: "
                + (System.currentTimeMillis() - systemTime));
    }

    static void printMemory() {
        System.err.println("Memory consumed: "
                + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime()
                        .freeMemory()) / 1000 + "kb");
    }

    static String next() {
        while (!tok.hasMoreTokens()) {
            String w = null;
            try {
                w = reader.readLine();
            } catch (Exception e) {
                e.printStackTrace();
            }
            if (w == null)
                return null;
            tok = new StringTokenizer(w);
        }
        return tok.nextToken();
    }

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

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

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

    static BigInteger nextBigInteger() {
        return new BigInteger(next());
    }
}


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

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

        int[] arr = new int[200000000];

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

        Arrays.sort(arr);

        if (arr[3] == (arr[0] + arr[1] + arr[2]) ||
                (arr[0] + arr[3]) == (arr[1] + arr[2])) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int[] arr = new int[4];

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

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

			System.out.println(arr[i]);
		}
		if ((arr[0] + arr[3]) == (arr[1] + arr[2])) {
			System.out.println("YES");
		}
		else if((arr[0]+arr[1]+arr[2])==arr[3])
		{
			System.out.println("YES");
		}
		else
			System.out.println("NO");

	}

	static void bubbleSort(int arr[]) {
		int n = arr.length;
		for (int i = 0; i < n - 1; i++) {
			for (int j = 0; j < n - i - 1; j++) {
				if (arr[j] > arr[j + 1]) {
					int temp = arr[j];
					arr[j] = arr[j + 1];
					arr[j + 1] = temp;
				}
			}
		}
	}

}


mport java.util.Scanner;

public class PolycarpsPockets {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int[] a = new int[n];
		int temp=0;
		for(int i=0;i<n;i++)
		{
			a[i]=scan.nextInt();
		}
		if(n>1)
		{
			temp=n/2;
			System.out.println(temp-1);
		}
		else
		{
			System.out.println("1");
		}
	}

}


package codeforcess;
import java.util.Arrays;
import java.util.Scanner;

public class Codeforcess {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int n;
        n = input.nextInt();
        int num[] = new int[n];
        for(int i=0;i<n;i++){
            num[i] = input.nextInt();
        }
        Arrays.sort(num);
        for(int i=0;i<n;i++){
            if(n==n-1){
                System.out.print(num[i]);
            }else{
                System.out.print(num[i]+" ");
            }
        }
        System.out.println();
    }

}


package div2.VolBITFormulasBlitz;

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

public class ProblemI {

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

		new ProblemI().solve(in, out);

		out.close();
	}

	public void solve(InputReader in, PrintWriter out) {
		long n = in.nextLong();

		 long res = 2 * 4 * 3 * (1l << (2 * n - 6));

         if (n >= 4) {
             res += (n - 3) * 4 * 3 * 3 * ( 1l << (2 * n - 8));
         }

         out.println(res);
	}

	static class InputReader {
		public BufferedReader br;
		public StringTokenizer st;

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

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

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

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

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

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


import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;

public class A {

    static void solve() throws IOException {
        String[] r = new String[] {
                "+------------------------+",
                "|#.#.#.#.#.#.#.#.#.#.#.|D|)",
                "|#.#.#.#.#.#.#.#.#.#.#.|.|",
                "|#.......................|",
                "|#.#.#.#.#.#.#.#.#.#.#.|.|)",
                "+------------------------+}" };
        int k = in.nextInt();
        char[][] b = new char[r.length][];
        for ( int i = 0; i < b.length; i ++ ) {
            b[i] = r[i].toCharArray();
        }
        for ( int i = 0; i < b[0].length; i ++ ) {
            for ( int j = 0; j < b.length; j ++ ) {
                if ( b[j][i] == '#' && k > 0 ) {
                    b[j][i] = 'O';
                    k --;
                }
            }
        }
        for ( char[] c : b ) {
            out.println( new String( c ) );
        }
    }

    static Scanner in;
//    static StreamTokenizer in;
    static PrintWriter out;

//    static int nextInt() throws IOException {
//        in.nextToken();
//        return ( int ) in.nval;
//    }

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


import java.util.*;
import java.io.*;
public class littleCloves3II {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
       long n=sc.nextInt();
       long m=sc.nextInt();
        if(n<m) {
            n = n + m;
            m = n - m;
            n = n - m;
        }
        int ans;
        if(m==1)
        {
            int a[]={0,0,0,2,4,6};
            ans=a[(int)((n-1)%6)]+ 6*((n-1)/6);
        }
        else if(m==2)
        {
            if (n==2)ans=0;
            else if(n==3 || n==7)  ans=m*(n-1);
            else ans=m*n;
        }
        else {
            ans=n*m;
            ans-=ans&1;
        }
        System.out.println(ans);
    }
}


import java.util.*;
import java.util.regex.Pattern;
public class Stub {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
long n = in.nextLong(); //
long m = in.nextLong();
long out = 0;
if (n+m < 5) {
    System.out.println("0"); // too small
} else {
    if (n==1 || m==1) {
        int l = n+m-1;
        int x = l/6;
        int y = 0;
        if (l%6 == 4) y+= 2;
        if (l%6 == 5) y += 4;
        out = x*6 + y;
        System.out.println(out);
        return;
    }
   out = (n*m)-(n*m)%2;
   if ((n%4 !=0) && (m%4 !=0) && (n+m)%4 == 1 && (n+m) <12) out -=2;
   if ((n+m > 9) && (n==3 || m==3) && ((n+m)%4 == 2)) out -=2;

System.out.println(out); //
}

} // end main
}