ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

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;
        cin >> n;
        vector<int> adj[n+1];
        map<int, int> hash;
        for(int i=0; i<n-1; i++) {
            int u, v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
            hash[u]++;
            hash[v]++;
        }
        if(n==2) {
            cout << 0 << "\n";
            continue;
        }
        int first = 0;
        int second = 0;
        int firstele=0, secele=0;
        
        for(auto it: hash) {
            if(it.second >= first) {
                second = first;
                first = it.second;
                secele = firstele;
                firstele = it.first;
            }
            else if(it.second > second) {
                second = it.second;
                secele = it.first;
            }
        }
        
        set<int> st;
        
        for(auto it: adj[firstele]) {
            st.insert(it);
        }
        
        for(auto it: hash) {
            if(it.second == second && st.find(it.first)==st.end()) {
                secele = it.first;
                second = it.second;
            } 
        }
        
        // cout << firstele << "-->" << hash[firstele] << "  " << secele << "-->" << hash[secele] << "\n";
        int flag = 0;
        int ans;
        for(auto it: adj[firstele]) {
            if(it == secele) flag = 1;
        }
        if(flag == 1) ans = hash[firstele] + hash[secele] - 2;
        else ans = hash[firstele] + hash[secele] - 1;
        cout << ans << "\n";
    }
    
    return 0;
}

Submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        set<pair<int, int> > edges;
        map<int, int> degree;
        for(int i=0; i<n-1; i++) {
            int u, v;
            cin >> u >> v;
            edges.insert({u, v});
            edges.insert({v, u});
            degree[u]++;
            degree[v]++;
        }
        int ans = 0;
        
        for(auto it: edges) {
            int deg1 = degree[it.first];
            int deg2 = degree[it.second];
            ans = max(deg1 + deg2 - 2, ans);
        }
        
        vector<pair<int, int>> v;
        for(auto it: degree) {
            v.push_back({it.second, it.first});
        }
        
        sort(v.begin(), v.end(), greater<pair<int, int>>());
        // for(auto it: edges) cout << it.first << " " << it.second << "\n";
        for(int i=0; i<v.size(); i++) {
            for(int j=i+1; j<v.size(); j++) {
                if(edges.find({v[i].second, v[j].second}) == edges.end()) {
                    // cout << "enter ";
                    int deg1 = degree[v[i].second];
                    int deg2 = degree[v[j].second];
                    ans = max(deg1 + deg2 - 1, ans);
                }
            }
        }
        
        cout << ans << "\n";
        
    }
    
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        set<pair<int, int> > edges;
        map<int, int> degree;
        for(int i=0; i<n-1; i++) {
            int u, v;
            cin >> u >> v;
            edges.insert({u, v});
            edges.insert({v, u});
            degree[u]++;
            degree[v]++;
        }
        int ans = 0;
        
        for(auto it: edges) {
            int deg1 = degree[it.first];
            int deg2 = degree[it.second];
            ans = max(deg1 + deg2 - 2, ans);
        }
        
        vector<pair<int, int>> v;
        for(auto it: degree) {
            v.push_back({it.second, it.first});
        }
        
        sort(v.begin(), v.end(), greater<pair<int, int>>());
        // for(auto it: edges) cout << it.first << " " << it.second << "\n";
        for(int i=0; i<n; i++) {
            for(int j=i+1; j<n; j++) {
                if(edges.find({v[i].second, v[j].second}) == edges.end()) {
                    // cout << "enter ";
                    int deg1 = v[i].first;
                    int deg2 = v[j].first;
                    ans = max(deg1 + deg2 - 1, ans);
                }
            }
        }
        
        cout << ans << "\n";
        
    }
    
    return 0;
}

Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        set<pair<int, int> > edges;
        map<int, int> degree;
        for(int i=0; i<n-1; i++) {
            int u, v;
            cin >> u >> v;
            edges.insert({u, v});
            edges.insert({v, u});
            degree[u]++;
            degree[v]++;
        }
        int ans = 0;
        
        for(auto it: edges) {
            int deg1 = degree[it.first];
            int deg2 = degree[it.second];
            ans = max(deg1 + deg2 - 2, ans);
        }
        
        vector<pair<int, int>> v;
        for(auto it: degree) {
            v.push_back({it.second, it.first});
        }
        
        sort(v.begin(), v.end(), greater<pair<int, int>>());
        // for(auto it: edges) cout << it.first << " " << it.second << "\n";
        for(int i=0; i<n; i++) {
            for(int j=i+1; j<n; j++) {
                if(edges.find({v[i].second, v[j].second}) == edges.end()) {
                    // cout << "enter ";
                    int deg1 = v[i].first;
                    int deg2 = v[j].first;
                    ans = max(deg1 + deg2 - 1, ans);
                    break;
                }
            }
        }
        
        cout << ans << "\n";
        
    }
    
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
using namespace std;
int main() {
    int t;
    cin >> t;
    while(t--) {
        int n;
        cin >> n;
        vector<int> adj[n+1];
        map<int, int> hash;
        for(int i=0; i<n-1; i++) {
            int u, v;
            cin >> u >> v;
            adj[u].push_back(v);
            adj[v].push_back(u);
            hash[u]++;
            hash[v]++;
        }
        int first = 0;
        int second = 0;
        int firstele=0, secele=0;
        
        for(auto it: hash) {
            if(it.second >= first) {
                second = first;
                first = it.second;
                secele = firstele;
                firstele = it.first;
            }
            else if(it.second > second) {
                second = it.second;
                secele = it.first;
            }
        }
        
        set<int> st;
        
        for(auto it: adj[firstele]) {
            st.insert(it);
        }
        
        for(auto it: hash) {
            if(it.second == second && st.find(it.first)==st.end()) {
                secele = it.first;
                second = it.second;
            } 
        }
        
        // cout << firstele << "-->" << hash[firstele] << "  " << secele << "-->" << hash[secele] << "\n";
        int flag = 0;
        int ans;
        for(auto it: adj[firstele]) {
            if(it == secele) flag = 1;
        }
        if(flag == 1) ans = hash[firstele] + hash[secele] - 2;
        else ans = hash[firstele] + hash[secele] - 1;
        cout << ans << "\n";
    }
    
    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

void solve(){
   
   ll n;
   cin >> n;
   
  // vector<ll> adj[n+1];
    vector<ll> indegree(n+1,0);
   
   for(int i=0;i<n-1;i++){
      ll x,y;
      cin >> x >> y;
      indegree[x]++;
   }
   
   int ans = 0;
   
   for(auto it:indegree){
     if(it == 2){
       ans++;
     }
   }
   
   
   cout << (2 * ans) << '\n';
   
}

int main(){
  ll t;
  cin >> t;
  while(t--){
    solve();
  }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

void solve(){
   
   ll n;
   cin >> n;
   
  // vector<ll> adj[n+1];
    vector<ll> indegree(n+1,0);
   
   for(int i=0;i<n-1;i++){
      ll x,y;
      cin >> x >> y;
      indegree[x]++;
   }
   
   int ans = 0;
   
   for(auto it:indegree){
     if(it == 2){
       ans++;
     }
   }
   
   
   cout << (2 * ans) << '\n';
   
}

int main(){
  ll t;
  cin >> t;
  while(t--){
    solve();
  }
}

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

void solve(){
   
   ll n;
   cin >> n;
   
  // vector<ll> adj[n+1];
    vector<ll> indegree(n+1,0);
   
   for(int i=0;i<n-1;i++){
      ll x,y;
      cin >> x >> y;
      indegree[x]++;
   }
   
   int ans = 0;
   
   for(auto it:indegree){
     if(it == 2){
       ans++;
     }
   }
   
   if(ans == 0){
     if(n <= 2){
        cout << 0 << endl;
        return;
     }else{
       cout << 1 << endl;
       return;
     }
   }
   cout << (2 * ans) << '\n';
   
}

int main(){
  ll t;
  cin >> t;
  while(t--){
    solve();
  }
}
Problem: 2063C - Remove Exactly Two
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 

void solve(){
   
   ll n;
   cin >> n;
   
  // vector<ll> adj[n+1];
    vector<ll> indegree(n+1,0);
   
   for(int i=0;i<n-1;i++){
      ll x,y;
      cin >> x >> y;
      indegree[x]++;
   }
   
   int ans = 0;
   
   for(auto it:indegree){
     if(it == 2){
       ans++;
     }
   }
   
   if(ans == 0){
     if(n <= 2){
        cout << 0 << endl;
        return;
     }else{
       cout << 1 << endl;
       return;
     }
   }
   cout << (2 * ans) << '\n';
   
}

int main(){
  ll t;
  cin >> t;
  while(t--){
    solve();
  }
}

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

void solve(){
   
   ll n;
   cin >> n;
   
   set<pair<ll,ll>> edges;
   vector<ll> indegree(n+1,0);
   
   for(int i=0;i<n-1;i++){
      ll x,y;
      cin >> x >> y;
      edges.insert({x,y});
      edges.insert({y,x});
      indegree[x]++;
      indegree[y]++;
   }
   
   ll ans = 0;
   
   // case 1 (if two nodes are adjacent to each other)
   
   for(auto edge:edges){
       ans = max(ans,indegree[edge.first] + indegree[edge.second] - 2);
   }
   
   
   // case 2 (if they are not adjacent)
   
   vector<pair<ll,ll>> v;
   
   for(int i=1;i<=n;i++){
      v.push_back({indegree[i],i});
   }
   
   sort(v.begin(),v.end(),greater<pair<ll,ll>>());
   
   for(int i=0;i<(int)v.size();i++){
      for(int j=i+1;j<(int)v.size();j++){
        if(edges.find({v[i].second,v[j].second}) == edges.end()){
            ans = max(ans,indegree[v[i].second] + indegree[v[j].second] - 1);
            break;
        }
      }
   }
   
   
   
   cout << ans << '\n';
   return;
}

int main(){
  ll t;
  cin >> t;
  while(t--){
    solve();
  }
}
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Runtime error on test 16):
#Kishore D code

# a=list(map(int,input().split()))
# b,c=map(int,input().split())
from collections import Counter
import heapq
from collections import defaultdict
from itertools import permutations

az=int(input())
for _  in range(az):
    s1=input()
    s2=input()
    s3=input()
    if len(s1)+len(s2)!=len(s3):
        print(-1)
    else:
        d={}
        def rec(ind1,ind2):
            
            if (ind1==len(s1) and ind2==len(s2)):
                return 0
            if (ind1,ind2) in d:
                return d[(ind1,ind2)]
            
            a=float('inf')
            
            if (ind1<len(s1)):
                a=min(a,rec(ind1+1,ind2)+(s1[ind1]!=s3[ind1+ind2]))
            if (ind2<len(s2)):
                a=min(a,rec(ind1,ind2+1)+(s2[ind2]!=s3[ind1+ind2]))
            #print(a)
            d[(ind1,ind2)]=a
            return a
        print(rec(0,0))


Submission (verdict: Runtime error on test 16):
from collections import defaultdict

az = int(input())
for _ in range(az):
    s1 = input()
    s2 = input()
    s3 = input()
    
    if len(s1) + len(s2) != len(s3):
        print(-1)
    else:
        d = {}

        def rec(ind1, ind2):
            # Base case: If both strings are fully processed
            if ind1 == len(s1) and ind2 == len(s2):
                return 0

            # Check memoized result
            if (ind1, ind2) in d:
                return d[(ind1, ind2)]

            a = float('inf')

            # Validity check and recursive calls
            if ind1 < len(s1) and ind1 + ind2 < len(s3):
                a = min(a, rec(ind1 + 1, ind2) + (s1[ind1] != s3[ind1 + ind2]))
            if ind2 < len(s2) and ind1 + ind2 < len(s3):
                a = min(a, rec(ind1, ind2 + 1) + (s2[ind2] != s3[ind1 + ind2]))

            # Store result in memoization dictionary
            d[(ind1, ind2)] = a
            return a

        print(rec(0, 0))
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Runtime error on test 16):
from collections import defaultdict

