import java.util.Scanner;

public class VityaInTheCountryside {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int daysObservedCount = Integer.parseInt(scanner.nextLine().split("\\r?\\n")[0]);
        String[] observedCycleStringArray = scanner.nextLine().split(" ");

        if (observedCycleStringArray[daysObservedCount - 1].equals("0")) {
            System.out.println("UP");
            return;
        }

        if (observedCycleStringArray[daysObservedCount - 1].equals("15")) {
            System.out.println("DOWN");
            return;
        }

        if (daysObservedCount <= 1) {
            System.out.println("-1");
            return;
        }

        int lastMoonCycle = Integer.parseInt(observedCycleStringArray[daysObservedCount - 1]);
        int cycleBeforeLastMoonCycle = Integer.parseInt(observedCycleStringArray[daysObservedCount - 2]);

        String output = lastMoonCycle > cycleBeforeLastMoonCycle ? "UP" : "DOWN";
        System.out.println(output);
    }
}


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

/**
 * Created by Timur on 10.11.2016.
 */
public class _610A {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();
        if(n%2==1)
            out.print(0);
        else
            out.print((n+2)/4 - 1);

        out.close();
    }
}


import java.util.Scanner;
public class HangDepTroai {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int c = input.nextInt();
        int d=0;
        if(a<=0 || c>=11){
            System.out.println("Error");
            }
        else if(b>a && b>c && ( a==1 && c==1)){
            d = b+a+c;
            System.out.println(d);
        }
        else if(c==1 && b>a){
            d = a*(b+c);
            System.out.println(d);
        }
        else if(c>a && c>b && ( a==1 && b==1)){
            d = c*(a+b);
            System.out.println(d);
        }
        else if(a==1 && b>c){
            d = c*(a+b);
        System.out.println(d);
        }
        else if(a>1 && a==c && b==1){
            d = c*(a+b);
            System.out.println(d);
        }
        else if(a>b && a>c &&( b==1|| c==1)){
            d = a*(b+c);
            System.out.println(d);
        }
        else if(a>b && a>c && ( b>1 || c>1 )){
            d = a*b*c;
            System.out.println(d);
        }
        else if(b>a && b>c && ( a==1 || c==1)){
            d = b*(a+c);
            System.out.println(d);
        }
        else if(b>a && b>c && ( a>1 || c>1)){
            d = a*b*c;
            System.out.println(d);
        }
        else if(c>a && c>b && ( a==1 || b==1)){
            d = c*(a+b);
            System.out.println(d);
        }
        else if(c>a && c>b && ( a>1 || b>1 )){
            d = a*b*c;
            System.out.println(d);
        }
        else if(a==1 && b==1 && c==1){
            d = a+b+c;
            System.out.println(d);
        }
        else if(a==b && b==c && c==a){
            d = a*b*c;
            System.out.println(d);
        }
        else if(c==1 && b>a){
            d = a*(b+c);
            System.out.println(d);
    }
  }
}


import java.io.*;
import java.math.*;
import java.util.*;
public class TheGreatJuliaCalendarEZ {
	public static void main(String[] args) {
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int N = I.nextInt();
		long[] dp = new long[N+1];
		for (int i = 1; i<= N; i++) {
			int cur = i;
			dp[i]=(int)(1e7);
			while (cur>0) {
				int dig = cur%10;
				dp[i]=min(dp[i],dp[i-dig]+1);
				cur/=10;
			}
		}
		O.pln(dp[N]);
//O.pln(ans);
	}
	public static long min(long a, long b) {return Math.min(a,b);}
	public static long max(long a, long b) {return Math.max(a,b);}
	public static long abs(long x, long y) {return Math.abs(x-y);}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0)
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return max(a,b);
		return GCD(max(a,b),max(a,b)%min(a,b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
		double nextDouble() {return Double.parseDouble(next());}
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}


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

public class Main
{
	public static BufferedReader reader;
	public static StringTokenizer in;
	public static PrintWriter out;
	public static final double EPS = 1e-9;

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

		int n = nextInt(), R = nextInt(), r = nextInt();

		if(n == 1)
			out.print(r > R ? "NO" : "YES");
		else
		{
			double a = (R - r) * Math.sin(Math.PI / n);
			out.print(r - EPS > a ? "NO" : "YES");
		}
		out.close();
	}

	public static void get() throws IOException
	{
		while(!in.hasMoreTokens()) in = new StringTokenizer(reader.readLine());
	}

	public static int nextInt() throws IOException
	{
		get();
		return Integer.parseInt(in.nextToken());
	}
}


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

public class Main
{
    static int MOD = 1000000007;
    static int dfac[],fac[],inv[];

    public static void generateInv(int maxn)
    {
        inv = new int[maxn+1];
        inv[1] = 1;
        for (int i = 2;i <= maxn;++i)
            inv[i] = (int)((long) inv[MOD%i] * (MOD - MOD/i) % MOD);
    }

    public static int A(int n,int r)
    {
        return (int)((long)fac[n] * dfac[n-r] % MOD);
    }

    public static int quickPow(int x,int n)
    {
        long ans = 1;
        for (;n != 0;n >>= 1)
        {
            if ((n & 1) != 0) ans = ans * x % MOD;
            x = (int)((long) x * x % MOD);
        }
        return (int)ans;
    }

    public static int eat(int len,int k,int w)
    {
        long ret = A(k,len);
        int delta = len - (w - 1);
        if (delta >= 0)
        {
            ret = ret * A(k-delta,len-delta) % MOD;
        }
        else
        {
            ret = ret * A(k,len) % MOD;
            ret = ret * quickPow(k,w-1-len) % MOD;
        }
        return (int)ret;
    }

    public static int fuck(int k,int w,boolean inclusive)
    {
        long ret = 0;
        for (int i = inclusive ? 1 : 2;i <= k;++i)
            ret = (ret + eat(i,k,w)) % MOD;
        return (int)ret;
    }

    public static int gao(int k,int w)
    {
        fac = new int[k+1];
        dfac = new int[k+1];
        fac[0] = 1;
        for (int i = 1;i <= k;++i)
            fac[i] = (int)((long)fac[i-1] * i % MOD);
        generateInv(k);
        dfac[0] = 1;
        for (int i = 1;i <= k;++i)
            dfac[i] = (int)((long)dfac[i-1] * inv[i] % MOD);
        return ( (fuck(k,w+1,true) - fuck(k,w,false) ) % MOD + MOD) % MOD;
    }

    public static void main(String args[])
    {
        Scanner cin = new Scanner(System.in);
        int k = cin.nextInt(), w = cin.nextInt();
        System.out.println(gao(k,w));
    }
}


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

public class Main {

	static int MOD = 1000 * 1000 * 1000 + 7;

	public static void shuffleArray(int[] arr) {
		int n = arr.length;
		Random rnd = new Random();
		for (int i = 0; i < n; ++i) {
			int tmp = arr[i];
			int randomPos = i + rnd.nextInt(n - i);
			arr[i] = arr[randomPos];
			arr[randomPos] = tmp;
		}
	}

	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		solve3(in, out);
		out.close();
		System.exit(0);
	}

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

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

		@Override
		public int compareTo(Pair o) {
			int comp = Integer.compare(x, o.x);
			int comp2 = Integer.compare(y, o.y);
			if (comp != 0) {
				return comp;
			} else {
				return comp2;
			}
		}

	}

	private static void solve3(InputReader in, PrintWriter out) {
		int a = in.nextInt();
		int b = in.nextInt();
		int[][] dp = new int[201][201];
		for (int sum = 2; sum <= 200; sum++) {
			for (int i = 1; i <= sum; i++) {
				int j = sum - i;

				if (i - 2 >= 0 && j > 0) {
					dp[i][j] = Math.max(dp[i][j], dp[i - 2][j + 1] + 1);
				}
				if (j - 2 >= 0 && i > 0) {
					dp[i][j] = Math.max(dp[i][j], dp[i + 1][j - 2] + 1);
				}
			}
		}

		out.print(dp[a][b]);
	}

	private static void solve2(InputReader in, PrintWriter out) {
		int n = in.nextInt();
		int[] tab = new int[1002];
		for (int i = 0; i < n; i++) {
			int curr = in.nextInt();
			tab[curr]++;
		}
		int res = 0;
		int all = 0;
		for (int i = 1000; i >= 1; i--) {
			res += Math.min(tab[i], all);
			all += tab[i];
		}

		out.print(res);
	}

	private static void solve(InputReader in, PrintWriter out) {

		int n = in.nextInt();
		long a = in.nextInt();
		long b = in.nextInt();
		long T = in.nextLong();
		char[] s = in.next().toCharArray();
		long[] right = new long[n];
		long[] left = new long[n];
		right[0] = 1 + (s[0] == 'w' ? b : 0);
		left[0] = 0;

		for (int i = 1; i < n; i++) {
			long changeCost = (s[i] == 'w' ? b : 0);
			right[i] = right[i - 1] + a + changeCost + 1;
		}
		for (int i = 1; i < n; i++) {
			int pos = n - i;
			long changeCost = (s[pos] == 'w' ? b : 0);
			left[pos] = left[(pos + 1) % n] + a + changeCost + 1;
		}

		long best = 0;
		int bestL = n - 1;
		for (int i = n - 1; i >= 0; i--) { // right
			long time = right[i];
			if (time <= T) {
				best = Math.max(best, i + 1);
				long rem = T - time;
				rem -= a * i; // back time
				while (bestL > i && rem >= left[bestL]) {
					best = Math.max(best, i + 1 + (n - bestL));
					bestL--;
				}
			}
		}

		char[] tmp = new char[s.length];
		tmp[0] = s[0];
		for (int i = 1; i < n; i++) {
			tmp[i] = s[n - i];
		}
		for (int i = 0; i < n; i++) {
			s[i] = tmp[i];
		}

		// **** left
		right = new long[n];
		left = new long[n];
		right[0] = 1 + (s[0] == 'w' ? b : 0);
		left[0] = 0;

		for (int i = 1; i < n; i++) {
			long changeCost = (s[i] == 'w' ? b : 0);
			right[i] = right[i - 1] + a + changeCost + 1;
		}
		for (int i = 1; i < n; i++) {
			int pos = n - i;
			long changeCost = (s[pos] == 'w' ? b : 0);
			left[pos] = left[(pos + 1) % n] + a + changeCost + 1;
		}

		bestL = n - 1;
		for (int i = n - 1; i >= 0; i--) { // right
			long time = right[i];
			if (time <= T) {
				best = Math.max(best, i + 1);
				long rem = T - time;
				rem -= a * i; // back time
				while (bestL > i && rem >= left[bestL]) {
					best = Math.max(best, i + 1 + (n - bestL));
					bestL--;
				}
			}
		}
		out.print(best);
	}

	/*
	 *
	 */
	// --------------------------------------------------------
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

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

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

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

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

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

			return str;
		}
	}

}


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

