ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int helper(int i , int j, string &a, string &b , string &c,vector<vector<int>> &dp) {
    if(i + j >= c.size()){
        return  dp[i][j] = 0 ;
    }
    int temp1 =1;
    if(a[i]==c[i+j]){
        temp1--;
    }
    int temp2 = 1;
    if(b[j] == c[i+j]){
        temp2--;
    }
    if(i==a.size()){
        
        return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp);
    }
    if(j==b.size()){
       
        return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp);
    }
    return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) );
}
int main()
{
    
    int n;
    cin>>n;
    
    while(n--)
    {
        string a  , b , c;
        cin>>a>>b>>c;
        vector<vector<int>> dp(a.size() + 1, vector<int> (b.size()+1));
        cout<<helper(0,0,a,b,c,dp);
        cout<<"\n";
      

    }
    return 0;
}


Submission (verdict: Accepted):
#include<bits/stdc++.h>
using namespace std;
int helper(int i , int j, string &a, string &b , string &c,vector<vector<int>> &dp) {
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    if(i + j >= c.size()){
        return  dp[i][j] = 0 ;
    }
    int temp1 =1;
    if(a[i]==c[i+j]){
        temp1--;
    }
    int temp2 = 1;
    if(b[j] == c[i+j]){
        temp2--;
    }
    if(i==a.size()){
        
        return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp);
    }
    if(j==b.size()){
       
        return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp);
    }
    return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) );
}
int main()
{
    
    int n;
    cin>>n;
    
    while(n--)
    {
        string a  , b , c;
        cin>>a>>b>>c;
        vector<vector<int>> dp(a.size() + 1, vector<int> (b.size()+1 , -1));
        cout<<helper(0,0,a,b,c,dp);
        cout<<"\n";
      

    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

Previous submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int helper(int i , int j, string a, string b , string c,vector<vector<int>> &dp) {
    if(i + j >= c.size()){
        return  dp[i][j] = 0 ;
    }
    int temp1 =1;
    if(a[i]==c[i+j]){
        temp1--;
    }
    int temp2 = 1;
    if(b[j] == c[i+j]){
        temp2--;
    }
    if(i==a.size()){
        
        return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp);
    }
    if(j==b.size()){
       
        return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp);
    }
    return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) );
}
int main()
{
    
    int n;
    cin>>n;
    
    while(n--)
    {
        string a  , b , c;
        cin>>a>>b>>c;
        vector<vector<int>> dp(a.size() + 1, vector<int> (b.size()+1));
        cout<<helper(0,0,a,b,c,dp);
        cout<<endl;
      

    }
    return 0;
}


Submission (verdict: Time limit exceeded on test 6):
#include<bits/stdc++.h>
using namespace std;
int helper(int i , int j, string &a, string &b , string &c,vector<vector<int>> &dp) {
    if(i + j >= c.size()){
        return  dp[i][j] = 0 ;
    }
    int temp1 =1;
    if(a[i]==c[i+j]){
        temp1--;
    }
    int temp2 = 1;
    if(b[j] == c[i+j]){
        temp2--;
    }
    if(i==a.size()){
        
        return dp[i][j] = temp2 + helper(i , j+1 , a , b,c,dp);
    }
    if(j==b.size()){
       
        return dp[i][j] = temp1 + helper(i+1 , j , a , b,c,dp);
    }
    return dp[i][j] = min(temp1 + helper(i+1 , j , a , b,c,dp) ,temp2 + helper(i , j+1 , a , b,c,dp) );
}
int main()
{
    
    int n;
    cin>>n;
    
    while(n--)
    {
        string a  , b , c;
        cin>>a>>b>>c;
        vector<vector<int>> dp(a.size() + 1, vector<int> (b.size()+1));
        cout<<helper(0,0,a,b,c,dp);
        cout<<"\n";
      

    }
    return 0;
}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)


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

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}int modda=0;

f(i,0,n-2){

    if(v[i]>v[i+1]&&v[i+1]>v[i+2]){

    modda=1;break;}

}

if(modda)

cout<<"no"<<endl;

else cout<<"yes"<<endl;

 }

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

    solve();

}}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}int modda=0;

f(i,0,n-2){

    if(v[i]>v[i+1]&&v[i+1]>v[i+2]){

    modda=1;break;}

}

if(modda)

cout<<"no"<<endl;

else cout<<"yes"<<endl;

 }

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

    solve();

}}

