=
import java.util.*;

public class BullsAndCows_36C {
    public static void solve(int n, String input1[], String input2[]) {
        String guess1 = input1[0];
        Map<Character, Integer> mapGuess1 = new HashMap<>();
        Map<Character, Integer> mapGuess2 = new HashMap<>();
        int index = 0;
        for (char c : guess1.toCharArray()) {
            if (mapGuess1.get(c) != null) {
                System.out.println("Incorrect data");
                return;
            }
            mapGuess1.put(c, index++);
        }
        int bulls = Integer.parseInt(input1[1]);
        int cows = Integer.parseInt(input1[2]);

        String guess2 = input2[0];
        index = 0;
        int found = 0;
        for (char c : guess2.toCharArray()) {
            if (mapGuess2.get(c) != null) {
                System.out.println("Incorrect data");
                return;
            }
            if (mapGuess1.get(c) != null) {
                found++;
            }
            mapGuess2.put(c, index++);
        }

        if (found == 0) {
            System.out.println("Incorrect data");
            return;
        }
        int bulls2 = Integer.parseInt(input2[1]);
        int cows2 = Integer.parseInt(input2[2]);
        if (cows + bulls == (cows2 + bulls2) && found < bulls + cows) {
            System.out.println("Need more data");
            return;
        }

//        List<String> results = new ArrayList<>();
        Set<String> set = new HashSet<>();
//        char arr[] = new char[4];
//        for (int i = 0123; i <= 9876; i++) {
        for (char a = '0'; a <= '9'; a++) {
            for (char b = '0'; b <= '9'; b++) {
                for (char c = '0'; c <= '9'; c++) {
                    for (char d = '0'; d <= '9'; d++) {
                        StringBuilder str = new StringBuilder();
                        str.append(a);
                        str.append(b);
                        str.append(c);
                        str.append(d);
                        if (isUnique(str.toString())) {
                            set.add(str.toString());
                        }
                    }
                }
            }
        }

//        }

//            Iterator<Integer> it = set.iterator();
        String s[] = new String[]{guess1, guess2};
        int bul[] = new int[]{bulls, bulls2};
        int cow[] = new int[]{cows, cows2};
        index = 0;
        while (n-- > 0) {
            Iterator<String> itr = set.iterator();
            while (itr.hasNext()) {
                if (!comp(itr.next(), s[index], bul[index], cow[index])) {
                    itr.remove();
                }
            }
            index++;
//        if (comp(set, guess1, bulls, cows, guess2, bulls2, cows2)) {

        }
        for (String r : set) {
            System.out.println(r);
        }
    }

    private static boolean isUnique(String num) {
        Set<Character> set = new HashSet<>();
        for (char a: num.toCharArray()) {
            set.add(a);
        }
        return set.size() == 4;
    }

    public static boolean compare(char current[], String guess1, int bulls, int cows, String guess2, int bulls2,
                                  int cows2) {

        Set<Character> set_1 = new HashSet<>();
        for (char s : guess1.toCharArray()) {
            set_1.add(s);// - '0');
        }
        Set<Character> set_2 = new HashSet<>();
        for (char s : guess2.toCharArray()) {
            set_2.add(s);// - '0');
        }
        int samePos = 0;
//        Iterator<Integer> it_current = current.iterator();
        List<Character> remain = new ArrayList<>();
        int index = 0;
        for (char s : guess1.toCharArray()) {
            if (s == current[index++]) {
                samePos++;
            } else {
                remain.add(s);
            }
        }

        int f_cows = 0;
        for (char r : remain) {
            if (set_1.contains(r) || set_2.contains(r)) {
                f_cows++;
            }
        }
        if (f_cows != cows || samePos != bulls) return false;
        remain = new ArrayList<>();
        samePos = 0;
        index = 0;
        for (char s : guess2.toCharArray()) {
            if (s == current[index++]) {
                samePos++;
            } else {
                remain.add(s);
            }
        }
//        if (samePos < bulls2) {
//            return false;
//        }
        f_cows = 0;
        for (char r : remain) {
            if (set_2.contains(r) || set_1.contains(r)) {
                f_cows++;
            }
        }
        if (f_cows != cows2 || samePos != bulls2) return false;
        return true;
    }

    static boolean comp(String current, String guess1, int bulls, int cows) {
        char m[] = new char[26];
        for (char c : current.toCharArray()) {
            m[c - '0'] = 1;
        }
        int c = 0;
        int b = 0;

//        for (int i = 0; i < 2; ++i) {
        b = 0;
        c = 0;
        for (int j = 0; j < 4; ++j) {
            if (guess1.charAt(j) == current.charAt(j)) {
                b++;
            } else if (m[guess1.charAt(j) - '0'] == 1) {
                c++;
            }
        }

        if (b != bulls || c != cows) {
            return false;
        }
//        }

        return true;
    }

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int n = Integer.parseInt(in.nextLine());
//        for (int i = 0; i < n; i++) {
        String input1 = in.nextLine();
        String input2 = in.nextLine();

        solve(n, input1.split(" "), input2.split(" "));
//        }
    }
}


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

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        int a[] = new int[12];
        for (int i = 0; i < 12; ++i) {
            a[i] = sc.nextInt();
        }

        Arrays.sort(a, (o1, o2) -> o2.compareTo(o1));
        int sum = 0, i = 0;
        while (i < 12 && sum < k) {
            sum += a[i];
            i += 1;
        }
        if (sum < k) {
            System.out.print(-1);
        } else {
            System.out.print(i);
        }
    }
}


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();
        if (m != 0)
            System.out.println(min(m,n-m));
        else
            System.out.println(m);
	}
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.*;

public class Test {

  static PrintWriter writer =
      new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
  boolean found = false;
  boolean[] asked = new boolean[128];
  List<Integer>[] nei = new List[128];
  Vector<Integer> path = new Vector<>();

  {
    for (int i = 0; i < nei.length; i++) nei[i] = new ArrayList<>();
  }

