codeparrot/codecomplex huggingface dataset:
// Problem: 1080_D. Olya and magical square
// Time complexity: logn
import java.io.*;
import java.util.StringTokenizer;

import static java.lang.Math.max;
import static java.lang.Math.min;

public class Main {
    FastScanner in;
    PrintWriter out;

    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

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

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

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

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

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

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

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

    void solve() {
        int t = in.nextInt();

        for (int sdfsdf = 0; sdfsdf < t; sdfsdf++) {
            long n = in.nextLong();
            long k = in.nextLong();

            if (n == 1) {
                if (k == 1)  {
                    out.println("YES 0");
                } else {
                    out.println("NO");
                }
                continue;
            }

            if (k == 3) {
                if (n == 2) {
                    out.println("NO");
                } else {
                    out.println("YES " + (n - 1));
                }
                continue;
            }

            long cuts = 1;
            long squares = 4;
            int zoom = 1;

            while (k > cuts + squares) {
                cuts += squares;
                squares *= 4;
                zoom++;
            }

            if (zoom > n) {
                out.println("NO");
                continue;
            }

            if (zoom == n && k > cuts) {
                out.println("NO");
                continue;
            }

            long current_cuts = k - cuts;

            if (current_cuts > squares - (2L * Math.sqrt(squares) - 1L)) {
                out.println("YES " + (n - zoom - 1L));
            } else {
                out.println("YES " + (n - zoom));
            }
        }
    }
}
// Problem: 1159_A. A pile of stones
// Time complexity: linear
/*
 * 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.
 */
//package newpackage;
import java.util.*;
/**
 *
 * @author parpaorsa
 */
public class NewClass {
    static Scanner in=new Scanner(System.in);
    public static void main(String[] args) {
        int n = in.nextInt(),ans=Integer.MAX_VALUE,t=0;
        String x = in.next();
        for (int i = 0; i < n; i++) {
            if(x.charAt(i)=='-')t--;
            else t++;
            ans=Math.min(ans,t);
        }
           if(ans <= 0) 
               System.out.println(Math.abs(ans)+t);
           else 
               System.out.println(t);
    }
 
}
// Problem: 1197_D. Yet Another Subarray Problem
// Time complexity: quadratic
import java.util.*;
public class TestClass
{
   public static void main(String args[])
   {
   	Scanner in = new Scanner(System.in);
   	int n = in.nextInt();
   	int m = in.nextInt();
   	int k = in.nextInt();
   	int arr[] = new int[n+1];
   	for(int i =0;i<n;i++)
   	 arr[i+1]= in.nextInt();
   	
   	long sum[] = new long [n+1];
   	
   	for(int i=1;i<=n;i++)
   	 sum[i]=sum[i-1]+arr[i];
   	
    long dp[] = new long[n+1];

    for(int i =1;i<=n;i++)
    {
      for(int j=i;j>i-m&&j>=1;j--)
      {
        long val = sum[i]-sum[j-1]+dp[j-1]-k;
        dp[i]= Math.max(dp[i],val);
      }	
    }
    long max =0;
    for(int i =1;i<=n;i++)
     max=Math.max(max,dp[i]);
    
    System.out.println(max);
     
   }	
}
// Problem: 1061_B. Views Matter
// Time complexity: nlogn
import java.util.*;
public class test{
public static void main(String args[])
{
Scanner s=new Scanner(System.in);
int n=s.nextInt();
int m=s.nextInt();
int arr[]=new int[n];
int max = Integer.MIN_VALUE;
        long sum = 0;
        for(int i=0;i<n;i++)
        {
            arr[i] = s.nextInt();
            sum = sum + arr[i];
            max = Math.max(max,arr[i]);
        }
        Arrays.sort(arr);
        int i = 0;
        int count = 0;
        int d = 0;
        for(i=0; i<n; i++)
        {
            if(arr[i] > d)
            {
                count++;
                d++;
            }
            else if(arr[i] == d && arr[i] > 0)
            {
                count++;
            }
        }
        //System.out.println(count + " " + max);
        if(max - d > 0)
        {
            count = count + max - d;
        }
        System.out.println(sum - count);}}
