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

int main()
{
    string s;
    cin>>s;
    int n=s.size(),x=0;
    for(int i=0;i<n/2;i++)
        if(s[i]!=s[n-1-i]) x++;
    cout<<x;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cassert>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>

using namespace std;

#define all(c) begin(c), end(c)
#define dump(c) cerr << "> " << #c << " = " << (c) << endl
#define REP(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;

const int INF = 1001001001;
const double EPS = 1e-10;


template<typename T1,typename T2>
ostream& operator<<(ostream& os, const pair<T1,T2>& p){
  return os << '(' << p.first <<',' << p.second << ')';
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& a){
  os << '[';
  rep(i,a.size()) os << (i ? " " : "") << a[i];
  return os << ']';
}

vector<int> get_primes(int N) {
  vector<int> table(N, 1);
  table[0] = table[1] = 0;
  for(int i = 2; i * i < N; i++) if(table[i])
      for(int j = i * i; j < N; j += i) table[j] = 0;

  vector<int> ret;
  rep(i, N) if(table[i]) ret.push_back(i);

  return ret;
}

int main() {
  auto primes = get_primes(2000000);

  for(int N; cin >> N, N != 0; ) {
    auto low = upper_bound(all(primes), N) - 1;
    if (*low == N) cout << 0 << endl;
    else cout << *(low + 1) - *low << endl;
  }
  
  
  return 0;
}

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

const int MAXN = 110;
const int MAXK = 1e5+10;

using ll = long long;

int N, K;
int a[MAXN];

// dp[i]: can i stones win?
int dp[MAXK];

int main() {
    cin >> N >> K;
    for(int i=1; i<=N; i++) cin >> a[i];
    sort(a+1, a+N+1);
    
    dp[0] = 0;
    for(int i=a[0]; i<=K; i++) {
        int flag = 0;
        for(int j=1; j<=N; j++) {
            if(i-a[j]>=0 && !dp[i-a[j]]){
                flag = 1;
                break;
            } 
        }
        if(flag) dp[i] = 1;
    }
    string res = dp[K]?"First":"Second";
    cout << res << endl; 
    return 0;
}

Measured memory_bytes: 4028
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define arep(x,n) for (int x: n)
using namespace std;
using ll = long long;

int main()
{
    int x;
    cin >> x;
    int ans;
    if(x >= 400 && x <= 599) ans = 8;
    else if (x >= 600 && x <= 799) ans = 7;
    else if (x >= 800 && x <= 999) ans = 6;
    else if (x >= 1000 && x <= 1199) ans = 5;
    else if (x >= 1200 && x <= 1399) ans = 4;
    else if (x >= 1400 && x <= 1599) ans = 3;
    else if (x >= 1600 && x <= 1799) ans = 2;
    else if (x >= 1800 && x <= 1999) ans = 1;

    cout << ans << endl;
}

Measured memory_bytes: 3632
<?php
fscanf(STDIN,'%d',$N);
for ($i=1; $i <=$N ; $i++) {
  // code...
  $count=0;
  for ($m=1; $m <=$i ; $m++) {
    // code...
    if($i%$m==0){
      $count++;

    }
  }
  if($count==8){
   $array[]=$i;
  }
}
$count2=0;
for ($l=0; $l <count($array) ; $l++) {
  // code...
  if($array[$l]%2==1){
    $count2++;
  }
}
echo $count2;
 ?>


Measured memory_bytes: 3700
//BROWNIE TK

#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define pb push_back
#define popb pop_back()
#define pf push_front
#define popf pop_front()
#define si size()
#define be begin()
#define en end()
#define all(v) v.be, v.en
#define le length()
#define mp make_pair
#define mt make_tuple
#define F first
#define S second

#define forz(i, n) for (int i = 0; i < n; i++)
#define forzm(i, m, n) for (int i = m; i < n; i++)
#define rforz(i, n) for (int i = n - 1; i >= 0; i--)
#define rforzm(i, m, n) for (int i = n - 1; i >= m; i--)
#define deci(n) fixed << setprecision(n)
#define high(n) __builtin_popcount(n)
#define parity(n) __builtin_parity(n)
#define ctz(n) __builtin_ctz(n)
#define lb lower_bound
#define ub upper_bound
#define er equal_range
#define maxe *max_element
#define mine *min_element
#define mod 1000000007
#define mod2 998244353
#define kira ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)

#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl

#define oset tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define osetlli tree<lli, null_type, less<lli>, rb_tree_tag, tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
#define ofk order_of_key
#define fbo find_by_order
using namespace std;

/*STD fucntions*/
lli power(lli x, lli y, lli p)
{
    lli res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        //y must be even now
        y = y >> 1; //y=y/2
        x = (x * x) % p;
    }
    return res;
}
lli gcd(lli a, lli b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
lli lcm(lli a, lli b)
{
    return a * b / gcd(a, b);
}
lli modi(lli a, lli m)
{
    // fermat little thm where m is prime
    return power(a, m - 2, m);
}
/*CODE BEGINS*/
int main()
{
    kira;
    lli k,x;
    cin>>k>>x;
    lli m=1e6;
    for(int i=max(-m,x-k+1);i<=min(m,x+k-1);i++)p0(i);
    return 0;
}

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

int main() {
	int h, w;
	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0) break;

		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (i % 2 == 0) {
					if (j % 2 == 0) cout << "#";
					else cout << ".";
				}
				else {
					if (j % 2 == 0) cout << ".";
					else cout << "#";
				}
			}
			cout << endl;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// 端点を間違えないように気をつけること!
