codeparrot/codecomplex huggingface dataset:
// Problem: 1029_E. Tree with Small Distances
// Time complexity: linear

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

public class CF_1029E_Tree_with_Small_Distances {
	static ArrayList<Integer> adj[];
	static int dist[];
	static boolean visitParent[];
	static int ans=0;
 public static void main(String[] args) throws IOException {
	Scanner sc = new Scanner(System.in);
	int n  =sc.nextInt();
	adj=new ArrayList[n+1];
	dist = new int[n+1];
	visitParent = new boolean[n+1];
	for(int i=0;i<=n;i++) adj[i]=new ArrayList<Integer>();
	int max=0;
	//first contribution
	for(int i=1;i<n;i++){
		int u = sc.nextInt(),v=sc.nextInt();
		adj[u].add(v);
		adj[v].add(u);
	}
	dist[1]=0;
	dfs(1,1);
 System.out.println(ans);
 
 
 }
private static void dfs(int i , int j) {
	// TODO Auto-generated method stub
	boolean f = false;
	for(int k=0;k<adj[i].size();k++){
		int x = adj[i].get(k);
		if(x!=j){
			dist[x]=dist[i]+1;
			dfs(x,i);
			if(visitParent[x])
				f=true;
		}
	}
	//System.out.println(Arrays.toString(dist));
	if(dist[i]>2&&!visitParent[j]&&!f&&!visitParent[i]){
		visitParent[j]=true;
		ans++;
		for(int v=0;v<adj[i].size();v++){
			
		}
	}
	
}
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 double nextDouble() throws IOException
    {
        String x = next();
        StringBuilder sb = new StringBuilder("0");
        double res = 0, f = 1;
        boolean dec = false, neg = false;
        int start = 0;
        if(x.charAt(0) == '-')
        {
            neg = true;
            start++;
        }
        for(int i = start; i < x.length(); i++)
            if(x.charAt(i) == '.')
            {
                res = Long.parseLong(sb.toString());
                sb = new StringBuilder("0");
                dec = true;
            }
            else
            {
                sb.append(x.charAt(i));
                if(dec)
                    f *= 10;
            }
        res += Long.parseLong(sb.toString()) / f;
        return res * (neg?-1:1);
    }


    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: 1080_D. Olya and magical square
// Time complexity: logn
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

/**
 * @author Don Li
 */
public class OlyaAndMagicalSquare {
    void solve() {
        long[] dp = new long[32];
        dp[0] = 0;
        for (int i = 1; i < 32; i++) {
            dp[i] = 4 * dp[i - 1] + 1;
        }
        
        int T = in.nextInt();
        L:
        while (T-- > 0) {
            int n = in.nextInt(); long k = in.nextLong();
            
            if (n > 31) {
                out.println("YES " + (n - 1));
                continue;
            }
            
            long tot = 0;
            for (int a = n - 1; a >= 0; a--) {
                k -= (1L << (n - a)) - 1;
                if (k < 0) break;
                if (k == 0) {
                    out.println("YES " + a);
                    continue L;
                }
                long limit = (1L << (n + 1 - a)) - 3;
                if (k <= tot || dp[a] > 0 && (k - tot + dp[a] - 1) / dp[a] <= limit) {
                    out.println("YES " + a);
                    continue L;
                }
                tot += dp[a] * limit;
            }
            out.println("NO");
        }
    }
    
