ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: java

Solution 1 (runtime: 327 ms):
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;

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

    int t = sc.nextInt();
    for (int tc = 0; tc < t; ++tc) {
      int n = sc.nextInt();
      int[] a = new int[n];
      for (int i = 0; i < a.length; ++i) {
        a[i] = sc.nextInt();
      }

      System.out.println(solve(a));
    }

    sc.close();
  }

  static long solve(int[] a) {
    long[] values = Arrays.stream(a).asLongStream().toArray();

    long result = Arrays.stream(values).sum();
    while (values.length != 1) {
      long[] values_ = values;
      values =
          IntStream.range(0, values.length - 1)
              .mapToLong(i -> values_[i + 1] - values_[i])
              .toArray();

      result = Math.max(result, Math.abs(Arrays.stream(values).sum()));
    }

    return result;
  }
}


Solution 2 (runtime: 249 ms):
import java.util.*;
import java.io.*;
import java.math.*;

public class sub {

	// can i get expert by summer please

	static int mod = 998244353;

	public static void main(String args[]) throws IOException {
		int t = sc.nextInt();
		while (t-- > 0) {
			int n = sc.nextInt();
			ArrayList<Long> a = new ArrayList();
			if (n == 1) {
				out.println(sc.nextInt());
			} else {
				long ans = 0;
				for (int i = 0; i < n; i++) {
					a.add(sc.nextLong());
					ans+=a.get(i);
				}
				for (int i = 1; i < n; i++) {
					ArrayList<Long> copy = new ArrayList();
					for(int j = 0;j<a.size()-1;j++) {
						copy.add(a.get(j) - a.get(j + 1));
					}
					a=copy;
					long sum = 0;
					for (int j = 0; j < a.size(); j++) {
						sum += a.get(j);
					}
					if(sum<0) {
						Collections.reverse(a);
					}
					
					ans=Math.max(ans,Math.abs(sum));
				}
				out.println(ans);
			}
		}
		out.close();
	}

//	static long bincoef(int n, int k) {
//	    if (n < k) return 0L;
//	    return (p[n] * pow((p[n - k] * p[k]) % mod, mod - 2, mod)) % mod;
//	}

	static long pow(long a, long b, long mod) {
		if (b == 0) {
			return 1L;
		}
		long val = pow(a, b / 2, mod);
		if (b % 2 == 0) {
			return val * val % mod;
		}
		return val * val % mod * a % mod;
	}

	static long gcd(long a, long b) {
		if (b == 0) {
			return a;
		}
		return gcd(b, a % b);
	}

	static long lcm(long a, long b) {
		return a * b / gcd(a, b);
	}

	static Kattio sc = new Kattio();
	static PrintWriter out = new PrintWriter(System.out);

	static class Kattio {

		static BufferedReader r;
		static StringTokenizer st;

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

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

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

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

		public double nextDouble() {
			return Double.parseDouble(next());
		}
	}
}
Problem: 2052A - Adrenaline Rush
Language: java

Solution 1 (runtime: 359 ms):
import java.util.*;

public class Main {
    public static HashMap<Long,Long> map;
    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        int tes=1;
        label:while(tes-->0){
           int n=sc.nextInt(),i,j,ans=0;
           int a[]=new int[n+1];
           int idx[]=new int[n+1];
           for(i=1;i<=n;i++) a[i]=sc.nextInt();
           for(i=1;i<=n;i++) idx[a[i]]=i;
           StringBuilder sb=new StringBuilder();
           for(i=1;i<=n;i++){
                for(j=n;j>idx[i];j--){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(i+" "+a[j]+"\n");
                }
                for(j=idx[i]-1;j>=1;j--){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(i+" "+a[j]+"\n");
                }
                for(j=1;j<idx[i];j++){
                    if(a[j]>i) continue;
                    ans++;
                    sb.append(a[j]+" "+i+"\n");
                }
           }
           System.out.println(ans+"\n"+sb);
        }
    }
}

