ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)

Previous submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int t;
  cin >> t;
  while(t--){
    string s;
    cin >> s;
    int cnt2 = 0 ;
    int cnt3 = 0 ;
    int sum = 0 ;
    for(int i = 0 ; i < s.size() ; i++){
      if(s[i] == '2'){
        cnt2++;
      }
      else if(s[i] == '3'){
        cnt3++;
      }
      sum += s[i] - '0';
      sum %= 9;
    }
    if(sum % 9 == 0){
      cout << "yes" << endl;
      continue;
    }
    bool flag = false;
    for(int i = 0 ; i <= cnt2 ; i++){
      for(int j = 0 ; j <= cnt3 ; j++){
        if((sum + (i * 2 + j * 6)) % 9 == 0){
          flag = true;
          break;
        }
      }
    }
    if(flag){
      cout << "yes" << endl;
      continue;
    }
    cout << "no" << endl;
  }
}

Submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int t;
  cin >> t;
  while(t--){
    string s;
    cin >> s;
    int cnt2 = 0 ;
    int cnt3 = 0 ;
    int sum = 0 ;
    for(int i = 0 ; i < s.size() ; i++){
      if(s[i] == '2'){
        cnt2++;
      }
      else if(s[i] == '3'){
        cnt3++;
      }
      sum += s[i] - '0';
      sum %= 9;
    }
    if(sum % 9 == 0){
      cout << "yes" << endl;
      continue;
    }
    bool flag = false;
    for(int i = 0 ; i <= cnt2 ; i++){
      for(int j = 0 ; j <= cnt3 ; j++){
        int tsum = sum ;
        tsum += (i * 2 + j * 6);
        if(tsum % 9 == 0){
          flag = true;
          break;
        }
      }
    }
    if(flag){
      cout << "yes" << endl;
      continue;
    }
    cout << "no" << endl;
  }
}
Problem: 2050C - Uninteresting Number
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 5):
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int t;
  cin >> t;
  while(t--){
    string s;
    cin >> s;
    int cnt2 = 0 ;
    int cnt3 = 0 ;
    int sum = 0 ;
    for(int i = 0 ; i < s.size() ; i++){
      if(s[i] == '2'){
        cnt2++;
      }
      else if(s[i] == '3'){
        cnt3++;
      }
      sum += s[i] - '0';
    }
    if(sum % 9 == 0){
      cout << "yes" << endl;
      continue;
    }
    bool flag = false;
    for(int i = 0 ; i <= cnt2 ; i++){
      for(int j = 0 ; j <= cnt3 ; j++){
        if((sum + (i * 2 + j * 6)) % 9 == 0){
          flag = true;
          break;
        }
      }
    }
    if(flag){
      cout << "yes" << endl;
      continue;
    }
    cout << "no" << endl;
  }
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   for(int i = 0; i < n; i++) cin >> a[i];
   ll ans = accumulate(a.begin(),a.end(),0ll);
   vector<ll>v;
   while(n>=1)
   {
       for(int i = 0; i < n-1; i++)
        v.push_back(a[i+1]-a[i]);
       ans = max(ans,abs(accumulate(v.begin(),v.end(),0ll)));
       for(int i = 0; i < n-1; i++)
        a[i] = v[i];
       v.clear();
       n--;
   }
   cout << ans << '\n';
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   for(int i = 0; i < n; i++) cin >> a[i];
   ll ans = accumulate(a.begin(),a.end(),0ll);
   vector<ll>v;
   while(n>1)
   {
       for(int i = 0; i < n-1; i++)
        v.push_back(a[i+1]-a[i]);
       ans = max(ans,abs(accumulate(v.begin(),v.end(),0ll)));
       for(int i = 0; i < n-1; i++)
        a[i] = v[i];
       v.clear();
       n--;
   }
   cout << ans << '\n';
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)


Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void findAns(vector<ll>&a)
{
    if(a.size() == 1)
    {
       ans = max(ans,(ll)a[0]);
       return;
    }
    vector<ll>b;
    for(int i = 0; i < a.size()-1; i++)
        b.push_back(a[i+1]-a[i]);
    findAns(b);
    b.clear();
    for(int i = a.size()-1; i > 0;i--)
        b.push_back(a[i-1]-a[i]);
    findAns(b);
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   ll temp = 0;
   for(int i = 0; i < n; i++)
   {
       cin >> a[i];
       temp += a[i];
   }
   findAns(a);
   cout << max(temp,ans) << '\n';

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

Previous submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void findAns(vector<ll>&a)
{
    if(a.size() == 1)
    {
       ans = max(ans,(ll)a[0]);
       return;
    }
    vector<ll>b;
    for(int i = 0; i < a.size()-1; i++)
        b.push_back(a[i+1]-a[i]);
    findAns(b);
    b.clear();
    for(int i = a.size()-1; i > 0;i--)
        b.push_back(a[i-1]-a[i]);
    findAns(b);
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   ll temp = 0;
   for(int i = 0; i < n; i++)
   {
       cin >> a[i];
       temp += a[i];
   }
   findAns(a);
   cout << max(temp,ans) << '\n';

}



Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   for(int i = 0; i < n; i++) cin >> a[i];
   ll ans = abs(accumulate(a.begin(),a.end(),0ll));
   vector<ll>v;
   while(n>=1)
   {
       for(int i = 0; i < n-1; i++)
        v.push_back(a[i+1]-a[i]);
       ans = max(ans,abs(accumulate(v.begin(),v.end(),0ll)));
       for(int i = 0; i < n-1; i++)
        a[i] = v[i];
       v.clear();
       n--;
   }
   cout << ans << '\n';
}
Problem: 2062C - Cirno and Operations
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   for(int i = 0; i < n; i++) cin >> a[i];
   ll ans = abs(accumulate(a.begin(),a.end(),0ll));
   vector<ll>v;
   while(n>=1)
   {
       for(int i = 0; i < n-1; i++)
        v.push_back(a[i+1]-a[i]);
       ans = max(ans,abs(accumulate(v.begin(),v.end(),0ll)));
       for(int i = 0; i < n-1; i++)
        a[i] = v[i];
       v.clear();
       n--;
   }
   cout << ans << '\n';
}



