ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define up(i,x,y) for (int i=x;i<=y;i++)
#define down(i,x,y) for (int i=x;i>=y;i--)
#define ll long long
#define elif else if
using namespace std;

int dp[2010][1010];

void solve(){
	string a,b,c;
	cin>>a>>b>>c;
	int la=a.size(),lb=b.size();
	a="^"+a;
	b="^"+b;
	c="^"+c;
	memset(dp,0x3f,sizeof dp);
	dp[0][0]=0;
	up(i,1,la+lb){
		int mn=max(1,i-lb),mx=min(la,i);
		up(j,1,mx){
			dp[i][j]=min(
				(i-1>=j?dp[i-1][j]+(b[i-j]!=c[i]):100000000),
				dp[i-1][j-1]+(a[j]!=c[i])
			);
		}
	}
	int res=100000000;
	cout<<dp[la+lb][la]<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--) solve();
} 

Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define up(i,x,y) for (int i=x;i<=y;i++)
#define down(i,x,y) for (int i=x;i>=y;i--)
#define ll long long
#define elif else if
using namespace std;

int dp[2010][1010];

void solve(){
	string a,b,c;
	cin>>a>>b>>c;
	int la=a.size(),lb=b.size();
	a="^"+a;
	b="^"+b;
	c="^"+c;
	up(i,0,la+lb) up(j,0,la) dp[i][j]=10000;
	dp[0][0]=0;
	up(i,1,la+lb){
		int mn=max(1,i-lb),mx=min(la,i);
		up(j,mn,mx){
			dp[i][j]=min(
				dp[i-1][j]+(b[i-j]!=c[i]),
				dp[i-1][j-1]+(a[j]!=c[i])
			);
		}
	}
	int res=10000;
	cout<<dp[la+lb][la]<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--) solve();
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define up(i,x,y) for (int i=x;i<=y;i++)
#define down(i,x,y) for (int i=x;i>=y;i--)
#define ll long long
#define elif else if
using namespace std;

int dp[2010][1010];

void solve(){
	string a,b,c;
	cin>>a>>b>>c;
	int la=a.size(),lb=b.size();
	a="^"+a;
	b="^"+b;
	c="^"+c;
	memset(dp,0x3f,sizeof dp);
	dp[0][0]=0;
	up(i,1,la+lb){
		int mn=max(1,i-lb),mx=min(la,i);
		up(j,1,mx){
			dp[i][j]=min(
				(i-1>=j?dp[i-1][j]+(b[i-j]!=c[i]):100000000),
				dp[i-1][j-1]+(a[j]!=c[i])
			);
		}
	}
	int res=100000000;
	cout<<dp[la+lb][la]<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--) solve();
}
Problem: 2050E - Three Strings
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 2):
#include<bits/stdc++.h>
#define up(i,x,y) for (int i=x;i<=y;i++)
#define down(i,x,y) for (int i=x;i>=y;i--)
#define ll long long
#define elif else if
using namespace std;

int dp[2010][1010];

void solve(){
	string a,b,c;
	cin>>a>>b>>c;
	int la=a.size(),lb=b.size();
	a="^"+a;
	b="^"+b;
	c="^"+c;
	up(i,0,la+lb) up(j,0,la) dp[i][j]=10000;
	dp[0][0]=0;
	up(i,1,la+lb){
		int mn=max(1,i-lb),mx=min(la,i);
		up(j,mn,mx){
			dp[i][j]=min(
				dp[i-1][j]+(b[i-j]!=c[i]),
				dp[i-1][j-1]+(a[j]!=c[i])
			);
		}
	}
	int res=10000;
	cout<<dp[la+lb][la]<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--) solve();
} 

Submission (verdict: Wrong answer on test 1):
#include<bits/stdc++.h>
#define up(i,x,y) for (int i=x;i<=y;i++)
#define down(i,x,y) for (int i=x;i>=y;i--)
#define ll long long
#define elif else if
using namespace std;

int dp[2010][1010];