az = int(input())
for _ in range(az):
    s1 = input()
    s2 = input()
    s3 = input()
    
    if len(s1) + len(s2) != len(s3):
        print(-1)
    else:
        d = {}

        def rec(ind1, ind2):
            # Base case: If both strings are fully processed
            if ind1 == len(s1) and ind2 == len(s2):
                return 0

            # Check memoized result
            if (ind1, ind2) in d:
                return d[(ind1, ind2)]

            a = float('inf')

            # Validity check and recursive calls
            if ind1 < len(s1) and ind1 + ind2 < len(s3):
                a = min(a, rec(ind1 + 1, ind2) + (s1[ind1] != s3[ind1 + ind2]))
            if ind2 < len(s2) and ind1 + ind2 < len(s3):
                a = min(a, rec(ind1, ind2 + 1) + (s2[ind2] != s3[ind1 + ind2]))

            # Store result in memoization dictionary
            d[(ind1, ind2)] = a
            return a

        print(rec(0, 0))


Submission (verdict: Accepted):
az = int(input())
for _ in range(az):
    s1 = input()
    s2 = input()
    s3 = input()

    if len(s1) + len(s2) != len(s3):
        print(-1)
        continue

    # DP table to store minimum cost
    dp = [[float('inf')] * (len(s2) + 1) for _ in range(len(s1) + 1)]
    dp[0][0] = 0

    # Fill the DP table
    for i in range(len(s1) + 1):
        for j in range(len(s2) + 1):
            if i > 0:  # Taking a character from s1
                dp[i][j] = min(dp[i][j], dp[i - 1][j] + (s1[i - 1] != s3[i + j - 1]))
            if j > 0:  # Taking a character from s2
                dp[i][j] = min(dp[i][j], dp[i][j - 1] + (s2[j - 1] != s3[i + j - 1]))

    # Output the result for this test case
    print(dp[len(s1)][len(s2)])
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Runtime error on test 16):
#Kishore D code

