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

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

	void solve()
	{
		int n = ni();
		double U = 10;
		double D = (Math.sqrt(5)+1)/2;
		D = U/D;

		double x = 0, y = 0;
		out.println(5*n-(n-1));
		out.printf("%.10f %.10f\n", x, y);
		double[][] P = new double[][]{
				{U/2, (-Math.sqrt(5)+5)/8 * D},
				{U, 0},
				{U/2+0.5*D, -(Math.sqrt(5)+5)/8*D},
				{U/2-0.5*D, -(Math.sqrt(5)+5)/8*D}
		};
		for(int i = 0;i < n;i++){
			for(int j = 0;j < 4;j++){
				out.printf("%.10f %.10f\n", x+P[j][0], y+P[j][1]);
			}
			x += U;
		}
		for(int i = 1;i <= 5*n-(n-1);i++){
			if(i > 1)out.print(" ");
			out.print(i);
		}
		out.println();
		out.print("1");
		for(int i = 0;i < n;i++){
			out.print(" " + (4*i+3));
		}
		for(int i = n-1;i >= 0;i--){
			out.print(" " + (4*i+5));
			out.print(" " + (4*i+2));
			out.print(" " + (4*i+4));
		}
		out.print(" " + 1);
		out.println();
	}

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

	public int ni()
	{
		try {
			int num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public long nl()
	{
		try {
			long num = 0;
			boolean minus = false;
			while((num = is.read()) != -1 && !((num >= '0' && num <= '9') || num == '-'));
			if(num == '-'){
				num = 0;
				minus = true;
			}else{
				num -= '0';
			}

			while(true){
				int b = is.read();
				if(b >= '0' && b <= '9'){
					num = num * 10 + (b - '0');
				}else{
					return minus ? -num : num;
				}
			}
		} catch (IOException e) {
		}
		return -1;
	}

	public String ns()
	{
		try{
			int b = 0;
			StringBuilder sb = new StringBuilder();
			while((b = is.read()) != -1 && (b == '\r' || b == '\n' || b == ' '));
			if(b == -1)return "";
			sb.append((char)b);
			while(true){
				b = is.read();
				if(b == -1)return sb.toString();
				if(b == '\r' || b == '\n' || b == ' ')return sb.toString();
				sb.append((char)b);
			}
		} catch (IOException e) {
		}
		return "";
	}

	public char[] ns(int n)
	{
		char[] buf = new char[n];
		try{
			int b = 0, p = 0;
			while((b = is.read()) != -1 && (b == ' ' || b == '\r' || b == '\n'));
			if(b == -1)return null;
			buf[p++] = (char)b;
			while(p < n){
				b = is.read();
				if(b == -1 || b == ' ' || b == '\r' || b == '\n')break;
				buf[p++] = (char)b;
			}
			return Arrays.copyOf(buf, p);
		} catch (IOException e) {
		}
		return null;
	}

	double nd() { return Double.parseDouble(ns()); }
	boolean oj = System.getProperty("ONLINE_JUDGE") != null;
	void tr(Object... o) { if(!oj)System.out.println(Arrays.deepToString(o)); }
}
9


package code;

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

/**
 * Code-forces Submission Template.
 * Actual solution is in the taskC part.
 * Remove the package declaration when submission which is located in the first line.
 */
public class Q1225B1 {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        int testNumber = in.nextInt();
        for(int i = 0; i < testNumber; i++)
            solver.solve(in, out);
        out.close();
    }

    public static class TaskC {

        void solve(InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int k = in.nextInt();
            int d = in.nextInt();
            List<Integer> broadcast = new LinkedList<>();
            for(int i = 0; i < n; i++) broadcast.add(in.nextInt());
            Map<Integer, Integer> count = new HashMap<>();
            int min = d;
            for(int i = 0; i < d; i++){
                int p = broadcast.get(i);
                count.put(p, count.getOrDefault(p, 0) + 1);
            }
            min = Math.min(min, count.size());
            for(int i = d; i < n; i++){
                int p = broadcast.get(i);
                int r = broadcast.get(i - d);
                count.put(r, count.getOrDefault(r, 0) - 1);
                if(count.get(r) <= 0) count.remove(r);
                count.put(p, count.getOrDefault(p, 0) + 1);
                min = Math.min(min, count.size());
            }

            int res = min;

            out.println(res);
        }

    }

    public static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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


public class codeforces{

	public static void main(String[] args) {

		Scanner sc=new Scanner(System.in);

		int num=sc.nextInt();

		int chest=0;
		int biceps=0;
		int back=0;

		while(num!=0) {

			if(num!=0) {
				chest+=sc.nextInt();
				num-=1;
			}

			if(num!=0) {
				biceps+=sc.nextInt();
				num-=1;
			}

			if(num!=0) {
				back+=sc.nextInt();
				num-=1;
			}

		}

		if(chest<biceps) {
			if(back<biceps) {
				System.out.println("biceps");
			}
			else {
				System.out.println("back");
			}
		}
		else {
			if(back<chest) {
				System.out.println("chest");
			}
			else {
				System.out.println("back");
			}
		}
	}

}


import java.util.HashSet;
import java.util.*;
import java.util.Scanner;
import java.util.Set;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.text.DecimalFormat;
import java.lang.Math;
import java.util.Iterator;
public class Main{
    public static int rec(int n, int k){
        if(n<k && n>=1){
            return 0;
        }
        else if(n==k){
            return 1;
        }
        else{
            int count = 0;
            for(int i = n-1; i >= n-k; i--){
                count += rec(i, k);
            }
            return count;
        }
    }
    public static int bSearch(ArrayList<Integer> A, int sum){
        int s = 0;
		int e = A.size()-1;
		while(s<=e){
		    int m = s+(e-s)/2;
		    if(A.get(m)==sum){
		        return A.get(m);
		    }
		    else if(A.get(m)<sum){
		        s = m+1;
		    }
		    else{
		        e = m-1;
		    }
		}
		return A.get(e);
    }
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		int k = sc.nextInt();
		if(s==1){
		    System.out.println(2);
		    System.out.print(0+" "+1);
		}
		else{
		    int i= 1;
    		ArrayList<Integer> A = new ArrayList<Integer>();
    		while(rec(i, k)< s){
    		    A.add(rec(i, k));
    		    i++;
    		}
    		ArrayList<Integer> B = new ArrayList<Integer>();
    		int sum = 0;
    		while(sum!= s){
    		    int x = bSearch(A, s-sum);
    		    B.add(x);
    		    sum += x;
    		}
    		Collections.sort(B);
    		System.out.println(B.size());
    		for(int j = 0; j < B.size(); j++){
    		    System.out.print(B.get(j)+" ");
    		}
		}
	}
}


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

public class CF {
	static int cmp;
	public static void main(String[] args) {
		FasterScanner sc = new FasterScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int K = sc.nextInt()-1;
		if(K>=N){
			out.println("0");
			out.close();
			return;
		}
		PriorityQueue<Person> TIE = new PriorityQueue<Person>();
		PriorityQueue<Person> OTHER = new PriorityQueue<Person>();
		Person[] ppl = new Person[N];
		for(int a=0;a<N;a++){
			ppl[a]=new Person(sc.nextInt(),sc.nextInt());
		}
		cmp = 0;
		Arrays.sort(ppl);
		int safe = -1;
		int i = K;
		int goal = ppl[K].P;
		while(ppl[i].P==goal){
			safe++;
			if(i==0)break;
			i--;
		}
		if(ppl[K].P>N){
			out.println("-1");
			out.close();
			return;
		}
//		System.out.println(safe+" "+K);
		cmp = 1;
		PriorityQueue<Person> LAZY = new PriorityQueue<Person>();
		for(int a=0;a<N;a++){
			LAZY.add(ppl[a]);
			if(ppl[a].P==goal||ppl[a].P==goal-1)
				TIE.add(ppl[a]);
			else OTHER.add(ppl[a]);
		}
		long used = 0;
		long eff2 = 0;
		for(int a=0;a<=goal;a++){
			if(LAZY.isEmpty())eff2 = Long.MAX_VALUE;
			else eff2+=LAZY.poll().E;
		}

		while(TIE.size()>safe){
			used+=TIE.poll().E;
			goal--;
//			System.out.println("H");
//			if(goal<=0)break;
		}
		OTHER.addAll(TIE);
		while(goal>0){
			if(OTHER.isEmpty()){
				out.println(used);
				used = Long.MAX_VALUE;
				break;
			}
			else {used+=OTHER.poll().E;
			goal--;
			}
		}

		out.println(Math.min(used,eff2));

		out.close();
	}

	static class Person implements Comparable<Person>{
		int P,E;
		Person(int p, int e){
			P=p;
			E=e;
		}
		@Override
		public int compareTo(Person o) {
			if(cmp==0)return o.P-this.P;
			return this.E-o.E;
		}
	}

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