import java.util.StringTokenizer;

public class Codeforces {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solve = new TaskA();
        solve.solve(1, in, out);
        out.close();
    }
    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
           int n = in.nextInt();
           int m = in.nextInt();

           int arr[] = new int[m];

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

           Arrays.sort(arr);

           int minimum = Integer.MAX_VALUE;

           if(m > n) {
               n--;
                for(int i = 0; i < m - n; ++i) {
                    minimum = Math.min(minimum, arr[i + n] - arr[i]);
                }
           } else if(m==n) {
               minimum = Math.min(minimum, arr[n-1] - arr[0]);
           } else {
                for(int j = 0; j < n-1; ++j) {
                    minimum = Math.min(minimum, arr[j + n-1] - arr[j]);
                }
           }

           out.println(minimum);

        }

        private static String reverse(String word) {
            String out = "";
            for(int i = word.length() -1; i >= 0; i--) {
                out += word.charAt(i);
            }
            return out;
        }
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

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

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

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

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

    }
}


import java.io.*;
import java.math.BigInteger;
import java.time.LocalDate;
import java.time.YearMonth;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.util.*;

public class Main {
    static boolean local = false;
    static FReader sc;
    static PrintWriter pw;

    public static void main(String args[]) throws FileNotFoundException {
        if (args.length != 0) {
            local = true;
            sc = new FReader("/Users/qjex/prj/jolymp/src/input.txt");
            try {
                pw = new PrintWriter(new FileOutputStream("/Users/qjex/prj/jolymp/src/output.txt"), false);
            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            sc = new FReader(System.in);
            pw = new PrintWriter(System.out);
        }
        solve();
        pw.close();
        sc.close();
    }

    public static void solve() {
        String a = sc.next(), b = sc.next();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy:MM:dd");
        LocalDate l = LocalDate.parse(a, formatter);
        LocalDate r = LocalDate.parse(b, formatter);
        pw.println(Math.abs(ChronoUnit.DAYS.between(l, r)));

    }

}

class FReader {
    BufferedReader br;
    StringTokenizer st;

