ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)


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

using namespace std;

#define ll long long 



void input(vector<int>&a,int n){

  

  a.resize(n);

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

    cin>>a[i];

  }



}

void printvec(vector<int>&a){

  for(auto num :a){

    cout<<num<<' ';

  }cout<<endl;

}



int main(){

   int test;

   cin>>test;

   while(test--){

    int n,l,r;

    cin>>n>>l>>r;

    vector<int>v(n);

    input(v,n);

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

    int ans=r-l+1;

    int sum=0;

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

      sum+=v[i];

    }

    cout<<sum<<endl;









}}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

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

using namespace std;

#define ll long long 



void input(vector<int>&a,int n){

  

  a.resize(n);

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

    cin>>a[i];

  }



}

void printvec(vector<int>&a){

  for(auto num :a){

    cout<<num<<' ';

  }cout<<endl;

}



int main(){

   int test;

   cin>>test;

   while(test--){

    int n,l,r;

    cin>>n>>l>>r;

    vector<int>v(n);

    input(v,n);

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

    int ans=r-l+1;

    int sum=0;

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

      sum+=v[i];

    }

    cout<<sum<<endl;









}}



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

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

}
void printvec(vector<int>&a){
  for(auto num :a){
    cout<<num<<' ';
  }cout<<endl;
}

int main(){
   int test;
   cin>>test;
   while(test--){
    int n,l,r;
    cin>>n>>l>>r;
    vector<int>v(n);
    input(v,n);
    vector<int>b,c;
    r--;l--;
    for(int i=l;i<n;i++){
       b.push_back(v[i]);
    }
for(int i=0;i<=r;i++){
  c.push_back(v[i]);
}
sort(b.begin(),b.end());
sort(c.begin(),c.end());

ll sum1 = accumulate(b.begin(),b.begin()+(int)(r-l+1),0);
ll sum2 = accumulate(c.begin(),c.begin()+(int)(r-l+1),0);
cout<<min(sum1,sum2)<<endl;
    
    



}}
Problem: 2063B - Subsequence Update
Language: C++23 (GCC 14-64, msys2)

Previous submission (verdict: Compilation error):
#include <bits/stdc++.h>
using namespace std;
#define ll long long 

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

}
void printvec(vector<int>&a){
  for(auto num :a){
    cout<<num<<' ';
  }cout<<endl;
}

int main(){
   int test;
   cin>>test;
   while(test--){
    ll n,l,r;
    cin>>n>>l>>r;
    vector<ll>v(n);
    input(v,n);
    vector<ll>b,c;
    r--;l--;
    for(ll i=l;i<n;i++){
       b.push_back(v[i]);
    }
for(ll i=0;i<=r;i++){
  c.push_back(v[i]);
}
sort(b.begin(),b.end());
sort(c.begin(),c.end());

ll sum1 = accumulate(b.begin(),b.begin()+(int)(r-l+1),0);
ll sum2 = accumulate(c.begin(),c.begin()+(int)(r-l+1),0);
cout<<min(sum1,sum2) <<endl;
    
    



}}


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

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

}
void printvec(vector<int>&a){
  for(auto num :a){
    cout<<num<<' ';
  }cout<<endl;
}