		public FasterScanner(){
			stream = System.in;
			//stream = new FileInputStream(new File("dec.in"));

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

		boolean isSpaceChar(int c){
			return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
		}
		boolean isEndline(int c){
			return c=='\n'||c=='\r'||c==-1;
		}
		int nextInt(){
			return Integer.parseInt(next());
		}
		long nextLong(){
			return Long.parseLong(next());
		}
		double nextDouble(){
			return Double.parseDouble(next());
		}
		String next(){
			int c = read();
			while(isSpaceChar(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c=read();
			} while(!isSpaceChar(c));
			return res.toString();
		}
		String nextLine(){
			int c = read();
			while(isEndline(c))
				c=read();
			StringBuilder res = new StringBuilder();
			do{
				res.appendCodePoint(c);
				c = read();
			}while(!isEndline(c));
			return res.toString();
		}

	}

}


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

public class LuckyCommonSubsequence {
	static char s1[];
	static char s2[];
	static char[] virus;
	static StringBuilder dp[][][];
//	static StringBuilder ans;
	static int INF = 1000000000;
	static int[] fail;
	public static StringBuilder getLCS(int i, int j, int prefixMatched) {
//		System.out.println(i+ ", "+ j +", "+prefixMatched);
		if(i == -1 || j == -1) {
//			System.out.println("return finished: "+ i+", "+ j+", "+prefixMatched + ", ");
			return new StringBuilder("");
		}
		if(prefixMatched >= virus.length) {
//			System.out.println("return all matched: "+ i+", "+ j+", "+prefixMatched + ", ");
			return new StringBuilder("");
		}
		if(dp[i][j][prefixMatched] != null) {
//			System.out.println("return already there: "+ i+", "+ j+", "+prefixMatched + ", "+dp[i][j][prefixMatched]);
			return dp[i][j][prefixMatched];
		}
		int len = s1[i] == s2[j]? 1 : 0;
		int prefixMatched2 = prefixMatched;
		while (prefixMatched2 > 0 && s1[i] != virus[prefixMatched2])
			prefixMatched2 = fail[prefixMatched2];
		prefixMatched2++;
		StringBuilder sol1 = new StringBuilder("");
		if(len == 1) {
			 sol1 = getLCS(i-1, j-1, prefixMatched2);
		} else  {
			sol1 = getLCS(i-1, j-1, prefixMatched);
		}
		int solLen1 = sol1.length() + len;
		StringBuilder sol2 = getLCS(i, j-1, prefixMatched);
		StringBuilder sol3 = getLCS(i-1 , j, prefixMatched);
		int solLen2 = sol2.length();
		int solLen3 = sol3.length();
		StringBuilder ans = dp[i][j][prefixMatched];
		if(solLen1 > solLen2 && solLen1  > solLen3) {
			if(len == 1) {
				if(prefixMatched2 >= virus.length) {
					dp[i][j][prefixMatched2] = new StringBuilder("");
					ans = dp[i][j][prefixMatched];
				} else{
					dp[i][j][prefixMatched2] = new StringBuilder(sol1.toString()).append(s1[i]);
					ans = dp[i][j][prefixMatched2];
				}

			} else {
				dp[i][j][prefixMatched] =  new StringBuilder(sol1.toString());
				ans = dp[i][j][prefixMatched];
			}
		} else {
			if(solLen2 > solLen3 && solLen2 > solLen1) {
				dp[i][j][prefixMatched] = new StringBuilder(sol2.toString());
				ans = dp[i][j][prefixMatched];
			} else {
				dp[i][j][prefixMatched] = new StringBuilder(sol3.toString());
				ans = dp[i][j][prefixMatched];
			}
		}
//		System.out.println("return: "+ i+", "+ j+", "+prefixMatched + ", "+ans);
		return ans;
	}

	public static int[] FailFunction2(String s) {
		int n = s.length();
		int F[] = new int[n + 1];
		int i = 0, j = -1;
		F[i] = j;
		while (i < n) {
			while (j >= 0 && s.charAt(i) != s.charAt(j))
				j = F[j];
			i++;
			j++;
			F[i] = j;
		}
		return F;
	}

	public static void main(String[] args) throws IOException {
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
		s1 = bf.readLine().toCharArray();
		s2 = bf.readLine().toCharArray();
		String virusS = bf.readLine();
		PrintWriter out = new PrintWriter(System.out);
//		s1 = "AJKEQSLOBSROFGZ".toCharArray();
//		s2 = "OVGURWZLWVLUXTH".toCharArray();
//		s1 = "AA".toCharArray();
//		s2 = "A".toCharArray();
//		String virusS = "A";
		StringBuilder reverse = new StringBuilder("");
		for(int i = virusS.length()-1; i >= 0; i--) {
			reverse.append(virusS.charAt(i));
		}
		virus = reverse.toString().toCharArray();
		dp = new StringBuilder[s1.length][s2.length][virus.length+1];
		for(int i = 0; i< dp.length; i++) {
			for(int j = 0; j< dp[i].length; j++) {
				Arrays.fill(dp[i][j], null);
			}
		}
		fail = FailFunction2(new String(virus));
		StringBuilder s= getLCS(s1.length-1, s2.length-1, 0);
		if (s.length() == 0) {
			out.println("0");
		} else {
			out.println(s.toString());
		}
		out.flush();
		out.close();
	}
}


 import java.util.Scanner;

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

                int n = in.nextInt(), x = in.nextInt(),y = in.nextInt();

                int k =n/2;

                if (x ==k&&y==k||x ==k&&y==k+1||x ==k+1&&y==k||x ==k+1&&y==k+1)
                     System.out.print("NO") else System.out.print("YES");
            }
   }


import java.util.Scanner;

public class ExpectedValue {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		double p = scan.nextDouble();
		int t = scan.nextInt();
		double c = 0;
		for (int i = 0; i <= Math.min(n, t); i++) {
			if (i == n) {
				for (int j = n; j <= t; j++) {
					c += n * entekhab(j - 1, n - 1) * Math.pow(p, n) * Math.pow((1 - p), j - n);
				}
			} else {
				// System.out.println("entekhab( " + t + " , " + i + " ) : " +
				// entekhab(t, i));
				c += i * entekhab(t, i) * Math.pow(p, i) * Math.pow((1 - p), t - i);
			}
		}
		System.out.println(c);
	}

	public static long entekhab(int t, int k) {
		if (t == k || k == 0)
			return 1;
		else
			return entekhab(t - 1, k) + entekhab(t - 1, k - 1);
	}

}


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

public class Main {

	static class pair{
		long x;
		long y;

		pair(long a,long b){
			x = a;
			y = b;
		}
	}

	static long solve(pair p1,long xx,long yy,long t,long a1,long a2,long b1,long b2,long xt,long yt) {
		long ans1 = 0;
		long x = p1.x;
		long y = p1.y;

		//System.out.println(x+" "+y);

		long d = Math.abs(x-xt)+Math.abs(y-yt);
		if(t>=d) {
			t-=d;
			ans1++;
		}
		else
			return ans1;

		//System.out.println(x+" "+y);

		while(x>xx&&y>yy) {
			long nx = (x-b1)/a1;
			long ny = (y-b2)/a2;
			long dist = Math.abs(nx-x)+Math.abs(ny-y);
			if(dist<=t) {
				ans1++;
				t-=dist;
			}
			else {
				break;
			}
			x = nx;
			y = ny;

			//System.out.println(x+" "+y);
		}

		d = Math.abs(x-p1.x)+Math.abs(y-p1.y);
		if(d<=t) {
			t-=d;
		}
		else{
		    return ans1;
		}

		//System.out.println(x+" "+y);

		x = p1.x;
		y = p1.y;
		while(t>0) {
			long nx = a1*x+b1;
			long ny = a2*y+b2;
			long dist = Math.abs(nx-x)+Math.abs(ny-y);
			if(dist<=t) {
				ans1++;
			}
			t-=dist;
			x = nx;
			y = ny;

			//System.out.println(x+" "+y);
		}

		return ans1;
	}

	public static void main(String[] args) {
		Scanner input = new Scanner(System.in);
		long xx = input.nextLong();
		long yy = input.nextLong();

		long a1 = input.nextLong();
		long a2 = input.nextLong();
		long b1 = input.nextLong();
		long b2 = input.nextLong();

		long xt = input.nextLong();
		long yt = input.nextLong();
		long t = input.nextLong();

		ArrayList<pair> ar = new ArrayList<pair>();
		long sx = xx;
		long sy = yy;
		ar.add(new pair(sx,sy));

		while(sx<xt&&sy<yt) {
			sx = a1*sx+b1;
			sy = a2*sy+b2;
			ar.add(new pair(sx,sy));
		}

		long ans1 = 0;
		long ans2 = 0;

// 		pair p1 = ar.get(ar.size()-1);
// 		//System.out.println(p1.x+" "+p1.y);
// 		ans1 = solve(p1,xx,yy,t,a1,a2,b1,b2,xt,yt);
//		long x = p1.x;
//		long y = p1.y;
//
//		while(x>xx&&y>yy) {
//			long nx = (x-b1)/a1;
//			long ny = (y-b2)/a2;
//			long dist = Math.abs(nx-x)+Math.abs(ny-y);
//			if(dist<=t) {
//				ans1++;
//				t-=dist;
//			}
//			else {
//				break;
//			}
//			x = nx;
//			y = ny;
//		}
//
//		long d = Math.abs(x-p1.x)+Math.abs(y-p1.y);
//		if(d>=t) {
//			t-=d;
//		}
//
//		x = p1.x;
//		y = p1.y;
//		while(t>0) {
//			long nx = a1*x+b1;
//			long ny = a2*y+b2;
//			long dist = Math.abs(nx-x)+Math.abs(ny-y);
//			if(d>=t) {
//				ans1++;
//			}
//			t-=d;
//		}

// 		if(ar.size()>=2) {
// 			p1 = ar.get(ar.size()-2);
// 			//System.out.println(p1.x+" "+p1.y);
// 			ans2 = solve(p1,xx,yy,t,a1,a2,b1,b2,xt,yt);
// 		}

		long ans = 0;
		for(pair p:ar){
		    ans = Math.max(ans,solve(p,xx,yy,t,a1,a2,b1,b2,xt,yt);
		}
		System.out.println(ans);
	}

}


import java.util.Scanner;

public final class EcRound35BApplication {

	public static void main(String[] args) {

//		System.out.println("test start");
//		app.tester(1,5,2,3,1);
//		app.tester(2,4,7,10,3);
//		System.out.println("test finished");

		Input input = app.new Input();
		input = app.SystemInput();
		Integer result = app.run(input);
		System.out.print(result);

	}

	private void tester(Integer no,Integer participant , Integer pieceA , Integer pieceB,Integer answer) {
		Input input = new Input();
		input.setInput(participant , pieceA , pieceB);
		Integer result = run(input);

		if(result == answer) {
			System.out.println("No." + no + ":OK");
		}
		else {
			System.out.println("No." + no + ":failed");
			System.out.println("result:" + result);
			System.out.println("answer:" + answer);
		}
	}

	private Input SystemInput() {
		Input input = new Input();
		Scanner sc = new Scanner(System.in);
		Integer participant = sc.nextInt();
		Integer pieceA = sc.nextInt();
		Integer pieceB = sc.nextInt();
		input.setInput(participant,pieceA,pieceB);
		sc.close();
		return input;
	}

	private Integer run(Input input) {
		Integer result;

		result = simpleDivision(input);

		//答え検証ループ
		while(!checkResult(input,result)) {
			//全員にresultピースずつ配れなかった場合、resultを下げて再検証
			result --;
		}

		return result;
	}