    FReader(String file) {
        try {
            br = new BufferedReader(new FileReader(file));
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        st = new StringTokenizer("");
    }

    FReader(InputStream is) {
        br = new BufferedReader(new InputStreamReader(is));
        st = new StringTokenizer("");
    }

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

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

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

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

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

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

class Pair implements Comparable<Pair> {

    public int first;
    public int second;

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

    @Override
    public int compareTo(Pair pairInt) {
        if (first > pairInt.first) return 1;
        if (first < pairInt.first) return -1;
        if (second > pairInt.second) return 1;
        return second == pairInt.second ? 0 : -1;
    }

    @Override
    public boolean equals(Object obj) {
        return obj instanceof Pair && compareTo((Pair) obj) == 0;
    }
}


//I have given up the treatment-_-||
import java.util.*;
import java.math.*;
public class a{
	public static int pp[][] = new int[10][3];
	public static int mat[][] = new int[5][5];
	public static int n;
	public static void main(String[] args){
		n=3;
		Scanner cin = new Scanner(System.in);
		while(cin.hasNext()){
			for(int i=1;i<=n;i++){
				pp[i][1]=cin.nextInt();
				pp[i][2]=cin.nextInt();
			}
			getmat();
			int ans=5;
			if(pp[1][1]==pp[2][1]&&pp[2][1]==pp[3][1]){
				ans=1;
			}
			if(pp[1][2]==pp[2][2]&&pp[2][2]==pp[3][2]){
				ans=1;
			}
			if(ans==1){
				System.out.println(ans);
				continue;
			}
			ans=3;
			for(int i=1;i<=3&&ans>2;i++){
				for(int j=1;j<=3&&ans>2;j++){
					if(i==j) continue;
					for(int k=1;k<=3&&ans>2;k++){
						if(k==i||k==j) continue;
						if(gao(i,j,k)){
							ans=2;
							break;
						}
					}
				}
			}
			System.out.println(ans);
		}
		cin.close();
	}
	public static void getmat(){
		for(int i=1;i<=n;i++){
			mat[i][i]=0;
			for(int j=i+1;j<=n;j++){
				int step=getstep(i,j);
				mat[i][j]=mat[j][i]=step;
			}
		}
		return;
	}
	public static int getstep(int x,int y){
		int ret=0;
		if(pp[x][1]!=pp[y][1]) ret++;
		if(pp[x][2]!=pp[y][2]) ret++;
		return ret;
	}
	public static boolean gao(int x,int y,int z){
		if(pp[x][1]>=pp[y][1]&&pp[x][1]>=pp[z][1]&&pp[y][2]==pp[z][2]){
			return true;
		}
		if(pp[x][1]<=pp[y][1]&&pp[x][1]<=pp[z][1]&&pp[y][2]==pp[z][2]){
			return true;
		}
		if(pp[x][2]>=pp[y][2]&&pp[x][2]>=pp[z][2]&&pp[y][1]==pp[z][1]){
			return true;
		}
		if(pp[x][2]<=pp[y][2]&&pp[x][2]<=pp[z][2]&&pp[y][1]==pp[z][1]){
			return true;
		}
		return false;
	}
}


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

@SuppressWarnings("unchecked")
public class P910B {

  int n;
  TreeMap<Integer, Integer> m;

  void use(int l) {
    Integer pl = m.ceilingKey(l);

    int c = m.get(pl) - 1;
    if (c > 0) {
      m.put(pl, c);
    } else {
      m.remove(pl);
    }

    if (pl != l) {
      m.put(pl - l, m.getOrDefault(pl - l, 0) + 1);
    }
  }

  public void run() throws Exception {
    n = nextInt();
    int a = nextInt(), b = nextInt(), k = Integer.MAX_VALUE;

    for (int mm = (1 << 6) - 1; mm > 0; mm--) {
      if (Integer.bitCount(mm) != 2) { continue; }

      m = new TreeMap();
      m.put(n, 6);
      for (int mi = 1 << 5; mi > 0; mi >>= 1) {
        if ((mm & mi) == 0) {
          use(a);
        } else {
          use(b);
        }
      }

      k = Math.min(k, 6 - m.getOrDefault(n, 0));
    }

    println(k);
  }

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

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

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

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

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

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


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

public class Main {

    public static String Sleep(int hh,int mm,int hh2 ,int mm2){
        int hhout,mmout;

        if(hh<hh2&&mm<mm2){
            hhout=23-(hh2-hh);

        }
        else
        if(hh<hh2)hhout=24-(hh2-hh);
        else
        if(hh==hh2&&mm<mm2)hhout=23;
        else
        if(hh>hh2&&mm<mm2){
            hh2=hh2+1;
            hhout=hh-hh2;
        }
        else
            hhout=hh-hh2;

        if(mm<mm2){
            mmout=(60-mm2)+mm;

        }
        else
            mmout=mm-mm2;

        String outmin=mmout+"";
        if(outmin.length()==1)outmin="0"+outmin;
        String outhours=hhout+"";
        if(outhours.length()==1)outhours="0"+outhours;

        return outhours+":"+outmin;

    }

  public static void main(String[] args) throws IOException {
  BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
  String[] test= bf.readLine().split(":");

  int hh = Integer.parseInt(test[0]);
  int mm = Integer.parseInt(test[1]);

  String[] test2= bf.readLine().split(":");

  int hh2 = Integer.parseInt(test2[0]);
  int mm2 = Integer.parseInt(test2[1]);

  //Test Using the values from the buffer zeft:
  System.out.println(Sleep(hh,mm,hh2,mm2));

 }

}


import java.io.*;
import java.util.*;
public class train
{
	public static void main(String[] Args)
	{
		Scanner p = new Scanner(System.in);
		int n=p.nextInt();
		int me=p.nextInt();
		int tt=p.nextInt();
		Scanner pp=new Scanner(System.in);
		String r=p.nextLine();
		String move=p.nextLine();
		String Schedule= p.nextLine();
		char minute[]= new char[Schedule.length()];
		int ttmove=0;
		if(move.charAt(3)=='h')
		{
			ttmove=-1;
		}
		else
		{
			ttmove=1;
		}
		int c=0;
		while((c<Schedule.length())&&(me!=tt))
		{
			if(Schedule.charAt(c)=='0')
			{
				if(me>tt)
				{
					if(me!=n)
					{
						me++;
					}
					else
					{
						if((me-1)!=tt)
						{
							;
						}
					}
				}
				else
				{
					if(me!=1)
					{
						me--;
					}
					else
					{
						;
					}
				}
			}
			else
			{
				if((ttmove==1)&&(tt!=1))
				{
					me=tt-1;
				}
				else if((ttmove==1)&&(tt==1))
				{
					me=1;
				}
				else if((ttmove==-1)&&(tt!=n))
				{
					me=tt+1;
				}
				else if((ttmove==-1)&&(tt==n))
				{
					me=n;
				}
				else
				{
					me+=ttmove;
				}
			}
			c++;
			tt+=ttmove;
			if(tt==n)
			{
				ttmove=-1;
			}
			else if(tt==1)
			{
				ttmove=1;
			}
		}
		if(c==Schedule.length())
		{
			System.out.println("Stowaway");
		}
		else
		{
			System.out.println("Controller "+c);
		}
	}
}


/*
If you want to aim high, aim high
Don't let that studying and grades consume you
Just live life young
******************************
If I'm the sun, you're the moon
Because when I go up, you go down
*******************************
*/
import java.util.*;
import java.io.*;
import java.math.*;

   public class x1097D
   {
      static long MOD = 1000000007L;
      public static void main(String omkar[]) throws Exception
      {
         //BufferedReader infile = new BufferedReader(new FileReader("cowdate.in"));
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         long N = Long.parseLong(st.nextToken());
         int T = Integer.parseInt(st.nextToken());
         long P = 1L;
         long Q = 1L;
         long top = N;
         if(N <= 1000)
         for(long p=2; p <= top; p++)
         {
            int cnt = 0;
            if(N%p != 0)
               continue;
            while(N%p == 0)
            {
               cnt++;
               N /= p;
            }
            long[] pow = new long[cnt+1];
            pow[0] = 1L;
            for(int i=1; i <= cnt; i++)
               pow[i] = (pow[i-1]*p)%MOD;
            long[][] dp = new long[cnt+1][T+1];
            for(int i=0; i <= cnt; i++)
               dp[i][0] = pow[i];
            for(int t=1; t <= T; t++)
            {
               long sum = 0L;
               for(int i=0; i <= cnt; i++)
               {
                  sum = (sum+dp[i][t-1])%MOD;
                  dp[i][t] = (sum*power(i+1, MOD-2, MOD))%MOD;
               }
            }
            long num = dp[cnt][T];
            //long denom = power(cnt+1, T, MOD);
            P = (P*num)%MOD;
            //Q = (Q*denom)%MOD;
         }
         else
         {
         for(long p=2; p*p <= top; p++)
         {
            int cnt = 0;
            if(N%p != 0)
               continue;
            while(N%p == 0)
            {
               cnt++;
               N /= p;
            }
            long[] pow = new long[cnt+1];
            pow[0] = 1L;
            for(int i=1; i <= cnt; i++)
               pow[i] = (pow[i-1]*p)%MOD;
            long[][] dp = new long[cnt+1][T+1];
            for(int i=0; i <= cnt; i++)
               dp[i][0] = pow[i];
            for(int t=1; t <= T; t++)
            {
               long sum = 0L;
               for(int i=0; i <= cnt; i++)
               {
                  sum = (sum+dp[i][t-1])%MOD;
                  dp[i][t] = (sum*power(i+1, MOD-2, MOD))%MOD;
               }
            }
            long num = dp[cnt][T];
            //long denom = power(cnt+1, T, MOD);
            P = (P*num)%MOD;
            //Q = (Q*denom)%MOD;
         }
         if(N > 1)
         {
            int cnt = 1;
            //if(N%p != 0)
            //   continue;
            //while(N%p == 0)
            //{
             //  cnt++;
              // N /= p;
            //}
            long p = N;
            long[] pow = new long[cnt+1];
            pow[0] = 1L;
            for(int i=1; i <= cnt; i++)
               pow[i] = (pow[i-1]*p)%MOD;
            long[][] dp = new long[cnt+1][T+1];
            for(int i=0; i <= cnt; i++)
               dp[i][0] = pow[i];
            for(int t=1; t <= T; t++)
            {
               long sum = 0L;
               for(int i=0; i <= cnt; i++)
               {
                  sum = (sum+dp[i][t-1])%MOD;
                  dp[i][t] = (sum*power(i+1, MOD-2, MOD))%MOD;
               }
            }
            long num = dp[cnt][T];
            //long denom = power(cnt+1, T, MOD);
            P = (P*num)%MOD;

         }
         }
         long res = (P*power(Q, MOD-2, MOD))%MOD;
         System.out.println((P+MOD)%MOD);
      }
      public static long power(long x, long y, long p)
      {
          long res = 1L;
          x = x % p;
          while (y > 0)
          {
              if((y & 1)==1)
                  res = (res * x) % p;
              y = y >> 1;
              x = (x * x) % p;
          }
          return res;
      }
   }


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

public class Date {

	public static void main(String[] args) {

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

		final int x;
		final int y;
		final int steps;
		try {
			String first = br.readLine();
			String[] suh = first.split(" ");
			x = Integer.parseInt(suh[0]);
			y = Integer.parseInt(suh[1]);
			steps = Integer.parseInt(suh[2]);
			Solver sol = new Solver();

			sol.solve(x, y, steps);

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

}

class Solver {

	public void solve(int x, int y, int stps) {
		int minSteps = Math.abs(x) + Math.abs(y);

		if ((minSteps - stps) % 2 == 0 && minSteps <= stps)
		{
			System.out.println("Yes");
		}
		else
		{
			System.out.println("No");
		}

	}

}


import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Random;
import java.util.StringTokenizer;

public class C {

	static StringBuilder decToTer(int x) {
		StringBuilder ret = new StringBuilder();
		while (x > 0) {

			int cur = x % 3;
			ret.append(cur);
			x /= 3;
		}

		return (ret.reverse());
	}

	static int terToDec(StringBuilder x) {
		int ret = 0;
		for (int i = x.length() - 1; i >= 0; i--) {
			ret += (Integer.parseInt(x.charAt(i) + "") * Math.pow(3, x.length() - i - 1));
		}
		return ret;
	}

	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int c = sc.nextInt();
		StringBuilder A = decToTer(a);
		StringBuilder C = decToTer(c);
		while (A.length() < C.length())
			A.insert(0, "0");
		while (C.length() < A.length())
			C.insert(0, "0");
		StringBuilder B = new StringBuilder();
		for (int i = 0; i < A.length(); i++) {
			for (int k = 0; k < 3; k++) {
				if ((Integer.parseInt(A.charAt(i) + "") + k) % 3 == (Integer.parseInt(C.charAt(i) + ""))) {
					B.append(k);
					break;
				}
			}
		}
		System.out.println(terToDec(B));

	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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

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

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

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

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

		public int[] nextIntArraySorted(int n) throws IOException {
			int[] a = nextIntArray(n);
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				int t = a[i];
				a[i] = a[j];
				a[j] = t;
			}
			Arrays.sort(a);
			return a;
		}

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

		public long[] nextLongArray1(int n) throws IOException {
			long[] a = new long[n + 1];
			for (int i = 1; i <= n; i++)
				a[i] = nextLong();
			return a;
		}

		public long[] nextLongArraySorted(int n) throws IOException {
			long[] a = nextLongArray(n);
			Random r = new Random();
			for (int i = 0; i < n; i++) {
				int j = i + r.nextInt(n - i);
				long t = a[i];
				a[i] = a[j];
				a[j] = t;
			}
			Arrays.sort(a);
			return a;
		}
	}
}


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

public class Main4 {
    static MyScanner sc;

    public static void main(String[] args) {
        sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

//        unitTests();

        //Ciel and Flowers
        solution();
    }

    private static void unitTests() {
        startTest(0, 0, 0, 0);
        startTest(0, 2, 2, 0);
        startTest(0, 0, 3, 1);
        startTest(0, 3, 3, 2);
        startTest(1, 3, 3, 2);
        startTest(1, 4, 4, 3);
        startTest(1, 1, 1, 1);
        startTest(2, 2, 2, 2);
        startTest(2, 4, 4, 3);
        startTest(4, 4, 4, 4);
        startTest(14, 14, 14, 14);
    }

    private static void startTest(long r, long g, long b, long count) {
        long bouketsCount = solutionWithParams(r, g, b);
        if (bouketsCount != count) {
            long bouketsCount2 = solutionWithParams(r, g, b);
        }
    }

    private static void solution() {
        long r = sc.nextLong();
        long g = sc.nextLong();
        long b = sc.nextLong();

        long bouketsCount = solutionWithParams(r, g, b);

        out.println(bouketsCount);
        out.close();

    }

    private static long solutionWithParams(long r, long g, long b) {
        long bouketsCount = 0;

        long minCount = r > g ? g : r;
        minCount = minCount > b ? b : minCount;

        long countToCut = minCount;
        if (countToCut > 2) {
            countToCut = 2;
        }

        minCount -= countToCut;
        if (minCount < 0) {
            minCount = 0;
        }

        long threeCeil = minCount - minCount % 3;
        bouketsCount += threeCeil;

        r -= threeCeil;
        g -= threeCeil;
        b -= threeCeil;

        if (r > 2 + countToCut) {
            long rThreeCeil = (r - countToCut) / 3;
            bouketsCount += rThreeCeil;
            r -= 3 * rThreeCeil;
        }

        if (g > 2 + countToCut) {
            long gThreeCeil = (g - countToCut) / 3;
            bouketsCount += gThreeCeil;
            g -= 3 * gThreeCeil;
        }

        if (b > 2 + countToCut) {
            long bThreeCeil = (b - countToCut) / 3;
            bouketsCount += bThreeCeil;
            b -= 3 * bThreeCeil;
        }

        while (r > countToCut && b > countToCut && g > countToCut) {
            bouketsCount++;
            r--;
            g--;
            b--;
        }

        //now all values are [2..4]
        if (r + g + b >= 10) {//442
            bouketsCount += 3;
        } else if (countToCut > 1) {
            bouketsCount += 2;
        } else if (countToCut > 0 && r + g + b >= 7) {
            bouketsCount += 2;
        } else if (countToCut > 0) {
            bouketsCount += 1;
        }

        return bouketsCount;
    }

    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;

    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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

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

        int 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;
        }

        String nextString(int length) {
            String str = "";
            try {
                char[] buff = new char[length];
                br.read(buff);
                str = new String(buff);
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }

    }
    //--------------------------------------------------------
}


import java.util.*;
import java.lang.*;
import java.io.*;
public class fence
{
    public static void main (String[] args) throws java.lang.Exception
	{

 Scanner sc =new Scanner(System.in);
	int t=0;
	t=sc.nextInt();
int s=t,y=t;
    int w=0;int e=-1;
		   int r=0;
		   while(s>0)
		   {
		       r=s%10;
		       w=w+r;
		       s=s/10;
		   }
		   if(w%4==0)
		   {
		       System.out.println(t);

		   }
		   else
		   {

		       while(e==-1)
		       {

		           y++;
		           int u=y;
		           w=0;
		            while(u>0)
		            {

		             w=w+u%10;
		              u=u/10;
                    }

		            if(w%4==0)
		            {
		                    System.out.println(y);
		                 e=0;
		             break;
		            }
		       }
		   }
	}
}


import java.util.*;
import java.io.*;
import java.math.BigInteger;
public class Tester {
	public static void main(String args[])
	{
		InputReader in = new InputReader(System.in);
		OutputStream outputStream = System.out;
		PrintWriter out = new PrintWriter(outputStream);
		String s=in.next();
		int i,j;
		char arr[]=s.toCharArray();
		char arr1[]=new char[s.length()];
		for(i=0;i<arr.length;)
		{
			if(arr[i]=='/')
			{
				for(i=i+1;i<arr.length;i++)
				{
					if(arr[i]=='/')
						arr[i]='.';
					else
						break;
				}
			}
			else
				i++;
		}
		int count=0;
		for(i=0;i<arr.length;i++)
		{
			if(arr[i]!='.')
			{
				arr1[count]=arr[i];
				count++;
			}
		}
		if(count==1)
			out.print(arr1[0]);
		else
		{
			if(arr1[count-1]=='/')
				arr1[count-1]='.';
			for(i=0;i<count;i++)
			{
				if(arr1[i]!='.')
				{
					out.print(arr1[i]);
				}
			}
		}
		out.close();
	}
	static class Pair implements Comparable<Pair>
	{
		//Iterator it = h.entrySet().iterator();
//	    while (it.hasNext()) {
//	        Map.Entry pair = (Map.Entry)it.next();
//	      //  System.out.println(pair.getKey() + " = " + pair.getValue());
//	        it.remove(); // avoids a ConcurrentModificationException
//	    }
		private int  first;
		private int index;
		//private long second;;

		public Pair(int i, int j)
		{
			this.first = i;
			this.index = j;
		}
		public int getFirst() { return first; }
		//public long getSecond() { return second; }
		public int getIndex() { return index ;}
		public void setFirst(int k) { this.first=k ; }
		public void setIndex(int k) { this.index=k ;}
		//public void setSecond(long k) { this.second=k ;}
		@Override
		public int compareTo(Pair o)
		{
			return Integer.compare(o.first,this.first);
		}
	}
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

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

		public String nextLine(){
			String fullLine=null;
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					fullLine=reader.readLine();
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
				return fullLine;
			}
			return fullLine;
		}
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}


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

public class PrimesOnInterval{