  static int readInt() {
    int ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static long readLong() {
    long ans = 0;
    boolean neg = false;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (c == '-') {
          start = true;
          neg = true;
          continue;
        } else if (c >= '0' && c <= '9') {
          start = true;
          ans = ans * 10 + c - '0';
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return neg ? -ans : ans;
  }

  static String readString() {
    StringBuilder b = new StringBuilder();
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          b.append((char) c);
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return b.toString();
  }

  static int readChars(char[] a, int off) {
    int cnt = 0;
    try {
      boolean start = false;
      for (int c = 0; (c = System.in.read()) != -1; ) {
        if (Character.isLetterOrDigit(c)) {
          start = true;
          a[off + cnt++] = (char) c;
        } else if (start) break;
      }
    } catch (IOException e) {
    }
    return cnt;
  }

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

  void ask(int u) {
    writer.println("? " + u);
    writer.flush();
    asked[u] = true;
    nei[u].clear();
    int k = readInt();
    for (int i = 0; i < k; i++) nei[u].add(readInt());
    if (k == 2) answer(u);
  }

  private void answer(int u) {
    writer.println("! " + u);
    writer.flush();
    found = true;
  }

  void findPath(int u) {
    path.add(u);
    ask(u);
    if (found) return;
    for (int v : nei[u])
      if (!asked[v]) {
        findPath(v);
        break;
      }
  }

  void bfs(int u) {
    int cnt = 0;
    Queue<Integer> q = new LinkedList<>();
    q.offer(u);
    while (!found && cnt < 6 && !q.isEmpty()) {
      u = q.poll();
      ask(u);
      cnt++;
      for (int v : nei[u]) if (!asked[v]) q.add(v);
    }
    if (!found) answer(q.poll());
  }

  void start() {
    int t = readInt();
    while (t-- > 0) {
      readInt();
      found = false;
      Arrays.fill(asked, false);
      path.clear();
      findPath(1);
      if (found) continue;
      for (int v : nei[1])
        if (!asked[v]) {
          Collections.reverse(path);
          findPath(v);
          break;
        }
      while (!found) {
        int h = (path.size() + 1) / 2;
        path.setSize(h);
        int u = path.get(h - 1);
        for (int v : nei[u])
          if (!asked[v]) {
            if (h >= 4) bfs(v);
            else findPath(v);
            break;
          }
      }
    }
  }
}


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

public class Main{
	public static void main(String[] args) {
		new Main().solve();
	}
	public void solve(){
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		Scanner in = new Scanner(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		char[]s = in.next().toCharArray();
		getCode(s);
		out.close();
	}
	void getCode(char[]cs){
		String ans = "-1";
		boolean[]alpha = new boolean[26];
		int i,size = 0,beg = 0,j; char c;
		boolean end = false;
		if(cs.length > 25){
			for(i = 0; i < cs.length && !end; i++){
				end = true; size = 0;
				alpha = new boolean[26];
				for(j = i; j < cs.length && size < 26 && end; j++){
					c = cs[j];
					if(c == '?') size++;
					else if(alpha[c-'A']) end = false;
					else {alpha[c-'A'] = true; size++;}
				}
				if(end && size > 25) beg = i;
				else end = false;
			}
			if(end){
				ans = getCode(cs, alpha, beg);
			}
		}
	}
	void getCode(char[]cs, boolean[] alpha, int beg){
		String ans = ""; int i, size = 1,j;
		for(i = beg; size <= 26; i++, size++){
			if(cs[i] == '?'){
				j = 25;
				while(alpha[j] && j > -1) j--;
				cs[i] = (char)(j+'A');
				//System.out.println(j+"###");
				alpha[j] = true;
			}
		}
		for(i = 0; i < cs.length; i++){
			if(cs[i] == '?') System.out.print("A");
			else System.out.print(cs[i]);
		}
	}

	class Scanner{
		BufferedReader reader;
		StringTokenizer tokenizer;
		public Scanner(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 class zher{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        int s= in.next();
        if (s%2==0) System.out.println(2);
        else System.out.println(1);
    }
}


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

/**
 * Created with IntelliJ IDEA.
 * User: chinh
 * Date: 12/19/13
 * Time: 12:38 AM
 * To change this template use File | Settings | File Templates.
 */
public class R220D2A {
    public static void main(String[] args) throws Exception{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int i = Integer.parseInt(st.nextToken());
        int j = Integer.parseInt(st.nextToken());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int[] u = {1,n,n,1};
        int[] v = {m,1,m,1};
        int result = Integer.MAX_VALUE;
        for(int e=0; e<4; e++){
            if((u[e]-i)%a==0 && (v[e]-j)%b==0){
                if(((u[e]-i)/a)%2 - (v[e]-j)/b)%2==0){
                    result = Math.min(result, Math.max(Math.abs(u[e]-i)/a, Math.abs(v[e]-j)/a));
                }
            }
        }
        if(result==Integer.MAX_VALUE) System.out.println("Poor Inna and pony!"); else System.out.println(result);
    }
}


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

/**
 * @author huangjinkun.
 * @date 16/4/2
 * @time 上午12:23
 */
public class Wash {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String line1 = scanner.nextLine();
        String line2 = scanner.nextLine();
        String line3 = scanner.nextLine();

        int limit = Integer.parseInt(line1);
        int result = 0;
        String[] array1Tmp = line2.split(" ");
        String[] array2Tmp = line3.split(" ");

        int[] array1 = new int[array1Tmp.length];
        int[] array2 = new int[array2Tmp.length];

        for (int i = 0; i < array1.length; i++) {
            array1[i] = Integer.parseInt(array1Tmp[i]);
            array2[i] = Integer.parseInt(array2Tmp[i]);
        }

        Set<Integer> set = new HashSet<Integer>();
        for (int i = 0; i <= 1600000; i++) {
            for (int j = 0; j < array1.length; j++) {
                if (i % array1[j] == array2[j]) {
                    set.add(i);
                }
            }

        }

        System.out.println((double) (set.size()) / (1600000 + 1));
    }
}


import java.util.Scanner;
public class Divide{
    public static void main( String[] args ){
        Scanner numScan = new Scanner( System.in );
        String s = numScan.nextLine();
        while( s.charAt(0) = '0' ){
            s = s.substring(1);
        }
        if( s.length() - s.replaceAll( "0", "" ).length() > 5 ){
            System.out.println( "yes" );
        }
        else{
            System.out.println( "no" );
        }
    }
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.HashMap;
import java.util.StringTokenizer;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author Andy Phan
 */
public class e {
    long MOD = 1_000_000_007;

    public e() {
        FS in = new FS(System.in);
        PrintWriter out = new PrintWriter(System.out);

        int num = 300_000_000;

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

        int tot = 0;
        BitSet set = new BitSet((b+5)/2);
        for(int k = 6; k <= b; k += 6) {
            {
                int i = k+1;
                if(set.get(i/2)) continue;
                if(i >= a && i <= b && (i&0b11) == 1) tot++;
                for(long j = (long)i*i; j <= b; j += i+i) {
                    set.set((int)j/2, true);
                }
            }
            {
                int i = k+5;
                if(set.get(i/2)) continue;
                if(i >= a && i <= b && (i&0b11) == 1) tot++;
                for(long j = (long)i*i; j <= b; j += i+i) {
                    set.set((int)j/2, true);
                }
            }
        }

        if(a <= 2 && b >= 2) tot++;

        out.println(tot);

        out.close();
    }
    public static void main(String[] args) {
        new e();
    }

    static class FS {

        BufferedReader in;
        StringTokenizer token;

        public FS(InputStream str) {
            in = new BufferedReader(new InputStreamReader(str));
        }

        public String next() {
            if (token == null || !token.hasMoreElements()) {
                try {
                    token = new StringTokenizer(in.readLine());
                } catch (IOException ex) {
                }
                return next();
            }
            return token.nextToken();
        }

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


import java.io.*;

public class Solution{

    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in);
        String read = br.readLine();
        int last = 97
        for(int i = 0; i < read.length(); i++){
            int current = (int) read.charAt(i);
            if(current > last){
                if(current == last+1){
                    last++;
                }else{
                    System.out.println("NO");
                }
            }else{
                System.out.println("NO");
            }
        }
        System.out.println("YES");
    }
}


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

public class Main {

	BufferedReader in;
	StringTokenizer str = null;
	PrintWriter out;

	private String next() throws Exception{
		while (str == null || !str.hasMoreElements())
			str = new StringTokenizer(in.readLine());
		return str.nextToken();
	}

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

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

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

	byte []dp;
	int n = 5, m = 9;
	int []x,y;

	public void run() throws Exception{
		in =  new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		char [][]a = new char[n][];
		for(int i=0;i<n;i++) {
			String x = in.readLine();
			while(x.length() < m) x+=" ";
			a[i] = x.toCharArray();
		}

		x = new int[19];
		y = new int[19];
		int at = 0;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if (a[i][j] != ' ') {
					x[at] = i;
					y[at++] = j;
				}
			}
		}

		// print(a);

		dp = new byte[1 << 19];
		Arrays.fill(dp, (byte)-1);

		int mask = encode(a);
		// print(decode(mask));
		boolean r = dfs(mask);

		if (r) out.println("Karlsson");
		else out.println("Lillebror");

		// for(int i=0;i<1<<19;i++){
		// 	if (dp[i] != -1) {
		// 		print(decode(i));
		// 		System.out.println("result: " + dp[i]);
		// 		System.out.println();
		// 		System.out.println();
		// 	}
		// }

		out.close();
	}

	int di[] = new int[]{0,  0, 1, -1, 1,  1, -1, -1};
	int dj[] = new int[]{2, -2, 0,  0, 1, -1, -1,  1};

	private boolean dfs(int mask) {
		if (mask == 0) return false;
		if (dp[mask] != -1) return dp[mask] > 0;

		// System.out.println(mask);

		char [][]a = decode(mask);
		char [][]b;
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				if (a[i][j] == 'O') {
					for(int k=0;k<di.length;k++){
						int ni = i, nj = j;
						b = copy(a);
						while(inRange(ni, nj) && b[ni][nj] == 'O') {
							b[ni][nj] = '.';
							int nmask = encode(b);
							// System.out.println("from ");
							// print(a);
							// System.out.println("to ");
							// print(b);
							if (!dfs(nmask)) {
								dp[mask] = 1;
								return true;
							}
							ni+=di[k];
							nj+=dj[k];
						}
					}
				}
			}
		}

		dp[mask] = 0;
		return false;
	}

	private boolean inRange(int i, int j) {
		if (i < 0 || j < 0) return false;
		if (i >= n || j >= m) return false;
		return true;
	}

	private void print(char [][]a) {
		for(int i=0;i<n;i++) System.out.println(Arrays.toString(a[i]));
		System.out.println();
	}

	private char[][] copy(char [][]a) {
		char [][]b = a.clone();
		for(int i=0;i<n;i++) {
			b[i] = b[i].clone();
		}
		return b;
	}

	private int encode(char [][]a) {
		int mask = 0;
		for(int i=0;i<19;i++){
			if (a[x[i]][y[i]] == 'O') {
				mask|=1<<i;
			}
		}
		return mask;
	}

	private char[][] decode(int mask) {
		char [][]a = new char[n][m];
		// for(char []i : a) Arrays.fill(i, ' ');
		for(int i=0;i<19;i++){
			if ((mask & (1 << i)) > 0) {
				a[x[i]][y[i]] = 'O';
			}else {
				a[x[i]][y[i]] = '.';
			}
		}
		return a;
	}

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


mport java.util.Scanner;

public class train {

    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        long u = in.nextLong();
        long v = in.nextLong();
        boolean b = false;
        long x;
        if (u == 0 && v == 0) {
            System.out.println("0");b=true;
        }
        else
        if (u > v) {
            b = false;
        } else {
            if (u == 1) {
                b = true;
                System.out.println(v);
                for (int i = 0; i < v; i++) {
                    System.out.print("1 ");
                }
            }
            else if((v-u) %2 == 0 && v>100){System.out.println("3\n"+(v-u)/2+" "+(v-u)/2+" "+u);b = true;}
            else {
                for (int i = 1; i <= v/2; i++) {
                    x = u ^ i;
                    if (x + i == v) {
                        System.out.println(2 + "\n" + i + " " + x);
                        b = true;
                        break;
                    }
                }
            }
        }
        if (b == false) {
            System.out.println("-1");
        }

    }

}


import java.util.*;
public class A
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int count=0,flag=0;
        if(n==m)
        System.out.println(0);
        else
        {
            while(m!=n)
            {
                if(m%(n*2)==0))
                {
                    count++;
                    n=n*2;
                }
                else if(m%(n*3)==0)
                {
                    count++;
                    n=n*3;
                }
                else
                {
                    flag==1;
                    break;
                }
            }
            if(flag==1)
            System.out.println(-1);
            else
            System.out.println(count);
        }
    }
}


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

