public class HanSolo {

    public static void main(String[] args) {
        Scanner ict = new Scanner(System.in);
        int counter=0, x = 0;
        int n = ict.nextInt(), k = ict.nextInt();

        int[] arr = new int[n];

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

        for(x = 0; x < arr.length && x >= arr[x]; x++){
            counter++;

        }
        if(x != n) {
            for (int i = arr.length - 1; i >= 0 && k >= arr[i]; i--) {
                counter++;

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


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

import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;
import static javaapplication31.NastyandanArray.n;

/**
 *
 * @author kinan
 */
public class MishkaandContest {
     public static void main(String[] args) throws IOException {
         //ArrayList <Integer> list = new ArrayList<Integer>();
         ArrayList <Integer> list1 = new ArrayList<Integer>();
        // ArrayList <Integer> list2 = new ArrayList<Integer>();

         Scanner scanner = new Scanner(System.in);
         int x=0;
         int r=0;
         int y=0;
          n = scanner.nextInt();
          int k =scanner.nextInt();
        int[] f = new int[n];

        for (int i = 0; i < n; i++) {
            f[i] = Integer.parseInt(scanner.next());
        }

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

            if (f[i]> k){
              list1.add(i+1);
                x = list1.get(0);
               int l =  (list1.size()-1);
               int index = list1.get(l);
                y = n - index + 1; }

             if (f[i] < k){
                  x =f.length;
                 y=0;
                }
                 if (f[0]>k && f[f.length-1]>k){
                  x =-1;
                  y=0;
                }}

               int max = Math.max(x,y);
               System.out.print(max);

            }
        }


import java.util.*;

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

        int n = sc.nextInt();
        int k = sc.nextInt();
        int a[] = new int[n];
        for(int i=0;i<n;i++){
            a[i] = sc.nextInt();
        }
        int count = 0;
        int l = 0;
        int r = a.length-1;
        for(int i=0;i<n;i++){
        if(a[l] <= k){
            l += 1;
            count += 1;
        }
        else if(a[r] <= k){
            r -= 1;
            count += 1;
        }
        else{
            System.out.println(count);
            break;
        }
        }
    }
}
→Judgem


import java.util.Scanner ;

public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in) ;
        String text = sc.next() ;
        System.out.println(text) ;

        String arr [] = text.split("/") ;
        for(int i = 0 ; i < arr.length - 1 ; i++){
            System.out.print(arr[i] + "/");
        }
        System.out.println(arr[i]) ;
    }
}


import java.util.* ;

public class Main {
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in) ;
        String text = sc.next() ;
        String ans = "" ;

        Stack<Integer> s = new Stack<>();
        for(int i = 0 ; i < text.length() ; i++){
            if(s.peek() == "/" && s.charAt(i) == "/"){

            }else {
                s.add(s.charAt(i));
                ans += s.peek() ;
            }
        }
        System.out.print(ans) ;
    }
}


import java.util.Scanner;

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

       for(int i = 0; i < 10; i++){
            s = s.replace("//","/");
       }
       if(s.length() == 1 && s.charAt(0) == '/'){
              System.out.println("/");
              break;
       }
       else if(s.charAt(s.length() - 1) == '/'){
            s = s.substring(0, s.length() - 1);
       }
        System.out.println(s);
       }
}


import net.egork.utils.Solver;
import net.egork.utils.io.InputReader;

import java.io.PrintWriter;

public class FsBERoS implements Solver {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        char s[] = in.readLine().toCharArray();
        boolean yet = false;
        for (int i = 0; i < s.length; ) {
            int j = i;
            for (; j < s.length && s[j] == '/'; ++j) ;
            if (yet && j < s.length && j - i > 0 || !yet && j - i > 0) {
                out.print("/");
                yet = true;
            }
            int k = j;
            while (k < s.length && s[k] != '/') ++ k;
            for (int u = j; u < k; ++u)
                out.print(s[u]);
            i = k;
        }

    }
}


import java.util.Scanner;

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

		long n = scan.nextLong();
		if(n==0){System.out.println(1);return;}
		long sol = 0;
		long x = 0, y = n;
		long n2 = n*n;
		while(x!=n||y!=0){
			if (x*x+y*y-n2>1e-8){
				y--;
			}else{
				sol++;
				if((x+1)*(x+1)+y*y-n2>1e-8 &&
				   (x+1)*(x+1)+(y-1)*(y-1)-n2>1e-8){
					y--;
				}else{
					x++;
				}
			}
		}

		System.out.println(sol*4);
	}
}


import java.util.*;
public class d {
public static void main(String[] args) {
	Scanner scan= new Scanner (System.in);

	int n=scan.nextInt();

	System.out.println(calc (n));
}

	static int calc ( int n )
	{
		if(n==0)
		{
			return 1;
		}
		if(n==1)
		{
			return 4;
		}
		if(n%2==0)
		{
		return calc (n-1) + 4;
		}
		return calc(n-1)*2;
		}
}


import java.util.*;
public class d {
public static void main(String[] args) {
	Scanner scan= new Scanner (System.in);

	int n=scan.nextInt();
	System.out.println(calc (n));
}

	static int calc ( int n )
	{
		if(n==1)
		{
			return 4;
		}
		if(n%2==0)
		{
		return calc (n-1) + 4;
		}
		return calc(n-1)*2;
		}
}


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

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


import java.util.Scanner;
public class codeforces1 {
	public static void main(String[] args) {
		Scanner lee=new Scanner(System.in);
		long x,cont=0;
		do {
		x=lee.nextInt();
		}while(x<1||x>100000);
		cont=x/2+x/3+x/5+x/7-x/6-x/10-x/14-x/15-x/21-x/35+x/30+x/42+x/70+x/105-x/210;
		System.out.println(x-cont);
	}
}


import java.util.Scanner;
public class codeforces1 {
	public static void main(String[] args) {
		Scanner lee=new Scanner(System.in);
		long x,cont=0;
		do {
		x=lee.nextInt();
		}while(x<1);
		cont=x/2+x/3+x/5+x/7-x/6-x/10-x/14-x/15-x/21-x/35+x/30+x/42+x/70+x/105-x/210;
		System.out.println(x-cont);
	}
}


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