Submission (verdict: Compilation error):
#include "bits/stdc++.h"

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}

if(n==2){

    if(v[0]>v[1])

    cout<<"no"<<end;

    else cout<<"yes"<<endl;

}

else{

int modda=0;

f(i,0,n-2){

    if(v[i]>v[i+1]&&v[i+1]>v[i+2]){

    modda=1;break;}

}

if(modda)

cout<<"no"<<endl;

else cout<<"yes"<<endl;}

 }

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

    solve();

}}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

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

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}

 if(v[0]>v[1])

 cout<<"no"<<endl;

else{

int modda=0;

f(i,0,n-2){

    if(v[i]>v[i+1]&&v[i+1]>v[i+2]){

    modda=1;break;}

}

if(modda)

cout<<"no"<<endl;

else cout<<"yes"<<endl;}

 }

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

    solve();

}}

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

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}int modda=0;

 f(i,0,n-1){

     if(v[i]>v[i+1]){

     modda=1;break;}

     v[i+1]=v[i+1]-min(v[i],v[i+1]);

 }

 if(modda)

 cout<<"no"<<endl;

 else cout<<"yes"<<endl;

 }

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

    solve();

}}
Problem: 2060D - Subtract Min Sort
Language: C++20 (GCC 13-64)

Previous submission (verdict: Compilation error):
#include "bits/stdc++.h"

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}

if(n==2){

    if(v[0]>v[1])

    cout<<"no"<<end;

    else cout<<"yes"<<endl;

}

else{

int modda=0;

f(i,0,n-2){

    if(v[i]>v[i+1]&&v[i+1]>v[i+2]){

    modda=1;break;}

}

if(modda)

cout<<"no"<<endl;

else cout<<"yes"<<endl;}

 }

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

    solve();

}}

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

using namespace std;

using ll= long long int;

#define f(i,a,b) for(ll i=a;i<(ll)(b);i++)

#define fr(i,a,b) for(ll i=a;i>(ll)(b);--i)

#define pb push_back

#define vi vector<ll>

void solve(){

ll n;cin>>n;

vi v(n);

f(i,0,n){

    cin>>v[i];

}

 if(v[0]>v[1])

 cout<<"no"<<endl;

else{

int modda=0;

f(i,0,n-2){

    if(v[i]>v[i+1]&&v[i+1]>v[i+2]){

    modda=1;break;}

}

if(modda)

cout<<"no"<<endl;

else cout<<"yes"<<endl;}

 }

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

    solve();

}}
Problem: 2050E - Three Strings
Language: PyPy 3-64


Submission (verdict: Time limit exceeded on test 16):
# author 
# Kidus Guade

import sys
import random
from types import GeneratorType
from sys import stdin,stdout
from math import gcd,floor,sqrt,log, ceil
from collections import defaultdict, Counter, deque
from bisect import bisect_left,bisect_right, insort_left, insort_right
def ints(): return map(int, sys.stdin.readline().strip().split())
def li(): return list(map(int, sys.stdin.readline().strip().split()))
def string(): return sys.stdin.readline().strip()
def get_int(): return int(sys.stdin.readline().strip())
def li_strings(): return list(map(str, sys.stdin.readline().strip().split()))


def bootstrap(f, stack=[]):
    def wrappedfunc(*args, **kwargs):
        if stack:
            return f(*args, **kwargs)
        else:
            to = f(*args, **kwargs)
            while True:
                if type(to) is GeneratorType:
                    stack.append(to)
                    to = next(to)
                else:
                    stack.pop()
                    if not stack:
                        break
                    to = stack[-1].send(to)
            return to
    return wrappedfunc
        

def primeFactors(n):
    
    i = 2
    primfac = []
    while i * i <= n:
        while n % i == 0:
            primfac.append(i)
            n = n / i
        i = i + 1
    if n > 1:
        primfac.append(int(n))
    return primfac
def prime_sieve(n):
    is_prime = [True for _ in range(n + 1)]
    is_prime[0] = is_prime[1] = False
    i = 2
    while i * i <= n:
        if is_prime[i]:
            j = i * i
            while j <= n:
                is_prime[j] = False
                j += i
        i += 1
    return is_prime
