akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

template <unsigned int MOD>
struct ModInt {
	using uint = unsigned int;
	using ull = unsigned long long;
	using M = ModInt;

	uint v;

	ModInt(ll _v = 0) { set_norm(_v % MOD + MOD); }
	M& set_norm(uint _v) { //[0, MOD * 2)->[0, MOD)
		v = (_v < MOD) ? _v : _v - MOD;
		return *this;
	}

	explicit operator bool() const { return v != 0; }
	M operator+(const M& a) const { return M().set_norm(v + a.v); }
	M operator-(const M& a) const { return M().set_norm(v + MOD - a.v); }
	M operator*(const M& a) const { return M().set_norm(ull(v) * a.v % MOD); }
	M operator/(const M& a) const { return *this * a.inv(); }
	M& operator+=(const M& a) { return *this = *this + a; }
	M& operator-=(const M& a) { return *this = *this - a; }
	M& operator*=(const M& a) { return *this = *this * a; }
	M& operator/=(const M& a) { return *this = *this / a; }
	M operator-() const { return M() - *this; }
	M& operator++(int) { return *this = *this + 1; }
	M& operator--(int) { return *this = *this - 1; }

	M pow(ll n) const {
		if (n < 0) return inv().pow(-n);
		M x = *this, res = 1;
		while (n) {
			if (n & 1) res *= x;
			x *= x;
			n >>= 1;
		}
		return res;
	}

	M inv() const {
		ll a = v, b = MOD, p = 1, q = 0, t;
		while (b != 0) {
			t = a / b;
			swap(a -= t * b, b);
			swap(p -= t * q, q);
		}
		return M(p);
	}

	bool operator==(const M& a) const { return v == a.v; }
	bool operator!=(const M& a) const { return v != a.v; }
	friend ostream& operator<<(ostream& os, const M& a) { return os << a.v; }
};

using Mint = ModInt<1000000007>;
const Mint m2(2);

Mint solve(int p, int q) { //T=1
	 Mint res = m2.pow(p) + m2.pow(q) + m2.pow(__gcd(p, q)) - Mint(3);
	 return res;
}

int main() {
	int H, W, T;
	cin >> H >> W >> T;
	int gh = __gcd(H, T);
	int gw = __gcd(W, T);

	Mint ans = solve(H / gh, W / gw).pow((ll)gh * gw);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
   
   char S[10];
   
   scanf("%s",S);
   
   if (S[2] == S[3] && S[4] == S[5]) {
      printf("Yes\n");
   }
   else {
      printf("No\n");
   }
   
   return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;

int main(void){
	int N, K, i, x, d = 0;
	scanf("%d\n%d", &N, &K);
	for(i = 0;i < N;i++){
		scanf("%d", &x);
		d += 2 * min(x, K - x);
	}
	printf("%d\n", d);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define debug(i) cout << i << endl;
#define debugarr(a) for(auto i : a) cout << i << " ";

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);

    int n, d;
    cin >> n >> d;

    int ans = (n + (d*2+1) - 1) /  (d * 2 + 1);
    cout << ans << endl;
}


Measured memory_bytes: 256
#ABC148 A - Round One

A=int(input())
B=int(input())

if A==1:
    if B==2:
        print(str(3))
    elif B==3:
        print(str(2))
        
elif A==2:
    if B==1:
        print(str(3))
    elif B==3:
        print(str(1))

else:
    if B==1:
        print(str(2))
    elif B==2:
        print(str(1))

Measured memory_bytes: 3064
W, H, N = map(int, input().split())

A = [0]*4
for i in range(4):
  A[i] = []
for i in range(N):
  x,y,a = map(int, input().split())
  if a==1 or a==2:
  	A[a-1].append(x)
  else:
    A[a-1].append(y)

A[0] = max(A[0]) if len(A[0])!=0 else 0
A[1] = min(A[1]) if len(A[1])!=0 else W
A[2] = max(A[2]) if len(A[2])!=0 else 0
A[3] = min(A[3]) if len(A[3])!=0 else W
print(max(0,A[1]-A[0])*max(0,A[3]-A[2]))


  



Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007;
const int INF = 1e15;
using Graph = vector<vector<int>>;

signed main(){
  int H, W;
  cin >> H >> W;
  vector<vector<int>> A(H, vector<int>(W));
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W; j++ ) cin >> A[i][j];
  }

  vector<int> X;
  vector<int> Y;
  vector<int> NX;
  vector<int> NY;
  int ans = 0;
  for( int i = 0; i < H; i++ ){
    for( int j = 0; j < W-1; j++ ){
      if( A[i][j]%2 == 1 ){
        X.push_back(i+1);
        Y.push_back(j+1);
        NX.push_back(i+1);
        NY.push_back(j+2);
        ans++;
        A[i][j]--;
        A[i][j+1]++;
      }
    }
  }
  for( int i = 0; i < H-1; i++ ){
    if( A[i][W-1]%2 == 1 ){
      X.push_back(i+1);
      Y.push_back(W);
      NX.push_back(i+2);
      NY.push_back(W);
      ans++;
      A[i][W-1]--;
      A[i+1][W-1]++;
    }
  }

  cout << ans << endl;
  for( int i = 0; i < ans; i++ ){
    cout << X[i] << " " << Y[i] << " " << NX[i] << " " << NY[i] << endl;
  }
}


Measured memory_bytes: 8152
#include <bits/stdc++.h>

using namespace std;

