akhauriyash/Code-Regression huggingface dataset:
/* ~ Programmer >> Tushar Mahajan */
#include <iostream>
#include <bits/stdc++.h> 
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL); 

int main() {
	ios;
	int n,l;
	cin>>n>>l;
	string s[n];
	for(int i=0;i<n;i++)
	{
	    cin>>s[i];
	}
	sort(s,s+n);
	for(int i=0;i<n;i++)
	{
	    cout<<s[i];
	}
	return 0;
}


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

int main(){
  int64_t A,B,C,K,ans=0;
  cin>>A>>B>>C>>K;
  if(A>K){
    cout<<K<<endl;
    return 0;
  }
  else{
    ans+=A;
    K-=A;
  }
  if(B>K){
    cout<<ans<<endl;
    return 0;
  }
  else{
    K-=B;
  }
  if(C>=K){
    ans-=K;
    cout<<ans<<endl;
  }
  
}


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

int main(){
  int N,M;  cin >> N >> M;
  vector<int>A(M);
  for(int i=0;i<M;i++){
    cin >> A.at(i);
  }
  sort(A.begin(),A.end());
  vector<long long>dp(N+1,0);
  dp.at(0) = 1;
  int temp = 0;
  for(int i=1;i<=N;i++){
    if(M > 0 && i == A.at(temp)){
      if(temp < M-1) temp++;
      else  temp = 0;
      continue;
    }
    dp.at(i) += dp.at(i-1)%1000000007;
    if(i>1)  dp.at(i) += dp.at(i-2)%1000000007;
  }
  cout << dp.at(N)%1000000007 << endl;
}


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


using namespace std;