public class q2 {
    public static MyScanner in = new MyScanner();
    public static PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out), true);
    public static MyViewer view = new MyViewer();
    public static Random rand = new Random(System.currentTimeMillis());

    static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        private boolean randomInput = false;
        private Random rand;

        void randomInput(boolean r) {
            randomInput = r;
            rand = new Random(System.currentTimeMillis());
            //rand = new Random(42);
        }

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

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

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

        int nextInt(int val) {
            return randomInput ? val : Integer.parseInt(next());
        }

        int nextInt(int low, int high) {
            if (randomInput) {
                return rand.nextInt(high - low + 1) + low;
            } else {
                return Integer.parseInt(next());
            }
        }

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

        long nextLong(long val) {
            return randomInput ? val : Long.parseLong(next());
        }

        long nextLong(long low, long high) {
            if (randomInput) {
                return low + ((long) (rand.nextDouble() * (high - low + 1)));
            } else {
                return Long.parseLong(next());
            }
        }

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

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

        int[] arrayInt(int n, int low, int high) {
            int[] a = new int[n];
            if (randomInput) {
                for (int i = 0; i < n; i++) {
                    a[i] = rand.nextInt(high - low + 1) + low;
                }
            } else {
                for (int i = 0; i < n; i++) {
                    a[i] = in.nextInt();
                }
            }
            return a;
        }

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

        ArrayList<Integer> list(int n, int low, int high) {
            ArrayList<Integer> a = new ArrayList<Integer>(n);
            if (randomInput) {
                for (int i = 0; i < n; i++) {
                    a.add(rand.nextInt(high - low + 1) + low);
                }
            } else {
                for (int i = 0; i < n; i++) {
                    a.add(in.nextInt());
                }
            }
            return a;
        }

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

        long[] arrayLong(int n, long low, long high) {
            long[] a = new long[n];
            if (randomInput) {
                for (int i = 0; i < n; i++) {
                    double r = rand.nextDouble();
                    a[i] = (long) (r * (double) (high - low + 1)) + low;
                    if (a[i] == 0) {
                        out.println("Ouch : " + r);
                    }
                }
            } else {
                for (int i = 0; i < n; i++) {
                    a[i] = in.nextLong();
                }
            }
            return a;
        }

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

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

        ArrayList<ArrayList<Integer>> randomTree(int n) {
            ArrayList<ArrayList<Integer>> edges = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                edges.add(new ArrayList<>());
            }

            for (int i = 1; i < n; i++) {
                int par = rand.nextInt(i);
                edges.get(par).add(i);
            }
            return edges;
        }
    }

    static class MyViewer {
        static boolean print = true;

        public void on() {
            print = true;
        }

        public void off() {
            print = false;
        }

        public <T extends List> void list(T a) {
            if (!print) return;
            out.print("List: [" + a.get(0));
            for (int i = 1; i < a.size(); i++) {
                out.print(", " + a.get(i));
            }
            out.println("] Len: " + a.size());
        }

        public <T> void array(T[] a) {
            if (!print) return;
            out.print("Array: [" + a[0]);
            for (int i = 1; i < a.length; i++) {
                out.print(", " + a[i]);
            }
            out.println("] Len: " + a.length);
        }

        public void array(boolean[] a) {
            if (!print) return;
            out.print("boolean[] Len: " + a.length + " [");
            for (boolean x : a) {
                out.print(x + ", ");
            }
            out.println("\b\b]");
        }

        public void array(int[] a) {
            if (!print) return;
            out.print("int[] Len: " + a.length + " [");
            for (int x : a) {
                out.print(x + ", ");
            }
            out.println("\b\b]");
        }

        public void array(long[] a) {
            if (!print) return;
            out.print("long Array: [");
            for (long x : a) {
                out.print(x + ", ");
            }
            out.println("\b\b] Len: " + a.length);
        }

        public void matrix(int[][] a, int cutoff) {
            if (cutoff == 0)
                cutoff = Integer.MAX_VALUE;
            for (int i = 0; i < a.length; i++) {
                if (i < cutoff) {
                    printMatrixRow(a[i], cutoff);
                } else {
                    out.println("     ...");
                    printMatrixRow(a[a.length - 1], cutoff);
                    break;
                }
            }
        }

        public void matrix(long[][] a, long cutoff) {
            if (cutoff == 0)
                cutoff = Long.MAX_VALUE;
            for (int i = 0; i < a.length; i++) {
                if (i < cutoff) {
                    printMatrixRow(a[i], cutoff);
                } else {
                    out.println("     ...");
                    printMatrixRow(a[a.length - 1], cutoff);
                    break;
                }
            }
        }

        public void matrix(boolean[][] a, int cutoff) {
            if (cutoff == 0)
                cutoff = Integer.MAX_VALUE;
            for (int i = 0; i < a.length; i++) {
                if (i < cutoff) {
                    printMatrixRow(a[i], cutoff);
                } else {
                    out.println("     ...");
                    printMatrixRow(a[a.length - 1], cutoff);
                    break;
                }
            }
        }

        private void printMatrixRow(int[] a, int cutoff) {
            for (int j = 0; j < a.length; j++) {
                if (j < cutoff) {
                    out.printf("%6d  ", a[j]);
                } else {
                    out.printf(" ... %6d", a[a.length - 1]);
                    break;
                }
            }
            out.println();
        }

        private void printMatrixRow(long[] a, long cutoff) {
            for (int j = 0; j < a.length; j++) {
                if (j < cutoff) {
                    out.printf("%6d  ", a[j]);
                } else {
                    out.printf(" ... %6d", a[a.length - 1]);
                    break;
                }
            }
            out.println();
        }

        private void printMatrixRow(boolean[] a, int cutoff) {
            for (int j = 0; j < a.length; j++) {
                if (j < cutoff) {
                    out.print(a[j] ? "T " : "F ");
                } else {
                    out.print(" ... " + (a[a.length - 1] ? "T" : "F"));
                    break;
                }
            }
            out.println();
        }

    }

    public static void main(String[] args) throws IOException {
        int n = in.nextInt();
        int m = in.nextInt();
        int[] a = in.arrayInt(m);
        int[] b = new int[n];

        Arrays.fill(b, -1);

        int l,nl;

        for (int mi = 1; mi < m; mi++) {
            l= a[mi-1]-1;
            nl = a[mi]-1;
            if( nl < l)
                nl += n;

            int x = nl - l;
            if( x == 0)
                x = n;
            if( b[l] < 0 ) {
                b[l] = x;
            } else if( b[l] == x) {
                continue;
            } else {
                out.println(-1);
                System.exit(0);
            }
        }

        boolean[] used = new boolean[n];

        for(int i = 0 ;i < n; i ++) {
            if( b[i] % n >= 0 && used[b[i] % n]) {
                out.println(-1);
                System.exit(0);
            }
            if( b[i] % n >= 0)
                used[b[i] % n] = true;
        }

        HashSet<Integer> hs = new HashSet<>();
        for(int x: b) {
            if (x >=0 )
                hs.add(x);
        }

        for(int i = 0 ;i < n; i ++) {
            if(b[i] == -1 ) {
                for(int j = 0; j < n; j ++) {
                    if (hs.contains(j))
                        continue;
                    b[i] = j;
                    hs.add(j);
                }
            }
        }

        for(int i = 0 ;i < n; i ++) {
            out.print((b[i]) + " ");
        }
        out.println();

        in.close();
    }


import jav.util.Scanner;
public class code{
    public static void main(String args){
      Scanner sc=new Scanner(System.in);
      String a=sc.next();
      String a=sc.next();
      int count=0;
      if(a.length()==b.length())
      {
      for(int i=0;i<a.length()-1;i++){
          if(a.charAt(i)!=b.charAt(i))
          count=1;
      }
      if(count==1)
      System.out.println(0);
      else{
          int a=Integer.parseInt(a.charAt(a.length()-1);
          int b=Integer.parseInt(b.charAt(b.length()-1);
          int c=1;
          for(int i=b;i>a;i--)
          c=c*i;
          c=c%10;
          System.out.println(c);
      }
    }
    else
    System.out.println(0);
    }
}


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

public class Joysticks {

    int chargingLevel;
    boolean connectedToCharger;

    Joysticks() {
    }

    public static void main(String[] args) {
        Joysticks a1 = new Joysticks();
        Joysticks a2 = new Joysticks();
        int numOfMinutes = 1;
        boolean chargerIsChanged;

        String input = "";
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            input = br.readLine();
        } catch (Exception e) {
            e.printStackTrace();
        }

        String[] arr = input.split(" ");
        a1.chargingLevel = Integer.parseInt(arr[0]);
        a2.chargingLevel = Integer.parseInt(arr[1]);

        while (a1.chargingLevel != 0 && a2.chargingLevel != 0) {

                if (numOfMinutes == 1) {
                    if (a1.chargingLevel < a2.chargingLevel) {
                        a1.connectedToCharger = true;
                        a1.chargingLevel += 1;
                        a2.chargingLevel -= 2;
                    }
                    if (a2.chargingLevel < a1.chargingLevel && !a1.connectedToCharger) {
                        a2.connectedToCharger = true;
                        a2.chargingLevel += 1;
                        a1.chargingLevel -= 2;
                    }
                    if(a1.chargingLevel == a2.chargingLevel && !a1.connectedToCharger && !a2.connectedToCharger){
                        a1.connectedToCharger = true;
                        a1.chargingLevel += 1;
                        a2.chargingLevel -= 2;
                    }
                }
                if (numOfMinutes > 1) {
                    if(a1.chargingLevel < a2.chargingLevel && !chargerIsChanged){
                        a1.chargingLevel += 1;
                        a2.chargingLevel -= 2;
                        chargerIsChanged = true;
                    }
                    if(a2.chargingLevel < a1.chargingLevel && !chargerIsChanged){
                        a2.chargingLevel += 1;
                        a1.chargingLevel -= 2;
                        chargerIsChanged = true;
                    }
                    if(a1.chargingLevel == a2.chargingLevel && !chargerIsChanged){
                        if (a1.connectedToCharger) {
                            a1.chargingLevel += 1;
                            a2.chargingLevel -= 2;
                        }
                        if (a2.connectedToCharger) {
                            a2.chargingLevel += 1;
                            a1.chargingLevel -= 2;
                        }
                    }
                }

            if (a1.chargingLevel != 0 && a2.chargingLevel != 0) {
                numOfMinutes++;
            }
        }
        System.out.println(numOfMinutes);
    }
}


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

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

    private void run() throws Exception{
        Scanner input = new Scanner(System.in);
        int a = input.nextInt();
        int b = input.nextInt();
        int m = input.nextInt();
        int r0 = input.nextInt();
        int pos = 0;
        ArrayList<Integer>list = new ArrayList<Integer>();
        while(true){
            if(list.contains(r0)){
                pos = list.size() - list.indexOf(r0);
                break;
            }
            else{
                list.add(r0);
            }
            r0 = (a*r0 + b)%m;
        }
        System.out.println(pos);
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in) ;
        int n = sc.nextInt() ;
        for (int i =0 ; i< n ; i++){
          System.out.println(sc.nextInt() / 2);
        }

    }


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

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