# a=list(map(int,input().split()))
# b,c=map(int,input().split())
from collections import Counter
import heapq
from collections import defaultdict
from itertools import permutations

az=int(input())
for _  in range(az):
    s1=input()
    s2=input()
    s3=input()
    d={}
    def rec(ind1,ind2):
        
        if (ind1==len(s1) and ind2==len(s2)):
            return 0
        if (ind1,ind2) in d:
            return d[(ind1,ind2)]
        
        a=float('inf')
        b=float('inf')
        if (ind1<len(s1)):
            a=min(a,rec(ind1+1,ind2)+(s1[ind1]!=s3[ind1+ind2]))
        if (ind2<len(s2)):
            b=min(a,rec(ind1,ind2+1)+(s2[ind2]!=s3[ind1+ind2]))
        #print(a)
        d[(ind1,ind2)]=min(a,b)
        return min(a,b)
    print(rec(0,0))


Submission (verdict: Runtime error on test 16):
#Kishore D code

# a=list(map(int,input().split()))
# b,c=map(int,input().split())
from collections import Counter
import heapq
from collections import defaultdict
from itertools import permutations

az=int(input())
for _  in range(az):
    s1=input()
    s2=input()
    s3=input()
    d={}
    def rec(ind1,ind2):
        
        if (ind1==len(s1) and ind2==len(s2)):
            return 0
        if (ind1,ind2) in d:
            return d[(ind1,ind2)]
        
        a=float('inf')
        
        if (ind1<len(s1)):
            a=min(a,rec(ind1+1,ind2)+(s1[ind1]!=s3[ind1+ind2]))
        if (ind2<len(s2)):
            a=min(a,rec(ind1,ind2+1)+(s2[ind2]!=s3[ind1+ind2]))
        #print(a)
        d[(ind1,ind2)]=a
        return a
    print(rec(0,0))
Problem: 2050E - Three Strings
Language: Python 3

Previous submission (verdict: Runtime error on test 16):
#Kishore D code

# a=list(map(int,input().split()))
# b,c=map(int,input().split())
from collections import Counter
import heapq
from collections import defaultdict
from itertools import permutations

az=int(input())
for _  in range(az):
    s1=input()
    s2=input()
    s3=input()
    d={}
    def rec(ind1,ind2):
        
        if (ind1==len(s1) and ind2==len(s2)):
            return 0
        if (ind1,ind2) in d:
            return d[(ind1,ind2)]
        
        a=float('inf')
        
        if (ind1<len(s1)):
            a=min(a,rec(ind1+1,ind2)+(s1[ind1]!=s3[ind1+ind2]))
        if (ind2<len(s2)):
            a=min(a,rec(ind1,ind2+1)+(s2[ind2]!=s3[ind1+ind2]))
        #print(a)
        d[(ind1,ind2)]=a
        return a
    print(rec(0,0))


Submission (verdict: Runtime error on test 16):
#Kishore D code