int main() {

    
    string str;
    cin >> str;
    int ans = 0;
    for (int i = 0; i < str.size()/2; i++){
        if (str[i] != str[str.size()-1-i]) ans++;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 384
local n=io.read("n","l")
local s={}
for i=1,n do
    local input=io.read()
    s[input]=(s[input] or 0)+1
end

print("AC x "..(s["AC"] or 0))
print("WA x "..(s["WA"] or 0))
print("TLE x "..(s["TLE"] or 0))
print("RE x "..(s["RE"] or 0))

Measured memory_bytes: 2792
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define fs first
#define se second
#define pi 2*acos(0)
#define PI 3.14159265358979323846264338

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

const int N = 100010;
const int MX = 123456;
const int mod = (int)1e9 + 7;
const int base = 1023456789;
const ull BS1 = 10000019ULL;
const int INF = (1 << 29);

template < class T > inline void fastScan(T &x){
    register char c = getchar();
    int neg = 0; x = 0;
    for(   ; (c < 48 || c > 57) && (c != '-'); c = getchar());
    if(c == '-') { neg = 1; c = getchar(); }
    for(   ; c > 47 && c < 58; c = getchar()){
        x = (x << 1) + (x << 3) + c - 48;
    }
    if(neg) x = -x;
}

// OrderedSet
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template < typename T > using ordered_set = tree < T, null_type, greater < T >, rb_tree_tag, tree_order_statistics_node_update >;

int n, Q;

char s[N + N];
char t[N + N][2];
char d[N + N][2];

bool isLeftOk(int pos){
  for(int i = 0; i < Q; i++){
    if(s[pos] == t[i][0]){
      if(d[i][0] == 'L'){
        pos--;
      } else {
        pos++;
      }
      if(pos < 0){
        return 0;
      } else if(pos >= n){
        return 2;
      }
    }
  }
  if(pos < 0){
    return 0;
  } else if(pos >= n){
    return 2;
  }
  return 1;
}

bool isRightOk(int pos){
  for(int i = 0; i < Q; i++){
    if(s[pos] == t[i][0]){
      if(d[i][0] == 'L'){
        pos--;
      } else {
        pos++;
      }
      if(pos >= n){
        return 0;
      } else if(pos < 0){
        return 2;
      }
    }
  }
  if(pos >= n){
    return 0;
  } else if(pos < 0){
    return 2;
  }
  return 1;
}

int main(){
  fastScan(n);
  fastScan(Q);
  scanf("%s", s);
  for(int i = 0; i < Q; i++){
    scanf("%s %s", t[i], d[i]);
  }
  int low = 0, high = n - 1, lft = n;
  while(low <= high){
    int mid = (low + high) >> 1;
    if(isLeftOk(mid) == 0){
      low = mid + 1;
    } else {
      high = mid - 1;
      lft = mid;
    }
  }
  cerr << lft << '\n';
  low = 0; high = n - 1; int rgt = -1;
  while(low <= high){
    int mid = (low + high) >> 1;
    if(isRightOk(mid) == 0){
      high = mid - 1;
    } else {
      low = mid + 1;
      rgt = mid;
    }
  }
  cerr << rgt << '\n';
  int ans = (lft <= rgt) ? (rgt - lft + 1) : 0;
  printf("%d\n", ans);
}


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

#define F first
#define S second
#define PB push_back

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;
typedef priority_queue<int> HEAP;
typedef priority_queue<int, vector<int>, greater<int> > RHEAP;

const int N = 100010, M = 1010;

int n;
char s[N];

int main()
{
	scanf("%s", s + 1);
	n = strlen(s + 1);
	
	for (int i = 1; i <= n - 1; i ++ )
		if (s[i] == s[i + 1])
		{
			printf("%d %d\n", i, i + 1);
			return 0;
		}
	
	for (int i = 1; i <= n - 2; i ++ )
		if (s[i] == s[i + 2])
		{
			printf("%d %d\n", i, i + 2);
			return 0;
		}
	
	puts("-1 -1");
	return 0;
}

Measured memory_bytes: 384
from collections import Counter
n = int(input())
s = [input() for _ in range(n)]
cnt = 0
d = {}
for i in range(n):
  sortsi = ''.join(sorted(s[i]))
  if sortsi in d:
    cnt+=d[sortsi]
    d[sortsi]+=1
  else: 
    d[sortsi]=1
print(cnt)

Measured memory_bytes: 25328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0; i<n; ++i)
#define rep1(i,n) for(ll i=1; i<=n; ++i)
#define revrep(i,n) for(ll i=n-1; i>=0; --i)
inline constexpr ll Inf = (1ULL << 62) -1;
#define fastio cin.tie(nullptr); ios_base::sync_with_stdio(false);
#define endl '\n'
template <class T> bool updmax(T& a, T b) { if (b > a) { a = b; return true;} return false;}
template <class T> bool updmin(T& a, T b) { if (b < a) { a = b; return true;} return false;}

int main() {
    fastio;
    ll N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    ll sum = 0;
    int s = 1;
    rep(i,N) {
        sum += s*a[i];
        s *= -1;
    }
    rep(i,N) {
        cout << sum << " ";
        sum = a[i]-(sum - a[i]);
    }
    cout << endl;
}


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

int main(){
  int H,N;
  cin>>H>>N;
  for(int i=0;i<N;i++){
    int j;
    cin>>j;
    H-=j;
  }
  if(H>0)
    cout<<"No"<<endl;
  else
    cout<<"Yes"<<endl;
}

Measured memory_bytes: 256
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=5000+10,INF=0x3f3f3f3f;
int main()
{
    char s[55];
    char t[20]={"FESTIVAL"};
    while(~scanf("%s",s)){
        for(int i=0;i<strlen(s)-8;i++){
            printf("%c",s[i]);

        }
        printf("\n");
    }
    return 0;
}


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

using namespace std;

int main() {

	long a, b, c;
	cin >> a >> b >> c;

	cout << (a!=b && a!=c && b!=c ? 3 : a==b && b!=c || a==c && a!=b || a!=b && b==c? 2
		 : 1) << endl;
}

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

long long mod = 1000000007;

long long modpow(long long a, long long n){
  long long res = 1;
  while (n > 0){
    if (n & 1){
      res = res * a % mod;
    }
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

long long modinv(long long a){
  return  modpow(a, mod-2);
}

long long modgamma(long long n){
  if (n < 0){
    return 0;
  }
  long long res = 1;
  for (long long i=0; i<n; i++){
    res = res * (i+1) % mod;
  }
  return res;
}

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

  // 並び替えの問題
  // 青いボールのグループの個数がiになる並べ方がいくつあるのかを計算する。
  // まず青いボールを i個のグループに分ける場合の数が何通りかを計算する
  // これは K-1個の境界からi-1個を選ぶ組み合わせの問題なので K-1_C_i-1
  // 次に赤いボールが並んだところに青いグループをどのように挿入するかの組み合わせの数を計算する
  // これは N - K + 1個の境界（両端含む）からi個を選ぶ組み合わせの問題なので N-K+1_C_i

  for (long long i=1; i<=K; i++){
    long long ans = modgamma(K-1) * modinv(modgamma(i-1)) % mod;
    ans = ans * modinv(modgamma(K-i)) % mod;
    ans = ans * modgamma(N-K+1) % mod;
    ans = ans * modinv(modgamma(i)) % mod;
    ans = ans * modinv(modgamma(N-K+1-i)) % mod;
    cout << ans << endl;
  }
  return 0;
}


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

typedef double du ;
typedef string st ;
typedef long long ll ;
typedef long double ld ;
typedef long long int lli ;

#define vi vector <lli>
#define loop(num) for (lli i = 0 ; i < num ; i ++ )
#define loop2(num) for (lli j = 0 ; j < num ; j ++ )
#define loopcin(num , ar ) for (lli i = 0 ; i < num ; i ++ ) {cin >> ar [i] ;}
#define loopcout(num , ar) for (lli i = 0 ; i < num ; i ++ ) {cout << ar [i] << ' '; }
#define looppu(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . push_back (x) ;}
#define loopin(num , ar) for (lli i = 0 ; i < num ;  i++) {lli x ; cin >> x ; ar . insert (x) ;}

#define forr(num1 , num2) for (lli i = num1 ; i < num2 ; i ++ )
#define forrcin(num1 , num2 , ar ) for (lli i = num1 ; i < num2 ; i ++ ) {cin >> ar [i] ;}
#define forrcout(num1 , num2 , ar) for (lli i = num1 ; i < num2 ; i ++ ) {cout << ar [i] << ' '; }

#define D2forrcin(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cin >> A[i][j] ;}}
#define D2forrcout(num1_1 , num1_2 , num2_1 , num2_2 , A ) for (lli i = num1_1 ; i < num1_2 ; i ++){ for (lli j = num2_1 ; j < num2_2 ; j++){cout << A[i][j] << ' ' ;}cout << endl ;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define F first
#define S second
#define pb push_back
#define pf push_front
#define pob pop_back ()
#define pof pop_front ()

#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

ll pw (ll &x) {
    ll s  = 1 ;
    for (ll i = 0 ; i < x ; i++ ){
        s *= 10 ;
    }
    return s ;
}
signed main ()
{
    fastio
    st s ;
    cin >> s ;
    ll len = s . size () , len2 =  0;
    vector <st> m1 ;
    loop(len - 2) {
        st ss ;
        ss = s . substr (i , 3) ;
        m1 . pb (ss) ;
    }
    len2 = m1 . size() ;
    //loopcout(len2, m1) ;
    //cout << endl ;
    vi ar[len2] ;
    vi res (len2);
    loop(len2) {
        for(int j = 2 ; j >= 0 ; j --) {
            ll x = m1 [i][j] - '0' ;
            ar[i] . pb (x) ;
        }
    }
    loop(len2){
        loop2(3) {
            res[i] += ar [i][j] * pw(j) ;
        }
        res [i] = abs(753 - res[i]) ;
    }
    sort(res . begin() ,res .end()) ;
    cout << res[0] << endl ;

    //loopcout(m1 . size() , aar) ;
    //cout << endl;
    //D2forrcout(0 , m1 .size() , 0 , 3 , ar) ;

    return 0 ;
}

/*___________________________________________________________________functions___________________________________________________________________________*/



Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int cnt = 0;
    rep(i,n){
        if(s[i] == '(') cnt++;
        else cnt = max(0, cnt-1);
    }
    if(cnt > 0){
        rep(i,cnt) s += ')';
    }
    cnt = 0;
    for(int i = s.size()-1; i >= 0; i--){
        if(s[i] == ')') cnt++;
        else cnt = max(0, cnt-1);
    }
    if(cnt > 0){
        rep(i,cnt) cout << "(";
    }
    cout << s << endl;
	return 0;
}

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

using namespace std;

using P = pair<int, int>;

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

    int n;
    cin >> n;
    vector<vector<P>> g(n);
    for (int i = 0; i < n - 1; i++)
    {
        int u, v, w;
        cin >> u >> v >> w;
        w %= 2;
        u--;
        v--;
        g[u].push_back(P(v, w));
        g[v].push_back(P(u, w));
    }
    vector<int> d(n, 1e9);
    deque<int> que;
    que.push_back(0);
    d[0] = 0;
    while (!que.empty())
    {
        int cur = que.front();
        que.pop_front();
        for (auto p : g[cur])
        {
            int dst = p.first, w = p.second;
            if (d[dst] != 1e9)
                continue;
            if (w == 0)
            {
                d[dst] = d[cur];
                que.push_front(dst);
            }
            else
            {
                d[dst] = 1 - d[cur];
                que.push_back(dst);
            }
        }
    }
    for (int i = 0; i < n; i++)
    {
        cout << d[i] << endl;
    }
}


