ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: C++20 (GCC 13-64)


Submission (verdict: Memory limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;

 

int main(){

    ios::sync_with_stdio(false);

    cin.tie(nullptr);

    

    int t;

    cin >> t;

    while(t--){

        int n, m;

        cin >> n >> m;

        vector<long long> a(n), b(m);

        long long sumA = 0, sumB = 0;

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

            cin >> a[i];

            sumA += a[i];

        }

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

            cin >> b[i];

            sumB += b[i];

        }

 

        // The sum must be equal.

        if(sumA != sumB){

            cout << "No\n";

            continue;

        }

 

        // Build a frequency map for numbers in a.

        unordered_map<long long, long long> freq;

        freq.reserve(n * 2);

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

            freq[a[i]]++;

        }

 

        // Use a max-heap (priority queue) to simulate splitting.

        priority_queue<long long> pq;

        for(auto x : b)

            pq.push(x);

 

        bool possible = true;

        long long countUsed = 0; // count how many numbers from a we have matched.

        while(!pq.empty() && possible){

            long long x = pq.top();

            pq.pop();

            if(freq[x] > 0){

                freq[x]--;

                countUsed++;

            } else {

                if(x == 1){

                    possible = false;

                    break;

                }

                // Split x into two parts.

                long long left = x / 2;

                long long right = x - left;

                pq.push(left);

                pq.push(right);

            }

        }

 

        // All a's must be matched.

        if(countUsed != n)

            possible = false;

 

        cout << (possible ? "Yes" : "No") << "\n";

    }

    return 0;

}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        int sum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum += v[i];
        }
        int ans = sum;
        while(v.size()>1){
            //two options 
            vector<int>temp1;
            for(int i=1;i<v.size();i++){
                temp1.push_back(v[i]-v[i-1]);
            }
            if(temp1.size()>1)ans = max(ans,abs(temp1.back()-temp1.front()));
            else ans = max(ans,abs(temp1.front()));
            v.clear();
            for(auto it:temp1){
                v.push_back(it);
            }
        }
        cout<<ans<<"\n";

    }

    return 0;
}

Submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        int sum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum += v[i];
        }
        int ans = sum;
        while(v.size()>1){
            //two options 
            vector<int>temp1;
            for(int i=1;i<v.size();i++){
                temp1.push_back(v[i]-v[i-1]);
            }
            if(temp1.size()>1)ans = max(ans,abs(temp1.back()-temp1.front()));
            else ans = max(ans,abs(temp1.front()));
            v.clear();
            for(auto it:temp1){
                v.push_back(it);
            }
        }
        ans = max(ans,v[0]);
        cout<<ans<<"\n";

    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        int sum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum += v[i];
        }
        int ans = sum;
        while(v.size()>1){
            //two options 
            vector<int>temp1;
            for(int i=1;i<v.size();i++){
                temp1.push_back(v[i]-v[i-1]);
            }
            if(temp1.size()>1)ans = max(ans,abs(temp1.back()-temp1.front()));
            else ans = max(ans,abs(temp1.front()));
            v.clear();
            for(auto it:temp1){
                v.push_back(it);
            }
        }
        ans = max(ans,abs(v[0]));
        cout<<ans<<"\n";

    }

    return 0;
}

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

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        int sum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum += v[i];
        }
        int ans = sum;
        while(v.size()>1){
            //two options 
            vector<int>temp1;
            for(int i=1;i<v.size();i++){
                temp1.push_back(v[i]-v[i-1]);
            }
            ans = max(ans,abs(v.front()-v.back()));
            v.clear();
            for(auto it:temp1){
                v.push_back(it);
            }
        }
        cout<<ans<<"\n";

    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        int sum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum += v[i];
        }
        int ans = sum;
        while(v.size()>1){
            //two options 
            vector<int>temp1;
            for(int i=1;i<v.size();i++){
                temp1.push_back(v[i]-v[i-1]);
            }
            if(temp1.size()>1)ans = max(ans,abs(temp1.back()-temp1.front()));
            else ans = max(ans,abs(temp1.front()));
            v.clear();
            for(auto it:temp1){
                v.push_back(it);
            }
        }
        cout<<ans<<"\n";

    }

    return 0;
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 6):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        int sum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum += v[i];
        }
        int ans = sum;
        while(v.size()>1){
            //two options 
            vector<int>temp1;
            for(int i=1;i<v.size();i++){
                temp1.push_back(v[i]-v[i-1]);
            }
            if(temp1.size()>1)ans = max(ans,abs(temp1.back()-temp1.front()));
            else ans = max(ans,abs(temp1.front()));
            v.clear();
            for(auto it:temp1){
                v.push_back(it);
            }
        }
        ans = max(ans,v[0]);
        cout<<ans<<"\n";

    }

    return 0;
}

Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int mod = 998244353;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        int n;cin>>n;
        vector<int>v(n);
        int sum = 0;
        for(int i=0;i<n;i++){
            cin>>v[i];
            sum += v[i];
        }
        int ans = sum;
        while(v.size()>1){
            //two options 
            vector<int>temp1;
            for(int i=1;i<v.size();i++){
                temp1.push_back(v[i]-v[i-1]);
            }
            if(temp1.size()>1)ans = max(ans,abs(temp1.back()-temp1.front()));
            else ans = max(ans,abs(temp1.front()));
            v.clear();
            for(auto it:temp1){
                v.push_back(it);
            }
        }
        ans = max(ans,abs(v[0]));
        cout<<ans<<"\n";

    }

    return 0;
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;   
using namespace std;
typedef long long ll;