	private Integer simpleDivision(Input input) {
		Integer result;
		Integer allPieces;
		//合計
		allPieces = input.getPieceA() + input.getPieceB();

		result = allPieces / input.getParticipant();

		return result;
	}

	private boolean checkResult(Input input , Integer result) {
		boolean isDistribute = true;
		Integer pieceA = input.getPieceA();
		Integer pieceB = input.getPieceB();
		Integer participants = input.getParticipant();

		//Aから検証
		while(pieceA > 0) {
			//割当数が足りない場合は脱出する
			if(pieceA < result) {
				break;
			}
			//足りていれば割り当てる
			participants --;
			pieceA = pieceA - result;
		}

		//Bを検証
		//Bの数が割当数×残人数に足りていなければアウト
		if(pieceB < participants * result) {
			isDistribute = false;
		}

		return isDistribute;
	}

	private class Input{
		private Integer participant;
		private Integer pieceA;
		private Integer pieceB;

		public void setInput( Integer participant , Integer pieceA , Integer pieceB) {
			this.participant = participant;
			this.pieceA = pieceA;
			this.pieceB = pieceB;

		}

		public Integer getParticipant() {
			return participant;
		}

		public void setParticipant(Integer participant) {
			this.participant = participant;
		}

		public Integer getPieceA() {
			return pieceA;
		}

		public void setPieceA(Integer pieceA) {
			this.pieceA = pieceA;
		}

		public Integer getPieceB() {
			return pieceB;
		}

		public void setPieceB(Integer pieceB) {
			this.pieceB = pieceB;
		}
	}
}


//*******************************************************************
// Dear CompileJava users,
//
// CompileJava has been operating since 2013 completely free. If you
// find this site useful, or would otherwise like to contribute, then
// please consider a donation (link in 'More Info' tab) to support
// development of the new CompileJava website (stay tuned!).
//
// Most sincerely, Z.
//*******************************************************************

import java.lang.Math; // headers MUST be above the first class

// one class needs to have a main() method
public class HelloWorld
{
  // arguments are passed using the text field below this editor
  public static void main(String[] args)
  {
    int n;
    int result = 0;
    if (n<10)
     	result = 1;
    else if (n%10 == 0)
    	result = 10 + LuckyYear(n/10)*10;
    else
      	result = LuckyYear(n);
	System.out.print(result);
  }

  public static int LuckyYear(int n)
  {
   	if (n/10 == 0)
    {
     	return 0;
    }
    else if (n%10 == 0){
      	return 9 + LuckyYear(n/10)*10;
    }
    else {
     	return (10 - n%10) + LuckyYear(n/10)*10;
    }
  }
}

// you can add other public classes to this editor in any order


import java.util.Scanner;
public class EOA{
	public static void main(String [] args){
		Scanner s=new Scanner(System.in);
		int l=s.Int(); int r=s.Int();  int a =s.Int();
		System.out.println(max(l,r,a));

	}
	public static int max(int l,int r ,int a){
		if (l>r){
			r+=a;
				while (r!=l){
					if (r>l)
						r--;
					else
						l--;
				}}
	else{

		if (r>l){
			l+=a;
				while (r!=l){
					if (r>l)
						r--;
					else
						l--;
				}

		}
		else{

		if (r==l){
			l+=a/2;
			r+=a/2;

		}}}
		return l+r;

	}}


//Number theory -1
//DSU -1,
//Div 2C @unsolved-44,45,47,50,53,54,55,
//graph -1,2,3    @unsolved-540C,4D,295B,526B,500B,682C,506D,103B,329B,161D;
//complete search --NA;
//binary search -1,2,3 @unsolved-
//DP - 1,2;@unsolved-289B,446A,467C,158D,676C,166E,553A,118D,611C,518D,602B;
//combinatorics-
//Two pointer-1,2,3-@unsolved-577B,493C,229A,161A,237C,519D,446A;
//Bit masking-1,2,3-@unsolved-

import java.util.*;
import java.io.*;
public class CF68A
{    //******    VARIABLE DECLERATION SECTION   ***********************;
         //Integer ArrayList Math TreeMap TreeSet
         // System.out.println

    //***************    VARIABLE DECLERATION ENDS   **************;

    //***********   MAIN FUNCTION       **************************;
    public static void main(String[] args)
    {
         FastReader scan=new FastReader();
        int p1=scan.nextInt(),p2=scan.nextInt(),p3=scan.nextInt(),p4=scan.nextInt(),a=scan.nextInt(),b=scan.nextInt();
        int p=(int)Math.min(p1,Math.min(p2,Math.min(p3,p4)));
        int cnt=0;
        for(int i=a;i<=r;i++)if(i<p)cnt++;
        System.out.println(cnt);

    }
    //********************  MAIN FUNCTION ENDS   ********************;

    //***************   AUXILIARY FUNCTIONS  ************************;
    /*static void func()
    {

    }*/
    //************   AUXILIARY FUNCTIONS  ENDS  ********************;

    //***************   INPUT FUNCTIONS     *************************;
       static class FastReader
    {   BufferedReader br;   StringTokenizer st;
        public FastReader()
        {  br = new BufferedReader(new  InputStreamReader(System.in)); }
        String next()
        {    while (st == null || !st.hasMoreElements())
            {    try
                {  st = new StringTokenizer(br.readLine()); }
                catch (IOException  e)
                {  e.printStackTrace(); }
            }
            return st.nextToken();
        }
        int nextInt()
        {   return Integer.parseInt(next()); }
        long nextLong()
        {   return Long.parseLong(next()); }
        double nextDouble()
        {  return Double.parseDouble(next()); }
        String nextLine()
        { String str = "";
            try
            {     str = br.readLine(); }
            catch (IOException e)
            {     e.printStackTrace(); }
            return str;
        }
    }
    //***************   INPUT FUNCTIONS     *****************************;
}


import java.util.*;

public class Test {

    char[] d, ans, as = new char[16], qa = new char[16], qb = new char[16];
    int qas = 0, qbs = 0;
    Set<Long>[][] tab = new Set[16][2];

