codeparrot/codecomplex huggingface dataset:
// Problem: 1019_B. The hat
// Time complexity: logn
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class B {
    public static PrintWriter out;
    public static BufferedReader bf;
    public static int n;
    public static int[] a;
    public static void main(String[] args) throws Exception {
        bf = new BufferedReader(new InputStreamReader(System.in));
        // Scanner scan = new Scanner(System.in);
        out = new PrintWriter(new OutputStreamWriter(System.out));
        n = Integer.parseInt(bf.readLine());
        a = new int[n];
        Arrays.fill(a, Integer.MAX_VALUE);
        if((n/2) % 2 != 0) {
          out.println("! " + (-1));
          out.flush();
          out.close(); System.exit(0);
        }

        ask(0);
        ask(opp(0));

        int low = 0;
        int high = opp(0);
        while(true) {
          int test = (low + high)/2;
          ask(test);
          ask(opp(test));
          int l_1 = a[low];
          int l_2 = a[test];
          int r_1 = a[opp(low)];
          int r_2 = a[opp(test)];
          if(1L*(l_1 - r_1)*(l_2 - r_2) < 0L) {
            high = test;
          }
          else low = test;
        }

        // StringTokenizer st = new StringTokenizer(bf.readLine());
        // int[] a = new int[n]; for(int i=0; i<n; i++) a[i] = Integer.parseInt(st.nextToken());
        // int n = Integer.parseInt(st.nextToken());
        // int n = scan.nextInt();

        //out.close(); System.exit(0);
    }
    public static int ask(int i) throws Exception { // 0 thru n-1;
      out.println("? " + (i+1));
      out.flush();
      int k = Integer.parseInt(bf.readLine());
      a[i] = k;
      if(a[i] == a[opp(i)]) {
        out.println("! " + (i+1));
        out.flush();
        out.close(); System.exit(0);
      }

      return k;
    }
    public static int opp(int k) {
      return ((k + n/2) % n);
    }
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.util.*;
import java.io.*;

public class CFB {
    static int n;
    static FastScanner in;
    public static void main(String[] args) throws Exception {
        in = new FastScanner(System.in);
        n = in.nextInt();
        int a = query(1);
        if(((a % 2)+2) % 2== 1){
            System.out.println("! -1");
            return;
        }
        if(a == 0){
            System.out.println("! 1");
            return;
        }
        bins(1 , n/2 + 1 , a , -a);
    }
    static void bins(int lo , int hi , int losign , int hisign){
        int mid = (lo + hi)/2;
        int k = query(mid);
        if(k == 0){
            System.out.println("! " + mid);
            System.exit(0);
        }
        if(k > 0 && losign > 0 || k < 0 && losign < 0){
            bins(mid , hi , k , hisign);
        }
        else {
            bins(lo , mid , losign , k);
        }

    }
    static int query(int i){
        System.out.println("? " + i);
        int a1 = in.nextInt();
        System.out.println("? " + ((i + (n/2)) > n ? (i - (n/2)) : (i + (n/2))));
        int a2 = in.nextInt();
        return a1 - a2;
    }

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

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

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

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

        boolean isEndline(int c) {
            return c == '\n' || c == '\r' || c == -1;
        }

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

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

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

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

        public String nextLine() {
            int c = read();
            while (isEndline(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            } while (!isEndline(c));
            return res.toString();
        }
    }
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
	static PrintWriter out = new PrintWriter(System.out);
	static FS in;
	
	static int N;
	static final boolean debug = false;
	static int inp[] = new int[] {1,2,3,2,1,0};
	public static void main(String[] args) {
		in = new FS();
		if(!debug) N = in.nextInt();
		else N = inp.length;
		int x = solve(0, N/2-1, N/2, N-1);
		out.println("! "+(x+1));
		out.flush();
		out.close();
	}
	
	static int solve(int l1, int r1, int l2, int r2) {
		int sz = r1-l1+1;
		if(sz <= 0) return -2;
		int a1 = query(l1);
		int a2 = query(l2);
		if(a1 == a2) return l1;
		
		if(sz == 1) return -2;
		
		int b1 = query(l1+sz/2);
		int b2 = query(l2+sz/2);
		if(b1 == b2) return l1 + sz/2;
		
		if(sz == 2) return -2;
		
		int d1 = a2-a1;
		int d2 =  b2-b1;
		if((d1 < 0 && d2 > 0) || (d1 > 0 && d2 < 0)) {
			return solve(l1+1, l1 + sz/2 - 1, l2+1, l2 + sz/2 - 1);
		}
		else {
			return solve(l1 + sz/2 + 1, r1, l2 + sz/2 + 1, r2);
		}
	}
	
	static int query(int a) {
		out.println("? "+(a+1));
		out.flush();
		if(debug) return inp[a];
		else return in.nextInt();
	}
	
	static class FS{
		BufferedReader br;
		StringTokenizer st;
		public FS() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {
			while(st == null || !st.hasMoreElements()) {
				try {st = new StringTokenizer(br.readLine());}
				catch(Exception e) { throw null;}
			}
			return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next());}
		double nextDouble() { return Double.parseDouble(next());}
		long nextLong() { return Long.parseLong(next());}
		int[] NIA(int n) {
			int r[] = new int[n];
			for(int i = 0; i < n; i++) r[i] = nextInt();
			return r;
		}
		long[] NLA(int n) {
			long r[] = new long[n];
			for(int i = 0; i < n; i++) r[i] = nextLong();
			return r;
		}
		char[][] grid(int r, int c){
			char res[][] = new char[r][c];
			for(int i = 0; i < r; i++) {
				char l[] = next().toCharArray();
				for(int j = 0; j < c; j++) {
					res[i][j] = l[j];
				}
			}
			return res;
		}
	}
	
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class B {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		if (N / 2 % 2 == 1) {
			output(-1, out);
		} else {
			int half = N / 2;
			int l = 1, r = half;
			int first = query(half, out, sc);
			int next = query(2 * half, out, sc);
			if (first == next) {
				output(half, out);
				return;
			}
			boolean less = first < next;
			while (l + 1 < r) {
				int med = (l + r) / 2;
				first = query(med, out, sc);
				next = query(med + half, out, sc);
				if (first == next) {
					output(med, out);
					return;
				} else if (first < next == less) {
					r = med;
				} else {
					l = med + 1;
				}
			}
			output(l, out);
		}
	}
	
	static int query(int pos, PrintWriter out, MyScanner sc) {
		out.println("? " + pos);
		out.flush();
		return sc.nextInt();
	}
	
	static void output(int pos, PrintWriter out) {
		out.println("! " + pos);
		out.flush();
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.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());
		}
	}
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.io.*;
import java.util.*;