# a=list(map(int,input().split()))
# b,c=map(int,input().split())
from collections import Counter
import heapq
from collections import defaultdict
from itertools import permutations

az=int(input())
for _  in range(az):
    s1=input()
    s2=input()
    s3=input()
    if len(s1)+len(s2)!=len(s3):
        print(-1)
    else:
        d={}
        def rec(ind1,ind2):
            
            if (ind1==len(s1) and ind2==len(s2)):
                return 0
            if (ind1,ind2) in d:
                return d[(ind1,ind2)]
            
            a=float('inf')
            
            if (ind1<len(s1)):
                a=min(a,rec(ind1+1,ind2)+(s1[ind1]!=s3[ind1+ind2]))
            if (ind2<len(s2)):
                a=min(a,rec(ind1,ind2+1)+(s2[ind2]!=s3[ind1+ind2]))
            #print(a)
            d[(ind1,ind2)]=a
            return a
        print(rec(0,0))
Problem: 2050E - Three Strings
Language: Python 3


Submission (verdict: Runtime error on test 16):
#Kishore D code

# a=list(map(int,input().split()))
# b,c=map(int,input().split())
from collections import Counter
import heapq
from collections import defaultdict
from itertools import permutations

az=int(input())
for _  in range(az):
    s1=input()
    s2=input()
    s3=input()
    d={}
    def rec(ind1,ind2):
        
        if (ind1==len(s1) and ind2==len(s2)):
            return 0
        if (ind1,ind2) in d:
            return d[(ind1,ind2)]
        
        a=float('inf')
        b=float('inf')
        if (ind1<len(s1)):
            a=min(a,rec(ind1+1,ind2)+(s1[ind1]!=s3[ind1+ind2]))
        if (ind2<len(s2)):
            b=min(a,rec(ind1,ind2+1)+(s2[ind2]!=s3[ind1+ind2]))
        #print(a)
        d[(ind1,ind2)]=min(a,b)
        return min(a,b)
    print(rec(0,0))
Problem: 2062C - Cirno and Operations
Language: C++20 (GCC 13-64)

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

#define ll long long
#define vi vector<int>
#define vil vector<long long>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MXL 1000000000000000000
#define PI (long double)2 * acos(0.0)
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl

void input(int i, int n, vector<int> &a) {
    for (int k = i; k < n; k++) cin >> a[k];
}

void inputl(int i, int n, vector<long long> &a) {
    for (int k = i; k < n; k++) cin >> a[k];
}

void print(vector<int> &a) {
    for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
    cout << endl;
}

void solve() {
    int n;
    cin>>n;
    vi a(n);
    input(0,n,a);
    if(n==1){
        cout<<a[0]<<endl;
        return;
    }
    ll ans = INT_MIN;
    ll sum = accumulate(all(a), 0LL);
    ans = max(ans, sum);
    for (int j = 0; j < n;j++){
        for (int i = 1; i < a.size(); i++)
        {
            a[i-1] = a[i] - a[i - 1];
        }
        a.pop_back();
        ans = max(abs(accumulate(all(a), 0LL)), ans);
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define vi vector<int>
#define vil vector<long long>
#define all(v) v.begin(), v.end()
#define MOD 1000000007
#define MXL 1000000000000000000
#define PI (long double)2 * acos(0.0)
#define NO cout << "NO" << endl
#define YES cout << "YES" << endl

void input(int i, int n, vector<int> &a) {
    for (int k = i; k < n; k++) cin >> a[k];
}

void inputl(int i, int n, vector<long long> &a) {
    for (int k = i; k < n; k++) cin >> a[k];
}

void print(vector<int> &a) {
    for (int i = 0; i < a.size(); i++) cout << a[i] << " ";
    cout << endl;
}

void solve() {
    int n;
    cin>>n;
    vi a(n);
    input(0,n,a);
    if(n==1){
        cout<<a[0]<<endl;
        return;
    }
    ll ans = MXL;
    ll sum = accumulate(all(a), 0LL);
    ans = max(ans, sum);
    for (int j = 0; j < n;j++){
        for (int i = 1; i < a.size(); i++)
        {
            a[i-1] = a[i] - a[i - 1];
        }
        a.pop_back();
        ans = max(abs(accumulate(all(a), 0LL)), ans);
    }
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}