	static boolean[] isPrime;
	public static void sieve()
	{
		isPrime = new boolean[1000005];
		Arrays.fill(isPrime, true);
		isPrime[0] = isPrime[1] = false;

		for (int i = 2; i < isPrime.length; i++) {
			if(!isPrime[i])
				continue;
			for (int j = i * 2; j < isPrime.length; j += i)
				isPrime[j] = false;
		}

	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int k = Integer.parseInt(st.nextToken());
		sieve();
		int count = 0;
		int idx = a;
		while(count < k && idx <= b)
		{
			if(isPrime[idx++])
				count++;
		}
		if(count != k)
		{
			System.out.println(-1);
			return;
		}

		int minL = idx - a;
		int end = idx;
		int i = a;
		for (; i <= b && end <= b; i++, end++)
		{
			while(i <= b && i <= end && !isPrime[i])i++;
			while(end <= b && !isPrime[end])end++;

			minL = Math.max(minL, end - i);
		}
		System.out.println(minL);
	}
}


import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.util.Scanner;
import java.lang.Math.*;

public class Main {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner cin = new Scanner(new BufferedInputStream(System.in));
        PrintWriter cout = new PrintWriter(new BufferedOutputStream(System.out));
        Task work = new Task(cin, cout);
        work.solve();
        cout.flush();
    }

}
class Task{
    Scanner cin;
    PrintWriter cout;
    final int maxn = 400005;
    final int MOD = 1000000007;
    int []dp = new int[maxn];
    int r, g;
    public Task(Scanner cin, PrintWriter cout) {
        // TODO Auto-generated constructor stub
        this.cin = cin;
        this.cout = cout;
        r = cin.nextInt();
        g = cin.nextInt();
    }
    public void read() {
        r = cin.nextInt();
        g = cin.nextInt();
    }
    int GetHeight(){
        for (int i = 1; ; i++){
            if (i * (i + 1) / 2 > r + g){
                return i-1;
            }
        }
    }
    public void solve(){
        int h = GetHeight();
        int res = 0;
        dp[0] = 1;
        for (int i = 1; i <= h; i++){
            for (int j = r; j >= 0; j--){
                dp[i+j] = (dp[i+j] + dp[j]) % MOD;
            }
        }
        for (int i = Math.max(h*(h+1)/2 - g, 0); i <= r; i++){
            res = (res + dp[i]) % MOD;
        }
        cout.println(res);
    }
}


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

import javax.tools.ToolProvider;

public class knapsack {
	static int a[];
	static int n;
	static int memo[][];

	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		Scanner sc=new Scanner(System.in);
		long n=sc.nextLong();
		int count=1;

		while(n-count>0) {
			n-=count;
			count++;
		}
		System.out.println(n);
	}

	static class Scanner {

        BufferedReader br;
        StringTokenizer st;

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

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

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

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

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

	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

    public static Scanner input = new Scanner(System.in);

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

        // BufferedReader buffer=new BufferedReader(new InputStreamReader(System.in));
        //  String str;
//         while((str=buffer.readLine())!=null){
        PrintWriter writer = new PrintWriter(new OutputStreamWriter(System.out));
//while(input.hasNextLine()){
       // Scanner sc=new Scanner(System.in);
                int t=input.nextInt();
                int r=input.nextInt();
                writer.println(Math.min((t+r)/3, Math.min(t, r)));
                writer.flush();

    }}


import java.util.Scanner;