void solve(){
	string a,b,c;
	cin>>a>>b>>c;
	int la=a.size(),lb=b.size();
	a="^"+a;
	b="^"+b;
	c="^"+c;
	up(i,0,la+lb) up(j,0,la) dp[i][j]=10000;
	dp[0][0]=0;
	up(i,1,la+lb){
		int mn=max(0,i-lb),mx=min(la,i);
		up(j,mn,mx){
			dp[i][j]=min(
				dp[i-1][j]+(b[i-j]!=c[i]),
				dp[i-1][j-1]+(a[j]!=c[i])
			);
		}
	}
	int res=10000;
	cout<<dp[la+lb][la]<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int T;
	cin>>T;
	while(T--) solve();
}
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 1):
len_, lst, op = int(input()), list(map(int, input().split())), []
if len_ == 1: print(0); exit()
for i in range(1, len_ + 1):
    if (index_ := lst.index(i)) != len_ - 1:
        for j in lst[index_ + 1:]:
            if j > i: op.append(f'{j} {i}')
    for k in range(1, i): op.append(f'{k} {i}')
print(len(op), *op, sep='\n')


Submission (verdict: Accepted):
len_, lst, op = int(input()), list(map(int, input().split())), []
if len_ == 1: print(0); exit()
for i in range(1, len_ + 1):
    if (index_ := lst.index(i)) != len_ - 1:
        for j in lst[index_ + 1:]:
            if j > i: op.append(f'{i} {j}')
    for k in range(1, i): op.append(f'{i} {k}')
print(len(op), *op[::-1], sep='\n')
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 4):
len_, arr = int(input()), list(map(int, input().split())); op = []
if len_ == 1: print(0); exit()
for i in range(1, len_ + 1):
    if not (index_ := arr.index(i)): continue
    reverse = False
    for j in arr[index_ - 1::-1]:
        if j > i: op.append(f'{j} {i}')
        elif j == i - 1: reverse = True
    if reverse: op.extend([f'{i - 1} {i}', f'{i} {i - 1}'])
print(len(op), *(op[::-1]), sep='\n')
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 7):
len_, lst = int(input()), list(map(int, input().split())); op = []
if len_ == 1: print(0); exit()
for i in range(1, len_ + 1):
    if not (index_ := lst.index(i)): continue
    reverse = set()
    for j in lst[index_ - 1::-1]:
        if j > i: op.append(f'{j} {i}')
        else: reverse.add(j)
    for k in range(i - 1, -1, -1):
        if k not in reverse:
            arr = range(k + 1, i)
            op.extend([f'{x} {i}' for x in arr[::-1]] + [f'{i} {x}' for x in arr]); break
print(len(op), *(op[::-1]), sep='\n')


Submission (verdict: Wrong answer on test 1):
len_, lst, op = int(input()), list(map(int, input().split())), []
if len_ == 1: print(0); exit()
for i in range(1, len_ + 1):
    if (index_ := lst.index(i)) != len_ - 1:
        for j in lst[index_ + 1:]:
            if j > i: op.append(f'{j} {i}')
    for k in range(1, i): op.append(f'{k} {i}')
print(len(op), *op, sep='\n')
Problem: 2052A - Adrenaline Rush
Language: PyPy 3-64

Previous submission (verdict: Wrong answer on test 4):
len_, arr = int(input()), list(map(int, input().split())); op = []
if len_ == 1: print(0); exit()
for i in range(1, len_ + 1):
    if not (index_ := arr.index(i)): continue
    reverse = False
    for j in arr[index_ - 1::-1]:
        if j > i: op.append(f'{j} {i}')
        elif j == i - 1: reverse = True
    if reverse: op.extend([f'{i - 1} {i}', f'{i} {i - 1}'])
print(len(op), *(op[::-1]), sep='\n')


