import java.io.*;
import java.util.*;
import java.lang.*;
public class n1
{
    public static void main(String args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int a=s.nextInt();
        int sum=0;
        for(int j=1;j<=n-1;j++)
        {
            int b=s.nextInt();

                if(a==1)
                {
                    if(b==2)
                    {
                    sum=sum+3;
                    if(d==3)
                    {
                        sum=sum-2;
                    }
                    if(b==3)
                    sum=sum+4;
                }
                else if(b==1)
                {
                    if(a==2)
                    sum=sum+3;
                    if(a==3)
                    sum=sum+4;
            }
            else if(a!=1&&b!=1)
            {
               sum=0;
               break;
            }
            a=b;

            }
            if(sum==0)
            {
            System.out.println("Infinite");
        }
            else

            {
                System.out.println("Finite");
                System.out.println(sum);

        }
    }
}


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

public class mai {
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

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

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

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

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

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

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

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

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

		int n=sc.nextInt();
		int arr[]=new int[n];
		for(int i=0;i<n;i++)
			arr[i]=sc.nextInt();
		int flag=0;
		for(int i=0;i<(n-1);i++)
		{
			if(arr[i]==2 && arr[i+1]==3)
				flag=1;
			else if(arr[i]==3 && arr[i+1]==2)
				flag=1;
		}
		if(flag==1)
		{
			System.out.println("Infinite");
		}
		else
		{
			int c=0;
			for(int i=0;i<(n-1);i++)
			{
				if((arr[i]==1 && arr[i+1]==2 )|| (arr[i]==2 && arr[i+1]==1 ))
				{
					c+=3;
				}
				else
				{
					c+=4;
				}

			}
            for(int i=0;i<(n-2);i++)
			{
	if((arr[i]==3 && arr[i+1]==1 && arr[i+2]==2 )
    c--;
            }
			System.out.println("Finite");
			System.out.println(c);
		}
	}
}


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

public class Inscribed {
	public static void main(String[] args) {
		Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
		int n = in.nextInt();

		int prev2 = -1;
		int prev = in.nextInt();
		int curr = 0;
		boolean infinite = false;
		int total = 0;

		for (int i = 1; i < n; i++) {
			curr = in.nextInt();
			if (curr == 2 && prev == 3 || curr == 3 && prev == 2) {
				infinite = true;
			}
			else if (curr == 1) {
				if (prev == 2) total += 3;
				else total += 4;
			}
			else {
				if (prev2 == curr || prev2 = -1) {
					if (curr == 2) total += 3;
					else total += 4;
				}
				else {
					if (curr == 2) total += 2;
					else total += 4;
				}
			}
			prev2 = prev;
			prev = curr;
		}

		if (infinite) {
			System.out.println("Infinite");
		}
		else {
			System.out.println("Finite");
			System.out.println(total);
		}
	}
}


public class Inscribed {
    static Supplier<InputStream> inputSupplier = () -> System.in;
    static Supplier<PrintWriter> outSupplier = () -> new PrintWriter(System.out);

    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(inputSupplier.get());
        PrintWriter out = outSupplier.get();
        int n = sc.nextInt();
        int arr[] = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = sc.nextInt();
        }
        int ret = 0;
        for (int i = 1; i < n; i++) {
            int prev = arr[i-1];
            int curr = arr[i];
            if ((prev == 2 && curr == 3) || (prev == 3 && curr == 2)) {
                ret = -1;
                break;
            }
            if ((prev == 1 && curr == 2) || (prev == 2 && curr == 1)) {
                ret += 3;
            } else {
                ret+=4;
            }
        }
        if (ret == -1) {
            out.println("Infinite");
        } else {
            out.println("Finite");
            out.println(ret);
        }
        sc.close();
        out.close();
    }
}


import java.util.Scanner;
public class Main{
    public static void main(String[] args)throws IOException{
        Scanner s=new Scanner(new File("Monty"));
        int x=s.nextInt();
        int y=s.nextInt();
        int[]a=new int[y];

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

        java.util.Arrays.sort(a);

        int min=Integer.MAX_VALUE;
        int i=0;
        do{
            min=Math.min(min,a[i+x-1]-a[i]);
            i++;
        }while(i+x<=a.length);
        System.out.println(min);
    }
}


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

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] args1 = sc.nextLine().split(" ");
        String[] args2 = sc.nextLine().split(" ");
        int students = Integer.valueOf(args1[0])-1;
        int puzzlesavailable = Integer.valueOf(args1[1]);
        Arrays.sort(args2);
        int currentmin = args2[args2.length-1];
        if (!args2[0].equals(args2[args2.length-1])) {
            for (int i = 0; i < puzzlesavailable - students; i++) {
                if (Math.abs(Integer.valueOf(args2[i + students]) - Integer.valueOf(args2[i])) < currentmin) {
                    currentmin = (Integer.valueOf(args2[i + students]) - Integer.valueOf(args2[i]));
                }
            }
        }
        else {
            currentmin = 0;
        }
        System.out.println(Math.abs(currentmin));
    }

}


import java.util.*;
import java.lang.*;
import java.io.*;
public class Puzzles
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int m=sc.nextInt();
        int x[]=new int[m];
        for(int i=0;i<m;i++) {
        x[i]=sc.nextInt();
        }
        Arrays.sort(x);
        x[n]-=x[m-n];
        System.out.println(x[n]);

	}


import java.util.Scanner;
public class Sol
{
    public static void main(Strin args[])
    {
        Scanner s=new Scanner(System.in);
        int n=s.nextInt();
        int m=s.nextInt();
        int a[]=new int[m];
        for(int i=0;i<m;i++)
        a[i]=s.nextInt();
        Arrays.sort(a);
        System.out.println(a[n-1]-a[0]);
    }
}


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

public class B172 {
    public static void main(String args[]) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(in.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int r = Integer.parseInt(st.nextToken());
        ArrayList<Integer> list = new ArrayList<Integer>();
        int point = 0;
        while (true) {
            int rr = (a * r + b) % m;
            if (list.contains(rr)) {
                point = list.indexOf(rr);
                break;
            }
            list.add(rr);
            r = rr;
        }
        System.out.println(list.size() - point);
    }
}


import java.util.*;

public class B172 {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int m = in.nextInt();
        int r = in.nextInt();
        ArrayList<Integer> list = new ArrayList<Integer>();
        int point = 0;
        while (true) {
            int rr = (a * r + b) % m;
            if (list.contains(rr)) {
                point = list.indexOf(rr);
                break;
            }
            list.add(rr);
            r = rr;
        }
        int count = 1;
        point = point + 1;
        while (point < list.size()) {
            ++count;
            ++point;
        }
        System.out.println(count);
    }
}


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

public class Solution {
    //<editor-fold desc="input parse" defaultstate="collapsed">

    private static BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static StringTokenizer st;

    private static void initTokenizer() throws IOException {
        st = new StringTokenizer(reader.readLine());
    }

    private static int nextInt() {
        return Integer.parseInt(st.nextToken());
    }

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

    private static long nextLong() {
        return Long.parseLong(st.nextToken());
    }

    private static short nextShort() {
        return Short.parseShort(st.nextToken());
    }

    private static byte nextByte() {
        return Byte.parseByte(st.nextToken());
    }

    //</editor-fold>

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

        int a = nextInt();
        int b = nextInt();
        int m = nextInt();
        int r = nextInt();

        ArrayList<Integer> row = new ArrayList<Integer>();
        row.add(r);

        while (true) {
            int next = (row.get(row.size() - 1) * a + b) % m;

            int index = row.indexOf(next);
            if (index != -1) {
                System.out.print(row.size() - index);
                return;
            }

            row.add(next);
        }
    }
}


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