// Problem: 1092_D1. Great Vova Wall (Version 1)
// Time complexity: linear
import java.io.*;
import java.util.*;


public class tr {
	static int[][] ad;
    static boolean []vis;
    static int []goods;
    static int[][]sol;
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		int n=sc.nextInt();
		int []a=new int [n];
		int max=0;
		for(int i=0;i<n;i++)
			a[i]=sc.nextInt();
		Stack<Integer> s=new Stack<>();
		boolean f=true;
				for(int i=0;i<n;i++) {
					max=Math.max(max,a[i]);
					if(!s.isEmpty() && a[i]>s.peek())
						f=false;
					s.push(a[i]);
					while(!s.isEmpty()) {
						int high=s.pop();
						if(s.isEmpty() || s.peek()!=high) {
							s.push(high);
							break;
						}
						s.pop();
					}
				//	System.out.println(s+" "+max);
				}
				//System.out.println(f+" "+max);
				if(f && s.size()==0)
					out.println("YES");
				else if(f && s.size()==1 && s.peek()==max)
					out.println("YES");
				else
					out.println("NO");
		 out.flush();
	}
	static int gcd(int a, int b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	static class pair implements Comparable<pair> {
		int a;
		int b;

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

		public String toString() {
			return a + " " + b;
		}

		@Override
		public int compareTo(pair o) {
			return  o.a-a ;
		}
	}

	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);
		}
	}
}
// Problem: 1080_B. Margarite and the best present
// Time complexity: constant
import java.util.Scanner;

public class MargariteBestPresent_1080B {

	private static int f(int x) {
		return (x%2==0)?x/2:(x-1)/2-x;
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n,r,l;
		n = sc.nextInt();
		while(n-->0) {
			l = sc.nextInt();
			r = sc.nextInt();

			System.out.println(f(r)-f(l-1));
		}
		sc.close();
	}

}
// Problem: 1028_A. Find Square
// Time complexity: quadratic
import java.util.*;

public class helloWorld 
{
	public static void main(String[] args) 
	{		
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int m = in.nextInt();
		int l = 1000, r = 0, u = 1000, b = 0;
		
		for(int i = 0; i < n; i++ ) {
			String str = in.next();
			for(int j = 0; j < m; j++)
				if(str.charAt(j) == 'B') {
					l = Math.min(j+1, l);
					r = Math.max(j+1, r);
					u = Math.min(i+1, u);
					b = Math.max(i+1, b);
				}
		}
		
		System.out.println((u+b)/2 + " " + (l+r)/2);
		
		in.close();
	}
}
// Problem: 608_C. Chain Reaction
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;
public class BOOL {
    static char [][]ch;
    static int n,m;
private static FastReader in =new FastReader();
    public static void main(String[] args) {
    int n=in.nextInt();
    int a[]=new int[1000002];
    int dp[]=new int[1000002],ans=0;
    for(int i=0;i<n;i++){a[in.nextInt()]=in.nextInt();}
    dp[0]=a[0]==0?0:1;
    for(int i=1;i<1000002;i++){
    if(a[i]==0){dp[i]=dp[i-1];}
    else{
    if(a[i]>=i){dp[i]=1;}
    else{
    dp[i]=dp[i-a[i]-1]+1;
    }}
    if(dp[i]>=ans)ans=dp[i];
    }
        System.out.println(n-ans);
    }}
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;
        }
}
// Problem: 987_C. Three displays
// Time complexity: quadratic
import java.util.*;

import java.lang.*;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.*;
 
public class Main {
        