def find_divisors(number):
    divisors = []
    for i in range(1, int(number**0.5) + 1):
        if number % i == 0:
            divisors.append(i)
            if i != number // i:
                divisors.append(number // i)
    return divisors    
def solve():
    a = string()
    b = string()
    c = string()
    memo = {}

    @bootstrap
    def dp(i, j, k):
        if k == len(c):
            yield 0
        if (i, k) in memo:
            yield memo[(i, k)]
        val = float('inf')
        if i < len(a):
            if a[i] == c[k]:
                vv = yield dp(i + 1, j, k + 1)
                
            else:
                vv = yield dp(i + 1, j, k + 1)
                vv += 1
            val = min(val, vv)
               
        if j < len(b):
            if b[j] == c[k]:
                vv = yield dp(i, j + 1, k + 1)
              
            else:
                vv = yield dp(i, j + 1, k + 1)
                vv += 1

            val = min(val, vv)
        memo[(i, k)] = val
        yield memo[(i, k)]
    return dp(0, 0, 0)

    
  


    
    
    
if __name__ == "__main__":
    for _ in range(get_int()):
        print(solve())
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)


Submission (verdict: Compilation error):
#include <iostream>

using namespace std;



int main() {

// your code goes here

int t; cin>>t;

while(t--){

int n; cin>>n;

itn flag=1;

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

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

if(a[i]>a[i-1]) flag=0;

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

a[i]-=x;

a[i+1]-=x;

}

if(flag) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Wrong answer on test 1):
#include <iostream>

using namespace std;



int main() {

// your code goes here

int t; cin>>t;

while(t--){

int n; cin>>n;

int flag=1;

int a[n];

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

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

if(a[i]>a[i-1]) flag=0;

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

a[i]-=x;

a[i+1]-=x;

}

if(flag) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

return 0;

}

Submission (verdict: Accepted):
#include <iostream>

using namespace std;



int main() {

// your code goes here

int t; cin>>t;

while(t--){

int n; cin>>n;

int flag=1;

int a[n];

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

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

if(a[i]>a[i+1]) flag=0;

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

a[i]-=x;

a[i+1]-=x;

}



if(flag) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

return 0;

}
Problem: 2060D - Subtract Min Sort
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Compilation error):
#include <iostream>

using namespace std;



int main() {

// your code goes here

int t; cin>>t;

while(t--){

int n; cin>>n;

itn flag=1;

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

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

if(a[i]>a[i-1]) flag=0;

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

a[i]-=x;

a[i+1]-=x;

}

if(flag) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

return 0;

}

Submission (verdict: Wrong answer on test 1):
#include <iostream>

using namespace std;



int main() {

// your code goes here

int t; cin>>t;

while(t--){

int n; cin>>n;

int flag=1;

int a[n];

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

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

if(a[i]>a[i-1]) flag=0;

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

a[i]-=x;

a[i+1]-=x;

}

if(flag) cout<<"YES"<<endl;

else cout<<"NO"<<endl;

}

return 0;

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


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

void removeNode(map<int, set<int>>&adjList, int node){
	for(auto ri = adjList[node].begin(); ri != adjList[node].end(); ri++){
		int adjNode = *ri;
		adjList[adjNode].erase(node);
	}
	adjList.erase(node);
}

int findHighestDegreeNode(map<int, set<int>>& adjList){
	int maxSize = 0, node;
	for(auto ri = adjList.begin(); ri != adjList.end(); ri++){
		if((ri -> second).size() >= maxSize){
			maxSize = (ri -> second).size();
			node = ri -> first;
		}
	}
	return node;
}

void visitComponent(map<int, set<int>>& adjList, int currNode, vector<int>& visited){
	if(visited[currNode])
		return;
	visited[currNode] = 1;
	for(auto ri = adjList[currNode].begin(); ri != adjList[currNode].end(); ri++){
		int adjNode = *ri;
		visitComponent(adjList, adjNode, visited);
	}
}

void solve(){
    int n;
    cin>>n;
    map<int, set<int>> adjList;
    for(int ri = 1; ri < n; ri++){
    	int u, v;
    	cin>>u>>v;
    	adjList[u].insert(v);
    	adjList[v].insert(u);
    }
    int highestDegreeNode = findHighestDegreeNode(adjList);
    removeNode(adjList, highestDegreeNode);
    highestDegreeNode = findHighestDegreeNode(adjList);
    removeNode(adjList, highestDegreeNode);
    int connectedComponentsCount = 0;
    vector<int> visited(n + 1);
    for(auto ri = adjList.begin(); ri != adjList.end(); ri++){
    	int currNode = ri -> first;
    	if(!visited[currNode]){
    		visitComponent(adjList, currNode, visited);
    		connectedComponentsCount++;
    	}
    }
    cout<<connectedComponentsCount<<endl;
}