#define FOR(i, m, n) for (ll i = (ll)(m); i <= (ll)(n); i++)
#define RFOR(i, m, n) for (ll i = (ll)(m); i >= (ll)(n); i--)
ll amari(ll a, ll b)
{
    if (a >= 0)
    {
        return a % b;
    }
    else
    {
        ll c = (-a) % b;
        return (b - c) % b;
    }
}

int main()
{
    ll N, L, T, t_1, t_2, kijun = 0;
    cin >> N >> L >> T;
    t_1 = (T / L) % N;
    t_2 = T % L;
    ll X[N], W[N];
    vector<ll> Y;
    FOR(i, 0, N - 1)
    {
        cin >> X[i] >> W[i];
        if (W[i] == 1)
        {
            Y.push_back(amari(X[i] + T, L));
            kijun -= t_1;
            if (X[i] + t_2 >= L)
            {
                kijun--;
            }
        }
        else
        {
            Y.push_back(amari(X[i] - T, L));
            kijun += t_1;
            if (X[i] - t_2 < 0)
            {
                kijun++;
            }
        }
    }
    kijun = amari(kijun, N);
    sort(Y.begin(), Y.end());
    FOR(i, 0, N - 1)
    {
        if (i < kijun)
        {
            cout << Y[i + N - kijun] << endl;
        }
        else
        {
            cout << Y[i - kijun] << endl;
        }
    }
}

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

int main(void){
  int n;cin >> n;
  int a;
  deque <int> b;
  for(int i=0;i<n;i++)
  {
    cin >> a;
    if(i%2==0)
    {
      b.push_back(a);
    }else
    {
      b.push_front(a);
    }

  }
  if(n%2==0)
  {
    for(auto i=b.begin();i!=b.end();i++)
    {
      cout << *i;
      if(i!=b.end()-1)
      {
        cout <<" ";
      }
    }
  }
  else
  {
    for(auto i=b.end()-1;i!=b.begin()-1;i--)
    {
      cout << *i;
      if(i!=b.begin())
      {
        cout <<" ";
      }
    }
  }


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


Measured memory_bytes: 2944
n,k = map(int, input().split())
x=0
i=0
pro=0.0
ans=0.0

for i in range(1,n+1):
    x=i
    j=0
    while x<k:
        j=j+1
        x=x*2
    pro=(1/n)*((1/2)**j)
    ans=ans+pro

print(ans)


Measured memory_bytes: 3060
w, h, n = list(map(int, input().split()))
c = [[] for _ in range(n)]
g = [[0] * w for _ in range(h)]
for i in range(n):
    x, y, a = map(int, input().split())
    if a == 1:
        for H in range(h):
            for W in range(x):
                g[H][W] = 1
    elif a == 2:
        for H in range(h):
            for W in range(x, w):
                g[H][W] = 1
    elif a == 3:
        for H in range(y):
            for W in range(w):
                g[H][W] = 1
    else:
        for H in range(y, h):
            for W in range(w):
                g[H][W] = 1
cnt = 0
for i in g:
    cnt += i.count(0)
print(cnt)


Measured memory_bytes: 9088
import fractions
import sys
from functools import reduce
import math

input = sys.stdin.readline


def main():
    n, a, b, c, d = input_list()
    s = input()
    uses = s[a-1:d]
    if '##' in uses:
        print('No')
        exit()
    if c < d:
        print('Yes')
    else:
        end = d+1 if d < len(s) else d
        if '...' in s[b-2:end]:
            print('Yes')
        else:
            print('No')


def get_camulative(l):
    import itertools
    # 累積和
    return [0] + list(itertools.accumulate(l))

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


def input_list():
    return list(map(int, input().split()))


def input_list_str():
    return list(map(str, input().split()))


def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)


def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


def gcd(*numbers):
    return reduce(fractions.gcd, numbers)


def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)


if __name__ == "__main__":
    main()


Measured memory_bytes: 65388
import sys
input = sys.stdin.readline
#from itertools import permutations


mod = 10**9+7 #出力の制限
N = 2*10**5 + 1
#N = nN
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル



def main():
    #N = int(input())
    N,P = map(int, input().split())
    #vP = tuple(map(int, input().split()))
    vA = list(map(int, input().split()))
    #vA = list(range(1,N+1))
    
    dp = [1, 0]
    print(dp, file=sys.stderr)
    for i,c in enumerate(vA,1):
        a = c%2
        p0, p1 = dp[a], dp[1^a]
        dp[0] += p0
        dp[1] += p1
    print(dp, file=sys.stderr)
    print(dp[P])
    #S = input().rstrip()
    #print(S)
    #print(lcm(N, M))
    #print("Yes" if X<=500*K else "No")
    #print(S.count("ABC"))
    #print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define M 1000001
#define L 14
#define NTL (-1)

char H[M][L];