    public static void main(String[] args) {
        in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)));
        out = new PrintWriter(System.out);
        new OlyaAndMagicalSquare().solve();
        out.close();
    }
    
    static FastScanner in;
    static PrintWriter out;
    
    static class FastScanner {
        BufferedReader in;
        StringTokenizer st;
        
        public FastScanner(BufferedReader in) {
            this.in = in;
        }
        
        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(in.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        public int nextInt() {
            return Integer.parseInt(nextToken());
        }
        
        public long nextLong() {
            return Long.parseLong(nextToken());
        }
        
        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}
// Problem: 1093_C. Mishka and the Last Exam
// Time complexity: linear
import java.io.*;
import java.util.*;
public class Main{
public static void main(String[] args){
 Scanner s= new Scanner(System.in);
 int n=s.nextInt();StringBuilder sb=new StringBuilder();
 long[] a=new long[n/2];
 for(int i=0;i<n/2;i++){
                  a[i]=s.nextLong();
 }int j=0;long[] a2=new long[n/2];long[] a1=new long[n/2];
 a1[j]=a[a.length-1]/2;
 a2[j]=a[a.length-1]-a[a.length-1]/2;
 for(int i=(n-1)/2-1;i>=0;i--){
 //    a1[j]=a[i]/2;a2[j++]=a[i]-a[i]/2;
    long n1=a1[j];
    if((a[i]-n1)<a2[j]){
      a2[j+1]=a2[j++];a1[j]=a[i]-a2[j];                      
     }else{a1[++j]=n1;a2[j]=a[i]-n1;}
 }int k=0;//int[] ans=new int[2*n];
 for(int i=(n-1)/2;i>=0;i--)
   sb.append(a1[i]+" ");
  for(int i=0;i<n/2;i++)
    sb.append(a2[i]+" ");
            System.out.println(sb.toString());     
}
}
// Problem: 979_A. Pizza, Pizza, Pizza!!!
// Time complexity: constant
import java.util.*;
public class Pizza {

	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		long num = sc.nextLong() + 1;
		sc.close();
		System.out.println(num % 2 == 0 || num == 1 ? num / 2 : num);
	}
	
}
// Problem: 1017_A. The Rank
// Time complexity: linear
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Cf1017A {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int result = 1;
        int thomasSum = 0;
        StringTokenizer stk;
        stk = new StringTokenizer(br.readLine());
        int first = Integer.parseInt(stk.nextToken());
        int second = Integer.parseInt(stk.nextToken());
        int third = Integer.parseInt(stk.nextToken());
        int fourth = Integer.parseInt(stk.nextToken());
        thomasSum = first + second + third + fourth;
        int tmp;
        for (int i = 1; i < n; i++) {
            stk = new StringTokenizer(br.readLine());
            first = Integer.parseInt(stk.nextToken());
            second = Integer.parseInt(stk.nextToken());
            third = Integer.parseInt(stk.nextToken());
            fourth = Integer.parseInt(stk.nextToken());
            tmp = first + second + third + fourth;
            if (tmp > thomasSum)
                result++;
        }
        System.out.println(result);
    }
}
// Problem: 1023_B. Pair of Toys
// Time complexity: constant
import java.util.Scanner;

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

		long n = sc.nextLong();
		long k = sc.nextLong();
		System.out.println(solve(n, k));

		sc.close();
	}

	static long solve(long n, long k) {
		return Math.max(0, Math.min(n, k - 1) - ((k + 2) / 2) + 1);
	}
}
// Problem: 994_C. Two Squares
// Time complexity: constant
import java.awt.Point;
import java.io.*;
import java.math.BigInteger;
import java.util.*;

public class C {

	static StringBuilder st = new StringBuilder();

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

		Point [] square = new Point [4] ; 
		Point [] rotSquare = new Point[4] ; 
		
		for(int i = 0 ; i < 4 ;i++)
			square[i] = new Point(sc.nextInt() , sc.nextInt());
		
		for(int i = 0 ; i < 4 ;i++)
			rotSquare[i] = new Point(sc.nextInt() , sc.nextInt());
		
		boolean can = false ; 
		
		for(int x = -100 ; x <= 100 ; x++)
			for(int y = -100 ; y <= 100 ; y++)
				can |= inside(new Point(x , y), square) & inside(new Point (x , y), rotSquare);
				
			
		
		
		out.println(can ? "YES" : "NO");
		
