ShaysXIA/CodeInsightBench huggingface dataset:
Problem: 2061D - Kevin and Numbers
Language: c++17 

Solution 1 (runtime: 374 ms):
#include<bits/stdc++.h>
using namespace std;
#define ll long long

ll power(ll a,ll n,ll m) {
    if(n==0) return 1;
    ll u = power(a,n/2,m);
    u = (u*u)%m;
    if(n%2) u = (u*a)%m;
    return u;
}

ll gcd(ll a,ll b) {
    if(b==0) return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b) {
    return (a*b)/gcd(a,b);
}


bool isPrime(ll n) {
    if(n==1) return false;
    for(ll i=2;i*i<=n;i++) {
        if(n%i==0) return false;
    }
    return true;
}

map<ll,ll> primeFactors(ll n) {
    map<ll,ll> mp;
    for(ll i=2;i*i<=n;i++) {
        while(n%i==0) {
            mp[i]++;
            n /= i;
        }
    }
    if(n>1) mp[n]++;
    return mp;
}

vector<ll> sieve(ll n) {
    vector<ll> prime(n+1,1);
    prime[0] = prime[1] = 0;
    for(ll i=2;i*i<=n;i++) {
        if(prime[i]) {
            for(ll j=i*i;j<=n;j+=i) {
                prime[j] = 0;
            }
        }
    }
    return prime;
}

void solve() {
    int n,m;
    cin>>n>>m;
    vector<ll> a(n),b(m);
    int sum1=0,sum2=0;
    for(int i=0;i<n;i++) cin>>a[i] ,sum1+=a[i];
    for(int i=0;i<m;i++) cin>>b[i] , sum2+=b[i];
    if(sum1!=sum2) {
        cout<<"No"<<endl;
        return;
    }
    multiset<int> s1,s2;
    for(int i=0;i<n;i++){
        s1.insert(a[i]);
    }
    for(int i=0;i<m;i++){
        s2.insert(b[i]);
    }
    // cout<<"HELLO"<<endl;
    int k=0;
    while(k<n-m && s1.size()>0 && s2.size()>0){
        auto it1 = s2.end();
        it1--;
        ll x = *it1;
        if(s1.find(x)==s1.end()){
         s2.erase(it1);
         s2.insert((x+1)/2);
         s2.insert(x/2);
         k++;
        }
        else {
            s2.erase(it1);
            s1.erase(s1.find(x));
        }
}
    if(s1==s2) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

Solution 2 (runtime: 327 ms):
#include <bits/stdc++.h>

#define ar array

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

using namespace std;

typedef long long ll;



void solve() {

    int n, m;

    cin >> n >> m;

    multiset <int> a;

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

        int x;

        cin >> x;

        a.insert(x);

    }

    int ok = 1;

    function <bool(int)> check = [&] (int x) -> bool {

        if (x == 0)

            return false;

        if (a.count(x)) {

            a.erase(a.find(x));

            return true;

        }

        int m = x >> 1;

        if (check(m))

            return check(x - m);

        return false;

    };

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

        int x; cin >> x;

        if (ok)

            ok &= check(x);

    }

    if (ok && a.empty())

        cout << "Yes\n";

    else

        cout << "No\n";

}



int main() {

    ios::sync_with_stdio(false);

    cin.tie(0); cout.tie(0);

    int t = 1;

    cin >> t;

    while (t--)

        solve();    

}
Problem: 2057C - Trip to the Olympiad
Language: c++17 

Solution 1 (runtime: 78 ms):
#include<iostream>
#define ll long long
#define getbit(x,y) ((x>>y)&1)
using namespace std;
int main() {
	int t;
	cin>>t;
	while(t--){
		ll l,r,now=0;
		cin>>l>>r;
		for(ll i=30;i>=0;i--) {
			if(getbit(l,i)!=getbit(r,i)) {
				ll x=(1ll<<i)-1,y=0;
				x+=now,y+=now+(1ll<<i);
				printf("%lld %lld ",x,y);
				if(x!=l&&y!=l) printf("%lld\n",l);
				else printf("%lld\n",r);
				break; 
			}
		now+=getbit(l,i)?(1ll<<i):0;
		}
	}
}