Solution 2 (runtime: 1983 ms):
import java.util.*;
public class AdrenalinRush{
public static void print(Object print){
    System.out.print(print);
}
public static void println(Object print){
    System.out.println(print);
}
public static void println(){
    System.out.println();
}
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] a = new int[n];
    int[] b = new int[n];
    HashMap<Integer, Integer> map = new HashMap<>();
    HashMap<Integer, Integer> map2 = new HashMap<>();
    ArrayList<int[]> arr = new ArrayList<>();
    int ans=0;
    for(int i=0; i<n; i++){
        a[i]=sc.nextInt();
        map.put(i, a[i]);
        map2.put(i+1, n-i-1);
        b[i]=n-i;
    }
    for(int i=1; i<=n; i++){
        for(int j=i+1; j<=n; j++){
            arr.add(new int[]{j, i});
            // println(j+" "+i);
        }
    }
    ans+=n*(n-1)/2;
    for(int j=n-1; j>=0; j--){
        int tar = map.get(j);
        int curr = map2.get(tar);
        for(int i=curr; i<j; i++){
            ans++;
            // println(b[i+1]+" "+b[i]);
            arr.add(new int[]{b[i+1], b[i]});
            int temp=b[i];
            b[i]=b[i+1];
            b[i+1]=temp;
            map2.put(b[i], i);
            map2.put(b[i+1], i+1);
        }
    }
    println(ans);
    for(int[] i: arr){
        println(i[0]+" "+i[1]);
    }

}
}
Problem: 2057C - Trip to the Olympiad
Language: java

Solution 1 (runtime: 249 ms):
import java.util.*;
public class triptotheolympiad {
    public static void main(String[] arg){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int testCase = 0; testCase < t; testCase++){
            long l = sc.nextLong();
            long r = sc.nextLong();

            String lBinary = Long.toBinaryString(l);
            String rBinary = Long.toBinaryString(r);

            int bit = -1;
            if(lBinary.length() < rBinary.length()){
                bit = rBinary.length() - 1;
            }else{
                //System.out.println(lBinary + " " + rBinary);
                for(int i = 0; i < rBinary.length(); i++){
                    if(lBinary.charAt(i) == rBinary.charAt(i)){
                        continue;
                    }else{
                        bit = rBinary.length() - i - 1;
                        break;
                    }
                }
            }

            long val = (long) Math.pow(2, bit);
            long firstNumber = (r / val) * val;

            long secondNumber = firstNumber - 1;
            long thirdNumber = 0;
            if(firstNumber == r){
                thirdNumber = r - 2;
            }else{
                thirdNumber = r;
            }

            System.out.println(firstNumber + " " + secondNumber + " " + thirdNumber);
        }

    }
}


Solution 2 (runtime: 265 ms):
#include<bits/stdc++.h>
using namespace std;

#define int long long

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vbl = vector<bool>;
using vpii = vector<pii>;
template<class T> using vv = vector<vector<T>>;

#define pb emplace_back
#define F first
#define S second
#define all(v) v.begin(), v.end()
#define siz(v) (int)(size(v))

#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (b); i--)
#define rept(a) rep(_, 1, a)

#define watch(x) cout << (#x) << ':' << (x) << '\n';
#define watch2(x, y) cout << (#x) << ':' << (x) << ',' << (#y) << ':' << (y) << '\n';

template<class T> bool ckmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

template<typename Ostream, typename ...Ts>
Ostream& operator<<(Ostream& os,  const pair<Ts...>& p){
	return os << '{' << p.first << ',' << p.second << '}';
}
template<typename Ostream, typename Cont>
typename enable_if<is_same<Ostream,ostream>::value, Ostream&>::type operator<<(Ostream& os,  const Cont& v){
	for (auto &x : v) os << x << ' ';
	return os;
}

const int inf = 1e9;
const ll llinf = 4e18;

void orz()
{
    int l, r; cin >> l >> r;
    rrep(i, 30, 0){
        if ((l>>i)^(r>>i)){
            cout << (1<<i) << ' ' << ((1<<i)-1) << ' ' << ((1<<i)-2 < l ? (1<<i)+1 : (1<<i)-2) << '\n';
            return;
        }
    }
}