		out.flush();
		out.close();

	}
	static int crossProduct(Point a , Point b)
	{
		int ans = a.x * b.y - a.y * b.x ; 
		
		if(ans < 0)return -1 ;
		if(ans == 0) return 0 ;
		return 1 ; 
	}
	
	static boolean inside(Point a , Point [] points)
	{
		boolean allPos = true ; 
		boolean allNeg = true ; 
		
		for(int i = 0 ; i < 4 ; i++)
		{
			Point v1 = new Point (points[i].x - a.x , points[i].y - a.y) ; 
			Point v2 = new Point (points[(i + 1) % 4].x - a.x , points[(i + 1) % 4].y - a.y) ; 
			
			allPos &= crossProduct(v1, v2) >= 0;
			allNeg &= crossProduct(v1, v2) <= 0;
		}
		return allPos | allNeg ; 
		
	}

	static class Scanner {
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in) {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() throws Exception {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());

			return st.nextToken();
		}

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

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

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

	}

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

}
// Problem: 1159_A. A pile of stones
// Time complexity: linear
    import jdk.nashorn.internal.objects.NativeArray;

    import javax.swing.JOptionPane ;
    import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
    import java.sql.SQLSyntaxErrorException;
    import java.util.Arrays;
    import java.util.Scanner;
    import java.util.Vector;


    import static jdk.nashorn.internal.objects.NativeArray.sort;
    import static jdk.nashorn.internal.runtime.ScriptObject.toPropertyDescriptor;

    public class Dialog1 {
        private static int n ;
        private static String s ;
        private static char[] a;
        public static void main(String[] args) {
            Scanner input = new Scanner(System.in);
            n = input.nextInt() ;
            s = input.next() ;
            a = s.toCharArray();
            for(int i = 0 ; i < 200 ; ++i) {
                int cur = i ;
                boolean fl = true ;
                for(int j = 0 ; j < n ; ++j) {
                    if(a[j] == '+')
                        ++cur ;
                    else
                        --cur ;
                    if(cur < 0)
                        fl = false ;
                }
                if(fl) {
                    System.out.print(cur);
                    return ;
                }
            }
        }
    }
// Problem: 1006_B. Polycarp's Practice
// Time complexity: nlogn
import java.io.*;
import java.util.*;

public class Solution {
    static class Data{
        int x,i;
        Data(int x,int i){
            this.x = x;
            this.i = i;
        }
    }
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split("\\s");
        int N = Integer.parseInt(s[0]);
        int K = Integer.parseInt(s[1]);
        s = br.readLine().split("\\s");
        int[] arr = new int[N];
        for(int i=0;i<N;++i) arr[i] = Integer.parseInt(s[i]);
        solve(N,K,arr);   
    }
    
    private static void solve(int N,int K,int[] arr){
       PriorityQueue<Data> pq = new PriorityQueue<Data>(2000,(a,b) -> a.x - b.x == 0 ? b.i - a.i : b.x - a.x);
       for(int i=0;i<arr.length;++i){
           pq.offer(new Data(arr[i],i));
       }
       
       int tot_sum = 0;
       List<Integer> ls = new ArrayList<>();
       Set<Integer> set = new HashSet<>();
       
       for(int i=1;i<=K;++i){
           Data t = pq.poll();
           tot_sum += t.x;
           set.add(t.i);
       }
       int last = -1;
       for(int i =0;i<arr.length;++i){
           if(set.contains(i)){
               K--;
               //System.out.println(i);
               if(K == 0) ls.add(arr.length-last-1);
               else ls.add(i-last);
               last = i;
           }
       }
       
       System.out.println(tot_sum);
       int size = ls.size();
       for(int i=0;i<size;++i){
           System.out.print(ls.get(i) + " ");
       }
    }
}
// Problem: 1068_A. Birthday
// Time complexity: constant
import java.util.*;
import java.math.*;
import java.io.*;