public class PRSP170B {
	public static void main(String[] args) throws IOException {
		BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(f.readLine());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int m = Integer.parseInt(st.nextToken());
		int r = Integer.parseInt(st.nextToken());
		ArrayList<Integer> nums = new ArrayList<Integer>();
		r=(a*r+b)%m; nums.add(r);
		r=(a*r+b)%m; nums.add(r);
		int t=0; int h=1;
		while(nums.get(h)!=nums.get(t)){
			r=(a*r+b)%m; nums.add(r);
			r=(a*r+b)%m; nums.add(r);
			t++;
			h+=2;
		}
		int first=nums.get(t);
		int period=1;
		while(nums.get(t+period)!=first){
			period++;
		}
		System.out.println(period);
	}
}


import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class Main {

	private static final int IN_BUFFER_SIZE = 1 << 16;
	private static final int OUT_BUFFER_SIZE = 1 << 16;
	private byte[] input = new byte[IN_BUFFER_SIZE];
	private int ix = IN_BUFFER_SIZE;
	private int bytesRead = ix;
	private byte[] output = new byte[OUT_BUFFER_SIZE];
	private int ox = 0;

	private void readMore() {
		try {
			bytesRead = System.in.read(input, 0, IN_BUFFER_SIZE);
			if (bytesRead <= 0)
				throw new RuntimeException();
			ix = 0;
		} catch (IOException e) {
			throw new RuntimeException();
		}
	}

	private void flushOut() {
		System.out.write(output, 0, ox);
		ox = 0;
	}

	private void append(String s) {
		char[] ca = s.toCharArray();
		for (int i = 0; i < ca.length; i++) {
			append(ca[i]);
		}
	}

	private void append(char c) {
		if (ox == OUT_BUFFER_SIZE)
			flushOut();
		output[ox++] = (byte) c;
	}

	private int nextInt() {
		skipSpaces();
		int ret = 0;
		if (ix == bytesRead) {
			readMore();
		}
		int sign = 1;
		if (input[ix] == '-') {
			sign = -1;
			ix++;
		}
		while (true) {
			if (ix == bytesRead) {
				try {
					readMore();
				} catch (RuntimeException e) {
					return ret;
				}
			}
			if (input[ix] < '0') {
				break;
			}
			ret *= 10;
			ret += input[ix++] - '0';
		}
		return sign * ret;
	}

	private long nextLong() {
		skipSpaces();
		long ret = 0;
		if (ix == bytesRead) {
			readMore();
		}
		int sign = 1;
		if (input[ix] == '-') {
			sign = -1;
			ix++;
		}
		while (true) {
			if (ix == bytesRead) {
				try {
					readMore();
				} catch (RuntimeException e) {
					return ret;
				}
			}
			if (input[ix] < '0')
				break;
			ret *= 10;
			ret += input[ix++] - '0';
		}
		return sign * ret;
	}

	private String nextLine() {
		StringBuilder sb = new StringBuilder();
		while (true) {
			if (ix == bytesRead) {
				readMore();
			}
			char c = (char) input[ix++];
			if (c == '\n')
				break;
			sb.append(c);
		}
		return sb.toString();
	}

	private String nextString() {
		try {
			skipSpaces();
		} catch (RuntimeException e) {
			return null;
		}
		StringBuilder sb = new StringBuilder();
		while (true) {
			if (ix == bytesRead) {
				try {
					readMore();
				} catch (RuntimeException e) {
					return sb.toString();
				}
			}
			if (input[ix] <= ' ')
				break;
			sb.append((char) input[ix++]);
		}
		return sb.toString();
	}

	private void nextCharArray(char[] ca, int len) {
		skipSpaces();
		for (int i = 0; i < len; i++) {
			if (ix == bytesRead) {
				readMore();
			}
			ca[i] = (char) input[ix++];
		}
	}

	private int charArrayLength;

	private void nextCharArray(char[] ca) {
		skipSpaces();
		if (ix == bytesRead) {
			readMore();
		}
		charArrayLength = 0;
		ca[charArrayLength++] = (char) input[ix++];
		while (true) {
			if (ix == bytesRead) {
				try {
					readMore();
				} catch (RuntimeException e) {
					return;
				}
			}
			char c = (char) input[ix++];
			if (c < '0')
				break;
			ca[charArrayLength++] = c;
		}
	}

	private char nextCharSkipRest() {
		skipSpaces();
		if (ix == bytesRead) {
			readMore();
		}
		char ret = (char) input[ix++];
		while (true) {
			if (ix == bytesRead) {
				readMore();
			}
			if (input[ix++] <= ' ')
				break;
		}
		return ret;
	}

	int cntSize;

	private char lastCharSkipRest() {
		skipSpaces();
		if (ix == bytesRead) {
			readMore();
		}
		char ret = (char) input[ix++];
		cntSize = 1;
		while (true) {
			if (ix == bytesRead) {
				readMore();
			}
			char c = (char) input[ix++];
			if (c <= ' ')
				break;
			ret = c;
			cntSize++;
		}
		return ret;
	}

	private void skipSpaces() {
		while (true) {
			if (ix == bytesRead) {
				readMore();
			}
			if (input[ix] > ' ')
				break;
			ix++;
		}
	}

	private char[] nn = new char[32];

	private void printLong(long n) {
		if (n == 0) {
			append('0');
		} else {
			if (n < 0) {
				append('-');
				n = -n;
			}
			int kk = 0;
			while (n > 0) {
				nn[kk++] = (char) (n % 10 + '0');
				n /= 10;
			}
			for (int i = kk - 1; i >= 0; i--) {
				append(nn[i]);
			}
		}
	}

	private void printInt(int n) {
		if (n == 0) {
			append('0');
		} else {
			if (n < 0) {
				append('-');
				n = -n;
			}
			int kk = 0;
			while (n > 0) {
				nn[kk++] = (char) (n % 10 + '0');
				n /= 10;
			}
			for (int i = kk - 1; i >= 0; i--) {
				append(nn[i]);
			}
		}
	}

	private void printDouble(double x, int p) {
		if (p == 0) {
			printLong(Math.round(x));
		} else {
			long pow = 1;
			for (int i = 0; i < p; i++) {
				pow *= 10;
			}
			x *= pow;
			long t = Math.round(x);
			printLong(t / pow);
			append('.');
			long rem = t % pow;
			if (rem == 0) {
				while (p-- > 0)
					append('0');
			} else {
				long tt = rem;
				while (tt > 0) {
					p--;
					tt /= 10;
				}
				while (p-- > 0)
					append('0');
				printLong(rem);
			}
		}
	}

	class State {
		int cur, used;
		long dest;

		public State(int cur, int used, long dest) {
			this.cur = cur;
			this.used = used;
			this.dest = dest;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + cur;
			result = prime * result + (int) (dest ^ (dest >>> 32));
			result = prime * result + used;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			State other = (State) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (cur != other.cur)
				return false;
			if (dest != other.dest)
				return false;
			if (used != other.used)
				return false;
			return true;
		}

		private Main getOuterType() {
			return Main.this;
		}
	}

	private int n, m, k;
	private long[] a, c[];
	private Map<State, Long> memo;

	private void work() {
		n = nextInt();
		m = nextInt();
		k = nextInt();
		a = new long[k];
		c = new long[51][51];
		for (int i = 0; i <= 50; i++) {
			c[i][0] = c[i][i] = 1L;
			for (int j = 1; j < i; j++) {
				c[i][j] = c[i - 1][j - 1] + c[i - 1][j];
			}
		}
		System.out.println(c[50][10] * c[40][10]);
		char[] ca = new char[k];
		for (int i = 0; i < k; i++) {
			nextCharArray(ca, k);
			for (int j = 0; j < k; j++) {
				a[i] <<= 1L;
				if (ca[j] == 'Y')
					a[i] |= 1L;
			}
		}
		memo = new HashMap<State, Long>();
		printLong(go(0, 0, (1L << k) - 1));
		append('\n');
		System.out.println(memo.size());
		if (ox > 0)
			flushOut();
		System.out.close();
	}

	private long go(int cur, int used, long dest) {
		int bc = Long.bitCount(dest);
		if (bc < m)
			return 0;
		if (used == n)
			return c[bc][m];
		if (cur == k || cur + (n - used) > k)
			return 0;
		State s = new State(cur, used, dest);
		if (memo.containsKey(s))
			return memo.get(s);
		long ret = go(cur + 1, used, dest);
		if (used < n)
			ret += go(cur + 1, used + 1, dest & a[cur]);
		memo.put(s, ret);
		return ret;
	}

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


import java.util.Scanner;

public class A_Little_Elephant_and_Interval {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long a = sc.nextLong();
        long b = sc.nextLong();
        String lef = a-1+"";
        String right = b+"";
        System.out.println(calc(right)-calc(left));

    }
    private static long calc(String s) {
        long res = 0;
        if (s.length() == 1){
            return Integer.parseInt(s);
        }
        if (s.length() == 2){
            res = 9 + s.codePointAt(0)-49;
            if (s.charAt(0) <= s.charAt(1)){
                res ++;
            }
            return res;
        }
        long a = 0;
        if (s.charAt(0) > s.charAt(s.length()-1)){
            a = Long.parseLong(s.substring(0,s.length()-1))-1;
            String t = a+"";
            t += t.charAt(0);
            s = t;
        }
        String t = s.substring(1,s.length()-1);
        res += Long.parseLong(t)+1;
        res += (s.codePointAt(0)-49)*(long)Math.pow(10, t.length());
        for (int i = 1; i < t.length(); i++) {
            res += 9*(long)Math.pow(10, i);
        }
        res += 18;
        return res;
    }

}
/*
458985985498001244 985458425544874008
ans
52647244004687276
10001 10000002
ans
999001

1 1000000000000000000
999999999999999999
ans
100000000000000008

*/