Solution 2 (runtime: 108 ms):
#include <bits/stdc++.h>
using namespace std;
#define pb push_back

typedef long long ll;

ll arr[30];

void solve(){
    ll a,b,c,l,r;
    cin>>l>>r;
    
    if(r-l==2){
    cout<<l<<" "<<l+1<<" "<<r<<endl;
    }
    
    else{
    ll sum=0;
    
    ll lo,hi;
    if(l>0)
    lo=log2(l);
    else
    lo=0;
    hi=log2(r);
    
    // cout<<lo<<" "<<hi<<endl;
    
    if(pow(2,hi)==r){
     a=r-2;
     b=r;
     c=r-1;
    }
    
    else if(hi-lo>0){
        a=pow(2,hi)-1;
        b=pow(2,hi);
        c=pow(2,hi)+1;
    }
    
    else{
        for(int i=29;i>=0;i--){
            if(arr[i]<=l){
                // cout<<i<<endl;
                sum+=arr[i];
                l-=arr[i];
                r-=arr[i];
                
                if(l>0)
                lo=log2(l);
                else
                lo=0;
                hi=log2(r);
                
                // cout<<l<<" "<<r<<" "<<lo<<" "<<hi<<endl;
                
                if(pow(2,hi)==r){
                    a=r-2+sum;
                    b=r+sum;
                    c=r-1+sum;
                    break;
                }
                
                if(hi-lo>0){
                    a=sum+pow(2,hi)-1;
                    b=sum+pow(2,hi);
                    c=sum+pow(2,hi)+1;
                    break;
                }
            }
        }
    }
    
    cout<<a<<" "<<b<<" "<<c<<endl;
    }
}

int main() {
    arr[0]=1;
    for(int i=1;i<30;i++)
    arr[i]=arr[i-1]*2;
    
    // for(int i=29;i>=0;i--)
    // cout<<arr[i]<<" ";
    // cout<<endl;
    
    ll t;
    cin>>t;
    while(t--)
    solve();
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 218 ms):
#include <bits/stdc++.h>
using namespace std;
// #define int long long

int main()
{
    int t;
    cin>>t;
    while(t--) {
        int n,k; cin>>n>>k;
        map<int,int> fq;
        for(int i=0;i<n;i++) {
            int x;
            cin>>x;
            fq[x]++;
        }
        vector<int> v;
        for(auto& x : fq) {
            v.push_back(x.second);
        }
        sort(v.begin(),v.end(), greater<int> ());
        while(k > 0 && !v.empty()) {
            if(v.back() > k)
                break;
            k -= v.back();
            v.pop_back();
        }
        cout <<  max((int)v.size(), 1) << endl;
    }
    return 0;
}

Solution 2 (runtime: 125 ms):
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>

using namespace std;

const int N = 100010;

int f[N];

map<int, int> mp;

int main() {
    int T; cin >> T;
    while (T --) {
        mp.clear();
        int n, k; scanf("%d %d", &n, &k);
        for (int i = 1; i <= n; i ++) {
            scanf("%d", &f[i]);
            mp[f[i]] ++;
        }

        vector<int> res;
        for (auto [x, y] : mp) res.push_back(y);
        sort(res.begin(), res.end());
        int ans = 0;
        for (auto x : res) {
            if (k >= x) {
                k -= x;
            } else ans ++;
        } 

        if (ans == 0) ans ++;
        cout << ans << endl;
    }
}
Problem: 2057B - Gorilla and the Exam
Language: c++17 

Solution 1 (runtime: 171 ms):
#include <bits/stdc++.h>
using namespace std;

void solve() {

    int a, b;
    cin >> a >> b;
    map <int, int> mp;

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

        int x;
        cin >> x;
        mp[x]++;
    }

    multimap <int, int> MM;
    for (auto& it : mp) {
        MM.insert(make_pair(it.second, it.first));
    }

    int k = mp.size();
    int gg = 0;
    for(auto x: MM) {
        if(x.first <= b) {
            b -= x.first;
            gg++;
        }
        else {
            break;
        }
    }

    if(k == gg) {
        cout << "1\n" << endl;
    } else {
        cout << (k - gg) << endl;
    }
}

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