Measured memory_bytes: 6784
#include "bits/stdc++.h"
// Custom Header {{{
#define ALL(x) x.begin(), x.end()
using namespace std;
using i64 = long long;
using pii = pair<i64, i64>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
// }}}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N;
    int a[200010];
    int l[200010];
    int r[200010];

    cin >> N;
    for (int i = 1; i <= N; ++i) {
        cin >> a[i];
    }

    l[0] = 0;
    for (int i = 1; i <= N; ++i) {
        l[i] = max(l[i-1], a[i]);
    }
    r[N+1] = 0;
    for (int i = N; i >= 1; --i) {
        r[i] = max(r[i+1], a[i]);
    }

    for (int i = 1; i <= N; ++i) {
        cout << max(l[i-1], r[i+1]) << "\n";
    }

    return 0;
}

// vim: set foldmethod=marker :


Measured memory_bytes: 3968
#include <stdio.h>
#define N 100

int main(){
  int i, j, k, n, minj = 0, m, con = 0;
  int a[N];

  scanf("%d", &n);

  for(k = 0; k < n; k++){
    scanf("%d", &a[k]);
  }

  for(i = 0; i <= n-1; i++){
    minj = i;
    for(j = i; j <= n-1; j++){
      if(a[j] < a[minj]){
	minj = j;
      }
    }
    if(i != minj){
      m = a[i];
      a[i] = a[minj];
      a[minj] = m;
      con++;
    }
  }

  printf("%d", a[0]);
  for(k = 1; k < n; k++){
    printf(" %d", a[k]);
  }
  printf("\n%d\n", con);

  return 0;
}



Measured memory_bytes: 2104
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
#include <utility>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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;}

int main() {
  string s;
  cin >> s;
  vector<ll> v;
  rep (i, s.size() - 1) {
    if (s[i] == 'R' && s[i + 1] == 'L') v.push_back(i);
  }

  ll index = 0;
  vector<ll> ans(s.size());
  int eru = 0;
  rep (i, s.size()) {
    if (eru == 1 && s[i] == 'R') {
      index++;
      eru = 0;
    }

    if (eru == 0 && s[i] == 'R') {
      if ((v[index] - i) % 2 == 0) ans[v[index]]++;
      else ans[v[index] + 1]++;
    } else {
      if ((v[index] + 1 - i) % 2 == 0) ans[v[index] + 1]++;
      else ans[v[index]]++;
      eru = 1;
    }
  }


  rep (i, s.size()) {
    cout << ans[i] << " ";
  }
  cout << endl;



  return 0;
}



Measured memory_bytes: 1912
import math
import sys

sys.setrecursionlimit(10000)
INF = float('inf')


def inv(x):
    return pow(x, MOD - 2, MOD)


def comb(n, r, mod):
    # https://fushime2.hatenablog.com/entry/2016/11/12/155543
    return (math.factorial(n) * inv(math.factorial(n - r)) * inv(math.factorial(r))) % mod


N, M, K = list(map(int, input().split()))


def pyramid(n):
    return n * (n + 1) * (n + 2) // 6


MOD = 10 ** 9 + 7

# K ==2 の場合
# print(pyramid(N - 1) * M ** 2 + pyramid(M - 1) * N ** 2)
k2 = (pyramid(N - 1) * M ** 2 + pyramid(M - 1) * N ** 2) % MOD
# k2 を何回使うか
c = comb(N * M - 2, K - 2, mod=MOD)
print(k2 * c % MOD)


Measured memory_bytes: 5892
# https://qiita.com/LorseKudos/items/9eb560494862c8b4eb56
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return len(divisors)

N = int(input())
ans = 0
for i in range(1, N + 1) :
    if i % 2 == 1 and make_divisors(i) == 8 :
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