import java.util.Scanner;

public class LittleElephantAndInterval {
    public static void main(String[] args) {
        long l,r;
        Scanner sc=new Scanner(System.in);
        l=sc.nextLong();
        r=sc.nextLong();
        long ans=0;
        long ten=1;
        for(int i=1;i<=18;i++)
        {
            for(int j=1;j<=9;j++)
            {
                long low=(long)(j)*(ten);
                long high=(long)(j+1)*ten-1;
                low=Math.max(low,l);
                high=Math.min(high,r);
                while(low%10!=j)low++;
                while(high%10!=j)high--;
                if(low<=high)ans+=(high-low)/10+1;
            }
            ten*=10;
        }
        print(ans);
    }
    public static void print(long x)
    {
        System.out.println(x);
    }

}


import java.util.Scanner;

public class Codeforces204A {

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);
		long a =  sc.nextLong();
		long b = sc.nextLong();
		long count = 0;
		for(long i = a ; i <= b ;i++) {
				long last  = i%10;
				long c= i;
				while(c >=10) c = c/10;

				if(last == c) {
					count++;

			}

		}
		System.out.println(count);

		sc.close();

	}

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long rest = n;
        long result = 0;
        boolean check = false;
        while (rest != 0) {
            for (long i = 2; i <= Math.sqrt(n); i++) {
                if (rest % i == 0) {
                    result++;
                    check = true;
                    rest = rest - i;
                    break;

                }
            }
            if(!check){
                rest=0;
                result++;
            }
            check = false;
        }
        System.out.println(result);
    }
}import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        long n = scanner.nextLong();
        long rest = n;
        long result = 0;
        boolean check = false;
        for (long i = 2; i <= Math.sqrt(n) && rest == n; i++) {
            if (n % i == 0) {
                rest = i;

            }
        }
        if (rest == 2) {
            System.out.println(n / 2);
        } else {
            System.out.println(1+(n-rest)/2);
        }
    }
}


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

public class Main {

    public static void main(String args[]) {
        try{
            BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
            Long n = Long.parseLong(bf.readLine());
            int d = getPrimeDivisor(n);
            if(d == -1) {
                System.out.println(1);
                return;
            }
            System.out.println(1 + n / 2);

        }catch (Exception e) {

        }
    }
}


import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class B1076 {
	public static void main(String[] args) throws FileNotFoundException {
		Scanner scan = new Scanner(System.in);
		long n = scan.nextLong();
		if(isPrime(n)) {
			System.out.println(1);
			System.exit(0);

		}else {
			if(n % 2 == 0) {
				System.out.println(n /2);
				System.exit(0);
			}else {
				long spd = smallestPrimeDiv(n);
				n -= spd;
				System.out.println(n/2 + 1);
			}
		}

	}

	static long smallestPrimeDiv(long n){
		for(int i =2 ; i < n ; i ++) {
			if(n % i == 0) {
				if(isPrime(i)) {
					return i;
				}
			}
		}
		return n;
	}
	static boolean isPrime(long n) {
		for(int i= 2; i <n-1; i ++) {
			if(n % i == 0) {
				return false;
			}
		}
		return true;
	}
}
→Judgement Protocol


import java.util.*;
public class susbus{
   public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      if(n%2==1){
         //n-i
         System.out.println((n-i+2)/2);
      }
      else {
         System.out.println(n/2);
      }
   }
   public static void smallestOddPrime(int n){
      for (int i=3;i<n;i+=2){
         if(n%i==0) return i;
      }
      return i;
   }
}


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.math.*;
import java.text.*;
import java.util.*;

public class A {
	static BufferedReader br;
	static StringTokenizer st;
	static PrintWriter pw;

	public static void main(String[] args) throws IOException {
		br = new BufferedReader(new InputStreamReader(System.in));
		pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		//int qq = 1;
		int qq = Integer.MAX_VALUE;
		//int qq = readInt();
		for(int casenum = 1; casenum <= qq; casenum++) {
			int ret = 0;
			String s = nextToken();
			for(int i = 0; i < s.length(); i++) {
				for(int i = i+1; j <= s.length(); j++) {
					String k = s.substring(i, j);
					String kk = new StringBuilder(k).reverse().toString();
					if(!k.equals(kk)) {
						ret = Math.max(ret, k.length());
					}
				}
			}
			pw.println(ret);
		}
		pw.close();
	}

	public static void exitImmediately() {
		pw.close();
		System.exit(0);
	}

	public static int readInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public static double readDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	public static long readLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public static String nextLine() throws IOException {
		st = null;
		if(!br.ready()) {
			exitImmediately();
		}
		return br.readLine();
	}

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


import java.util.*;
import java.io.*;
public class Solution{
    public static void main(String[] args )
    {
        Scanner sc=new Scanner(System.in);
        String e=sc.next();
        int b=0,c=0;
        for(int i=0,k=e.length();k>=i;i++,k--)
        {
            if(e.charAt(i)==e.charAt(k))
            {
                if(e.charAt(0)==e.charAt(i))
                {
                    c++;
                }
            }
            else
            {
                b=1;
                break;
            }
        }
        if(b==0)
        System.out.println(e.length()-1);
         if(c==e.length());
        System.out.println(0);
        else
        System.out.println(e.length());
    }

}


import java.util.*;
import java.io.*;
public class Palindrome
{
	 public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s=sc.next();
		int b=0;
		for(int i=0,int k=s.length()-1;i!=k||i+1!=k;i++,k--)
		{
			if(s.charAt[i]==s.chart[k])
			{

			}
			else if(s.charAt[i]==s.charAt[0])
			{
				b++;

			}
			else
			{
				 b=1;
				break;
			}
		}
			if(b==1)
				System.out println(s.length());
			if(b==0)
				System.out.println(s.length()-1);
			else
				System.out.println(0);

	}
}


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

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

    static class TaskA {
        int is_palindrom(String s) {
            int low = 0, high = s.length() - 1;
            while (low <= high) {
                if (s.charAt(low) != s.charAt(high))
                    return 0;
                low++;
                high--;
            }
            return 1;
        }

        public void solve(int testNumber, InputReader in, PrintWriter out) {

            String s = in.nextString();
            int len = s.length();
            int low = 0, high = len - 1, ans = 0;
            if (is_palindrom(s) == 0) {
                out.print(s.length());
                return;
            }
            while (low <= high) {
                if (s.charAt(low) != s.charAt(high)) {
                    if (is_palindrom(s.substring(low) == 0))
                        ans = Math.max(ans, high - low + 1);
                }
                low++;
            }
            low = 0;
            high = len - 1;
            while (low <= high) {
                if (s.charAt(low) != s.charAt(high)) {
                    if (is_palindrom(s.substring(0, high)) == 0)
                        ans = Math.max(ans, high - low + 1);
                }
                high--;
            }
            out.print(ans);
        }

    }

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

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

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

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

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

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

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

        }

    }
}


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.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 long a=ir.nextLong();
 long b=ir.nextLong();
 out.println(count(b)-count(a-1));
}

