ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    
    ll ans = sum;
    for(int i = 1; i < n; i++){
        ll currSum = 0;
        for(int j = n - 1; j >= i; j--){
            v[j] = v[j] - v[j - 1];
            currSum += v[j];
        }
        //cout << currSum << " ";
        ans = max(sum, abs(currSum));
    }
    
    cout << ans << endl;
}

int main() {
    // Write C++ code here
    int tt;
    cin >> tt;
    while(tt--){
        solve();
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    
    ll ans = sum;
    for(int i = 1; i < n; i++){
        ll currSum = 0;
        for(int j = n - 1; j >= i; j--){
            v[j] = v[j] - v[j - 1];
            currSum += v[j];
        }
        //cout << currSum << " ";
        ans = max(sum, abs(currSum));
    }
    
    cout << ans << endl;
}

int main() {
    // Write C++ code here
    int tt;
    cin >> tt;
    while(tt--){
        solve();
    }

    return 0;
}

Submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    
    ll ans = sum;
    for(int i = 1; i < n; i++){
        ll currSum = 0;
        for(int j = n - 1; j >= i; j--){
            v[j] = v[j] - v[j - 1];
            currSum += v[j];
        }
        //cout << currSum << " ";
        ans = max(sum, max(-currSum, currSum));
    }
    
    cout << ans << endl;
}

int main() {
    // Write C++ code here
    int tt;
    cin >> tt;
    while(tt--){
        solve();
    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    
    ll ans = sum;
    for(int i = 1; i < n; i++){
        ll currSum = 0;
        for(int j = n - 1; j >= i; j--){
            v[j] = v[j] - v[j - 1];
            currSum += v[j];
        }
        //cout << currSum << " ";
        ans = max(sum, max(-currSum, currSum));
    }
    
    cout << ans << endl;
}

int main() {
    // Write C++ code here
    int tt;
    cin >> tt;
    while(tt--){
        solve();
    }

    return 0;
}

Submission (verdict: Accepted):
// Online C++ compiler to run C++ program online
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long

void solve(){
    ll n;
    cin >> n;
    vector<ll> v(n);
    ll sum = 0;
    
    for(int i = 0; i < n; i++){
        cin >> v[i];
        sum += v[i];
    }
    
    ll ans = sum;
    for(int i = 1; i < n; i++){
        ll currSum = 0;
        for(int j = n - 1; j >= i; j--){
            v[j] = v[j] - v[j - 1];
            currSum += v[j];
        }
        //cout << currSum << " ";
        ans = max(ans, max((-currSum), currSum));
    }
    
    cout << ans << endl;
}

int main() {
    // Write C++ code here
    int tt;
    cin >> tt;
    while(tt--){
        solve();
    }

    return 0;
}
Problem: 2061D - Kevin and Numbers
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 3):
import sys
from collections import Counter

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")


def solve(test_case):
    N,M = multi_int_input()
    A = list_input()
    B = list_input()
    
    a = Counter(A)
    b = Counter(B)
    for i,j in a.items():
        t = b[i]
        if t >= j:
            b[i] = t-j
            a[i] = 0
        else:
            b[i] = 0
            a[i] = j-t
        
    
    #print(a,b)
    A = []
    for i in sorted(a.keys()):
        A.extend([i]*a[i]) 
        
    B = []
    for i in sorted(b.keys()):
        B.extend([i]*b[i]) 
        
    N = len(A)
    M = len(B)
    #print(A,B)
    
    

    i = 0
    j = 0
    while i < N and j < M:
        if A[i] == B[j]:
            i += 1
            j += 1
        elif A[i] > B[j]:
            break
        else:
            sm = A[i]
            i += 1
            while i<N and sm < B[j] and A[i] - sm < 2:
                sm += A[i]
                i += 1
            if sm == B[j]:
                j += 1
            else:
                break
    
    if i == N and j == M:
        P1('Yes')
    else:
        P1('No')
                


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))
Problem: 2061D - Kevin and Numbers
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 3):
import sys
from collections import Counter

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")


def solve(test_case):
    N,M = multi_int_input()
    A = list_input()
    B = list_input()
    
    a = Counter(A)
    b = Counter(B)
    for i,j in a.items():
        t = b[i]
        if t >= j:
            b[i] = t-j
            a[i] = 0
        else:
            b[i] = 0
            a[i] = j-t
        
    
    #print(a,b)
    A = []
    for i in sorted(a.keys()):
        A.extend([i]*a[i]) 
        
    B = []
    for i in sorted(b.keys()):
        B.extend([i]*b[i]) 
        
    N = len(A)
    M = len(B)
    #print(A,B)
    
    

    i = 0
    j = 0
    while i < N and j < M:
        if A[i] == B[j]:
            i += 1
            j += 1
        elif A[i] > B[j]:
            break
        else:
            sm = A[i]
            i += 1
            while i<N and sm < B[j] and A[i] - sm < 2:
                sm += A[i]
                i += 1
            if sm == B[j]:
                j += 1
            else:
                break
    
    if i == N and j == M:
        P1('Yes')
    else:
        P1('No')
                


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))