Solution 2 (runtime: 124 ms):
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t;
    cin >> t;
    while (t--) {
        int n, k;
        cin >> n >> k;
        vector<int> a(n);
        for (int &x : a) cin >> x;

        map<int, int> freq;
        for (int x : a) freq[x]++;

        vector<int> frequencies;
        for (auto &[key, val] : freq) frequencies.push_back(val);

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

        int distinct = frequencies.size();
        int possible_merges = 0;
        for (int i = 0; i < distinct - 1; ++i) {
            if (k >= frequencies[i]) {
                k -= frequencies[i];
                possible_merges++;
            } else {
                break;
            }
        }

        int new_distinct = distinct - possible_merges;
        cout << new_distinct << '\n';
    }

    return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 187 ms):
#include<bits/stdc++.h>

using namespace std;

#define MOD 1000000007

#define N 1000000

#define int long long







int32_t main(){

  int tc=1; 

  cin>>tc;

  while(tc--){

    int n,l,r; cin >> n >> l >> r;

    l--; r--;

    std::vector<int> a(n);

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

      cin >> a[i];

    }

    std::vector<int> x,y;

    

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

      x.emplace_back(a[i]);

    }

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

      y.emplace_back(a[i]);

    }

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

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

    

    int ans1 = accumulate(x.begin(),x.begin()+(int)(r-l+1), 0LL);

    int ans2 = accumulate(y.begin(), y.begin() + (int)(r-l+1),0LL);

    cout << min(ans1, ans2) <<endl;

    



       

     }

   

}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>



#pragma GCC optimize("O3,unroll-loops")

#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")



using namespace std;

using ll = long long;



void solution() {

    int n, l, r;

    cin >> n >> l >> r;



    vector<int> a(n);

    for (auto &i : a) {

        cin >> i;

    }

    vector<int> b = a;



    ll ans_left = 0, ans_right = 0;



    sort(a.begin(), a.begin()+r);

    sort(b.begin()+l-1, b.end());



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

        ans_left += a[i];

    }



    for (int i = l-1; i < r; i++) {

        ans_right += b[i];

    }



    cout << min(ans_left, ans_right) << '\n';

}



int main() {

    ios_base::sync_with_stdio(false);

    cin.tie(nullptr);



    int t;

    cin >> t;

    for (int i = 0; i < t; i++)

        solution();

}
Problem: 2062C - Cirno and Operations
Language: c++17 

Solution 1 (runtime: 46 ms):
#include <bits/stdc++.h>

using namespace std;

#define mp(a,b) make_pair(a,b)
using ll = long long;

void solve(){
    int n; cin>>n;
    vector<ll> v(n);
    for(int i=0;i<n;i++) cin>>v[i];
    ll ans=0;
    for(int i=0;i<n;i++) ans+=v[i];
        // for(auto e: v) cout<<e<<" "; cout<<endl;
    while(v.size()>1){
        ll s1=0,s2=0;
        for(int i=0;i<v.size()-1;i++){
            s1+=v[i+1]-v[i];
            s2+=-(v[i+1]-v[i]);
        }
        if(s1>s2){
            // cout<<"normal\n";
            ans=max(s1,ans);
            for(int i=0;i<v.size()-1;i++){
                v[i] = v[i+1]-v[i];
            }
            v.pop_back();
        }else{
            // cout<<"reverse\n";
            ans=max(s2,ans);
            for(int i=0;i<v.size()-1;i++){
                v[i] = -(v[i+1]-v[i]);
            }
            v.pop_back();
        }
        // for(auto e: v) cout<<e<<" "; cout<<endl;
    }
    cout<<ans<<'\n';
}

int main(){
    int n; cin>>n;
    for(int i=0;i<n;i++) solve();
}