public class CF1068A {
	public CF1068A() {
		FS scan = new FS();
		long n = scan.nextLong(), m = scan.nextLong(), k = scan.nextLong(), l = scan.nextLong();
		long ceil = (k + l + m - 1) / m;
		if(k + l <= n && ceil * m <= n) System.out.println(ceil);
		else System.out.println(-1);
	}
	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		public String next() {
			while(!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch(Exception e) { e.printStackTrace(); }
			}
			return st.nextToken();
		}
		public int nextInt() { return Integer.parseInt(next()); }
		public long nextLong() { return Long.parseLong(next()); }
	}
	public static void main(String[] args) { new CF1068A(); }
}
// Problem: 991_A. If at first you don't succeed...
// Time complexity: constant
import java.util.*;

public class helloWorld 
{
	public static void main(String[] args) 
	{		
		Scanner in = new Scanner(System.in);
		int a = in.nextInt();
		int b = in.nextInt();
		int c = in.nextInt();
		int n = in.nextInt();

		int ans = n - (a + b - c);
		if(ans < 1 || a >= n || b >= n || c > a || c > b)
			ans = -1;
		
		System.out.println(ans);
		
		in.close();
	}
}
// Problem: 1179_A. Valeriy and Deque
// Time complexity: linear
import java.io.*;
import java.util.*;

public class Main
	{	
		class node{
		int data;
		node next;
		public node(int val){
			data=val;
			next=null;
		}
	}
	class linkedlist{
		node start;
		node end;
		int size;
		int turn;
		public linkedlist(){
			start=null;
			end=null;
			size=0;
		}
		void add(int val){
			if(size==0){
				node t=new node(val);
				start=t;
				end=t;
				size++;
			}
			else{
				node t=new node(val);
				end.next=t;
				end=end.next;
				size++;
			}
		}
		void myfunc(){
			if(start.data>start.next.data){
				// System.out.println("me ni hu");
				node t=new node(start.next.data);
				start.next=start.next.next;
				end.next=t;
				end=end.next;
			}
			else{
				// System.out.println("me hu");
				int t=start.data;
				start=start.next;
				add(t);
				size--;
			}
		}
		int findmax(){
			int m=0;
			node temp=start;
			for(int i=0;i<size;i++){
				if(temp.data>m){
					m=temp.data;
				}
				temp=temp.next;
			}
			return m;
		}
		void display(){
			node temp=start;
			for(int i=0;i<size;i++){
				System.out.print(temp.data+" ");
				temp=temp.next;
			}
			System.out.println("");
		}
	}
	linkedlist l;
	public Main(){
		l=new linkedlist();
	}
	public static void main(String [] argv) throws IOException
	{
		BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
		Main ma=new Main();
		String[] l1=in.readLine().split(" ");
		int n=Integer.parseInt(l1[0]);
		int q=Integer.parseInt(l1[1]);
		String[] ar=in.readLine().split(" ");
		int a1=Integer.parseInt(ar[0]);
		int b1=Integer.parseInt(ar[1]);
		for(int i=0;i<n;i++){
			ma.l.add(Integer.parseInt(ar[i]));
		}
		int m=ma.l.findmax();
		int[][] pair=new int[n][2];
		int t=0;
		for(int i=0;i<n;i++){
			if(ma.l.start.data==m)
				break;
			ma.l.myfunc();
			pair[t][0]=ma.l.start.data;
			pair[t][1]=ma.l.start.next.data;
			t++;
		}
		int rl[]=new int[n];
		node temp=ma.l.start;
		for(int i=0;i<n;i++){
			rl[i]=temp.data;
			temp=temp.next;
		}
		for(int i=0;i<q;i++){
			long a=Long.parseLong(in.readLine());
			if(a==1){
				System.out.println(a1 + " " + b1);
			}
			else{
				if(a<=t+1){
					System.out.println(pair[(int)(a-2)][0]+" "+pair[(int)(a-2)][1]);
				}
				else{
					if((a-t)%(n-1)==0){
						System.out.println(rl[0]+" "+rl[n-1]);
					}
					else{
						System.out.println(rl[0]+" "+rl[(int)((a-t)%(n-1))]);
					}
				}
			}
		}
	}
}
// Problem: 1086_A. Connect Three
// Time complexity: nlogn
import java.util.*;
import java.io.*;