public class K {

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

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

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

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

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

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

    static InputReader r = new InputReader(System.in);
    static PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) {
        long n = r.nextLong();

        long[] notDiv = new long[2521];
        for(int i = 1; i <= 2520; i++){
            if(i % 2 != 0 && i % 3 != 0 && i % 5 != 0 && i % 7 != 0){
                notDiv[i] = notDiv[i-1] + 1;
            } else{
                notDiv[i] = notDiv[i-1];
            }
        }
        pw.println(notDiv[2520] * (n/2520) + notDiv[n%2520]);
        pw.close();
    }
}

/**
*                _        _                 _
*               | |      | |               | |
*   ___ ___   __| | ___  | |__  _   _    __| | __ _ _ __ _ __ ___ _ __     _   _  __ _  ___
*  / __/ _ \ / _` |/ _ \ | '_ \| | | |  / _` |/ _` | '__| '__/ _ \ '_ \   | | | |/ _` |/ _ \
* | (_| (_) | (_| |  __/ | |_) | |_| | | (_| | (_| | |  | | |  __/ | | |  | |_| | (_| | (_) |
*  \___\___/ \__,_|\___| |_.__/ \__, |  \__,_|\__,_|_|  |_|  \___|_| |_|   \__, |\__,_|\___/
*                                __/ |                               ______ __/ |
*                               |___/                               |______|___/
 */


import java.util.*;
public class Solution
{
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        long inp=in.nextLong();
        long add[]=new Long[7];
        long sub[]= new Long[7];
        add[0]=inp/2;
        add[1]=inp/3;
        add[2]=inp/5;
        add[3]=inp/7;
        add[4]=inp/30;
        add[5]=inp/105;
        add[6]=inp/70;
        sub[0]=inp/6;
        sub[1]=inp/10;
        sub[2]=inp/14;
        sub[3]=inp/15;
        sub[4]=inp/21;
		sub[5]=inp/35;
		sub[6]=inp/210;
		long out=0;
		for(int i=0;i<7;i++)
		{
			out+=add[i];
		}
		for(int i=0;i<7;i++)
		{
			out-=sub[i];
		}
			out=inp-out;
			System.out.println(out);
		in.close();
    }
}


import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int[] arr = new int[3];
		arr[0] = in.nextInt();
		arr[1] = in.nextInt();
		arr[2] = in.nextInt();
		int minDistance = 0;
		Arrays.sort(arr);
		if (arr[0]+arr[1]<=arr[2]) {
			minDistance = 2 * (arr[0]+arr[1]);
		} else {
			if (arr[0]==arr[1] && arr[2]==arr[1]]) {
				minDistance = arr[0]+arr[2]+arr[2];
			} else {
				minDistance = 2 * (arr[0]+arr[2]);
			}
		}
		System.out.println(minDistance);
	}
}


import java.util.*;

public class _1
{
    public static void main(String args[])
    {
        Scanner in=new Scanner(System.in);
        long x=in.nextLong();
        long y=in.nextLong();
        long z=in.nextLong();

        System.out.println(Math.min(2*(x+y),x+y+z));

    }


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

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


public class A{

     public static void main(String []args){
        BufferedReader br = new BufferedReader(new FileReader("input"));
        PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output")));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int a = Integer.parseInt(st.nextToken());
        int b = Integer.parseInt(st.nextToken());
        int c = Integer.parseInt(st.nextToken());
        if (a + b < c)
            pw.println(2 * (a + b));
        else
            pw.println(2 * c);
        pw.close();
        System.exit(0);
     }
}


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

public class c {

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

		FastReader s = new FastReader();
		int len = s.nextInt();
		String str = s.next();

		String ans = "";
		int i=0;
		int inc = 1;
		while(i<len)
		{
			ans += str.charAt(i);
			i = i + (inc++);
		}

		System.out.println(ans);

	}

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

}
close


//RepeatingCipher.java

import java.util.Scanner;

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

     String t;
     t = s.nextLine();
     int counter = 1;

     String s = t.substring( 0, 1);
     for ( int i = 2 ; counter < n; i++ )
     {
       s = s + t.substring( counter , counter + 1);
       counter += i;
     }
     System.out.println( s );
  }
}


//RepeatingCipher.java

import java.util.Scanner;

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

     String t;
     Scanner s2 = new Scanner( System.in );
     t = s2.nextString();
     int counter = 1;

     String s = t.substring( 0, 1);
     for ( int i = 2 ; counter < n; i++ )
     {
       s = s + t.substring( counter , counter + 1);
       counter += i;
     }
     System.out.println( s );
  }
}


import java.util.Scanner;
import java.util.Arrays;
public class A1095 {
	public static void main(String[] args) {
	    Scanner scan = new Scanner(System.in);
	    int x = scan.nextInt();
	    String str = scan.nextString();
	    int i = 1;
	    while((i*(i+1))/2 != x){
	        i ++;

	    }
	    String s = "";
	    for(int j = 1; j < i; j ++){
	        s = s + x.charAt(j * (j + 1)/2);
	    }
	    System.out.println(s);

	}
}


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

   public class x430A
   {
      public static void main(String hi[]) throws Exception
      {
         BufferedReader infile = new BufferedReader(new InputStreamReader(System.in));
         StringTokenizer st = new StringTokenizer(infile.readLine());
         int N = Integer.parseInt(st.nextToken());
         int M = Integer.parseInt(st.nextToken());
         for(int i=0; i < N; i++)
            System.out.print((i%2)+" ");
         Pair[] arr = new Pair[N];
         st = new StringTokenizer(infile.readLine());
         for(int i=0; i < N; i++)
            arr[i] = new Pair(Integer.parseInt(st.nextToken()), i);
         Collections.sort(arr);
         int tag = 0;
         int[] res = new int[N];
         for(Pair p: arr)
         {
            res[p.dex] = tag;
            tag = 1-tag;
         }
         for(int x: res)
            System.out.print(x+" ");
      }
   }
   class Pair implements Comparable<Pair>
   {
      int val;
      int dex;

      public Pair(int a, int b)
      {
         val = a;
         dex = b;
      }
      public int compareTo(Pair oth)
      {
         return val-oth.val;
      }
   }