Solution 2 (runtime: 46 ms):
/*
    Author-Abhinav Audukoori
    Date-09-02-25
*/
#include <bits/stdc++.h>
using namespace std;
#define print(v) for(auto i :v){cout << i << " ";}cout << endl;
#define printpp(v) for(auto i : v){cout << i.first << " " << i.second << endl;}
#define vll(n) vector<long long>v(n)
#define vi(n) vector<int>v(n)
#define input(v,n) for(int i = 0;i < n;i++){cin >> v[i];}
#define Ceil(a,b) ((a+b-1)/b)
const long long MOD = 1e9 + 7; 
//<---------------------------------------------WRITE HERE---------------------------------------------------?
void solve() {
    int n;
    cin >> n;
    vector<long long>v(n);
    input(v,n);
    int now = n;
    long long ans = INT_MIN;
    for(int i = 1;i <= n;i++) {
        long long sum = 0;
        for(int i = 0;i < now;i++) sum += v[i];
        if(i == 1) ans = max(sum,ans);
        else ans = max(ans,max(sum,-sum));
        for(int i = 0;i < now;i++) v[i] = v[i+1] - v[i];
        now--;         
    }
    cout << ans << endl;
    return;
}
//<---------------------------------------------DONT TOUCH---------------------------------------------------->
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    long long t = 1;
    cin >> t;
    while (t--) {
        solve();
    }
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
long long int dp[2010][2010];
int main(){
	int t;
	scanf("%d",&t);
	while(t--){
		string a,b,c;
		cin>>a>>b>>c;
		int n1=a.size();
		int n2=b.size();
		a=' '+a;
		b=' '+b;
		c=' '+c;
		for(int i=0;i<=n1;i++){
			for(int j=0;j<=n2;j++){
				if(i+j==0){
					dp[i][j]=0;
					continue;
				}
				dp[i][j]=1e9;
				if(i!=0) dp[i][j]=min(dp[i][j],dp[i-1][j]+!(a[i]==c[j+i]));
				if(j!=0) dp[i][j]=min(dp[i][j],dp[i][j-1]+!(b[j]==c[j+i]));
			}
		}
		
		cout<<dp[n1][n2]<<endl;
	}
	return 0;
}

Solution 2 (runtime: 92 ms):
#include <bits/stdc++.h>
#define int long long
using namespace std;

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

    int n = a.size(), m = b.size();
    vector<vector<int>> dp(n + 1, vector<int>(m + 1, 1e9));

    dp[0][0] = 0; // Base case: no changes at the start

    for (int i = 0; i <= n; i++) {
        for (int j = 0; j <= m; j++) {
            int k = i + j; // Index in string c

            if (k >= c.size()) continue;

            // Option 1: Take a character from a
            if (i < n) {
                int cost = (a[i] != c[k]); // Cost if mismatch occurs
                dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + cost);
            }

            // Option 2: Take a character from b
            if (j < m) {
                int cost = (b[j] != c[k]); // Cost if mismatch occurs
                dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + cost);
            }
        }
    }

    cout << dp[n][m] << endl;
}

signed main() {
    int t;
    cin >> t;

    while (t--) {
        solve();
    }
    return 0;
}
Problem: 2052A - Adrenaline Rush
Language: c++17 

Solution 1 (runtime: 281 ms):
#include<string>
#include<algorithm>
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define big 998244353
#define pb push_back
#define mp make_pair
#define forn for(int i=0;i<n;i++)
using namespace std;

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

    int b[n];
    forn cin>>b[i];

    int a[n];
    forn a[i]=i+1;

    int ans = 0;

    int effective_size = n;

    vector<pair <int,int>> answers;
    
    for(int i=n-1;i>=0;i--)
    {
        int ele = b[i];
        int loc;
        for(int j=0;j<n;j++)
        {
            if(a[j]==ele)
            {
                loc = j;
                break;
            }
        }

        // cout<<ele<<" is at "<<loc<<endl;

        for(int j=loc-1;j>=0;j--)
        {
            // cout<<ele<<" "<<a[j]<<endl;
            answers.pb(mp(a[j+1],a[j]));
            swap(a[j+1],a[j]);
            // cout<<"potato";
            ++ans;
        }

        for(int j=0;j<i;j++)
        {
            // cout<<a[j+1]<<" "<<a[j]<<endl;
            answers.pb(mp(a[j+1],a[j]));
            swap(a[j],a[j+1]);
            ans++;
        }

        // for(int j=0;j<n;j++)
        // cout<<a[j]<<" ";
        // cout<<endl;

    }

    cout<<ans<<endl;
    for(int i=0;i<answers.size();i++){
        cout<<answers[i].first<<" "<<answers[i].second<<endl;
    }
}