public static long count(long x){
 if(x==0||x==1) return 0;
 if(x<=3) return 1;
 String t=Long.toBinaryString(x);
 long ret=(long)(t-1)*(t-2)/2;
 long p=(1L<<(long)t.length())-1L;
 for(int i=t.length-2;i>=0;i--){
  long q=p^(long)(1L<<(long)i);
  if(x<q){
   return ret+t.length-2-i;
  }
 }
 return ret+t.length()-1;
}

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


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.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 long a=ir.nextLong();
 long b=ir.nextLong();
 String s=Long.toBinaryString(a),t=Long.toBinaryString(b);
 int n=s.length(),m=t.length();
 long ans=0;
 if(n+1<=m-1){
  ans+=(long)(n+m-2)*(m-n-1)/2;
 }
 long p=((long)1<<(long)n)-1,q=((long)1<<(long)m)-1;
 for(int i=0;i<n-1;i++){
  if(p^((long)1<<(long)i)>=a){
   ans+=n-1-i;
   break;
  }
 }
 for(int i=0;i<m-1;i++){
  if(p^((long)1<<(long)i)>=b){
   ans+=i;
   break;
  }
 }
 out.println(ans);
}

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


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.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 long a=ir.nextLong();
 long b=ir.nextLong();
 String s=Long.toBinaryString(a),t=Long.toBinaryString(b);
 int n=s.length(),m=t.length();
 long ans=0;
 if(n==m){
  long p=((long)1<<(long)n)-1;
  for(int i=0;i<n-1;i++){
   long q=p^((long)1<<(long)i)
   if(q>=a&&q<=b){
    ans++;
   }
  }
  out.println(ans);
  return;
 }
 if(n+1<=m-1){
  ans+=(long)(n+m-2)*(m-n-1)/2;
 }
 long p=((long)1<<(long)n)-1,q=((long)1<<(long)m)-1;
 for(int i=0;i<n-1;i++){
  if((p^((long)1<<(long)i))>=a){
   ans+=n-1-i;
   break;
  }
 }
 for(int i=0;i<m-1;i++){
  if((q^((long)1<<(long)i))>=b){
   ans+=i;
   break;
  }
 }
 out.println(ans);
}

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


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.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 long a=ir.nextLong();
 long b=ir.nextLong();
 out.println(count(b)-count(a-1));
}

public static long count(long x){
 if(x==0||x==1) return 0;
 if(x<=3) return 1;
 String t=Long.toBinaryString(x);
 long ret=(long)(t.length()-1)*(t.length()-2)/2;
 long p=(1L<<(long)t.length())-1L;
 for(int i=t.length-2();i>=0;i--){
  long q=p^(long)(1L<<(long)i);
  if(x<q){
   return ret+t.length-2-i;
  }
 }
 return ret+t.length()-1;
}

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


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

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

        int n = in.nextInt();
        String s = in.next();
        int left = 0;
        int down = 0;
        int right = 0;
        int up = 0;
        for (int i = 0; i < n; i++) {
            if(s.charAt(i) == 'L'){
                left++;
            }else if(s.charAt(i) == 'R'){
                right++;
            }else if(s.charAt(i) == 'D'){
                down++;
            }else if(s.charAt(i) == 'U'){
                up++;
            }
        }
        int sum = Math.abs(up - down) + Math.abs(left-right);]
        System.out.println(sum);
    }
}


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

public class Main {
	public static void main(String args[]) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int[] dirs = new int[4]; //0 L 1 R 2 D 3 U
		String inp = s.nextString();
		for (int i = 0; i < n; i++) {
			if (inp.charAt(i) == 'L') {
				dirs[0]++;
			} else if (inp.charAt(i) == 'R') {
				dirs[1]++;
			} else if (inp.charAt(i) == 'D') {
				dirs[2]++;
			} else if (inp.charAt(i) == 'U') {
				dirs[3]++;
			}
		}
		int ans = (Math.min(dirs[0], dirs[1]) * 2) + (Math.min(dirs[2], dirs[3]) * 2);
		System.out.println(ans);
	}
}


import java.util.*;
public final class B
{
	public static void main(String[] args)
    {
  		Scanner br = new Scanner(System.in);
  		int n = br.nextInt();
			String s = a.next();
			int Left = 0;
			int Right = 0;
			int Up = 0;
			int Down = 0;
  		int res=0;
			for (char c : s.toCharArray())
				{
					if ( c == 'L' )
						{
							Left++;
						}
					if ( c == 'R' )
						{
							Right++;
						}
					if ( c == 'U' )
						{
							Up++;
						}
					if ( c == 'D' )
						{
							Down++;
						}
				}
			if (Left<=Right)
				{
					res+=Left*2;
				}
			else
				{
					res+=Right*2;
				}
			if (Up<=Down)
				{
					res+=Up*2;
				}
			else
				{
					res+=Down*2;
				}
  	}
}


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

        BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
        int n=Integer.parseInt(sc.readLine());

        String s=sc.next();

        int u=0;
        int l=0;
        int r=0;
        int d=0;
        for(int i=0;i<n;i++)
        {
        char ch=ob.next().charAt(0);
        if(ch=='U')
        u++;
        if(ch=='L')
        l++;
        if(ch=='R')
        r++;
        if(ch=='D')
        d++;
        int x=(int)Math.min(u,l);
        int y=(int)Math.min(r,d);
        int z=(int)Math.min(x,y);
        System.out.print(z);
        }

    }
}


import resource.InputReader;

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author a1M
 */
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();
        solver.solve(1, in, out);
        out.close();
    }

    static int[] visited = new int[20];

    static class TaskA {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = 0;
            int[] a = new int[n];
            int[] cola = new int[n];
            int[] counter = new int[10000];

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

            for (int i = n-1; i >= 0; i--) {

                counter[a[i]]++;
                if(counter[a[i]] == 1){
                    cola[i] = a[i];
                    m++;
                }
            }
            out.println(m);
            for (int i = 0; i < n; i++) {
                if(cola[i] != 0) out.print(cola[i] + " ");
            }
        }

    }

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

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

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

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

    }
}


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

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

          int n=sc.nextInt();

          int[] a=new int[n];

          for(int i=0;i<n;i++)
           a[i]=sc.nextInt();

           Stack<Integer> st=new Stack<>();

           HashSet<Integer> hs=new HashSet<>();

           for(int i=n-1;i>=0;i--)
            {
                if(!hs.contains(a[i]))
                {
                  hs.add(a[i]);
                  st.push(a[i]);
                }
            }

            for(int h=0;h<st.size();h++)
              System.out.print(st.pop());

      }
}