public class A1 {

    public static void main(String args[]) {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] pt = new int[n];
        int[] x = new int[m];
        int[] y = new int[m];
        for (int i=0; i<n; i++) {
            pt[i] = sc.nextInt();

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

        for (int i=0; i<n; i++) {
            int belongs = 0;
            for (int j=0; j<m; j++) {
                if (pt[i] >= x[j] && pt[i] <= y[j]) {
                    System.out.print("0 ");
                    belongs = 1;
                    break;
                }
            }
            if (belongs == 0) {
                System.out.print("-1 ");
            }
        }
    }
}


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

public class Points_and_Segments_easy_430
{

	public static void main(String[] args) throws IOException
	{
		Points_and_Segments_easy_430 main = new Points_and_Segments_easy_430();
		main.input();
		main.solve();
	}

	void solve()
	{

		for (int i : points)
		{
			System.out.print(cols[i] + " ");
		}
	}

	/******************************************************************
	 ****************************** INPUT******************************
	 ******************************************************************/

	static int n;
	static int m;
	static Integer[] cols;
	static Integer[] pos;
	static int[] points;

	// static int[][] segments;

	void input() throws IOException
	{
		Init(System.in);
		n = NextInt();
		m = NextInt();
		cols = new Integer[n];
		points = new int[n];
		int point = 0;
		for (int i = 0; i < n; i++)
		{
			point = NextInt();
			points[i] = point;
			if ((point & 0x00000001) == 0)
			{
				cols[point] = 0;
			}
			else
			{
				cols[point] = 1;
			}
		}
	}

	/******************************************************************
	 ****************************** READER*****************************
	 ******************************************************************/
	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void Init(InputStream input)
	{
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String Next() throws IOException
	{

		while (!tokenizer.hasMoreTokens())
		{
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	static int NextInt() throws IOException
	{

		return Integer.parseInt(Next());
	}

	static long NextLong() throws IOException
	{

		return Long.parseLong(Next());
	}

	static Double NextDouble() throws IOException
	{

		return Double.parseDouble(Next());
	}

}


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

public class TaskA {
    public static void main(String[] args){
        FastScanner3 sc = new FastScanner3();
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] points = sc.readIntArray(n);
        Arrays.sort(points);
        Segment[] segments = new Segment[n];
        for(int i=0;i<m;i++){
            segments[i] = new Segment(sc.nextInt(),sc.nextInt());
        }
//      Arrays.sort(segments);
//      int[] coloring = new int[n];
//      Arrays.fill(coloring, -1);
//      for(Segment s: segments){
//          int pointsStart = 0;
//          int pointsStop = points.length-1;
//          for(;pointsStart<n && points[pointsStart] < s.start;pointsStart++){}
//          for(;pointsStop>=1 && points[pointsStop] > s.stop;pointsStop--){}
//          if(pointsStart > pointsStop){
//              continue;
//          }
//          int size = pointsStop - pointsStart + 1;
//
//      }
        for(int i=0;i<n;i++){
            if(i % 2 == 0){
                System.out.print(0);
            }else{
                System.out.print(1);
            }
            if(i < n-1){
                System.out.print(" ");
            }
        }
    }
}

class Segment implements Comparable<Segment>{
    int start,stop;
    int dist;
    public Segment(int start, int stop){
        this.start = start;
        this.stop = stop;
        dist = stop - start;
    }
    @Override
    public int compareTo(Segment arg0) {
        return ((Integer) dist).compareTo(arg0.dist);
    }

}

class FastScanner3 {

    private BufferedReader in;
    private StringTokenizer st;

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

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

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

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

}


import com.sun.org.apache.bcel.internal.generic.RETURN;
import com.sun.xml.internal.ws.api.pipe.ServerTubeAssemblerContext;

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

public class main {

    static int MAXSTEPS = 100;
    static int[] fx = {0, 1, 1, 1, 0, -1, -1, -1};
    static int[] fy = {1, 1, 0, -1, -1, -1, 0, 1};
    static int[][][] d = new int[MAXSTEPS+1][10][10];
    static char[][] c = new char[10][10];
    static boolean isinside(int x, int y) {
        return  (x >= 0 && x < 8 && y >= 0 && y < 8);
    }
    static boolean isstatue(int x, int y) {
        return (isinside(x, y) && c[x][y] == 'S');
    }
    static boolean Try(int t, int x, int y) {
        if (t > MAXSTEPS) return false;
        if (!isinside(x, y)) return false;
        if (isstatue(x-t, y)) return false;
        if (x == 0 && y == 7) return true;
        if (d[t][x][y] != -1) return (d[t][x][y]==1) ? true : false;
        boolean res = false;
        for (int i = 0; i < 8; i++) {
            int nx = x + fx[i];
            int ny = y + fy[i];
            if (isinside(nx, ny) && !isstatue(nx-t, ny))
                res |= Try(t+1, nx, ny);
        }
        d[t][x][y] = (res) ? 1 : 0;
        return res;
    }
    public static void main(String []args) {
        Scanner nhap = new Scanner(System.in);
        for (int i = 0; i < 8; i++) {
            c[i] = nhap.next().toCharArray();
            //System.out.println(c[i]);
        }
        for (int i = 0; i < MAXSTEPS; i++)
            for (int j = 0; j < 8; j++)
                Arrays.fill(d[i][j], -1);
        System.out.print(Try(0, 7, 0) ? "WIN" : "LOSE");

    }
}


import java.util.Queue;
import java.util.Scanner;

public class A {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[][][] cs = new char[20][8][8];
        for(int i = 0; i < 8; i++) {
            cs[0][i] = sc.next().toCharArray();
        }

        for(int i = 0; i < 19; i++) {
            for(int y = 0; y < 8; y++)
                for(int x = 0; x < 8; x++)
                    if(cs[i][y][x] == 'M')
                        for(int dy = -1; dy <= 1; dy++)
                            for(int dx = -1; dx <= 1; dx++) {
                                final int xx = x+dx;
                                final int yy = y+dy;
                                if(0 <= xx && xx < 8 && 0 <= yy && yy < 8 && cs[i][yy][xx] != 'S')
                                    cs[i+1][yy][xx] = 'M';
                            }

            for(int y = 6; y >= 0; y--)
                for(int x = 0; x < 8; x++)
                    if(cs[i][y][x] == 'S')
                        cs[i+1][y+1][x] = 'S';
        }

        String res = "LOSE";
        for(int y = 0; y < 8; y++)
            for(int x = 0; x < 8; x++)
                if(cs[19][y][x] == 'M')
                    res = "WIN";
        System.out.println(res);
    }
}


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

public class C {
    static int[] dx = { 0, 0, 0, 1, -1, 1, 1, -1, -1 };
    static int[] dy = { 0, 1, -1, 0, 0, 1, -1, -1, 1 };

