akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <math.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define PI 3.14159265359
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  string t;
  cin >> t;
  int zero = 0;

  ll ans = 0;
  rep(i, t.size()) {
    if (t[i]-'0' == 0) zero++;
    else if (i % 2 == 0) {
      ans += (zero + 1) / 2;
    } else {
      ans += zero / 2;
    }
  }

  zero = 0;
  ll one = 0;
  bool ris1 = false;
  for (int i=t.size()-1; i>=0; i--) {
    if (t[i]-'0' == 1) one++;
    if (t[i]-'0' == 0) {
      zero++;
      ris1 = false;
    } else if (!ris1) {
      ans += zero; ris1 = true;
    } else {
      ris1 = false;
    }
  }

  //cout << "the number of 1 is " << one << endl;
  ans += (one + 1) / 2 * ((one + 1) / 2 + 1);
  ans = ans - (one % 2 == 0 ? 0 : (one + 1) / 2);

  cout << ans << endl;

  return 0;
}

/*
*/


Measured memory_bytes: 3720
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] argv) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");

        long a = Long.parseLong(str[0]);
        long b = Long.parseLong(str[1]);
        long x = Long.parseLong(str[2]);

        if(a==0) System.out.println(b/x + 1);
        else System.out.println(b/x - (a-1)/x);
    }
}


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

int main(){
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    int n = s.size();
    for (int i = 0; i < n - 1; i++){
        if (s[i] == s[i+1]){
            cout << "no" << endl;
            return 0;
        }
    }

    cout << "yes" << endl;
}