Submission (verdict: Wrong answer on test 1):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();
ll ans = -1e18;
int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<ll>a(n);
   for(int i = 0; i < n; i++) cin >> a[i];
   ll ans = accumulate(a.begin(),a.end(),0ll);
   vector<ll>v;
   while(n>=1)
   {
       for(int i = 0; i < n-1; i++)
        v.push_back(a[i+1]-a[i]);
       ans = max(ans,abs(accumulate(v.begin(),v.end(),0ll)));
       for(int i = 0; i < n-1; i++)
        a[i] = v[i];
       v.clear();
       n--;
   }
   cout << ans << '\n';
}
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;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i] > maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   int ans = maxi;
   for(int i = 0; i < element[num].size(); i++)
      cnt[element[num][i]]--;
   maxi = 0;
   for(int i = 1; i <= n; i++)
      if(cnt[i] > maxi) maxi = cnt[i];
   ans += (maxi-1);
   cout << ans << '\n';
}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int cnt0 = 0;
   for(int i = 1; i <=n; i++)
   {
       if(cnt[i] == 1)
        cnt0++;
   }
   if(cnt0 == 2 && n >= 5)
   {
       cout << "3\n";
       return;
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i] > maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   int ans = maxi;
   for(int i = 0; i < element[num].size(); i++)
      cnt[element[num][i]]--;
   maxi = 0;
   for(int i = 1; i <= n; i++)
      if(cnt[i] > maxi) maxi = cnt[i];
   ans += (maxi-1);
   cout << ans << '\n';
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)

Previous submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i]>=maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   int ans = maxi;
   for(int i = 0; i < element[num].size(); i++)
      cnt[element[num][i]]--;
   maxi = 0;
   for(int i = 1; i <= n; i++)
      if(cnt[i]>=maxi) maxi = cnt[i];
   ans += (maxi-1);
   cout << ans << '\n';
}



Submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i] > maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   int ans = maxi;
   for(int i = 0; i < element[num].size(); i++)
      cnt[element[num][i]]--;
   maxi = 0;
   for(int i = 1; i <= n; i++)
      if(cnt[i] > maxi) maxi = cnt[i];
   ans += (maxi-1);
   cout << ans << '\n';
}
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;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int cnt0 = 0;
   for(int i = 1; i <=n; i++)
   {
       if(cnt[i] == 1)
        cnt0++;
   }
   if(cnt0 == 2 && n >= 5)
   {
       cout << "3\n";
       return;
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i] > maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   int ans = maxi;
   for(int i = 0; i < element[num].size(); i++)
      cnt[element[num][i]]--;
   maxi = 0;
   for(int i = 1; i <= n; i++)
      if(cnt[i] > maxi) maxi = cnt[i];
   ans += (maxi-1);
   cout << ans << '\n';
}