    public static boolean rec(char[][] B, int x, int y, int t) {
        if (t >= 8)
            return true;
        if (B[x][y] == 'S')
            return false;
        char[][] _B = new char[8][8];
        for (int i = 0; i < 7; i++)
            for (int j = 0; j < 8; j++)
                if (B[i][j] == 'S') {
                    _B[i + 1][j] = 'S';
                }
        for (int i = 0; i < 9; i++) {
            int X = x + dx[i];
            int Y = y + dy[i];
            if (X < 0 || Y < 0 || X == 8 || Y == 8)
                continue;
            if (B[X][Y] != 'S' && rec(_B, X, Y, t + 1))
                return true;

        }
        return false;
    }

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        char[][] B = new char[8][8];
        for (int i = 0; i < 8; i++)
            B[i] = in.readLine().toCharArray();
        if (rec(B, 7, 0, 0))
            System.out.println("WIN");
        else
            System.out.println("LOSE");
    }
}


import java.util.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;
import java.util.Stack;
import java.util.StringTokenizer;

public class Main {

//public static HashMap<Integer,node> hs=new HashMap<Integer, node>();
public static LinkedList<Integer> graph [] = new LinkedList[64];
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st;
        LinkedList<Integer> stat = new LinkedList<Integer>();
        start();
            boolean [] visited = new boolean[64];
            boolean [] steps = new boolean[100];
            int [] parent = new int[64];
           int m =0, a=0;
            for (int i = 0; i < 8; i++) {
                st=new StringTokenizer(in.readLine().trim());
                char[]c=st.nextToken().toCharArray();
                for (int j = 0; j < 8; j++) {
                    if(c[j]=='S'){
                        int pos =(i*8)+j;
                        stat.add(pos);
                       // System.out.println("S: "+pos);
                }
                    else if(c[j]=='M'){
                     m=(i*8)+j;
                    }
                    else if(c[j]=='A'){
                      a=(i*8)+j;
                    }
            }
            }// end of for

            Stack <Integer> list = new Stack<Integer>();
            list.add(m);
            boolean reach=false;
            while(!list.isEmpty()){
                int temp = list.pop();
                visited[temp]=true;
                if(temp==a){
                    reach=true;
                    break;
            }
                for (int i = 0; i < graph[temp].size(); i++) {
                    int pos=graph[temp].get(i);
                    parent[pos]=parent[temp]+1;
                    if( statue(pos ,stat , parent[pos] )){
                        list.add(pos);
                    }
                }

            }
            if(reach)
                System.out.println("WIN");
            else
                System.out.println("LOSE");

        }
public static void start(){
    int count=1;
    for (int i = 0; i < graph.length; i++) {
       graph[i]= new LinkedList<Integer>();

    }
    for (int i = 0; i < 8; i++) {
        for (int j = 0; j < 8; j++) {
                int pos = (i*8)+j;
             //   System.out.print("p : "+pos);
             graph[pos].add(pos);    if(j+1<8)graph[pos].add(pos+1);
                 if(j-1 >= 0)graph[pos].add(pos-1);
               // if(i+7 >= 0 && j+7<8)graph[pos].add(pos+7);
                if(i-1 >= 0 && j+1<8)graph[pos].add(pos-7);
               // if(i+9 >= 0 && j+9<8)graph[pos].add(pos+9);
                if(i-1 >= 0 && j-1 >=0)graph[pos].add(pos-9);
               // if(i+8 >= 0 && j+8<8)graph[pos].add(pos+8);
                if(i-1 >= 0)graph[pos].add(pos-8);
            }
       // System.out.println("");
        }
    for (int i = 0; i < graph.length; i++) {
        LinkedList<Integer> temp = graph[i];
        for (int j = 0; j < temp.size(); j++) {
        //    System.out.print(temp.get(j)+" ");
        }
      //  System.out.println("--");
    }
    }
public static boolean statue(int pos , LinkedList<Integer> stat , int step){
boolean flag=true;
    for (int i = 0; i < stat.size(); i++) {
         if((stat.get(i)+(8*(step-1))<64)&&stat.get(i)+(8*(step-1))==pos)
            flag=false;

         if((stat.get(i)+(8*step)<64)&&stat.get(i)+(8*step)==pos)
            flag=false;

    }
   // System.out.println("pos "+pos+" flag "+flag+" step "+step);
return flag;
}
}

class node {
    int i,j;

    public node (int a, int b ){
        i=a;
        j=b;

    }

}


import java.util.*;

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

        long x = sc.nextLong();

        long binaryForm = 0;

        long number = x;
        int count = 0;

        while(number > 0){
            int rem = number%2;
            number /= 2;
            binaryForm += rem*(long)Math.pow(10,count);
            count++;
        }

        int noOfOnes = 0;
        long bForm = binaryForm;
        while(bForm > 0){
            if(bForm%10 == 1){
                noOfOnes++;
            }

            bForm /= 10;
        }

        System.out.println(noOfOnes);
    }
}


input Java.IO.File;
public class RaisingBacteria{

	public static void main(String[] args) throws FileNotFoundException{
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();

		if(x%2 == 0){
			return 1;
		}
		else{
			return 2;
		}
	}
}


package code;
import java.util.Scanner;
public class emy {