import java.io.*;
import java.util.*;
public class Main{
    public static void main(String args[])throws IOException{
        HashSet<Integer>set = new HashSet<Integer>();
        int n = Integer.parseInt(br.readLine());
        int []a = new int[n];
        String[]inp= br.readLine().trim().split(" ");
        for(int i=0;i<n;i++){
            a[i]=Integer.parseInt(inp[i]);
            h.add(a[i]);
        }
        for(int i=0;i<n;i++){
            if(set.contains(a[i]){
                System.out.print(a[i]+" ");
                set.remove(a[i]);
            }
        }
    }
}


import java.io.BufferedReader;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.ArrayList;
import java.util.Scanner;
//ArrayList<Integer> list = new ArrayList<Integer>();
import java.util.Collections;
import java.util.List;
import java.util.Random;
public class LOL {
static int[][] d=new int [3][3];
	public static void main(String[] args) throws IOException{
	    Scanner sc=new Scanner(System.in);
	    int c=sc.nextInt();
	    int a[]= new int [c];
	    for(int i=0 ; i<c; i++) {
	    	a[i]=sc.nextInt();
	    }
	    boolean flag=true;

	    int n=0;

	    for(int i=0; i<a.length ; i++) {
	    	flag=false;
	    	for(int j=i+1  ;j<a.length ; j++) {

	    	if(a[i]==a[j]) {
	    		flag=true;
	    		break;
	    	}

	    	}
          if(!flag) {
	    		n++;
	    	}

	    }

	    	int b[]=new int[n];
	    	int k=0;
	    	 for(int i=0; i<b.length ; i++) {
	    		 flag=false;
	    		 for(int j=i+1  ;j<b.length ; j++) {
	    				if(a[i]==a[j]) {
	    		    		flag=true;
	    		    		break;
	    		    	}

	    		    	}
	    	          if(!flag) {
	    	        	  b[k]=a[i];

	    		 	      k++;
	    		    	}
	 	    	}

	   display(b);
	}
	public static boolean add1(int a[][], int b[][] , int c[][]) {

		for(int i=0 ; i<a.length ; i++) {
			for(int j=0 ; j<a[i].length ; j++) {
				d[i][j]=a[i][j]+b[i][j];
			}
		}
		for(int i=0 ; i<a.length ; i++) {
			for(int j=0 ; j<a[i].length ; j++) {
				if(d[i][j]!=c[i][j]) {
					return false;
				}
			}
		}
		return true;
	}
public static boolean add2(int a[][], int b[][] , int c[][]) {
	for(int i=0 ; i<a.length ; i++) {
		for(int j=0 ; j<a[i].length ; j++) {
			d[i][j]=c[i][j]+b[i][j];
		}
	}

	for(int i=0 ; i<a.length ; i++) {
		for(int j=0 ; j<a[i].length ; j++) {
			if(d[i][j]!=a[i][j]) {
				return false;
			}
		}
	}
	return true;
	}
public static boolean add3(int a[][], int b[][] , int c[][]) {
	for(int i=0 ; i<a.length ; i++) {
		for(int j=0 ; j<a[i].length ; j++) {
			d[i][j]=c[i][j]+b[i][j];
		}
	}
	for(int i=0 ; i<a.length ; i++) {
		for(int j=0 ; j<a[i].length ; j++) {
			if(d[i][j]!=b[i][j]) {
				return false;
			}
		}
	}
	return true;

}
public static void display(int[] b) {
	for(int i=0 ; i<b.length ; i++) {
		System.out.println(b[i]);
	}
}

public static int[] Order(int l[][]) {
	int n=1;
	boolean f=true;
	for(int i=0; i<l.length ; i++) {
		if(l[i].length!=n) {
			f=false;
			break;
		}
		for(int j=0 ; j<l[i].length; j++) {
			if(l[i][j]!=n) {
				f=false;
				break;
			}
		}
		n++;

	}

}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

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

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

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

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

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

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

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

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

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


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

public class TaskE{
  public static void main(String[] args) {
    TaskE tE = new TaskE();
    PrintWriter pw = new PrintWriter(System.out);
    tE.solve(new Scanner(System.in), pw);
    pw.close();
  }

  public void solve(Scanner input, PrintWriter output) {
    int n = input.nextInt();
    int x = input.nextInt();
    int y = input.nextInt();

    long [] f = new int[n * 2 + 1];
    f[1] = x;
    for (int i = 2; i <= 2 * n; i++) {
      f[i] = f[i - 1] + x;
      if (i % 2 == 0) {
        f[i] = Math.min(f[i], f[i / 2] + y);
      }
    }

    for (int i = 2 * n - 1; i > 1; i--) {
      f[i] = Math.min(f[i], f[i + 1] + x);
    }
    output.println(f[n]);
  }
}


public class test{
    public static void main(String args[]){
        Scanner reader = new Scanner(System.in);  // Reading from System.in
        System.out.println("Enter a number: ");
        int n = reader.nextInt();
    }
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner input = new Scanner(System.in);

        int n = input.nextInt();
        int insertWeight = input.nextInt();
        int doubleWeight = input.nextInt();

        int ans[] = new int[n + 1];
        ans[0] = 0;
        ans[1] = insertWeight;
        for (int i = 2; i < n+1; i++) {
            if (i % 2 == 1) {
                ans[i] = Math.min(ans[(i - 1)] + insertWeight, ans[(i + 1) / 2] + insertWeight;
            } else {
                ans[i] = Math.min(ans[i / 2] + doubleWeight, ans[i / 2] + insertWeight * i / 2);

            }
        }

        System.out.print(ans[n]);
    }
}


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

public class GenerateAString_Edu16 {
//	static int n, x, y;

	public static void main(String[] args) throws NumberFormatException, IOException {
		Scanner sc = new Scanner(System.in);
		n = sc.nextInt();
		x = sc.nextInt();
		y = sc.nextInt();
//		System.out.println(dijkstra(0, n));
		System.out.println(yamosahel());
	}

//	static int INF = 1000000000;

//	static long[] dp;
	static long yamosahel()
	{
		PriorityQueue<Pair> pq = new PriorityQueue<>();
		long[] time = new long[(int) 1e7+1];
		Arrays.fill(time, INF);
		pq.add(new Pair(0,0));
		time[0] = 0;
//		dp = new long[time.length+1];
		Arrays.fill(dp, -1);
		while(!pq.isEmpty())
		{
//			if(dp[cur.n])
			Pair cur = pq.remove();
//			System.out.println(cur);
			if(dp[cur.node] !=-1)
				time[cur.node] = dp[cur.node];
			if(cur.node==n)
				return cur.time;
//			if(cur.node)
			if(cur.time>time[cur.node]) continue;

			if (cur.node+1<=n && cur.time+x<time[cur.node+1])
				pq.add(new Pair(cur.node + 1, time[cur.node + 1] = cur.time + x));

			if (cur.node>0 && cur.node-1<=n && cur.time+x<time[cur.node-1] )
				pq.add(new Pair(cur.node-1, time[cur.node-1] = cur.time+x));

			if (cur.node*2 !=0 && cur.node*2 < time.length && cur.time+y < time[cur.node*2])
				pq.add(new Pair(cur.node*2, time[cur.node*2] = cur.time+y));
		}
		return -1;
	}

	static long n,x,y;
	static final long INF = (long)1e18;

	static class Pair implements Comparable<Pair>
	{
		int node;
		long time;
		Pair(int a, long b)
		{
			node = a; time = b;
		}

		public int compareTo(Pair p)
		{
			// time-p.time
			if(p.time!=time) return (time > p.time)? 1:-1;
			return node-p.node;
		}
		public String toString()
		{
			return node + " "+time;
		}
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

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

		Scanner(FileReader r) {
			br = new BufferedReader(r);

		}

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

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


import java.util.Scanner;

    public class Main{
        public static void main(String [] args){
            Scanner sc = new Scanner(System.in);
            int n = s.nextInt(), R = s.nextInt(), r = s.nextInt();
            if (n < 2) {
                System.out.println(r <= R ? "YES" : "NO");
            } else {
                System.out.println((r * (1 + 1 / Math.sin(Math.PI / n)) <= R + 1e-6) ? "YES" : "NO");
            }
            sc.close();
        }
    }


import java.text.DecimalFormat;
import java.util.Scanner;

public class A_New_Year_Table {