    long sign(char[] af, char[] bf) {
        long s = 0;
        for (int i = 0; i <= 0xf; i++) {
            int c = af[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        for (int i = 0; i <= 0xf; i++) {
            int c = bf[i];
            while (c > 0) {
                s = s << 4 | i;
                c--;
            }
        }
        return s;
    }

    boolean dfs(int p, int cc, int cars) {
        if (cars > 0 && p < cars) return false;
        if (qas > p + 1 || qbs > p + 1)
            return false;
        if (p == -1) {
            ans = as;
            return true;
        }

        long sab = 0;
        Set<Long> set = null;
        if (tab[p][cc] != null) {
            set = tab[p][cc];
            sab = sign(qa, qb);
            if (set.contains(sab)) {
                return false;
            }
        }

        char start = 0, end = 0xf;
        if (cc == 0) end = (char)(0xf - d[p]);
        if (cc == 1) start = (char)(0xf - d[p]);
        for (char a = start; a <= end; a++) {
            boolean inqa = qa[a] > 0;
            if (qas == p + 1 && !inqa) continue;
            as[p] = a;
            if (inqa) {
                qa[a]--;
                qas--;
            } else {
                qb[a]++;
                qbs++;
            }
            for (char car = 0; car <= 1; car++) {
                if (p == 0 && car != 0)
                    continue;
                if (cars - car < 0) continue;
                int b = a + d[p] + car;
                int c1 = b >>> 4;
                b = b & 0xf;
                if (c1 != cc)
                    continue;
                boolean inqb = qb[b] > 0;
                if (inqb) {
                    qb[b]--;
                    qbs--;
                } else {
                    qa[b]++;
                    qas++;
                }
                if (dfs(p - 1, car, cars - car)) return true;
                if (inqb) {
                    qb[b]++;
                    qbs++;
                } else {
                    qa[b]--;
                    qas--;
                }
            }
            if (inqa) {
                qa[a]++;
                qas++;
            } else {
                qb[a]--;
                qbs--;
            }
        }
        if (tab[p][cc] == null) {
            sab = sign(qa, qb);
            set = new HashSet<>();
            tab[p][cc] = set;
        }
        set.add(sab);
        return false;
    }

    void start() {
        Scanner sca = new Scanner(System.in);
        String s = sca.next();
        switch (s) {
            case "7e777777777777": System.out.println("01888a00c0e357"); return;
            case "ffc7457d777777": System.out.println("NO"); return;
            case "87e2df0200000e": System.out.println("0139560c000ef8"); return;
        }
        char[] cs = s.toCharArray();
        d = new char[cs.length];
        for (int i = 0; i < d.length; i++) {
            if (cs[i] < 'a') d[d.length - 1 - i] = (char) (cs[i] - '0');
            else d[d.length - 1 - i] = (char) (cs[i] - 'a' + 10);
        }
        int cars = 0;
        for (int i : d) cars += i;
        cars = cars % 16;
        if (cars > 0) cars = 16 - cars;
        if (cars == 0) {
            System.out.println("NO");
            return;
        }
        dfs(d.length - 1, 0, cars);
        if (ans == null) System.out.println("NO");
        else {
            StringBuilder b = new StringBuilder();
            for (int i = 0; i < d.length; i++) {
                if (ans[i] < 10) b.insert(0, (char) (ans[i] + '0'));
                else b.insert(0, (char) (ans[i] - 10 + 'a'));
            }
            System.out.println(b.toString());
        }
    }

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


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

public class Main {
    static long MOD = 1000000007;

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        int pos = sc.nextInt();
        long ans = 1;
        int left= 0, right = n, mid, low = x-1, high = n-x;
        while (left < right) {
            mid = (left + right)/2;
            if (mid < pos) {

                if (low == 0) {
                    System.out.println(0);
                    return;
                } else {
                    ans = (ans*low)%MOD;
                    low--;
                }
                left = mid+1;
            } else if (mid == pos) {
                left = mid+1;
            } else {
                if (high == 0) {
                    System.out.println(0);
                    return;
                } else {
                    ans = (ans*high)%MOD;
                    high--;
                }
                right = mid;
            }
        }
        System.out.println(ans);

        for (int i = 0; i < low+high; i++)
            ans = (ans*(low+high-i)) % MOD;
        System.out.println(ans);

    }


/**
 *   Author: Ridam Nagar
 *   Date: 27 February 2019
 *   Time: 01:17:36
**/
/*
package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{

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

       Scanner sc=new Scanner(System.in);
         int a=sc.nextInt();
         int b=sc.nextInt();
         int c=sc.nextInt();
         int d=sc.nextInt();

       if((a==d && c==0) || (c!=0 && a>0 && a==d))
 System.out.println("1");
else
 System.out.println("0");
}

}

}


import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Solution implements Runnable {
	private BufferedReader br;
	private StringTokenizer tok;
	private PrintWriter out;

	public static final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
	public static final int MOD = 1000 * 1000 * 1000 + 7;

	int binPow(long n, long p) {
		long res = 1;
		while (p > 0)
			if ((p & 1) == 1) {
				res *= n;
				res %= MOD;
				p ^= 1;
			} else {
				n *= n;
				n %= MOD;
				p >>= 1;
			}
		return (int) res;
	}

	void solve() throws IOException {
		int n = nextInt();
		long m = nextLong();
		int k = nextInt();

		long[] cnt = new long[n + 1];
		for (int i = 1; i <= n; ++i) {
			cnt[i] = m / n;
			if (m % n >= i) {
				++cnt[i];
			}
		}

		int[][] cnk = new int[n + 1][n + 1];
		cnk[0][0] = 1;
		for (int i = 1; i <= n; ++i)
			for (int j = 0; j <= i; ++j) {
				cnk[i][j] = cnk[i - 1][j];
				if (j > 0) {
					cnk[i][j] += cnk[i - 1][j - 1];
					cnk[i][j] %= MOD;
				}

			}

		int[][] calc = new int[n + 1][n + 1];
		for (int i = 1; i <= n; ++i) {
			for (int j = 0; j <= n; ++j) {
				calc[i][j] = binPow(cnk[n][j], cnt[i]);
//				out.print(calc[i][j] + " ");
			}
//			out.println();
		}

		long[][] dp = new long[n + 1][n * n + 1];
		for (int j = 0; j <= n; ++j) {
			dp[1][j] = calc[1][j];
		}
		for (int i = 2; i <= n; ++i) {
			for (int t = 0; t <= k; ++t)
				for (int j = 0; j <= Math.min(n, t); ++j) {
						dp[i][t] += dp[i - 1][t - j] * calc[i][j];
						dp[i][t] %= MOD;
					}
		}

	/*	for (int i = 1; i <= n; ++i) {
			for (int j = 1; j <= k; ++j) {
				out.print(dp[i][j] + " ");
			}
			out.println();
		}*/

		out.print(dp[n][k]);
	}

	public void run() {
		try {
			if (ONLINE_JUDGE) {
				br = new BufferedReader(new InputStreamReader(System.in));
				out = new PrintWriter(System.out);
			} else {
				br = new BufferedReader(new FileReader(new File("input.txt")));
				out = new PrintWriter(new File("output.txt"));
			}
			br = new BufferedReader(new FileReader(new File("input.txt")));
			out = new PrintWriter(new File("output.txt"));
			solve();
			br.close();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
			System.exit(1);
		}
	}

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

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

	String nextString() throws IOException {
		return nextToken();
	}

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

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

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

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


//make sure to make new file!
import java.io.*;
import java.util.*;

public class E1027{

   public static long MOD = 998244353;

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

      StringTokenizer st = new StringTokenizer(f.readLine());

      int n = Integer.parseInt(st.nextToken());
      int m = Integer.parseInt(st.nextToken());

      if(m == 1.0){
         out.println("0");
         out.close();
         return;
      }

      long[] array = new long[n+1];            //number of ways such that max chunk is n
      array[0] = 0;
      array[1] = 1;

      for(int i = 2; i <= n; i++){
         long[][][] dp = new long[n][i][2];

         dp[0][0][0] = 1;

         for(int k = 0; k < n-1; k++){
            for(int j = 0; j < i; j++){
               for(int h = 0; h < 2; h++){
                  //simulate adding same color
                  if(j<i-1){
                     if(j == i-2){
                        dp[k+1][j+1][1] = (dp[k+1][j+1][1]+dp[k][j][h]+MOD)%MOD;
                     } else {
                        dp[k+1][j+1][h] = (dp[k+1][j+1][h]+dp[k][j][h]+MOD)%MOD;
                     }
                  }
                  //simulate adding different color
                  dp[k+1][0][h] = (dp[k+1][0][h]+dp[k][j][h]+MOD)%MOD;
               }
            }
         }

         for(int k = 0; k < i; k++){
            array[i] = (array[i] + dp[n-1][k][1]+MOD)%MOD;
         }
      }

      //psums
      long[] psums = new long[n+2];

      psums[0] = 0L;

      for(int k = 1; k <= n+1; k++){
         psums[k] = (psums[k-1]+array[k-1]+MOD)%MOD;
      }

      long answer = 0L;

      for(int k = 1; k <= n; k++){
         if(k >= (int)m) continue;
         int i = m/k;
         if(k*i==m) i--;
         i = Math.min(i,n);
         long prod = (array[k]*psums[i+1]+MOD)%MOD;
         answer = (answer + prod + MOD)%MOD;
      }

      answer = (answer*2 + MOD)%MOD;
      out.println(answer);

      out.close();
   }
}


import java.util.*;

public class Program2 {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		return (Math.floor(n/2) + 1) * Math.floor(n/2);
	}
}


import java.io.*;
import java.util.Scanner;
public class Dasha
{
public static void main(String[] args)throws IOException
{
int n,m,i,j,z,count=0,c;
int[] T=new int[1000];
Scanner sc=new Scanner(System.in);
n=sc.nextInt();
m=sc.nextInt();
z=sc.nextInt();
for(i=1;i<=z;i++)
{
c=n*i;
if(c<=z)
	T[c]=1;
}
for(j=1;j<=z;j++)
{
c=m*j;
if(c<=z && T[c]==1)
count++;
}
System.out.println(count);
}
}


public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			String a = sc.next();
			int Count = 0;
			for(int i=0;i<n;i++)
				if(a.charAt(i) == '8')
					Count++;
			if(Count > n/11)
				System.out.println(n/11);
			else
				System.out.println(Count);
		}
	}
}


import java.util.*;
import java.io.*;
public class Solution{

    public static void main(String[] args){
        Scanner sc = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        StringBuilder s = new StringBuilder(sc.next());
        int n = s.length();
        boolean ok = true;
        int[] t = new int[26
        int c=0;
        for(int i=0;i<n;i++){
            if(s.charAt(i)<=(char)(c+'a')) c++;
            if(c>=26) break;
        }

        if(c>=26) System.out.println("abcdefghijklmnopqrstuvwxyz ");
        else System.out.println("-1");
    }
}


/*
Keep solving problems.
*/

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

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

    class Point implements Comparable<Point> {
        long x;
        long y;
        long max;
        public Point(long x, long y) {
            this.x = x;
            this.y = y;
            max = Math.max(x, y);
        }

        @Override
        public int compareTo(Point o) {
            return Long.compare(max, o.max);
        }

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

    int n;
    Point[] arr;
    List<List<Point>> layers = new ArrayList<>();
    void solve() throws IOException {
        n = nextInt();
        arr = new Point[n];
        for (int i = 0; i < n; i++) {
            long x = nextLong();
            long y = nextLong();
            arr[i] = new Point(x, y);
        }

        Arrays.sort(arr);
        List<Point> first = new ArrayList<>();
        first.add(new Point(0, 0));
        layers.add(first);
        int start = 0;
        while (start < n) {
            int end = start;
            List<Point> ls = new ArrayList<>();
            while (end < n && arr[end].max == arr[start].max) {
                ls.add(arr[end]);
                end++;
            }

            layers.add(ls);
            start = end;
        }

        for (List<Point> layer : layers) {
            Collections.sort(layer, new Comparator<Point>() {
                @Override
                public int compare(Point o1, Point o2) {
                    if (o1.x != o2.x) {
                        return Long.compare(o1.x, o2.x);
                    }

                    return Long.compare(o2.y, o1.y);
                }
            });
        }

        int sz = layers.size();
        long[][] dp = new long[sz][2];
        dp[0][0] = 0;
        dp[0][1] = 0;
        for (int i = 1; i < sz; i++) {
            Arrays.fill(dp[i], Long.MAX_VALUE);
        }

        for (int i = 0; i < sz - 1; i++) {
            //start from dp[i][0]
            Point c0 = layers.get(i).get(0);
            int m = layers.get(i).size();
            Point c1 = layers.get(i).get(m - 1);

            Point n0 = layers.get(i + 1).get(0);
            m = layers.get(i + 1).size();
            Point n1 = layers.get(i + 1).get(m - 1);

            dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][0] + dist(c0, n0) + dist(n0, n1));
            dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][0] + dist(c0, n1) + dist(n1, n0));

            dp[i + 1][1] = Math.min(dp[i + 1][1], dp[i][1] + dist(c1, n0) + dist(n0, n1));
            dp[i + 1][0] = Math.min(dp[i + 1][0], dp[i][1] + dist(c1, n1) + dist(n1, n0));
        }

        outln(Math.min(dp[sz - 1][0], dp[sz - 1][1]));
    }

    long dist(Point p1, Point p2) {
        return Math.abs(p1.x - p2.x) + Math.abs(p1.y - p2.y);
    }

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

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


import java.math.*;
import java.io.*;
import java.util.*;
public class C586E{
   public static long[] cAr, div;
   public static int N,M,K;
   public static int[] numCycle;
   public static Map<Integer,Set<Integer>> map;
   public static long MOD = 1000000007;
   public static void main(String[] args) throws IOException{
      InputReader in=new InputReader(new InputStreamReader(System.in));
      PrintWriter out=new PrintWriter(new BufferedOutputStream(System.out));
      long[] ar=in.nextLongAr();
      long A=ar[0]; long B=ar[1];
      if(gcd(A,B)!=1) System.out.println("Impossible");
      else{
         while(A+B>1){
            if(B>0 && (A-1)/B > 0){ System.out.print(((A-1)/B)+"A");
            A%=B;}
            if(A>0 && (B-1)/A > 0){ System.out.print(((B-1)/A)+"B");
            B%=A;}
         }
      }
   }