Submission (verdict: Accepted):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       maxi = max(maxi,cnt[i]);
   }
   vector<int>maxnode;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i] == maxi)
        maxnode.push_back(i);
       if(maxnode.size() >= 2)
        break;
   }
   int fans = 0;
   for(int i = 0; i < min(2,(int)maxnode.size()); i++)
   {
       int ans = cnt[maxnode[i]];
       cnt[maxnode[i]] = -1;
       for(int j = 0; j < element[maxnode[i]].size(); j++)
          cnt[element[maxnode[i]][j]]--;
       int smax = 0;
       for(int j = 1; j <= n; j++)
          smax = max(cnt[j],smax);
       fans = max(fans, ans + smax -1);
       cnt[maxnode[i]] = maxi;
       for(int j = 0; j < element[maxnode[i]].size(); j++)
          cnt[element[maxnode[i]][j]]++;
   }
   cout << fans << '\n';
}
Problem: 2063C - Remove Exactly Two
Language: C++17 (GCC 7-32)


Submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i]>=maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   for(int i = 0; i < element[num].size(); i++)
   {
       cnt[element[num][i]]--;
   }
   maxi = 0;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i]>=maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   for(int i = 0; i < element[num].size(); i++)
   {
       cnt[element[num][i]]--;
   }
   int ans = 0,cnt1 = 0;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i] == 0)
        ans++;
       if(cnt[i] == 1)
        cnt1++;
   }
   ans += (cnt1/2);
   cout << ans << '\n';

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

Previous submission (verdict: Wrong answer on test 3):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i]>=maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   for(int i = 0; i < element[num].size(); i++)
   {
       cnt[element[num][i]]--;
   }
   maxi = 0;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i]>=maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   for(int i = 0; i < element[num].size(); i++)
   {
       cnt[element[num][i]]--;
   }
   int ans = 0,cnt1 = 0;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i] == 0)
        ans++;
       if(cnt[i] == 1)
        cnt1++;
   }
   ans += (cnt1/2);
   cout << ans << '\n';

}



Submission (verdict: Wrong answer on test 4):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fios(); ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

void solution();