	public static void main(String[] args) {
		int x,sum=0,count=0;
		Scanner input=new Scanner(System.in);
		x=input.nextInt();
		if(x!=0)
		{
			count++;
			sum++;
		}
		while(count<x)
		{
			count*=2;

		}
		if(count>x)
		{
			count/=2;
			sum+=x-count;
		}
		System.out.println(sum);
	}


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

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

        int x = 0;
        Scanner sc = new Scanner(System.in);
        x = sc.nextInt();

        if (x <= 0) {
            System.out.println ("0");

        } else if (x%2 == 0) {
            System.out.println ("1");
        } else {
            System.out.println ("2");
        }

        System.exit(0);
    }
}


import java.util.Scanner;

public class Main {
	public static int intat(int a,int cur)
	{
		int tema=a;
		for(int flag=0;flag<cur;flag++)
		{
			tema/=10;
		}
		return tema%10;
	}
	static class guess
	{
		int num;
		int posright;
		int difright;
	}
	public static boolean difdigit(int x)
	{
		int occupied[]=new int[12];
		for(int flag=0;flag<10;flag++)
		{
			occupied[flag]=0;
		}
		for(int flag=0;flag<4;flag++)
		{
			if(occupied[intat(x,flag)]==1)
			{
				return false;
			}
			occupied[intat(x,flag)]=1;
		}
		return true;
	}
	public static boolean ok(int x,guess g[],int line)
	{
		for(int flag=0;flag<line;flag++)
		{
			int pr=0;
			int dr=0;
			for(int flag1=0;flag1<4;flag1++)
			{
				if(intat(g[flag].num,flag1)==intat(x,flag1))
				{
					pr++;
				}
			}
			int occupied[]=new int[12];
			for(int flag1=0;flag1<10;flag1++)
			{
				occupied[flag1]=0;
			}
			for(int flag1=0;flag1<4;flag1++)
			{
				occupied[intat(g[flag].num,flag1)]++;
				occupied[intat(x,flag1)]++;
			}
			for(int flag1=0;flag1<10;flag1++)
			{
				if(occupied[flag1]>=2)
				{
					dr++;
				}
			}
			dr-=pr;
			if(dr!=g[flag].difright)
				return false;
			if(pr!=g[flag].posright)
				return false;
		}
		return true;
	}
	public static void main(String[] args)
	{
		Scanner cin=new Scanner(System.in);
		int line;
		while(cin.hasNextInt())
		{
			line=cin.nextInt();
			guess g[]=new guess[105];
			for(int flag=0;flag<line;flag++)
			{
				g[flag]=new guess();
				g[flag].num=cin.nextInt();
				g[flag].posright=cin.nextInt();
				g[flag].difright=cin.nextInt();
			}
			int ans=0;
			int res=0;
			for(int count=0;count<=9999;count++)
			{
				if(difdigit(count))
				{
					if(ok(count,g,line))
					{
						ans++;
						res=count;
					}
				}
			}
			if(ans==1)
			{
				System.out.println(res);
			}
			else if(ans==0)
			{
				System.out.println("Incorrect data");
			}
			else if(ans>1)
			{
				System.out.println("Need more data");
			}
		}
	}
}


import java.util.ArrayList;

/**
 * Created by IntelliJ IDEA.
 * User: piyushd
 * Date: 2/28/11
 * Time: 9:18 PM
 * To change this template use File | Settings | File Templates.
 */
public class Task3 {

	int[] a;
	int[] b;
	int[] c;
	ArrayList<Integer> list = new ArrayList<Integer>();

	int bull(int a, int b){
		int ans = 0, i = 0;
		while(i < 4){
			if(a % 10 == b % 10)ans++;
			a /= 10; b /= 10;
			i++;
		}
		return ans;
	}

	int cow(int a, int b){
		int ans = 0, i = 0;
		while(i < 4){
			int find = a % 10;
			int x = b;
			for(int j = 0; j < 4; j++){
				if(j != i && find == x % 10)ans++;
				x /= 10;
			}
			a /= 10;
			i++;
		}
		return ans;
	}

	void solve(int n, boolean[] used, int x){
		if(n == 4){
			boolean ok = true;
			for(int i = 0; i < a.length && ok; i++){
				ok = ok && bull(a[i], x) == b[i];
				ok = ok && cow(a[i], x) == c[i];
			}
			if(ok) list.add(x);
			return;
		}

		for(int i = 0; i < 10; i++)
			if(!used[i]){
				used[i] = true;
				solve(n + 1, used, x * 10 + i);
				used[i] = false;
			}

	}

	void run(){
 		int n = nextInt();
		a = new int[n];
		b = new int[n];
		c = new int[n];
		for(int i = 0; i < n; i++){
			a[i] = nextInt(); b[i] = nextInt(); c[i] = nextInt();
		}

		boolean[] used = new boolean[10];
		solve(0, used, 0);

		if(list.size() == 1){
			System.out.println(list.get(0));
		}else if(list.size() > 1){
			System.out.println("Need more data");
		}else{
			System.out.println("Incorrect data");
		}
    }