//
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
typedef tree<pair<ll,ll>, null_type, less<pair<ll,ll>>, rb_tree_tag, tree_order_statistics_node_update> ordered_pset;
//
#define ld long double
#define pb push_back
/* You may enter other macros defined by you */
#define vi vector<ll>
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rep1(i,a,b) for(ll i=a;i<=b;i++)
#define ff first
#define ss second
#define pll pair<ll, ll>
#define vpll vector<pair<ll,ll> >
#define vvl vector<vector<ll> >
#define printv(a) for(auto x: a){cout<<x<<" ";}cout<<"\n";
#define input(a,n) rep(i,0,n)cin>>a[i];
#define input1(a,n) rep1(i,1,n)cin>>a[i];
#define mp make_pair

#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define minv(a) *min_element(all(a))
#define maxv(a) *max_element(all(a))
void yes() { cout<<"YES\n"; }
void no() { cout<<"NO\n"; }
// random number generator
mt19937 rnd(593); 

  
const ll mod = 1e9+7;
//const ll mod = 998244353;
const ld PI = acos(-1);
const ld EPS = 1e-9;
const ll INF = 1e18;
const ll N=3e5+10;
inline int add(int x, int y) { int ret = x + y; if (ret >= mod) ret -= mod; return ret; }
inline int sub(int x, int y) { int ret = (x - y); if (ret < 0) ret += mod; return ret; }
inline int mul(int x, int y) { int ret = (1ll * x * y) % mod; return ret; }
int exp(int a, int b) { int ret = 1; while (b) { if (b & 1) ret = mul(ret, a); a = mul(a, a); b >>= 1;} return ret; }
int dv(int a, int b) { int ret = exp(b, mod - 2); ret = mul(ret, a); return ret; }

vvl adj;

multiset<ll> s;

ll ans=-1;

void dfs(ll u,ll e){
  s.erase(s.find(adj[u].size()));
  if(u!=e){
    s.erase(s.find(adj[e].size()));
  }
  for(auto x: adj[u]){
    if(x==e)continue;
    ans=max(ans,adj[u].size()+adj[x].size()-2ll);
    s.erase(s.find(adj[x].size()));
  }
  if(s.size()!=0){
    ans=max(ans,adj[u].size()+*s.rbegin()-1ll);
  }

  s.insert(adj[u].size());
  if(u!=e)
  s.insert(adj[e].size());
  for(auto x: adj[u]){
    if(x==e)continue;
    s.insert(adj[x].size());
  }
  for(auto x: adj[u]){
    if(x==e)continue;
    dfs(x,u);
  }
}


void solve(){   
  ll n;cin>>n;
  s.clear();
  adj.assign(n+1,vi(0));
  rep(i,0,n-1){
    ll u,v;cin>>u>>v;
    adj[u].pb(v);
    adj[v].pb(u);
  }
  rep1(i,1,n){
    s.insert(adj[i].size());
  }
  dfs(1,1);
  cout<<ans<<endl;

}
    
int main(){

  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int t;
  cin>>t;while(t--)
    solve();
  cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";

  return 0; 
}
Problem: 2050C - Uninteresting Number
Language: Python 3

Previous submission (verdict: Wrong answer on test 1):
t = int(input())

def solve():
    num = [int(x) for x in input()]
    
    num_sum = sum(num)
    need = 9 - (num_sum % 9)
    
    count3 = num.count(3)
    count2 = num.count(2)
    
    for i in range(count2+1):
        for j in range(count3+1):
            if (i * 2 + j * 6) - need % 9 == 0:
                print("YES")
                return
    
    print("NO")
    return

for _ in range(t):
    solve()

Submission (verdict: Accepted):
t = int(input())

def solve():
    num = [int(x) for x in input()]
    
    num_sum = sum(num)
    need = 9 - (num_sum % 9)
    
    count3 = num.count(3)
    count2 = num.count(2)
    
    for i in range(count2+1):
        for j in range(count3+1):
            if ((i * 2 + j * 6) - need) % 9 == 0:
                print("YES")
                return
    
    print("NO")
    return