public class kFactorization_797A {
	public static boolean prime(int n) {
		if(n==1)
			return false;
		if(n==2)
			return true;
		for(int i=2;i<n;i++)
			if(n%i==0)
				return false;
		return true;
	}
public static void main(String[]   args) {
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int k=sc.nextInt();
	int []res=new int[k];
	int c=0;
	int p=1;

		while(p<n) {
			if(prime(p) && n%p==0) {
				res[c++]=p;
			    n=n/p;
		     }
			else
		       p+=1;
			if(c==k-1) {
				res[c++]=n;
				break;
			}
			if(prime(n)) {
				res[c++]=n;
			     break;
		}

		}
		if(c==k) {
			for(int i=0;i<c;i++)
				System.out.print(res[i]+" ");
				System.out.println();

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

}
}


import java.util.Scanner;
public class Solution {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int x = scan.nextInt();
		int y = scan.nextInt();
		int z = scan.nextInt();
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		String result = "YES";
		if(x > a) {
			result = "NO";
		} else {
			a -= x;
			if(y > a + b) {
				result = "NO";
			} else {
				int k = a + b - y;
				if(z > k + c) {
					result = "NO";
				}
			}
		}
		System.out.println(result);
	}
}


//package school3;

import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class A {
	Scanner in;
	PrintWriter out;
	String INPUT = "";

	void solve()
	{
		Map<String, Integer> map = new HashMap<String, Integer>();
		String[] x = {"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"};
		for(int i = 0;i < x.length;i++){
			map.put(x[i], i);
		}

		String mon = in.next();
		int n = ni();
		out.println(x[(map.get(mon) + n) % 12]);
	}

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

		solve();
		out.flush();
	}

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

	int ni() { return Integer.parseInt(in.next()); }
	void tr(Object... o) { if(INPUT.length() != 0)System.out.println(o.length > 1 || o[0].getClass().isArray() ? Arrays.deepToString(o) : o[0]); }
}


import java.util.*;

public class may16 {

	public static void main(String[] args) {

		Scanner s=new Scanner(System.in);
		//System.out.println("enter n");
		int n=s.nextInt();
		int count=n;
		for(int i=1; i<=n-1; i++)
		{
			count=count + (n-i)*i;
		}
		System.out.println(count);
	}
}


import java.util.*;
public class Main {
    public static void main(String[] args)
    {
        int n = new Scanner (System.in).nextInt() ; int c = 0 ; int sum = 1 ;
        for (int i=1 ; sum<=n ; i++)
        {
            c++;
            sum+=i;
            n-=sum;
        }
        System.out.println(c);
    }
}


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

public class Main {

    public static void main(String[] args) throws IOException{
        Scanner sc = new Scanner(System.in);//new File("input.txt"));
        PrintWriter pw = new PrintWriter(System.out);//new File("output.txt"));
        int n = sc.nextInt();
        int x = n;
        int m = 0;
        while (x > 0)
        {
            x /= 10;
            m++;
        }
        long ans = (long)n*m + m - 1;
        long k = 1;
        for (int i = 0; i < m-1; i++)
        {
            k *= 10;
            ans -=k;
        }
        pw.println(ans);
       pw.close();
    }
}


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

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

    static class D {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long n = in.ni(), k = in.ni();
            long a = in.ni(), b = in.ni();
            long nk = n * k;
            long x = Long.MAX_VALUE;
            long y = 0;
            for (int i = 0; i <= n + 2; i++) {
                long l = a + b + k * i;
                long ans = nk / IntegerUtils.gcd(nk, l);
                x = Math.min(x, ans);
                y = Math.max(y, ans);

                l = a - b + k * i;
                if (l > 0) {
                    ans = nk / IntegerUtils.gcd(nk, l);
                    x = Math.min(x, ans);
                    y = Math.max(y, ans);
                }

                l = b - a + k * i;
                if (l > 0) {
                    ans = nk / IntegerUtils.gcd(nk, l);
                    x = Math.min(x, ans);
                    y = Math.max(y, ans);
                }

                l = -a - b + k * i;
                if (l > 0) {
                    ans = nk / IntegerUtils.gcd(nk, l);
                    x = Math.min(x, ans);
                    y = Math.max(y, ans);
                }
            }
            out.print(x + " " + y);
        }

    }

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

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

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

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

    }

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

    }
}


import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Main
{
	public static void main(String[] args)throws IOException {
	    BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(System.out));
        int n=Integer.parseInt(br.readLine());
        int[][] arr=new int[n][n];
        int sum=0;
        for(int i=0;i<n;i++)
        {
            String[] str=br.readLine().split(" ");
            for(int j=0;j<n;j++)
            {
                arr[i][j]=Integer.parseInt(str[j]);
                if(i==j)
                    sum+=arr[i][j];
                if(i+j==n-1)
                    sum+=arr[i][j];
            }
        }
        for(int i=0;i<n;i++)
        {
            sum+=arr[n/2][i];
            sum+=arr[i][n/2];
        }
        sum=sum-(3*arr[n/2][n/2]);
        bw.write(sum+"\n");
	 bw.flush();
	}
}


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

public class lab864B {
    public static void main(String args[]) throws IOException {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            int n = in.nextInt();
            String arr = in.next();
            String s[] = arr.split("[A-Z]");
            Set set = new HashSet();
            int min = 0;
            for (int i = 0; i < s.length; i++) {
                for (int b = 0; b < s[i].length(); b++) {
                    set.add(s[i].charAt(b));
                }
                if (set.size() > min) {
                    min = set.size();
                }
                set.clear();
            }
            System.out.println(min);
        }
    }
}


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

public class Solution{
    public static void main(String []args){
        long d1,d2,d3,dis1,dis2,dis3,dis4;
        Scanner scan=new Scanner(System.in);
        d1=scan.nextInt();
        d2=scan.nextInt();
        d3=scan.nextInt();
        dis1=d1+d2+d3;
        dis2=d1+d3+d3+d1;
        dis3=d2+d3+d3+d2;
        dis4=d1+d1+d2+d2;
        System.out.println(Math.min(dis1,Math.min(dis2,Math.min(dis3,dis4))));
    }
}


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

public class Dummy {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        //variable
        int t = in.nextInt();
        int n,k,d;
        int ans[] = new int[t];

        //variable
        for (int i=0; i<t; i++) {

            n = in.nextInt();
            int tv[] = new int[n];
            Set<Integer> s = new HashSet<Integer>();
            k = in.nextInt();
            d = in.nextInt();
            ans[i] = k;
            for (int j = 0; j < n; j++) {
                tv[j] = in.nextInt();
            }
            for (int j = 0; j < n; j++) {
                for (int z = 0; z < d; z++) {
                    if (j+z<n){
                        s.add(tv[j + z]);
                    }
                }
                //System.out.println("set size=" +s.size());
                if (s.size() < ans[i]) {
                    ans[i] = s.size();
                }
                s.clear();
                if (j+d>=n){
                    break;
                }
            }

        }
        for (int i=0; i<t; i++){
            System.out.println(ans[i]);
        }

    }
}


import java.util.*;
public class A70 {
	public static void main(String args[]){

		Scanner in = new Scanner(System.in);

		int n = in.nextInt();

		if (n==0) System.out.println("1");
		else{
			int sum = 1;
			while(n>1){
				sum=sum*3%1000003;
				n--;
			}
			System.out.println(sum);
		}
	}

}


import java.util.*;

public class C304C {

    static Vector<Vector<Integer>> hash1 = new Vector() , hash2 = new Vector();

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();

        Vector<Integer> v1 = new Vector<Integer>() , v2 = new Vector();
        for(int i = 0;i < k;i ++)v1.add(in.nextInt());

        k = in.nextInt();

        for(int i = 0;i < k;i ++)v2.add(in.nextInt());

        /*if(v1.size() != v2.size()){
            System.out.println(-1);
            return;
        }*/

        hash1.add(v1); hash2.add(v2);

        int sum = 0;
        while(true){
            if(v1.get(0) > v2.get(0)){
                v1.add(v2.remove(0)); v1.add(v1.remove(0));
            }else{
                v2.add(v1.remove(0)); v2.add(v2.remove(0));
            }

            sum ++;
            if(v1.size() == 0 || v2.size() == 0)break;

            if(sum > 200000){
                System.out.println(-1);
                return ;
            }

        }

        System.out.println(sum + " " + (v1.size() == 0?2:1));
    }

}


import java.util.*;

public class Solution{

    public static void main(String args[]){

        Scanner scan = new Scanner(System.in);

        int limar = scan.nextInt();
        int bob = scan.nextInt();
        int years = 0;
        while(limar<=bob){
            years++;
            limar=limar*3;
            bob=bob*2;
        }
        System.out.println(years);
    }
}


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

public class ne {
	static class Reader1 {
	    static  BufferedReader reader;
	    static StringTokenizer tokenizer;

	    /** call this method to initialize reader for InputStream */
	    static void init(InputStream input) {
	        reader = new BufferedReader(
	                     new InputStreamReader(input) );
	        tokenizer = new StringTokenizer("");
	    }

	    /** get next word */
	    static String next() throws IOException {
	        while ( ! tokenizer.hasMoreTokens() ) {
	            //TODO add check for eof if necessary
	            tokenizer = new StringTokenizer(
	                   reader.readLine() );
	        }
	        return tokenizer.nextToken();
	    }

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