int32_t main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    cin.exceptions(cin.failbit);

    int t = 1; cin >> t;
    while (t--) orz();

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: java

Solution 1 (runtime: 1436 ms):
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int T = sc.nextInt();
        while (T-- > 0) {
            int n = sc.nextInt();
            int m = sc.nextInt();
            int[] a = new int[n];
            for (int i = 0; i < n; i++) a[i] = sc.nextInt();
            int[] b = new int[m];
            for (int i = 0; i < m; i++) b[i] = sc.nextInt();

            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());
            for (int val : b) pq.offer(val);

            Map<Integer, Integer> freqMap = new HashMap<>();
            for (int val : a) freqMap.put(val, freqMap.getOrDefault(val, 0) + 1);

            boolean isValid = true;

            for (int i = 0; i < n - m + n; i++) {
                if (pq.isEmpty()) {
                    isValid = false;
                    break;
                }

                int val = pq.poll();
                if (freqMap.getOrDefault(val, 0) == 0) {
                    pq.offer(val / 2);
                    pq.offer((val + 1) / 2);
                } else {
                    freqMap.put(val, freqMap.get(val) - 1);
                }
            }

            System.out.println(isValid && pq.isEmpty() ? "Yes" : "No");
        }
        sc.close();
    }
}

Solution 2 (runtime: 1530 ms):
import java.util.*;



public class hello {

    

    public static boolean f(int n,TreeMap<Integer,Integer> tm){

        if(n==0)return false;

        else if(tm.containsKey(n)){

            if(tm.get(n)==1){

                tm.remove(n);

            }else{

                tm.put(n, tm.get(n)-1);

            }

            return true;

        }else if(n>1){

            return f(n/2,tm) && f((n+1)/2,tm);

        }else return false;

    }

    

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int t = sc.nextInt();

        while (t-- > 0) {

            int a = sc.nextInt();

            int b = sc.nextInt();

            int[] arr = new int[a];

            int[] brr = new int[b];

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

                arr[i] = sc.nextInt();

            }

            for(int j=0;j<b;j++){

                brr[j] = sc.nextInt();

            }



            PriorityQueue<Integer> pq = new PriorityQueue<>(Collections.reverseOrder());



            for(int i:brr)pq.add(i);



            TreeMap<Integer,Integer> tm = new TreeMap<>();

            for(int i:arr){

                tm.put(i,tm.getOrDefault(i, 0)+1);

            }

            boolean flag = true;

            while(!pq.isEmpty()){

                int x = pq.poll();

                if(f(x,tm))continue;

                else {

                    flag = false;

                    break;

                }

            }

            if(flag && tm.size()==0 && pq.isEmpty()) System.out.println("Yes");

            else System.out.println("No");

        }

        sc.close();

    }

}
Problem: 2050D - Digital string maximization
Language: java

Solution 1 (runtime: 312 ms):
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0){
            String s=sc.next();
            char[] res=s.toCharArray();
            for(int i=1;i<s.length();i++){
                if(res[i]>res[i-1]){
                    while(i>0 && res[i]>res[i-1] && res[i]-res[i-1]>1){
                        res[i]--;
                        char temp=res[i];
                        res[i]=res[i-1];
                        res[i-1]=temp;
                        i--;
                    }
                }
            }
            String str=new String(res);
            System.out.println(str);
        }
        sc.close();
    }
}

Solution 2 (runtime: 858 ms):
import java.util.Arrays;
import java.util.Scanner;
import java.util.Stack;

public class Solution {

    static void tc(Scanner sc){
        String str = sc.next();
        Stack<Integer> ans = new Stack<>();
        for(int i=0; i<str.length(); i++){
            int x = str.charAt(i)-'0';
            
            Stack<Integer> temp = new Stack<>();
            while (ans.isEmpty()==false && ans.peek() < x-1) {
                x--;
                temp.add(ans.pop());
            }
            ans.add(x);
            while (temp.isEmpty()==false) {
                ans.add(temp.pop());
            }
        }
        for(int x:ans){
            System.out.print(x);
        }
        System.out.println();
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t-- > 0) {
            // System.out.println(t);
            tc(sc);
        }
        sc.close();
    }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 687 ms):