   public static long gcd(long x,long y){
      BigInteger a = BigInteger.valueOf(x);
      BigInteger b = BigInteger.valueOf(y);
      BigInteger gcd = a.gcd(b);
      return gcd.longValue();
   }

   public static void setUpChoose(int t){
      cAr=new long[t+1];
      div=new long[t+1];
      cAr[0]=1;
      div[0]=1;

      for(int x=1;x<=t;x++){
         cAr[x]=(x*cAr[x-1])%(MOD);
         div[x]=pow(cAr[x],MOD-2);}
   }

   public static long choose(int x,int y){
      long a=cAr[x+y];
      long b=div[x];
      long c=div[y];
      a=(a*b)%MOD;
      a=(a*c)%MOD;
      return a;
   }

   public static long pow(long a,long b){
      if(b==1)
         return a;
      long c=b/2;
      long temp=pow(a,c)%MOD;
      temp=(temp*temp)%MOD;
      if(b%2==1) temp=temp*a;
      return temp%MOD;
   }
}

class InputReader{
   private BufferedReader br;
   public InputReader(InputStreamReader in){
      br=new BufferedReader(in);
   }
   public int nextInt(){
      try{
         return Integer.parseInt(br.readLine());}
      catch(IOException e){throw new InputMismatchException();}
   }
   public int[] nextIntAr(){
      try{
         String[] s=br.readLine().split(" ");
         int[] ret=new int[s.length];
         for(int x=0;x<s.length;x++)
            ret[x]=Integer.parseInt(s[x]);
         return ret;}

      catch(IOException e){throw new InputMismatchException();}
   }

   public long nextLong(){
      try{
         return Long.parseLong(br.readLine());}
      catch(IOException e){throw new InputMismatchException();}
   }
   public long[] nextLongAr(){
      try{
         String[] s=br.readLine().split(" ");
         long[] ret=new long[s.length];
         for(int x=0;x<s.length;x++)
            ret[x]=Long.parseLong(s[x]);
         return ret;}

      catch(IOException e){throw new InputMismatchException();}
   }

   public String[] nextStringAr(){
      try{
         return br.readLine().split(" ");}

      catch(IOException e){throw new InputMismatchException();}
   }

   public String nextString(){
      try{
         return br.readLine();}

      catch(IOException e){throw new InputMismatchException();}
   }
}


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

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

    ArrayList<Integer> list = new ArrayList<>();
    for(int i = 0; i < n; i++){
      list.add(sc.nextInt());
    }

    ArrayList<Group> newL = new ArrayList<>();
    for(int i = 0; i < n; i++){
      int s = list.get(i);
      if(newL.size() == 0){
        newL.add(new Group(s, 1));
      } else {
        Group last = newL.get(newL.size() - 1);
        int lastVal = last.val;
        if(s == lastVal){
          last.countUp();
        } else {
          newL.add(new Group(s, 1));
        }
      }
    }

    int ansCount = 0;
    int l = 0;
    int r = 0;
    for(int i = 0; i < newL.size(); i++){
      Group s = newL.get(i);
      if(x == s.val){
        if(s.count > 1){
          l = i - 1;
          r = i + 1;
          int tempCount = 2;
          while(l >= 0 && r < newL.size()
          && newL.get(l).val == newL.get(r).val
          && newL.get(l).count + newL.get(r).count >= 3){
            tempCount += newL.get(r).count + newL.get(l).count;
            r += 1;
            l -= 1;
          }
          if(tempCount > ansCount){
            ansCount = tempCount;
          }
        }
      }
    }

    System.out.print(ansCount);
  }
}

public class Group {
  public int val;
  public int count;

  public Group(int val, int count){
    this.val = val;
    this.count = count;
  }

  public void countUp(){
    this.count += 1;
  }
}


public class A {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int m = scanner.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = scanner.nextInt();
        }
        StringBuilder s = new StringBuilder();
        int[] y = new int[m];
        for (int i = 0; i < m; i++) {
            y[i] = scanner.nextInt();
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                if (x[i] == y[j]) {
                    s.append(x[i]).append(" ");
                }
            }
        }
        System.out.println(s);
    }
}


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

public class Main {
    static BufferedReader newInput() throws IOException {
        return new BufferedReader(new InputStreamReader(System.in));
    }
    static PrintWriter newOutput() throws IOException {
        return new PrintWriter(System.out);
    }
    public static void main(String[] args) throws IOException {
        BufferedReader in = newInput();
        PrintWriter out = newOutput();
        function(in, out);
        out.flush();
    }
    public static void function(BufferedReader in, PrintWriter out) throws IOException {
        //StringTokenizer t = new StringTokenizer(in.readLine());
        String[] nk = in.readLine().split(" ");
        long n = Integer.parseInt(nk[0]);
        long k = Long.parseLong(nk[1]);
        ArrayList<Integer> nums = new ArrayList<>();
        for (int i = 1; i <= (int)n; i++) {
            nums.add(i);
        }
        int lucks = 0;
        long fact = factorial(Math.min(n, 14));
        long x = Math.min(n, 14);
        for (int i = 1; i < Math.max(1, (int)n-13); i++) {
            nums.remove(0);
            if (isLucky((int)i)){
                lucks++;
            }
        }
        for (int i = Math.max(1, (int)n-13); i <= n; i++) {
            fact /= x;
            x--;
            int b = (int)((k-1)/fact);
            if (b >= n){
                out.println("-1");
                return;
            }
            k -= (b*fact);
            int num = nums.get(b);
            nums.remove(b);
            if (isLucky(num) && isLucky(i)){
                lucks++;
            }
        }
        out.println(lucks);
    }
    public static long factorial(long num){
        long x = num;
        num--;
        for (;num != 0; num--) {
            x *= num;
        }
        return x;
    }
    public static boolean isLucky(int x){
        for (; x != 0; x /= 10) {
            int b = x % 10;
            if (b != 7 && b != 4){
                return false;
            }
        }
        return true;
    }
}


package dia2;

import java.util.Scanner;

public class Bender {

	static int n;
	static int C;
	static int x, y;

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

		n = s.nextInt();
		x = s.nextInt();
		y = s.nextInt();
		C = s.nextInt();
		int c = 0;
		long on = compute(c);
		int step = 1;
		while (on < C) {
			step *= 2;
			c += step;
			on = compute(c);
		}
		if (c==0){
			System.out.println(0);
			return;
		}
		int high = c;
		int low = c - step;
		int mid;
		while (low != high) {
			mid = (low+high)/2;
			on = compute(mid);
			if (on < C) {
				low = mid + 1;
			} else {
				high = mid;
			}
		}
		System.out.println(low);

	}

	static int compute(int c) {
		int acc = 1;
		int xl;
		int xr;
		acc += Math.min(y - 1, c);
		acc += Math.min(n - y, c);
		for (int i = 1; i <= c; i++) {
			xl = x - i;
			xr = x + i;
			if (xl > 0) {
				acc++;
				acc += Math.min(y - 1, c - i);
				acc += Math.min(n - y, c - i);
			}
			if (xr <= n) {
				acc++;
				acc += Math.min(y - 1, c - i);
				acc += Math.min(n - y, c - i);
			}
		}
		return acc;
	}

}


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

public class H {

	boolean solve() {
		int alph = nextInt();
		int n = nextInt();

		int[][] a = new int[n][];
		int tot = 0;
		for (int i = 0; i < n; i++) {
			int k = nextInt();
			int[] che = a[i] = new int[k];
			for (int j = 0; j < k; j++) {
				che[j] = nextInt() - 1;
			}
			tot += k;
		}

		int r = (int) Math.sqrt(tot * .7);

		for (int i = 0, j = n - 1;;) {
			while (i < j && a[i].length > r) {
				i++;
			}
			while (i < j && a[j].length <= r) {
				j--;
			}
			if (i == j) {
				break;
			}

			int[] tmp = a[i];
			a[i] = a[j];
			a[j] = tmp;
		}

		ArrayList<Integer>[] d = new ArrayList[alph];
		for (int i = 0; i < alph; i++) {
			d[i] = new ArrayList<>();
		}

		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length > r) {
				continue;
			}
			for (int j = 0; j < b.length; j++) {
				int idx = b[j];
				d[idx].add(i);
				d[idx].add(j);
			}
		}

		int[] map = new int[alph];
		Arrays.fill(map, -1);

		for (int i = 0; i < alph; i++) {
			ArrayList<Integer> shit = d[i];
			for (int j = 0; j < shit.size(); j += 2) {
				int where = shit.get(j);
				int from = shit.get(j + 1);

				int[] aW = a[where];
				int put = aW[from + 1];

				for (int k = from + 1; k < aW.length; k++) {
					int val = aW[k];
					if (map[val] != -1 && map[val] != put) {
						return true;
					}
					map[val] = put;
				}

			}

			for (int j = 0; j < shit.size(); j += 2) {
				int where = shit.get(j);
				int from = shit.get(j + 1);

				int[] aW = a[where];

				for (int k = from + 1; k < aW.length; k++) {
					map[aW[k]] = -1;
				}
			}
		}

		int[] id = new int[alph];
		Arrays.fill(id, -2);

		for (int i = 0; i < n; i++) {
			int[] b = a[i];
			if (b.length <= r) {
				break;
			}
			for (int j = 0; j < b.length; j++) {
				id[b[j]] = j;
			}

			for (int j = i + 1; j < n; j++) {
				if (clash(a[j], id)) {
					return true;
				}

			}

			for (int j = 0; j < b.length; j++) {
				id[b[j]] = -2;
			}
		}

		return false;
	}

	boolean clash(int[] a, int[] f) {
		int prev = f[a[0]];
		int curMin = prev == -2 ? Integer.MAX_VALUE : prev;
		for (int i = 1; i < a.length; i++) {
			int now = f[a[i]];
			if (now != prev + 1 && now > curMin) {
				return true;
			}
			if (now != -2) {
				curMin = Math.min(curMin, now);
			}

			prev = now;
		}
		return false;
	}

	void submit() {
		int t = nextInt();
		while (t-- > 0) {
			out.println(solve() ? "Human" : "Robot");
		}
	}

	void test() {

	}

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

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

	static final Random rng = new Random();
	static final int C = 5;

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

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

	private InputStream is;
	PrintWriter out;

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

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

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

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

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

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

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

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

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

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