    int nextInt(){
        try{
            int c = System.in.read();
            if(c == -1) return c;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return c;
            }
            if(c == '-') return -nextInt();
            int res = 0;
            do{
                res *= 10;
                res += c - '0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

    long nextLong(){
        try{
            int c = System.in.read();
            if(c == -1) return -1;
            while(c != '-' && (c < '0' || '9' < c)){
                c = System.in.read();
                if(c == -1) return -1;
            }
            if(c == '-') return -nextLong();
            long res = 0;
            do{
                res *= 10;
                res += c-'0';
                c = System.in.read();
            }while('0' <= c && c <= '9');
            return res;
        }catch(Exception e){
            return -1;
        }
    }

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

    String next(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(Character.isWhitespace(c))
                c = System.in.read();
            do{
                res.append((char)c);
            }while(!Character.isWhitespace(c=System.in.read()));
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

    String nextLine(){
        try{
            StringBuilder res = new StringBuilder("");
            int c = System.in.read();
            while(c == '\r' || c == '\n')
                c = System.in.read();
            do{
                res.append((char)c);
                c = System.in.read();
            }while(c != '\r' && c != '\n');
            return res.toString();
        }catch(Exception e){
            return null;
        }
    }

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


import java.util.*;

public class bullCow
{

    static int [] countN(int a)
    {
        String s = Integer.toString(a);
        if(s.length() < 4)
            s = "0000".substring(0,4-s.length()) + s;
        int [] count = new int[10];
        for(int i=0;i<s.length();i++)
            count[s.charAt(i) - '0']++;
        return count;
    }
    static boolean check(int a)
    {
        int [] count = countN(a);
        for(int i: count)
            if(i>1)
                return false;
        return true;
    }

    static boolean match(int m, int [] guess)
    {
        int arr[][] = new int[2][4];
        int nn[] = {m, guess[0]};
        for(int i=0;i<2;i++)
        {
            int a = nn[i];
            for(int j=0;j<4;j++)
            {
                arr[i][j] = a%10;
                a/=10;
            }
        }
        int cows = 0, bulls = 0;
        for(int i=0;i<4;i++)
            for(int j=0;j<4;j++)
                if(arr[0][i] == arr[1][j])
                    if(i == j)
                        bulls++;
                    else
                        cows++;
        return (guess[1] == bulls && guess[2] == cows);
    }

    public static void main(String [] args)
    {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int [][] guess = new int[n][3];
        for(int i=0;i<n;i++)
            for(int j=0;j<3;j++)
                guess[i][j] = sc.nextInt();
        ArrayList<Integer> matches = new ArrayList<Integer>();
        for(int i=100;i<10000;i++)
        {
            if(!check(i))
                continue;
            boolean ok = true;
            for(int j=0;j<n;j++)
                if(!match(i,guess[j]))
                {
                    ok = false;
                    break;
                }
            if(ok)
                matches.add(i);
        }
        if(matches.size() > 1)
            System.out.println("Need more data");
        else
            if(matches.size() == 0)
                System.out.println("Incorrect data");
            else
                System.out.println(matches.get(0));
    }
}


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

public class C {
	static String[] data;
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader r=new BufferedReader(new InputStreamReader(System.in));
		String s=r.readLine();

		int n=Integer.parseInt(s);
		data=new String[n];
		for (int i = 0; i < data.length; i++) {
			data[i]=r.readLine();
		}

		LinkedList<String> l=new LinkedList<String>();
		for(int a=0;a<10;a++ ){
			for(int b=0;b<10;b++){
				for(int c=0;c<10;c++){
					for(int d=0;d<10;d++){
						String num=a+""+b+""+c+""+d;

						if(can(num))l.add(num);
					}
				}
			}
		}
		if(l.size()==0)System.out.println("Incorrect data");
		else if(l.size()>1)System.out.println("Need more data");
		else System.out.println(l.remove());
	}
	private static boolean can(String num) {
		for(String s:data){
			if(!c(num,s))return false;
		}
		return true;
	}
	private static boolean c(String num, String s) {
		String[] sp=s.split(" ");
		String comp=sp[0];
		int similar=Integer.parseInt(sp[1]);
		int dif=Integer.parseInt(sp[2]);
		int count=0; //similar

		for(int i=0;i<num.length();i++){
			if(num.charAt(i)==comp.charAt(i))count++;
		}
		int c=0;
		for(int i=0;i<num.length();i++){
			if(comp.contains(num.charAt(i)+""))c++;
		}
		c-=count;
		return count==similar&&c==dif;
	}

}


import java.util.*;
public class subtraction{
  public static void main(String args[]){
      int n;
      int k;
      Scanner scan=new Scanner(System.in);
      n=scan.nextInt();
      k=scan.nextInt();
      int p=n;
      int r=p%10;
      int count=0;
   }
      if(r!=0){

      if(r-k>=0){
          System.out.print(n-k);
      }
      else{
          for(;r>0;r--){
              n--;
              count++;
          }

      for(;k-count>0;count++){
          n=n/10;
      }
      }
      }
      else{
          for(;count<k;count++){
              n=n/10;
          }
          System.out.print(n);
      }
  }
}


public class WrongAns{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int k=sc.nextInt();
        while(k>0)
        {
            if(n%10==0){n=n/10;}
            else n--;
        k--;}
        System.out.println(n);
    }
}


package com.wrongsubtraction;

public class NewClass {

	public static void main(String[] args) {

	    int x ;
	    int y;

		System.out.println(WrongSubtraction(x , y));
	}

	public static int WrongSubtraction(int number, int index) {

		for (int i = 0; i < index; i++) {
			if ((number % 10) == 0)
				number /= 10;
			else
				number -= 1;
		}
		return number;
	}

}


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

public class Test{

    public static void main(String args[]) throws IOException
    {
        Scanner scanner = new Scanner(System.in);
        int number,steps;
        number = scanner.nextInt();
        steps = scanner.nextInt();
        for(int i=0;i<steps;i++)
        {
            if(number%10 == 0)
                number/=10;
            else number--;
        }
        System.out.println(number);
        /*while ((number = scanner.nextInt()) > 0)
        {

        }*/

    }

    static class Scanner {

        StringTokenizer st;
        BufferedReader br;

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

        public Scanner(String file) throws Exception {
            br = new BufferedReader(new FileReader(file));
        }

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

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

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

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

        public char nextChar() throws IOException {
            return next().charAt(0);
        }

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

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