Submission (verdict: Wrong answer on test 7):
len_, lst = int(input()), list(map(int, input().split())); op = []
if len_ == 1: print(0); exit()
for i in range(1, len_ + 1):
    if not (index_ := lst.index(i)): continue
    reverse = set()
    for j in lst[index_ - 1::-1]:
        if j > i: op.append(f'{j} {i}')
        else: reverse.add(j)
    for k in range(i - 1, -1, -1):
        if k not in reverse:
            arr = range(k + 1, i)
            op.extend([f'{x} {i}' for x in arr[::-1]] + [f'{i} {x}' for x in arr]); break
print(len(op), *(op[::-1]), sep='\n')
Problem: 2063B - Subsequence Update
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

int main() 

{

    int t;

    cin >> t;

    while(t--){

      int n,l,r;

      cin >> n >> l >> r;

      ll a[n];

      for(int i = 0 ; i < n ; i++)cin >> a[i];

      sort(a,a+n);

      ll ans = 0;

      

      for(int i = 0 ; i < (r-l)+1;i++)ans+=a[i];

      cout << ans << '\n';

    }

    return 0;

}

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

using namespace std;

#define ll long long

int main() 

{

    int t;

    cin >> t;

    while(t--){

      int n,l,r;

      cin >> n >> l >> r;

      ll a[n];

      for(int i = 0 ; i < n ; i++)cin >> a[i];

      sort(a,a+n);

      ll ans = 0,ans2 = 0;

      vector<ll>vec1,vec2;

      for(int i = 0 ; i < r ; i++)vec1.push_back(a[i]);

      for(int i = l-1; i < n ; i++)vec2.push_back(a[i]);

      sort(vec1.begin(),vec1.end());

      sort(vec2.begin(),vec2.end());

      for(int i = 0 ; i < (r-l)+1;i++)ans+=vec1[i];

      for(int i = 0 ; i < (r-l)+1;i++)ans2+=vec2[i];

      ans = min(ans,ans2);

      cout << ans << '\n';

    }

    return 0;

}
Problem: 2063B - Subsequence Update
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

int main() 

{

    int t;

    cin >> t;

    while(t--){

      int n,l,r;

      cin >> n >> l >> r;

      ll a[n];

      for(int i = 0 ; i < n ; i++)cin >> a[i];

      sort(a,a+n);

      ll ans = 0,ans2 = 0;

      vector<ll>vec1,vec2;

      for(int i = 0 ; i < r ; i++)vec1.push_back(a[i]);

      for(int i = l-1; i < n ; i++)vec2.push_back(a[i]);

      sort(vec1.begin(),vec1.end());

      sort(vec2.begin(),vec2.end());

      for(int i = 0 ; i < (r-l)+1;i++)ans+=vec1[i];

      for(int i = 0 ; i < (r-l)+1;i++)ans2+=vec2[i];

      ans = min(ans,ans2);

      cout << ans << '\n';

    }

    return 0;

}

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

using namespace std;

#define ll long long

int main() 

{

    int t;

    cin >> t;

    while(t--){

      int n,l,r;

      cin >> n >> l >> r;

      ll a[n];

      for(int i = 0 ; i < n ; i++)cin >> a[i];

      

      ll ans = 0,ans2 = 0;

      vector<ll>vec1,vec2;

      for(int i = 0 ; i < r ; i++)vec1.push_back(a[i]);

      for(int i = l-1; i < n ; i++)vec2.push_back(a[i]);

      sort(vec1.begin(),vec1.end());

      sort(vec2.begin(),vec2.end());

      for(int i = 0 ; i < (r-l)+1;i++)ans+=vec1[i];

      for(int i = 0 ; i < (r-l)+1;i++)ans2+=vec2[i];

      

      cout << min(ans,ans2) << '\n';

    }

    return 0;

}
Problem: 2063B - Subsequence Update
Language: C++20 (GCC 13-64)


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

using namespace std;

#define ll long long

int main() 

{

    int t;

    cin >> t;

    while(t--){

      int n,l,r;

      cin >> n >> l >> r;

      ll a[n];

      for(int i = 0 ; i < n ; i++)cin >> a[i];

      sort(a,a+n);

      ll ans = 0;

      

      for(int i = 0 ; i < (r-l)+1;i++)ans+=a[i];

      cout << ans << '\n';

    }

    return 0;

}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)


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