class TaskA {
    long check(int hy, int ay, int dy, int hm, int am, int dm) {
        if ( dm >= ay ) return (long)1e9;
        if ( dy >= am ) return 0L;

        int monsterHints = (hy + am - dy - 1) / (am - dy);
        int yangHints = (hm + ay- dm - 1) / (ay - dm);

        if ( monsterHints > yangHints ) return 0;
        else if ( monsterHints == yangHints ) return 1 * (am - dy);
        else return (yangHints - monsterHints + 1) * (am - dy);
    }

    public void solve(int testNumber, Scanner in, PrintWriter out) {
        int hpy = in.nextInt();
        int atky = in.nextInt();
        int defy = in.nextInt();

        int hpm = in.nextInt();
        int atkm = in.nextInt();
        int defm = in.nextInt();

        int h = in.nextInt();
        int a = in.nextInt();
        int d = in.nextInt();

        long ans = (int)1e9;
        for (int i = 0; i <= 100; i++)
            for (int j = 0; j <= 100; j++) {
                ans = Math.min( ans, i*a + j*d + check(hpy, atky + i, defy + j, hpm, atkm, defm)*h );
            }

        out.println( ans );
    }
}


/*
  Goal: Become better in CP!
  Key: Consistency and Discipline
  Desire: SDE @ Google USA
  Motto: Do what i Love <=> Love what i do
  If you don't use your brain 100%, it deteriorates gradually
*/

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

public class Solution {

  static StringBuffer str=new StringBuffer();
  static BufferedReader bf;
  static PrintWriter pw;
  static int n, x;
  static long mod=998244353l;
  static long dp[][];
  static long comb[][];

  static long mod_mul(long a, long b) {
    a = a % mod;
    b = b % mod;
    return (((a * b) % mod) + mod) % mod;
  }

  static long mod_add(long a, long b) {
    a = a % mod;
    b = b % mod;
    return (((a + b) % mod) + mod) % mod;
  }

  static long pow(long a, long b) {
    long res = 1;
    while (b > 0) {
        if (b % 2 == 1) res = (res * a)%mod;
        a = (a * a)%mod;
        b = b >> 1l;
    }
    return res;
  }

  // O(n*x*n) solution
  static long count(int i, int j){
    if(i==1) return 0;
    if(i==0) return 1;
    if(j>=x) return 0;
    if(dp[i][j]!=-1) return dp[i][j];

    int cost = Math.min(x, j+i-1);
    // Transition from dp[i][j] to dp[k][cost]
    long ans=0;
    for(int k=0;k<=i;k++){
      ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), count(k, cost))));
    }
    return dp[i][j]=ans;
  }

  // DP + Combinatorics
  static void solve(int te) throws Exception{
    comb = new long[501][501];
    comb[0][0] = 1;
    for (int i = 1; i <= 500; i++) {
      comb[i][0] = 1;
      for (int j = 1; j <= i; j++) {
        comb[i][j] = (comb[i-1][j] + comb[i-1][j-1]) % mod;
      }
    }

    /* // Top down dp

    // dp[i][j] = # of ways to choose health = required answer
    // i -> i heros still alive => i=n is required
    // j -> already received j damage => j<=x is required

    // sum of dp[0][j] for each j in [0, x] is the answer
    dp=new long[n+1][x+1];
    for(int i=0;i<=n;i++){
      for(int j=0;j<=x;j++){
        dp[i][j]=-1;
      }
    }
    str.append(count(n, 0)).append("\n");
    */
    // bottom up dp
    dp=new long[n+1][x+1];

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

    for(int i=2;i<=n;i++){
      for(int j=x-1;j>=0;j--){
        int cost = Math.min(x, j+i-1);
        // Transition from dp[i][j] to dp[k][cost]
        long ans=0;
        for(int k=0;k<=i;k++){
          ans=mod_add(ans, mod_mul(comb[i][i-k], mod_mul(pow(cost-j, i-k), dp[k][cost])));
        }
        dp[i][j]=ans;
      }
    }
    str.append(dp[n][0]).append("\n");
  }

  public static void main(String[] args) throws java.lang.Exception {
    boolean lenv=false;
    int te=1;
    if(lenv){
      bf = new BufferedReader(
                          new FileReader("input.txt"));
      pw=new PrintWriter(new
            BufferedWriter(new FileWriter("output.txt")));
    }else{
      bf = new BufferedReader(new InputStreamReader(System.in));
      pw = new PrintWriter(new OutputStreamWriter(System.out));
    }

    // int q1 = Integer.parseInt(bf.readLine().trim());
    // for(te=1;te<=q1;te++) {
      String s[]=bf.readLine().trim().split("\\s+");
      n=Integer.parseInt(s[0]);
      x=Integer.parseInt(s[1]);
      solve(te);
    // }
    pw.print(str);
    pw.flush();
    // System.out.println(str);
  }
}


import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int num = in.nextInt();
        in.nextLine();
        int[] arr = new int[num];
        for (int i = 0; i < num; i++) {
            arr[i] = in.nextInt();
        }
        if (num % 2 == 1 && arr[0] % 2 == 1 && arr[num - 1] % 2) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }
}


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

public class Kitchen{

    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int r=sc.nextInt();
        int k=sc.nextInt();
        HashMap<Integer,Integer> h=new HashMap<>();
        int max=1;
        for(int i=0;i<n;i++)
        {
            int a=sc.nextInt();
            if(h.containsKey(a))
            {
                int x=h.get(a);
                x++;
                h.put(a,x);
                if(x>max)
                max=x;
            }
            else
            {
                h.put(a,1);
            }
        }
        while(max%k!=0)
        {
            max++;
        }
        int c=0;
        for(int g:h.keySet())
        {
            int y=h.get(g);
            c=c+(max-y);
        }
        System.out.println(c);

    }

}


import java.util.*;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int grains = sc.nextInt();
        int m = sc.nextInt();
        int n = grains;
        int days = 0;
        int s = 0;
        while(n!=0) {
            days++;
            s++;
            n+=m;
            if(n>=grains) {
                n = grains;
            }
            n -= sp;
            if(n<=0) {
                break;
            }
        }
        System.out.println(days);
    }
}


import org.jetbrains.annotations.NotNull;

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

public class CodeForces {
    private final static FastReader in = new FastReader();
    private final static PrintWriter out = new PrintWriter(System.out);

    static class ele implements Comparable<ele> {
        int a, b;

        public ele(int a, int b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public int compareTo(@NotNull CodeForces.ele ele) {

            return ele.b - b;
        }
    }

    public static void main(String[] args) {
        int n = in.nextInt(), m = in.nextInt();
        ArrayList<ele> arrayList = new ArrayList<>(m);
        while (m-- > 0) {
            arrayList.add(new ele(in.nextInt(), in.nextInt()));
        }
        Collections.sort(arrayList);
        ele e;
        int res = 0;
        for (int i = 0; i < arrayList.size(); i++) {
            e = arrayList.get(i);
            if (e.a <= n) {
                n -= e.a;
                res += (e.a * e.b);
            } else if (e.a > n && n != 0) {
                res += (n * e.b);
                break;
            } else {
                break;
            }
        }
        out.println(res);
        out.flush();
    }

    private static final class FastReader {
        private static BufferedReader BF;
        private static StringTokenizer ST;

        public FastReader() {
            BF = new BufferedReader(new InputStreamReader(System.in));
            ST = null;
        }

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

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

    }

}


import java.io.*;
import java.util.*;
/*
 * 	Heart beats fast
 * 		Colors and promises
 * 			How to be brave
 * 				How can I love when I am afraid to fall...
 */
public class Main
{
	public static void main(String[] args) throws IOException
	{
		int n =ni();
		long a=1,b=1;
		long ans=0;
		for(i=1;i<=n;i++){
			a=(27*a)%mod;
			b=(7*b)%mod;
			ans=(a-b+mod)%mod;
		}
		System.out.println(ans);
	}
	static int bsl(int arr[],int data,int start,int end){
		int mid=start+(end-start)/2;
		if(arr[mid]==data)
			return mid;
		if(end-start==1)
			return mid;
		else if(data > arr[mid])
			return bsl(arr,data,mid,end);
		else
			return bsl(arr,data,start,mid);
	}
	static final int mod=1000000007;
	static final double eps=1e-8;
	static final long inf=100000000000000000L;
	static final boolean debug=true;
	static Reader in=new Reader();
	static StringBuilder ans=new StringBuilder();
	static long powm(long a, long b, long m)
	{
		long an=1;
		long c=a;
		while(b>0)
		{
			if(b%2==1)
				an=(an*c)%m;
			c=(c*c)%m;
			b>>=1;
		}
		return an;
	}
	static Random rn=new Random();
	static void pd(){if(debug)ans.append("hola");}
	static void pd(Object a){if(debug)ans.append(a+"\n");}
	static void pr(Object a){ans.append(a+"\n");}
	static void pr(){ans.append("\n");}
	static void p(Object a){ans.append(a);}
	static void sop(Object a){System.out.println(a);}
	static int ni(){return in.nextInt();}
	static int[] nia(int n){int a[]=new int[n];for(int i=0; i<n; i++)a[i]=ni();return a;}
	static long[] nla(int n){long a[]=new long[n];for(int i=0; i<n; i++)a[i]=nl();return a;}
	static String[] nsa(int n){String a[]=new String[n];for(int i=0; i<n; i++)a[i]=ns();return a;}
	static long nl(){return in.nextLong();}
	static String ns(){return in.next();}
	static double nd(){return in.nextDouble();}
	static String pr(String a, long b)
	{
		String c="";
		while(b>0)
		{
			if(b%2==1)
				c=c.concat(a);
			a=a.concat(a);
			b>>=1;
		}
		return c;
	}
	static class Reader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public Reader() {
            reader = new BufferedReader(new InputStreamReader(System.in), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
        	return Long.parseLong(next());
        }
        public double nextDouble() {
        	return Double.parseDouble(next());
        }
    }
	static class dyns
	{
		dyns(long le,long ri)
		{
			lb=le;
			rb=ri;
		}
		dyns l,r;
		long val,lb,rb;
		void set(long te)
		{
			val++;
			if(lb!=te||rb!=te)
			{
				if((lb+rb)/2>=te)
				{
					if(l==null)
						l=new dyns(lb, (lb+rb)/2);
					l.set(te);
				}
				else
				{
					if(r==null)
						r=new dyns(((lb+rb)/2)+1,rb);
					r.set(te);
				}
			}
		}
		void reset(long a)
		{
			val--;
			if(val==0)
			{
				l=null;
				r=null;
				return;
			}
			if(lb!=a||rb!=a)
			{
				if((lb+rb)/2>=a)
					l.reset(a);
				else
					r.reset(a);
			}
		}
		long count(long le, long ri)
		{
			if(le<=lb&&ri>=rb)
				return val;
			if(le>rb)
				return 0;
			if(ri<lb)
				return 0;
			int a=0;
			if(l!=null)
				a+=l.count(le,ri);
			if(r!=null)
				a+=r.count(le,ri);
			return a;
		}
	}
}


package vanilla;

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

public class Main {

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