import java.util.*;



public class AS {



    public static void main(String[] args) {



        Scanner s = new Scanner(System.in);



        int t = s.nextInt();

        s.nextLine();



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



            int c = s.nextInt();

            s.nextLine();



            int[] arr = new int[c];



            for (int j = 0; j < c; j++) {



                arr[j] = s.nextInt();

            }

            s.nextLine();



            boolean flag = true;

            for (int j = 0; j < c - 1; j++) {



                int temp = Math.min(arr[j], arr[j + 1]);

                arr[j] -= temp;

                arr[j + 1] -= temp;



                if (arr[j] > 0) {

                    flag = false;

                    break;

                }

            }



            if (flag)

                System.out.println("yes");

            else

                System.out.println("no");



        }



        s.close();

    }

}

Solution 2 (runtime: 765 ms):


import java.util.Deque;

import java.util.LinkedList;

import java.util.Scanner;

import javax.print.DocPrintJob;













public class SumTo {

    private static boolean  Solution(int[]a,int n){

        Deque<Integer>dq=new LinkedList<>();

        for(int num:a){

            dq.add(num);

        }

        while(dq.size()>1){

            if(((LinkedList<Integer>) dq).get(0)>((LinkedList<Integer>) dq).get(1)){

                return false;

            }

            else if(((LinkedList<Integer>) dq).get(0)<((LinkedList<Integer>) dq).get(1)){

                int first = dq.removeFirst();

                int second = dq.removeFirst();

                dq.addFirst(second - first);



            }else{

                dq.pollFirst();

                dq.pollFirst();

            }

        }

        return true;

        

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t=sc.nextInt();

        while(t-->0){

            int n=sc.nextInt();

            int[]a=new int[n];

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

                a[i]=sc.nextInt();

            }

            System.out.println(Solution(a,n)?"Yes":"NO");

        }

    }

}
Problem: 2050C - Uninteresting Number
Language: java

Solution 1 (runtime: 328 ms):
import java.util.*;
public class Main
{
	public static void main(String[] args) {
	    Scanner sc=new Scanner(System.in);
	    int t=sc.nextInt();
	    while(t-->0){
	        String n=sc.next();
	        int s=0;
	        HashMap<Integer,Integer>hm=new HashMap();
	        for(int i=0;i<n.length();i++){
	            s+=n.charAt(i)-'0';
	            if((n.charAt(i)-'0')==3)
	            hm.put(6,hm.getOrDefault(6,0)+1);
	            else if((n.charAt(i)-'0')==2)
	            hm.put(2,hm.getOrDefault(2,0)+1);

	            
	        }

            int f=0;
	        if(s%9==0)
	        		System.out.println("YES");
	        		else{
	        		    for(int i=0;i<=hm.getOrDefault(2,0);i++){
	        		        if(f==1)
	        		        break;
	        		        
	        		        for(int j=0;j<=hm.getOrDefault(6,0);j++){
	        		            if((s+i*2+j*6)%9==0)
	        		            {
	        		                f=1;
	        		                break;
	        		            }
	        		        }
	        		    }
	        		    System.out.println((f==1)?"YES":"NO");
	                    }



	        
	    }
	}
}


Solution 2 (runtime: 311 ms):
import java.util.*;

public class Main {
    static Scanner in;

    public static void main(String[] args) {
        int t = 1;
        in = new Scanner(System.in);
        t = in.nextInt();
        while (t-- > 0) {
            solve();
        }
        in.close();
    }

    static void solve() {
        String n = in.next(); 
        int sum = 0, two = 0, three = 0;

        for (char c : n.toCharArray()) {
            int digit = c - '0'; 
            sum += digit;
            if (digit == 2) two++;
            if (digit == 3) three++;
        }

        int remain = 9-sum % 9;
        if (remain == 9 || canReach(remain, two, three)) System.out.println("YES");
        else System.out.println("NO");
        return;
    }