int main() {

    int n;
    cin >> n;

    vector<long long> l(n+1);
    l[0] = 2;
    l[1] = 1;

    for(int i = 2;i <= n;i++){
        l[i] = l[i - 1] + l[i - 2];
    }

    cout << l[n] << endl;

    return 0;
}

Measured memory_bytes: 256
a, b, x = gets.chomp.split.map(&:to_f)
v = a * a * b
if x * 2 > v
  res = Math::atan((b / a - x / (a ** 3)) * 2.0)
else
  res = Math::atan(a * b * b / (2.0 * x))
end
puts "%.7f" % [res / Math::PI * 180]

Measured memory_bytes: 14748
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int32_t main(){
	int a,b;
	cin>>a>>b;  
	if(a>b){
		cout<<-1<<endl; 
		return 0;
	}
	int ans = -1; 
	for(int i=b*10;i<=1000;i++){
		int price1 = (i*8)/100; 
		int price = (i)/10; 
		if(price1 == a and price == b){
			ans = i; 
			break;
		}
	} 
	cout<<ans<<endl;
}

Measured memory_bytes: 256
from collections import deque
n,q = map(int,input().split())
Q = []
for i in range(n):
    Q.append(deque())
for i in range(q):
    a = input().split()
    t = int(a[1])
    if a[0] == "0":Q[t].append(a[2])
    elif a[0] == "1":print(*Q[t])
    else: Q[t].clear()



Measured memory_bytes: 42828
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define sz(a) ((int)a.size())
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijoMOD(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll div_num(ll n){
  vl div(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      div[i]++;
    }
  }
  if(n!=1)div[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=div[i];
  }
  return num;
}
vector<ll> divisor(ll n) {
  vector<ll> ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}



//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//vc Alp ={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
//cout<<""<<endl;
int main(){
 int N,K;cin>>N>>K;string S;cin>>S;
  int ch=0;
  
  rep(i,S.size()-1){
   if(S[i]=='R' && S[i+1]=='L'){
     ch++;
   }
  }
  int l=0,r=0;
  if(S[0]=='L')l++;
  if(S[S.size()-1]=='R')r++;  
  if(K>=ch+1)cout<<N-1<<endl;
  else if(K<ch+1)cout<<min(N-1,N-l-r-2*(ch-K))<<endl;
  
   
  
}







Measured memory_bytes: 512
# ABC149 D
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,k=nm()
r,s,p=nm()
t=si()
l=[[] for i in range(k)]
ans=0

for i in range(n):
    j=(i+1)%k
    l[j].append(t[i:i+1])

same_flg=False
for ll in l:
    cur_str=''
    for lll in ll:
        if cur_str=='':
            if lll=='p':
                ans+=s
            elif lll=='r':
                ans+=p
            elif lll=='s':
                ans+=r 
            cur_str=lll
            same_flg=True
            continue

        if lll==cur_str:
            # 足さない
            cur_str=lll
            if same_flg==True:
                same_flg=False
            elif same_flg==False:
                if lll=='p':
                    ans+=s
                elif lll=='r':
                    ans+=p
                elif lll=='s':
                    ans+=r 
                same_flg=True
            pass
        else:
            if lll=='p':
                ans+=s
            elif lll=='r':
                ans+=p
            elif lll=='s':
                ans+=r
            cur_str=lll
            same_flg=True
print(ans)

Measured memory_bytes: 13428
#include<bits/stdc++.h>

using namespace std;

typedef long long int li;
typedef long double ld;
typedef vector<li> vi;
typedef pair<li,li> pi;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define B begin()
#define E end()
#define f(i,l,r) for(li i=l;i<=r;++i)
#define fr(i,l,r) for(li i=l;i>=r;--i)
#define u_map unordered_map
#define endl "\n"
#define debug(x) cerr<<#x<<" = "<<x<<endl

li fastpow(li base,li exp,li M) 
{
    li res=1;
    while(exp>0) {
        if(exp&1)
            res=(res*base)%M;

        base=(base*base)%M;
        exp>>=1;
    }
    return res;
}

void solve()
{
    li n;

    cin>>n;

    const li M=1e9+7;

    cout<<(fastpow(10,n,M)-(2*fastpow(9,n,M))%M+fastpow(8,n,M)+M)%M;
}

int main()
{    
    //remove this in kickstart

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
    #endif

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

    li t=1;

    // cin>>t;

    f(i,1,t)
    {
        // cout<<"Case #"<<i<<": ";

        solve();
    }

    return 0;
}

Measured memory_bytes: 3608
#include<stdio.h>
int main(){
	long long int n, i, min, max, sum, a[10000];
	scanf("%lld", &n);
	scanf("%lld", &a[0]);
	min = a[0];
	max = a[0];
	sum = a[0];
	for(i=1; i<n; i++){
		scanf("%ld", &a[i]);
		if(a[i] < min)
			min = a[i];
		if(a[i] > max)
			max = a[i];
		sum += a[i];
	}
	printf("%lld %lld %lld\n",min ,max ,sum);
	return 0;
}

Measured memory_bytes: 680
my @string = split('', <>);

my $max = 0;
my $count = 0;
for ( @string ) {
    if ( $_ =~ /[ATCG]/) {
        $count++;
    }
    else {
        $max = $count > $max ? $count : $max;
        $count = 0;
    }
}

print $max;