for _ in range(t):
    solve()
Problem: 2050C - Uninteresting Number
Language: Python 3

Previous submission (verdict: Time limit exceeded on test 3):
t = int(input())

def rec(count3, count2, have, need):
    if (have - need) % 9 == 0:
        return True
        
    if count3 == 0 and count2 == 0:
        return False
    
    if count3 == 0 and count2 > 0:
        return rec(count3, count2 - 1, have + 2, need)
    if count3 > 0 and count2 == 0:
        return rec(count3 - 1, count2, have + 6, need)
        
    return max(rec(count3 - 1, count2, have + 6, need), rec(count3, count2 - 1, have + 2, need))

for i in range(t):
    num = input()
    
    numbers_sum = sum([int(x) for x in num])
    need = 9 - (numbers_sum % 9)
    
    count3 = 0
    count2 = 0
    
    for i in num:
        if i == "2":
            count2 += 1
        if i == "3":
            count3 += 1
            
    answers = ["NO", "YES"]
    print(answers[rec(count3, count2, 0, need) == True])

# 322 -> 7 2 -> 11 - 2 = 9

Submission (verdict: Wrong answer on test 1):
t = int(input())

def solve():
    num = [int(x) for x in input()]
    
    num_sum = sum(num)
    need = 9 - (num_sum % 9)
    
    count3 = num.count(3)
    count2 = num.count(2)
    
    for i in range(count2+1):
        for j in range(count3+1):
            if (i * 2 + j * 6) - need % 9 == 0:
                print("YES")
                return
    
    print("NO")
    return

for _ in range(t):
    solve()
Problem: 2050C - Uninteresting Number
Language: Python 3


Submission (verdict: Time limit exceeded on test 3):
t = int(input())

def rec(count3, count2, have, need):
    if (have - need) % 9 == 0:
        return True
        
    if count3 == 0 and count2 == 0:
        return False
    
    if count3 == 0 and count2 > 0:
        return rec(count3, count2 - 1, have + 2, need)
    if count3 > 0 and count2 == 0:
        return rec(count3 - 1, count2, have + 6, need)
        
    return max(rec(count3 - 1, count2, have + 6, need), rec(count3, count2 - 1, have + 2, need))

for i in range(t):
    num = input()
    
    numbers_sum = sum([int(x) for x in num])
    need = 9 - (numbers_sum % 9)
    
    count3 = 0
    count2 = 0
    
    for i in num:
        if i == "2":
            count2 += 1
        if i == "3":
            count3 += 1
            
    answers = ["NO", "YES"]
    print(answers[rec(count3, count2, 0, need) == True])

# 322 -> 7 2 -> 11 - 2 = 9
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>

using namespace std;
#define maxn 200002
//#define int long long
#define ll long long
//int arr[maxn] = {};

bool flag[maxn] = {};

vector<vector<int>> clear(int n, vector<vector<int>>& v) {
    int maxNum = 0, node = 0;
    for (int i = 1; i <= n; ++i) {
        if (v[i].size() > maxNum) {
            maxNum = v[i].size();
            node = i;
        }
    }

    vector<vector<int>> newV(n + 1);
    for (int i = 1; i <= n; ++i) {
        if (i == node) continue;
        for (auto j : v[i]) {
            if (j != node) {
                newV[i].push_back(j);
            }
        }
    }
    return newV;
}

void dfs(int node, vector<vector<int>>& v) {
    for (auto i : v[node]) {
        if (!flag[i]) {
            flag[i] = true;
            dfs(i, v);
        }
    }
}

void solve() {
    int n = 0;
    cin >> n;
    vector<vector<int>> v(n + 1);
    for (int i = 1; i < n; ++i) flag[i] = false;
    for (int i = 1, v1, v2; i < n; ++i) {
        cin >> v1 >> v2;
        v[v1].push_back(v2);
        v[v2].push_back(v1);
    }
    v = clear(n, v);
    v = clear(n, v);
    int res = 0;
    for (int i = 1; i <= n; ++i) {
        if (!flag[i]) {
            dfs(i, v);
            res += 1;
        }
    }
    cout << res - 2 << endl;
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
//    solve();
    int t; cin >> t;
    while (t--) solve();
}
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
def can_be_divisible_by_9(n):
    # Calculate the sum of digits
    digit_sum = sum(int(ch) for ch in n)
    
    # If the sum is already divisible by 9, return "YES"
    if digit_sum % 9 == 0:
        return "YES"
    
    # Calculate the possible replacements
    replacements = {
        0: 0,
        1: 1,
        2: 4,
        3: 9
    }
    
    # Calculate the difference for each digit
    diffs = [replacements.get(int(ch), 0) - int(ch) for ch in n]
    
    # Sort the differences in descending order
    diffs.sort(reverse=True)
    
    # Try to adjust the sum to be divisible by 9
    for diff in diffs:
        digit_sum += diff
        if digit_sum % 9 == 0:
            return "YES"
    
    return "NO"

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        n = data[idx]
        idx += 1
        result = can_be_divisible_by_9(n)
        results.append(result)
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()