	/**
	 *
	 * 2012-1-6
	 *
	 * @author froest
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner scan = new Scanner(System.in);
		int a[] = new int[3];
		for (int i = 0; i < 3; i++) {
			a[i] = scan.nextInt();
		}
		if(a[0] == 1){
			if(a[1]>=a[2]){
				System.out.println("YES");
			}else{
				System.out.println("NO");
			}
		}else if(a[0] == 2){
			if(a[1]>=2*a[2]){
				System.out.println("YES");
			}else{
				System.out.println("NO");


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

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

class Main {

    BufferedReader reader;
    StringTokenizer st;

    void run() throws Exception {
        reader = new BufferedReader(new InputStreamReader(System.in));

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

        Integer n = Integer.parseInt(st.nextToken());
        Integer R = Integer.parseInt(st.nextToken());
        Integer r = Integer.parseInt(st.nextToken());

        Double tmpR = (r * 1.0) / (Math.sin(Math.PI / n));

        if ((n == 1) && (r <= R) || (n == 2) && (2 * r <= R) || (Integer)(Math.round(tmpR)) <= R - r)
            System.out.println("YES");
        else
            System.out.println("NO");

        reader.close();
    }
}


import java.util.*;

public class NewYear {

	public static void main(String args[]) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		double bigR = in.nextInt();
		double r = in.nextInt();

		if (r > bigR) {
			System.out.println("NO");
		} else if (r > bigR/2 && r <= bigR) {
			if (n <= 1) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} else if(r == bigR/2) {
			if (n <= 2) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		} else {
			double slice = 2*Math.asin(r/(bigR-r));
			if (slice*n <= 2*Math.PI) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
		}

	}
}


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

public class Secrets {
    public static void main(String[] args) throws IOException {
        BufferedReader f = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(f.readLine());
        while (n % 3 == 0)
            n /= 3;
        System.out.println(1+n/3);
    }
}


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

public class Main {
	static final int INF = (int)1E9;

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

		long i = 1;
		int n = in.nextInt();
		while (true) {
			if (n % i != 0) {
				out.print(n / i + 1);
				break;
			}
			i *= 3;
		}

		out.close();
	}
}

class Fenwick {

}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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

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


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

public class C {

	private static StringTokenizer tokenizer;
    private static BufferedReader bf;
    private static PrintWriter out;

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

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

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

	public static void main(String[] args) throws IOException {
		bf = new BufferedReader(new InputStreamReader(System.in));
    	tokenizer = null;
    	out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
    	long n = nextLong();
    	int[] a = new int[40];
    	int[] r = new int[40];
    	long m = n; int ind = 0;
    	while(m > 0) {
    		a[ind++] = (int) (m%3);
    		m /= 3;
    	}
    	r[0] = a[0];
    	for(int i = 1; i < ind; i++) {
    		r[i] = a[i] + r[i-1];
    	}
    	int id;
    	for(id = 0; id < ind; id++) {
    		if(a[id] != 0) break;
    	}
    	while(a[id] != 2) id++;
    	int count = r[ind-1]-r[id]+1;
    	out.print(count);
    	out.close();
	}

}


import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;

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);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }
}

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

        long m = n, div = 1;
        while (m != 0 && m % 3 == 0){
            m /= 3;
            div *= 3;
        }
        div *= 3;
        out.println((n + div - 1) / div);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

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

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

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

}


import java.util.*;
import java.io.*;
public class spoj
{
    public static void main(String[] args)
    {
        Scanner sc=new Scanner(System.in);
        int radius=sc.nextInt();
       float x1=sc.nextFloat();
       float y1=sc.nextFloat();
       float x2=sc.nextFloat();
       float y2=sc.nextFloat();
       float dist=(float)Math.sqrt(Math.pow(x1-x2,2)+Math.pow(y1-y2,2));
       System.out.println(Math.ceil(dist/2*r));

    }
}


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

public class CircleCenter {
        public int numberOfSteps(int r, int x, int y, int xx, int yy) {
                double distance = getDistance(x, y, xx, yy);
                return (int)Math.ceil(distance / (2 * r));
        }

        public double getDistance(long x, long y, long xx, long yy) {
                return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));
        }

        public static void main(String[] args) {
                BufferedReader scanner = new BufferedReader(new InputStreamReader(System.in));
                try {
                        StringTokenizer tokenizer = new StringTokenizer(scanner.readLine());
                        int r = Integer.parseInt(tokenizer.nextToken());
                        int x = Integer.parseInt(tokenizer.nextToken());
                        int y = Integer.parseInt(tokenizer.nextToken());
                        int xx = Integer.parseInt(tokenizer.nextToken());
                        int yy = Integer.parseInt(tokenizer.nextToken());

                        System.out.println(numberOfSteps(r, x, y, xx, yy));

                } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        }
}


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

public class CircleCenter {
        public static int numberOfSteps(int r, int x, int y, int xx, int yy) {

        }

        public static double getDistance(long x, long y, long xx, long yy) {
                return Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));
        }

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

                        StringTokenizer tokenizer = new StringTokenizer(scanner.readLine());
                        int r = Integer.parseInt(tokenizer.nextToken());
                        int x = Integer.parseInt(tokenizer.nextToken());
                        int y = Integer.parseInt(tokenizer.nextToken());
                        int xx = Integer.parseInt(tokenizer.nextToken());
                        int yy = Integer.parseInt(tokenizer.nextToken());

    double distance =  Math.sqrt((xx - x) * (xx - x) + (yy - y) * (yy - y));

                        System.out.println( (int)Math.ceil(distance / (2 * r)));

        }
}


By joshkirstein, contest: Codeforces Round #287 (Div. 2), problem: (B) Amr and Pins, Accepted, #
 import java.util.*;

public class B {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int rad = sc.nextInt();
		int x = sc.nextInt(), y = sc.nextInt();
		int xp = sc.nextInt(), yp = sc.nextInt();
		double d = Math.hypot(x-xp, y-yp);
		double dist = (d-rad)/(2*rad);
		System.out.println((int) Math.ceil(dist+0.5));
	}
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class Task389A_FoxAndNumberGame {
        int n;
        int x;

        public void solve(int testNumber, InputReader in, OutputWriter out) {
            n = in.nextInt();
            x = in.nextIntArray(n);
            while (!isEqual()) {
                Arrays.sort(x);
                subtract();
            }
            out.print(x[0] * n);
        }

        public boolean isEqual() {
            int value = x[0];
            for (int i = 0; i < n; ++i)
                if (x[i] != value)
                    return false;
            return true;
        }

        public void subtract() {
            for (int i = n - 1; i > 0; --i) {
                if (x[i] != x[i - 1]) {
                    x[i] -= x[i - 1];
                }
            }
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

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

    }

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

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

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

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

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

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

        public interface SpaceCharFilter {
            boolean isSpaceChar(int ch);

        }

    }
}


import java.util.*;
import java.util.stream.*;

public  class Problem300A {
    public static void main(String[] args) {
         BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n=sc.Integer.parseInt(br.readLine());
        int a[] = new int[n];
        for(int i=0;i<n;i++){
            a[i]=Integer.parseInt(br.readLine());
        }
        Arrays.sort(a);
        int max= Arrays.stream(a).max().getAsInt();
        if(max!=a[0]){
           while(max!=a[0]){
               max= Arrays.stream(a).max().getAsInt();
               Arrays.sort(a);
               for(int i=n-1;i>=1;i--){
                  a[i]=a[i]-a[i-1];
               }
           }
           int sum = IntStream.of(a).sum();
           System.out.println(sum*n);
        }
        else{
             int sum = IntStream.of(a).sum();
             System.out.println(sum);
        }
    }
}


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

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

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

				int n =Integer.parseInt(br.readLine());
				int arr[]=new int[n];
				String a[]=br.readLine().split(" ");
				for(int i=0;i<a.length;i++)
					arr[i]=Integer.parseInt(a[i]);
				Arrays.sort(arr);
				while(Same(arr))
				{
					arr[arr.length-1]-=arr[arr.length-2];
					Arrays.sort(arr);
				}
				int sum=0;
				for(int x:arr)
					sum+=x;
				System.out.println(sum);

				}
				catch(Exception e)
				{

				}
	 }

	private static boolean Same(int[] arr) {
		// TODO Auto-generated method stub
		int temp=arr[0];
		for(int i=1;i<arr.length;i++)
			if(arr[i]!=temp)
				return false
		return true;
	}
}


package practice;

import io.InputReader;

public class fox_number {
    public static void main(String[] args) {
        InputReader in = new InputReader(System.in);
        int n = in.readInt();
        int a = in.readInt();
        int b = in.readInt();
        int ans = gcd(a, b);
        for(int i=2;i<n;i++)
            ans = gcd(ans, in.readInt());

        System.out.println(n * ans);

    }

    public static int gcd(int x, int y)
    {
        if(y == 0)
            return x;
        if(x >= y)
            return gcd(y, x % y);
        return gcd(x, y % x);
    }

}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        String ch = sc.nextLine();
        char[] bin = new char[n];

        for (int i = 0; i < n; i++) {
            if (ch.charAt(i) == 'B') bin[n-i-1] = '1';
            else bin[n-i-1] = '0';
        }
        System.out.println(Integer.parseInt(new String(bin), 2));

//        for (int i = n - 1; i >= 0; i--) {
//            st.add(ch.charAt(i) == 'B' ? true : false);
//        }
//
//        int numberOfCommands = 0;
//        do {
//            numberOfCommands++;
//            while (!st.peek()) {
//                st.pop();
//            }
//            st.pop();
//            st.push(false);
//            while (st.size() != n) {
//                st.push(true);
//            }
//        } while (!AllNotTheSame(st));
//
//        System.out.print(numberOfCommands);
    }

    private static boolean AllNotTheSame(String st) {
        Boolean allFalse = true;

        for (int i = 0; i < st.length(); i++)
            if (st.charAt(i) == 'B') allFalse = false;

        return allFalse;

    }
}


package untitled;

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

public class Solution {

	public static void main(String[] args) {
		int count = 0;
		String balls = new String();
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		balls = in.next();
		StringBuilder b = new StringBuilder(balls);

		while (true) {
			if (b.indexOf("B") == -1)
				break;
			else if (b.charAt(0) == 'B') {
				b.replace(0, 1, "R");
				count++;
			} else if (b.charAt(0) == 'R') {
				b.deleteCharAt(0);
				if (b.charAt(0) == 'B') {
					b.replace(0, 1, "R");
					b.reverse();
					count++;
					while (b.length() < n) {
						b.append("B");
					}
					b.reverse();
				}
			}
		}
		System.out.println(count);
	}
}


import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        sc.nextLine();
        String ch = sc.nextLine();
        char[] bin = new char[n];
        if (AllNotTheSame(ch)) {
            System.out.println(0);
            return;
        }
        if (n == 1) {
            if (ch.charAt(0) == 'B') System.out.println(0);
            else System.out.println(1);
        }
        for (int i = 0; i < n; i++) {
            if (ch.charAt(i) == 'B') bin[n - i - 1] = '1';
            else bin[n - i - 1] = '0';
        }
        System.out.println(Integer.parseInt(new String(bin), 2));

//        for (int i = n - 1; i >= 0; i--) {
//            st.add(ch.charAt(i) == 'B' ? true : false);
//        }
//
//        int numberOfCommands = 0;
//        do {
//            numberOfCommands++;
//            while (!st.peek()) {
//                st.pop();
//            }
//            st.pop();
//            st.push(false);
//            while (st.size() != n) {
//                st.push(true);
//            }
//        } while (!AllNotTheSame(st));
//
//        System.out.print(numberOfCommands);
    }

    private static boolean AllNotTheSame(String st) {
        Boolean allFalse = true;

        for (int i = 0; i < st.length(); i++)
            if (st.charAt(i) == 'B') allFalse = false;

        return allFalse;

    }
}


/* IMPORTANT: class must not be public. */

/*
 * uncomment this if you want to read input.
import java.io.BufferedReader;
import java.io.InputStreamReader;
*/
import java.util.*;
public class TestClass {
    public static void main(String args[] ) throws Exception {
        /*
         * Read input from stdin and provide input before running

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        int N = Integer.parseInt(line);
        for (int i = 0; i < N; i++) {
            System.out.println("hello world");
        }
        */
        Scanner s =new Scanner(System.in);
        long n=s.nextLong();
        String str=s.next();
        long c=0;
        for(long i=0;i<n;i++)    {
            if(str.charAt(i)=='B')    {
                c+=(long)Math.pow(2,i);
            }
        }
        System.out.println(c);
    }
}


import java.util.Scanner;

/**
 * Created by Kirill Antonov on 19.02.2016.
 */

public class codeforces {
    static class Point {
        long x, y;

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