        Solver solver = new Solver();
        solver.solve(in, out);
        out.close();
    }
}


import java.util.*;
public class Arpa {

	public static void main(String[] args) {

		Scanner in = new Scanner(System.in);

		int t = in.nextInt();

		int x = Math.pow(8, t);

		System.out.println(x % 10);

	}

	}


public class Main{
	public static void public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String palavra = scan.next():
		int lMax =0;
		int lMin = 0;
		for (int i=0;i<palavra.lenght();i++ ) {
			if(palavra.charAt(i)==nome.toUpperCase().charAt(i)){
				lMax+=i;
			}else{
				lMin+=i;
			}
		}
		if(lMax>lMin){
			System.out.println(nome.toUpperCase());
		}else{
			System.out.println(nome.toLowerCase());
		}
	}
}
// 1506478776669


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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Iain Watson-Smith
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskA solver = new TaskA();
		int testCount = Integer.parseInt(in.next());
		for (int i = 1; i <= testCount; i++)
			solver.solve(i, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        class Pair
        {
            int x;
            int y;
            Pair(int x, int y) {
                this.x = Math.min(x, y);
                this.y = Math.max(x, y);
            }
        }
        int n = in.getInt();
        int [] A = new int[n];

        for(int i = 0; i < n; ++i){
            A[i] = in.getInt();
        }
        ArrayList<Pair> scores = new ArrayList<Pair>();
        for(int i = 1; i < n; ++i){
            int x = A[i - 1];
            int y = A[i];
            Pair p = new Pair(x, y);
            scores.add(p);
        }
        boolean ok = true;
        for(int i = 0; i < n - 1; ++i){
            for(int j = 0; j < n - 1; ++j)
            {
                if(j!=i){

                    Pair a = scores.get(i);
                    Pair b = scores.get(j);
                    int x1 = a.x;
                    int x2 = a.y;
                    int x3 = b.x;
                    int x4 = b.y;
                    if(x1 < x3 && x3 < x2 && x2 < x4)
                    {
                        ok = false;
                    }
                    if(x3 < x1 && x1 < x4 && x4 < x2){
                        ok = false;
                    }
                }
            }
        }
        if(ok){
            System.out.println("no");
        }
        else System.out.println("yes");
    }
}

class InputReader {

    BufferedReader reader;
    StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenizer = null;
    }
    public String nextToken() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int getInt() {
        return Integer.parseInt(nextToken());
    }
    public long getLong() {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() {
        return Double.parseDouble(nextToken());
    }
}


import java.util.*;
public class given_len_sum_of_dig {

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

		}


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

public class TaskC {

    Scanner in;

    public void solve() {
        int left = in.nextInt();
        int right = in.nextInt();
        int res = 0;
        String str = Integer.toBinaryString(left);
        int pos  = str.length() - 1;
        long num = (long)Math.pow(2,pos);
        if (num < left) {
            num = num * 2;
        }
        long cur = num;
        while (cur <= right) {
            res++;
            long cur2 = cur * 3;
            while (cur2 <= right) {
                res++;
                cur2 = cur2 * 3;
            }
            cur = cur * 2;
        }
        cur = num/2;
        while (cur > 0) {
            long cur2 = cur;
            while (cur2 < left) {
                cur2 = cur2 * 3;
            }
            while (cur2 <=right) {
                res++;
                cur2 = cur2*3;
            }
            cur = cur / 2;
        }

        System.out.println(res);

    }
    public void run() {
        in = new Scanner();
        solve();

    }

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


import java.util.Scanner;

public class QueueAtTheSchool {
    public static void main(String[] args) {

        Scanner scr = new Scanner(System.in);
         int gb=scr.nextInt();
         int t=scr.nextInt();
         String  s=  scr.next();
        char[] array = s.toCharArray();
        char temp;
         char  []temparray=s.toCharArray() ;
         for (int i=0 ; i<t ; i++ ){
             for (int j=0 ; j<gb-1 ; j++ ){
                 if (temparray[j]=='B'&&temparray[j+1]=='G'){
                     temp = array[j];
                     array[j]=array[j+1];
                     array[j+1]=temp;

                 }
                 temparray[j]=array[j];
             }
             for (int k =0 ; k<gb ; k++){
                 System.out.print(array[k]);
             }
         }
    }


public class CodeForces {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		long n = sc.nextLong();
		long a = sc.nextLong();
		long b = sc.nextLong();
		long c = sc.nextLong();
		long glass = b-c;
		long count = 0;
		while(n >= a || n >= b) {
			if(glass < a) {
				if(n >= b) {
					long num = (n-b-1)/glass;
					num++;
					count+= num;
					n-= num*glass;
				}
				if(n >= a) {
					long num2 = n/a;
					count+= num2;
					n-= num2*a;
				}
			} else {
				if(n >= a) {
					long num = n/a;
					count+= num;
					n-= num*a;
				}
				if(n >= b) {
					long num = (n-b+1)/glass;
					count+= num;
					n-= num*glass;

				}
			}

		}
		System.out.print(count);

	}
}


import java.util.*;
public class shell
{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int x=sc.nextInt();
        int arr[]=new int(3);
        arr[x]=1;
        int temp=0;
        while(n!=0)
        {
            if(n%2==0)
            {
               temp=a[1];
               a[1]=a[2];
               a[2]=temp;
            }
            else
            {
                temp=a[1];
               a[1]=a[0];
               a[0]=temp;
            }
            n=n-1;
        }
        for(int i=0;i<3;i++)
        {
            if(arr[i]==1)
            System.out.println(i);
        }
    }
}


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
     public static void main (String[] args) throws java.lang.Exception
     {
     	Scanner in =new Scanner(System.in);
		int t=1,n,i,j,m=0,k,p=0,h,l,x,y,d;
		String s,st;
		for(i=0;i<t;i++)
		{
		    m=0;
		    n=in.nextInt();
		    d=y;
		    while(n>0)
		    {
		         x=n%10;
		         m+=x;
		         n=n/10;
		    }
		    y=m%4;
		    switch(y)
		    {
		         case 0: break;
		         case 1: d+=3;
		         case 2: d+=2;
		         case 3: d+=1;
		    }
		    System.out.println(d);
		}
	}
}


import java.util.Scanner;

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

        int numLessons = scan.nextInt();

        int[] lessons = new int[numLessons];

        for(int i=0;i<numLessons;i++){
            lessons[i] = scan.nextInt();
        }

        int periodsPresent = 0;
        int i=0;
        while(lessons[i] == 0){
            i++;
        }

        int numZeros = 0;

        for(;i<lessons;i++){
            if(lessons[i] == 0){
                numZeros++;
            }else if(numZeros == 1){
                periodsPresent+=2;
            }else{
                periodsPresent++;
            }
        }

        System.out.println(periodsPresent);
    }
}


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

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

        String[] ss = read.readLine().split(" ");
        int r = Integer.parseInt(ss[0]);
        int h = Integer.parseInt(ss[1]);
        long ret = getCount(r, h);
        System.out.println(""+ret);
    }

    private static long getCount(long r, long h) {
        if (r > h * 2) return 1;
        double height45 = h + Math.sqrt(2) / 2.0 * r;
        //long side = (long) (Math.floor(height45 / (double)r));
        long side = (long) Math.floor((h - r/ 2.0) / (double) r);
        side++;
        long ret = side * 2;
        double lastcenter = side * r - r / 2.0;
        double x = h + r/2.0 - lastcenter;
        double diag = Math.sqrt(x * x + r * r / 4.0);
        if (diag >= r) {
            ret++;
        }
        return ret;
    }
}


import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;
import java.math.BigDecimal;
import java.math.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;
static final int INF=Integer.MAX_VALUE;
static final long LINF=Long.MAX_VALUE;

static void solve(){
 char[][] map=ir.nextCharMap(8,8);
 int a;
 int b;
 outer:
 for(int i=0;i<8;i++){
  for(int j=0;j<8;j++){
   if(map[i][j]=='W'){
    a=i;
    break outer;
   }
  }
 }
 for(int i=0;i<8;i++){
  for(int j=0;j<8;j++){
   if(map[7-i][j]=='W'){
    b=i;
    break outer;
   }
  }
 }
 out.println(a<(7-b)?"A":"B");
}

public static void main(String[] args) throws Exception{
 ir=new InputReader(System.in);
 out=new PrintWriter(System.out);
 solve();
 out.flush();
}

static class InputReader {
 private InputStream in;
 private byte[] buffer=new byte[1024];
 private int curbuf;
 private int lenbuf;

 public InputReader(InputStream in) {this.in=in; this.curbuf=this.lenbuf=0;}