int32_t main() {
    // fast io
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    // int t;
    // cin >> t;

    // while (t--) 
        solve();
}

Solution 2 (runtime: 1406 ms):
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<deque>
#define fi first
#define se second
#define pb push_back
#define ppb pop_back
#define int long long
using namespace std;
 
const int N=1000000,mod=1e9+7;
int a[N],b[N];
int s=0,n=0;
pair<int,int> ans[N];

void go(int cur,int begin,int end) {
    for (int i=begin;i<n;++i) {
        ans[++s]={b[i+1],b[i]};
        swap(b[i],b[i+1]);
    }
    for (int i=n;i>end;--i) {
        ans[++s]={b[i],b[i-1]};
        swap(b[i],b[i-1]);
    }
}

signed main() {
    cin>>n;
    for (int i=1;i<=n;++i) cin>>a[i];
    for (int i=1;i<=n;++i) b[i]=i;
    for (int i=1;i<=n;++i) {
        int pos;
        for (int j=1;j<=n;++j) {
            if (a[i]==b[j]) pos=j;
        }
        go(a[i],pos,i);
        //cout<<a[i]<<" "<<pos<<" "<<i<<endl;
    }
    cout<<s<<endl;
    for (int i=1;i<=s;++i) {
        cout<<ans[i].first<<" "<<ans[i].second<<endl;
    }
	return 0;
}
Problem: 2063B - Subsequence Update
Language: c++17 

Solution 1 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

void test_case() {
  ll n, l, r;
  cin >> n >> l >> r;
  vector<ll> a(n);
  vector<ll> b(n);
  for (int i=0;i<n;i++) {
    cin >> a[i];
    b[i] = a[i];
  }

  l--; 
  sort(a.begin()+l, a.end());
  sort(b.begin(), b.begin()+r);
  reverse(b.begin(), b.begin()+r);

  ll k = r-l+1;
  ll s1 = 0, s2 = 0;
  for (int i=l;i<r;i++) {
    s1 += a[i];
    s2 += b[i];
  }

  cout << min(s1, s2) << endl;
}

int32_t main(){
  ios_base::sync_with_stdio(0); cin.tie(0);

  int t;
  cin >> t;
  while (t--){
    test_case();
  }
}

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>

using namespace std;



// Fast I/O

#define FAST_IO                       \

    ios_base::sync_with_stdio(false); \

    cin.tie(nullptr);                 \

    cout.tie(nullptr);



// Aliases for convenience

using ll = long long;

using vi = vector<int>;

using vll = vector<long long>;

using pii = pair<int, int>;



// Constants

const int MOD = 1e9 + 7;

const int INF = INT_MAX;



// Solve function

void solve()

{

    int n, l, r;

    cin >> n >> l >> r;

    vector<int> v(n);

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

        cin >> v[i];

    }

    vector<int> left;

    vector<int> right;

    vector<int> mid;

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

        if(i<l-1){

            left.push_back(v[i]);

        }else if(i>r-1){

            right.push_back(v[i]);

        }else{

            mid.push_back(v[i]);

        }

    }

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

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

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

    ll mergeWithLeft = 0 ;

    ll mergeWithRight = 0;

    int L_idx = 0 ; 

    int R_idx = 0;

    for (int i = mid.size()-1; i>= 0 ; i--){

        if(R_idx<right.size()){

            mergeWithRight +=  min(mid[i],right[R_idx]);

            R_idx++;

        }else{

            mergeWithRight += mid[i];

        }

        if(L_idx<left.size()){

            mergeWithLeft +=  min(mid[i],left[L_idx]);

            L_idx++;

        }else{

            mergeWithLeft += mid[i];

        }

    }

    cout << min(mergeWithLeft, mergeWithRight) << "\n";

}



int main()