Submission (verdict: Wrong answer on test 1):
def can_be_divisible_by_9(n_str):
    # 计算数字各位之和
    S = sum(int(ch) for ch in n_str)
    if S % 9 == 0:
        return "YES"
    
    # 计算目标值
    target = (9 - S % 9) % 9
    
    # 统计数字中2和3的个数
    count2 = n_str.count('2')
    count3 = n_str.count('3')
    
    # 枚举选择多少个3的平方（6）
    for b in range(0, count3 + 1):
        temp = (target - 6 * b) % 9
        if temp % 2 == 0:
            a = temp // 2
            if 0 <= a <= count2:
                return "YES"
    return "NO"

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        n_str = data[idx]
        idx += 1
        result = can_be_divisible_by_9(n_str)
        results.append(result)
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 1):
def can_be_divisible_by_9(n):
    # Calculate the sum of digits
    digit_sum = sum(int(ch) for ch in n)
    
    # If the sum is already divisible by 9, return "YES"
    if digit_sum % 9 == 0:
        return "YES"
    
    # Calculate the possible replacements
    replacements = {
        0: 0,
        1: 1,
        2: 4,
        3: 9
    }
    
    # Calculate the difference for each digit
    diffs = [replacements.get(int(ch), 0) - int(ch) for ch in n]
    
    # Sort the differences in descending order
    diffs.sort(reverse=True)
    
    # Try to adjust the sum to be divisible by 9
    for diff in diffs:
        digit_sum += diff
        if digit_sum % 9 == 0:
            return "YES"
    
    return "NO"

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        n = data[idx]
        idx += 1
        result = can_be_divisible_by_9(n)
        results.append(result)
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
def can_be_divisible_by_9(n_str):
    # 计算数字各位之和
    S = sum(int(ch) for ch in n_str)
    if S % 9 == 0:
        return "YES"
    
    # 计算目标值
    target = (9 - S % 9) % 9
    
    # 统计数字中2和3的个数
    count2 = n_str.count('2')
    count3 = n_str.count('3')
    
    # 枚举选择多少个3的平方（6）
    for b in range(0, count3 + 1):
        temp = (target - 6 * b) % 9
        if temp % 2 == 0:
            a = temp // 2
            if 0 <= a <= count2:
                return "YES"
    return "NO"

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        n_str = data[idx]
        idx += 1
        result = can_be_divisible_by_9(n_str)
        results.append(result)
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()

Submission (verdict: Accepted):
def can_be_divisible_by_9(n_str):
    # 计算数字各位之和
    S = sum(int(ch) for ch in n_str)
    if S % 9 == 0:
        return "YES"
    
    # 计算目标值
    target = (-S) % 9
    new_target = (5 * target) % 9
    
    # 统计数字中2和3的个数
    cnt2 = n_str.count('2')
    cnt3 = n_str.count('3')
    
    # 枚举选择多少个3的平方（6）
    for b in range(0, min(cnt3, 8) + 1):
        a = (new_target - 3 * b) % 9
        if 0 <= a <= cnt2:
            return "YES"
    return "NO"

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        n_str = data[idx]
        idx += 1
        result = can_be_divisible_by_9(n_str)
        results.append(result)
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()
Problem: 2050E - Three Strings
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 1):
def minimal_changes(a, b, c):
    m = len(a)
    n = len(b)
    c_len = len(c)
    if c_len != m + n:
        return -1  # Invalid case as per problem constraints

    # Initialize DP array
    dp = [0] * (n + 1)
    for j in range(1, n + 1):
        dp[j] = dp[j - 1] + (b[j - 1] != c[j - 1])

    for i in range(1, m + 1):
        prev = dp[0]
        dp[0] += (a[i - 1] != c[i - 1])
        for j in range(1, n + 1):
            temp = dp[j]
            dp[j] = min(prev + (b[j - 1] != c[i + j - 1]),
                         dp[j - 1] + (a[i - 1] != c[i + j - 1]))
            prev = temp

    return dp[n]

def main():
    import sys
    input = sys.stdin.read
    data = input().split()
    
    idx = 0
    t = int(data[idx])
    idx += 1
    results = []
    
    for _ in range(t):
        a = data[idx]
        idx += 1
        b = data[idx]
        idx += 1
        c = data[idx]
        idx += 1
        result = minimal_changes(a, b, c)
        results.append(result)
    
    for res in results:
        print(res)

if __name__ == "__main__":
    main()