    static class Line {
        long a, b, c;
        Point p, q;

        public Line(Point a, Point b) {
            this.p = a;
            this.q = b;
            this.a = b.y - a.y;
            this.b = a.x - b.x;
            this.c = a.y * b.x - a.x * b.y;
        }
    }

    public static boolean compr(Line l, Point p) {
        if (l.a * p.x + l.b * p.y + l.c == 0) return true;
        return false;
    }

    public static boolean perp(Line l1, Line l2) {
        long n1 = l1.p.x - l1.q.x, m1 = l1.p.y - l1.q.y, n2 = l2.p.x - l2.q.x, m2 = l2.p.y - l2.q.y;
        if (n1 * n2 + m1 * m2 == 0) {
            return true;
        }
        return false;
    }

    public static Point a;
    public static Point b;
    public static Point c;

    public static boolean check(Line l, int i, boolean ox) {
        if (i == 0) return checker(c, l, ox);
        if (i == 1) return checker(b, l, ox);
        if (i == 2) return checker(a, l, ox);
        return false;
    }

    public static boolean checker(Point k, Line l, boolean ox) {
        long upy = Math.max(l.q.y, l.p.y), upx = Math.max(l.p.x, l.q.x), downy = Math.min(l.q.y, l.p.y), downx = Math.min(l.q.x, l.p.x);
        if (ox) {
            if (downy <= k.y && k.y <= upy) return false;
            else return true;
        } else {
            if (downx <= k.x && k.x <= upx) return false;
            else return true
        }

    }

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        a = new Point(in.nextInt(), in.nextInt());
        b = new Point(in.nextInt(), in.nextInt());
        c = new Point(in.nextInt(), in.nextInt());
        Line oy = new Line(new Point(0, 0), new Point(0, 1)), ox = new Line(new Point(0, 0), new Point(1, 0));
        Line ab = new Line(a, b), bc = new Line(b, c), ac = new Line(a, c);
        Line[] lines = {ab, ac, bc};
        int ans = 0;
        if ((perp(ab, ox) && perp(ac, ox)) || (perp(ab, oy) && perp(ac, oy))) ans = 1;
        else {
            for (int i = 0; i < 3; i++) {
                if (perp(lines[i], ox)) {
                    if (check(lines[i], i, true)) ans = 2;
                    break;
                }
                if (perp(lines[i], oy)) {
                    if (check(lines[i], i, false)) ans = 2;
                    break;
                }
            }
            if (ans == 0) ans = 3;
        }
        System.out.print(ans);
    }
}


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.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 int n=3;
 int[][] co=new int[n][];
 for(int i=0;i<n;i++) co[i]=ir.nextIntArray(2);
 if((co[0][0]==co[1][0]&&co[1][0]==co[2][0])||(co[0][1]==co[1][1]&&co[1][1]==co[2][1])){
  out.println(1);
  return;
 }
 for(int k=0;k<2;k++){
  for(int i=0;i<n;i++){
   for(int j=i+1;j<n;j++){
    if(co[i][k]==co[j][k]){
     if((long)(co[i][k^1]-co[d(i,j)][k^1])*(co[d(i,j)][k^1]*co[j][k^1]<0){
      out.println(3);
     }
     else out.pritln(2);
     return;
    }
   }
  }
 }
 out.println(3);
}

public static int d(int a,int b){
 if(a==0&&b==1) return 2;
 if(a==0&&b==2) return 1;
 return 0;
}

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

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


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.BigInteger;

public class Main{

static PrintWriter out;
static InputReader ir;

static void solve(){
 int n=3;
 int[][] co=new int[n][];
 for(int i=0;i<n;i++) co[i]=ir.nextIntArray(2);
 if((co[0][0]==co[1][0]&&co[1][0]==co[2][0])||(co[0][1]==co[1][1]&&co[1][1]==co[2][1])){
  out.println(1);
  return;
 }
 for(int k=0;k<2;k++){
  for(int i=0;i<n;i++){
   for(int j=i+1;j<n;j++){
    if(co[i][k]==co[j][k]){
     if((long)(co[i][k^1]-co[d(i,j)][k^1])*(co[d(i,j)][k^1]*co[j][k^1])<0){
      out.println(3);
     }
     else out.pritln(2);
     return;
    }
   }
  }
 }
 out.println(3);
}

public static int d(int a,int b){
 if(a==0&&b==1) return 2;
 if(a==0&&b==2) return 1;
 return 0;
}

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


import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import static java.lang.Integer.max;
import static java.lang.Math.abs;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
            try (PrintWriter out = new PrintWriter(outputStream)) {
                TaskB solver = new TaskB();
                solver.solve(1, in, out);
            }
    }
}

class TaskB {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        HashSet x = new HashSet();
        HashSet y = new HashSet();
        for(int i = 0; i < 3; ++i){
            int a = in.nextInt();
            int b = in.nextInt();
            x.add(a);
            y.add(b);
        }
        out.println(Math.min(x.size(), y.size()));
    }
}
class InputReader {
    private final BufferedReader reader;
    private StringTokenizer tokenizer;

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

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

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

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


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

public class HelpfulMaths339A
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// Input
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int[] nums = new int[(s.length()/2)+1];
		int index = 0;

