Language: C++

#include "bits/stdc++.h"
#define int long long int;
using namespace std;
 
int n, q;
 
void solve(){
    cin >> n;
    int sum = 0;
    vector<int> freq(100069, 0);
    for(int i = 0, inp; i < n; ++i){
        cin >> inp;
        freq[inp]++;
        sum += inp;
    }
    cin >> q;
    while(q--){
        int b, c;
        cin >> b >> c;
        sum -= freq[b]*b;
        sum += freq[b]*c;
        freq[c] += freq[b];
        freq[b] = 0;
        cout << sum << endl;
    }
}
 
int32_t main(){
    ios_base::sync_with_stdio(false),cin.tie(nullptr);
    // int t; cin >> t;
    // while(t--)
        solve();
    return 0;
}

Compiler output:
a.cc:2:23: error: declaration does not declare anything [-fpermissive]
    2 | #define int long long int;
      |                       ^~~
a.cc:5:1: note: in expansion of macro 'int'
    5 | int n, q;
      | ^~~
a.cc:5:5: error: 'n' does not name a type
    5 | int n, q;
      |     ^
a.cc: In function 'void solve()':
a.cc:8:12: error: 'n' was not declared in this scope; did you mean 'yn'?
    8 |     cin >> n;
      |            ^
      |            yn
a.cc:2:23: error: declaration does not declare anything [-fpermissive]
    2 | #define int long long int;
      |                       ^~~
a.cc:9:5: note: in expansion of macro 'int'
    9 |     int sum = 0;
      |     ^~~
a.cc:9:9: error: 'sum' was not declared in this scope
    9 |     int sum = 0;
      |         ^~~
a.cc:2:23: error: template argument 1 is invalid
    2 | #define int long long int;
      |                       ^~~
a.cc:10:12: note: in expansion of macro 'int'
   10 |     vector<int> freq(100069, 0);
      |            ^~~
a.cc:2:23: error: template argument 2 is invalid
    2 | #define int long long int;
      |                       ^~~
a.cc:10:12: note: in expansion of macro 'int'
   10 |     vector<int> freq(100069, 0);
      |            ^~~
a.cc:10:15: error: expected primary-expression before '>' token
   10 |     vector<int> freq(100069, 0);
      |               ^
a.cc:10:17: error: 'freq' was not declared in this scope; did you mean 'free'?
   10 |     vector<int> freq(100069, 0);
      |                 ^~~~
      |                 free
a.cc:2:23: error: declaration does not declare anything [-fpermissive]
    2 | #define int long long int;
      |                       ^~~
a.cc:11:9: note: in expansion of macro 'int'
   11 |     for(int i = 0, inp; i < n; ++i){
      |         ^~~
a.cc:11:13: error: 'i' was not declared in this scope
   11 |     for(int i = 0, inp; i < n; ++i){
      |             ^
a.cc:11:20: error: 'inp' was not declared in this scope; did you mean 'int'?
   11 |     for(int i = 0, inp; i < n; ++i){
      |                    ^~~
      |                    int
a.cc:11:30: error: expected ')' before ';' token
   11 |     for(int i = 0, inp; i < n; ++i){
      |        ~                     ^
      |                              )
a.cc:11:34: error: 'i' was not declared in this scope
   11 |     for(int i = 0, inp; i < n; ++i){
      |                                  ^
a.cc:16:12: error: 'q' was not declared in this scope
   16 |     cin >> q;
      |            ^
a.cc:2:23: error: declaration does not declare anything [-fpermissive]
    2 | #define int long long int;
      |                       ^~~
a.cc:18:9: note: in expansion of macro 'int'
   18 |         int b, c;
      |         ^~~
a.cc:18:13: error: 'b' was not declared in this scope
   18 |         int b, c;
      |             ^
a.cc:18:16: error: 'c' was not declared in this scope
   18 |         int b, c;
      |                ^