public class Three{
    public static void main(String[] args) {
	Scanner in = new Scanner (System.in);
	PrintWriter out = new PrintWriter(System.out);

	pair[] points = new pair [3];
	for (int i = 0; i < 3; ++i) {
	    int x = in.nextInt();
	    int y = in.nextInt();
	    points[i] = new pair (x, y);
	}

	Arrays.sort(points);

	int MaxY = Math.max(Math.max(points[0].y, points[1].y), points[2].y);
	int MinY = Math.min(Math.min(points[0].y, points[1].y), points[2].y);

	out.println(MaxY - MinY + points[2].x - points[0].x + 1);
	for (int i = MinY; i <= MaxY; ++i)
	    out.println(points[1].x + " " + i);
	for (int i = points[0].x; i < points[1].x; ++i)
	    out.println(i + " " + points[0].y);
	for (int i = points[1].x + 1; i <= points[2].x; ++i)
	    out.println(i + " " + points[2].y);
	
	out.close();
    }

    public static class pair implements Comparable<pair> {
	int x, y;
	public pair (int x_, int y_) {
	    x = x_; y = y_;
	}

	@Override
	public int compareTo(pair o) {
	    return x - o.x;
	}
    }
}
// Problem: 1113_A. Sasha and His Trip
// Time complexity: constant
    import java.util.Scanner;

    public class Sasha1113A {

        static int solution(int n, int v){
            int count;
            if(v>=n)
                return n-1;
            else{
                count = (v-1) + ((n-v)*(n-v+1))/2;
            }
            return count;
        }

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

            System.out.print(solution(n, v));
        }
    }
// Problem: 1003_E. Tree Constructing
// Time complexity: quadratic
import java.io.*;
import java.lang.*;
public class CF1003E{
    public static void main(String args[]) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] s = br.readLine().split(" ");
        int n = Integer.parseInt(s[0]);
        int d = Integer.parseInt(s[1]);
        int k = Integer.parseInt(s[2]);
        StringBuffer sb = new StringBuffer();
        int[] rem = new int[n];
        int[] deg = new int[n];
        int i = 0;
        if(k == 1){
            if(n <= 2){

            }else{
                System.out.println("NO");
                return;
            }
        }
        for(i=0;i<d;i++){
            if(i>=n-1){
                System.out.println("NO");
                return;
            }
            sb.append((i+1) +" " + (i+2)+"\n");
            rem[i] = Math.min(i, d-i);
            deg[i]++;
            if(i+1<n)
            deg[i+1]++;
        }
        if(i<n){
            rem[i] = 0;
            deg[i] = 1;
        }
        i++;
        int j  = 0;
        for(;i<n;i++){
            //For all remaining Nodes
            while(true){
                if(j>=n){
                    System.out.println("NO");
                    return;
                }
                if(rem[j] > 0 && deg[j]<k){
                    deg[j]++;
                    rem[i] = rem[j] - 1;
                    sb.append((j+1)+" "+(i+1)+"\n");
                    deg[i]++;
                    break;
                }else{
                    j++;
                }
            }
        }
        System.out.println("YES");
        System.out.println(sb);
    }
}
// Problem: 1068_A. Birthday
// Time complexity: constant
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

  static class ABirthday {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
      long N = in.readLong(), M = in.readLong(), K = in.readLong(), L = in.readLong();

      long ans = ((L + K) - 1) / M + 1;
      if (ans * M > N || ans * M - K < L) out.printLine(-1);
      else out.printLine(ans);
    }
  }

  static class OutputWriter {
    private final PrintWriter writer;

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

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

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

    public void printLine(long i) {
      writer.println(i);
    }

    public void printLine(int i) {
      writer.println(i);
    }
  }

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

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

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

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

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

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

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