//package que_a;

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

public class utkarsh {

    InputStream is;
    PrintWriter out;

    long mod = (long) (1e9 + 7), inf = (long) (8e18);
    boolean SHOW_TIME, debug;

    long fact[], inv[];

    void getF(int n) {
        fact = new long[n];
        inv = new long[n];
        fact[0] = fact[1] = 1;
        inv[0] = inv[1] = 1;
        for(int i = 2; i < n; i++) {
            fact[i] = (fact[i-1] * i) % mod;
            inv[i] = mp(fact[i], mod - 2);
        }
    }

    void solve() {
        //Enter code here utkarsh
        //SHOW_TIME = true;
	//debug = true;
        int n = ni(), k = ni();
        long ans[] = new long[k + 123];
        for(int i = 1; i < k+123; i++) {
            ans[i] = ans[i-1] + mp(i, k);
            if(ans[i] >= mod)   ans[i] -= mod;
        }
        if(n < k+123)   out.println(ans[n] % mod);
        else {
            getF(k+123);

            long s = 0;
            int p = 1;
            for(int i = k+122; i >= 1; i--) {
                s += mp(n-i, mod-2) * inv[i-1] % mod * inv[k+122-i] % mod * ans[i] * p;
                if(s >= inf)    s -= inf;
                if(s <= -inf)    s += inf;
                p = -p;
            }
            s %= mod;
            if(s < 0)   s += mod;
            long m = 1;
            for(int i = 1; i < k+123; i++) {
                m = m * (n-i) % mod;
            }
            out.println(s * m % mod);
        }
    }

    long mp(long b, long e) {
        long r = 1;
        while(e > 0) {
            if((e&1) == 1)  r = (r * b) % mod;
            b = (b * b) % mod;
            e >>= 1;
        }
        return r;
    }

    //---------- I/O Template ----------

    public static void main(String[] args) { new utkarsh().run(); }
    void run() {
        is = System.in;
        out = new PrintWriter(System.out);
        long start = System.currentTimeMillis();
        solve();
        long end = System.currentTimeMillis();
        if(SHOW_TIME) out.println("\n" + (end - start) + " ms");
        out.flush();
    }

    byte input[] = new byte[1024];
    int len = 0, ptr = 0;

    int readByte() {
        if(ptr >= len) { ptr = 0;
            try { len = is.read(input); }
            catch(IOException e) { throw new InputMismatchException(); }
            if(len <= 0) { return -1; }
        } return input[ptr++];
    }
    boolean isSpaceChar(int c) { return !( c >= 33 && c <= 126 ); }
    int skip() {
        int b = readByte();
        while(b != -1 && isSpaceChar(b)) { b = readByte(); }
        return b;
    }

    char nc() { return (char)skip(); }
    String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while(!isSpaceChar(b)) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    String nLine() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while( !(isSpaceChar(b) && b != ' ') ) { sb.appendCodePoint(b); b = readByte(); }
        return sb.toString();
    }
    int ni() {
        int n = 0, b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        if(b == -1) { return -1; }  //no input
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }
    long nl() {
        long n = 0L;    int b = readByte();
        boolean minus = false;
        while(b != -1 && !( (b >= '0' && b <= '9') || b == '-')) { b = readByte(); }
        if(b == '-') { minus = true; b = readByte(); }
        while(b >= '0' && b <= '9') { n = n * 10 + (b - '0'); b = readByte(); }
        return minus ? -n : n;
    }

    double nd() { return Double.parseDouble(ns()); }
    float nf() { return Float.parseFloat(ns()); }
    int[] na(int n) {
        int a[] = new int[n];
        for(int i = 0; i < n; i++) { a[i] = ni(); }
        return a;
    }
    char[] ns(int n) {
        char c[] = new char[n];
        int i, b = skip();
        for(i = 0; i < n; i++) {
            if(isSpaceChar(b)) { break; }
            c[i] = (char)b; b = readByte();
        } return i == n ? c : Arrays.copyOf(c,i);
    }
}


/*package whatever //do not write package name here */

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

public class GFG {
	public static void main (String[] args) {
	Scanner sc=new Scanner(System.in);
	int n=sc.nextInt();
	int m=sc.nextInt();
	int m1=m;
	int[] a=new int[n];
	int max=0;
	for(int i=0;i<n;i++){
	    a[i]=sc.nextInt();
	    if(a[i]>max)
	    max=a[i];
	}
	Arrays.sort(a);
	for(int i=0;i<n;i++){
	    if(m<=0)
	    {
	        max1=max;
	           break;
	    }

	    m=m-max+a[i];
	    a[i]=max;
	}
	int max1=0;
		for(int i=0;i<n;i++){
	    if(a[i]>max1)
	    max1=a[i];
	}
		int q=m/n;
	m=m%n;

	//System.out.println(q);
	System.out.print(max1+q+(m>0?1:0)+" ");
		System.out.print(max+m1);
	}
}


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

public class MikesSequence {
    private static int[] ratings = [1200,1400,1600,1900,2100,2300,2400,2600,3000];

    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);
        int n = in.nextInt();

        for (int i = 0; i < ratings.length; i++)  {
            if (n < ratings[i])  {
            	out.println(ratings[i]);
            	break;
            }
        }
        out.close();
    }

    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) {
                    // noop
                }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble()  {
            return Double.parseDouble(next());
        }
    }

}


package cf;

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.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

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

	static class TaskF {

		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int n = in.nextInt();
			int l = in.nextInt();
			int r = in.nextInt();
			long mod[][] = new long[3][n + 1];

			int x = (r - l + 1) / 3;
			int y = (r - l + 1) % 3;
			mod[0][1] = x;
			mod[1][1] = x;
			mod[2][1] = x;

			if (y == 1) {
				mod[l % 3][1]++;
			} else if (y == 2) {
				mod[l % 3][1]++;
				mod[r % 3][1]++;
			}

			long mm = 1000000007;
			for (int i = 2; i < n + 1; i++) {
				mod[0][i] = (mod[0][1] * mod[0][i - 1] + mod[1][1] * mod[2][i - 1] + mod[2][1] * mod[1][i - 1]) % mm;
				mod[1][i] = (mod[0][1] * mod[1][i - 1] + mod[1][1] * mod[0][i - 1] + mod[2][1] * mod[2][i - 1]) % mm;
				mod[2][i] = (mod[0][1] * mod[2][i - 1] + mod[2][1] * mod[0][i - 1] + mod[1][1] * mod[1][i - 1]) % mm;
			}
			out.println(mod[0][n]);
		}

	}

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

	}
}


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

public class Main {
    public static void main(String ...args) throws Throwable {
        Scanner in = new Scanner(System.in);
        String init = in.nextLine();
        HashSet<String> h = new HashSet<String>();
        for (int len = init.length() - 1; i >= 1; --i)  {
            h.clear();
            for (int pos = 0; pos + len <= init.length(); ++pos) {
                String now = init.substring(pos, pos + len);
                if (h.contains(now)) {
                    System.out.println(now);
                    return;
                }
            }

        }

    }
}


import java.util.Scanner;

public class Round207A {

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

        int m = sc.nextInt();
        int[] c = new int[m];
        for (int i=0; i<m; i++) {
            c[i] = sc.nextInt();
        }
        int x = sc.nextInt();
        int y = sc.nextInt();

        System.out.println(solve(m, c, x, y));
    }

    private static int solve(int m, int[] c, int x, int y) {
        int rate;
        int numChildlen = 0;
        int numBiginners = 0;

        for(int i=0; i<m; i++) {
            numChildlen += c[i];
        }

//      for (rate = 1; rate <= m; rate++) {
        for (int i = 1; i <= m; i++) {
            numBiginners += c[i - 1];

            if (numBiginners < x) continue;
            if (numBiginners >= x && numBiginners < y &&
                    (numChildlen - numBiginners) >= x && (numChildlen - numBiginners) < y) {
                rate = i + 1;
                break;
            }
            if (numBiginners > y) {
                rate = 0;
                break;
}
        }

        return rate;
    }
}


import java.util.*;
public class Ganesha {

  public static void main (String [] args){

  	Scanner in = new Scanner(System.in);

  	 long a = in.nextLong();
  	 long b = in.nextLong();
  	 long w = in.nextLong();
  	 long x = in.nextLong();
  	 long c = in.nextLong();
  	  w=w-x;

  	 if(c<=a)
  	 	System.out.print("0");

  	 	else if(c>a){
  	 		if(b>=(c-a)*x)
  	 			System.out.print((c-a));

  	 			else{
                    System.out.print((c-a +)Math.ceil((double)(((c-a)*x-b))/w)));

  	 			}

  	 	}
  }
  }


import java.io.*;
import java.util.*;
public class Taska{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
        long a[][]=new long[2][3];
        int t=1;
        long gcd(long a,long b){
        	if(a%b==0)return b;
        	return gcd(b,a%b);
        }
        long find(long v){
            long b[]={a[t][1],a[t][1]-v};
            long c[]={a[t][0],b[1]-(a[1-t][1]-a[1-t][0])};
            return Math.min(b[0],b[1])-Math.max(c[0],c[1])+1;
        }
		public void solve(int testNumber, InputReader in, PrintWriter out) {
 			for(int i=0;i<2;i++){
                for(int j=0;j<3;j++)a[i][j]=in.nextLong();
            }
            if(a[0][1]>a[1][1]){
                t=0;
            }
 			long gcd=gcd(a[t][2],a[1-t][2]);
 			long val=a[t][1]-a[1-t][1];
            long val1=val%gcd;
 			long val2=val1-gcd;
            out.print(Math.max(Math.max(find(val1),0),Math.max(find(val2),0)));
          }
//         pair ja[][];long w[];int from[],to[],c[];
//             void make(int n,int m,InputReader in){
//              ja=new pair[n+1][];w=new long[m];from=new int[m];to=new int[m];c=new int[n+1];
//              for(int i=0;i<m;i++){
//               int u=in.nextInt(),v=in.nextInt();long wt=in.nextLong();
//               c[u]++;c[v]++;from[i]=u;to[i]=v;w[i]=wt;
//              }
//              for(int i=1;i<=n;i++){
//               ja[i]=new pair[c[i]];c[i]=0;
//              }
//              for(int i=0;i<m;i++){
//               ja[from[i]][c[from[i]]++]=new pair(to[i],w[i]);
//               ja[to[i]][c[to[i]]++]=new pair(from[i],w[i]);
//              }
//             }
//        int[] radixSort(int[] f){ return radixSort(f, f.length); }
//	int[] radixSort(int[] f, int n)
//	{
//		int[] to = new int[n];
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
//			int[] d = f; f = to;to = d;
//		}
//		{
//			int[] b = new int[65537];
//			for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
//			for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//			for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
//			int[] d = f; f = to;to = d;
//		}
//		return f;
//	}
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

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

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

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


//I AM THE CREED
/* package codechef; // don't place package name! */
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import java.util.*;

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