using namespace std;
using vi = vector<int>;

void solve() {
    string num;
    cin >> num;
    for(int i = 0; i < num.size(); i++) {
        int max = num[i];
        int pos = i;
        for(int j = i + 1; j < num.size(); j++) {
            if(num[j] - (j - i) > max) {
                max = num[j] - (j - i);
                pos = j;
            }
        }
        num.erase(pos, 1);
        num.insert(num.begin() + i, max);
    }
    cout << num << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) solve();
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;

void solve() {
    string num;
    cin >> num;
    for(int i = 0; i < num.size(); i++) {
        int max = num[i];
        int pos = i;
        for(int j = i + 1; j < num.size(); j++) {
            if(num[j] - (j - i) > max) {
                max = num[j] - (j - i);
                pos = j;
            }
        }
        num.erase(pos, 1);
        num.insert(num.begin() + i, max);
    }
    cout << num << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) solve();
}


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

using namespace std;

void solve() {
    string s; cin >> s;
    for (int i = 0; i < s.size(); i++) {
        int best = s[i] - '0', pos = i;
        for (int j = i; j < min(i + 10, (int) s.size()); j++) {
            if (s[j] - '0' - (j - i) > best) {
                best = s[j] - '0' - (j - i);
                pos = j;
            }
        }
        while (pos > i) {
            swap(s[pos], s[pos - 1]);
            pos--;
        }
        s[i] = char(best + '0');
    }
    cout << s;
}