        public void waitForInput() throws InterruptedException {
            Thread.sleep(3000);
        }
    }
}

Click to see test details

Codeforces (c) Copyright 2010-2020 Mike Mirzayanov
The only programming contests Web 2.0 platform
Server time: Jan/22/2020 13:10:52UTC+6 (g2).
Desktop version, switch to mobile version.
Privacy Policy
Supported by
Telegram  ИТМО


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

public class C {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		String x = sc.next();
		int n = x.length();
		long all = Long.parseLong(x, 2);
		BigInteger m = BigInteger.valueOf(2).modPow(BigInteger.valueOf(n - 1), BigInteger.valueOf(1000000007));
		BigInteger res = m.multiply(BigInteger.valueOf(all).mod(BigInteger.valueOf(1000000007)));
		res = res.mod(BigInteger.valueOf(1000000007));
		out.println(res);
		out.flush();
		out.close();
	}

	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 long nextLong() throws IOException {
			return Long.parseLong(next());
		}

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

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

	}
}


    package cont187.copy;

    import java.util.*;

    public class probA {

        private static Scanner in;

        public static void main(String[] args) {
            in = new Scanner(System.in);
            String s =in.nextLine();
            int n = s.length();
            long ans[] = new long[n];
            long pow[] = new long[n+19];
            long pow1[] = new long[n+19];
            int mod = 1000000007;
            long Ans = 0;

            pow[0] = 1;
            pow1[0] = 2;

            for (int i = 1; i < n+1; i++){
                pow[i] = pow[i-1]*2 % mod;
                pow1[i] = (pow[i] + pow1[i-1]) %mod;
            }

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

                if (s.charAt(n-i-1)=='1')
                    if (i>0) ans[i] = (pow1[i-1])*pow[i]; else ans[i] = 1;
                if (i>0) ans[i] +=ans[i-1];
                ans[i] = ans[i]%mod;
                Ans += ans[i];
                ans[i] = Ans;
            }
            System.out.println(Ans%mod);
        }
}


import java.util.Scanner;

/**
 *
 * @author Javi
 */
public class MalekDanceClub {

    private static final int MODULO = 1000000007;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] input = in.nextLine().split(" ");
        String binaryEntry = input[0];

        int modPower = modularPower(binaryEntry.length());
        int modEntry = modularEntry(binaryEntry);
        long modProduct = modularProduct(modEntry, modPower);
        System.out.println(modProduct);

        // Binary number --> BigInteger
        // (BigInteger times 2^(n-1)) mod (10^(9)+7)

        in.close();
    }

    private static int modularPower(int n) {
        int res = 1;
        for (int i = 1; i < n; i++) {
            res = res * 2;
            if (res > MODULO) {
                res = res % MODULO;
            }
        }
        return res;
    }

    private static int modularEntry(String number) {
        int accCount = 1;
        int res = 0;
        for (int i = number.length() - 1; i >= 0; i--) {
            char charAt = number.charAt(i);
            if(charAt == '1') {
                res += accCount;
            }
            accCount = accCount * 2;
            if(accCount > MODULO) {
                accCount = accCount % MODULO;
            }
            if(res > MODULO) {
                res = res % MODULO;
            }
        }
        return res;
    }

    private static long modularProduct(int n1, int n2) {
        long res = n1;
        for (int i = 1; i < n2; i++) {
            res += n1;
            if (res > Long.MAX_VALUE - n1) {
                res = res % MODULO;
            }
        }
        return res % MODULO;
    }
}


import java.util.Calendar;
import java.util.Scanner;

/**
 *
 * @author Javi
 */
public class MalekDanceClub {

    private static final int MODULO = 1000000007;

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String[] input = in.nextLine().split(" ");
        String binaryEntry = input[0];

        int modPower = modularPower(binaryEntry.length());
        int modEntry = modularEntry(binaryEntry);
        long modProduct = modularProduct(modEntry, modPower);
        System.out.println(modProduct);

        // Binary number --> BigInteger
        // (BigInteger times 2^(n-1)) mod (10^(9)+7)

        in.close();
    }

    private static int modularPower(int n) {
        int res = 1;
        for (int i = 1; i < n; i++) {
            res = res * 2;
            if (res > MODULO) {
                res = res % MODULO;
            }
        }
        return res;
    }

    private static int modularEntry(String number) {
        int accCount = 1;
        int res = 0;
        for (int i = number.length() - 1; i >= 0; i--) {
            char charAt = number.charAt(i);
            if(charAt == '1') {
                res += accCount;
            }
            accCount = accCount * 2;
            if(accCount > MODULO) {
                accCount = accCount % MODULO;
            }
            if(res > MODULO) {
                res = res % MODULO;
            }
        }
        return res;
    }

    private static long modularProduct(int n1, int n2) {
        long res = n1;
        for (int i = 1; i < n2; i++) {
            res += n1;
            if (res > Long.MAX_VALUE - n1) {
                res = res % MODULO;
            }
        }
        return res % MODULO;
    }
}


public class Main {

    public static void main(String[] args) {

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

        short [] arrTemp = new short[n];

        arrTemp[0] = in.nextShort();
        arrTemp[1] = in.nextShort();
        int progr = arrTemp[1] - arrTemp[0];
        int nextProgr = 0;
        boolean flagProgr = true;

        for (int i = 2; i < n; i++){
            arrTemp[i] = in.nextShort();

            nextProgr = arrTemp[i] - arrTemp[i-1];
            if(nextProgr != progr)
                flagProgr = false;

            progr = nextProgr;
        }

        System.out.print(flagProgr ? arrTemp[n-1] + progr : arrTemp[n-1]);
    }
}


qpackage javaapplication51;
import java.util.*;
public class CodeForcess {

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

        int []aa=new int[n];
        for(int i=0;i<aa.length;i++)
        {
        aa[i]=s.nextInt();
        }
        int s1=aa[1]-aa[0];
        boolean x=false;
        for(int i=0;i<aa.length-1;i++){
       if(i+1 < aa.length && s1==(aa[i+1]-aa[i]))
            x=true;
        else
        {
        x=false;
        break;
        }}

        if(aa.length<2||x==false)
                System.out.println(aa[aa.length-1]);
        else

                System.out.println(aa[aa.length-1]+s1);

        }

    }


import java.util.*;

public class Main{
    public static void main(String args[]){
        scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int prev = sc.nextInt();
        int x = sc.nextInt();
        int cd = x-prev;
        prev = x;
        boolean ap = true;
        for(int i=1 ; i<=n-2 ; i++){
            int p = sc.nextInt();
            if((p-prev) != cd){
                ap=false;
            }
            prev = p;
        }
        if(ap==true)
            System.out.println(p+cd);
        else
            System.out.println(p);
    }
}


import java.util.*;

public class Main{
    public static void main(String args[]){
        int n = sc.nextInt();
        int prev = sc.nextInt();
        int x = sc.nextInt();
        int cd = x-prev;
        prev = x;
        boolean ap = true;
        for(int i=1 ; i<=n-2 ; i++){
            int p = sc.nextInt();
            if((p-prev) != cd){
                ap==false;
            }
            prev = p;
        }
        if(ap==true)
            System.out.println(p+cd);
        else
            System.out.println(p);
    }
}