int getChar(char ch){
  if(ch=='A')return 1;
  else if(ch=='C') return 2;
  else if(ch=='G')return 3;
  else if(ch=='T')return 4;
  else return 0;
}


long long getKey(char str[]){
  long long sum=0,p=1,i;
  for(i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
    p*=5;
  }
  return sum;
}


int h1(int key){return key%M;}
int h2(int key){return 1+(key%(M-1));}

int find(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0; ;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])== 0)return 0;
  }
  return 0;
}

int insert(char str[]){
  long long key,i,h;
  key=getKey(str);
  for(i=0;;i++){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(H[h],str)==0)return 1;
    else if(strlen(H[h])==0){
      strcpy(H[h],str);
      return 0;
    }
  }
  return 0;
}

int main(){
  int i,n,h;
  char str[L],com[9];

  for(i=0;i<M;i++)H[i][0]='\0';
  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf("%s %s", com, str);
    if(com[0]=='i') insert(str);
    else {
      if(find(str)){
	printf("yes\n");
      }
      else {
	printf("no\n");
      }
    }
  }
  return 0;
}
  




Measured memory_bytes: 15412
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdlib>
#include <string>
#include <cstring>
#include <cmath>
#include <climits>
#define endl '\n'
#define ll long long
#define mod 1000000007
#define NCONS 200001

using namespace std;