public class B {
	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(1, in, out);
		out.close();
	}

	static class Task {
		int n = 0;
		int query(int p, InputReader in) {
			p %= n;
			if (p <= 0) p += n;
			System.out.println("? " + p);
			System.out.flush();
			int x = in.nextInt();
			return x;
		}
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			n = in.nextInt();
			if (n % 4 != 0) {
				out.println("! -1");
				return;
			}
			int p = query(0, in);
			int q = query(n / 2, in);
			int l = 0;
			int r = n / 2;
			if (p == q) {
				out.println("! " + (n / 2));
				return;
			}
			while (l + 1 < r) {
				int mid = (l + r) / 2;
				int u = query(mid, in);
				int v = query(mid + n / 2, in);
				if (u == v) {
					out.println("! " + (mid + n / 2));
					return;
				}
				if ((p < q) == (u < v)) {
					l = mid;
				} else {
					r = mid;
				}
			}
		}
	}

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

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

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

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

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

	}
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskB {
        int N;

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            N = in.nextInt();
            int low = 1;
            int lowVal = getval(1, out, in);
            int high = N / 2 + 1;
            int highVal = -lowVal;
            if (Math.abs(lowVal) % 2 == 1) {
                out.println("! -1");
                out.flush();
            } else {
                while (low < high) {
                    int mid = (low + high) / 2;
                    int a = getval(mid, out, in);
                    if (Integer.signum(a) == 0) {
                        out.println("! " + mid);
                        out.flush();
                        return;
                    } else {
                        if (Integer.signum(a) == Integer.signum(lowVal)) {
                            low = mid + 1;
                        } else {
                            high = mid;
                        }
                    }
                }
                out.println("! " + low);
                out.flush();
            }
        }

        int getval(int i, PrintWriter out, InputReader in) {
            out.println("? " + i);
            out.flush();
            int a = in.nextInt();
            out.println("? " + (i + N / 2));
            out.flush();
            int b = in.nextInt();
            return a - b;
        }

    }

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

    }
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.io.*;
import java.util.*;
public class Main {
	final static int MAXN = 100005;
	static int n;
	static Scanner cin;
	static int[] a;
	static boolean[] used;
	public static int Query(int x) {
		System.out.print("? ");
		System.out.println(x);
		System.out.flush();
		int a = cin.nextInt();
		return a;
	}
	public static int Q(int x) {
		if(used[x]) return a[x];
		used[x] = true;
		a[x] = Query(x) - Query(x + n / 2);
		if(a[x] == 0) {
			System.out.print("! ");
			System.out.println(x);
			System.out.flush();
			cin.close();
			System.exit(0);
		}
		return a[x];
	}
	public static void main(String[] args) {
		cin = new Scanner(System.in);
		n = cin.nextInt();
		a = new int[MAXN];
		used = new boolean[MAXN];
		if(n % 4 != 0) {
			System.out.println("! -1\n");
			System.out.flush();
			cin.close();
			return;
		}
		int l = 1, r = n / 2, mid;
		while(l <= r) {
			mid = (l + r) / 2;
			int x = Q(mid);
			if(Q(l) * x < 0) {
				r = mid - 1;
			} else if(x * Q(r) < 0) {
				l = mid + 1;
			}
		}
		System.out.println("! -1\n");
		System.out.flush();
		cin.close();
	}
}
// Problem: 1019_B. The hat
// Time complexity: logn
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