using namespace std;
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define FOR(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define RREP(i, a) for(int (i) = (a) - 1; (i) >= 0; (i)--)
#define FORR(i, a, b) for(int (i) = (a) - 1; (i) >= (b); (i)--)
#define DEBUG(C) cerr << #C << " = " << C << endl;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<LL>;
using VVL = vector<VL>;
using VD = vector<double>;
using VVD = vector<VD>;
using PII = pair<int, int>;
using PDD = pair<double, double>;
using PLL = pair<LL, LL>;
using VPII = vector<PII>;
#define ALL(a) begin((a)), end((a))
#define RALL(a) rbegin((a)), rend((a))
#define SORT(a) sort(ALL((a)))
#define RSORT(a) sort(RALL((a)))
#define REVERSE(a) reverse(ALL((a)))
#define MP make_pair
#define FORE(a, b) for (auto &&a : (b))
#define FIND(s, e) ((s).find(e) != (s).end())
#define EB emplace_back

const int INF = 1e9;
const int MOD = INF + 7;
const LL LLINF = 1e18;

void solve(int N) {
    int cnt = 0;
    bool now = false;
    bool l = now, r = now;
    while (N--) {
        string S;
        cin >> S;
        if (S == "lu") {
            l = true;
        } else if (S == "ru") {
            r = true;
        } else if (S == "ld") {
            l = false;
        } else {
            r = false;
        }
        if (l == r && l != now) {
            cnt++; now = l;
        }
    }
    cout << cnt << endl;
}

signed main(void) {
    int n, m, p, a, b, c, x, y, z, q;
    string s;
    while (cin >> n, n) {
        solve(n);
    }
}

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

#define     bip(a)         __builtin_popcount(a)
#define     ull            unsigned long long
#define     ll             long long
#define     u              unsigned
#define     pb             push_back
#define     pf             push_front ///for list
#define     mp             make_pair
#define     is             insert
#define     ff             first
#define     ss             second
#define     vi             vector<int>
#define     vl             vector<ll>
#define     si             set<int>
#define     sl             set<ll>
#define     li             list<int>
#define     pii            pair<int,int>
#define     pll            pair<ll,ll>
#define     mii            map<int,int>
#define     mll            map<ll,ll>
#define     ma             INT_MAX
#define     mi             INT_MIN
#define     mod            1000000007
#define     pi             3.14159265359
#define     e              2.71828182846
#define     inf            1000000000000000LL
#define     all(x)         x.begin(), x.end()
#define     lb(a,b,c)      lower_bound(a,a+b,c)-a
#define     ub(a,b,c)      upper_bound(a,a+b,c)-a
#define     lbv(a,c)       lower_bound(all(a),c)-a.begin()
#define     ubv(a,c)       upper_bound(all(a),c)-a.begin()
#define     srt1(a,b)      sort(a,a+b)
#define     srt2(a,b)      sort(a,a+b,greater<int>())
#define     gcd(a,b)       __gcd(a,b)
#define     lcm(a,b)       (a*(b/gcd(a,b)))
#define     harmonic(n)    0.57721566490153286l+log(n)
#define     mem(a, b)      memset(a, b, sizeof(a))

///s.lower_bound(a),s.upper_bound(a), for set
///nCr(x, y) = nCr(x-1, y-1) + nCr(x-1, y)
///factorial digit   ((n * log10(n / e) +log10(2 * pi * n) /2.0));


int main()
{
    int a,b;
    cin>>a>>b;
    cout<<a*b<<endl;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
vector<int> edges[100005];
vector<int> parent(100005);
void BFS(int s,int V) 
{ 
    bool *visited = new bool[V+1];
    for(int i = 1; i <= V; i++) 
        visited[i] = false; 
  
    list<int> queue; 
  
    visited[s] = true; 
    queue.push_back(s); 
  
  
    while(!queue.empty()) 
    { 
        s = queue.front(); 
        queue.pop_front(); 

        for (auto i = edges[s].begin(); i != edges[s].end(); ++i) 
        { 
            if (!visited[*i]) {
                parent[*i] = s;
                visited[*i] = true; 
                queue.push_back(*i); 
            } 
        } 
    } 
} 
int main(int argc, const char** argv) {
    int n,m,a,b,i,j;
    cin>>n>>m;
    for(i=0;i<m;++i){
        cin>>a>>b;
        edges[a].push_back(b);
        edges[b].push_back(a);
    }
    BFS(1,n);
    for(i=2;i<=n;++i){
        if(parent[i] == 0){
            cout<<"No\n";
            return 0;
        }

    }
    cout<<"Yes\n";
    for(i=2;i<=n;++i)
        cout<<parent[i]<<"\n";
    
    return 0;
}

Measured memory_bytes: 12780
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main()
{
    int num;
    scanf("%d",&num);
    vector<int> out;
    vector<pair<int,int> >  v;
    for(int i=0;i<num;i++){
        int current;
        scanf("%d",&current);
        v.push_back(make_pair(current,i));
    }
    sort(v.begin(),v.end());
    for(int i=0;i<num;i++){
        if(v[num-1].second!=i){
            printf("%d\n",v[num-1].first);
        }else{
            printf("%d\n",v[num-2].first);
        }
    }
    return 0;
}

Measured memory_bytes: 3312
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

const int MAX_N = 100;

string s;

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

    cin >> s;

    bool ans = false;
    for (int i = 0; i < s.size();) {
        string substr = s.substr(i, 5);
        if (substr == "dream") {
            if (s[i + 5] == 'e' && s[i + 6] == 'r' && s[i + 7] != 'a') {
                i += 7;
            } else {
                i += 5;
            }
        } else if (substr == "erase") {
            if (s[i + 5] == 'r') {
                i += 6;
            } else {
                i += 5;
            }
        } else {
            ans = true;
            break;
        }
    }

    if (ans) {
        cout << "NO\n";
    } else {
        cout << "YES\n";
    }

    return 0;
}

Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mod = 1e9 + 7;
const int inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

#include <vector>

struct UnionFind
{
    vector<int> data;

    UnionFind(int sz) : data(sz, -1) {}

    bool unite(int x, int y)
    {
        x = root(x), y = root(y);
        if (x == y)
            return false;
        if (data[x] > data[y])
            swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return true;
    }

    int root(int k)
    {
        if (data[k] < 0)
            return k;
        data[k] = root(data[k]);
        return data[k];
    }

    int size(int k)
    {
        return (-data[root(k)]);
    }

    bool same(int x, int y)
    {
        return (root(x) == root(y));
    }
};

int main()
{
    int N, Q;
    scanf("%d %d", &N, &Q);
    UnionFind uf(N);
    while (Q--)
    {
        int t, x, y;
        scanf("%d %d %d", &t, &x, &y);
        if (t == 0)
            uf.unite(x, y);
        else
            printf("%d\n", uf.root(x) == uf.root(y));
    }
}


Measured memory_bytes: 3252
def win
  n=Hash.new{0}
  S.each{|c|n[c]+=1}
  if S[0]!=S[-1]
    d=(n[S[0]]-n[S[-1]]).abs
    x=S.size-n[S[0]]-n[S[-1]]+d
    return x.odd?
  end
  S.size.even?
end
S=gets.chop.chars
puts win ? :First : :Second


Measured memory_bytes: 8956
import java.util.*


fun main(args: Array<String>) {
    val (x, n) = getInts()
    val s = TreeSet<Int>().also {
        it.addAll((-1..101))
    }
    if (n != 0) {
        s.removeAll(getInts())
    }

    println(
    s.map { Math.abs(it - x) to it }
            .minBy { it.first }
            ?.second
    )
}


fun getInt() = readLine()!!.toInt()
fun getInts() = readLine()!!.split(" ").map { it.toInt() }

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

bool cmp (pair<int, int> a, pair<int, int> b) {

    return a.second < b.second;
}

int main () {

    int N, M;
    scanf("%d %d", &N, &M);

    vector<pair<int, int>> island(M);
    for (int i = 0; i < M; i++) {
        int a, b;
        scanf("%d %d", &a, &b);

        island[i] = make_pair(a, b);
    }

    sort(island.begin(), island.end(), cmp);

    int bridge = island[0].second;
    int ans = 1;

    for (int i = 1; i < M; i++) {
        if (island[i].first >= bridge) {
            ans++;
            bridge = island[i].second;
        }
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1024
import math

S = input()

ans = 0
for i in range(2**(len(S)-1)):
    j = 0
    k = 1
    for c in format(i, '0' + str(len(S)-1) + 'b'):
        if c == '1':
            ans += int(S[j:k])
            j = k
        k += 1
    ans += int(S[j:k])

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
#include <string>
using namespace std;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int R;
    cin >> R;
    if (R < 1200) {
        cout << "ABC" << endl;
    } else if (R < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>

using namespace std;

struct Node {
    int key;
    int left;
    int right;
};

int n;
char command[7];

Node tree[500000];
int tree_num;
int root = -1;

inline int create_node(int key) {
    Node& node = tree[tree_num];
    node.key = key;
    node.left = -1;
    node.right = -1;
    return tree_num++;
}

inline void insert(int key) {

    if (root == -1) {
        root = create_node(key);
        return;
    }

    int node = root, parent = 0;
    while (node != -1) {
        parent = node;
        if (key < tree[node].key) {
            node = tree[node].left;
        }
        else {
            node = tree[node].right;
        }
    }

    int newnode = create_node(key);
    if (key < tree[parent].key) {
        tree[parent].left = newnode;
    }
    else {
        tree[parent].right = newnode;
    }
}

void pre_order(int root) {
    Node& node = tree[root];
    printf(" %d", node.key);
    if (node.left != -1) {
        pre_order(node.left);
    }
    if (node.right != -1) {
        pre_order(node.right);
    }
}

void in_order(int root) {
    Node& node = tree[root];
    if (node.left != -1) {
        in_order(node.left);
    }
    printf(" %d", node.key);
    if (node.right != -1) {
        in_order(node.right);
    }
}

int main(void) {

    scanf("%d", &n);

    for (int i = 0, key; i < n; ++i) {
        scanf("%s", command);
        if (command[0] == 'i') {
            scanf("%d", &key);
            insert(key);
        }
        else {  // print 
            if (root == -1) { continue; }
            in_order(0);
            printf("\n");
            pre_order(0);
            printf("\n");
        }
    }

    return 0;
}

Measured memory_bytes: 7056
#include <bits/stdc++.h>
#define re return
#define ull unsigned long long
#define ll long long
#define ld long double
#define f first
#define s second
#define oo 1e9
#define pi acos(-1)
#define OO 4e18
#define EPS 1e-12
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define Hossam_Yehia ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
int n,m,r,arr[10];
int dis[210][210];
int x,y,c,ans,Min(INT_MAX);
int main(){
    Hossam_Yehia;
    cin >> n >> m >> r;
    for(int i=0;i<r;++i)
        cin >> arr[i];
    sort(arr,arr+r);
    for(int i=0;i<=205;++i){
        for(int j=0;j<=205;++j)
            dis[i][j]=oo;
        dis[i][i]=0;
    }
    while(m--){
        cin >> x >> y >> c;
        dis[x][y]=dis[y][x]=c;
    }
    for(int k = 1; k <= n; ++k) {
        for (int i = 1; i <= n; ++i) {
            for (int j = 1; j <= n; ++j) {
                if(dis[i][k] + dis[k][j]<dis[i][j])
                    dis[i][j] = dis[i][k] + dis[k][j];
            }
        }
    }
    do{
        ans=0;
        for(int i=1;i<r;++i)
            ans+=dis[arr[i]][arr[i-1]];
        Min=min(Min,ans);
    }while(next_permutation(arr,arr+r));
    cout<<Min<<endl;
    re 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, K;
  cin>>N>>K;
  int barr[K+1][K+1], warr[K+1][K+1];
  for(int i=0;i<=K;++i) {
    for(int j=0;j<=K;++j) {
      barr[i][j] = 0;
      warr[i][j] = 0;
    }
  }
  int x, y;
  char c;
  for(int i=0;i<N;++i) {
    cin>>x>>y>>c;
    if((x/K+y/K)%2==1) {
      if(c=='B') c = 'W';
      else c = 'B';
    }
    x %= K;
    y %= K;
    x++;
    y++;
    if(c=='B') {
      barr[x][y]++;
    }
    else {
      warr[x][y]++;
    }
  }
  for(int i=1;i<=K;++i) {
    for(int j=1;j<=K;++j) {
      barr[i][j] = barr[i-1][j]+barr[i][j-1]+barr[i][j]-barr[i-1][j-1];
      warr[i][j] = warr[i-1][j]+warr[i][j-1]+warr[i][j]-warr[i-1][j-1];
    }
  }
  int ans = 0;
  int tmp;
  for(int i=0;i<=K;++i) {
    for(int j=0;j<=K;++j) {
      tmp = barr[i][j]+(barr[K][K]-barr[i][K]-barr[K][j]+barr[i][j])+warr[i][K]-warr[i][j]+warr[K][j]-warr[i][j];
      ans = max(ans, tmp);
      tmp = warr[i][j]+(warr[K][K]-warr[i][K]-warr[K][j]+warr[i][j])+barr[i][K]-barr[i][j]+barr[K][j]-barr[i][j];
      ans = max(ans, tmp);
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 11400
/*
██╗  ██╗ █████╗ ██████╗ ███████╗███████╗███╗   ███╗        ██╗  ██╗██╗  ██╗ █████╗ ██╗     ███████╗██████╗
██║ ██╔╝██╔══██╗██╔══██╗██╔════╝██╔════╝████╗ ████║        ██║ ██╔╝██║  ██║██╔══██╗██║     ██╔════╝██╔══██╗
█████╔╝ ███████║██████╔╝█████╗  █████╗  ██╔████╔██║        █████╔╝ ███████║███████║██║     █████╗  ██║  ██║
██╔═██╗ ██╔══██║██╔══██╗██╔══╝  ██╔══╝  ██║╚██╔╝██║        ██╔═██╗ ██╔══██║██╔══██║██║     ██╔══╝  ██║  ██║
██║  ██╗██║  ██║██║  ██║███████╗███████╗██║ ╚═╝ ██║███████╗██║  ██╗██║  ██║██║  ██║███████╗███████╗██████╔╝
╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═╝     ╚═╝╚══════╝╚═╝  ╚═╝╚═╝  ╚═╝╚═╝  ╚═╝╚══════╝╚══════╝╚═════╝
				Believe in yourself ,( try and try and then try ), You can do it  
*/
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include<unordered_map>
#define endl "\n"
#define Ceil(x,y) ((x+y-1)/y)
#define clr(arr, x) memset(arr, x, sizeof arr)
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define rt(s) return cout<<s,0
#define watch(x) cout<<(#x)<<" = "<<x<<endl
#define sz(s)	(int)(s.size())
#define OO 0x3f3f3f3f3f3f3f3fLL
const int oo = 0x3f3f3f3f, mod = 1e9 + 7;
using namespace std;
typedef long long ll;
int dx[] { 1, -1, 0, 0, 1, 1, -1, -1 };
int dy[] { 0, 0, 1, -1, 1, -1, 1, -1 };
void K_K(){ 
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main(){
	K_K();
	int n;
	cin >> n;
	unordered_map<ll, int>mp;
	ll ans = 0;
	for (int i = 1; i <= n; i++){
		int x;
		cin >> x;
		ans += mp[i - x];
		mp[i + x]++;
	}
	cout << ans;
}

Measured memory_bytes: 18536
#根付き木テンプレ(ABC138-D)
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
ABW = [list(map(int,readline().split())) for i in range(N-1)]

graph = [[] for _ in range(N+1)] #隣接リスト(重み付き)
for a,b,w in ABW:
    graph[a].append((b,w%2)) #重みは偶奇さえわかれば良い
    graph[b].append((a,w%2))

#親のノードに子を入れてくdfs
stack = [1]
parent = [0]*(N+1)
order = []
while stack:
    x = stack.pop()
    order.append(x)
    for i,j in graph[x]: #jは重みなのでとりあえず使わん
        if i == parent[x]:
            continue
        parent[i] = x
        stack.append(i)

#色のリストを作り、order順に入れてく
#この時、親方向に逆流しないように注意。
color = [-1]*(N+1)
color[1] = 0
for x in order: #親
    c = 0 if color[x] == -1 or color[x] == 0 else 1
    for y,w in graph[x]: #子
        if y == parent[x]: #逆流防止弁
            continue
        if w == 0:
            color[y] = c
        else:
            color[y] = 1 - c

#output
for i in color[1:]:
    print(i)

Measured memory_bytes: 84316
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 200005
#define M 200005
#define seed 23333

using namespace std;
typedef long long LL;
const LL INF=1e18;
int K,i,j,m,n,p,k,B[N],C[N],L[N],R[N];
LL A[N],Min[N*4],Add[N*4];
void build_tree(int l,int r,int t)
{
		if (l==r) Min[t]=-C[l];
		else 
		{
				build_tree(l,mid,ls); build_tree(mid+1,r,rs);
				Min[t]=min(Min[ls],Min[rs]);
		}
}
void down(int t)
{
		if (Add[t]==-1) return;
		Add[ls]=Add[rs]=Min[ls]=Min[rs]=INF;
		Add[t]=-1;
}
long long FindMin(int ll,int rr,int l,int r,int t)
{
		if (ll>rr) return INF;
		else if (ll<=l&&r<=rr) return Min[t];
		else 
		{
					down(t);
					long long S=INF;
					if (ll<=mid) S=min(S,FindMin(ll,rr,l,mid,ls));
					if (rr>mid)  S=min(S,FindMin(ll,rr,mid+1,r,rs));
					return S; 
		}
}
void update(int ll,long long c,int l,int r,int t)
{
		if (l==r) Min[t]=min(Min[t],c-C[l]);
		else 
		{
				down(t);
				if (ll<=mid) update(ll,c,l,mid,ls);
				else update(ll,c,mid+1,r,rs);
				Min[t]=min(Min[ls],Min[rs]);
		}
}
long long DFS(int l,int r,int t)
{
		if (l==r) return Min[t]+C[l];
		else 
		return down(t),min(DFS(l,mid,ls),DFS(mid+1,r,rs));
}
void del(int ll,int rr,int l,int r,int t)
{
		if (ll>rr) return;
		if (ll<=l&&r<=rr) Add[t]=Min[t]=INF;
		else
		{
				down(t);
				if (ll<=mid) del(ll,rr,l,mid,ls);
				if (rr>mid)  del(ll,rr,mid+1,r,rs);
				Min[t]=min(Min[ls],Min[rs]); 
		}	
}
int main()
{
		scanf("%d%d",&n,&K);
		memset(Add,-1,sizeof(Add));
		for (i=1;i<=n;++i)
		{
				scanf("%lld%d",&A[i],&B[i]);
				if (B[i]==1&&2*A[i]>K)
				{
						puts("-1");
						return 0;
				}
				A[i]+=A[i-1];
				if (B[i]==2) continue;
				L[i]=(-2*A[i-1])%K; if (L[i]<0) L[i]+=K;
				R[i]=(-2*A[i])%K; if (R[i]<0) R[i]+=K;
				C[++C[0]]=L[i]; C[++C[0]]=R[i];  
		}
		sort(C+1,C+C[0]+1); C[0]=unique(C+1,C+C[0]+1)-(C+1);
		build_tree(1,C[0],1);
		for (i=1;i<=n;++i)
		{
				if (B[i]==2) continue; 
				int l=lower_bound(C+1,C+C[0]+1,L[i])-C,r=lower_bound(C+1,C+C[0]+1,R[i])-C;
				if (l>r)
				{
						update(l,FindMin(r+1,l-1,1,C[0],1)+C[l],1,C[0],1);
						del(r+1,l-1,1,C[0],1);
				}
				else 
				{
						update(l,FindMin(r+1,C[0],1,C[0],1)+C[l]+K,1,C[0],1);
						update(l,FindMin(1,l-1,1,C[0],1)+C[l],1,C[0],1);
						del(r+1,C[0],1,C[0],1);
						del(1,l-1,1,C[0],1);
				}
		}
		printf("%lld\n",2*A[n]+DFS(1,C[0],1)); 
}


Measured memory_bytes: 15104
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from fractions import gcd
from math import factorial, sqrt
from functools import lru_cache, reduce
INF = 1 << 60
mod = 1000000007
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline

# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# ここから書き始める
a, b = map(int, input().split())
if a <= 0 <= b:
    print("Zero")
elif a > 0:
    print("Positive")
else:
    if (b - a + 1) % 2 == 0:
        print("Positive")
    else:
        print("Negative")


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

int main() {
	long long int a,b,c,k,m,n,p,sum=0;
	cin>>a;
	cin>>b;
	cin>>c;
	cin>>k;
	
if(k>0 && a>k)
{
    m=k;
    sum=sum+(m*1);
    k=k-m;
}
if(k>0 && a<=k)
{
    m=a;
    sum=sum+(m*1);
    k=k-m;
}
if(k>0 && b>k)
{
    n=k;
    sum=sum+(n*0);
    k=k-n;
}
if(k>0 && b<=k)
{
    n=b;;
    sum=sum+(n*0);
    k=k-n;
}
	if(k>0 && c>k)
{
    p=k;
    sum=sum+(p*-1);
    k=k-p;
}
if(k>0 && c<=k)
{
    p=c;
    sum=sum+(p*-1);
    k=k-p;
}
cout<<sum<<"\n";
}

Measured memory_bytes: 3596
import sys
from collections import Counter

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 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

N = INT()
A = LIST()

C = Counter(A)
cur = sum(A)
Q = INT()
for _ in range(Q):
    b, c = MAP()
    cur -= b * C[b]
    cur += c * C[b]
    print(cur)
    C[c] += C[b]
    C[b] = 0


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

lli a,b,c;
lli k;
lli ans = LONG_MAX;

lli solve(lli x){
  if(x < 0){
    x *= -1;
    if(x%2 == 0) return x/2;
    else return x/2+2;
  }else{
    return x;
  }
}

int main(){
  cin >> a >> b >> c;
  for(lli k = 0;k <= 50;k++){
    lli a_ = a-k;
    lli b_ = b-k;
    lli c_ = c-k;
    ans = min(ans,solve(a_)+solve(b_)+solve(c_));
  }
  cout << ans << endl;
  return 0;

}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define BUFMAX 1001

char* w[2]={"Hoshino","Hoshina"};

int main(void){
	char buf[BUFMAX]; int i=0, j, n;
	
	scanf("%d%*c",&n);
	
	for(;n--;){
		i=0;
		while((buf[i]=getchar())!='\n') i++;
	
		i=0;
		while(1){
			/* \n */
			if(buf[i]=='\n'){
				printf("\n");
				break;
			}
			
			/* w[0]->w[1] */
			for(j=0; j<strlen(w[0]); j++)
				if(buf[i+j]!=w[0][j]) break;
					
			if(j==strlen(w[0])){
				printf("%s",w[1]);
				i+=strlen(w[0]);
				continue;
			}
						
			/* otherwise */
			printf("%c",buf[i]);
			i++;
		}
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int main(){
  int a,b,c;
  int box;
  scanf("%d %d %d",&a,&b,&c);
  while(a > b || b > c){
    if(a > b){
      box = a;
      a = b;
      b = box;
    }
    if(b > c){
      box = b;
      b = c;
      c = box;
    }
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
 //for study source code by other coder
using namespace std;
 
#define M 33
 
int n, z;
long long x[1005], y[1005];
char ans[40];
set<int> s;
 
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", x + i, y + i);
		s.insert(abs(x[i] + y[i]) & 1);
	}
	if (s.size() == 2)
		printf("-1\n");
	else {
		z = *s.begin();
		if (z) {
			printf("%d\n", M);
			for (int i = 0; i < M; i++)
				printf("%lld%c", 1LL << i, i == M - 1 ? '\n' : ' ');
		} else {
			printf("%d\n", M + 1);
			for (int i = 0; i < M; i++)
				printf("%lld ", 1LL << i);
			puts("1");
			ans[M] = 'L';
		}
		for (int i = 0; i < n; i++) {
			if (!z)
				x[i]++;
			for (int j = 0; j < M - 1; j++)
				if (abs(x[i]) & (1LL << j))
					if ((x[i] < 0) ^ !((abs(x[i]) ^ abs(y[i])) & (1LL << (j + 1))))
						ans[j] = 'L', x[i] += 1LL << j;
					else
						ans[j] = 'R', x[i] -= 1LL << j;
				else
					if ((y[i] < 0) ^ !((abs(x[i]) ^ abs(y[i])) & (1LL << (j + 1))))
						ans[j] = 'D', y[i] += 1LL << j;
					else
						ans[j] = 'U', y[i] -= 1LL << j;
			if (abs(x[i]) & (1LL << (M - 1)))
				if (x[i] < 0)
					ans[M - 1] = 'L', x[i] += 1LL << (M - 1);
				else
					ans[M - 1] = 'R', x[i] -= 1LL << (M - 1);
			else
				if (y[i] < 0)
					ans[M - 1] = 'D', y[i] += 1LL << (M - 1);
				else
					ans[M - 1] = 'U', y[i] -= 1LL << (M - 1);
			printf("%s\n", ans);
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>

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


void solve()
{
	int N, P;
	cin >> N >> P;
	vector<int> A(N);
	bool isOdd = false;
	for (int i = 0; i < N; ++i)
	{
		cin >> A[i];
		if (A[i] % 2 == 1)
		{
			isOdd = true;
		}
	}
	long long int ans = 1;
	if (isOdd == false)
	{
		ans = pow(2, N);
	}
	else
	{
		ans = pow(2, N - 1);
	}
	if (P == 0)
	{
		cout << ans << endl;
	}
	else
	{
		cout << (long long int)pow(2, N) - ans << endl;
	}
}

int main()
{
	solve();
	return(0);
}

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

// DPテーブル
const int MAX_N = 15;
const int MAX_W = 110000;
int dp[MAX_N][MAX_W]; // 12 種類だが余裕をもつ

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

    // 品物を列挙 (価値はすべて 1)
    vector<int> weight;
    for (int i = 1; i <= W; i *= 6) weight.push_back(i);
    for (int i = 9; i <= W; i *= 9) weight.push_back(i); // 1 が重複しないように (しても問題はない)
    int n = (int)weight.size();

    // DP初期条件: dp[i][0] = 0
    for (int i = 0; i < MAX_N; ++i) for (int w = 0; w < MAX_W; ++w) dp[i][w] = 1 << 29; // INF
    for (int i = 0; i <= n; ++i) dp[i][0] = 0;

    // DPループ
    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= W; ++w) {
            dp[i + 1][w] = min(dp[i + 1][w], dp[i][w]);
            if (w >= weight[i]) dp[i + 1][w] = min(dp[i + 1][w], dp[i + 1][w - weight[i]] + 1);
        }
    }

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

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

#define sp ' '
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define forn(YY, yy) for(int yy = 0; yy < YY; ++yy)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;

const int MOD = 1e9 + 7;
const int INF = 2e9 + 13;
const int mINF = -2e9 - 13;
const double PI = 3.14159265358979;
const double EPS = 1e-9;

int main(int argc, char **argv)
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    int N; cin >> N;
    double sum = 0;
    string S;

    for(int i = 1; i <= N; ++i) S += (char)(i + '0');

    vector<pair<double, double>> cors;

    for(int i = 0; i < N; ++i)
    {
        double x, y; cin >> x >> y;
        cors.pb(mp(x, y));
    }

    do
    {
        for(int i = 0; i < N-1; ++i)
        {
            char c1 = S[i], c2 = S[i+1];
            int s1 = c1 - '0', s2 = c2 - '0';

            sum += sqrt(( pow(fabs( cors[s1-1].st - cors[s2-1].st ), 2.0) + pow(fabs( cors[s1-1].nd - cors[s2-1].nd ), 2.0) ));
        }
    }while(next_permutation(S.begin(), S.end()));

    double nfac = 1;
    for(int i = 1; i <= N; ++i) nfac *= i;
    sum /= nfac;

    printf("%.10lf\n", sum);

    return 0;
}

//cikisir



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long double ld;
typedef long long ll;
const int inf = 1e9 + 1;
using namespace std;
int main() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    cout << setprecision(20);
    ll x;
    cin >> x;
    ll sq = sqrt(x + 1);
    for (int k = sq; k > 0; --k) {
        if (x % k == 0) {
            cout<<k+x/k-2<<endl;
            return 0;
        }
    }
    //    int n;
//    ll k;
//    cin >> n >> k;
//    vector<ll> a(n);
//    for (int i = 0; i < n; i++) {
//        cin >> a[i];
//    }
//    vector<ll> b(n);
//    for (int j = 0; j < n; j++) {
//        cin >> b[j];
//    }
//    sort(a.begin(), a.end());
//    sort(b.begin(), b.end());
//    ll ans = 0;
//
////    for (int i = 0; i < n; i++) {
////        cout << a[i] << " ";
////    }
////    cout << endl;
////    for (int j = 0; j < n; j++) {
////        cout << b[j] << " ";
////    }
////    cout << endl;
//    set<pair<ll,int>> x;
//    for (int i = 0; i < n; i++) {
//        if (k >= a[i]) {
//            k -= a[i];
//        } else {
//            ans += (a[i] - k) * b[n - 1 - i];
//            k = 0;
//        }
//        cout << ans << " ";
//    }
//    cout << ans;
    return 0;
}


Measured memory_bytes: 256