int main(void)
{
    cin.tie(NULL); ios_base::sync_with_stdio(false);
    int N; cin >> N;
    double ret = 0;
    
    while(N--)
    {
        double input; string str;
        cin >> input >> str;
        if(str == "JPY")
        {
            ret += input;
        }
        else
        {
            ret += input * 380000;
        }
    }
    
    
    cout << ret << endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#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 999999999999
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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

int main() {
	llong W,H,x,y;
    cin >>W >> H >> x >> y;

    double mx = W/2.0;double my=H/2.0;
    int a = (x==mx && y==my);
    cout << double(W)*H/2.0 << " "<< a << endl;


    return 0;
    




}


Measured memory_bytes: 256
//“Make it work, make it right, make it fast.” – Kent Beck
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dd;
const int siz = 1e6 + 5;
const int MOD = 1e9 + 7;
#define endl '\n'
#define deb(x) cout << #x << " = " << x << endl;
void solve(){
	int a, b;
	cin >> a >> b;
	double A = 0.08, B = 0.1;
	double ans = 0;
	bool flag = 0;
	for(int i = 1; i <= 1002; i++){
		if(floor(i*A) == (double)a && floor(i*B) == (double)b){
			ans = i;
			flag = 1;
			break;
		}
	}
	if(flag)
		cout << (int)ans;
	else
		cout << -1 << endl;
}

int main(){
	#ifndef RAY
		//freopen("input.txt", "r", stdin);
	#endif
		ios::sync_with_stdio(false);
		cin.tie(nullptr);
		int t = 1;
		//cin >> t;
		while(t--){
			solve();
		}
	return 0;
}


Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <cstdio>
#include <vector>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
using namespace std;

const int MOD = 1e9 + 7;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
#define fst first
#define snd second

template<class T>
void Max(T &x, T y) {
    if (x < y) x = y;
}

template<class T>
void Min(T &x, T y) {
    if (x > y) x = y;
}

ll gcd(ll a, ll b) {
    return !b ? a : gcd(b, a % b);
}

ll mod_pow(ll a, ll b, ll c) {
    ll ans = 1;
    while (b > 0) {
        if (b & 1) ans = ans * a % c;
        a = a * a % c;
        b >>= 1;
    }
    return ans;
}

int t[100010], a[100010];

int main(void) {

    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    for (int i = 0; i < n; ++ i) cin >> t[i];
    for (int i = 0; i < n; ++ i) cin >> a[i];

    ll ans = 1, mi = t[0], ma = a[0];
    if (mi > ma || t[n - 1] < a[n - 1]) {
        cout << 0 << endl;
        return 0;
    }
    for (int i = 1; i < n - 1; ++ i) {
        if (t[i] < t[i - 1]) {
            ans = 0;
            break;
        }
        if (a[i] > a[i - 1]) {
            ans = 0;
            break;
        }

        if (t[i] > t[i - 1] && t[i] > a[i]) {
            ans = 0;
            break;
        }

        if (t[i] == t[i - 1] && a[i] == a[i + 1]) {
            ans = ans * min(t[i], a[i]) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;using v=vector<int>;int n;bool h(v a,v b){bool r=1;for(int i=0;i<n;i++)r&=(a[i]!=b[i]);return r;}void f(bool g, v a) {cout<<(g?"Yes\n":"No\n");if(g)for(int e:a)cout<<e<<'\n';}int main(){cin>>n;v a(n),b(n),c;for(int&e:a)cin>>e;for(int&e:b)cin>>e;c=b;reverse(begin(b),end(b));rotate(begin(c),begin(c)+(n/2),end(c));if(h(a, b))f(1, b);else if(h(a, c))f(1, c);else f(0, a);}

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

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define X first
#define Y second
#define pb push_back
#define make_unique(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define int long long

const LL mod = 1e9 + 7;


template<class T>
istream& operator >> (istream& in, vector<T>& v){ for (auto &x : v) { in >> x; } return in; }

template<class T, class U>
istream& operator >> (istream& in, pair<T, U> & v){ in >> v.X >> v.Y;return in; }

template<class T, class U>
ostream& operator << (ostream& out, pair<T, U> & v){ out << v.X << " " << v.Y;return out; }

void chkmax(int &a, int b) {
    a = max(a, b);
    return;
}

void chkmin(int &a, int b) {
    a = min(a, b);
    return;
}

LL ppow (LL x, LL s) {
    if (!s) return 1;
    if (!(s - 1)) return x % mod;
    if (s % 2) return (x * ppow (x, s - 1)) % mod;
    LL b = ppow (x, s / 2);
    return (b * b) % mod;
}

main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    //freopen("ILUXA.in", "r", stdin);
    int n;
    cin >> n;
    vector<vector<int> > gg(n, vector<int> (3));
    cin >> gg;
    int dp[n][3];
    dp[0][0] = gg[0][0];
    dp[0][1] = gg[0][1];
    dp[0][2] = gg[0][2];

    for (int i = 1;i < n;i++) {
        dp[i][0] = max(dp[i - 1][1], dp[i - 1][2]) + gg[i][0];
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][2]) + gg[i][1];
        dp[i][2] = max(dp[i - 1][1], dp[i - 1][0]) + gg[i][2];
    }
    int ans = max(max(dp[n - 1][0], dp[n - 1][1]), dp[n - 1][2]);
    cout << ans;

    return 0;
}


Measured memory_bytes: 8064
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORD(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

// 10で何回割れるかは、min(2で何回割れるか, 5で何回割れるか)
ll f(ll n)
{
  if (n < 2)
  {
    return 1;
  }
  return n * f(n - 2);
}

ll g1(ll n, int p)
{
  if (n == 0)
    return 0;
  return n / p + g1(n / p, p);
}

ll g2(ll n, int p)
{
  if (n % 2 == 1)
  {
    return g1(n, p) - g2(n - 1, p);
  }
  ll res = g1(n / 2, p);
  if (p == 2)
  {
    res += n / 2;
  }
  return res;
}

int main()
{
  ll n;
  cin >> n;
  ll ans = min(g2(n, 2), g2(n, 5));
  cout
      << ans << "\n";
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int K, X;
    cin >> K >> X;
    if(K*500 >= X) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
/* ＵＴＦ－８ */
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	
	int X, Y;
	std::cin >> X >> Y;

	int result = 0;
	if (X <= 3)
		result += 100000 * (4-X);
	if (Y <= 3)
		result += 100000 * (4-Y);
	if (X == 1 && Y == 1)
		result += 400000;

	std::cout << result << "\n";
}


Measured memory_bytes: 256
N=int(input())
a,b=map(int,input().split())
list=list(map(int,input().split()))
list1=[]
list2=[]
list3=[]
list.sort()
for i in range(len(list)):
    if list[i]<=a:
        list1.append(list[i])
    elif a+1<=list[i]<=b:
        list2.append(list[i])
    else:
        list3.append(list[i])
print(min(len(list1),len(list2),len(list3)))

Measured memory_bytes: 3064
package main

import (
	"fmt"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func main() {
	var N int
	fmt.Scan(&N)
	s := make([][]int, N)
	for i := range s {
		ss := make([]int, 3)
		for j := range ss {
			fmt.Scan(&ss[j])
		}
		s[i] = ss
	}
	ans := "Yes"
	difT := 0
	difD := 0
	if N == 1 {
		difT = s[0][0]
		difD = s[0][1] + s[0][2]
		if difT-difD < 0 || (difT-difD)%2 == 1 {
			ans = "No"
		}
	} else {
		for i := 0; i < N-1; i++ {
			difT = s[i+1][0] - s[i][0]
			difD = abs(s[i+1][1]-s[i][1]) + abs(s[i+1][2]-s[i][2])
			if difT-difD < 0 || (difT-difD)%2 == 1 {
				ans = "No"
				break
			}
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 10496
#include <iostream>
#define INF 1000000000

int main(){
    int N;
    std::cin >> N;
    int maxi = -INF;
    
    int R[200010];
    for(int k=0; k<N; k++){
        std::cin >> R[k];
    }

    int mini = R[0];

    for(int i=1; i<N; i++){
        maxi = std::max(maxi, R[i] - mini);
        mini = std::min(mini, R[i]);
    }

    std::cout << maxi << std::endl;
}


Measured memory_bytes: 3856
n = int(input())

divisors = set()
for i in range(1, int(n**.5)+1):
    if n % i == 0:
        divisors |= {i, n//i}
ans = 0
for div in divisors:
    m = div-1
    if m <= n//div:
        continue
    ans += m
print(ans)


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

typedef long long ll;
typedef vector< ll > vi;
typedef vector< vi > vvi;
typedef pair< ll,ll > ii;
#define pb push_back
#define mp make_pair
#define all(c) ((c).begin(), (c).end)
#define sz(a) int((a).size())
#define tr(c,i) for(typeof(c).begin() i = (c).begin();it!=(c).end();it++)
#define present(c,x) ((c).find(x)!=(c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end)
#define cp(s,c) copy(all(c),(s).begin())
// note that data is copied from C --> S's reference

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int s, w;
    cin >> s >> w;
    cout << ((w >=s)?"unsafe":"safe") << endl;
    return 0;
}

Measured memory_bytes: 3600
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
S = input()[::-1]

def check(a):
    for i in range(min(N, a+M), a, -1):
        if S[i] == '0':
            return i
    return a

i = 0
ans = []
while i < N:
    res = check(i)
    if res == i:
        print(-1)
        exit()
    ans.append(res-i)
    i = res
print(*ans[::-1])


Measured memory_bytes: 50800
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] p = new int[N];
		for(int i = 0; i < N; i++) {
			p[i] = sc.nextInt();
		}
		sc.close();
		int r = 0;
		for(int i = 0; i < N; i++) {
			if(p[i] != i + 1) r++;
		}
		System.out.println(r <= 2 ? "YES" : "NO");
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

inline ll digit(char c) {
    return '0' <= c && c <= '9' ? c - '0' : c - 'a' + 10;
}

int main() {

    vector<string> clr = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
    vector<vector<ll>> clrv = {
        {0, 0, 0},
        {0, 0, 0xff},
        {0, 0xff, 0},
        {0, 0xff, 0xff},
        {0xff, 0, 0},
        {0xff, 0, 0xff},
        {0xff, 0xff, 0},
        {0xff, 0xff, 0xff}
    };

    string cl;
    while (cin >> cl, cl != "0") {

        ll r = digit(cl[1]) * 16 + digit(cl[2]);
        ll g = digit(cl[3]) * 16 + digit(cl[4]);
        ll b = digit(cl[5]) * 16 + digit(cl[6]);

        ll d2min = 0x7FFFFFFFFFFFFFFFLL, did = -1;
        for (ll i = 8; i--; ) {
            ll dr = clrv[i][0] - r;
            ll dg = clrv[i][1] - g;
            ll db = clrv[i][2] - b;
            ll d2 = dr*dr + dg*dg + db*db;
            if (d2min > d2) {
                d2min = d2;
                did = i;
            }
        }
        cout << clr[did] << "\n";
        
    }

}


Measured memory_bytes: 3204
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);
		
		int a = stdIn.nextInt();
		int b = stdIn.nextInt();
		
		if(a*b%2 == 0)
		{
			System.out.println("Even");
		}
		else
		{
			System.out.println("Odd");
		}

	}

}


Measured memory_bytes: 35484
import java.util.Scanner;


public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        for (int i = 0; i < s.length(); i++) {
            int a = (s.charAt(i) + n);
            if (a > 90) {
                a = a % 90 + 64;
            }
            System.out.print((char)(a));
        }
    }
}

