stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);

	ll n,a,q,b,c,sum=0;

	cin>>n;

	vector<ll>v(1000000);

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

		cin>>a;

		v[a]++;

		sum+=a;

	}

	cin>>q;

	for(ll i=0;i<q;i++){

		cin>>b>>c;

		int w;

		w=v[b];

		v[b]=0;

		v[c]+=w;

		sum=sum-(b*w)+(c*w);

		cout<<sum<<endl;

	}

	return 0;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;



int main() {

	cin.tie(0);

	ios::sync_with_stdio(false);

	ll n,a,q,b,c,sum=0;

	cin>>n;

	vector<ll>v(100001);

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

		cin>>a;

		v[a]++;

		sum+=a;

	}

	cin>>q;

	for(ll i=0;i<q;i++){

		cin>>b>>c;

		int w;

		w=v[b];

		v[b]=0;

		v[c]+=w;

		sum=sum-(b*w)+(c*w);

		cout<<sum<<endl;

	}

	return 0;

}


// Fastest known solution for this problem:
#include<bits/stdc++.h>

using namespace std;

#define ll long long

#include <string>

const int mxN=1e5;

const int maxN=5e3;

#define ld long double

#define pb push_back

#define mp make_pair

#define ins insert

#define vi vector<int>



int main()

{

    int n;

    cin >> n;

    int cnt[100000]={};

    ll s=0;

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

    {

        int x;

        cin >> x;

        cnt[x-1]++;

        s+=x;

    }

    int q;

    cin >> q;

    while(q--)

    {

        int b,c;

        cin >> b >> c;

        s+=cnt[b-1]*(c-b);

        cnt[c-1]+=cnt[b-1];

        cnt[b-1]=0;

        cout << s << "\n";

    }

}
// Original C++ solution (slower):
#include <bits/stdc++.h>



using namespace std;



#define PROBLEM "B"

#define TESTC ""



#define USE_CPPIO() ios_base::sync_with_stdio(0); cin.tie(0)

typedef pair<int, int> P;

#define F first

#define S second

#define INF 0x3f3f3f3f

#define MP make_pair

#define PB push_back

#define MAXN 1000005



bool arr[MAXN];



int main()

{

	#ifdef DBG

	freopen(PROBLEM TESTC ".in", "r", stdin);

	freopen(PROBLEM ".out", "w", stdout);

	#endif



	int num;

	

	while(~scanf("%d",&num))

	{

		memset(arr,0,sizeof(arr));



		int cnt = 1;

		while(1)

		{

			arr[num] = true;

			if (num % 2 == 0)

			{

				num /= 2;

			}

			else

			{

				num = num*3+1;

			}

			cnt++;

			if(arr[num])

			{

				break;

			}	

		}



		printf("%d\n",cnt);

		

	}

	

	return 0;

}

// Optimized solution to the same problem (faster):
#include<bits/stdc++.h>

using namespace std;

#define LL long long int

#define DL double

#define MLL map<LL,LL>::iterator

#define MSL map<string,L>::iterator

#define MLS map<LL,string>::iterator

#define MSS map<string,string>::iterator

#define MCL map<char,LL>::iterator

#define SL set<LL>::iterator

#define SS set<string>::iterator

#define VL vector<LL>::iterator

#define G getline

#define SZ size()

#define IN insert

#define C clear()

#define B begin()

#define F front()

#define T top()

#define E end()

#define EM empty()

#define V vector

#define Q queue

#define DQ deque

#define PQ priority_queue

#define ST stack

#define FI first

#define SE second

#define PI acos(-1)

#define PS push

#define PP pop()

#define PSF push_front

#define PSB push_back

#define PPF pop_front()

#define PPB pop_back()

#define endl "\n"

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)

void Y()

{

    cout<<"Yes"<<endl;

}

void N()

{

    cout<<"No"<<endl;

}

map<LL,LL>u;

int main()