 public boolean hasNextByte() {
  if(curbuf>=lenbuf){
   curbuf= 0;
   try{
    lenbuf=in.read(buffer);
   }catch(IOException e) {
    throw new InputMismatchException();
   }
   if(lenbuf<=0) return false;
  }
  return true;
 }

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

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

 private void skip(){while(hasNextByte()&&isSpaceChar(buffer[curbuf])) curbuf++;}

 public boolean hasNext(){skip(); return hasNextByte();}

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

 public int nextInt() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  int res=0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

 public long nextLong() {
  if(!hasNext()) throw new NoSuchElementException();
  int c=readByte();
  while (isSpaceChar(c)) c=readByte();
  boolean minus=false;
  if (c=='-') {
   minus=true;
   c=readByte();
  }
  long res = 0;
  do{
   if(c<'0'||c>'9') throw new InputMismatchException();
   res=res*10+c-'0';
   c=readByte();
  }while(!isSpaceChar(c));
  return (minus)?-res:res;
 }

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

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

 public BigDecimal nextBigDecimal(){return new BigDecimal(next());}

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

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

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


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

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

        String pointA[] = stdin.readLine().split(" ");

        String pointB[] = stdin.readLine().split(" ");

        String pointC[] = stdin.readLine().split(" ");

        double Ax = Double.parseDouble(pointA[0]), Ay = Double.parseDouble(pointA[1]);

        double Bx = Double.parseDouble(pointB[0]), By = Double.parseDouble(pointB[1]);

        double Cx = Double.parseDouble(pointC[0]), Cy = Double.parseDouble(pointC[1]);

        double a = Math.sqrt((Bx - Cx) * (Bx - Cx) + (By - Cy) * (By - Cy));

        double b = Math.sqrt((Ax - Cx) * (Ax - Cx) + (Ay - Cy) * (Ay - Cy));

        double c = Math.sqrt((Ax - Bx) * (Ax - Bx) + (Ay - By) * (Ay - By));

        double p = (a + b + c) / 2;

        double S = Math.sqrt(p * (p - a) * (p - b) * (p - c));

        double R = a * b * c / (4 * S);

        double alpha = Math.acos((b * b + c * c - a * a) / (2 * b * c));

        double beta = Math.acos((a * a + c * c - b * b) / (2 * a * c));

        double gamma = Math.PI - alpha - beta;

        long n = Math.round(Math.PI / gcd(beta, gcd(alpha, gamma)));

        PrintWriter stdout = new PrintWriter(System.out);

        stdout.println(R * R * Math.sin(2 * Math.PI / n) * n / 2);

        stdout.close();

    }

    private static double gcd(double a, double b) {

        if (a < b) return gcd(b, a);

        if (Math.abs(b) < 0.001) {

            return a;

        } else {

            return (gcd(b, a - Math.floor(a / b) * b));

        }

    }

}
}


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

import static java.lang.Math.*;

/**
 * Created by IntelliJ IDEA.
 * User: Taras_Brzezinsky
 * Date: 4/26/11
 * Time: 6:37 PM
 * To change this template use File | Settings | File Templates.
 */
public class Main extends Thread {
    public Main() {
        this.setPriority(Thread.MAX_PRIORITY);
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            StringTokenizer tokens = new StringTokenizer(in.readLine(), " ");
            int n = Integer.parseInt(tokens.nextToken()),
                    m = Integer.parseInt(tokens.nextToken()),
                    k = Integer.parseInt(tokens.nextToken());
            int firstDiv = Integer.MAX_VALUE;
            if (BigInteger.valueOf(m).isProbablePrime(20)){
                firstDiv = m;
            }
            else{
                for (int i = 2; i * i <= m; ++i){
                    if (m % i == 0){
                        firstDiv = i;
                        break;
                    }
                }
            }
            if (m / firstDiv > k || firstDiv == m && k != 1){
                out.println("Marsel");
            }
            else{
                if ((n == 1){
                    out.println("Timur");
                }
                else{
                    out.println("Marsel");
                }
            }
            out.flush();
            out.close();
        } catch (Throwable e) {
            System.err.println("Exception from runtime....");
            handleException(e);
        }
    }

    public static void main(String[] args) {
        try {
            new Main().start();
        } catch (Throwable e) {
            handleException(e);
        }
    }

    private static void handleException(Throwable e) {
        System.err.println(e.getMessage());
        System.err.println(e.getStackTrace());
    }

    private BufferedReader in;
    private PrintWriter out;
}


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

import java.util.Scanner;
import java.util.StringTokenizer;

public class Main {
    private static final long MOD=(long)(1e9)+7L;
    private static long dp[][]=new long[6000*3000][2];
    private static int n;
    private static int cnt=0;
    private static int fid[][]=new int[3000][3000];
    private static int lson[]=new int[30000];
    private static int rson[]=new int[30000];
    private static int val[]=new int[30000];
    private static int DFS(int u,int ln){
        System.out.println(u+" "+ln);
        int idn=0;
        long son=0;
        long blk=0;
        if(fid[u][ln]!=0){
            return fid[u][ln];
        }
        idn=++cnt;
        dp[cnt][1]=1;
        dp[cnt][0]=0;
        long lok=0,lno=0;
        long rok=0,rno=0;
        int xson;
        if(ln<n){
            //

            xson=DFS(u+1,ln+1);
            lok=dp[xson][1];lno=dp[xson][0];
            blk+=dp[xson][0];
        }
        if(ln>u-ln){

            xson=DFS(u+1,ln);
            rok=dp[xson][1];rno=dp[xson][0];
            blk+=dp[xson][0];
        }
        son=Math.max(Math.max(lok+rno,lno+rok),rno+lno);
        dp[idn][0]+=son;
        dp[idn][1]+=blk;
        dp[idn][0]%=MOD;
        dp[idn][1]%=MOD;
     //   System.out.println(u+" "+ln+" "+idn+" "+dp[idn][0]+" "+dp[idn][1]+" son:"+son+" blk"+blk);
        fid[u][ln]=idn;
        return idn;
    }
    public static void main(String[] args)throws IOException{
        //
        Reader.init(System.in);
        n=Reader.nextInt();
        cnt=0;
        DFS(0,0);
        System.out.print(dp[1][0]);
    }

}
//
class Reader{
    static BufferedReader reader;
    static StringTokenizer tokenizer;

    static void init(InputStream input){
        reader=new BufferedReader(new InputStreamReader(input));
        tokenizer=new StringTokenizer("");
    }
    //
    static String next()throws IOException{
        while(!tokenizer.hasMoreTokens()){
            tokenizer=new StringTokenizer(reader.readLine());
        }
        return tokenizer.nextToken();
    }
    //
    static int nextInt() throws IOException {return Integer.parseInt(next());}
    static double nextDouble()throws IOException{return Double.parseDouble(next());}
    static long nextLong()throws IOException{return Long.parseLong(next());}
}


import java.util.*;
public class Main
{
    public static void main(String[] args)
    {
        TaskA solver = new TaskA();
        TaskA.solve();
    }
}

class TaskA
{
    public static void solve()
    {
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        String s = input.next();

        int s1 = sum(s,0,n/2);
        int s2 = sum(s,n/2,n)

        if(s1 != -1 && s1 == s2 )
            System.out.println("YES");
        else
            System.out.println("NO");
    }
    public static int sum(String s, int b, int e)
    {
        int sum = 0;
        for(int i = b; i < e; ++i)
        {
            if(s.charAt(i) != '4' && s.charAt(i) != '7')
            {
                return -1;
            }
            sum += s.charAt(i) - '0';
        }
        return sum;
    }
}


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

public class Codeforces548C {
	public static int numStepsToGetTo(int[] heights, int start, int end)
	{
		int steps = 0;
		int initial = start;
		boolean[] visited = new boolean[heights.length];
		while(initial != end && !visited[initial])
		{
			steps++;
			visited[initial] = true;
			initial = heights[initial];
		}
		if(initial != end)
			return -1;
		else
			return steps;
	}
	public static void main(String[] args) {
		try
		{
			BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
			int m = Integer.parseInt(f.readLine());
			StringTokenizer st = new StringTokenizer(f.readLine());
			long h1 = Integer.parseInt(st.nextToken());
			long a1 = Integer.parseInt(st.nextToken());
			st = new StringTokenizer(f.readLine());
			long x1 = Integer.parseInt(st.nextToken());
			long y1 = Integer.parseInt(st.nextToken());
			st = new StringTokenizer(f.readLine());
			long h2 = Integer.parseInt(st.nextToken());
			long a2 = Integer.parseInt(st.nextToken());
			st = new StringTokenizer(f.readLine());
			long x2 = Integer.parseInt(st.nextToken());
			long y2 = Integer.parseInt(st.nextToken());
			f.close();

			long[] height1 = new long[m];
			for(int i = 0; i < m; i++)
				height1[i] = (x1*i + y1)%m;
			long[] height2 = new long[m];
			for(int i = 0; i < m; i++)
				height2[i] = (x2*i + y2)%m;

			/*boolean containsA1 = false;
			for(int i = 0; i < m; i++)
			{
				if(height1[i] == a1)
				{
					containsA1 = true;
					break;
				}
			}
			boolean containsA2 = false;
			for(int i = 0; i < m; i++)
			{
				if(height2[i] == a2)
				{
					containsA2 = true;
					break;
				}
			}

			if(!containsA1 || !containsA2)
				System.out.println(-1);
			else
			{*/
				int h1ToA1 = numStepsToGetTo(height1, h1, a1);
				int h2ToA2 = numStepsToGetTo(height2, h2, a2);
				if(h1ToA1 == -1 || h2ToA2 == -1)
					System.out.println(-1);
				else
				{
					if(h1ToA1 == h2ToA2)
						System.out.println(h1ToA1);
					else
					{
						int period1 = 1 + numStepsToGetTo(height1, height1[a1], a1);
						int period2 = 1 + numStepsToGetTo(height2, height2[a2], a2);
						/*if(period1 == 0 && period2 == 0)
							System.out.println(-1);
						else
						{
							/*if(period1 == 0)
							{
								if(h1ToA1%period2 == h2ToA2)
									System.out.println(h1ToA1);
								else
									System.out.println(-1);
							}
							else if(period2 == 0)
							{
								if(h2ToA2%period1 == h1ToA1)
									System.out.println(h2ToA2);
								else
									System.out.println(-1);
							}
							else
							{*/
								long result = h1ToA1;
								boolean found = false;
								for(int i = 0; i < period2; i++)
								{
									if(result%period2 == h2ToA2)
									{
										found = true;
										break;
									}
									result += period1;
								}
								if(found)
									System.out.println(result);
								else
									System.out.println(-1);
							//}
						//}
					}
				}
			//}
		}
		catch(IOException e)
		{
			System.out.println(e);
		}

	}

}


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