{

    FAST_IO;



    int t; // Number of test cases

    cin >> t;

    while (t--)

    {

        solve();

    }



    return 0;

}
Problem: 2050C - Uninteresting Number
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
void solve()
{
	/*
	x 的取值只能是 2，3
	求通过运算（使用 x*x 替换 x ），是否可能得到一个能杯
	9整除的数吗？
	我觉得先找出能被9整除的特点 % 9 == 0 
	  
	*/
	string str;
	cin>>str;
	int sum = 0;
	int cnt1 = 0,cnt2 = 0; 
	for(int i = 0;i < str.size();i++)
	{
		sum += str[i] - '0';
		if(str[i] == '2') cnt1 ++;
		if(str[i] == '3') cnt2 ++; 
	}
	
	for(int i = 0;i <= 8&&i <= cnt2 ;i++)
	{
		for(int j = 0;j <= 8 &&j <= cnt1;j++)
		{
			if((sum + 2 * j + 6 * i) % 9 == 0){
				cout<<"YES"<<endl;
				return ;
			}
		}
	 }
	 cout<<"No"<<endl;
}
int main()
{
	int t;cin>>t;
	while(t--)
	{
		solve();
	}
	return 0;
 } 

Solution 2 (runtime: 62 ms):
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

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

    int t;
    cin >> t;
    while(t--) {
        string n;
        cin >> n;
        ll digitSum = 0;
        int count2 = 0, count3 = 0;
        for(char digit : n) {
            digitSum += digit - '0';
            if(digit == '2') count2++;
            if(digit == '3') count3++;
        }
        if(digitSum % 9 == 0) {
            cout << "YES\n";
            continue;
        }

        bool found = false;
        int rem = digitSum % 9;

       
        for(int i = 0; i <= min(count2, 8); i++) {
            for(int j = 0; j <= min(count3, 8); j++) {
                int newRem = (rem + (i * 2 + j * 6) % 9) % 9;
                if(newRem == 0) {
                    found = true;
                    goto end;  
                }
            }
        }

        end:
        cout << (found ? "YES\n" : "NO\n");
    }
    return 0;
}
Problem: 2050E - Three Strings
Language: c++17 

Solution 1 (runtime: 62 ms):
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
// using pll = pair<ll,ll>;

void solve(){
  string a,b,c;
  cin>>a>>b>>c;
  int la = a.size(),lb = b.size(),lc = c.size();
  vector<vector<int>> dp(la+1,vector<int>(lb+1,INT_MAX));
  dp[0][0] = 0;
  for (int i = 0; i < la; i++) {
        dp[i + 1][0] = dp[i][0] + (a[i] != c[i]);
  }
  for (int j = 0; j < lb; j++) {
      dp[0][j + 1] = dp[0][j] + (b[j] != c[j]);
  }
  for (int j=1;j<=la;j++){
    for (int k=1;k<=lb;k++){
      dp[j][k] = min(dp[j-1][k]+(a[j-1]!=c[j+k-1]),dp[j][k-1]+(b[k-1]!=c[j+k-1]));
    }
  }
  cout<<dp[la][lb]<<endl;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    // 中间填保留几位小数，不填默认
    // cout.precision();
    int t;cin>>t;
    while (t--) solve();
    
}

Solution 2 (runtime: 77 ms):
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int t;
    cin>>t;
    while(t--) {
        string a, b, c;
        cin>>a>>b>>c;
        
        int l = a.length(), m = b.length(), n = c.length();

        int dp[l+1][m+1];
        dp[0][0] = 0;

        for(int i = 0; i <= l; i++) {
            for(int j = 0; j <= m; j++) {       
                if(i == 0 && j == 0) continue; 
                if(i == 0) dp[i][j] = dp[i][j-1] + (b[j-1] != c[i+j-1]);
                else if(j == 0) dp[i][j] = dp[i-1][j] + (a[i-1] != c[i+j-1]);
                else dp[i][j] = min(dp[i-1][j] + (a[i-1] != c[i+j-1]), dp[i][j-1] + (b[j-1] != c[i+j-1]));
            }
        }

        cout<<dp[l][m]<<endl;
    }
    return 0;
}