Measured memory_bytes: 640
#include<stdio.h>
int abs(int a)
{
    if(a<0)
        return 0-a;
    return a;
}
int main()
{
    int i,n,tmp,ans,a[105];
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(i) a[i]=a[i]+a[i-1];
    }
    ans=a[n-1];
    for(i=0; i<n; i++)
    {
        tmp=a[n-1]-a[i];
        if(abs(tmp-a[i])<ans) ans=abs(tmp-a[i]);
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
N = int(input())
A = [int(input()) for _ in range(N)]
p = [0 for _ in range(N)]
for i in range(N):
  A[i] -= 1
  p[A[i]] = i
m = 0
prev = -1
cnt = 0
for i in range(N):
  if p[i] > prev:
    cnt += 1
  else:
    m = max(m, cnt)
    cnt = 1
  prev = p[i]
m = max(m, cnt)
print(N-m)

Measured memory_bytes: 24976
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main() {
int x;
cin>>x;
vector<int> p;
for(int i=2; i<=10; i++){
    for(int j=1; j<=40; j++){
        llong num=pow(j,i);
        if(num>x)break;
        p.push_back(num);
    }
}
sort(p.begin(),p.end(),greater<int>());
cout<<p[0]<<endl;
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String line = sc.nextLine();
		String[] str = line.split(" ", 0);
        long a = Integer.parseInt(str[0]);
        long b = Integer.parseInt(str[1]);
        long c = Integer.parseInt(str[2]);
        long d = Integer.parseInt(str[3]);
        
		long max = 0;

      	for(int i=0;i<=3;i++){
          	max = a * c;
			if(max < a * d){
              	max = a * d;
            }
			if(max < b * c){
              	max = b * c;
            }
   			if(max < b * d){
              	max = b * d;
            }
        }
      
		System.out.println(max);
    }
}

Measured memory_bytes: 35592
#include<stdio.h>
#define N 100
#define MAX 1000000 

int main(){
  int n ,i ,j ,a=0 ,x=0 ,s[N][N] ,al[N] ,r[N] ,m ,l;

  scanf("%d" ,&n); 

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d" ,&s[i][j]);
    }
  } 
  for(i=0 ; i<n ; i++){ 
    al[i] = MAX;
    r[n] = 0;
  } 
    
  al[0] = 0;
    
  while(1){
    m = MAX;
   for(i=0 ; i<n ;i++){
      if(r[i] != 1 && al[i] < m){
        m = al[i];
        l = i;
      }
    }

    if(m == MAX) break;
    r[l] = 1;

    for(i=0 ; i<n ; i++){
      if(s[l][i] != -1 && r[i] != 1 && s[l][i] < al[i]) al[i] = s[l][i];
    }
  }

  for(i=0 ; i<n ; i++){
    a += al[i];
  }

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

   return 0;
}


Measured memory_bytes: 2060
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
using vvi=vector<vi>;
using vs=vector<string>;
using msi=map<string,int>;
using mii=map<int,int>;
using pii=pair<int,int>;
using vlai=valarray<int>;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define INF 1e9
#define EPS 1e-9
int solve(string s){
    static int depth=0;
    //cout<<depth<<" in :  "<<s<<endl;
    vs a;
    int d=0,st=1;
    if(isdigit(s[0])){return (int)ceil(stoi(s)/2.0);}
    vi v;
    for(int i=0;i<s.size();i++){
        if(s[i]=='[')d++;
        else if(s[i]==']'){
            d--;
            if(d==0){
                auto sep=s.substr(st,i-st);
                depth++;
                v.pb(solve(sep));
                depth--;
                st=i+2;
            }
        }
    }
    sort(all(v));
    int ans=0;
    //for(auto i:v)cout<<i<<",";cout<<endl;
    rep(i,(v.size()+1)/2)ans+=v[i];
    //cout<<depth<<":"<<ans<<endl;
    return ans;
}