	    static double nextDouble() throws IOException {
	        return Double.parseDouble( next() );
	    }
	    static float nextFloat() throws IOException {
	        return Float.parseFloat( next() );
	    }
	    static long nextLong() throws IOException {
	        return Long.parseLong( next() );
	    }}
public static void main(String[] args) throws IOException{

		Reader1.init(System.in);
		int n=Reader1.nextInt();
		int m=Reader1.nextInt();
		int[] a= new int[m+n];
		for(int i=0;i<m+n;i++)
			a[i]=-1;
		int m1=m;
		int n1=n;
		n1--;
		//Starting with n=1 and m=0
		a[0]=1;
		for(int i=1;i<m+n;i++)
		{
					if(i%2==0)
					{
						if(a[i-1]==1)
							{if(n1>0)
								{a[i]=1;n1--;}
							else
								{a[i]=0;m1--;}}
						else
						{
							if(m1>0)
							{a[i]=0;m1--;}
						else
							{a[i]=1;n1--;}}

					}
					else
					{
						if(a[i-1]==1)
							{if(m1>0)
								{a[i]=0;m1--;}
							else
								{a[i]=1;n1--;}}

						else
							{if(a[i-1]==0)
							{if(n1>0)
								{a[i]=1;n1--;}
							else
								{a[i]=0;m1--;}}}

					}

}
		//n
//		for(int i=0;i<m+n;i++)
//			System.out.print(a[i]+" ");

		int count=0;
		for(int i=0;i<m+n-1;i++)
		{
			if((a[i]^a[i+1])==0)
				count++;

		}
		 m1=m;
		n1=n;
		//m-0
		a[0]=0;
		m1--;
		for(int i=1;i<m+n;i++)
		{
					if(i%2==0)
					{
						if(a[i-1]==1)
							{if(n1>0)
								{a[i]=1;n1--;}
							else
								{a[i]=0;m1--;}}
						else
						{
							if(m1>0)
							{a[i]=0;m1--;}
						else
							{a[i]=1;n1--;}}

					}
					else
					{
						if(a[i-1]==1)
							{if(m1>0)
								{a[i]=0;m1--;}
							else
								{a[i]=1;n1--;}}

						else
							{if(a[i-1]==0)
							{if(n1>0)
								{a[i]=1;n1--;}
							else
								{a[i]=0;m1--;}}}

					}

}	int count1=0;
		for(int i=0;i<m+n-1;i++)
		{
			if((a[i]^a[i+1])==0)
				count1++;

		}

		//m
//				for(int i=0;i<m+n;i++)
//					System.out.print(a[i]+" ");

		int count2=0;
		if(count1>count)
			count2=count1;
		else
			count2=count;
		int k=m+n-1-count2;
		System.out.println(count2+" "+ k);

}

}//5 5 ans should be 0 9
// 5 4 ans should be 1 7


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

public class q_3 {
    static Scanner sc;

    public static void main(String[] args){
        sc = new Scanner(System.in);
        int n = getInt();
        int[] arr = new int[n/2];
        for(int i=0 ; i<n/2 ; i++){
            arr[i] = getInt()-1;
        }
        Arrays.sort(arr);
        // all black
        int c=  0;
        long bb = 0l;
        for(int i=0 ; i<n/2 ; i++ , c+=2){
            bb+=Math.abs(arr[i]-c);
        }
        long ww = 0l;
        c = 1;
        for(int i=0 ; i<n/2 ; i++ , c+=2){
            ww+=(Math.abs(arr[i] - c));
        }
        System.out.println(Math.min(bb,ww));

    }

    public static int getInt(){
        return sc.nextInt();
    }

    public static String getString(){
        return sc.next();
    }

    public static String nextLine(){
        return sc.nextLine();
    }

    public static long nextLong(){
        return sc.nextLong();
    }

}


import java.util.Scanner;
public class BearAndFindingCriminal {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int crim = 0;
		sc.nextLine();
		int city [] = new int [n+1];
		for (int i = 1; i <= n; i++) {
			city[i] = sc.nextInt();
		}
		if (city[a] == 1) {
			crim++;
		}
		if (n/2 >= a) {
			for (int i = 2*a; i <= n; i++) {
				if (city[i] == 1) {
					crim++;
				}
			}
			for (int i = a + 1; i < 2*a; i++) {
				if (city[i] == 1 && city[i] == city[2*a - i]) {
					crim += 2;
				}
			}
		} else {
			for (int i = 1; i < 2*a-n; i++) {
				if (city[i] == 1) {
					crim++;
				}
			}
			for (int i = a + 1; i <= n; i++) {
				if (city[i] == 1 && city[i] == city[2*a - i]) {
					crim += 2;
				}
			}
		}
		System.out.println(crim);}
	}


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

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

	void solve()
	{
		long n = nl();
		int m = Long.toString(n).length();
		int[] f = new int[10];
		for(char c : Long.toString(n).toCharArray()){
			f[c-'0']++;
		}

		int M = 1;
		for(int i = 0;i < 10;i++){
			f[i]++;
			M *= f[i];
		}

		long[] dp = new long[M];
		dp[0] = 1;
		long ans = 0;
		for(int k = 1;k <= m;k++){
			long[] ndp = new long[M];

			int[] b = new int[10];
			int id = 0;
			do{
				for(int j = 0;j <= 9;j++){
					if(b[j] + 1 < f[j]){
						b[j]++;
						if(j >= 1){
							boolean ok = true;
							for(int t = 0;t < 10;t++){
								if(f[t] == 1 || b[t] >= 1){
								}else{
									ok = false;
								}
							}
							if(ok)ans += dp[id];
						}
						ndp[(int)encInc(b, f)] += dp[id];
						b[j]--;
					}
				}
				id++;
			}while(inc(b, f));
			dp = ndp;
		}
		out.println(ans);
	}

public static boolean inc(int[] b, int[] a)
{
	for(int i = b.length-1;i >= 0;i--){
		if(++b[i] < a[i])return true;
		b[i] = 0;
	}
	return false;
}

	public static long encInc(int[] a, int[] lim)
	{
		long code = 0;
		for(int i = 0;i < a.length;i++){
			code = code * lim[i] + a[i];
		}
		return code;
	}

	public static int[] decInc(long code, int[] lim)
	{
		int n = lim.length;
		int[] a = new int[n];
		for(int i = n-1;i >= 0;i--){
			a[i] = (int)(code % lim[i]);
			code /= lim[i];
		}
		return a;
	}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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


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

public class Smile {
	static Scanner in;
	static PrintWriter out;

	public static void main(String[] args) {
		in = new Scanner(System.in);
		out = new PrintWriter(System.out);
		int n = in.nextInt();
		int d = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		Arrays.sort(a);
		int m = in.nextInt();
		int temp = Math.min(n, m);
		int ans = 0;
		for (int i = 0; i < temp; i++) {
			ans += a[i];
		}
		if (m > temp) {
			ans = ans - d * (m - temp);
		}
		out.println(ans);
		out.close();
}
}


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

public class Main{

public static int[] res;
public static int cont;

public static void main(String [] args) throws Exception{
BufferedReader entrada = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(entrada.readLine());
res= new int[n];
cont=0;
s(n);
StringBuilder sb = new StringBuilder();
sb.append(n+" ");
for(int i=0;i<cont;i++)
sb.append(res[i]+" ");
System.out.println(sb.toString().trim());
}

public static void s(int n){
    for(int i=n-1;i>=1;i--)
        if(n%i==0){
            res[cont++]=i;
            s(i);
            return;
        }
}

}


import java.util.*;

public class A{

    public static void main(String args[]){
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int a[]=new int[n];
        for(int i=0;i<n;i++)
           a[i]=s.nextInt();
        int sm=0;
        Arrays.sort(a);
        for(int i=0;i<n-1;i+=2)
           sm+=a[i+1]-a[i];
        System.out.println(sm);
    }
}


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

public class EightEightEightB {
    byte inputCommNum;
    int answer = 0;
    String commands;

    public static void main (String[] args) {
        EightEightEightB c = new EightEightEightB();
        c.readParams();
        c.solve();

        System.out.println(c.getAnswer());
    }

    private void solve() {
        int ls = 0;
        int rs = 0;
        int us = 0;
        int ds = 0;
        for (byte i = 0; i < commands.length(); i++) {
            char c = commands.charAt(i);
            switch (c) {
                case 'U':
                    us++;
                    break;
                case 'D':
                    ds++;
                    break;
                case 'L':
                    ls++;
                    break;
                case 'R':
                    rs++;
                    break;
                default:
                    break;
            }
        }
        if (ls == 0 || rs == 0) {
            answer = 2 * Math.min(us, ds);
        } else if (us == 0 || rs == 0) {
            answer = 2 * Math.min(ls, rs);
        } else {
            answer = (byte) (2 * (Math.min(ls, rs) + Math.min(us, ds)));
        }
    }