int main(){
   int test;
   cin>>test;
   while(test--){
    ll n,l,r;
    cin>>n>>l>>r;
    vector<ll>v(n);
    input(v,n);
    vector<ll>b,c;
    r--;l--;
    for(ll i=l;i<n;i++){
       b.push_back(v[i]);
    }
for(ll i=0;i<=r;i++){
  c.push_back(v[i]);
}
sort(b.begin(),b.end());
sort(c.begin(),c.end());

ll sum1 = accumulate(b.begin(),b.begin()+(int)(r-l+1),0);
ll sum2 = accumulate(c.begin(),c.begin()+(int)(r-l+1),0);
cout<<min(sum1,sum2) <<endl;
    
    



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


Submission (verdict: Time limit exceeded on test 2):
#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long
#include <algorithm>

using namespace std;

const ll oo = 1e9;

ll ll_max(ll a, ll b){return a>b?a:b;}

ll get_max(vector<int> &arr, ll max_sum){
    // Caso base
    if (arr.size() == 1) return ll_max(max_sum, arr[0]);

    // Recursao com vector reduzido e vector invertido reduzido
    
    // Somas
    // Soma vector
    ll soma = 0;
    for (size_t i=0; i<arr.size(); i++){
        soma += arr[i];
    }

    // Soma vector invertido
    vector<int> inv_arr(arr);
    reverse(inv_arr.begin(), inv_arr.end());
    ll soma_inv = 0;
    for (size_t i=0; i<inv_arr.size(); i++){
        soma_inv += inv_arr[i];
    }  
    
    // Inversoes
    // Vector reduzido
    vector<int> arr_1(arr.size()-1);
    for (size_t i=0; i < arr_1.size(); i++){
        arr_1[i] = arr[i+1] - arr[i];
    }
    // Vector invertido reduzido
    vector<int> inv_arr_1(inv_arr.size()-1);
    for (size_t i=0; i < inv_arr_1.size(); i++){
        inv_arr_1[i] = inv_arr[i+1] - inv_arr[i];
    }
    
    ll new_max = ll_max(ll_max(soma, soma_inv), max_sum);
    return ll_max(get_max(inv_arr_1, new_max), get_max(arr_1, new_max));
}
 
int main(){
    BOOST

    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        vector<int> arr(n);
        for (auto &v:arr){ cin >> v; }

        cout << get_max(arr, -oo) << "\n";
    }

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

Previous submission (verdict: Wrong answer on test 2):
#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

// Converter vector de long long para string para memoizacao
string vecToKey(const vector<ll>& arr) {
    string key;
    for (ll x : arr) {
        key += to_string(x) + ",";
    }
    return key;
}

unordered_map<string, ll> memo;

ll F(const vector<ll> &arr) {
    // Casos base
    string key = vecToKey(arr);
    if (memo.count(key))
        return memo[key];       // memoizacao
    
    if (arr.size() == 1)
        return memo[key] = arr[0];

    // Recursao    
    // Soma do original
    ll sum1 = 0;
    for (int x : arr)
        sum1 += x;
    
    // Soma do invertido
    vector<ll> rev(arr);
    reverse(rev.begin(), rev.end());
    ll sum2 = 0;
    for (int x : rev)
        sum2 += x;
    
    // Sequencia original
    vector<ll> diff1;
    for (size_t i = 0; i < arr.size()-1; i++){
        diff1.push_back(arr[i+1] - arr[i]);
    }
    
    // Sequencia invertida
    vector<ll> diff2;
    for (size_t i = 0; i < rev.size()-1; i++){
        diff2.push_back(rev[i+1] - rev[i]);
    }
    
    ll ans = max({ sum1, sum2, F(diff1), F(diff2) });
    memo[key] = ans;
    return ans;
}
 
int main(){
    BOOST
    
    int t;
    cin >> t;
    while (t--){
        int n;
        cin >> n;
        vector<ll> arr(n);
        for (int i = 0; i < n; i++){
            cin >> arr[i];
        }
        memo.clear();
        cout << F(arr) << "\n";
    }
    return 0;
}


Submission (verdict: Accepted):
/**
 * SUGERIDO:
 */

#include <bits/stdc++.h>
#define BOOST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long

using namespace std;

int main(){
    BOOST
    
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        vector<ll> arr(n);
        for (int i = 0; i < n; i++){
            cin >> arr[i];
        }
        
        // Se n = 1, nao precisa processar
        if(n == 1){
            cout << arr[0] << "\n";
            continue;
        }
        
        // Se k = 0: nao calcula subtracoes
        ll sum0 = 0;
        for (ll x : arr)
            sum0 += x;
        ll best = sum0; // Nota, nao inverter para k=0
        
        vector<ll> current = arr;
        
        // Para cada k de 1 ate n-1, aplicar operacao 2 ("Replace the sequence with its difference sequence")
        for (int k = 1; k < n; k++){
            vector<ll> next;
            for (int i = 0; i < (int)current.size() - 1; i++){
                next.push_back(current[i+1] - current[i]);
            }
            // Soma da diferenca
            ll s = 0;
            for (ll x : next)
                s += x;
            
            // Para k >= 1 ver com o sinal trocado (se s negativo, inversao da positivo - llabs)
            best = max(best, llabs(s));
            
            // Proxima iteracao
            current = next;
        }
        
        cout << best << "\n";
    }
    return 0;
}
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;



void noTimeLimit()

{

cin.tie(0);

cin.sync_with_stdio(0);

cout.tie(0);

cout.sync_with_stdio(0);

}

#define ll long long

#define ss string

#define dd double

#define yes "YES"

#define v vector<ll>



#define no "NO"

#define el "\n"

#define fr(x, i, n) for (ll i = x; i < n; i++)

#define frr(i, n) for (ll i = n - 1; i >= 0; i--)

#define all(a) a.begin(), a.end()

#define allr(a) a.rbegin(), a.rend()

#define pi 3.141592653589793238462643383279502884197

#define ee 2.718281828459045

const ll mod = 1e9 + 7;

int inf = 1e9;



void solve()

{

int n;

cin >> n;

vector<int> a(n);

fr(0, i, n) cin >> a[i];

bool f = 1;

if (a[0] == *max_element(all(a)))

return void(cout << no);

fr(1, i, n - 1)

{

if ((a[i] > a[i + 1] and a[i] < a[i - 1]) or (a[i] > a[i + 1] and a[i] - a[i + 1] > a[i - 1]) or (a[i] > a[i - 1] and a[i] - a[i - 1] > a[i + 1]))

f = 0;

}

if (f)

cout << yes;

else

cout << no;

}



int main()

{

// freopen("input.txt", "r", stdin);

// freopen("output.txt", "w", stdout);

noTimeLimit();

int testCase = 1;

cin >> testCase;

while (testCase--)

{

solve();

cout << el;

}

return 0;

}

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



using namespace std;



void noTimeLimit()

{

cin.tie(0);

cin.sync_with_stdio(0);

cout.tie(0);

cout.sync_with_stdio(0);

}

#define ll long long

#define ss string

#define dd double

#define yes "YES"

#define v vector<ll>



#define no "NO"

#define el "\n"

#define fr(x, i, n) for (ll i = x; i < n; i++)

#define frr(i, n) for (ll i = n - 1; i >= 0; i--)

#define all(a) a.begin(), a.end()

#define allr(a) a.rbegin(), a.rend()

#define pi 3.141592653589793238462643383279502884197

#define ee 2.718281828459045

const ll mod = 1e9 + 7;

int inf = 1e9;



void solve()

{

int n;

cin >> n;

vector<int> a(n);

fr(0, i, n) cin >> a[i];

fr(1, i, n)

{

int minn = min(a[i], a[i - 1]);

a[i] -= minn, a[i - 1] -= minn;

}

bool f = 1;

fr(0, i, n - 1)

{

if (a[i] > a[i + 1])

f = 0;

}

if (f)

cout << yes;

else

cout << no;

}



int main()

{

// freopen("input.txt", "r", stdin);

// freopen("output.txt", "w", stdout);

noTimeLimit();

int testCase = 1;

cin >> testCase;

while (testCase--)

{

solve();

cout << el;

}

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;



void noTimeLimit()

{

cin.tie(0);

cin.sync_with_stdio(0);

cout.tie(0);

cout.sync_with_stdio(0);

}

#define ll long long

#define ss string

#define dd double

#define yes "YES"

#define v vector<ll>



#define no "NO"

#define el "\n"

#define fr(x, i, n) for (ll i = x; i < n; i++)

#define frr(i, n) for (ll i = n - 1; i >= 0; i--)

#define all(a) a.begin(), a.end()

#define allr(a) a.rbegin(), a.rend()

#define pi 3.141592653589793238462643383279502884197

#define ee 2.718281828459045

const ll mod = 1e9 + 7;

int inf = 1e9;



void solve()

{

int n;

cin >> n;

vector<int> a(n);

fr(0, i, n) cin >> a[i];

bool f = 1;

fr(1, i, n - 1)

{

if (a[i] > a[i + 1] and a[i] < a[i - 1])

f = 0;

}

if (f)

cout << yes;

else

cout << no;

}



int main()

{

// freopen("input.txt", "r", stdin);

// freopen("output.txt", "w", stdout);

noTimeLimit();

int testCase = 1;

cin >> testCase;

while (testCase--)

{

solve();

cout << el;

}

return 0;

}
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;



void noTimeLimit()

{

cin.tie(0);

cin.sync_with_stdio(0);

cout.tie(0);

cout.sync_with_stdio(0);

}

#define ll long long

#define ss string

#define dd double

#define yes "YES"

#define v vector<ll>



#define no "NO"

#define el "\n"

#define fr(x, i, n) for (ll i = x; i < n; i++)

#define frr(i, n) for (ll i = n - 1; i >= 0; i--)

#define all(a) a.begin(), a.end()

#define allr(a) a.rbegin(), a.rend()

#define pi 3.141592653589793238462643383279502884197

#define ee 2.718281828459045

const ll mod = 1e9 + 7;

int inf = 1e9;



void solve()

{

int n;

cin >> n;

vector<int> a(n);

fr(0, i, n) cin >> a[i];

bool f = 1;

fr(1, i, n - 1)

{

if ((a[i] > a[i + 1] and a[i] < a[i - 1]) or (a[i] > a[i + 1] and a[i] - a[i + 1] > a[i - 1]) or (a[i] > a[i - 1] and a[i] - a[i - 1] > a[i + 1]))

f = 0;

}

if (f)

cout << yes;

else

cout << no;

}



int main()

{

// freopen("input.txt", "r", stdin);

// freopen("output.txt", "w", stdout);

noTimeLimit();

int testCase = 1;

cin >> testCase;

while (testCase--)

{

solve();

cout << el;

}

return 0;

}

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



using namespace std;



void noTimeLimit()

{

cin.tie(0);

cin.sync_with_stdio(0);

cout.tie(0);

cout.sync_with_stdio(0);

}

#define ll long long

#define ss string

#define dd double

#define yes "YES"

#define v vector<ll>



#define no "NO"

#define el "\n"

#define fr(x, i, n) for (ll i = x; i < n; i++)

#define frr(i, n) for (ll i = n - 1; i >= 0; i--)

#define all(a) a.begin(), a.end()

#define allr(a) a.rbegin(), a.rend()

#define pi 3.141592653589793238462643383279502884197

#define ee 2.718281828459045

const ll mod = 1e9 + 7;

int inf = 1e9;



void solve()

{

int n;

cin >> n;

vector<int> a(n);

fr(0, i, n) cin >> a[i];

bool f = 1;

if (a[0] == *max_element(all(a)))

return void(cout << no);

fr(1, i, n - 1)

{

if ((a[i] > a[i + 1] and a[i] < a[i - 1]) or (a[i] > a[i + 1] and a[i] - a[i + 1] > a[i - 1]) or (a[i] > a[i - 1] and a[i] - a[i - 1] > a[i + 1]))

f = 0;

}

if (f)

cout << yes;

else

cout << no;

}



int main()

{

// freopen("input.txt", "r", stdin);

// freopen("output.txt", "w", stdout);

noTimeLimit();

int testCase = 1;

cin >> testCase;

while (testCase--)

{

solve();

cout << el;

}

return 0;

}
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;



void noTimeLimit()

{

cin.tie(0);

cin.sync_with_stdio(0);

cout.tie(0);

cout.sync_with_stdio(0);

}

#define ll long long

#define ss string

#define dd double

#define yes "YES"

#define v vector<ll>



#define no "NO"

#define el "\n"

#define fr(x, i, n) for (ll i = x; i < n; i++)

#define frr(i, n) for (ll i = n - 1; i >= 0; i--)

#define all(a) a.begin(), a.end()

#define allr(a) a.rbegin(), a.rend()

#define pi 3.141592653589793238462643383279502884197

#define ee 2.718281828459045

const ll mod = 1e9 + 7;

int inf = 1e9;



void solve()

{

int n;

cin >> n;

vector<int> a(n);

fr(0, i, n) cin >> a[i];

bool f = 1;

fr(1, i, n - 1)

{

if (a[i] > a[i + 1] and a[i] < a[i - 1])

f = 0;

}

if (f)

cout << yes;

else

cout << no;

}



int main()

{

// freopen("input.txt", "r", stdin);

// freopen("output.txt", "w", stdout);

noTimeLimit();

int testCase = 1;

cin >> testCase;

while (testCase--)

{

solve();

cout << el;

}

return 0;

}

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



using namespace std;



void noTimeLimit()

{

cin.tie(0);

cin.sync_with_stdio(0);

cout.tie(0);

cout.sync_with_stdio(0);

}

#define ll long long

#define ss string

#define dd double

#define yes "YES"

#define v vector<ll>



#define no "NO"

#define el "\n"

#define fr(x, i, n) for (ll i = x; i < n; i++)

#define frr(i, n) for (ll i = n - 1; i >= 0; i--)

#define all(a) a.begin(), a.end()

#define allr(a) a.rbegin(), a.rend()

#define pi 3.141592653589793238462643383279502884197

#define ee 2.718281828459045

const ll mod = 1e9 + 7;

int inf = 1e9;



void solve()

{

int n;

cin >> n;

vector<int> a(n);

fr(0, i, n) cin >> a[i];

bool f = 1;

fr(1, i, n - 1)

{

if ((a[i] > a[i + 1] and a[i] < a[i - 1]) or (a[i] > a[i + 1] and a[i] - a[i + 1] > a[i - 1]) or (a[i] > a[i - 1] and a[i] - a[i - 1] > a[i + 1]))

f = 0;

}

if (f)

cout << yes;

else

cout << no;

}



int main()

{

// freopen("input.txt", "r", stdin);

// freopen("output.txt", "w", stdout);

noTimeLimit();

int testCase = 1;

cin >> testCase;

while (testCase--)

{

solve();

cout << el;

}

return 0;

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

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


int helper(int i, int j, string& a,string& b,string& c){
    if(i==a.size() && j == b.size()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int res = 1e9;int pos = i+j;
    if(i<a.size()){
        int cost = helper(i+1,j,a,b,c)+(a[i]!=c[pos]);
        res = min(res,cost);
    }
    if(j<b.size()){
        int cost = helper(i,j+1,a,b,c)+(b[j]!=c[pos]);
        res = min(res,cost);
    }
    return dp[i][j]=res;
}
int main(){
    int t;cin>>t;
    while(t--){
        string a,b,c;cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        dp.assign(n+1,vector<int>(m+1,-1));
        cout<<helper(0,0,a,b,b)<<endl;
    }
    return 0;
}

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


int helper(int i, int j, string& a,string& b,string& c){
    if(i==a.size() && j == b.size()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int res = 1e9;int pos = i+j;
    if(i<a.size()){
        int cost = helper(i+1,j,a,b,c)+(a[i]!=c[pos]);
        res = min(res,cost);
    }
    if(j<b.size()){
        int cost = helper(i,j+1,a,b,c)+(b[j]!=c[pos]);
        res = min(res,cost);
    }
    return dp[i][j]=res;
}
int main(){
    int t;cin>>t;
    while(t--){
        string a,b,c;cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        dp.assign(n+1,vector<int>(m+1,-1));
        cout<<helper(0,0,a,b,c)<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)


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


int helper(int i, int j, string& a,string& b,string& c){
    if(i==a.size() && j == b.size()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int res = 1e9;int pos = i+j;
    if(i<a.size()){
        int cost = helper(i+1,j,a,b,c)+(a[i]!=c[pos]);
        res = min(res,cost);
    }
    if(j<b.size()){
        int cost = helper(i,j+1,a,b,c)+(b[j]!=c[pos]);
        res = min(res,cost);
    }
    return dp[i][j];
}
int main(){
    int t;cin>>t;
    while(t--){
        string a,b,c;cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        dp.assign(n+1,vector<int>(m+1,-1));
        cout<<helper(0,0,a,b,b)<<endl;
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: C++20 (GCC 13-64)

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


int helper(int i, int j, string& a,string& b,string& c){
    if(i==a.size() && j == b.size()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int res = 1e9;int pos = i+j;
    if(i<a.size()){
        int cost = helper(i+1,j,a,b,c)+(a[i]!=c[pos]);
        res = min(res,cost);
    }
    if(j<b.size()){
        int cost = helper(i,j+1,a,b,c)+(b[j]!=c[pos]);
        res = min(res,cost);
    }
    return dp[i][j];
}
int main(){
    int t;cin>>t;
    while(t--){
        string a,b,c;cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        dp.assign(n+1,vector<int>(m+1,-1));
        cout<<helper(0,0,a,b,b)<<endl;
    }
    return 0;
}

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


int helper(int i, int j, string& a,string& b,string& c){
    if(i==a.size() && j == b.size()){
        return 0;
    }
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    int res = 1e9;int pos = i+j;
    if(i<a.size()){
        int cost = helper(i+1,j,a,b,c)+(a[i]!=c[pos]);
        res = min(res,cost);
    }
    if(j<b.size()){
        int cost = helper(i,j+1,a,b,c)+(b[j]!=c[pos]);
        res = min(res,cost);
    }
    return dp[i][j]=res;
}
int main(){
    int t;cin>>t;
    while(t--){
        string a,b,c;cin>>a>>b>>c;
        int n = a.size();
        int m = b.size();
        dp.assign(n+1,vector<int>(m+1,-1));
        cout<<helper(0,0,a,b,b)<<endl;
    }
    return 0;
}
Problem: 2050D - Digital string maximization
Language: Python 3

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



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+j:

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1



    print("".join([str(digit) for digit in s]))

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



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+j-1:

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1

            print("".join([str(digit) for digit in s]))



    print("".join([str(digit) for digit in s]))
Problem: 2050D - Digital string maximization
Language: Python 3

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



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+j-1:

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1



    print("".join([str(digit) for digit in s]))

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



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+((j+i)-maxPos):

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1



    print("".join([str(digit) for digit in s]))
Problem: 2050D - Digital string maximization
Language: Python 3


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



for _ in range(t):

    word = input()

    s = [int(digit) for digit in word]

    l = len(s)



    for i in range(l):

        findMax= s[i]

        maxPos = i

        for j in range(10):

            if s[i+j]>findMax+j:

                findMax = s[i+j]

                maxPos = i+j

            

            if l-(i+j)-1==0:

                break



        for j in range(maxPos-i):

            temp = s[maxPos-1]

            s[maxPos-1] = s[maxPos]-1

            s[maxPos] = temp

            maxPos-=1



    print("".join([str(digit) for digit in s]))