Submission (verdict: Time limit exceeded on test 26):
import sys
from collections import Counter
from heapq import heapify, heappop, heappush

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")

def cud(n, d):
    if d[n]:
        d[n] -= 1
        return True
    if n == 1:
        return False
    return cud(n // 2, d) and cud((n // 2) + (n&1),d)
    

def solve(test_case):
    N,M = multi_int_input()
    A = list_input()
    B = list_input()
    
    b = sorted(B, reverse=True)
    
    '''print(heap)
    print(b)'''
    d = Counter(A)
    # 1 1 1
    # 3  
    for i in b:
        if not cud(i, d):
            P1('No')
            return
        
        
        
    #print(d)
    if any(d.values()):
        P1('No')
    else:
        P1('Yes')
        
                


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))
Problem: 2061D - Kevin and Numbers
Language: PyPy 3-64

Previous submission (verdict: Time limit exceeded on test 26):
import sys
from collections import Counter
from heapq import heapify, heappop, heappush

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")

def cud(n, d):
    if d[n]:
        d[n] -= 1
        return True
    if n == 1:
        return False
    return cud(n // 2, d) and cud((n // 2) + (n&1),d)
    

def solve(test_case):
    N,M = multi_int_input()
    A = list_input()
    B = list_input()
    
    b = sorted(B, reverse=True)
    
    '''print(heap)
    print(b)'''
    d = Counter(A)
    # 1 1 1
    # 3  
    for i in b:
        if not cud(i, d):
            P1('No')
            return
        
        
        
    #print(d)
    if any(d.values()):
        P1('No')
    else:
        P1('Yes')
        
                


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))

Submission (verdict: Accepted):
import sys
from collections import Counter
from heapq import heapify, heappop, heappush

input = sys.stdin.readline
output = sys.stdout.write
str_input = lambda: input().strip()
int_input = lambda: int(input())
multi_int_input = lambda: map(int, input().split())
list_input = lambda: list(map(int, input().split()))
P1 = lambda X: result_array.append(f"{X}\n")
P2 = lambda X,Y: result_array.append(f"{X} {Y}\n")
P3 = lambda X,Y,Z: result_array.append(f"{X} {Y} {Z}\n")
PA = lambda X: result_array.append(f"{' '.join(map(str,X))}\n")