    private void readParams() {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            inputCommNum = Byte.parseByte(br.readLine());
            commands = br.readLine();
        } catch (IOException e) {
            return;
        }
    }

    public int getAnswer() {
        return answer;
    }

}


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

public class Main {
    public static void main(String args[]) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader inputReader = new InputReader(inputStream);
        PrintWriter printWriter = new PrintWriter(outputStream);
        TaskSolver solver = new TaskSolver(inputReader, printWriter);
        solver.solve();
        printWriter.close();
    }
}

class TaskSolver {
    private InputReader in;
    private PrintWriter out;

    public TaskSolver(InputReader inputReader, PrintWriter printWriter) {
        in = inputReader;
        out = printWriter;
    }

    public void solve() {
        int a = in.nextInt();
        int b = in.nextInt();
        int m = in.nextInt();
        int r0 = in.nextInt();
        int[] r = new int[ (int) 1e+6];
        int[] check = new int[ (int) 1e+6];
        Arrays.fill(check, -1);
        r[0] = (a * r0 + b) % m;
        check[r[0]] = 0;
        int res = 0;
        for (int i = 1; ; i++) {
            r[i] = (a * r[i - 1] + b) % m;
            if (check[r[i]] == -1) {
                check[r[i]] = i;
            } else {
                res = i - check[r[i]];
                break;
            }
        }
        out.print(res);
    }
}

class InputReader {
    private BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

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


import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;

public class Main {

	private static StreamTokenizer inputReader = new StreamTokenizer(
			new BufferedReader(new InputStreamReader(System.in)));

	public static int nextInt() {
		int a = -1;
		try {
			inputReader.nextToken();
			a = (int) inputReader.nval;
		} catch (Exception e) {
		}
		return a;
	}

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

		int[] xs = new int[n];
		int[] ys = new int[n];

		int minX = Integer.MAX_VALUE;
		int maxX = Integer.MIN_VALUE;
		int minY = Integer.MAX_VALUE;
		int maxY = Integer.MIN_VALUE;

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

			if (x < minX) {
				minX = x;
			}

			if (x > maxX) {
				maxX = x;
			}

			if (y < minY) {
				minY = y;
			}

			if (y > maxY) {
				maxY = y;
			}
		}

		int diffX = maxX - minX;
		int diffY = maxY - minY;

		int area = diffX * diffY;

		if (area == 0) {
			System.out.println(-1);
		} else {
			System.out.println(Math.abs(area));
		}

	}

	private static class Pair implements Comparable<Pair>{
		int x;
		int y;

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

		@Override
		public int compareTo(Pair other) {
			if (this.x != other.x) {
				return Integer.compare(this.x, other.x);
			}

			return Integer.compare(this.y, other.y);
		}
	}

}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;

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

    static class APaintTheNumbers {
        public void solve(int testNumber, Scanner in, PrintWriter out) {

            int n = in.nextInt();

            int[] A = new int[n];
            for (int i = 0; i < n; i++) {
                int c = in.nextInt();

                A[i] = c;
            }

            Arrays.sort(A);

            boolean rem[] = new boolean[n];
            int count = 0;
            for (int i = 0; i < n; i++) {
                if (rem[i]) continue;
                for (int j = i; j < n; j++) {
                    if (rem[j]) continue;
                    if (A[j] % A[i] == 0) {
                        rem[j] = true;
                    }
                }
                count++;
            }
            out.println(count);

        }

    }
}


import java.util.*;

public class WhereDoITurn227A
{
    public static void main(String[] args)
    {
        // Set up scanner
        Scanner sc = new Scanner(System.in);
        // System.out.println("Enter xa");
        long xa = sc.nextLong();
        // System.out.println("Enter ya");
        long ya = sc.nextLong();

        // System.out.println("Enter xb");
        long xb = sc.nextLong();
        // System.out.println("Enter yb");
        long yb = sc.nextLong();

        // System.out.println("Enter xc");
        long xc = sc.nextLong();
        // System.out.println("Enter yc");
        long yc = sc.nextLong();

        if (xa==xb && ya<yb)
        {
            if (yb<yc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (xb<xc)
            {
                System.out.println("RIGHT");
                return;
            }
            else
            {
                System.out.println("LEFT");
                return;
            }
        }

        if (xa==xb && ya>yb)
        {
            if (yb>yc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (xb<xc)
            {
                System.out.println("LEFT");
                return;
            }
            else
            {
                System.out.println("RIGHT");
                return;
            }
        }

        if (xa<xb && ya==yb)
        {
            if (xb<xc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (yb>yc)
            {
                System.out.println("RIGHT");
                return;
            }
            else
            {
                System.out.println("LEFT");
                return;
            }
        }

        if (xa>xb && ya==yb)
        {
            if (xb>xc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (yb>yc)
            {
                System.out.println("LEFT");
                return;
            }
            else
            {
                System.out.println("RIGHT");
                return;
            }
        }

        if (xa<xb && ya<yb)
        {
            if (xb<xc && yb<yc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (xb<xc)
            {
                System.out.println("RIGHT");
                return;
            }
            else
            {
                System.out.println("LEFT");
                return;
            }
        }

        if (xa<xb && ya>yb)
        {
            if (xb<xc && yb>yc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (xb<xc)
            {
                System.out.println("LEFT");
                return;
            }
            else
            {
                System.out.println("RIGHT");
                return;
            }
        }

        if (xa>xb && ya<yb)
        {
            if (xb>xc && yb<yc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (xb>xc)
            {
                System.out.println("LEFT");
                return;
            }
            else
            {
                System.out.println("RIGHT");
                return;
            }
        }

        if (xa>xb && ya>yb)
        {
            if (xb>xc && yb>yc)
            {
                System.out.println("TOWARDS");
                return;
            }
            else if (xb>xc)
            {
                System.out.println("RIGHT");
                return;
            }
            else
            {
                System.out.println("LEFT");
                return;
            }
        }
    }
}


import java.util.Scanner;

public class B734 {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int [] array = new int[4];
        int result = 0;

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

        int tfx = Math.min(array[0],Math.min(array[2],array[3]));
        int tt = Math.min(array[0], array[1]);

        if (tfx == array[0]) {
            result = tfx * 256;
        } else {
            if (tfx == 0) {
                result = tt * 32;
            } else {
                if (tt >= array[0] - tfx) {
                    result = tfx * 256 + ((array[0] - tfx) * 32);
                } else {
                    result = tfx * 256 + tt * 32;
                }
            }
        }

        System.out.println(result);

    }
}


import java.util.Scanner;

public class CalculatingFunction {

	public static void main(String[] args) {
		try {
			Scanner scan=new Scanner(System.in);
			long n=scan.nextLong();
			long res=0;
			if(n%2==0)
			{
				res=n/2;

			}

			else {
				res=(n/2)-n;
			}
			System.out.println(res);
		} catch (Exception e) {
			// TODO: handle exception
		}

	}

}


import java.util.Scanner;

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

        String str = scan.next();
        int upper = 0;
        int lower = 0;
        for(int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            if(Character.toLowerCase(c) == c) {
                lower++;
            } else {
                upper++;
            }
        }

        String output = (upper > lower) ? str.toUpperCase() : str.toLowerCase();
        System.out.println(output);
    }
}


import java.util.Scanner;

public class champion {
	static long n, m, k;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		n = scan.nextLong();
		m = scan.nextLong();
		k = scan.nextLong();
		long low = 1;
		long high = n * (m+1);

		while(low < high) {
			long x = (high+low) >> 1;
			if(works(x)) {
				low = x+1;
			} else {
				high = x;
			}
		}

		System.out.println(high-1);

	}

	public static boolean works(long attempt) {
		long num = 0;
	    attempt--;
	    for(int i=1; i<=n; ++i) {
	    	num += Math.min(m, attempt/i);
	    }
	    return num < k;
	}
}


import java.util.*;
public class cheaptravel {
public static void main (String[]args)
{
	Scanner sc = new Scanner (System.in);
	int annplan = sc.nextInt();//a
	int mtickplan = sc.nextInt();//b
	int onetickp = sc.nextInt();//c
	int mtickp = sc.nextInt();//d
	int a1=annplan/mtickplan;
	int a2=a1*mtickplan;
	int a3=annplan-a2;
	int price=0;
	if(mtickp==(onetickp*mtickplan))//
		price=onetickp*annplan;
	if((onetickp*(a1+a3))<((a1*mtickp)))
	{
price=onetickp*annplan;
	}
	if(mtickp<(onetickp*mtickplan) && mtickp<onetickp)
	{
		price=(a1+a3)*mtickp;
	}
		if(mtickp<(onetickp*mtickplan) && onetickp<mtickp)
		{
			price=a1*mtickp;
			price+=a3*onetickp;
		}
			if(mtickp>(onetickp*mtickplan) && onetickp<mtickp)
			{
				price=(a2+a3)*onetickp;
			}
				if((mtickplan>annplan)&&(mtickp<(onetickp*annplan)))
						{
					price=mtickp;
						}

						if(mtickp<onetickp)
						{
							price=a1*mtickp;
				            if(a3>0&&a3<mtickplan)
				            	price+=mtickp;
				            		if (a3>0&&a3>mtickplan)
				            		{
				            			while(a3 >mtickplan)
				            			{
				            				price+=mtickp;
				            				a3-=mtickplan;
				            			}
				            			price+=mtickp;
				            		}

						}
					//else
						if(mtickp==onetickp)
						{
							price=a1*mtickp;
							if(a3>0&&a3<mtickplan)
				            	price+=mtickp;
							else
								if (a3>0&&a3>mtickplan)
		            		{
		            			while(a3 >mtickplan)
		            			{
		            				price+=mtickp;
		            				a3-=mtickplan;
		            			}
		            			price+=mtickp;
		            		}
						}
System.out.print(price);
}
}


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

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

    static class TaskAA {
        public void solve(int testNumber, Kattio in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            int[] ans = new int[n + 1];
            for (int i = 0; i < m; ++i) {
                int x = in.nextInt();
                for (int j = x; j <= n; ++j) {
                    if (ans[j] != 0) break;
                    ans[j] = x;
                }
            }

            for (int i = 1; i <= n; ++i)
                out.print(ans[i] + " ");
        }

    }

    static class Kattio extends PrintWriter {
        private BufferedReader r;
        private String line;
        private StringTokenizer st;
        private String token;

        public Kattio(InputStream i) {
            super(new BufferedOutputStream(System.out));
            r = new BufferedReader(new InputStreamReader(i));
        }

        public Kattio(InputStream i, OutputStream o) {
            super(new BufferedOutputStream(o));
            r = new BufferedReader(new InputStreamReader(i));
        }

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

        private String peekToken() {
            if (token == null)
                try {
                    while (st == null || !st.hasMoreTokens()) {
                        line = r.readLine();
                        if (line == null) return null;
                        st = new StringTokenizer(line);
                    }
                    token = st.nextToken();
                } catch (IOException e) {
                }
            return token;
        }

        private String nextToken() {
            String ans = peekToken();
            token = null;
            return ans;
        }

    }
}


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

public class Problem_50A {

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

		String[] temp = in.readLine().split(" ");
		int M = Integer.parseInt(temp[0]);
		int N = Integer.parseInt(temp[1]);

		int area = M * N;

		if(area == 1){
			System.out.println(0);
			return;
		}

		System.out.println(area / 2);
		return;
	}
}


// A : Is your horseshoe on the other hoof?

import java.util.Scanner;

public class A {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int cnt = 0;
        boolean f;
        int[] values = new int[4];
        for (int i = 0; i < 4; i++) {
            values[i] = in.nextInt();
            f = false;
            for (int j = 0; j < i; j++) {
                if (values[i] == values[j]) {
                    f = true;
                }
            }
            if (f) {
                cnt++;
            }
        }
        System.out.println(cnt);
    }
}


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