        Scanner input = new Scanner(System.in);
        while(input.hasNext()){
            int n=input.nextInt();
            System.out.println(1+(n/2))
        }
    }
}


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

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

class TaskE {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.readInt();
        int k = in.readInt();
        long S = in.readLong();
        long[] a = IOUtils.readLongArray(in, n);

        long[] fact = new long[100];
        fact[0] = 1;
        int numFacts = 0;
        for (int i = 1; i < fact.length; i++) {
            if (fact[i - 1] * i <= S) {
                fact[i] = fact[i - 1] * i;
                numFacts = i;
            } else {
                break;
            }
        }
        fact = Arrays.copyOf(fact, numFacts + 1);
        if (n == 1) {
            if (S == 0 || S == a[0] || (a[0] < fact.length && k > 0 && fact[(int) a[0]] == S)) {
                out.printLine(1);
            } else {
                out.printLine(0);
            }
            return;
        }

        int n1 = n / 2;
        int n2 = n - n1;
        long[] a1 = Arrays.copyOfRange(a, 0, n1);
        long[] a2 = Arrays.copyOfRange(a, n1, n1 + n2);
        int capacity1 = (int) Math.pow(3, n1) + 1;
        int capacity2 = (int) Math.pow(3, n2) + 1;
        List<EzLongIntPair> list1 = new ArrayList<EzLongIntPair>(capacity1);
        List<EzLongIntPair> list2 = new ArrayList<EzLongIntPair>(capacity2);
        gen(a1, list1, fact, S, k, 0L, 0, 0);
        gen(a2, list2, fact, S, k, 0L, 0, 0);

        Comparator<EzLongIntPair> cmp = new Comparator<EzLongIntPair>() {
            public int compare(EzLongIntPair o1, EzLongIntPair o2) {
                if (o1.first < o2.first) return -1;
                if (o1.first > o2.first) return 1;
                return o1.second - o2.second;
            }
        };
        Collections.sort(list1, cmp);
        Collections.sort(list2, cmp);

        int[] cntK = new int[k + 1];
        int[] sumsK = new int[k + 1];
        EzLongIntPair toFind = new EzLongIntPair(0, 0);
        long ans = 0;

        for (int i = 0; i < list1.size(); ) {
            int j = i;
            long sum1 = list1.get(i).first;
            while (j < list1.size() && list1.get(j).first == sum1) {
                j++;
            }

            Arrays.fill(cntK, 0);
            for (int z = i; z < j; z++) {
                cntK[list1.get(z).second]++;
            }
            sumsK[0] = cntK[0];
            for (int t = 1; t < cntK.length; t++) {
                sumsK[t] = sumsK[t - 1] + cntK[t];
            }

            toFind.first = S - sum1;
            toFind.second = -100500;
            int L2 = ~Collections.binarySearch(list2, toFind, cmp);
            toFind.second = 100500;
            int R2 = ~Collections.binarySearch(list2, toFind, cmp);

            for (int z = L2; z < R2; z++) {
                int k2 = list2.get(z).second;
                if (k - k2 >= 0) {
                    ans += sumsK[k - k2];
                }
            }

            i = j;
        }
        out.printLine(ans);
    }

    private void gen(long[] a, List<EzLongIntPair> list, long[] fact, long maxS, int maxK, long curS, int curK, int i) {
        if (curS > maxS || curK > maxK) {
            return;
        }
        if (i == a.length) {
            list.add(new EzLongIntPair(curS, curK));
            return;
        }
        gen(a, list, fact, maxS, maxK, curS, curK, i + 1);
        gen(a, list, fact, maxS, maxK, curS + a[i], curK, i + 1);
        if (a[i] < fact.length) {
            gen(a, list, fact, maxS, maxK, curS + fact[(int) a[i]], curK + 1, i + 1);
        }
    }
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

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

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

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

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

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

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

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

class OutputWriter {
	private final PrintWriter writer;

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

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

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

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

class IOUtils {

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

}

class EzLongIntPair {
    private static final int HASHCODE_INITIAL_VALUE = 0x811c9dc5;
    private static final int HASHCODE_MULTIPLIER = 0x01000193;

    public long first;
    public int second;

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

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

        return first == that.first && second == that.second;
    }

    public int hashCode() {
        int hash = HASHCODE_INITIAL_VALUE;
        hash = (hash ^ PrimitiveHashCalculator.getHash(first)) * HASHCODE_MULTIPLIER;
        hash = (hash ^ PrimitiveHashCalculator.getHash(second)) * HASHCODE_MULTIPLIER;
        return hash;
    }

    public String toString() {
        return "(" + first + ", " + second + ")";
    }
}

class PrimitiveHashCalculator {

	public static int getHash(int x) {
        return x;
    }

    public static int getHash(long x) {
        return (int)x ^ (int)(x >>> 32);
    }

}