public class Div1_503B {

	public static void main(String[] args) throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		PrintWriter printer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
		int N = Integer.parseInt(reader.readLine());
		printer.println("? 1");
		printer.flush();
		int v1 = Integer.parseInt(reader.readLine());

		printer.println("? " + (1 + N / 2));
		printer.flush();
		int v2 = Integer.parseInt(reader.readLine());

		if ((v1 + v2) % 2 != 0) {
			printer.println("! -1");
			printer.close();
			return;
		}

		if (v1 == v2) {
			printer.println("! 1");
			printer.close();
			return;
		}
		boolean less = v1 < v2;

		int low = 1;
		int high = (1 + N / 2);

		while (low != high) {
			int mid = (low + high) >> 1;

			printer.println("? " + mid);
			printer.flush();
			int r1 = Integer.parseInt(reader.readLine());

			int q2 = (mid + N / 2);
			if (q2 > N) {
				q2 -= N;
			}
			printer.println("? " + q2);
			printer.flush();
			int r2 = Integer.parseInt(reader.readLine());

			if (r1 == r2) {
				printer.println("! " + mid);
				printer.close();
				return;
			}

			if (r1 < r2 == less) {
				low = mid + 1;
			} else {
				high = mid - 1;
			}
		}
		printer.println("! " + low);
		printer.close();
		return;
	}
}
// Problem: 1019_B. The hat
// Time complexity: logn
//package contests.CF1019;

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