		// Get actual numbers
		for (char c : s.toCharArray()) {
			if (c != '+') {
				nums[index] = Character.getNumericValue(c);
				index++;
			}
		}

		// Sort in non-decreasing order
		Arrays.sort(nums);

		// Output nums
		for (int i = 0; i < nums.length-1; i++) {
			System.out.print(nums[i]+"+");
		}
		System.out.print(nums[nums.length-1]);
	}
}
© 2020 GitHub, Inc.


import java.util.Scanner;

public class HelpfulMaths {

	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    String a = sc.nextLine();
	    int[] tmp = new int[100];
	    int j = 0;

	    for(int i=0; i<a.length(); i++){
	        if(a.charAt(i) != '+'){
	            tmp[j] = a.charAt(i)-'0';
	            j++;
	        }
	    }
	    for(int i=0; i<a.length()-j; i++){
	        System.out.print(tmp[i]);
	        if(tmp[i] == '') System.out.print("!");
	    }

	    int forchange = -1;
	    for(int i=0; i<a.length()-j; i++){
	        for(int k=i; k<a.length()-j; k++){
	            if(tmp[i]>tmp[k]){
	                forchange = tmp[i];
	                tmp[i] = tmp[k];
	                tmp[k] = forchange;
	            }
	        }
	    }
	    for(int i=0; i<a.length(); i++){
	        if(i != a.length()-1) System.out.print(tmp[i]+'+');
	        else  System.out.print(tmp[i]);
	    }

	}
}


import java.util.*;
public class Arraange
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);
        String st = sc.nextInt();
        int i,k,counter=0;
        int a[] = new int[st.length()];
        for(i=0;i<st.length()-1;i++)
        {
            k = st.charAt(i);
            if(k>='0' && k<='9')
                a[counter++] = Character.getNumericValue(k);
        }
        for(i=0;i<a.length-1;i++)
        {
            for(j=0;j<a.length-1-i;j++)
            {
                if(a[j]>a[j+1])
                {
                    temp = a[j];
                    a[j]=a[j+1];
                    a[j+1]=temp;
                }
            }
        }
        for(i=0;i<a.length;i++)
        {
            System.out.print(a[i]+"+");
        }
    }
}


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

public class Solution{
    public static void main(String[] args){
         Scanner in=new Scanner(System.in) ;
         String line=in.next() ;
         String numbers[] = line.split("+") ;
         int num[]=new int[4] ;
         for(int i=0;i<4;i++){num[i]=0 ;}
         for(int i=0;i<numbers.length();i++){

         }
         }
    }
}


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

import static java.util.Arrays.fill;
import static java.lang.System.*;
/**
 * Created by Firеfly on 12/18/2016.
 */
public class code {
    public static void main(String[] args) throws IOException {
        Woorker worker = new Woorker();
    }
}
class Woorker {
    static int n;
    static int a, b;
    static boolean found;
    int cur;
    char[] mas;
    boolean[] masq;
    boolean used[];

    Woorker() throws IOException {
        FastScannerqq fs = new FastScannerqq(new InputStreamReader(System.in));
        String s = fs.nextLine();
        int p[] = new int[26], p1 = -1, p2 = -1;
        fill(p, -1);
        for (int i = 0; i < 27; i++) {
            int c = s.charAt(i) - 'A';
            if (p[c] == -1) {
                p[c] = i;
            } else {
                p1 = p[c];
                p2 = i;
                break;
            }
        }
        if (p1 + 1 == p2) {
            out.print("Impossible");
            return;
        }
        s = s.substring(0, p2) + s.substring(p2 + 1);
        int shift = (p1 + p2 + 1) / 2;
        s = s.substring(shift) + s.substring(0, shift);
        out.println(s.substring(0, 13));
        out.print(new StringBuilder(s.substring(13)).reverse().toString());
        }
    }

    boolean able(char k, int pos, int from) {
        int i =0;
        used[pos] = true;
        if (k == '>')
            i = pos+1;
        else i = pos-1;
        if (i<0 || i>=n)
        {
            masq[pos] = true;
            return true;
        } else if (i!=from) {
            boolean q;
            if (used[i])
            q = masq[i];
            else q = able(mas[i], i, pos);
            masq[pos] = q;
            return q;
        } else {
            return false;
        }
    }

}

class FastScannerqq {
    BufferedReader br;
    StringTokenizer stok;

    FastScannerqq(InputStreamReader fr) {
        br = new BufferedReader(fr);
    }

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


import java.util.Scanner;
public class Main
{
  public static void main(String[] args)
  {
      Scanner sc= new Scanner(System.in);
      String lin=sc.nextLine();
      sc.close();
      int s=0;
      int f=0;
      for(int x=0;x<lin.length();x++)
      {
      if(lin.indexOf(lin.charAt(x))==lin.lastIndexOf(lin.charAt(x)))
      {
          s=lin.indexOf(lin.charAt(x));
          f=lin.lastIndexOf(lin.charAt(x));
      }
      }
      if(f-s<2)
      {
      System.out.println("Impossible");
      }
      else
      {
          String[][] need= new String[2][13];
          int j=13-(f-s)/2;
          int hat=s;
          for(int q=j;q<13;q++)
          {
              need[0][q]=lin.substring(hat%26,hat%26+1);hat++;
          }
          for(int q=12;q>=0;q--)
          {
              need[1][q]=lin.substring(hat%26,hat%26+1);hat++;
          }
          for(int q=0;q<j;q++)
          {
              need[0][q]=lin.substring(hat%26,hat%26+1);hat++;
          }
      }
      for(int pal=0;pal<13;pal++)
      {
          System.out.print(need[0][pal]);
      }
      System.out.println();
      for(int pal=0;pal<13;pal++)
      {
          System.out.print(need[1][pal]);
      }
  }
}