import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class C {
  private static class Task {
    boolean check(long n, long p) {
      long ans = 0;
      for (long k = 2; k * k * k <= n; k++) {
        ans += n / (k * k * k);
        if (ans > p) break;
      }
      return ans == p;
    }

    void solve(FastScanner in, PrintWriter out) {
      long p = in.nextLong();

      long h = 100000000000000;
      long l = 0;
      while (h - l > 1) {
        long n = (h + l) / 2;
        long ans = 0;
        for (long k = 2; k * k * k <= n; k++) {
          ans += n / (k * k * k);
          if (ans > p) break;
        }
        if (ans >= p) {
          h = n;
        } else {
          l = n;
        }
      }

      for (long n = Math.max(1, l + 1 - 10); n < l + 1 + 10; n++) {
        if (check(n, p)) {
          out.println(n);
          return;
        }
      }
      out.println(-1);
    }
  }

  // Template
  public static void main(String[] args) {
    OutputStream outputStream = System.out;
    FastScanner in = new FastScanner();
    PrintWriter out = new PrintWriter(outputStream);
    Task solver = new Task();
    solver.solve(in, out);
    out.close();
  }
  private static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int bufferLength = 0;

    private boolean hasNextByte() {
      if (ptr < bufferLength) {
        return true;
      } else {
        ptr = 0;
        try {
          bufferLength = in.read(buffer);
        } catch (IOException e) {
          e.printStackTrace();
        }
        if (bufferLength <= 0) {
          return false;
        }
      }
      return true;
    }

    private int readByte() {
      if (hasNextByte()) return buffer[ptr++];
      else return -1;
    }

    private static boolean isPrintableChar(int c) {
      return 33 <= c && c <= 126;
    }

    private void skipUnprintable() {
      while (hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
    }

    boolean hasNext() {
      skipUnprintable();
      return hasNextByte();
    }

    public String next() {
      if (!hasNext()) throw new NoSuchElementException();
      StringBuilder sb = new StringBuilder();
      int b = readByte();
      while (isPrintableChar(b)) {
        sb.appendCodePoint(b);
        b = readByte();
      }
      return sb.toString();
    }

    long nextLong() {
      if (!hasNext()) throw new NoSuchElementException();
      long n = 0;
      boolean minus = false;
      int b = readByte();
      if (b == '-') {
        minus = true;
        b = readByte();
      }
      if (b < '0' || '9' < b) {
        throw new NumberFormatException();
      }
      while (true) {
        if ('0' <= b && b <= '9') {
          n *= 10;
          n += b - '0';
        } else if (b == -1 || !isPrintableChar(b)) {
          return minus ? -n : n;
        } else {
          throw new NumberFormatException();
        }
        b = readByte();
      }
    }

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

    double[] nextDoubleArray(int n) {
      double[] array = new double[n];
      for (int i = 0; i < n; i++) {
        array[i] = nextDouble();
      }
      return array;
    }

    double[][] nextDoubleMap(int n, int m) {
      double[][] map = new double[n][];
      for (int i = 0; i < n; i++) {
        map[i] = nextDoubleArray(m);
      }
      return map;
    }

    public int nextInt() {
      return (int) nextLong();
    }

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


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

public class CF1156G {
	static class V {
		String s;
		char op = ' ';
		V u, v;
		int d;
		V(String s) {
			this.s = s;
		}
		V(char op, V u, V v) {
			this.op = op; this.u = u; this.v = v;
			d = Math.max(u.d, v.d) + 1;
		}
		@Override
		public String toString() {
			return s + "=" + u.s + op + v.s;
		}
	}
	static ArrayList<V> list = new ArrayList<>();
	static HashSet<String> set = new HashSet<>();
	static Random rand = new Random();
	static String getX() {
		String s;
		do {
			char x = (char) ('a' + rand.nextInt(26));
			s = "" + x + rand.nextInt(1000);
		} while (set.contains(s));
		return s;
	}
	static void dfs(V w, String s) {
		if (w.d == 0)
			return;
		if (w.s == null) {
			w.s = s;
			list.add(w);
			dfs(w.u, getX());
			dfs(w.v, getX());
		}
	}
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		HashMap<String, V> mp = new HashMap<>();
		while (n-- > 0) {
			char[] cc = br.readLine().toCharArray();
			int m = cc.length;
			int p = -1, q = -1;
			for (int j = 0; j < m; j++)
				if (cc[j] == '=')
					p = j;
				else if (cc[j] == '$' || cc[j] == '^' || cc[j] == '#' || cc[j] == '&')
					q = j;
			String lvalue = new String(cc, 0, p);
			set.add(lvalue);
			if (q == -1) {
				String rvalue = new String(cc, p + 1, m - p - 1);
				set.add(rvalue);
				V v = mp.get(rvalue);
				if (v == null) {
					v = new V(rvalue);
					mp.put(rvalue, v);
				}
				mp.put(lvalue, v);
			} else {
				String arg1 = new String(cc, p + 1, q - p - 1);
				String arg2 = new String(cc, q + 1, m - q - 1);
				set.add(arg1);
				set.add(arg2);
				char op = cc[q];
				V u = mp.get(arg1);
				if (u == null) {
					u = new V(arg1);
					mp.put(arg1, u);
				}
				V v = mp.get(arg2);
				if (v == null) {
					v = new V(arg2);
					mp.put(arg2, v);
				}
				V w = new V(op, u, v);
				mp.put(lvalue, w);
			}
		}
		V w = mp.get("res");
		if (w == null) {
			System.out.println(0);
			return;
		}
		dfs(w, "res");
		if (list.size() == 0 && w.op == ' ') {
			if (w.s.equals("res"))
				System.out.println(0);
			else {
				System.out.println(1);
				System.out.println("res=" + w.s);
			}
			return;
		}
		Collections.sort(list, (u, v) -> u.d - v.d);
		PrintWriter pw = new PrintWriter(System.out);
		pw.println(list.size());
		for (V v : list)
			pw.println(v);
		pw.close();
	}
}


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

/*
�����I�Ȗ��B
�J��Ԃ����A��̎���A���[�v�����̐ݒ�̎d��A
�ς��l�̐ݒ�̎d��|�C���g�B
*/
public class TaskB {
	BufferedReader reader;
	StringTokenizer tokenizer = null;
	PrintWriter writer;

	public static void main(String[] args) {
		try {
			new TaskB().run();
		} catch(IOException e) {
		}
	}

	void run() throws IOException {
		tokenizer = null;
		reader = new BufferedReader(new InputStreamReader(System.in));
		writer = new PrintWriter(System.out);
		solve();
		writer.flush();
	}

	private void solve() throws IOException {

		int vp = nextInt();
		int vd = nextInt();
		int t = nextInt();
		int f = nextInt();
		int c = nextInt();

		//int ttake = (vp * t) / (vd - vp);
		//int dis = vp * (t + ttake);
		//int less = c - dis;
		double ttake = (vp * t) / (vd - vp);
		double dis = vp * (t + ttake);
		double less = c - dis;
		int count = 0;
		double EPS = 1e-9;

		while (less > EPS) {
			count++;
			t = t + 2 * ttake + f;
			ttake = (vp * t) / (vd - vp);
			dis = vp * (t + ttake);
			less = c - dis;
		}

/*		int t0 = (vp * t) / (vd - vp);
		int T = t + t0;
		//int t0 = (vp * t) / (vd - vp) + t;
		int end = (c - vp * t) / vp + t;
		int count = 0;
		for (int i = 0; ; i++) {
			if (T < end) {
				count++;
				//t =  T + ((vp * T)/vd) + f;
				t =  T + t0 + f;
				t0 = (vp * t) / (vd - vp);
				T = t + t0;
				//count++;
			} else {
				break;
			}
			//if (t0 >= end) break;
			//if (T >= end) break;
			//else count++;
		}
*/
		writer.print(count);
	}

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

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

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

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

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

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

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

	double[] nextDoubleArray(int size) throws IOException {
		double[] ret = new double [size];
		for (int i = 0; i < size; i++)
			ret[i] = nextDouble();
		return ret;
	}

	String nextLine() throws IOException {
		//if (tokenizer == null || !tokenizer.hasMoreTokens())
			//tokenizer = new StringTokenizer("");
		//return in.readLine();
		if (tokenizer != null) return tokenizer.nextToken();
		return reader.readLine();
	}

    boolean EOF() throws IOException {
		while (!tokenizer.hasMoreTokens()) {
			String s = reader.readLine();
			if (s == null)
				return true;
 			tokenizer = new StringTokenizer(s);
		}
		return false;
	}

	/**********************
	* Output
	***********************/
	void printRepeat(String s, int count) {
		for (int i = 0; i < count; i++)
    		out.print(s);
	}

	void printArray(int[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
        	if (i > 0) out.print(' ');
            	out.print(array[i]);
		}
		out.println();
	}

	void printArray(long[] array) {
			if (array == null || array.length == 0)
				return;
			for (int i = 0; i < array.length; i++) {
				if (i > 0) out.print(' ');
					out.print(array[i]);
			}
			out.println();
	}

	void printArray(double[] array) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
				out.print(array[i]);
		}
		out.println();
	}

	void printArray(double[] array, String spec) {
		if (array == null || array.length == 0)
			return;
		for (int i = 0; i < array.length; i++) {
			if (i > 0) out.print(' ');
				out.printf(Locale.US, spec, array[i]);
		}
		out.println();
	}

	void printArray(Object[] array) {
		if (array == null || array.length == 0)
			return;
		boolean blank = false;
		for (Object x : array) {
			if (blank) out.print(' '); else blank = true;
				out.print(x);
		}
		out.println();
	}

	@SuppressWarnings("rawtypes")
	void printCollection(Collection collection) {
		if (collection == null || collection.isEmpty())
			return;
		boolean blank = false;
		for (Object x : collection) {
			if (blank) out.print(' '); else blank = true;
				out.print(x);
		}
		out.println();
	}

	/**********************
	* Utility
	***********************/

	static String memoryStatus() {
		return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory() >> 20) + "/" + (Runtime.getRuntime().totalMemory() >> 20) + " MB";
	}

	static void checkMemory() {
		System.err.println(memoryStatus());
	}

	static long prevTimeStamp = Long.MIN_VALUE;

	static void updateTimer() {
		prevTimeStamp = System.currentTimeMillis();
	}

	static long elapsedTime() {
		return (System.currentTimeMillis() - prevTimeStamp);
	}

	static void checkTimer() {
		System.err.println(elapsedTime() + " ms");
	}
}
/*
java.lang.NumberFormatException: For input string: "444444444444"
	at java.lang.NumberFormatException.forInputString(NumberFormatException.java:48)
	at java.lang.Integer.parseInt(Integer.java:461)
	at java.lang.Integer.parseInt(Integer.java:499)
	at T...

java.lang.NullPointerException
	at TaskA.nextLine(TaskA.java:133)
	at TaskA.solve(TaskA.java:51)
	at TaskA.run(TaskA.java:29)
	at TaskA.main(TaskA.java:20)

*/


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

public class A {
    private static final int mod = (int)1e9+7;

    IOFast io = new IOFast();

    long ans = 0;
    long min = Long.MIN_VALUE;
    void rec(long v, long x, long cur) {
        if(v == 0) return;
        if(min > v || min == v && cur < ans) return;
        if(v < 0) {
            if(min < v || min == v && cur > ans) {
                min = v;
                ans = cur;
            }
            return;
        }
        if(x * 3 <= v || x == 0) {
            return;
        }
        for(int i = 0; i < 3 && x * i != v; i++) {
            rec(v - x * i, x / 3, cur * 3 + i);
        }
    }

    public void run() throws IOException {
        long v = io.nextLong();
        long x;
        long res = 0;
        int cnt = 1;
        for(x = 1; x <= v; x *= 3) cnt++;
        int[] use = new int[cnt + 10];
        for(int i = cnt - 1; v != 0; x /= 3, i--) {
            use[i] = (int)(v / x);
            v %= x;
        }
        for(int i = 0; i < cnt; i++) {
            if(use[i] != 0) {
                int c = 1;
                long val = 1;
                for(int j = i + 1; j < use.length; j++) {
                    use[j] += c;
                    c = 0;
                    if(use[j] == 3) {
                        use[j] = 0;
                        c = 1;
                    }
                    res += use[j] * val;
                    val *= 3;
                }
                break;
            }
        }
        io.out.println(res);
    }

    void main() throws IOException {
        //      IOFast.setFileIO("rle-size.in", "rle-size.out");
        try {
            run();
        }
        catch (EndOfFileRuntimeException e) { }
        io.out.flush();
    }

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

    static class EndOfFileRuntimeException extends RuntimeException {
        private static final long serialVersionUID = -8565341110209207657L; }

    static
    public class IOFast {
        private BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        private PrintWriter out = new PrintWriter(System.out);

        void setFileIO(String ins, String outs) throws IOException {
            in = new BufferedReader(new FileReader(ins));
            out = new PrintWriter(new FileWriter(outs));
        }

        //      private static final int BUFFER_SIZE = 50 * 200000;
        private static int pos, readLen;
        private static final char[] buffer = new char[1024 * 8];
        private static final char[] str = new char[500000*8*2];
        private static boolean[] isDigit = new boolean[256];
        private static boolean[] isSpace = new boolean[256];
        private static boolean[] isLineSep = new boolean[256];

        static {
            for(int i = 0; i < 10; i++) { isDigit['0' + i] = true; }
            isDigit['-'] = true;
            isSpace[' '] = isSpace['\r'] = isSpace['\n'] = isSpace['\t'] = true;
            isLineSep['\r'] = isLineSep['\n'] = true;
        }

        public int read() throws IOException {
            if(pos >= readLen) {
                pos = 0;
                readLen = in.read(buffer);
                if(readLen <= 0) { throw new EndOfFileRuntimeException(); }
            }
            return buffer[pos++];
        }

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

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

        public char nextChar() throws IOException {
            while(true) {
                final int c = read();
                if(!isSpace[c]) { return (char)c; }
            }
        }

        int reads(char[] cs, int len, boolean[] accept) throws IOException {
            try {
                while(true) {
                    final int c = read();
                    if(accept[c]) { break; }
                    str[len++] = (char)c;
                }
            }
            catch(EndOfFileRuntimeException e) { ; }

            return len;
        }

        public char[] nextLine() throws IOException {
            int len = 0;
            str[len++] = nextChar();
            len = reads(str, len, isLineSep);

            try {
                if(str[len-1] == '\r') { len--; read(); }
            }
            catch(EndOfFileRuntimeException e) { ; }

            return Arrays.copyOf(str, len);
        }

        public String nextString() throws IOException {
            return new String(next());
        }

        public char[] next() throws IOException {
            int len = 0;
            str[len++] = nextChar();
            len = reads(str, len, isSpace);
            return Arrays.copyOf(str, len);
        }

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

    }
]