    public static void main(String[] args) throws Exception{
        FastReader sc=new FastReader(); 
        OutputStream outputStream = System.out;
        PrintWriter out = new PrintWriter(outputStream);
        int n=sc.nextInt();
        int[] font=new int[n];
        int[] cost=new int[n];
        for(int i=0;i<n;i++) {
            font[i]=sc.nextInt();
        
        }
        for(int i=0;i<n;i++) {
            cost[i]=sc.nextInt();
        }
        int[] dou= new int[n];
        for(int i=0;i<n;i++) {
            int min=Integer.MAX_VALUE;
            for(int j=0;j<i;j++) {
                if(font[j]<font[i]) {
                    if(min>cost[i]+cost[j]) {
                        min=cost[i]+cost[j];
                    }
                }
            }
            dou[i]=min;
        }
        int ans=Integer.MAX_VALUE;
        for(int i=0;i<n;i++) {
            int min=Integer.MAX_VALUE;
            for(int j=0;j<i;j++) {
                if(dou[j]!=Integer.MAX_VALUE && font[j]<font[i]) {
                    if(min>dou[j]+cost[i]) {
                        min=dou[j]+cost[i];
                    }
                }
            }
            if(min<ans) {
                ans=min;
            }
        }
        if(ans==Integer.MAX_VALUE) {
            System.out.println(-1);
        }
        else {
            System.out.println(ans);
        }
    }
}

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; 
    } 
}
// Problem: 992_C. Nastya and a Wardrobe
// Time complexity: logn
/* package codechef; // don't place package name! */

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

/* Name of the class has to be "Main" only if the class is public. */
public class Codechef
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner in=new Scanner(System.in);
		long x=in.nextLong();
		long k=in.nextLong();
		
		long mod=1000000007;
		long get=power(2,k,mod);
		long ans=((get%mod)*((2*x)%mod))%mod-get+1;
		if(ans<0)
		ans+=mod;
		if(x==0)
		ans=0;
		System.out.println(ans);
		
	}
	static long power(long x, long y, long p)
    {
        // Initialize result
        long res = 1;     
        
        // Update x if it is more  
        // than or equal to p
        x = x % p; 
     
        while (y > 0)
        {
            // If y is odd, multiply x
            // with result
            if((y & 1)==1)
                res = (res * x) % p;
     
            // y must be even now
            // y = y / 2
            y = y >> 1; 
            x = (x * x) % p; 
        }
        return res;
    }
}
// Problem: 908_C. New Year and Curling
// Time complexity: quadratic
 import java.util.Scanner;
    public class New_Year_and_Curling {
        static final double E = 0.00001;
 
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
 
            int n = sc.nextInt();
            int r = sc.nextInt();
            double[] y = new double[n];
            int arr[] = new int[n];
 
            for (int i = 0; i < n; i++) {
                arr[i] =sc.nextInt();
                double top = r; // if we make it 0 and subtract from the result will get WA (do not know why!!!)
                int x = arr[i];
                for(int  j =0 ;j<i;j++)
                {
                    if(Math.abs(arr[j] -x )<=2*r) {
 
                            top = Math.max(top  , y[j] + Math.sqrt((4 * r * r) - ((arr[j] - x) * (arr[j] - x))));
 
                    }
                }
                y[i] = top ;
                double res = y[i] ;
                System.out.print(res+" ");
            }
 
        }
 
    }
// Problem: 608_C. Chain Reaction
// Time complexity: nlogn

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.StringTokenizer;

public class ChainReaction implements Closeable {

  private InputReader in = new InputReader(System.in);
  private PrintWriter out = new PrintWriter(System.out);
  
  private class Beacon implements Comparable<Beacon> {
    private int position, range, score;

    private Beacon(int position, int range) {
      this.position = position;
      this.range = range;
    }

    public void setScore(int score) {
      this.score = score;
    }

    @Override
    public int compareTo(Beacon o) {
      return Integer.compare(this.position, o.position);
    }
  }