int main(){
	int n;
	cin>>n;
	rep(lp,n){
	    string s; cin>>s;
	    cout<<solve(s)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3276
n = int(input())
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
input_list = [a,b,c,d,e]
input_list.sort()
if n % input_list[0] == 0:
    k = n // input_list[0]
else:
    k = n// input_list[0] + 1
print(k +4)

Measured memory_bytes: 3064
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<utility>
#include<queue>
#include<tuple>
#include<stdio.h>
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int x;
	cin>>x;
	int a=x/500*1000, b=x%500;
	cout<<a+b/5*5<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;

int main(){
    int a, b, ans;
    char c;
    while (cin >> a >> c >> b && c != '?'){
        if (c == '+') ans = a + b;
        else if (c == '-') ans = a - b;
        else if (c == '*') ans = a * b;
        else ans = a / b;
        cout << ans << endl;
    }
}

Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
    cout << fixed << setprecision(10);

    int N; cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

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

    int amax = A[N-1];
    vector<int> dp(amax+1);

    int ans = 0;
    rep(i, N) {
        if (dp[A[i]]) continue;
        ans += 1;
        if (i < N-1 & A[i] == A[i+1]) ans -= 1;
        for(int j=A[i]; j <= amax; j+=A[i]) {
            dp[j] = 1;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7956
#include<iostream>
#include<string>
using namespace std;

int main(){
    //input
    string S,T;
    cin >> S >> T;

    //calc
    int i,j;
    bool exist;
    for(i=S.length()-T.length(); i>=0; i--){
        exist=1;
        for(j=0; j<T.length(); j++){
            if(S[i+j]!='?'&&S[i+j]!=T[j]){
                exist=0;
            }
        }
        if(exist){
            break;
        }
    }
    //answer
    if(i>=0){
        for(j=0; j<i; j++){
            if(S[j]=='?'){
                cout << 'a';
            }else{
                cout << S[j];
            }
        }
        for(j=0; j<T.length(); j++){
            cout << T[j];
        }
        for(j=i+T.length(); j<S.length(); j++){
            if(S[j]=='?'){
                cout << 'a';
            }else{
                cout << S[j];
            }
        }
        cout << endl;
    }else{
        cout << "UNRESTORABLE" << endl;
    }
    system("pause");
    return 0;
}

Measured memory_bytes: 504
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int digit_sum(int x){
    int ans = 0;
    while(x){
        ans += x % 10;
        x /= 10;
    }
    return ans;
}

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

    int N, A, B;
    cin >> N >> A >> B;

    int ans = 0;
    for(int a = 1; a <= N; a++){
        int dsum = digit_sum(a);
        if(A <= dsum && dsum <= B){
            ans += a;
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
#------------------------template--------------------------#
import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import*
from io import BytesIO, IOBase
def vsInput():
    sys.stdin = open('input.txt', 'r')
    sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
ALPHA='abcdefghijklmnopqrstuvwxyz'
M=10**9+7
EPS=1e-6
def value():return tuple(map(int,input().split()))
def array():return [int(i) for i in input().split()]
def Int():return int(input())
def Str():return input()
def arrayS():return [i for i in input().split()]


#-------------------------code---------------------------#
#vsInput()

n=Int()
a=sorted(array())

ans=0
# print(a)
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if(a[i]+a[j]>a[k] and a[i]!=a[j] and a[j]!=a[k] ):
                # print(a[i],a[j],a[k])
                ans+=1

print(ans)

Measured memory_bytes: 10568
#include <iostream>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const long long INF = 1LL<<60;

const int MAX_N = 110;
const int MAX_V = 100100;

// 入力
int N;
long long W, weight[MAX_N], value[MAX_N]; // 品物の個数は 100 個なので少し余裕持たせてサイズ 110 に

// DPテーブル
long long dp[MAX_N][MAX_V];

int main() {
    cin >> N >> W;
    for (int i = 0; i < N; ++i) cin >> weight[i] >> value[i];

    // 初期化
    for (int i = 0; i < MAX_N; ++i) for (int j = 0; j < MAX_V; ++j) dp[i][j] = INF;

    // 初期条件
    dp[0][0] = 0;

    // DPループ
    for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - value[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - value[i]] + weight[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }

    // 最適値の出力
    long long res = 0;
    for (int sum_v = 0; sum_v < MAX_V; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;
}

Measured memory_bytes: 89676
#include<iostream>
using namespace std;

int bubbleSort(int A[],int N){
 int sw=0;
 bool flag=1;
 for(int i=0;flag;i++){
  flag=0;
  for(int j=N-1;j>=i+1;j--){
   if(A[j]<A[j-1]){
   swap(A[j],A[j-1]);
   flag=1;
   sw++;
   }
  }
 }
 return sw;
}

int main(){
 int A[100],N,sw;
 cin >> N;
 for(int i=0;i<N;i++) cin >> A[i];

 sw=bubbleSort(A,N);
 
 for(int i=0;i<N;i++){
  if(i) cout << " ";
  cout << A[i];
  }
  cout << endl;
  cout << sw << endl;

 return 0;
}

Measured memory_bytes: 3092
<?php

//1???????????????
$inputLine = trim(fgets(STDIN));

//????§???????????????§?????????
list($comparison1, $comparison2, $comparison3) = explode(" ", $inputLine);

//1 < 2 < 3?????¶????????????
if ($comparison1 < $comparison2 && $comparison2 < $comparison3) {

	echo "Yes";

} else {

	echo "No";
}

?>

Measured memory_bytes: 15264
import sys
n = int(input())
a = [sys.maxsize]*4
for i in range(n):
	t = int(input())
	if t < a[0]:
		a[3]=a[2]
		a[2]=a[1]
		a[1]=a[0]
		a[0]=t
	elif t < a[1]:
		a[3]=a[2]
		a[2]=a[1]
		a[1]=t
	elif t < a[2]:
		a[3]=a[2]
		a[2]=t
	elif t < a[3]:
		a[3]=t

m = min(4,len(a))
ans = [sys.maxsize]*3
for i in range(m):
	for j in range(m):
		if i!=j:
			t=int(str(a[i])+str(a[j]))
			if t < ans[0]:
				ans[2]=ans[1]
				ans[1]=ans[0]
				ans[0]=t
			elif t < ans[1]:
				ans[2]=ans[1]
				ans[1]=t
			elif t < ans[2]:
				ans[2]=t
print(ans[2])



Measured memory_bytes: 5624
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#define ll long long
using namespace std;

int main() {
	ll a, b,r,tmp;
	cin >> a >> b;
	

	/* ユークリッドの互除法 */
	r = a % b;
	while (r != 0) {
		a = b;
		b = r;
		r = a % b;
	}

	/* 最大公約数を出力 */
	//printf("最大公約数 = %d\n", b);
	ll x = b,ans=1;
	for (ll i = 2; i*i <= x; i++) {
		if (b%i == 0) {
			while(b%i == 0){
				b = b / i;
			}
			ans++;
		}
	}
	if (b != 1) {
		ans++;
	}
	cout << ans << endl;



}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	ll dp[5001] = {};
	dp[2500] = 1;
	ll cop[5001] = {};
	int n; int a,x[50];
	cin >> n >> a;
	rep(i, n) {
		cin >> x[i]; x[i] -= a;
	}
	rep(i, n) {
		rep(j, 5001) {
			cop[j] = 0;
		}
		rep(j, 5001) {
			cop[j] += dp[j];
			if (0 <= j + x[i] && j + x[i] <= 5000) {
				cop[j + x[i]] += dp[j];
			}
		}
		rep(j, 5001) {
			dp[j] = cop[j];
		}
	}
	cout << dp[2500] - (ll)1 << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <numeric>
#include <set>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 999999999
#define MINF -999999999
#define ALL(n) n.begin(),n.end()

int main() {
	int n, k,s[114514],m = INF;
	cin >> n >> k;
	REP(i, n) cin >> s[i];
	sort(s, s + n);
	REP(i, n - k + 1) {
		m = min(m, s[i + k - 1] - s[i]);
	}
	cout << m << endl;
}




Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    cin >> n >> k;
    map<int, int> cnt;
    for (int i = 0; i < k; ++i) {
        int d;
        cin >> d;
        for (int j = 0; j < d; ++j) {
            int a;
            cin >> a;
            cnt[a]++;
        }
    }
    cout << n - cnt.size() << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int x,a,b,c;
    cin>>a>>b>>c>>x;
    int i,j,k,ans=0;
    for(i=0;i<=a;i++){
        for(j=0;j<=b;j++){
            for(k=0;k<=c;k++){
                ans+=(i*500+j*100+k*50)==x;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<typename T> bool chmax(T &a,T b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T &a,T b){if(a>b){a=b;return true;}return false;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef tuple<ll,ll,ll> tlll;
typedef tuple<int,int,int> tiii;
const ll mod=1e9+7;
const int inf=1<<30;

int main(){
  ll x; cin >> x;
  ll mx=0;
  while(mx*mx*mx*mx*mx<=1e18){
    mx++;
  }
  for(ll a=-mx;a<=mx;a++){
    for(ll b=-mx;b<=mx;b++){
      if(a*a*a*a*a-b*b*b*b*b==x){
        cout << a << " " << b << endl;
        return 0;
      }
    }
  }
  
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;


const ll mod=1e9+7;
const ll inf=1e16; 

#define rep(i,m,n) for(ll i=m;i<n;i++)
#define repr(i,m,n) for(ll i=m;i>=n;i--)


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

  ll n;
  string x;
  cin >> n;
  vector<string> s(n);
  vll t(n);
  ll res=0;
  rep(i,0,n) {
    cin >> s[i] >> t[i];
    res+=t[i];
  }
    cin >> x;
  
 
  rep(i,0,n){
   res-=t[i];
   if(x==s[i]) break;
  }
  cout << res << endl;
  
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <memory>
#include <string>
#include <map>
using namespace std;
#define MAX 1003

char A[MAX];
char B[MAX];

void print(){}
int DP[MAX][MAX];
int dp(int i,int j){
    if(i<0||j<0) return 0;
    if(DP[i][j]!=-1) return DP[i][j];
    if(A[i]==B[j]) return DP[i][j]=dp(i-1,j-1)+1;
    return DP[i][j]=max(dp(i,j-1),dp(i-1,j));
}
void solve(){


    int tmp;
        scanf("%d",&tmp);
        int r,c;
        while(tmp--){

                scanf("%s%s",A,B);
                r=strlen(A);
                c=strlen(B);
                memset(DP,-1,sizeof(DP));
            printf("%d\n",dp(r-1,c-1));
        }

}

int main(){

    //freopen("in","r",stdin);
    solve();
    return 0;
}

Measured memory_bytes: 7216
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(long long int i=0;i<p;i++)
#define reep(i,p) for(long long int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

ll int N ,K;
cin >> N >> K;
vector<ll int> p(N);
rep(i,N){
	cin >> p[i];
}

ll int ans = 0;
sort(p.begin(),p.end());
for(long long int i=0;i<K;i++){
	ans += p[i];
  }

cout << ans;







	return 0;

}



Measured memory_bytes: 3604
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
	int n, r, p, c;
	
	while(cin >> n >> r && n>0)
		{
			//山を作る
			int A[n];
			for(int i = 0; i<n; i++){ A[i] = n-i; }
			
			//表示
			//for(int i = 0; i<n; i++){ cout << A[i] << " "; }
			//cout << endl;
			
			for(int i = 0; i<r; i++)
			{
				cin >> p >> c;
				rotate(&A[0], &A[p-1], &A[p+c-1]);
				
				//表示
				//for(int i = 0; i<n; i++){ cout << A[i] << " "; }
				//cout << endl;
			}
			cout << A[0] << endl;
		}
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;

int main() {
  int n;
  cin >> n;
  vector<string> v(n);
  string s;
  for (int i = 0; i < n; i++) {
    cin >> s;
    if (find(v.begin(), v.end(), s) != v.end()) {
      cout << "No" << endl;
      return 0;
    } else {
      v[i] = s;
    }
  }
  for (int i = 0; i < n - 1; i++) {
    if (v[i][v[i].size() - 1] != v[i + 1][0]) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n * m) / gcd(n, m);//gl=xy
}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
 
using namespace std;


//ここから
vector<bool>visited,visited2;
vector<int>dis,dis2;
vector<vector<int>>g;

void dfs(int v,int d){
  visited[v]=true;
  dis[v]=d;
  for(auto e:g[v]){
    if(!visited[e])dfs(e,d+1);
  }
}
void dfs2(int v,int d){
  visited2[v]=true;
  dis2[v]=d;
  for(auto e:g[v]){
    if(!visited2[e])dfs2(e,d+1);
  }
}

void solve(){
  int n;
  cin>>n;
  dis.resize(n);
  dis2.resize(n);
  visited.resize(n);
  visited2.resize(n);
  g.resize(n);
  rep(i,n-1){
    int a,b;
    cin>>a>>b;
    a--;b--;
    g[a].pb(b);
    g[b].pb(a);
  }
  dfs(0,0);
  dfs2(n-1,0);
  int b=0,w=0;
  rep(i,n){
    if(dis[i]<=dis2[i])++b;
    else ++w;
  }
  if(b>w)cout<<"Fennec";
  else cout<<"Snuke";
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 9600
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Accepted
{
    class Accepted
    {
        static void Main(string[] args)
        {

            string inpString = Console.ReadLine();

            int Len = inpString.Length;

            int ret = Len - inpString.Replace("1","").Length;

            Console.WriteLine(ret);

            return;
        }
    }
}


Measured memory_bytes: 13140
import Control.Monad
import qualified Data.Set as Set

main :: IO ()
main = do
  n <- readLn
  ws <- replicateM n $ getLine :: IO [String]
  putStrLn $ solve ws


solve :: [String] -> String
solve (w:ws) = go w ws $ Set.singleton w
  where 
    go :: String -> [String] -> Set.Set String -> String
    go _ [] _ = "Yes"
    go prev (w:ws) hist 
      | Set.member w hist = "No"
      | otherwise = if last prev == head w 
                    then go w ws (Set.insert w hist)
                    else "No"
        

Measured memory_bytes: 636
#include <cstddef>
#include <functional>
#include <iostream>
#include <limits>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  long long k;
  cin >> n >> k;

  vector<long long> positive_nums;
  vector<long long> negative_nums;
  long long z = 0;
  for (int i = 0; i < n; i++) {
    long long num;
    cin >> num;
    if (num > 0) {
      positive_nums.push_back(num);
    } else if (num < 0) {
      negative_nums.push_back(num);
    } else {
      z++;
    }
  }

  sort(positive_nums.begin(), positive_nums.end());
  sort(negative_nums.begin(), negative_nums.end());
  
  long long p_size = positive_nums.size();
  long long n_size = negative_nums.size();
  long long negative_cnt = p_size * n_size;
  long long zero_cnt = z * (p_size + n_size) + z * (z - 1) / 2;
  long long ans;

  if (negative_cnt >= k) {
    long long left = -1e18 - 1ll, right = -1;
    while (right - left > 1) {
      long long mid = (left + right) / 2;
      long long cnt = accumulate(positive_nums.begin(), positive_nums.end(), 0ll,
          [&](auto acc, auto num) {
            auto right_it = upper_bound(
                negative_nums.begin(),
                negative_nums.end(),
                (mid - num + 1) / num);
            return acc + distance(negative_nums.begin(), right_it);
          });

      if (cnt < k) {
        left = mid;
      } else {
        right = mid;
      }
    }

    ans = right;
  } else if (negative_cnt + zero_cnt >= k) {
    ans = 0;
  } else {
    long long left = 1, right = 1e18 + 1ll;
    while(right - left > 1) {
      long long mid = (left + right) / 2;
      long long cnt = negative_cnt + zero_cnt;
      if (positive_nums.size() > 1) {
        for (size_t i = 0; i < positive_nums.size() - 1; i++) {
          auto it = upper_bound(
              positive_nums.begin() + i + 1,
              positive_nums.end(),
              mid / positive_nums[i]);
          cnt += distance(positive_nums.begin() + i + 1, it);
        }
      }

      if (negative_nums.size() > 1) {
        for (size_t i = 0; i < negative_nums.size() - 1; i++) {
          auto it = lower_bound(
              negative_nums.begin() + i + 1,
              negative_nums.end(),
              mid / negative_nums[i]);
          cnt += distance(it, negative_nums.end());
        }
      }

      if (cnt < k) {
        left = mid;
      } else {
        right = mid;
      }
    }

    ans = right;
  }

  cout << ans << "\n";
  return 0;
}

Measured memory_bytes: 2420
n = int(input())
s = input()

bool = True
if n % 2 == 1 :
    bool = False #奇数を除く

h = int (len(s) / 2)
#print (h)
strat_str = s[:h]
end_str = s[h:]
#print (strat_str)
#print (end_str)

if strat_str != end_str :
    bool = False
'''
half_n = n / 2
for i in range(half_n) :
    if s[i] != s[n/2 + i] :
        bool = False
        break #条件にマッチしないものを除く
'''

if bool == True :
    print ("Yes")
else :
    print ("No")


Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
    int N,M;
    cin >> N >> M;
    int max=N,min=1;
    for(int i=0;i<M;i++){
        int tmp_min,tmp_max;
        cin >> tmp_min >> tmp_max;
        if(tmp_min>min)min=tmp_min;
        if(tmp_max<max)max=tmp_max;
    }
    if(min<=max)cout << max-min+1;
    else cout << 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(ll i=a;i<n;i++)
#define rev(i,n,a) for(ll i=n-1;i>=a;i--)
#define f first
#define s second
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vpii vector<pair<int,int>>
#define vpll vector<pll>
#define pll pair<ll,ll>
#define secreterror() ios_base::sync_with_stdio(false);cin.tie(NULL);

void solve(){
    ll n;
    cin>>n;
    vector<ll>arr(n);
    ll overall=0;
    rep(i,0,n){
        cin>>arr[i];
        overall^=arr[i];
    }

    rep(i,0,n){
        ll num=overall^arr[i];
        cout<<num<<" ";
    }
    cout<<endl;
    
}


int main()
{
    secreterror()
    // ll t;
    // cin>>t;
    //while(t--){
        solve();
        
    //}

}

Measured memory_bytes: 4760
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;


int solve(char a[10], char b[10])
{
  int x = 0;
  int y = 0;
  int tmp;
  for(int i = 0; i <= strlen(a); i++){
    //a    
    if(a[i] == 'm'){
      if(i == 0){
	x += 1000;
      }
      else{
	tmp = a[i - 1] - '0';
	x += tmp * 1000;
      }
    }

    if(a[i] == 'c'){
      if(i == 0 || a[i - 1] == 'm'){
        x += 100;
      }
     else{
	tmp = a[i - 1] - '0';
	x += tmp * 100;
      }
    }

    if(a[i] == 'x'){
      if(i == 0 || a[i - 1] == 'm' || a[i - 1] == 'c'){
        x += 10;
      }
     else{
	tmp = a[i - 1] - '0';
	x += tmp * 10;
      }
    }

    if(a[i] == 'i'){
      if(i == 0 || a[i - 1] == 'm' || a[i - 1] == 'c' || a[i - 1] == 'x'){
        x += 1;
      }
     else{
	tmp = a[i - 1] - '0';
	x += tmp;
      }
    }
  }
    for(int i = 0; i <= strlen(b); i++){
    //b
    if(b[i] == 'm'){
      if(i == 0){
	y += 1000;
      }
      else{
	tmp = b[i - 1] - '0';
	y += tmp * 1000;
      }
    }

    if(b[i] == 'c'){
      if(i == 0 || b[i - 1] == 'm'){
        y += 100;
      }
     else{
	tmp = b[i - 1] - '0';
	y += tmp * 100;
      }
    }

    if(b[i] == 'x'){
      if(i == 0 || b[i - 1] == 'm' || b[i - 1] == 'c'){
        y += 10;
      }
     else{
	tmp = b[i - 1] - '0';
	y += tmp * 10;
      }
    }

    if(b[i] == 'i'){
      if(i == 0 || b[i - 1] == 'm' || b[i - 1] == 'c' || b[i - 1] == 'x'){
        y += 1;
      }
     else{
	tmp = b[i - 1] - '0';
	y += tmp;
     }
    }
  }
 
  return x + y;
}


void out(int ans)
{
  int m, c, x, i;

  m = ans / 1000;
  c = (ans - m * 1000) / 100;
  x = (ans - m * 1000 - c * 100) / 10;
  i = ans - m * 1000 - c * 100 - x * 10;


  if(m == 1) cout << "m";
  if(m - 1 > 0) cout << m << "m";

  if(c == 1) cout << "c";
  if(c - 1 > 0) cout << c << "c";

  if(x == 1) cout << "x";
  if(x - 1 > 0) cout << x << "x";

  if(i == 1) cout << "i";
  if(i - 1 > 0) cout << i << "i";

  cout << endl;
}


int main()
{
  int n;
  char a[10], b[10];
  int ans;
  scanf("%d", &n);
    for(int i = 0; i < n; i++){
      scanf("%s %s", a, b);

      ans = solve(a, b);
      //cout << ans << endl;
      out(ans);
    }
  return 0;
}

Measured memory_bytes: 1216
#ifdef __APPLE__
#include <iostream>
#include <vector>
#include <utility>
#include <stack>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <iomanip>
#include <cmath>
#include <ctgmath>
#include <math.h>
#else
#include <bits/stdc++.h>
#endif

using namespace std;
#define io ios_base::sync_with_stdio(false), cin.tie(NULL)
#define GFOR(i,a,n) for (i=a;i<n;i++)
#define FOR(i,a,n) for (int i=a;i<n;i++)
#define RFOR(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define tc(t) for (int tc=1; tc<=t; tc++)
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<long long int> vll;
typedef vector<pair<int, int> > vpi;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll modInverse (ll a) {ll p = mod - 2; return powmod(a, p);}
// head

void solve() {
    int n;
    cin >> n;
    vi a(n);
    unordered_map<int, int> data;
    ll sum = 0;
    for (auto &x : a)
        cin >> x, data[x]++, sum += (ll)x;

    int q, b, c;
    cin >> q;

    FOR (i, 0, q) {
        cin >> b >> c;
        auto it = data.find(b);
        if (it == data.end()) {
            cout << sum << "\n";
            continue;
        }
        int f = it->second;
        data.erase(b);
        data[c] += f;

        sum += (c - b)*(ll)f;
        cout << sum << "\n";
    }
}

int main() {
    io;
    int t = 1;
    tc(t) {
        solve();
    }
}
//check for edge cases in limits
//printing double may print 1.223232e9 like values, beware of that


Measured memory_bytes: 7040
/*
START BY THE NAME OF ALMIGHTY ALLAH
THIS WONT BE ACCEPTED
STOP_GIVING_UP

██╗███████╗████████╗██╗ █████╗ ██╗  ██╗
██║██╔════╝╚══██╔══╝██║██╔══██╗██║ ██╔╝
██║███████╗   ██║   ██║███████║█████╔╝
██║╚════██║   ██║   ██║██╔══██║██╔═██╗
██║███████║   ██║   ██║██║  ██║██║  ██╗
╚═╝╚══════╝   ╚═╝   ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝

*/
#include<bits/stdc++.h>
#define l(i,a,n)for(int i=a;i<n;i++)
#define pb push_back
#define in insert
#define mp make_pair
#define lw(v) sort(v.begin(),v.end());
#define hi(v) sort(v.begin(),v.end(),greater<long long>());
#define all(v) v.begin(),v.end()
#define filein freopen ("input.txt", "r", stdin)
#define fileout freopen ("output.txt", "w", stdout)
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    long long t,r=1,r1=0,r2=0,k=0,a,b,c=1,m,d=0,n,e,f,x=0,g,p=0,q=0,y=0,z=0;
    vector<long long>v;
    vector<long long>u;
    set<long long>s;
    std::vector<int>::iterator it;
    string  s1,s2,s3,s4;
    cin>>n>>m;
    b=m;
    l(i,1,n)
    {
        cin>>a;
        if(a>=b)
        {
            d++; b=a;
        }

    }
  cout<<d+1<<endl;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>

using namespace std;

int main(int argc, char* argv[]) {
  string s;
  cin >> s;

  int ret;
  for (int i = s.size() - 2; i > 0; --i) {
    if ((i + 1) % 2 == 1)
      continue;
    bool is_even = true;
    for (int j = 0; j < (i + 1) / 2; ++j) {
      if (s[j] != s[(i + 1) / 2 + j]) {
        is_even = false;
        break;
      }
    }
    if (is_even) {
      ret = i + 1;
      break;
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RREP(i, a, b) for (int i = (int)(a)-1; i >= (int)(b); --i)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) RREP(i, n, 0)
#define ALL(r) (r).begin(), (r).end()

void Main();

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main() {
    string s; cin >> s;
    if (s[0] == s[1] && s[1] == s[2]) {
        if (s[1] == 'R') {
            cout << 3;
        } else {
            cout << 0;
        }
    } else
    if ((s[0] == s[1] || s[1] == s[2]) && s[1] == 'R') {
        cout << 2;
    } else {
        cout << 1;
    }
    cout << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#define ALF 26
using namespace std;

int main(){
	string h[3] = {"the","that","this"};
	string s;
	while(getline(cin,s)){
	int c = 0;
	for(int j=0;j<ALF;j++){
		for(int m=0;m<3;m++){
			for(int k=0;k<=s.size()-h[m].size();k++){
				string t = s.substr(k,h[m].size());
				for(int l=0;l<h[m].size();l++) t[l] = (t[l]-'a'+j)%ALF + 'a';
				if(t==h[m]) c = j;
			}
		}
	}
	for(int j=0;j<s.size();j++){
		if('a'<=s[j] and s[j]<='z') s[j] = (s[j]-'a'+c)%ALF + 'a';
	}
	cout << s << endl;
	}
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
#define FORR(I,A,B) for(ll I = ((B)-1); I >= (A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a<b)swap(a,b);if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}//saisyo kobaisu
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=1e18+7;
const ll MOD=1e9+7;
#define pri(a) cout << (a) << endl


int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll N;
	cin >> N;
	vector<ll> A(N+2,0);
	FOR(i,1,N+1)cin >> A[i];
	ll sum = 0;
	FOR(i,0,N+1){
		sum += abs(A[i]-A[i+1]);
	}
	FOR(i,1,N+1){
		ll m = abs(A[i]-A[i+1])+abs(A[i]-A[i-1]);
		ll p = abs(A[i-1]-A[i+1]);
		cout << sum - m + p << endl;
	}
}

Measured memory_bytes: 2048
#define _CRT_SECURE_NO_WARNINGS
#include <cassert>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
ll MOD = 1000000007LL;

int N, M;
int A[1003], B[1003];

void imposs() {
	puts("0");
	exit(0);
}

int main() {
	cin >> N >> M;
	for (int i=1; i<=N; i++) cin >> A[i];
	for (int i=1; i<=M; i++) cin >> B[i];

	sort(A+1, A+N+1); reverse(A+1, A+N+1);
	sort(B+1, B+M+1); reverse(B+1, B+M+1);

	for (int i=1; i<=N-1; i++) if (A[i] == A[i+1]) imposs();
	for (int j=1; j<=M-1; j++) if (B[j] == B[j+1]) imposs();
	if (A[1]!=M*N || B[1]!=M*N) imposs();

	int i = 1;
	int j = 1;
	int occupied = 0;
	ll ans = 1;
	for (int v=N*M; v>=1; v--) {
		if (i+1<=N && A[i+1]>=v) i++;
		if (j+1<=M && B[j+1]>=v) j++;

		if (i*j <= occupied) imposs();

		if (A[i]==v && B[j]==v) ans *= 1;
		else if (A[i]==v) ans *= j;
		else if (B[j]==v) ans *= i;
		else ans *= ((i*j)-occupied);

		occupied++;
		if (ans == 0) imposs();
		ans %= MOD;
	}
	
	ans %= MOD;
	cout << ans << endl;





	return 0;
}

Measured memory_bytes: 256