Measured memory_bytes: 256
{-# OPTIONS_GHC -O2 -funbox-strict-fields #-}
import qualified Data.ByteString.Char8 as BC
import           Data.Maybe            (fromJust)
import qualified Data.Vector           as V

main :: IO ()
main = do
  [h, w] <- map readInt . BC.words <$> BC.getLine
  sss <- lines <$> getContents
  putStrLn $ if solve h w sss then "Yes" else "No"

solve :: Int -> Int -> [[Char]] -> Bool
solve h w sss = all p [(i, j) | i <- [0 .. h-1]
                              , j <- [0 .. w-1]
                              , sss' V.! i V.! j == '#'] where
  sss' = V.fromList $ map V.fromList sss
  p (i, j) = any (q (i, j)) [(i + di, j + dj)
                            | (di, dj) <- [(1, 0), (0, 1)
                                          ,(-1, 0), (0, -1)]]
  q (i, j) (i', j')
    | i' < 0 || h <= i' || j' < 0 || w <= j' = False
    | sss' V.! i' V.! j' == '#'              = True
    | otherwise                              = False



readInt :: BC.ByteString -> Int
readInt = fst . fromJust . BC.readInt


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

using namespace std;
using i64 = int64_t;
#define int i64
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
const int INF = (1 << 30);
const i64 INFL = (1LL << 62);
const i64 MOD = 1000000007;

template <typename T>
T in() {
  T value;
  cin >> value;
  return value;
}

#undef int
int main() {
#define int i64
  cin.tie(0);
  ios::sync_with_stdio(false);
  int a = in<int>();
  int b = in<int>();
  int c = in<int>();
  int x = in<int>();
  int y = in<int>();
  int ans = INF;
  rep(i, pow(10, 5) + 1) {
    int tmp = i * 2 * c + max((i64)(0), x - i) * a + max((i64)(0), y - i) * b;
    ans = min(ans, tmp);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(void)
{
	int w,h,x,y,r;
	cin>>w>>h>>x>>y>>r;
	if(x+r<=w && y+r<=h && 0<=y-r && 0<=x-r) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}


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

typedef long long ll;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;


//===

const ll mod = static_cast<ll>(1e9 + 7);




class ModComb {
private:
	Vl fac, inv, finv;
public:
	ModComb(ll n) : fac(n), inv(n), finv(n) {
		fac[0] = fac[1] = 1;
		finv[0] = finv[1] = 1;
		inv[1] = 1;
		for (ll i = 2; i < n; ++i) {
			fac[i] = fac[i - 1] * i % mod;
			inv[i] = mod - inv[mod % i] * (mod / i) % mod;
			finv[i] = finv[i - 1] * inv[i] % mod;
		}
	}

	ll comb(ll n, ll k) {
		if (n < k) return 0;
		if (n < 0 || k < 0) return 0;
		return fac[n] * (finv[n - k] * finv[k] % mod) % mod;
	}
};

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



int main() {
	ll N, A, B, C;
	cin >> N >> A >> B >> C;

	ModComb mc(2 * N);

	A = A * mpow(100 - C, mod - 2) % mod;
	A = A * 100 % mod;
	B = B * mpow(100 - C, mod - 2) % mod;
	B = B * 100 % mod;
	
	ll ans = 0;
	for (ll M = N; M <= 2 * N - 1; ++M) {
		ll tmp, tmp2;
		tmp = mpow(A, N) * mpow(B, M - N) % mod;
		tmp = (tmp + mpow(A, M - N) * mpow(B, N) % mod) % mod;
		tmp = tmp * M % mod;
		tmp = tmp * mc.comb(M - 1, N - 1) % mod;

		tmp2 = mpow(100, M - 1) * (100 - C) % mod;

		ans = ans + (tmp * mpow(tmp2, mod - 2) % mod);
		ans = ans % mod;
	}

	cout << ans << endl;
}

Measured memory_bytes: 4992
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

const int MOD = 1000000007, INF = 1111111111;
using namespace std;
using lint = long long;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (int i = 0; i < (int)vec.size(); i++) {
		os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	}
	return os;
}

#ifdef _DEBUG
template <class Head>
void dump(const char* str, Head &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + 1, t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	deque<int> deq;
	for (int i = 0; i < N; i++) {
		int a;
		cin >> a;
		if (N & 1 ^ i & 1) deq.emplace_front(a);
		else deq.emplace_back(a);
	}

	for (const auto &e : deq) cout << e << " ";

	return 0;
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/rope>
using namespace std;
using namespace chrono;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
mt19937 rng(high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rngll(high_resolution_clock::now().time_since_epoch().count());
template<typename T> T ctmax(T &x, const T &y){ return x = max(x, y); }
template<typename T> T ctmin(T &x, const T &y){ return x = min(x, y); }
template<typename T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;



int main(){
	cin.tie(0)->sync_with_stdio(0);
	int n;
	cin >> n;
	map<int, int> a;
	for(auto i = 0; i < n; ++ i){
		int x;
		cin >> x;
		++ a[x];
	}
	if(int(a.size()) == 1){
		if(!a.begin()->first){
			cout << "Yes";
		}
		else{
			cout << "No";
		}
	}
	else if(n % 3){
		cout << "No";
	}
	else if(int(a.size()) == 2){
		if(!a.begin()->first && a.begin()->second == n / 3){
			cout << "Yes";
		}
		else{
			cout << "No";
		}
	}
	else if(int(a.size()) == 3){
		if(a.begin()->second == n / 3 && a.rbegin()->second == n / 3 && !(a.begin()->first ^ next(a.begin())->first ^ a.rbegin()->first)){
			cout << "Yes";
		}
		else{
			cout << "No";
		}
	}
	else{
		cout << "No";
	}
	return 0;
}

/*

*/

////////////////////////////////////////////////////////////////////////////////////////
//                                                                                    //
//                                   Coded by Aeren                                   //
//                                                                                    //
////////////////////////////////////////////////////////////////////////////////////////

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



int main()
{
int n;
cin>>n;
int ans[n];

ans[n-1]=0;
for(int index=0;index<n-1;index++)
{
    ans[index]=0;
    int i;
    cin>>i;
    i--;
    ans[i]++;
}

for(int index=0;index<n;index++)
{
    cout<<ans[index]<<endl;
}


    return 0;
}


Measured memory_bytes: 4328
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int> a(n+2), dist(n+1);
    a[0] = 0;
    for(int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    a[n+1] = 0;
    int sum = 0;
    for(int i = 0; i <= n; i++)
    {
        dist[i] = abs(a[i] - a[i+1]);
        sum += dist[i];
    }
    for(int i = 1; i <= n; i++)
    {
        if ((a[i-1]<=a[i] && a[i]<=a[i+1]) || (a[i+1]<=a[i] && a[i]<=a[i-1])) {
            cout << sum << endl;
        }
        else if ((a[i]<a[i-1] && a[i-1]<a[i+1]) || (a[i+1]<a[i-1] && a[i-1]<a[i])) {
            cout << sum - 2*dist[i-1] << endl;
        }
        else
        {
            cout << sum - 2*dist[i] << endl;
        }
        
    }
    
}

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

#define Mset(s, n)      memset(s, n, sizeof(s))
#define Rp0(i, m)       for(int i = 0; i < m; ++i)
#define Rpd(i, m, l)    for(int i = m; i >= l; --i)
#define Rp1(i ,m)       for(int i = 1; i <= m; i++)
#define All(a)          (a).begin(), (a).end()
#define Lwb             lower_bound
#define Upb             upper_bound
#define Sz(a)           int((a).size())
#define u_map           unordered_map
#define fi              first
#define se              second
#define pb              push_back
#define pf              push_front
#define is              insert
#define ooi             INT_MAX
#define ool             LLONG_MAX
#define ll              long long
#define ull             unsigned ll
#define ld              long double
#define pii             pair<int, int>
#define vi              vector<int>
#define vpii            vector<pii>

const ll MOD = (ll) 1e9 + 7;
const ld PI = acos((ld) -1);
inline int Get_bit(int x, int k){return (x >> (k - 1)) & 1;}
inline ll Gcd(ll a, ll b) {ll r; while(b){ r = a % b; a = b; b = r;} return a;}
inline ll Lcm(ll a, ll b) {return a / Gcd(a, b) * b;}
inline ll Pow(ll n, ll k) {ll r = 1; for(; k; k >>= 1, n = n * n % MOD){if(k & 1) r = r * n % MOD;} return r;}
const int base = 311;


const int N = 2e5 + 10;


ll n, m, k, ans, a[N], f[N];

void Solve(){
    cin >> n;
    Rp0(i, n) cin >> a[i];
    Rpd(i, n - 1, 0){
        if(a[i] >= a[i + 1]) f[i] = f[i + 1] + 1;
        else f[i] = 1;
        ans = max(ans, f[i]);
    }
    cout << ans - 1;
}


int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout << fixed << setprecision(10);
    Solve();
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
  long long w[201];
  long long i=0,j=0;
  long long sum=4280;
  long long ans=0;
  long long a=125;
  long long b=140;
  long long c=160;
  while(1){
    cin >> w[i];
    if(w[i]==-1){
      break;
    }
    if(30<w[i]){
      ans=1150+a*10+b*10+c*w[i]-c*30;
    }else if(20<w[i]&&w[i]<=30){
      ans=1150+a*10+b*w[i]-b*20;
    }else if(10<w[i]&&w[i]<=20){
      ans=1150+a*w[i]-a*10;
    }else if(w[i]<=10){
      ans=1150;
    }
    cout << sum-ans <<endl;
    i+=1;
    ans=0;
  }
  return(0);
}



Measured memory_bytes: 3012
#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
using namespace std;


struct Node{
	vector<int> pos;
	vector<int> emp;
	int cost;
	Node(){pos.resize(28);cost=0;}
	Node getSuccessor(int idx){
		Node res = *this;
		for(int i = 0 ; i < 28 ; i++){
			if( res.pos[i] == res.emp[idx]-1 ){
				if( i % 7 == 6 ) continue;
				int t = res.emp[idx];
				res.emp[idx] = res.pos[i+1];
				res.pos[i+1] = t;
				return res;
			}
		}
		res.pos.clear();
		return res;
	}
};
bool operator < (const Node &a,const Node &b){
	return a.pos < b.pos;
}

int main(){
	int T; cin >> T;
	while(T--){
		Node fst;
		for(int i = 0 ; i < 4 ; i++){
			for(int j = 0 ; j < 7 ; j++){
				int x; cin >> x; x -= 11;
				x = x / 10 * 7 + x % 10;
				int y = i * 8 + j + 1;
				fst.pos[x] = y;
				if( x % 7 == 0 ){
					fst.emp.push_back(y);
					fst.pos[x] = x / 7 * 8;
				}
			}
		}
		queue<Node> Q;
		Q.push(fst);
		map<Node,bool> done;
		vector<int> correct(28);
		for(int i = 0 ; i < 28 ; i++) correct[i] = (i / 7) * 8 + i % 7;
		
		while(Q.size()){
			Node q = Q.front(); Q.pop();
			if( done[q] ) continue;
			else done[q] = true;
			if( correct == q.pos ){
				cout << q.cost << endl;
				goto succ;
			}
			for(int i = 0 ; i < 4 ; i++){
				Node get = q.getSuccessor(i);
				if( get.pos.size() == 0 ) continue;
				get.cost = q.cost + 1;
				Q.push(get);
			}
		}
		cout << -1 << endl;
		succ:;
	}
}

Measured memory_bytes: 18684
#include<iostream>
#include<fstream>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<string>
#include<queue>
#include<set>
#include<vector>
#include<cmath>
#include<ctime>
#include<locale>
using namespace std;
long c[9];
int main()
{
    memset(c,0,sizeof(c));
    long n;
    cin>>n;
    for(long i=0;i<n;i++)
        {
            long x;
            scanf("%d",&x);
            c[min(x/400,(long)8)]++;
        }
    long a=0;
    for(long i=0;i<8;i++)if(c[i]>0)a++;
    cout<<max((long)1,a)<<' '<<a+c[8];
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PI 3.141592653589
#define ll long long
using namespace std;

int main(){
  string s, t;
  cin >> s >> t;

  sort(s.begin(), s.end());
  sort(t.begin(), t.end(), greater<int>());


  string S = s;
  string T = t;

  if(S < T){
    cout <<"Yes";
  }
  else cout << "No";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


signed main() {
    int N;
    cin >> N;
    string S;
    cin >> S;

    deque<char> st;
    int cnt = 0;
    for(int i=N-1; i>=0; i--) {
        if(S[i]=='(') {
            int temp = 0;
            int j=i;
            while(S[j]=='(' && j>=0) {
                temp++;
                j--;
            }
            j++; i=j;
            if(temp > cnt) {
                rep(k, temp-cnt) st.push_back(')');
                cnt = 0;
            } else cnt -= temp;
            rep(k, temp) st.push_front('(');
            //cout << temp << " ";
        } else {
            st.push_front(')');
            cnt++;
        }
        //cout << cnt << endl;
    }
    rep(i, cnt) {
        st.push_front('(');
    }
    
    while(!st.empty()) {
        cout << st.front();
        st.pop_front();
    }
    return 0;
}

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

int main() {
  ll N, M;
  cin >> N >> M;

  ll ans = 0;
  
  if (2 * N > M) {
    ans += M / 2;
  }
  else if (2 * N < M) {
    ans = N + (M - (2 * N)) / 4;
  }
  else {
    ans += N;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
string S; int N, cnt;
 
int main() {
	string S;
    cin >> S;
    if(S[0]==S[1]){
        if(S[1]==S[2])cout << "No" << endl;
        else cout << "Yes" << endl;
    }else cout << "Yes" << endl;
}

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

typedef pair<int, int> P;
typedef pair<int, P> P2;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
vector<P2> G[10000], R[10000];
int D[10000];

void dijkstra() {
  rep(i, N) D[i] = INF;
  priority_queue<P, vector<P>, greater<P> > q;
  q.push(P(0, 0));
  D[0] = 0;

  while (!q.empty()) {
    int x, d;
    tie(d, x) = q.top(); q.pop();
    if (D[x] < d) continue;

    for (P2 &p : G[x]) {
      int t = p._1;
      int nd = d + p._2._1;
      if (D[t] > nd) {
        D[t] = nd;
        q.push(P(D[t], t));
      }
    }
  }
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  while (cin >> N >> M) {
    if (N == 0 && M == 0) break;
    rep(i, N) {
      G[i].clear();
      R[i].clear();
    }
    rep(i, M) {
      int u, v, d, c;
      cin >> u >> v >> d >> c;
      u--, v--;
      G[u].pb(P2(v, P(d, c)));
      G[v].pb(P2(u, P(d, c)));
    }
    dijkstra();
    long long m = 0;
    rep(x, N) {
      if (x == 0) continue;
      int cost = INF;
      for (P2 &p : G[x]) {
        int t = p._1, d = p._2._1;
        if (D[x] == D[t]+d) {
          cost = min(cost, p._2._2);
        }
      }
      m += cost;
    }
    cout << m << "\n";
  }
  return 0;
}

Measured memory_bytes: 5328
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 3005;
int MOD;

ll inv[MAX_N],fac[MAX_N],finv[MAX_N];

void make()
{
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2;i<MAX_N;i++){
		inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
		fac[i] = fac[i-1] * (ll) i % MOD;
		finv[i] = finv[i-1] * inv[i] % MOD;
	}
}

ll comb(int a,int b)
{
	if(a<b){
		return 0;
	}
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}

inline ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

inline ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

inline ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int t[9000005];
int tt[3005];
int S[3005][3005];

void Stirling(int N)
{
    S[0][0] = 1;
    rep(i,N){
        rep(j,i+1){
            S[i+1][j+1] = add(S[i][j],mul(j+1,S[i][j+1]));
        }
    }
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n >> MOD;
    make();
    t[0] = 1;
    rep(i,n*n){
        t[i+1] = mul(t[i],2);
    }
    tt[0] = 2;
    rep(i,n){
        tt[i+1] = mul(tt[i],tt[i]);
    }
    Stirling(n+1);
    int ans = 0;
    rep(k,n+1){
        int cri = 0;
        rep(i,k+1){
            cri = add(cri,mul(t[i*(n-k)],S[k+1][i+1]));
        }
        if(k % 2){
            ans = sub(ans,mul(cri,mul(tt[n-k],comb(n,k))));
        }else{
            ans = add(ans,mul(cri,mul(tt[n-k],comb(n,k))));
        }
    }
    cout << ans << "\n";
    return 0;
}


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

#define pout(n)  printf ("%d\n", n)
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
 
typedef long long ll;
using namespace std;
 
int main() {
  char s[200];
  cin >> s;

  int n = strlen(s);

  for(int i = n-2; i; i -= 2){
    if(strncmp(s,s+i/2,i/2) == 0){
      pout(i);
      return 0;
    }
  }

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int i,j,a,b,c;
	for(c=1;;)
	{
		scanf("%d %d",&a,&b);
		if(a==0 && b==0)break;
		for(j=1;j<=a;j++)
		if(j%2==0)
	{
		for(i=1;i<=b;i++)
			{
				if(i%2==0)
					printf("#");
				else
					printf(".");
		}
			printf("\n");
		}
		else
		{
				for(i=1;i<=b;i++)
				{
				if(i%2==0)
					printf(".");
				else
					printf("#");
				}
					printf("\n");
		}	
			printf("\n");
	}
	return 0;
}


Measured memory_bytes: 2044
package main

import (
	"fmt"
)

func main() {
	var a, b float64
	fmt.Scan(&a, &b)

	if a > b {
		fmt.Println("GREATER")
	} else if a < b {
		fmt.Println("LESS")
	} else {
		fmt.Println("EQUAL")
	}

}


Measured memory_bytes: 512
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> res;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			res[i] ++;
			n /= i;
		}
	}
	if (n != 1) res[n] = 1;
	return res;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


#define in(x) cin >> x
#define out(x) cout << x
#define outn(x) cout << x << '\n'
#define outs(x) cout << x << ' '
#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}

int main() {
	ll N, M, s;
	char c;
	std::cin >> N >> M;
	map<ll, char> dic;
	map<ll, bool> flg;
	rep(i, 0, M) {
		std::cin >> s >> c;
		if (flg[s] && dic[s] != c) {
			std::cout << -1 << endl;
			return 0;
		}
		flg[s] = true;
		dic[s] = c;
	}

	if (N > 1) {
		if (flg[1] && dic[1] == 0) {
			std::cout << -1 << endl;
			return 0;
		}
		else if (!flg[1]) {
			dic[1] = '1';
		}
	}

	ll cnt = 0;
	string str = "";
	for (auto itr = dic.begin(); itr != dic.end(); itr++) {
		if (itr->first - cnt > 1) {
			str += string(itr->first - cnt - 1, '0');
		}
		cnt = itr->first;
		str += itr->second;
	}
	if (str != "0" && str.size() < N) {
		str += string(N - str.size(), '0');
	}

	if (str.size() == N) {
		std::cout << str << endl;
	}
	else {
		std::cout << -1 << endl;
	}


	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h> 
 
#define INF (1<<31) - 1 //INT_MAX/2
#define MOD 1000000007
#define PI  acos(-1)
 
using ll  = long long;
using ull = unsigned long long;
 
int main(int argc, char *argv[])
{
    int N, K;
    std::cin >> N >> K;

    std::vector<int> h(N);
    for (int i = 0; i < N; i++) {
        std::cin >> h[i];
    }

    std::vector<int> dp(N);
    for (int i = 0; i < N; i++) {
        dp[i] = INF;
    }

    dp[0] = 0;
    if (N <= K+1) {
        dp[N-1] = std::abs(h[N-1] - h[0]);
    } else {
        for (int i = 1; i <= K; i++) {
            dp[i] = std::abs(h[i] - h[0]);
        }
        for (int i = K+1; i < N; i++) {
            int min = INF;
            for (int j = 1; j <= K; j++) {
                int temp = dp[i-j] + std::abs(h[i] - h[i-j]);
                if (min > temp) {
                    min = temp;
                }
            }
            dp[i] = min;
        }
    }

    std::cout << dp[N-1] << std::endl;
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const string YES = "Yes";
const string NO = "No";

int main()
{
  ll N;
  scanf("%lld",&N);
  string s;
  cin >> s;

  int red = 0;
  int blue = 0;
  for (auto c:s) {
    if (c=='R') red++;
    else blue++;
  }
  if (red>blue) cout << YES << endl;
  else cout << NO << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,n) for(i=a;i<n;i++)
#define ll long long int 
int main() {
	ll n,d,b,cnt=0,i,j,k,l,r,mn=2020;
    cin>>l>>r;
    
    if(r-l>2019)
    cout << 0<<endl;
    else{
        for(i=l;i<r;i++)
        {
            for(j=i+1;j<=r;j++)
            {
                d=(i*j);
                d%=2019;
                // cout << i<<" "<<j<<" "<<d<<endl; 
                mn=min(d,mn);
            }
        }
    cout <<mn<<endl;
    }
	return 0;
}

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

using namespace std;

int day[101];
int n, q;

int main()
{
	cin >> n >> q;
	while (n) {
		for (int i = 0; i < n; i++) {
			int m;
			cin >> m;
			for (int j = 0; j < m; j++) {
				int t;
				cin >> t;
				day[t]++;
			}
		}
		int i = 0;
		int ma = -1;
		for (i = 1; i < 101; i++) {
			if (day[i] >= q) ma = max(day[i], ma);
		}
		for (i = 1; i < 101; i++) {
			if (day[i] == ma) break; 
		}
		if (i == 101) cout << 0 << endl;
		else cout << i << endl;
		for (i = 1; i < 101; i++) day[i] = 0;	
		cin >> n >> q;
	}
}


Measured memory_bytes: 3028
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
using namespace std;

int main(void)
{
	int A, B, C;
	cin >> A >> B >> C;

	if(A+B >= C)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


	return 0;
}


Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,a,b,ans=0; 
    cin>>n>>a>>b;
    if (b<a or ((n==1) and (a!=b))) ans=0;
    else {
        n-=2;
        int l=n*a,r=n*b;
        ans =(r-l+1);
    }
    cout << ans << endl;
}

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


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

#define ff first
#define ss second
#define mp make_pair

using namespace std;

typedef long long ll;

char s[200005];
char t[200005];

int main(){
	int n,m;

	scanf("%d%d", &n, &m);
	
	printf("%lld\n", ((ll)n*m)/__gcd(n,m));

	return 0;
}

Measured memory_bytes: 256
N = int(input())
a = [int(input()) for i in range(N)]
cnt=0
for i in range(N):
    if a[i]//2 >=1:
        cnt+=a[i]//2
        a[i]-=a[i]//2*2
    if i!=N-1:
        if a[i+1]>=1 and a[i]==1:
            cnt+=1
            a[i+1]-=1
            a[i]-=1
print(cnt)

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

#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <functional>
#include <math.h>
#include <map>
#include <queue>
#include <stack>

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i=(b-1);i>=(a);--i)
#define REP(i,n)   FOR(i,0,n)
#define RREP(i,n)   RFOR(i,0,n)
#define SORT(s) sort(s.begin(), s.end())
#define P pair<int, int>
#define mp make_pair

const double INF = 1e+09;
const int MOD = 1e9+7;

using namespace std;

template <typename _Ty>
ostream& operator << (ostream& ostr, const vector<_Ty>& v) {if (v.empty()) {ostr << "{ }"; return ostr;}
    ostr << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) {ostr << ", " << *itr;}
    ostr << "}";
    return ostr;}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int gcd(int a, int b){
   if (a%b == 0) return(b);
   else return(gcd(b, a%b));}

int lcm(int a, int b)
{return a * b / gcd(a, b);}

vector<int> uniq(vector<int> vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return vec;}

vector<ll> divisor(ll n) {
vector<ll> ret;
for(int64_t i = 1; i * i <= n; i++) {
  if(n % i == 0) {
    ret.push_back(i);
    if(i * i != n) ret.push_back(n / i);
  }
}
  sort(begin(ret), end(ret));
  return (ret);
}
void permu(int n){
  vector<int> perm(n);
  REP(i, n) perm[i] = i;
do{
  cout << perm  << endl;
}
while (next_permutation(perm.begin(), perm.end()));
return;}

vector<pair<ll, int>> prime_div(ll n){
  vector<pair<ll, int>> res;
  for (ll i=2; i*i <= n;i++){
    if (n%i == 0){
      int a = 0;
      while(n%i == 0){
        n /= i;
        a++;
      }
      pair<ll, int> tmp;
      tmp.first = i;
      tmp.second = a;
      res.push_back(tmp);
    }
  }
  if (n != 1){
    pair<ll, int> now;
    now.first = n;
    now.second = 1;
    res.push_back(now);}
  return res;
}


// printf("%.10f\n" , ans);
int main(void){
  ios::sync_with_stdio(false);
  int x1, x2, x3, x4, x5;
  cin >> x1 >> x2 >> x3 >> x4 >> x5;
  int tmp = x1 + x2 + x3 + x4 + x5;
  cout << 15 - tmp << endl;
  return 0;
}



Measured memory_bytes: 3092
using System;
using System.Linq;

class Program
{
      static void Main(string[] args)
      {
        int n = int.Parse(Console.ReadLine());
        int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        
        double m = 0;
        for(int i=0;i<n;i++)
        {
          m+=1d/a[i];
        }
        Console.WriteLine(1d/m);
      }
}


Measured memory_bytes: 13396
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <deque>
#include <vector>
#include <bitset>
#include <cmath>
#include <utility>
#define Maxn 100005
#define Maxm 1000005
#define lowbit(x) x&(-x)
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define PI acos(-1.0)
#define LL long long 
#define Inf (1LL<<62)
#define inf 0x3f3f3f3f
#define input freopen("input.txt","r",stdin)
#define output freopen("output.txt","w",stdout)
using namespace std;
LL tree[Maxn<<1];
struct Node
{
	LL sum;
	int id;
}node[Maxn<<1];
void add(LL pos,int n)
{
	for(LL i=pos;i<=n;i+=lowbit(i))
		tree[i]++;
}
LL sum(LL pos)
{
	LL sum=0;
	for(LL i=pos;i>0;i-=lowbit(i))
		sum+=tree[i];
	return sum;
}
bool cmp1(Node a,Node b)
{
	return a.sum<b.sum;
}
bool cmp2(Node a,Node b)
{
	return a.id<b.id;
}
int main()
{
	LL n,k,ans,cnt;
	//input;output;
	while(~scanf("%lld%lld",&n,&k))
	{
		ans=0;
		cnt=1;
		memset(tree,0,sizeof(tree));
		node[0].id=node[0].sum=0;
		for(int i=1;i<=n;i++)
		{
			scanf("%lld",&node[i].sum);
			node[i].sum-=k;
			node[i].sum+=node[i-1].sum;
			node[i].id=i;
		}
		sort(node,node+1+n,cmp1);
		LL pre=node[0].sum;
		for(int i=1;i<=n;i++)
		{
			LL tmp=node[i].sum;
			node[i].sum=tmp==pre?cnt:++cnt;
			pre=tmp;
		}
		node[0].sum=1;
		sort(node,node+1+n,cmp2);
		for(int i=0;i<=n;i++)
		{
			ans+=sum(node[i].sum);
			add(node[i].sum,n+1);
		}
		printf("%lld\n",ans);
	}
	return 0;
}

Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <set>
#include <iomanip>
#include <fstream>
#include <stdint.h>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
using namespace std;

constexpr int INF       = 1000000000;/* 1e+9a */
constexpr int MODULO    = 1000000007;

#define REP(i,f,n) for(int i=(f); i < (n); ++i)
#define PER(i,f,n) for(int i=(n-1); i >= f; --i)

constexpr int evx[4] = { 1, 0, -1, 0 };
constexpr int evy[4] = { 0, 1, 0, -1 };

//----------------------------------
//----------------------------------

signed main()
{
    ios::sync_with_stdio(false);
	int w, h;
	cin >> w >> h;
	vector<long> p, q;
	REP(i, 0, w)
	{
		int tmp;
		cin >> tmp;
		p.push_back(tmp);
	}
	REP(i, 0, h)
	{
		int tmp;
		cin >> tmp;
		q.push_back(tmp);
	}
	long ans = 0;
	sort(p.begin(), p.end());
	sort(q.begin(), q.end());

	int j = 0;
	long sum = 0;
	REP(i, 0, w)
	{
		while(j < h && q[j] < p[i])
		{
			sum += q[j++];
		}
		ans += sum;
		ans += p[i] * (h-j);
	}
	
	REP(i, 0, w)
		ans += p[i];
	REP(i, 0, h)
		ans += q[i];

	cout << ans << '\n';
}



Measured memory_bytes: 2676
#include <bits/stdc++.h>
using namespace std;
#define elif else if
typedef long long ll;
typedef unsigned long long ull;
#define DEBUG(x) cout << (x) << endl

map<ll, ll> d;
ll arr[200005] = {0};

int main()
{
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", arr + i);
        d[arr[i]] += 1;
    }
    ll ans = 0;
    for (map<ll, ll>::iterator it = d.begin(); it != d.end(); it++)
    {
        ans += (it->second) * (it->second - 1) / 2;
    }
    ll tmp;
    for (int i = 0; i < n; i++)
    {
        ll ttmp = d[arr[i]];
        tmp = ans - ttmp * (ttmp - 1) / 2 + (ttmp - 1) * (ttmp - 2) / 2;
        printf("%lld\n", tmp);
    }
    return 0;
}

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

#define int long long
#define rep(i, n) for (int i = 0; i < (int) (n); i++)
#define reps(i, n) for (int i = 1; i <= (int) (n); i++)
#define all(x) (x).begin(), (x).end()
#define uniq(x) (x).erase(unique(all(x)), (x).end())
#define bit(n) (1LL << (n))
#define cdiv(a, b) (((a) - 1) / (b) + 1)
#define dump(x) cerr << #x " = " << (x) << endl
using vint = vector<int>;
using vvint = vector<vint>;
using pint = pair<int, int>;
using vpint = vector<pint>;
template<typename T> using priority_queue_rev = priority_queue<T, vector<T>, greater<T>>;
constexpr double PI = 3.1415926535897932384626433832795028;
constexpr int DY[9] = {0, 1, 0, -1, 1, 1, -1, -1, 0};
constexpr int DX[9] = {1, 0, -1, 0, 1, -1, -1, 1, 0};
int gcd(int a, int b) {
    while (b) { swap(a %= b, b); }
    return a;
}
int lcm(int a, int b) { return a / gcd(a, b) * b; }
int sign(int x) { return (x > 0) - (x < 0); }
template<typename T> void fin(T mes) {
    cout << mes << endl;
    exit(0);
}
template<typename T, typename U> bool chmax(T &a, const U &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> bool chmin(T &a, const U &b) {
    if (b < a) {
        a = b;
        return true;
    }
    return false;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &rhs) {
    os << "(" << rhs.first << ", " << rhs.second << ")";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const vector<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const deque<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T> ostream &operator<<(ostream &os, const set<T> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
template<typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &rhs) {
    os << "{";
    for (auto itr = rhs.begin(); itr != rhs.end(); itr++) {
        os << *itr << (next(itr) != rhs.end() ? ", " : "");
    }
    os << "}";
    return os;
}
struct setup {
    static constexpr int PREC = 20;
    setup() {
        cout << fixed << setprecision(PREC);
        cerr << fixed << setprecision(PREC);
    };
} setup;

int N;
int a[330000];
signed main() {
    cin >> N;
    rep(i, 3 * N) { cin >> a[i]; }
    sort(a, a + 3 * N), reverse(a, a + 3 * N);
    int ans = 0;
    rep(i, N) { ans += a[2 * i + 1]; }
    cout << ans << endl;
}

Measured memory_bytes: 5924
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

typedef long long ll;
typedef pair<ll, ll> P;


int main()
{
  int N, K;
  cin >> N >> K;
  string S;cin >> S;
  S[K-1] += 'a'-'A';
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 256
var lines: string[] = [];
var reader: any = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout
});
reader.on("line", function(line: string) {
  lines.push(line);
});

reader.on("close", function() {
  var str: string = lines[0];

  if (
    -1 != str.indexOf("a") &&
    -1 != str.indexOf("b") &&
    -1 != str.indexOf("c")
  ) {
    console.log("Yes");
  } else {
    console.log("No");
  }
});


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)

using namespace std;
const long long INF = 1LL << 61;

int main() {
	int a; cin >> a;
	string s; cin >> s;
	if (a >= 3200)cout << s;
	else cout << "red";
}

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

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

vector<pair<ll, int>> factorize(ll g) {
    vector<pair<ll, int>> res;
    for (ll i = 2; i * i <= g; i++) {
        if (g % i != 0) continue;
        res.emplace_back(i, 0);
        while(g % i == 0) {
            g /= i;
            res.back().second++;
        }
    }
    if (g != 1) res.emplace_back(g, 1);
    return res;
}

int main() {
    ll a, b;
    cin >> a >> b;
    ll g = gcd(a, b);
    auto f = factorize(g);
    int ans = f.size() + 1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
/* ~ 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;
	ll n,q;
	ll sum=0;
	cin>>n;
	ll a[n];
	map<ll,ll> m; 
	for(int i=0;i<n;i++)
	{
	    cin>>a[i];
	    m[a[i]]++;
	    sum += a[i];
	}
	cin>>q;
	while(q--)
	{
	    ll b1,c1;
	    cin>>b1>>c1;
	    ll value = m[b1];
        sum = sum-(b1*value);
        sum = sum+(c1*value);
         m[b1] = 0;
        m[c1] += value;
        cout<<sum<<endl;
	}
	return 0;
}


Measured memory_bytes: 10332
#include <bits/stdc++.h>
using namespace std;
#define ll                  long long
#define ld                  long double
#define pb                  push_back
#define mkp                 make_pair
#define f(i,l,h)            for(ll i=l;i<h;i++)
#define fr(i,h,l)           for(ll i=h;i>=l;i--)
#define mem(a,val)          memset(a,val,sizeof(a))
#define all(v)              (v).begin(),(v).end()
#define ff                  first
#define ss                  second
#define spc(x)              cout<<fixed<<setprecision((x));
#define deb(x)              cout<<#x<<" "<<x<<endl;
#define deba(x)             cout<<#x<<": "; for(auto u:x) cout<<u<<" ";  cout<<endl;
#define check               cout<<"hello"<<endl;
#define fastio              ios_base::sync_with_stdio(false);cin.tie(NULL)
const ld pi=3.141592653589793;
const ll mod=998244353;
const ll INF=(ll)(1e9+7);
typedef pair<ll,ll> pll;
typedef vector<ll> vll;

ll power(ll a,ll b){
    ll res=1;
	while(b){
	    if(b&1) res=(res*a);
	    a=(a*a);
	    b>>=1;
	}
	return res;
}

ll dfs(ll u,vll adj[],ll dp[]){
    if(dp[u]!=-1) return dp[u];
    for(auto v:adj[u]){
        dp[u]=max(dp[u],dfs(v,adj,dp));
    }
    return dp[u]=dp[u]+1;
}

int main()
{
    //cout << "Hello world!" << endl;
    ll n,m;
    cin>>n>>m;
    vll adj[n+1];
    ll a,b;
    f(i,0,m){
        cin>>a>>b;
        adj[a].pb(b);
    }

    ll dp[n+1];
    mem(dp,-1);

    f(i,1,n+1){
        if(dp[i]!=-1) continue;
        dfs(i,adj,dp);
    }
    ll mx=0;

    f(i,1,n+1){
        mx=max(mx,dp[i]);
    }
    cout<<mx<<endl;



    return 0;
}


Measured memory_bytes: 11708
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <cmath>
#include <tuple>
#include <sstream>
#include <iomanip>
#include <map>
#include <unordered_map>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())

using namespace std;
typedef long long ll;

int main(int argc, const char * argv[]) {
    //    ifstream in("input.txt");
    //    cin.rdbuf(in.rdbuf());
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    
    string ans = "AC";
    
    if (s[0] != 'A') ans = "WA";
    
    int cntCapitalC = 0;
    rep(i, s.size())
    {
        bool isLowercase = s[i] >= int('a') && s[i] <= 'z';
        bool isInRange = i >= 3 - 1 && i <= s.size() - 2;
        if (isInRange && !isLowercase && s[i] != 'C')
            ans = "WA";
        if (!isInRange && !isLowercase && i != 0)
            ans = "WA";
        if (s[i] == 'C')
            ++cntCapitalC;
    }
    
    if (cntCapitalC != 1)
        ans = "WA";
    
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stack>

using namespace std;

#define rep(i, n) for (int i=0; i<int(n); i++)

#define MAX_N 100001
int n;

int fetch() {
  int x; // 0 or 1 -> -1 or 1
  cin >> x;
  return x == 0 ? -1 : 1;
}
bool same_sgn(int x, int y) {
  return (x > 0 && y > 0) || (x < 0 && y < 0) || (x == 0 || y == 0);
}

int main() {
  while (true) {
    cin >> n;
    if (n == 0) break;

    stack<int> v;

    // head
    v.push(fetch());

    // tail
    for(int i=1; i<n; i++) {
      int x = fetch();
      // ?\???°
      // if ((i+1) % 2 == 1)
      int t = v.top();
      if (i % 2 == 0) {
        // ?¬?????????????
        if (same_sgn(x, t)) {
          v.pop();
          v.push(x + t);
        }
        else v.push(x);
      }
      // ??¶??°
      else {
        // ?¬?????????????
        if (same_sgn(x, t)) {
          v.pop();
          v.push(x + t);
        }
        else {
          // shuffle
          v.pop();
          int z = -t + x;

          // i = 2
          if (v.empty()) {
            v.push(z);
          }
         else {
            int u = v.top();

            // push???????????¨???????????????(z)??¨
            // ???????????????(u)??§??????????????????
            if (same_sgn(z, u)) {
              v.pop();
              v.push(z + u);
            }
            else {
              v.push(z);
            }
          }
        }
      }
    }
    int count = 0;
    while(!v.empty()) {
      int t = v.top();
      //cout << ' ' << t << endl; // DEBUG
      if (t < 0) count += (-t);
      v.pop();
    }
    cout << count << '\n';
  }
  return 0;
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;

int main() {
    int N;
    cin >> N;
    int d[N];
    REP(i, N)cin >> d[i];
    sort(d, d + N);
    cout << d[N/2] - d[N/2 - 1] << endl;
    return 0;
}


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

using namespace std;


int  main() {

	string a, b;

	cin >> a >> b;
	if ((a == "H"&&b == "H") || (a == "D"&&b == "D")) {
		cout << "H" << endl;
	}
	else {
		cout << "D" << endl;
	}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S; cin >> S;
  int k=S.size();
  if(k==1){
    cout << 1 << endl;
    return 0;
  }
  vector<char> MY(k);
  for(int i=0;i<k;i++){
    MY[i]=S.at(i);
  }
  int ans=1;
  string a="";
  a+=MY[0];
  string b="";
  for(int i=1;i<k;i++){
    b+=MY[i];
    if(a!=b){
      ans++;
      a=b;
      b="";
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 772
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define BUF_SIZE 10

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

#define DIGITS_MAX 100
#define K_MAX 100000

int main(void) {
    static int dp[DIGITS_MAX+1][10] = {0};
    int whole = 0;
    int k = get_int();
    // special case
    if(k <= 12) {
        printf("%d\n", k);
        return 0;
    }
    int i, j;
    for(i = 0; i < 10; i++) {
        dp[0][i] = 1;
    }
    int digit_stack[DIGITS_MAX];
    int sidx = 0;
    whole += 9;
    int size, digit;
    int k_size;
    for(size = 1; size <= DIGITS_MAX; size++) {
        dp[size][0] = dp[size-1][0] + dp[size-1][1];
        int flag = 0;
        for(digit = 1; digit < 10; digit++) {
            int res = 0;
            if(digit+1 <= 9) res += dp[size-1][digit+1];
            res += dp[size-1][digit] + dp[size-1][digit-1];
            dp[size][digit] = res;
            int new = whole + dp[size][digit];
            if(new >= k) {
                k_size = size;
                digit_stack[sidx++] = digit;
                flag = 1; break;
            }
            whole = new;
#ifdef DEBUG
            printf("[%d] dp[%d][%d]\n", whole, size, digit);
#endif
        }
        if(flag) {
#ifdef DEBUG
            printf("whole: %d, %d %d\n", whole, k_size, digit_stack[0]);
#endif
            break;
        }
    }

    int pivot = digit_stack[sidx-1];
    int sum = whole;
    for(size = k_size-1; size >= 0; size--) {
        for(digit = pivot-1; digit <= pivot+1; digit++) {
            if(digit<0 || digit > 9) continue;
            int new = sum + dp[size][digit];
            if(new>=k) {
                digit_stack[sidx++] = digit;
                pivot = digit;
                break;
            }
            sum = new;
#ifdef DEBUG
            printf("[%d] dp[%d][%d]\n", sum, size, digit);
#endif
        }
    }
    for(i = 0; i < sidx; i++) {
        putchar('0' + digit_stack[i]);
    }
    putchar('\n');
    return 0;
}

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

int main() {
	int N;
	string S;
	cin >> N >> S;
	vector<int> P(1<<N);
	for (int i = 0;i < 1 << N;++ i) cin >> P[i];
	
	static int dp[19][1<<18]; // dp[i][j]: 高さi, 左からj番目を開始点とするトーナメントの勝者
	for (int i = 0;i < 1 << N;++ i) dp[0][i] = P[i];
	for (int i = 1;i <= N;++ i) {
		for (int j = 0;j < 1 << N;++ j) {
			int left = dp[i - 1][j];
			int right = dp[i - 1][(j + (1 << i - 1)) % (1 << N)];
			int x = min(left, right), y = max(left, right); // 前のトーナメントにおける勝者2名, x≦y
			dp[i][j] = S[y - x - 1] == '0' ? x : y;
		}
	}
	for (int i = 0;i < 1 << N;++ i) cout << dp[N][i] << endl;
}


Measured memory_bytes: 23780