public class D {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

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

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

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

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

    char nextChar() throws IOException {
        return (char) (br.read());
    }

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

    private void solve() throws IOException {
        int n = nextInt();
        String s = nextToken();
        if (n <= 10)
        {
            BigInteger bigInteger = new BigInteger(s, n);
            out.println(bigInteger.toString());
            return;
        }

        ArrayList<Integer> integers = new ArrayList<>();
        StringBuilder sb = new StringBuilder();
        char[] c = s.toCharArray();

        int i = s.length() - 1;
        while (i >= 0)
        {
            int j;
            for (j = i - 1; j >= 0; j--) {
                int x = Integer.valueOf(s.substring(j, i + 1));
                if (x >= n) {
                    do {
                        j++;
                    } while (j < i && s.charAt(j) == '0');
                    break;
                }
            }
            j = Math.max(j, 0);
            integers.add(Integer.valueOf(s.substring(j, i + 1)));
            i = j - 1;
        }

        long ans = 0;
        for (int q = integers.size() - 1; q >= 0; q--) {
            ans = ans * n + integers.get(q);
//            System.err.println(integers.get(q));
        }
        out.println(ans);
    }

    void run() throws IOException {
        // br = new BufferedReader(new FileReader("input.txt"));
        // out = new PrintWriter("output.txt");
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        // Locale.setDefault(Locale.US);
        new D().run();
    }
}


public class Main {
    public static void main(String[] args) {
        var s = new java.util.Scanner(System.in);
        var hhmm = s.nextLine().split(":");
        int hh = hhmm[0];
        int mm = hhmm[1];
        System.out.println((hh%12)*30+mm/2 + " " + mm*6);
    }
}


public class MyPractise1 {
    private static String  solve(int sum,HashSet<Integer> hs,int data,String str){
        if(data==10){
            if(sum==0)
                return str;
            return "1231231231";
        }
        String str1=solve(sum,hs,data+1,str);
        String str2="111111111111";
        if(sum-data>=0) {
            hs.add(data);
            str2 = solve(sum - data, hs,data+1,str+Integer.toString(data));
            hs.remove(data);
        }
        if(str1.length()<str2.length())
            return str1;
        return str2;
    }

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
int t =sc.nextInt();
for(int i=0;i<t;i++){
    int sum=sc.nextInt();
    HashSet<Integer> hs=new HashSet<>();
   System.out.println( solve(sum,hs,1,""));
}
    }
}


import static java.lang.Math.ceil;
import static java.lang.Math.sqrt;
import java.util.*;
public class Main{
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        n=(int) ceil(sqrt(n)*2);
        System.out.println(m);
    }
}


import com.sun.xml.internal.fastinfoset.util.CharArray;

import java.util.Scanner;

/**
 * Created by Samsung900 on 30.04.2014.
 */
public class Main {
    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        char[] s = sc.next().toCharArray();
        int x = 0;
        for (char ch:s)
            if (ch == 'x')
                ++x;
        System.out.println(Math.abs(x-n/2));
    }
}


public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int t = scan.nextInt();
        for (int k = 0; k < t; k++) {
            int keyNumberInHand = scan.nextInt();

            int[] keys = new int[3];

            for (int i = 0; i < keys.length; i++) {
                keys[i] = scan.nextInt();
            }

            System.out.println(canOpenAllDoors(key, keys));
        }
    }

    private static String canOpenAllDoors(int key, int[] keys) {
        int count = 0;
        for (int i = 0; i < keys.length; i++) {
            if (keys[key] == 0 && count != 3) {
                return "FALSE";
            }
        }

        return "TRUE";
    }
}


public class Main {
	  public  void solution(){
		Scanner s= new Scanner(System.in);
		int number= s.nextInt();
		int k= s.nextInt();
		int sasha=0;
		int lena= 0;
		while(number>=k)
		{
			sasha+=k;
			number-=k;
			if(number<k)
				break;
			lena+=k;
			number-=k;
		}
		if(sasha>lena)
			System.out.println("YES");
		else
			System.out.println("NO");
	    }

}


import java.lang.Math;
import java.io.*;
public class HelloWorld
{

  public static void main(String[] args) throws IOException
  {
   BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
   int n=Integer.parseInt(bf.readLine());
   PrintWriter pw=new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
   pw.write(Math.max(1,8*(Math.pow(n*2,0.5))));
   pw.flush();
  }
}


import java.util.*;
public class Q1064A
{
    public static void main(String[] args)
    {
        int a[],max=0;
        Scanner sc=new Scanner(System.in);
        a=new int[3];
        for(int i=0;i<3;i++)
        {
            a[i]=sc.nextInt();
        }
        for(int i=0;i<3;i++)
        {
            if(a[i]>a[i+1])
            {
                max=a[i+1];
                a[i+1]=a[i];
                a[i]=max;
            }
        }
        if(a[2]==(a[1]+1[0])
        {
            System.out.println(0);
        }
        else
        {
            System.out.println((a[2]-(a[1]+a[0])+1));
        }
        sc.close();
    }
}


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

public class A {
    public static void main(String args[])throws Exception {
        new A().f();
    }
    int MOD = 1000000007;
    void f()throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int dp[][] = new int[n+1][n+1];
        for(int ar[] : dp)
            Arrays.fill(ar, -1);
        for(int i = 1; i <= n; i++) {
            dp[1][i] = i;
            dp[i][1] = 1;
        }
        int x = recur(dp, n, n);
        System.out.println((x+x)%MOD-n);
    }
    int recur(int dp[][], int n, int x) {
        if(dp[n][x] == -1) {
            dp[n][x] = (recur(dp, n-1, x)%MOD + recur(dp, n, x-1)%MOD)%MOD;
        }
        return dp[n][x];
    }
}


import javax.lang.model.util.ElementScanner9;
import java.lang.reflect.Array;
import java.util.Scanner;

public class CielAndFlowers {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int[] f = new int[3];
        for (int i = 0; i < 3; i++) {
            f[i] = s.nextInt();
        }
        solve(f);
    }

    public static void solve(int[] arr) {
        long sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }

        if (sum % 3 == 0) {
            System.out.println(sum / 3);
            return;
        }

        sum = sum - sum % 3;

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


import java.util.Scanner;

public class Main{

    public static void main(String args[]){

        Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		boolean color = false;
		int[] arr = new int[n*m];

		for (int i = 0; i < n*m; i++){
			arr[i] = in.next();
			if (arr[i].equals("C") || arr[i].equals("M") || arr[i].equals("Y")){
				color = true;
			}
		}
		if (color){
			System.out.println("#Color");
		}
		else{
			System.out.println("#Black&White");
		}

    }
}


import java.util.Scanner;
public class vviek{
    int lcm(int x,int y){
        int i=2;
        int c=1;
        while(x!=1 && y!=1){
            if(x%i==0 && y%i==0){
                x=x/i;
                y=y/i;
                c=c*i;
            }
            if(x%i==0){
                x=x/i;
                c=c*i;
            }
            if(x%i==0 && y%i==0){
                y=y/i;
                c=c*i;
            }
            if(x%i==0 && y%i==0){
                i++;
            }
        }
        return c;
    }
    public static void main(String args[]){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            int n=sc.nextInt();
            int min=9999999999;
            if(n%2==0){
                for(int i=1;i<n/2;i++){
                    if(n=lcm(i,n-i)){
                        System.out,println(i+" "+n-i);
                        break;
                    }
                }
                if(n=lcm((n/2)+1,(n/2)+1)){
                    System.out,println((n/2)+1+" "+(n/2)+1);
                    break;
                }
            }
            else{
                for(int i=1;i<n/2;i++){
                    if(n=lcm(i,n-i)){
                        System.out,println(i+" "+n-i);
                        break;
                    }
                }
            }
        }
    }
}


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

  int k;
  int fs=0;
  int sf=0;
   Scanner sc=new Scanner(System.in);
  k=sc.nextInt();
  String d;
  d=sc.nextLine();

  for(int m=1;m<k;m++)
  {
      if((d[m]=="F")&&(d[m+1]=="S"))
      {
       fs++;
      }
      if((d[m]=="S")&&(d[m+1]=="F"))
      {
          sf++;
      }
  }
  if(sf>fs)
  {
      System.out.println("Yes");
  }
 }
}


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

public class B {
	BufferedReader in;
	StringTokenizer str;
	PrintWriter out;
	String SK;

	String next() throws IOException {
		while ((str == null) || (!str.hasMoreTokens())) {
			SK = in.readLine();
			if (SK == null)
				return null;
			str = new StringTokenizer(SK, ":");
		}
		return str.nextToken();
	};

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

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

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