  public void solve() {
    int n = in.ni();
    if (n == 1) {
      out.println(0);
      return;
    }
    beacons = new ArrayList<>();
    for (int i = 0; i < n; i++) {
      beacons.add(new Beacon(in.ni(), in.ni()));
    }
    beacons.sort(Comparator.naturalOrder());
    for (int i = 1; i < n; i++) {
      int left = 0, right = i - 1, position = beacons.get(i).position, range = beacons.get(i).range;
      int leftmost = i;
      while (left <= right) {
        int mid = left + (right - left) / 2;
        if (position - range <= beacons.get(mid).position) {
          leftmost = Math.min(leftmost, mid);
          right = mid - 1;
        } else {
          left = mid + 1;
        }
      }
      beacons.get(i).setScore(i - leftmost);
    }
    dp = new Integer[n];
    int ans = Integer.MAX_VALUE;
    for (int i = n - 1; i >= 0; i--) {
      ans = Math.min(n - 1 - i + recurse(i), ans);
    }
    out.println(ans);
  }
  
  private List<Beacon> beacons;
  private Integer[] dp;
  
  private int recurse(int idx) {
    if (idx <= 0) return 0;
    
    if (dp[idx] != null) return dp[idx];
    
    int destroyed = beacons.get(idx).score;
    int ans = destroyed + recurse(idx - destroyed - 1);
    return dp[idx] = ans;
  }
  
  @Override
  public void close() throws IOException {
    in.close();
    out.close();
  }

  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 ni() {
      return Integer.parseInt(next());
    }

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

    public void close() throws IOException {
      reader.close();
    }
  }

  public static void main(String[] args) throws IOException {
    try (ChainReaction instance = new ChainReaction()) {
      instance.solve();
    }
  }
}
// Problem: 1010_A. Fly
// Time complexity: nlogn
import java.util.Scanner;
import java.util.Vector;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int a[] = new int[n];
        int b[] = new int[n];
        for (int i = 0; i < n; i++) a[i] = sc.nextInt();
        for (int i = 0; i < n; i++) b[i] = sc.nextInt();
        int c[] = new int[2 * n];
        c[0] = a[0];
        for (int i = 1; i < n; i++) {
            c[i * 2] = a[i];
            c[i * 2 - 1] = b[i];
            if (a[i] == 1 || b[i] == 1) {
                System.out.print(-1);
                System.exit(0);
            }
        }
        c[2 * n - 1] = b[0];
        if (a[0] == 1 || b[0] == 1) {
            System.out.print(-1);
            System.exit(0);
        }
        System.out.println(bin_search(c, m));
    }

    private static double bin_search(int[] c, int m) {
        double start = 0;
        double end = Integer.MAX_VALUE;
        double mid;
        while (start + 0.0000001 < end) {
            mid = (start + end) / 2;
            if (test(mid, m, c)) end = mid;
            else start = mid;
        }
        return end;
    }

    private static boolean test(double fuel, int m, int[] c) {
        for (int i = 0; i < c.length; i++) {
            fuel -= (m + fuel) / c[i];
            if (fuel < 0) {
                return false;
            }
        }
        return true;
    }
}
// Problem: 1054_A. Elevator or Stairs?
// Time complexity: constant
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main (String[] args) {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
            String parameterStringList[] = reader.readLine().split(" ");
            int x = Integer.parseInt(parameterStringList[0]);
            int y = Integer.parseInt(parameterStringList[1]);
            int z = Integer.parseInt(parameterStringList[2]);
            int t1 = Integer.parseInt(parameterStringList[3]);
            int t2 = Integer.parseInt(parameterStringList[4]);
            int t3 = Integer.parseInt(parameterStringList[5]);

            int T1 = Math.abs(x-y) * t1;
            int T2 = Math.abs(x-z) * t2 + 3*t3 + Math.abs(x-y) * t2;

            if(T2 <= T1) System.out.println("YES");
            else System.out.println("NO");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
// Problem: 909_A. Generate Login
// Time complexity: linear
import java.util.Scanner;

public class GenerateLogin {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String a = scan.next();
		String b = scan.next();
		char last = b.charAt(0);
		String ans = ""+a.charAt(0);
		for(int i = 1;i<a.length();i++){
			if(a.charAt(i)>=last)break;
			ans+=a.charAt(i);
		}
		ans+=last;
		System.out.println(ans);
	}

}