int main()
{
    int t;
    scanf("%d",&t);
    while(t--){
        solve();
    }
    return 0;
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

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

#define int long long


int get_sum(int n){
    int sum = 0;
    while(n>0){
        sum += (n%10);
        n=n/10;
    }
    return sum;
}


int get_two(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 2) a++;
        n=n/10;
    }
    return a;
}

int get_three(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 3) a++;
        n=n/10;
    }
    return a;
}


void solve(){
    int n;
    cin>>n;
    int sum = get_sum(n);
    int left = (((sum+8)/9)*9)  - sum;
    
    
    // cout<<"LEFT IS: "<<left<<endl;
    
    int find2 = get_two(n);
    int find3 = get_three(n);

    if(left == 0){
        cout<<"YES\n";
        return;
    }else if(left == 1){
        if(find2>=5 || (find3>=1 && find2>=2)){
            cout<<"YES\n";
            return;
        }
    }
    else if(left == 2 && find2>=1){
        cout<<"YES\n";
        return;
    }
    else if(left == 3){
        if(find3>=2 || (find2>=6) || (find3>=1 && find2>=3)){
            cout<<"YES\n";
            return;
        }
    }
    else if(left == 4 &&  find2>=2){
        cout<<"YES\n";
        return;
        
    }else if(left == 5){
        //make 14
        if(find2>=7 || (find3>=2 && find2>=1) || (find3>=1 && find2>=4)){
            cout<<"YES\n";
            return;
        }
    }
    else if(left == 6 && (find2>=3 || find3>=1)   ){
        cout<<"YES\n";
        return;
        
    }
    else if(left == 7){
        if(find2>=8 || (find3>=2 && find2>=2) || (find3>=1 && find2>=5)){
            cout<<"YES\n";
            return;
        }
    }
    
    else if(left == 8 && ( find2>=4  || (find3>=1 && find2>=1)) ){
        cout<<"YES\n";
        return;
        
    }
        cout<<"NO\n";
    
    
    
    
    
}


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

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

#define int long long


int get_sum(int n){
    int sum = 0;
    while(n>0){
        sum += (n%10);
        n=n/10;
    }
    return sum;
}


int get_two(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 2) a++;
        n=n/10;
    }
    return a;
}

int get_three(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 3) a++;
        n=n/10;
    }
    return a;
}


void solve(){
    int n;
    cin>>n;
    int sum = get_sum(n);
    int left = (((sum+8)/9)*9)  - sum;
    
    
    // cout<<"LEFT IS: "<<left<<endl;
    
    int find2 = get_two(n);
    int find3 = get_three(n);
    for(int i=0;i<=find2;i++){
        for(int j=0;j<=find3;j++){
            if((sum + 6*j + 2*i)%9 == 0){
                cout<<"YES\n";
                return;
            }
        }
    }
        cout<<"NO\n";
    
    
    
    
    
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t;
    cin >> t;
    while (t--){
       solve();
    }
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)


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

#define int long long


int get_sum(int n){
    int sum = 0;
    while(n>0){
        sum += (n%10);
        n=n/10;
    }
    return sum;
}


int get_two(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 2) a++;
        n=n/10;
    }
    return a;
}

int get_three(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 3) a++;
        n=n/10;
    }
    return a;
}


void solve(){
    int n;
    cin>>n;
    int sum = get_sum(n);
    int left = (((sum+8)/9)*9)  - sum;
    
    
    // cout<<"LEFT IS: "<<left<<endl;
    
    int find2 = get_two(n);
    int find3 = get_three(n);

    if(left == 0){
        cout<<"YES\n";
        return;
    }else if(left == 1){
        if(find2>=5 || (find3>=1 && find2>=2)){
            cout<<"YES\n";
            return;
        }
    }
    else if(left == 2 && find2>=1){
        cout<<"YES\n";
        return;
    }
    else if(left == 3){
        if(find3>=2 || (find2>=6) || (find3>=1 && find2>=3)){
            cout<<"YES\n";
            return;
        }
    }
    else if(left == 4 &&  find2>=2){
        cout<<"YES\n";
        return;
        
    }else if(left == 5){
        //make 14
        if(find2>=7 || (find3>=2 && find2>=1) || (find3>=1 && find2>=4)){
            cout<<"YES\n";
            return;
        }
    }
    else if(left == 6 && (find2>=3 || find3>=1)   ){
        cout<<"YES\n";
        return;
        
    }
    else if(left == 7){
        if(find2>=8 || (find3>=2 && find2>=2) || (find2>=1 && find2>=5)){
            cout<<"YES\n";
            return;
        }
    }
    
    else if(left == 8 && ( find2>=4  || (find3>=1 && find2>=1)) ){
        cout<<"YES\n";
        return;
        
    }
        cout<<"NO\n";
    
    
    
    
    
}


signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int t;
    cin >> t;
    while (t--){
       solve();
    }
}
Problem: 2050C - Uninteresting Number
Language: C++23 (GCC 14-64, msys2)

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

#define int long long


int get_sum(int n){
    int sum = 0;
    while(n>0){
        sum += (n%10);
        n=n/10;
    }
    return sum;
}


int get_two(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 2) a++;
        n=n/10;
    }
    return a;
}

int get_three(int n){
    int a = 0;
    while(n>0){
        if(n%10 == 3) a++;
        n=n/10;
    }
    return a;
}


void solve(){
    int n;
    cin>>n;
    int sum = get_sum(n);
    int left = (((sum+8)/9)*9)  - sum;
    
    
    // cout<<"LEFT IS: "<<left<<endl;
    
    int find2 = get_two(n);
    int find3 = get_three(n);
    for(int i=0;i<=find2;i++){
        for(int j=0;j<=find3;j++){
            if((sum + 6*j + 2*i)%9 == 0){
                cout<<"YES\n";
                return;
            }
        }
    }
        cout<<"NO\n";
    
    
    
    
    
}


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

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

#define int long long

void solve(){
    string n;
    cin>>n;
    

    int sum = 0;
    int find2 = 0;
    int find3 = 0;
    
    
    for(auto it:n){
        sum += (it-'0');
        if((it-'0') == 2) find2++;
        if((it-'0') == 3) find3++;
    }

    for(int i=0;i<=find2;i++){
        for(int j=0;j<=find3;j++){
            if((sum + 6*j + 2*i)%9 == 0){
                cout<<"YES\n";
                return;
            }
        }
    }
        cout<<"NO\n";
    
    
    
    
    
}


signed main(){
    ios_base::sync_with_stdio(false);
    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>
using namespace std;


string a,b,c;

int dp[5010][1010];

int rec(int level , int i){
    
    int j = level - i;
    
    if (j < 0 || j > b.size()) return 1e9;
    
    
    if(level == c.size()){
        return 0;
    }

    
    if(dp[level][i] != -1)return dp[level][i];
    
    int ans = 1e9;
    
    
    if(a[i] == c[level]){
        ans = min(ans , rec(level+1 , i+1 ));
    }else if(b[j] == c[level]){
        ans = min(ans , rec(level+1 , i));
    }else{
        ans = min(ans ,1 +  min(rec(level+1 , i) , rec(level+1 , i+1 )));
    }
    
    
    
    if (i < a.size()) {
        ans = min(ans, 1 + rec(level + 1, i + 1));  
    }

    if (j < b.size()) {
        ans = min(ans, 1 + rec(level + 1, i)); 
    }
    
    return dp[level][i] =  ans;
}


void solve(){
    cin>>a>>b>>c;
    memset(dp,-1,sizeof(dp));
    cout<<rec(0,0)<<endl;
}



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

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

string a, b, c;
int dp[5010][1010];

int rec(int level, int i) {
    int j = level - i;

    if (j < 0 || j > b.size()) return 1e9; 
    if (level == c.size()) return 0; 

    if (dp[level][i] != -1) return dp[level][i];

    int ans = 1e9;

    if (i < a.size() && a[i] == c[level]) {
        ans = min(ans, rec(level + 1, i + 1));
    }

 
    if (j < b.size() && b[j] == c[level]) {
        ans = min(ans, rec(level + 1, i));
    }


    if (i < a.size()) {
        ans = min(ans, 1 + rec(level + 1, i + 1));
    }

    if (j < b.size()) {
        ans = min(ans, 1 + rec(level + 1, i));
    }

    return dp[level][i] = ans;
}

void solve() {
    cin >> a >> b >> c;
    memset(dp, -1, sizeof(dp)); 
    cout << rec(0, 0) << endl;
}

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