	int[] get(String S) {
		int n = S.length();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			if (S.charAt(i) >= 'A')
				a[i] = 10 + S.charAt(i) - 'A';
			else
				a[i] = S.charAt(i) - '0';
		}
		return a;
	}

	long count(int[] a, int b) {
		long res = 0;
		int n = a.length;
		for (int i = 0; i < n; i++)
			if (a[i] >= b)
				return 500;
			else
				res = res * b + a[i];
		return res;
	}

	void solve() throws IOException {
		int[] a = get(next());
		int[] b = get(next());
		boolean fl = true;
		for (int i = 0; i < a.length - 1; i++)
			fl = fl && (a[i] == 0);
		for (int i = 0; i < b.length - 1; i++)
			fl = fl && (b[i] == 0);
		if (fl) {
			out.println("-1");
			return;
		}
		int[] can = new int[100];
		int sum = 0;
		for (int i = 0; i < 100; i++) {
			if (count(a, i) < 24 && count(b, i) < 60) {
				sum++;
				can[i] = 1;
			}
		}
		if (sum == 0)
			out.println(sum);
		else
			for (int i = 0; i < 100; i++)
				if (can[i] == 1)
					out.print(i + " ");
	};

	void run() throws IOException {

		in = new BufferedReader(new InputStreamReader(System.in));
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

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

}


import java.util.*;
public class MaxTable{
	public static void main(String[]args){
		Scanner kbd = new Scanner(System.in);
		int tableSize = kbd.nextInt();

		if(tableSize == 1){
		    System.out.println(1));

		}

		int table1[] = new int[tableSize];
		int table2[] = new int[tableSize];

		for(int i = 0; i < tableSize; i++){
			table1[i] = 1;
		}

		for(int i = 0; i < tableSize -1; i++){

			for(int j = 0; j < tableSize; j++){
				if(j == 0){
					table2[j] = table1[j];
				} else {
					table2[j] = table2[j-1] + table1[j];
				}

				table1[j] = table2[j];
			}

		}

		System.out.print(table2[tableSize-1]);

	}
}


import java.util.Scanner;

public class HappyNumbers {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        long b =b1;
        long a = sc.nextInt();
        for(int i=0;i<=a;i++)
        {
            b *=2;
        }
        System.out.println(b-2);

    }

}


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

public class A {
	public static void main(String[] args) throws Exception {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int k = scan.nextInt();
		PrimeGen p = new PrimeGen(1000);
		List<Integer> prims = new ArrayList<Integer>();
		for(int i = 2; i <= n; i++){
			if(p.isPrime(i)>0){
				prims.add(i);
			}
		}
		System.out.println(prims);
		CGen<Integer> cgen = new CGen<Integer>(prims.toArray(new Integer[0]));
		while(cgen.hasNext()){
			List<Integer> l = cgen.next();
			if(l.size() == k && sum(l) <= n){
				System.out.println("YES");
				return;
			}
		}
		System.out.println("NO");
	}

	static int sum(List<Integer> is) {
		int c = 0;
		for (int i : is)
			c += i;
		return c;
	}

	static class CGen<T> {
		T[] s;
		int n = 0;

		CGen(T[] s) {
			this.s = s;
		}

		boolean hasNext() {
			return n < 1 << s.length;
		}

		java.util.List<T> next() {
			java.util.List<T> c = new java.util.ArrayList<T>();
			for (int i = 0; i < s.length; ++i)
				if ((n & (1 << i)) < 1)
					c.add(s[i]);
			++n;
			return c;
		}
	}

	static class PrimeGen {
		public PrimeGen(int m) {
			m = (int) Math.sqrt(m);
			double max = 0;
			int r = 1;
			for (int i = 0; i < 4;) {
				max += r * m / Math.pow(Math.log1p(m), ++i);
				r *= i;
			}
			p = new int[(int) max];
			for (int i = 0, e = 2; i < p.length; i++) {
				for (; isPrime(e) < 1; e++)
					;
				p[i] = e++;
			}
			this.m = p[p.length - 1];
			this.m = this.m * this.m;
		}

		int isPrime(int n) {
			for (int e : p)
				if (e < 1)
					break;
				else if (n != e && n % e < 1)
					return 0;
			return 1;
		}

		int max() {
			return m;
		}

		int[] p;
		int m;
	}
}


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

public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
      int a=in.nextInt();
      int b=in.nextInt();
      int c=in.nextInt();
      int d=in.nextInt();
      int f=1;

       if(Math.abs ((n/k)-Math.abs (d-t))<((n/k)*t)
                      System.out.println("YES");

      else
       System.out.println("NO");

        in.close();
    }
}


public class first_acm_problem {

    public static void main(String[] args) {
        Scanner b = new Scanner(System.in);
        int n = b.nextInt();
        int m= b.nextInt();
        int count=0;
        for (int i = n; i >=1; i/=m) {
            count+=i;
        }
        System.out.println(count);
    }


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

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

/* Name of the class has to be "Main" only if the class is public. */
public class Rextester
{
  public static void main (String[] args) throws java.lang.Exception
  {
    ArrayList<String> lines = new ArrayList<String>();
        Scanner sc = new Scanner(System.in);
        while(sc.hasNextLine()) {
            lines.add(sc.nextLine());
        }
        int[][] prior = {
            {3, 3, 4, 4, 3 ,3},
            {3, 3, 4, 4, 3, 3},
            {2, 2, 3, 3, 2, 2},
            {2, 2, 3, 3, 2, 2},
            {1, 1, 2, 2, 1, 1},
            {1, 1, 2, 2, 1, 1}
        };
        for(int i = 0; i < 6; i++) {
            String s = lines.get(i);
            s = "" + s.charAt(0) + s.charAt(1) + s.charAt(3) + s.charAt(4) + s.charAt(6) + s.charAt(7);
            lines.add(s);
        }
        int x = 0, y = 0, mx = -1;
        for(int i = 0; i < 6; i++)
        {
            for(int j = 0; j < 6; j++)
            {
                if(lines.get(i).charAt(j) == '.' && prior[i][j] > mx)
                {
                    mx = prior[i][j];
                    x = i;
                    y = j;
                }
            }
        }
        String s = lines.get(x);
        StringBuilder myName = new StringBuilder(s);
        myName.setCharAt(y, 'P');
        lines.set(x, myName.toString());
        for(int i = 0; i < 6; i++) {
            String ss = lines.get(i);
            ss = "" + ss.charAt(0) + ss.charAt(1) + "-" + ss.charAt(3) + ss.charAt(4) + "-" + ss.charAt(6) + ss.charAt(7);
            System.out.println(ss);
        }
  }
}


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


import edu.princeton.cs.algs4.ST;

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

public class Main {
    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int x,y,z,t1,t2,t3;
        x = scanner.nextInt();
        y = scanner.nextInt();
        z = scanner.nextInt();
        t1 = scanner.nextInt();
        t2 = scanner.nextInt();
        t3 = scanner.nextInt();

        int st = 0;
        int el = 0;

        int floorCnt = Math.abs(x-y);
        st = floorCnt * t1;

        int elFrom = Math.abs(x-z);

        el = (elFrom + floorCnt)*t2 + 3*t3;

        if(el <= st)
            System.out.println("YES");
        else
            System.out.println("NO");

    }

}


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

public class C {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

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

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

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

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

    char nextChar() throws IOException {
        return (char) (br.read());
    }

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

    long c;
    long h1;
    long h2;
    long w1;
    long w2;

    /* double f(double x) {
         double y = (c - w1 * x) / w2;
         return h1 * x + h2 * y;
     }*/
    class Point {
        long x, y;

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

    public long gcd(long a, long b) {
        if (b == 0) return a;
        long x = a % b;
        return gcd(b, x);
    }

    private void solve() throws IOException {
        final long  MAXC = 1000000;
        long c = nextLong();
        long h1 = nextLong();
        long h2 = nextLong();
        long w1 = nextLong();
        long w2 = nextLong();
        if (h1 * 1. / w1 > h2 * 1. / w2) {
            long x = h1;
            long y = w1;
            h1 = h2;
            w1 = w2;
            h2 = x;
            w2 = y;
        }
        long y = (long) (c + .0) / (w2);
        long max = -1;
        for (long j = y - MAXC; j < y + MAXC; j++) {
            long i = (long) Math.floor((c - j * w2) * 1. / w1);
            if (j < 0 || i < 0) {
                continue;
            }
            max = Math.max(i * h1 + j * h2, max);
        }
        out.println(max);
    }

    void run() throws IOException {
        //br = new BufferedReader(new FileReader("input.txt"));
        //out = new PrintWriter("output.txt");
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        // Locale.setDefault(Locale.US);
        new C().run();
    }
}


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

public class phoenix_and_computers {

	public static void main(String[] args) throws NumberFormatException, IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		String[] st = br.readLine().split(" ");
		int n = Integer.parseInt(st[0]);
		int m = Integer.parseInt(st[1]);

		long[][] ncr = ncrcoll(405, 405, m);
		int[] p2 = new int[n + 1];
		p2[0] = 1;
		for (int i = 1; i < p2.length; i++) {
			p2[i] = 2 * p2[i - 1] % m;
		}

		int[][] dp = new int[405][405];
		dp[0][0] = 1;

		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= i; j++) {
				for (int k = 1; i + k <= n; k++) {
					dp[i + k + 1][j + k] += ((dp[i][j] * p2[k - 1]) % m * ncr[j + k][k]);
					dp[i + k + 1][j + k] %= m;
				}
			}
		}

		long ans = 0;
		for (int i = 0; i <= n; i++) {
			ans = (ans + dp[n + 1][i]) % m;
		}

		System.out.println(ans);
	}

	static long[][] ncrcoll(int n, int k, int p) {
		long[][] arr = new long[n + 1][k + 1];
		for (int i = 1; i < arr.length; i++) {
			arr[i][0] = 1;
		}
		for (int i = 1; i < arr.length; i++) {
			for (int j = 1; j <= i && j < arr[0].length; j++) {
				if (i == 1 && j == 1) {
					arr[i][j] = 1;
				} else {
					arr[i][j] = (arr[i - 1][j] + arr[i - 1][j - 1]) % (p);
				}
			}
		}
		return arr;
	}

	public static long xpown(long x, long n) {
		long res = 1;
		while (n > 0) {
			if (n % 2 != 0) {
				res = (res * x) % 1000000007;
				n--;
			} else {
				x = (x * x) % 1000000007;
				n = n / 2;
			}
		}
		return res;
	}
}