int main()
{
    int t = 1;
    fios();
    cin >> t;
    while(t--)
        solution();
}
void solution()
{
   int n; cin >> n;
   vector<vector<int>>element(n+1);
   vector<int>cnt(n+1,0);
   for(int i = 0; i < n-1; i++)
   {
       int a,b; cin >> a >> b;
       cnt[a]++;
       cnt[b]++;
       element[a].push_back(b);
       element[b].push_back(a);
   }
   int maxi = 0,num;
   for(int i = 1; i <= n; i++)
   {
       if(cnt[i]>=maxi)
       {
          maxi = cnt[i];
          num = i;
       }
   }
   cnt[num] = -1;
   int ans = maxi;
   for(int i = 0; i < element[num].size(); i++)
      cnt[element[num][i]]--;
   maxi = 0;
   for(int i = 1; i <= n; i++)
      if(cnt[i]>=maxi) maxi = cnt[i];
   ans += (maxi-1);
   cout << ans << '\n';
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

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

using namespace std;

#define int long long



int n;

string c;



int dp[1001][1001];

int f(string &a, string &b, int i, int j)

{

    if(i+j == n)

    {

        return 0;

    }

    

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







    int ans=INT_MAX;

    if(i<a.size())

    {

        //choosing i

        if(a[i]!=c[i+j]) 

        {

            ans= min({ans, 1+ f(a,b,i,j+1), 1+ f(a,b,i+1,j)});

        }

        else

        {

            ans= min({ans, 1+f(a,b,i,j+1), f(a,b,i+1,j)});

        }

    }



    if(j<b.size())

    {

        //choosing j

         if(b[j]!=c[i+j]) 

        {

            ans= min({ans, 1+ f(a,b,i,j+1), 1+ f(a,b,i+1,j)});

        }

        else

        {

            ans= min({ans, 1+f(a,b,i+1,j), f(a,b,i,j+1)});

        }

    }



    return dp[i][j]= ans;



}



void solve()

{

    memset(dp, -1, sizeof(dp));

    string a, b; cin>>a>>b>>c;

    n= c.size();



    cout<<f(a, b, 0, 0)<<endl;

}



signed main()

{

    int t; cin>>t;

    while(t--) solve();

}

Submission (verdict: Accepted):


#include <bits/stdc++.h>

using namespace std;

#define int long long



int n;

string c;



int dp[1001][1001];

int f(string &a, string &b, int i, int j)

{

    if(i+j==n) return 0;

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

    

    int ans=INT_MAX;

    if(i<a.size()) 

    {

        if(a[i]==c[i+j]) ans= f(a,b,i+1,j);

        ans= min(ans, 1+f(a,b,i+1, j));

    }

    if(j<b.size())

    {

        if(b[j]==c[i+j]) ans= min(ans, f(a,b,i,j+1));

        ans= min(ans, 1+f(a,b,i,j+1));

    }

    

    return dp[i][j]= ans;

}



void solve()

{

    memset(dp, -1, sizeof(dp));

    string a, b; cin>>a>>b>>c;

    n= c.size();



    cout<<f(a, b, 0, 0)<<endl;

}



signed main()

{

    int t; cin>>t;

    while(t--) solve();

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

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

using namespace std;

#define int long long



int n;

string c;



int dp[1001][1001];

int f(string &a, string &b, int i, int j)

{

    if(i+j == n)

    {

        return 0;

    }

    

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







    int ans=INT_MAX;

    if(i<a.size())

    {

        //choosing i

        if(a[i]!=c[i+j]) ans= min(ans, 1+ f(a, b, i+1, j));

        else ans= f(a, b, i+1, j);

    }



    if(j<b.size())

    {

        //choosing j

        if(b[j]!=c[i+j]) ans= min(ans, 1+ f(a, b, i, j+1));

        else ans= f(a, b, i, j+1);

    }



    return dp[i][j]= ans;



}



void solve()

{

    memset(dp, -1, sizeof(dp));

    string a, b; cin>>a>>b>>c;

    n= c.size();



    cout<<f(a, b, 0, 0)<<endl;

}



signed main()

{

    int t; cin>>t;

    while(t--) solve();

}

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

using namespace std;

#define int long long



int n;

string c;



int dp[1001][1001];

int f(string &a, string &b, int i, int j)

{

    if(i+j == n)

    {

        return 0;

    }

    

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







    int ans=INT_MAX;

    if(i<a.size())

    {

        //choosing i

        if(a[i]!=c[i+j]) 

        {

            ans= min({ans, 1+ f(a,b,i,j+1), 1+ f(a,b,i+1,j)});

        }

        else

        {

            ans= min({ans, 1+f(a,b,i,j+1), f(a,b,i+1,j)});

        }

    }



    if(j<b.size())

    {

        //choosing j

         if(b[j]!=c[i+j]) 

        {

            ans= min({ans, 1+ f(a,b,i,j+1), 1+ f(a,b,i+1,j)});

        }

        else

        {

            ans= min({ans, 1+f(a,b,i+1,j), f(a,b,i,j+1)});

        }

    }



    return dp[i][j]= ans;



}



void solve()

{

    memset(dp, -1, sizeof(dp));

    string a, b; cin>>a>>b>>c;

    n= c.size();



    cout<<f(a, b, 0, 0)<<endl;

}



signed main()

{

    int t; cin>>t;

    while(t--) solve();

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


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

using namespace std;

#define int long long



int n;

string c;



int dp[1001][1001];

int f(string &a, string &b, int i, int j)

{

    if(i+j == n)

    {

        return 0;

    }

    

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







    int ans=INT_MAX;

    if(i<a.size())

    {

        //choosing i

        if(a[i]!=c[i+j]) ans= min(ans, 1+ f(a, b, i+1, j));

        else ans= f(a, b, i+1, j);

    }



    if(j<b.size())

    {

        //choosing j

        if(b[j]!=c[i+j]) ans= min(ans, 1+ f(a, b, i, j+1));

        else ans= f(a, b, i, j+1);

    }



    return dp[i][j]= ans;



}



void solve()

{

    memset(dp, -1, sizeof(dp));

    string a, b; cin>>a>>b>>c;

    n= c.size();



    cout<<f(a, b, 0, 0)<<endl;

}



signed main()

{

    int t; cin>>t;

    while(t--) solve();

}