int main() {
    int TESTS = 1; cin >> TESTS;
    while (TESTS --> 0) {
        solve();
        cout << '\n';
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;

void solve() {
    string num;
    cin >> num;
    for(int i = 0; i < num.size(); i++) {
        int max = num[i];
        int pos = i;
        for(int j = i + 1; j < num.size(); j++) {
            if(num[j] - (j - i) > max) {
                max = num[j] - (j - i);
                pos = j;
            }
        }
        num.erase(pos, 1);
        num.insert(num.begin() + i, max);
    }
    cout << num << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) solve();
}


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

using namespace std;

void solve() {
    string num;
    cin >> num;
    for(int i = 0; i < num.size(); i++) {
        int max = num[i];
        int pos = i;
        for(int j = i + 1; j < num.size(); j++) {
            if(num[j] - (j - i) > max) {
                max = num[j] - (j - i);
                pos = j;
            }
        }
        num.erase(pos, 1);
        num.insert(num.begin() + i, max);
    }
    cout << num << '\n';
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int t;
    cin >> t;
    while (t--) solve();
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


Submission (verdict: Memory limit exceeded on test 14):
// https://codeforces.com/problemset/problem/2050/E

#include <bits/stdc++.h>
using namespace std;

int rec(string& a, string& b, string& c, int i, int j, int k, vector<vector<vector<int>>>& dp) {
    if (k == c.size()) return 0;
    if (dp[i][j][k] != -1) return dp[i][j][k];

    int minAns = INT_MAX;

    if (i < a.size() && j < b.size()) {
        if (a[i] == c[k] && b[j] == c[k]) {
            minAns = min({rec(a, b, c, i + 1, j, k + 1, dp),
                          rec(a, b, c, i, j + 1, k + 1, dp)});
        } else if (a[i] == c[k]) {
            minAns = min(rec(a, b, c, i + 1, j, k + 1, dp), 
                         1 + rec(a, b, c, i, j + 1, k + 1, dp));
        } else if (b[j] == c[k]) {
            minAns = min(1 + rec(a, b, c, i + 1, j, k + 1, dp), 
                         rec(a, b, c, i, j + 1, k + 1, dp));
        } else {
            minAns = 1 + min(rec(a, b, c, i + 1, j, k + 1, dp), 
                             rec(a, b, c, i, j + 1, k + 1, dp));
        }
    } else if (i < a.size()) {
        int add = (a[i] != c[k]) ? 1 : 0;
        minAns = add + rec(a, b, c, i + 1, j, k + 1, dp);
    } else if (j < b.size()) {
        int add = (b[j] != c[k]) ? 1 : 0;
        minAns = add + rec(a, b, c, i, j + 1, k + 1, dp);
    }

    return dp[i][j][k] = minAns;
}

void solve() {
    string a, b, c;
    cin >> a >> b >> c;

    vector<vector<vector<int>>> dp(a.size() + 1, vector<vector<int>>(b.size() + 1, vector<int>(c.size() + 1, -1)));
    int minRep = rec(a, b, c, 0, 0, 0, dp);
    cout << minRep << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 16):
// https://codeforces.com/problemset/problem/2050/E

#include <bits/stdc++.h>
using namespace std;

void solve() {
    string a, b, c;
    cin >> a >> b >> c;

    int n = a.size(), m = b.size(), o = c.size();
    vector<vector<int>> prev(n + 1, vector<int>(m + 1, INT_MAX));
    vector<vector<int>> curr(n + 1, vector<int>(m + 1, INT_MAX));

    for (int i = 0; i <= n; ++i) {
        for (int j = 0; j <= m; ++j) {
            prev[i][j] = 0;
        }
    }

    for (int k = o - 1; k >= 0; --k) {
        for (int i = n; i >= 0; --i) {
            for (int j = m; j >= 0; --j) {
                int minAns = INT_MAX;
                if (i < n && j < m) {
                    if (a[i] == c[k] && b[j] == c[k]) {
                        minAns = min({prev[i + 1][j], prev[i][j + 1]});
                    } else if (a[i] == c[k]) {
                        minAns = min(prev[i + 1][j], 1 + prev[i][j + 1]);
                    } else if (b[j] == c[k]) {
                        minAns = min(1 + prev[i + 1][j], prev[i][j + 1]);
                    } else {
                        minAns = 1 + min(prev[i + 1][j], prev[i][j + 1]);
                    }
                } else if (i < n) {
                    minAns = (a[i] != c[k]) + prev[i + 1][j];
                } else if (j < m) {
                    minAns = (b[j] != c[k]) + prev[i][j + 1];
                }

                curr[i][j] = minAns;
            }
        }
        prev = curr;
    }

    cout << prev[0][0] << endl;
}

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


Submission (verdict: Accepted):
// https://codeforces.com/problemset/problem/2050/E

#include <bits/stdc++.h>
using namespace std;

void solve() {
    string a, b, c;
    cin >> a >> b >> c;
    int n = a.size(), m = b.size(), o = c.size();
    unordered_map<int, int> curr, next;
    curr[0] = 0;
    for (int k = 0; k < o; ++k) {
        next.clear();
        for (auto &[state, cost] : curr) {
            int i = state / (m + 1);
            int j = state % (m + 1);
            if (i < n) {
                int newCost = cost + (a[i] != c[k]);
                int newState = (i + 1) * (m + 1) + j;
                if (!next.count(newState) || next[newState] > newCost) {
                    next[newState] = newCost;
                }
            }
            if (j < m) {
                int newCost = cost + (b[j] != c[k]);
                int newState = i * (m + 1) + (j + 1);
                if (!next.count(newState) || next[newState] > newCost) {
                    next[newState] = newCost;
                }
            }
        }
        swap(curr, next);
    }

    int minCost = INT_MAX;
    for (auto &[state, cost] : curr) {
        minCost = min(minCost, cost);
    }
    cout << minCost << endl;
}

int main() {
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: PyPy 3-64


Submission (verdict: Wrong answer on test 2):
for i in range(int(input())):
    n=(input())
    a=0
    for i in n:
        a+=int(i)
    a=a%9
    a=9-a
    if a==9:
        print("YES")
    else:
        if a%2!=0:
            p=0
            q=0
            for i in n:
                if i=="2":
                    p+=1
                if i=="3":
                    q+=1
            if a==1:
                if p>=5 or (p>+2 and q>=1):
                    print("YES")
                else:
                    print("NO")
            elif a==3:
                if q>=2 or p>=6 or (q>=1 and p>=3):
                    print("YES")
                else:
                    print("NO")
            elif a==5:
                if p>=7 or (q>=1 and p>=4) or (q>=2 and p>=1):
                    print("YES")
                else:
                    print('NO')
            else:
                if p>=8 or (q>=1 and p>=5) or (q>=2 and p>=2):
                    print("YES")
                else:
                    print("NO")
        else:
            if a<6:
                a=a//2
                ans=0
                for i in n:
                    if i=="2":
                        ans+=1
                if ans>a:
                    print("YES")
                else:
                    print("NO")
            else:
                if a==6:
                    a=a//2
                    ans=0
                    for i in n:
                        if i=="2":
                            ans+=1
                    if ans>a:
                        print("YES")
                    else:
                        for i in n:
                            if i=="3":
                                print("YES")
                                break
                        else:
                            print("NO")
                else:
                    a=a//2
                    ans=0
                    for i in n:
                        if i=="2":
                            ans+=1
                    if ans>a:
                        print("YES")
                    else:
                        if ans<1:
                            print("NO")
                        else:
                            for i in n:
                                if i=="3":
                                    print("YES")
                                    break
                            else:
                                print("NO")
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)


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



using namespace std;

int t, s, x, dv, th;

string n;

int main()

{   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> t;

    while (t--) {

        cin >> n;

        dv = 0; th = 0; x = 0; s = 0;

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

            x = n[i] - '0';

            s += x;

            if (x == 2) {dv++;}

            if (x == 3) {th++;}

        }

        if (s % 9 == 0) {cout << "YES" << '\n'; continue;}

        int f = 0;

        while (s % 9 != 0) {

            if (dv == 0 && th == 0) {break;}

            if (dv > 0) {s += 2; dv--;}

            if (s % 9 == 0) {f = 1; break;}

            if (th > 0) {s += 6; th--;}

            if (s % 9 == 0) {f = 1; break;}

            if (s % 9 == 2) {f = 1; break;}

        }

        if (f == 0) {cout << "NO" << '\n';} else {cout << "YES" << '\n';}

    }

    return 0;

}
Problem: 2050C - Uninteresting Number
Language: C++20 (GCC 13-64)

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



using namespace std;

int t, s, x, dv, th;

string n;

int main()

{   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> t;

    while (t--) {

        cin >> n;

        dv = 0; th = 0; x = 0; s = 0;

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

            x = n[i] - '0';

            s += x;

            if (x == 2) {dv++;}

            if (x == 3) {th++;}

        }

        if (s % 9 == 0) {cout << "YES" << '\n'; continue;}

        int f = 0;

        while (s % 9 != 0) {

            if (dv == 0 && th == 0) {break;}

            if (dv > 0) {s += 2; dv--;}

            if (s % 9 == 0) {f = 1; break;}

            if (th > 0) {s += 6; th--;}

            if (s % 9 == 0) {f = 1; break;}

            //if (s % 9 == 2) {f = 1; break;}

        }

        if (f == 0) {cout << "NO" << '\n';} else {cout << "YES" << '\n';}

    }

    return 0;

}



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



using namespace std;

int t, s, x, dv, th;

string n;

int main()

{   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    cin >> t;

    while (t--) {

        cin >> n;

        dv = 0; th = 0; x = 0; s = 0;

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

            x = n[i] - '0';

            s += x;

            if (x == 2) {dv++;}

            if (x == 3) {th++;}

        }

        if (s % 9 == 0) {cout << "YES" << '\n'; continue;}

        int f = 0;

        x = s % 9;

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

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

                if ((x + (i * 6) + (j * 2)) % 9 == 0) {f = 1;}

            }

        }

        if (f == 0) {cout << "NO" << '\n';} else {cout << "YES" << '\n';}

    }

    return 0;

}