    public static boolean canReach(int r, int maxTwo, int maxThree) {
        for (int x = 0; x <= maxTwo; x++) {
            for (int y = 0; y <= maxThree; y++) {
                if ((2 * x + 6 * y) % 9 == r) {
                    return true;
                }
            }
        }
        return false;
    }

    static int[] readArray(int n) {
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) arr[i] = in.nextInt();
        return arr;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: java

Solution 1 (runtime: 562 ms):
// Gorilla and the exam

import java.util.*;

public class _2057B {
    public static void sovle(int k, int arr[]) {
        Arrays.sort(arr);
        List<Integer> cnt = new ArrayList<>();
        cnt.add(1);
        for (int i = 1; i < arr.length; i++) {
            if (arr[i] == arr[i - 1]) {
                cnt.set(cnt.size() - 1, cnt.get(cnt.size() - 1) + 1);
            } else {
                cnt.add(1);
            }
        }

        Collections.sort(cnt);
        int m = cnt.size();
        for (int i = 0; i < m - 1; i++) {
            if (cnt.get(i) > k) {
                System.out.println(m - i);
                return;
            }
            k -= cnt.get(i);
        }
        System.out.println(1);
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        while (t > 0) {
            int n = sc.nextInt();
            int k = sc.nextInt();

            int arr[] = new int[n];

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

            sovle(k, arr);

            t--;
        }
        sc.close();
    }
}

Solution 2 (runtime: 562 ms):
import java.util.*;
public class Main{
    public static void main(String args[])
    {
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0) {
            int n=sc.nextInt();
            int k=sc.nextInt();
            int[] a=new int[n];
            HashMap<Integer,Integer> mp=new HashMap<>();
            for(int i=0;i<n;i++)
            {
                a[i]=sc.nextInt();
                if(!mp.containsKey(a[i]))
                    mp.put(a[i],1);
                else {
                    mp.put(a[i], mp.get(a[i]) + 1);
                }
            }
            ArrayList<Integer> l=new ArrayList<>();
            for(int e:mp.values())
            {
                l.add(e);
            }
            Collections.sort(l);
            int ans=l.size();
            for(int i:l)
            {
                k-=i;
                if(k<0)
                    break;
                ans--;
            }
            if(ans<1)
                System.out.println(1);
            else System.out.println(ans);

        }

    }
}
Problem: 2060D - Subtract Min Sort
Language: java

Solution 1 (runtime: 702 ms):
import java.util.*;
         
public class CompCode {
    static Scanner sc = new Scanner(System.in);
 
    static int MOD = 998244353; 
 
    public static void main(String... args) {
        int tc = sc.nextInt();
        while(tc-- > 0) {
            int n = sc.nextInt();
            int[] a = new int[n];
            int i;
            for(i=0; i<n; i++) {
                a[i] = sc.nextInt();
            }

            if(n==2) {
                if(a[1]>=a[0]) {
                    System.out.println("YES");
                } else {
                    System.out.println("NO");
                }
                continue;
            }

            for(i=1; i<n-1; i++) {
                if(a[i]<a[i-1]) {
                    break;
                }
                if(a[i]-a[i-1] > a[i+1]) {
                    break;
                }
                a[i] = a[i]-a[i-1];
                // System.out.print(a[i]+ " ");
            }
            if(i==n-1) {
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        } 
    }
}

Solution 2 (runtime: 639 ms):
import java.util.Scanner;



public class Main {

    static  boolean check(int[] arr){

        for (int i = 0; i < arr.length-1; i++) {

            if (arr[i]>arr[i+1]) return  false;

        }

        return true;

    }

    public static void main(String[] args) {

        Scanner sc=new Scanner(System.in);

        int t = sc.nextInt();

        while(t-->0) {

            int n = sc.nextInt();

            int[] a =new int[n];

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

                a[i]= sc.nextInt();

            }

            boolean flag=false;

            int i =0;

            while (i< n-1){

                int min=Math.min(a[i],a[i+1]);

                a[i]=a[i]-min;

                a[i+1]=a[i+1]-min;

                i++;

            }

            if (check(a)) System.out.println("YES");

            else System.out.println("NO");

        }

    }

}