def cud(n, d):
    if d.get(str(n),0):
        d[str(n)] -= 1
        return True
    if n == 1:
        return False
    return cud(n // 2, d) and cud((n // 2) + (n&1),d)
    

def solve(test_case):
    N,M = multi_int_input()
    A = list_input()
    B = list_input()
    
    b = sorted(B, reverse=True)
    
    d = {}
    for i in A:
        i = str(i)
        d[i] = d.get(i,0) + 1
        
    for i in b:
        if not cud(i, d):
            P1('No')
            return
        
        
        
    #print(d)
    if any(d.values()):
        P1('No')
    else:
        P1('Yes')
        
                


tc = 1
tc = int_input()
result_array = []
for test_case in range(1,tc+1):
    solve(test_case)
output(''.join(result_array))
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            s.insert(a[i]);
            freq[a[i]]++;
        }
        vector <pair<long int,int>> f;
        for (const auto& elem : freq) {
            f.push_back(elem); 
        }
        sort(f.begin(), f.end(), 
        [](const pair<long int, int>& a, const pair<long int, int>& b) {
            return a.second < b.second;  // Compare the second element of each pair
        });
        int index=0;
        for(int i=0;i<k;i++) {
            f[index].second--;
            if(f[index].second==0) {
                s.erase(f[index].first);
                index++;
            }
            if(index==n-1) {break;}
        }
        cout << s.size() << "\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        //set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            //s.insert(a[i]);
            freq[a[i]]++;
        }
        vector <pair<long int,int>> f;
        for (const auto& elem : freq) {
            f.push_back(elem); 
        }
        sort(f.begin(), f.end(), 
        [](const pair<long int, int>& a, const pair<long int, int>& b) {
            return a.second > b.second;
        });
        for(int i=0;i<k;i++) {
            int last=f.size();
            f[last-1].second--;
            if(f[last-1].second==0) {f.pop_back();}
        }
        cout << f.size() << "\n";
    }
}

Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        //set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            //s.insert(a[i]);
            freq[a[i]]++;
        }
        if(k>=n-1) {cout << "1\n";}
        else {
            vector <pair<long int,int>> f;
            for (const auto& elem : freq) {
                f.push_back(elem); 
            }
            sort(f.begin(), f.end(), 
            [](const pair<long int, int>& a, const pair<long int, int>& b) {
                return a.second > b.second;
            });
            for(int i=0;i<k;i++) {
                int last=f.size();
                f[last-1].second--;
                if(f[last-1].second==0) {f.pop_back();}
            }
            cout << f.size() << "\n";
        }
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            s.insert(a[i]);
            freq[a[i]]++;
        }
        vector <pair<long int,int>> f;
        for (const auto& elem : freq) {
            f.push_back(elem); 
        }
        sort(f.begin(), f.end(), 
        [](const pair<long int, int>& a, const pair<long int, int>& b) {
            return a.second < b.second;  // Compare the second element of each pair
        });
        int index=0;
        for(int i=0;i<k;i++) {
            f[index].second--;
            if(f[index].second==0) {
                s.erase(f[index].first);
                index++;
            }
            if(index==n-1) {break;}
        }
        cout << s.size() << "\n";
    }
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            s.insert(a[i]);
            freq[a[i]]++;
        }
        vector <pair<long int,int>> f;
        for (const auto& elem : freq) {
            f.push_back(elem); 
        }
        sort(f.begin(), f.end(), 
        [](const pair<long int, int>& a, const pair<long int, int>& b) {
            return a.second > b.second;
        });
        for(int i=0;i<k;i++) {
            int last=f.size();
            f[last-1].second--;
            if(f[last-1].second==0) {f.pop_back();}
        }
        cout << s.size() << "\n";
    }
}
Problem: 2057B - Gorilla and the Exam
Language: C++20 (GCC 13-64)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            s.insert(a[i]);
            freq[a[i]]++;
        }
        vector <pair<long int,int>> f;
        for (const auto& elem : freq) {
            f.push_back(elem); 
        }
        sort(f.begin(), f.end(), 
        [](const pair<long int, int>& a, const pair<long int, int>& b) {
            return a.second > b.second;
        });
        for(int i=0;i<k;i++) {
            int last=f.size();
            f[last-1].second--;
            if(f[last-1].second==0) {f.pop_back();}
        }
        cout << s.size() << "\n";
    }
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n,k;
        cin >> n >> k;
        long int a[n];
        map <long int,int> freq;
        //set <long int> s;
        for(int i=0;i<n;i++) {
            cin >> a[i];
            //s.insert(a[i]);
            freq[a[i]]++;
        }
        vector <pair<long int,int>> f;
        for (const auto& elem : freq) {
            f.push_back(elem); 
        }
        sort(f.begin(), f.end(), 
        [](const pair<long int, int>& a, const pair<long int, int>& b) {
            return a.second > b.second;
        });
        for(int i=0;i<k;i++) {
            int last=f.size();
            f[last-1].second--;
            if(f[last-1].second==0) {f.pop_back();}
        }
        cout << f.size() << "\n";
    }
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 3):
// time-limit: 3000
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    map<pair<int,int>,int> m2;
    for(auto i: m){
       int x = degree[i.first.first], y = degree[i.first.second];
       if(x>y)swap(x,y);
       m2[{x,y}]++;
    }
    int idx = distance(degree.begin(),max_element(degree.begin(), degree.end()));
    vector<int> degree2 = degree;
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m2[{y,x}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>=choice) {
            ans--;
        }
        cout<<ans<<"\n";
    }
    else {
        int ans = x + y -2;

        for(int i=0;i<n;i++){
            if(i==idx)continue;
            int res = degree2[i] + x -1 ;
            // cout<<i<<" "<<idx<<" "<<res<<"\n";
            if(m.find({min(i,idx),max(i,idx)})!=m.end()){
                res--;
            } 
            ans=max(ans,res);
        }
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    map<pair<int,int>,int> m2;
    for(auto i: m){
       int x = degree[i.first.first], y = degree[i.first.second];
       if(x>y)swap(x,y);
       m2[{x,y}]++;
    }
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        ll freq = count(degree.begin(),degree.end(),x);
        ll num = m2[{y,x}];
        int ans = 2*x - 1;
        ll choice = (1LL*(freq)*(freq-1))/2;
        if(num>=choice) {
            ans--;
        }
        cout<<ans<<"\n";
    }
    else {
        int freq = count(degree.begin(),degree.end(),y);
        int num = m2[{y,x}];
        int ans = y + x -1;
        int choice = freq;
        if(num>=choice) ans--;
        cout<<ans<<"\n";
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
// time-limit: 3000
#include<bits/stdc++.h>
using namespace std;

#define ll long long 
#define ar array

const int mod = 1e9+7;

void solve(){
    int n;cin>>n;
    vector<int> adj[n];
    vector<int> degree(n,0);
    map<pair<int,int>,int> m;

    for(int i=0;i<n-1;i++){
        int x,y;cin>>x>>y;
        x--,y--;
        if(x>y)swap(x,y);
        m[{x,y}]++;
        degree[x]++,degree[y]++;
    }
    sort(degree.begin(),degree.end());
    int x = degree[n-1], y = degree[n-2];
    if(x == 1)cout<<"0\n";
    else if(x == y){
        int freq = count(degree.begin(),degree.end(),x);
        int num = m[{x,y}];
        int ans = 2*x - 1;
        int choice = (1LL*(freq)*(freq-1))/2;
        if(num>choice)ans--;
        cout<<ans<<"\n";
    }
    else {
        int freq = count(degree.begin(),degree.end(),y);
        int num = m[{y,x}];
        int ans = y + x -1;
        int choice = freq;
        if(num>choice) ans--;
        if(y==1)ans--;
        cout<<ans<<"\n";
    }
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t;cin>>t;
    while(t--)
    solve();
        return 0;
}