public class cod {

    static int INFINITY = 2000000000;

    public static void main(String[] args) throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        sc = new StringTokenizer("");

        int array[] = new int[10];

        String line = br.readLine();
        String str[] = line.split(" ");

        int num[] = new int[str.length];

        for (int i = 0; i < num.length; i++) {
            num[i] = Integer.parseInt(str[i]);
        }

        for (int i = 0; i < num.length; i++) {
            array[num[i]]++;
        }

        boolean legs = false;
        for (int i = 1; i < array.length; i++) {
            if (array[i] >= 4) {
                legs = true;
                array[i] -=4;
                break;
            }
        }

        if (!legs) {
            System.out.println("Alien");
        } else {
            boolean elep=false;
            for (int i = 1; i < array.length; i++) {
                if (array[i] == 2) {
                    System.out.println("Elephant");
                    elep=true;
                }
            }
            if(!elep){
                System.out.println("Bear");
            }
        }

    }// end Main.

    static BufferedReader br;
    static StringTokenizer sc;
    static PrintWriter out;

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

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

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

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

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

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

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

}// end class


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

public class CodeForce {

	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb = new StringBuilder();
	//	int t=Integer.parseInt(br.readLine());

	//	while(t-->0)
	String[] sr=br.readLine().split(" ");
	int n=Integer.parseInt(sr[0]);
	int a=Integer.parseInt(sr[1]);
	int b=Integer.parseInt(sr[2]);
	int temp=Math.min(a, b);
	int temp1=Math.max(a, b);
	a=temp;
	b=temp1;
	int l=(int)(Math.log(n)/Math.log(2));
	Queue<Integer>q=new LinkedList<Integer>();
	Queue<Integer>st1=new LinkedList<Integer>();
	int count=2;

	if(n==2)
	{
		System.out.println("Final!");
		return;
	}

	for(int i=1;i<=n;i=i+2)
	{
		if(i==a&&i+1==b)
	{System.out.println("1");
		return;}
		if(i==a||i+1==a)
			q.add(a);

		else if(i==b||i+1==b)
			q.add(b);

		else
			q.add(i+1);

	}

	while(true)
	{
		if(st1.isEmpty())
	{
			while(!q.isEmpty())
	{
			int x=q.poll();
	 int y=q.poll();
	 if(x==a&&y==b)
		{if(count==l)
			System.out.println("Final!");
		else System.out.println(count);
			return;}
			if(x==a||y==a)
				st1.add(a);

			else if(x==b||y==b)
				st1.add(b);

			else
				st1.add(y);

	}
	}
	else if(q.isEmpty())
	{
		while(!st1.isEmpty())
		{
		int x=st1.poll();
	     int y=st1.poll();
	      if(x==a&&y==b)
	 {if(count==l)
			System.out.println("Final!");
		else System.out.println(count);
			return;}
			if(x==a||y==a)
				q.add(a);

			else if(x==b||y==b)
				q.add(b);

			else
				q.add(y);

	}}
		count++;
	}

			}}


import java.util.ArrayList;

import java.util.Scanner;

public class Duplicateelement {

    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        int n,c=0;
        int c1=0;
        n=input.nextInt();
        String s;
        s=input.next();
        for (int i = 0; i < s.length(); i++) {
            if(s.charAt(i)=='0'){

                c1++;
            }else{
                c++;
            }
        }
        if(c>0){
             System.out.print("1");
        }

        for (int i = 0; i < c1; i++) {
            System.out.print("0");
        }

    }

}


import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	public static void main(String[] args)
	{
		long n=ni(),m=ni();
		long k=nl();
		if(k<n)
		{
			pr((k+1)+" "+1);
		}
		else if(k<n+m-1)
		{
			pr(n+" "+(k-n+2));
		}
		else if(k==n+m-1)
		{
			pr((n-1)+" "+m);
		}
		else
		{
			long te=k-n-m+1;
			n--;
			m--;
			if((n-te/m)%2==1)
			pr((n-te/m)+" "+(m+1-te%m));
			else
				pr(n-te/m+" "+(te%m+2));
		}
		System.out.print(output);
	}

	///////////////////////////////////////////
	///////////////////////////////////////////
	///template from here
	static final long mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static Reader in=new Reader();
	static StringBuilder output=new StringBuilder();
	static Random rn=new Random();
	//output functions////////////////
	static void pr(Object a){output.append(a+"\n");}
	static void pr(){output.append("\n");}
	static void p(Object a){output.append(a);}
	static void pra(int[]a){for(int i:a)output.append(i+" ");output.append("\n");}
	static void pra(long[]a){for(long i:a)output.append(i+" ");output.append("\n");}
	static void pra(String[]a){for(String i:a)output.append(i+" ");output.append("\n");}
	static void pra(double[]a){for(double i:a)output.append(i+" ");output.append("\n");}
	static void sop(Object a){System.out.println(a);}
	static void flush(){System.out.println(output);output=new StringBuilder();}
	//////////////////////////////////
	//input functions/////////////////
	static int ni(){return in.nextInt();}
	static long nl(){return Long.parseLong(in.next());}
	static String ns(){return in.next();}
	static double nd(){return Double.parseDouble(in.next());}
	static int[] nia(int n){int a[]=new int[n];for(int i=0; i<n; i++)a[i]=ni();return a;}
	static int[] pnia(int n){int a[]=new int[n+1];for(int i=1; i<=n; i++)a[i]=ni();return a;}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static double[] nda(int n){double a[]=new double[n];for(int i=0; i<n; i++)a[i]=nd();return a;}
	//////////////////////////////////
	//some utility functions
	static void psort(Integer[][] a)
	{
		Arrays.sort(a, new Comparator<Integer[]>()
		{
			@Override
			public int compare(Integer[]a,Integer[]b)
			{
				if(a[0]>b[0])
					return 1;
				else if(b[0]>a[1])
					return -1;
				return 0;
			}
		});
	}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static int gcd(int a, int b)
	{
		if(b==0)
			return a;
		else
			return gcd(b, a%b);
	}
	/////////////////////////
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
}


//package Codeforces;

import java.util.Scanner;

public class FafaAndCompany {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = n;
		int count = 0;

		if(n==2) {
			System.out.println(1);
			return;
		}
		for(int i=2;i<n;i++) {
			m-=i;
			if(n%m==0) count++;
			m = n;
		}

		System.out.println(count);
	}

}