public class B {

    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        int half = n/2;
        pw.println("? 1");
        pw.flush();
        int a = sc.nextInt();
        pw.println("? " + (1+half));
        pw.flush();
        int b = sc.nextInt();
        if(a - b == 0){
            pw.println("! 1");
        }
        else
        if((a - b)%2 != 0)
        {
            pw.println("! -1");
        }else{
            boolean greater = a > b;
            int lo = 1;
            int hi = half;

            boolean ans = false;
            while(lo <= hi){
                int mid = (lo + hi) /2;
                pw.println("? " + mid);
                pw.flush();
                a = sc.nextInt();
                pw.println("? " + (mid+half));
                pw.flush();
                b = sc.nextInt();

                if(a == b){
                    pw.println("! " + mid);
                    ans = true;
                    break;
                }

                if(a > b != greater){
                    hi = mid-1;
                }else{
                    lo = mid+1;
                    greater = a>b;
                }
            }

            if(!ans){
                pw.println("! -1");
            }

        }

        pw.flush();
        pw.close();
    }



    static int[][] packD(int n, int[] from, int[] to) {
        int[][] g = new int[n][];
        int[] p = new int[n];
        for (int f : from) if(f != -1) p[f]++;
        for (int i = 0; i < n; i++) g[i] = new int[p[i]];
        for (int i = 0; i < from.length; i++) if(from[i] != -1) {g[from[i]][--p[from[i]]] = to[i];}
        return g;
    }

    static void shuffle(int[] a)
    {
        int n = a.length;
        for(int i = 0; i < n; i++)
        {
            int r = i + (int)(Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }

    static class Scanner
    {
        StringTokenizer st; BufferedReader br;
        public Scanner(InputStream s){	br = new BufferedReader(new InputStreamReader(s));}
        public Scanner(String s) throws FileNotFoundException {	br = new BufferedReader(new FileReader(new File(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();}
    }
}
// Problem: 817_C. Really Big Numbers
// Time complexity: logn
import java.util.Scanner;
import java.io.*;
import java.util.*;
public class ReallyBigNumbers817c {
     static long sd(String s) {
        long c = 0;
        for (int i = 0; i < s.length(); i++) {
            c += s.charAt(i);
        }
        return c - s.length() * 0x30;
    }
     
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        long n = in.nextLong();
        long s = in.nextLong(); // number
         // level -- > (n + 8) / 9 * 9; --- > s
        long i = (s/10+1)*10 ;
        if (n<10||n-sd(n+"")<s) {
            System.out.println(0);
            return;
        }
        while(!(i-sd(i+"")>=s)){
        i+=10;
        
        }
        System.out.println(n-i+1);
       
    }
    
	}
// Problem: 817_C. Really Big Numbers
// Time complexity: logn

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


public class ReallyBigNumbers1 
{
    
    public static void main(String[] args) throws IOException 
    {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        PrintWriter out = new PrintWriter(System.out);
        long n = Long.parseLong(st.nextToken());
        long s = Long.parseLong(st.nextToken());
        
        int r = 0 ;
        
        long l = 0L ;
        long u = n ;
        
        if(  (l-sumDigits(l)< s )  && (u-sumDigits(u)< s ) )
        {
            out.println(0);
            out.flush();
            out.close();
            return ;
        }
        
        long specified = 0L ;
        while( true )
        {
            long m = (l + u) / 2L ;
            
            if( ( m - sumDigits(m) ) >= s && ( (m-1) - sumDigits(m-1) ) < s  )
            {
                specified = m ;
                break ;
            }
            
            if( l > u  )
                break ;
            
            else
            {
                if( ( m - sumDigits(m) ) >= s )
                    u = m-1 ;
                else
                    l = m+1 ;
            }
        }
        
        out.println( n-specified+1 );
        out.flush();
        out.close();
        
    }
    
    public static int sumDigits(long n)
    {
        char [] a = (n+"").toCharArray();
        int sum = 0 ;
        for(int k = 0 ; k < a.length ; k++)
        {
            sum += Integer.parseInt(a[k]+"") ;
        }
        return sum ;
    }
    
}