{

    FAST;

    LL n,m,i,j,k,p,q,o,l,s,t,z,a,b,c,d,e,f,g,h;

    cin>>n;

    u[n]++;

    k=0;

    while(1)

    {

        if(n%2==0)

        {

            n/=2;

        }

        else

        {

            n=(3*n)+1;

        }

        u[n]++;

        k++;

        if(u[n]>1)

        {

            cout<<k+1<<endl;

            break;

        }

    }





    return 0;

}




// Fastest known solution for this problem:
#include <iostream> 



int main()

{

    int s;

    std::cin >> s;

    int list[1000000];

    int index = 0;

    int a_i;

    int a_pre = s;

    list[0] = s;

    index = index + 1;

    bool search_flag = false;

    while( true){

        if ( a_pre % 2 == 0){

            a_i = a_pre / 2;

        } else {

            a_i = 3 * a_pre + 1;

        }

        list[index] = a_i;

        index = index + 1;

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

            if ( list[i] == a_i) {

                search_flag = true;

                break;

            }

        }

        if (search_flag==true){

            break;

        } 

        a_pre = a_i;



    }

    std::cout << index << std::endl;

    return 0;

}
// Original C++ solution (slower):
#include<bits/stdc++.h>

#define ll long long

#define MAXN 100010

#define INF 1000000010



using namespace std;



ll n, dp[MAXN], h[MAXN], k;



void init(){

    for(int i=1; i<=n; i++) dp[i]=INF;

    dp[1]=0;

    h[0]=INF;

}



int main(){



    ios_base::sync_with_stdio(0);

    cin.tie(0);

    cout.tie(0);



    cin>>n>>k;



    for(int i=1; i<=n; i++) cin>>h[i];



    init();



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

        for(int j=1; j<=k; j++){

            if(i-j>0) dp[i]=min(dp[i], dp[i-j]+abs(h[i]-h[i-j]));

        }

    }



    cout<<dp[n];



return 0;

}


// Optimized solution to the same problem (faster):
#include<stdio.h>

#include<stdlib.h>

#include<math.h>





typedef long long ll;





ll *mem, *inp, dist, min_dist, N;

int k;



int main()

{

    ll i, j;

    scanf("%lld%d", &N, &k);



    mem =(ll*) malloc(N * sizeof(ll));

    inp =(ll*) malloc(N * sizeof(ll));



    for(i = 0; i<N; ++i){

        scanf("%lld", inp+i);

    }



    *(mem+N-2) = llabs(*(inp+N-2) - *(inp+N-1));



    for(i = 3; i<=k+1 && i<=N; ++i)

        *(mem+N-i) = llabs(*(inp+N-i) - *(inp+N-1));



    for(i = N-(k+2); i>=0; --i){



        min_dist = llabs(*(inp+i) - *(inp+i+1)) + *(mem+i+1);

        for(j = 2; j<=k && i+j<N; ++j){

            dist = llabs(*(inp+i) - *(inp+i+j)) + *(mem+i+j);

            if (dist < min_dist) min_dist = dist;

        }



        *(mem+i) = min_dist;

    }



    printf("%lld\n", *mem);



    return 0;

}








// Fastest known solution for this problem:
#include <iostream>

#include <array>

#include <vector>

#include <iomanip>

#include <string>

#include <cmath>

#include <array>

#include <algorithm>

#include <queue>

#include <map>

using namespace std;



typedef  pair<int,int> P;

typedef long long LL;



const LL  INF=1<<31;







int main(){

     int n,k;

     cin>>n>>k;

     int h[100000];

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

          cin>>h[i];

     }

     LL dp[100001];



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

           dp[i]=INF;

      }

            dp[0]=0;

            dp[1]=abs(h[0]-h[1]);







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

          dp[i]=dp[i-1]+abs(h[i-1]-h[i]);

          for(int j=2;j<=k;++j){



               if(j<=i)dp[i]=min(dp[i],dp[i-j]+abs(h[i-j]-h[i]));

          }

     }     



     cout<<dp[n-1]<<endl;





}