Measured memory_bytes: 26452
n = int(input())
a = list(map(int, input().split()))

X, x = sum(a), a[0]
min_y = abs(X-2*x)

for i in range(1, n-1):
    x += a[i]
    if abs(X-2*x) < min_y:
        min_y = abs(X-2*x)

print(min_y)


Measured memory_bytes: 24832
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using lint = long;
using llint = long long;
using namespace std;

int main() {
    fastIO;
    int a, b;
    char op;
    while (true) {
        cin >> a >> op >> b;
        switch (op) {
        case '+':
            cout << a + b << endl;
            break;
        case '-':
            cout << a - b << endl;
            break;
        case '*':
            cout << a * b << endl;
            break;
        case '/':
            cout << a / b << endl;
            break;
        case '?':
            return 0;
        }
    }
}




Measured memory_bytes: 3148
#include<stdio.h>
#include<math.h>
int hantei(int n){
int i;
for(i=2;i<=sqrt(n);i++){
if(n%i==0){
return 0;
}
}
return 1;
}

int main(){
int n,i,count,array[999999];
for(i=0;i<999999;i++){
array[i]=hantei(i+1);
}
while(scanf("%d",&n)!=EOF){
count=-1;
for(i=0;i<n;i++){
count+=array[i];
}
printf("%d\n",count);
}
return 0;
}