import java.util.Scanner;

public class b96 {
	public static Scanner scn = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long numb = 0;
		long nums = 0;
		long numc = 0;
		String str = scn.next();

		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'B') {
				numb++;
			}
			if (str.charAt(i) == 'S') {
				nums++;
			}
			if (str.charAt(i) == 'C') {
				numc++;
			}
		}

		long b = 0, s = 0, c = 0;
		// for (int i = 0; i < 3; i++) {
		b = scn.nextInt();
		s = scn.nextInt();
		c = scn.nextInt();

		// }
		long pb = 0, ps = 0, pc = 0;

		pb = scn.nextInt();
		ps = scn.nextInt();
		pc = scn.nextInt();
		// }

		long r = scn.nextLong();
		int count = 0;

		int a = 0;

		long lo = 1;
		long hi = 1e18;
		long val = 0;
		long mid = 0;

		int price = 0;
		int d = 0;
		while (lo <=hi) {
			mid = (lo + hi) / 2;

			long mm = ((mid * numb) - b) * pb;
			long mm2 = ((mid * nums) - s) * ps;
			long mm3 = ((mid * numc) - c) * pc;

				if (mm > 0) {
					price += mm;
				}
				if (mm2 > 0) {
					price += mm2;

				}
				if (mm3 > 0) {
					price += mm3;
				}

				if (0<=price && price <= r ) {
				    val=mid;
					lo = mid + 1;
				} else {
					hi = mid - 1;
				}

			price=0;

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

		System.out.println(val);

	}

}


import java.util.Scanner;

public class b96 {
	public static Scanner scn = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long numb = 0;
		long nums = 0;
		long numc = 0;
		String str = scn.next();

		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'B') {
				numb++;
			}
			if (str.charAt(i) == 'S') {
				nums++;
			}
			if (str.charAt(i) == 'C') {
				numc++;
			}
		}

		long b = 0, s = 0, c = 0;
		// for (int i = 0; i < 3; i++) {
		b = scn.nextInt();
		s = scn.nextInt();
		c = scn.nextInt();

		// }
		long pb = 0, ps = 0, pc = 0;

		pb = scn.nextInt();
		ps = scn.nextInt();
		pc = scn.nextInt();
		// }

		long r = scn.nextLong();
		int count = 0;

		int a = 0;

		long long lo = 1;
		long long hi = 9223372036854775807;
		long long val = 0;
		long long mid = 0;

		int price = 0;
		int d = 0;
		while (lo <=hi) {
			mid = (lo + hi) / 2;

			long mm = ((mid * numb) - b) * pb;
			long mm2 = ((mid * nums) - s) * ps;
			long mm3 = ((mid * numc) - c) * pc;

				if (mm > 0) {
					price += mm;
				}
				if (mm2 > 0) {
					price += mm2;

				}
				if (mm3 > 0) {
					price += mm3;
				}

				if (0<=price && price <= r ) {
				    val=mid;
					lo = mid + 1;
				} else {
					hi = mid - 1;
				}

			price=0;

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

		System.out.println(val);

	}

}


import java.util.Scanner;

public class CHamburgers {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String rec = in.nextLine();
        int nb,ns,nc;
        nb = in.nextInt();
        ns = in.nextInt();
        nc = in.nextInt();
        byte pb,ps,pc;
        pb = in.nextInt();
        ps = in.nextInt();
        pc = in.nextInt();
        long r = in.nextLong();
        int[] needs = new int[3];

        for(int i=0; i<rec.length(); i++) {
            if (rec.charAt(i) == 'B') needs[0]++;
            if (rec.charAt(i) == 'S') needs[1]++;
            if (rec.charAt(i) == 'C') needs[2]++;
        }

        long start = 0l;
        long end = 1000000000000l;
        long middle = 0l;

        while(start<=end) {
            middle = start+(end-start)/2;
            if(Math.max(0,needs[0]*middle-nb)*pb+Math.max(0,needs[1]*middle-ns)*ps+Math.max(0,needs[2]*middle-nc)*pc>r) {
                end=middle-1;
            } else if(Math.max(0,needs[0]*middle-nb)*pb+Math.max(0,needs[1]*middle-ns)*ps+Math.max(0,needs[2]*middle-nc)*pc<r) {
                start=middle+1;
            } else {
                end = middle;
                start = middle;
                break;
            }
        }

        System.out.println(end);
    }
}


import java.util.Scanner;

public class b96 {
	public static Scanner scn = new Scanner(System.in);

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		long numb = 0;
		long nums = 0;
		long numc = 0;
		String str = scn.next();

		for (int i = 0; i < str.length(); i++) {
			if (str.charAt(i) == 'B') {
				numb++;
			}
			if (str.charAt(i) == 'S') {
				nums++;
			}
			if (str.charAt(i) == 'C') {
				numc++;
			}
		}

		long b = 0, s = 0, c = 0;
		// for (int i = 0; i < 3; i++) {
		b = scn.nextInt();
		s = scn.nextInt();
		c = scn.nextInt();

		// }
		long pb = 0, ps = 0, pc = 0;

		pb = scn.nextInt();
		ps = scn.nextInt();
		pc = scn.nextInt();
		// }

		long r = scn.nextLong();
		int count = 0;

		int a = 0;

		long lo = 1;
		long hi = 9223372036854775;
		long val = 0;
		long mid = 0;

		int price = 0;
		int d = 0;
		while (lo <=hi) {
			mid = (lo + hi) / 2;

			long mm = ((mid * numb) - b) * pb;
			long mm2 = ((mid * nums) - s) * ps;
			long mm3 = ((mid * numc) - c) * pc;

				if (mm > 0) {
					price += mm;
				}
				if (mm2 > 0) {
					price += mm2;

				}
				if (mm3 > 0) {
					price += mm3;
				}

				if (0<=price && price <= r ) {
				    val=mid;
					lo = mid + 1;
				} else {
					hi = mid - 1;
				}

			price=0;

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

		System.out.println(val);

	}

}