Measured memory_bytes: 4500
#include<cstdio>
#include<iostream>
#include<vector>
#include<queue>
#include<bitset>
#include<string>
#include<stack>
#include<set>
#include<map>
#include<cstring>
#include<complex>
#include<cmath>
#include<algorithm>
#include<list>
#include<functional>
#define mp make_pair
#define X first
#define Y second
#define INF 1987654321
#define PI 3.14159265358979323846264
#define MOD 1000000007LL
#define fup(i,a,b,c) for(int (i)=(a);(i)<=(b);(i)+=(c))
#define fdn(i,a,b,c) for(int (i)=(a);(i)>=(b);(i)-=(c))
#define MEM0(a) memset(a,0,sizeof(a));
#define MEM_1(a) memset(a,-1,sizeof(a));
#define ALL(a) a.begin(),a.end()
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
typedef vector<int> Vi;
typedef vector<ll> Vll;
typedef vector<double> Vd;
typedef vector<Pi> VPi;
typedef vector<Pll> VPll;
typedef vector<Pd> VPd;
typedef complex<double> base;
ll POW(ll a, ll b) { if (b == 0)return 1; if (b == 1)return a; if (b & 1)return (a*POW(a, b - 1)) % MOD; ll t = POW(a, b / 2); return (t*t) % MOD; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int dx[] = { 0,-1,1,0 }, dy[] = { 1,0,0,-1 };//동북남서

char s[200001];
int main() {
	stack<char> st;
	scanf("%s", s);
	for (int i=0;s[i];i++)
	{
		char c = s[i];
		if (c == 'S')st.push(c);
		else if (!st.empty() && st.top() == 'S')st.pop();
		else st.push(c);
	}
	printf("%d", st.size());
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<string>
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<map>
#include<set>
#include<limits>
#include<bitset>
#include<array>
#include<numeric>
#include<iomanip>
#include<functional>
#include<deque>

using namespace std;
typedef long long int ll;

#define C cout<<
#define E <<endl

ll n,m,a,b,c,x,y,z,aa[200010],ab[200010],ac[100010];
bool r,ra,rb,rc;
string s,sa,sb,sc[1000];
char ca,cb,cc,cd[1000][1000];
vector<int> va,vb,vc;

void wi107(ll &nq){
    nq=nq%1000000007;
}

int main(){
    cin>>n;
    cin>>s;
    c=0;
    x=0;
    
    for(int i=1;i<s.size();i++){
        if(s[i]=='E')x++;
    }
    y=x;
    //C x<<" ";
    for(int i=1;i<s.size();i++){
        if(s[i-1]=='W')x++;
        if(s[i]=='E')x--;
        y=min(x,y);
        //C x<<" ";
    }
    C y E;
    
    
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll f(ll a) {
    if (a%2)
        return (a+1)/2%2;
    return a/2%2^a;
}

int main() {
    ll a,b;cin>>a>>b;
    cout<<(f(a-1)^f(b))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, ll> Pl;
const double PI = 3.1415926535897932;   // acos(-1)
const double EPS = 1e-15;
const int mod = 1e+9 + 7;
const int INF = 1e+9;

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

    int n;
    cin >> n;
    vector<P> info(n);
    for(int i = 0; i < n; ++i){
        int a;
        cin >> a;
        info[i] = P(a, i);
    }
    sort(info.begin(), info.end());
    set<int> s;
    ll res = 0;
    for(int i = 0; i < n; ++i){
        s.insert(info[i].second);
        int left = 0, right = n-1;
        auto it = s.find(info[i].second);
        if(it != s.begin())     left = *--it + 1;
        it = s.find(info[i].second);
        if(++it != s.end())     right = *it - 1;
        
        res += (ll)info[i].first * (right - info[i].second + 1) * (info[i].second - left + 1);
    }
    cout << res << endl;
}

Measured memory_bytes: 11264
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;

int main() {
    lint N, K;
    cin >> N >> K;

    vector<lint> A(N);
    for(auto& elem : A)  cin >> elem;
    for(auto& elem : A)  elem--;

    if(K <= N+N) {
        lint idx = 0;
        for(lint i=0; i<K; i++) {
            idx = A[idx];
        }
        cout << ++idx << endl;
        return 0;
    }

    vector<lint> v;
    map<lint, lint> prev;
    lint idx = 0, loop;
    for(lint i=0;; i++) {
        if(prev.count(idx)) {
            loop = i - prev[idx];
            break;
        }
        prev[idx] = i;
        v.push_back(idx);
        idx = A[idx];
    }
    K -= (v.size() - loop);
    vector<lint> vec(v.end()-loop, v.end());
    cout << ++vec[K%vec.size()] << endl;
}

Measured memory_bytes: 16040
a, b, c = map(int, input().split())

amari = []

for i in range(0, 10000000):
    d = a * i
    if d % b == c:
        print("YES")
        break

    else:
        if d % b not in amari:
            amari.append(d % b)
        else:
            print("NO")
            break


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,C,b2,i;
   cin>>A;
   cin>>B;
   cin>>C;
  b2=A-B;
   i=C-b2;

  if(i<0)
    cout<<"0";
  else if(B<A)
  cout<<i;
  else
  cout<<C;
  
  
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#define ll long long
using namespace std;

const int N = 1e5 + 7;
const long long oo = 1e18L + 5;

int n, k, w[101], v[101];

int main() {
    cin >> n >> k;
    int sum_values = 0;
    for (int i = 0; i < n; ++i) {
        cin >> w[i] >> v[i];
        sum_values += v[i];
    }
    // dp[i]: minimum total weight of items with total values i
    vector<vector<int>> dp(n + 1, vector<int>(sum_values + 1, 1e9));
    dp[0][0] = 0;
    for (int i = 0; i < n; ++i) {
        for (int cur_value = 0; cur_value <= sum_values; cur_value++) {
            // take an item: 1. increase the value 2. decrease the weight
            if (cur_value + v[i] <= sum_values) {
                dp[i + 1][cur_value + v[i]] = min(dp[i + 1][cur_value + v[i]], dp[i][cur_value] + w[i]);
            }
            // not take an item
            dp[i + 1][cur_value] = min(dp[i][cur_value], dp[i + 1][cur_value]);
        }
    }
    int ans = 0;
    for (int i = 0; i <= n; ++i) {
        for (int cur_value = sum_values; cur_value >= 0; cur_value--) {
            if (dp[i][cur_value] <= k) {
                ans = max(ans, cur_value);
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 40192
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
#include <cmath>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
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 ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N,M;cin>>N>>M;
    int a[50],b[50],c[50],d[50];
    REP(i,N) cin >> a[i] >> b[i];
    REP(i,M) cin >> c[i] >> d[i];
    REP(i,N){
        ll val = INF;
        int idx;
        for(int j=M-1;j>=0;--j){
            ll diff = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(diff<=val){
                val = diff;
                idx = j;
            }
        }
        cout << idx+1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// Problem : C - Ubiquity
// Contest : AtCoder - AtCoder Beginner Contest 178
// URL : https://atcoder.jp/contests/abc178/tasks/abc178_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

//#pragma GCC optimize "trapv"//  WA to RE int!!
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<n;i++)
#define FORR(i,n) for(int i=n;i>=0;i--)
#define pb push_back
#define vint vector<int>
#define sint set<int>
#define mint map<int,int>
#define pint pair< int,int >
#define int long long int 
#define test int tt1234; cin>>tt1234;while(tt1234--)
#define endl "\n"
#define SI(a,n) int a[n];FOR(i,n) cin>>a[i];
#define input(a,n) int n;cin>>n; SI(a,n)
#define all(zz) zz.begin(),zz.end()
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define error(x) cerr << #x <<" is " << x << endl;
#define Error(a,b) cerr<<"( "<<#a<<" , "<<#b<<" ) = ( "<<(a)<<" , "<<(b)<<" )\n";
#define precision(x) cout<<fixed<<setprecision(x);
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define present(container, element) (container.find(element)!=container.end())
#define fint fast;test
#define set(a,x) memset(a,x,sizeof(a))
#define L(x)	((x)<<1)
#define R(x)	(((x)<<1)+1)
#define ft first
#define se second
#define MOD 1000000007
using namespace std;
template<typename... T> void rd(T&... args) { ((cin >> args), ...); }
template<typename... T> void pp(T... args) { ((cout << args << " "), ...); cout<<"\n"; }
int power(int a,int b,int m)
{
	if(b==0)return 1;
	if(b&1) return ((a%m)*(power(a,b-1,m)%m))%m;
	return((power(a,b/2,m)%m)*(power(a,b/2,m)%m))%m;
}
void solve(){
	int n;
	rd(n);
	if(n<2)pp(0);
	else
	{
		int tot=power(10,n,MOD)%MOD;
		int noZ=power(8,n,MOD)%MOD;
		int x=power(9,n,MOD)%MOD;
		tot=(tot+noZ)%MOD;
		int rem=(2*x)%MOD;
		pp((tot-rem+MOD)%MOD);
		return ;

	}	
	return;	
}


int32_t main() {
    // fint{
    	fast;
    	solve();
    // }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define pii pair<int,int>
using namespace std;
map<pii, int>Map;
int n, res;
pii w[60];
int main() {
	int i, j, k;
	scanf("%d", &n);
	res = n;
	for (i = 1; i <= n; i++) {
		scanf("%d%d", &w[i].first, &w[i].second);
		Map[w[i]] = 1;
	}
	for (i = 1; i <= n; i++) {
		for (j = 1; j <= n; j++) {
			if (i == j)continue;
			int x = w[j].first - w[i].first, y = w[j].second - w[i].second;
			int c = 0;
			for (k = 1; k <= n; k++) {
				if (Map.count({ w[k].first + x,w[k].second + y }))c++;
			}
			res = min(res, n - c);
		}
	}
	printf("%d\n", res);
	return 0;
}

Measured memory_bytes: 384
<?php

fscanf(STDIN, "%d %d %d", $a, $b, $q);

$S = [PHP_INT_MIN];
for ($i = 0; $i < $a; ++$i) {
    $S[] = intval(trim(fgets(STDIN)));
}
$S[] = PHP_INT_MAX;

$T = [PHP_INT_MIN];
for ($i = 0; $i < $b; ++$i) {
    $T[] = intval(trim(fgets(STDIN)));
}
$T[] = PHP_INT_MAX;

$X = [];
for ($i = 0; $i < $q; ++$i) {
    $X[] = intval(trim(fgets(STDIN)));
}

for ($i = 0; $i < $q; ++$i) {
    $x = $X[$i];

    $l = 0;
    $r = count($S);
    while ($r - $l >= 1) {
        $mid = intdiv($r + $l, 2);
        if ($S[$mid] > $x) {
            $r = $mid;
        } else {
            $l = $mid + 1;
        }
    }
    $sx = $r;

    $l = 0;
    $r = count($T);
    while ($r - $l >= 1) {
        $mid = intdiv($r + $l, 2);
        if ($T[$mid] > $x) {
            $r = $mid;
        } else {
            $l = $mid + 1;
        }
    }
    $tx = $r;

    $min = PHP_INT_MAX;
    foreach ([$S[$sx], $S[$sx - 1]] as $s) {
        foreach ([$T[$tx], $T[$tx - 1]] as $t) {
            $d1 = abs($x - $s) + abs($s - $t);
            $d2 = abs($x - $t) + abs($s - $t);

            $min = min($min, $d1, $d2);
        }
    }

    echo $min, PHP_EOL;
}



Measured memory_bytes: 18928
#include<stdio.h>
#include <assert.h>
#include <stdio.h>
#include <string.h>

/*
	入力例：
	3
	1 1 3
*/

int main(){
	int i,j;
	long lN;
	long aryNum[100005]={0};
	scanf("%ld", &lN);

	long lA[lN];
	for(long i=0;i<lN;i++){
	 scanf("%ld", &lA[i]);
	}

	long lQ;
	scanf("%ld", &lQ);
	long lBC[lQ][2];
	for(long i=0;i<lQ;i++){
		for(int j=0;j<2;j++){
			scanf("%ld", &(lBC[i][j]));
		}
	}
	long strRet=0;
 	for(long i=0;i<lN;i++){
		aryNum[lA[i]]+=1;
		strRet+=lA[i];
	}
	for(long i=0;i<lQ;i++){
		strRet+=lBC[i][1]*aryNum[lBC[i][0]];
		strRet-=lBC[i][0]*aryNum[lBC[i][0]];
		aryNum[lBC[i][1]]+=aryNum[lBC[i][0]];
		aryNum[lBC[i][0]]=0;
		printf("%ld\n",strRet);
	}
 return 0;
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef pair<ll, int> PILL;
typedef pair<ll, ll> PLL;

const int MAX_N = 2e5+5;
const int M = 1e6;
const ll INF = (ll)(1e18);
const int inf = 1e9;
const ll MOD = 1000000007LL;

void solve() {

}

bool is(int x) {
    int i = 2;
    while (i*i <= x) {
        if (x%i == 0) return false;
        i++;
    }
    return true;
}

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


    int x;
    cin >> x;
    while (true) {
        if (is(x)) {
            cout << x;
            return 0;
        }
        x++;
    }







    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vint;
typedef vector<double> vd;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<vector<int>> vvint;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef priority_queue<int, vector<int>, greater<int>> spqint; //小さい順に取り出し
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;     //小さい順に取り出し
typedef priority_queue<int, vector<int>, less<int>> bpqint;    //大きい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;        //大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define FOR(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); i++)
#define FI first
#define SE second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define PF push_front
#define TS to_string
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define NP next_permutation
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) (ll) x.size()
#define SP(x) setprecision((ll)x)


int INF = 1e9;
int NIL = -1;
ll MOD = 1000000007;
ll LINF = 1e18;
double EPS = 1e-9;
double PI = M_PI;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; } //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}
//-----------------------------------------

//-----------------------------------------
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::chrono::system_clock::time_point start,end;
    start = std::chrono::system_clock::now();
    ll a, b ;
    cin >> a >> b ;
  if(a!=0){
    a-- ;
  }
    vll vec ;
    ll k = 1 ;
    REP(i,50){
        vec.PB(k) ;
        k *= 2 ;
    }
    ll ans = 0 ;
    REP(i,49){
        ll tmpa = ( a/vec[i+1]*vec[i] + max( (ll)0, ((vec[i+1]+a)%vec[i+1] - (vec[i]-1)) ) ) ;
        ll tmpb = ( b/vec[i+1]*vec[i] + max( (ll)0, ((vec[i+1]+b)%vec[i+1] - (vec[i]-1)) ) ) ;
        ans += ( (tmpb-tmpa) %2 )*vec[i] ;
    }
    cout << ans <<endl;



    end = std::chrono::system_clock::now();
    auto elapsed = std::chrono::duration_cast< std::chrono::milliseconds >(end - start).count();
    //std::cout << elapsed <<"ms"<< std::endl;

    

    return 0;
}

Measured memory_bytes: 3628
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<long, long> PLL;
typedef long long LL;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define INF 10000000

int cnt[31];
int main(){
	string str;
	cin>>str;
	string abc="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
	REP(i,SZ(str)){
		int cnt=(unsigned int)(str[i]-'A');
		cnt=(cnt+23)%26;
		str[i]=abc[cnt];
	}
	cout<<str<<endl;
	return 0;
}

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

int main(){
    int n;
    cin >> n;

    vector<bool> is_prime_list(55556, true);
    is_prime_list[0] = false; 
    is_prime_list[1] = false;

    vector<int> primes;
    for(int i=2; i<=55555; i++) {
        if(is_prime_list[i] == true){
            for(int j=i*2; j<=55555; j+=i){
                is_prime_list[j] = false;// exclude multipliers of i (prime)
            }
            if(i % 5 == 1) primes.push_back(i);
        }// if not prime, do nothing -> proceed to i+1
    }

    for(int i=0; i<n; i++){
        cout << primes[i] << " ";
    }
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>
#include <tuple>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> pii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (auto &i : a) cin >> i;
  int res = 0;
  vector<int> dp(n, 0);
  for (int i = n - 2; i >= 0; --i) {
    if (a[i] >= a[i + 1]) {
      dp[i] = 1 + dp[i + 1];
    }
    res = max(res, dp[i]);
  }
  cout << res << '\n';
  return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <fstream>
#include <list>
#include <string>
using namespace std;

int main()
{
	ifstream fin("input.txt");
	long long n, x = 0, y = 0;
	cin >> n;
	x = n * 800;
	y = 200 * (n / 15);
	cout << x - y << endl;
}

Measured memory_bytes: 256