akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int gcd(int a, int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int lcm(int a, int b){
    return a*b/gcd(a,b);
}


signed main(void) {
    int i,j;
    int n;
    cin >> n;
    vi a(n);
    rep(i,n) cin >> a[i];
    vector<pii> p(n);
    rep(i,n)p[i] = pii(a[i],i);
    sort(all(p));
    set<pii> land;
    rep(i,n)if(a[i]){
        int j = 0;
        while(i+j < n && a[i+j])j++;
        land.insert(pii(i, i+j-1));//[i,i+j-1]
        i += j;
    }
    int ans = land.size();
    rep(i,n)if(p[i].first){
        int q = p[i].second;
        auto itr = land.lower_bound(pii(q+1,q));
        itr--;
        int l = itr->first;
        int r = itr->second;
        //cout << "!" << q << " " << l << " " << r << endl;
        land.erase(itr);
        if(q == l){
            if(l != r)land.insert(pii(q+1,r));
        }else if(q == r){
            if(l != r)land.insert(pii(l,q-1));
        }else{
            land.insert(pii(l,q-1));
            land.insert(pii(q+1,r));
        }
        if(i < n && p[i].first == p[i+1].first)continue;
        /*
        cout << p[i].first << endl;
        for(set<pii>::iterator itr = land.begin(); itr != land.end(); ++itr){
            cout << (itr->first) << " " << (itr->second) << endl;
        }
        */
        ans = max(ans, (ll)land.size());
    }
    cout << ans << endl;
}



Measured memory_bytes: 8220
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

//AC

int main(void){
	ll X,ans;
	cin>>X;
	rep(i,1e9){
		if(i*(i+1)/2>=X){
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXN = 200, MAXT = 10000 + 10;

vector<int> G[MAXN];
bool mark[MAXN];
int p[MAXN], t[MAXN], k[MAXN];
int N, M, T;

namespace SCC {
  vector<int> SCC[MAXN], SCCG[MAXN];
  int low[MAXN], dfn[MAXN], ord[MAXN];
  int scc_cnt;
  void dfs(int x) {
    static int stk[MAXN], top = 0, sz = 0;
    stk[++ top] = x; low[x] = dfn[x] = ++ sz;
    for (auto &y : G[x]) {
      if (!dfn[y]) {
        dfs(y); low[x] = min(low[x], low[y]);
      }
      else if (ord[y] == -1) low[x] = min(low[x], dfn[y]);
    }
    if (dfn[x] == low[x]) {
      SCC[scc_cnt ++].clear();
      do {
        SCC[scc_cnt - 1].push_back(stk[top]);
        ord[stk[top]] = scc_cnt - 1;
      } while (x != stk[top --]);
    }
  }
  void scc() {
    memset(dfn, 0, sizeof(dfn));
    memset(ord, -1, sizeof(ord));
    scc_cnt = 0;
    for (int i = 0; i < N; ++ i) {
      if (!dfn[i]) dfs(i);
    }
  }
  void build() {
    for (int i = 0; i < scc_cnt; ++ i) {
      SCCG[i].clear();
      for (auto &u : SCC[i]) for (auto &v : G[u]) {
        if (ord[v] != ord[u]) SCCG[i].push_back(ord[v]);
      }
      sort(SCCG[i].begin(), SCCG[i].end());
      SCCG[i].resize(unique(SCCG[i].begin(), SCCG[i].end()) - SCCG[i].begin());
    }
  }
  int deg[MAXN], self[MAXN];
  int dp[MAXN][MAXT];
  void update(int x) {
    vector<PII> item;
    for (auto &u : SCC[x]) {
      for (int s = 1; s <= k[u]; s <<= 1) {
        item.push_back(PII(s * t[u], s * p[u]));
        k[u] -= s;
      }
      if (k[u]) item.push_back(PII(k[u] * t[u], k[u] * p[u]));
    }
    for (auto &v : item) {
      for (int i = T; i >= v.first; -- i) {
        dp[x][i] = max(dp[x][i], dp[x][i - v.first] + v.second);
      }
    }
  }
  int solve() {
    scc(); build();
    memset(deg, 0, sizeof(deg));
    for (int i = 0; i < scc_cnt; ++ i) {
      self[i] = (SCC[i].size() == 1 && mark[SCC[i][0]]);
      for (auto &v : SCCG[i]) deg[v] ++;
      for (int j = 0; j <= T; ++ j) dp[i][j] = 0;
    }
    queue<int> Q;
    for (int i = 0; i < scc_cnt; ++ i) {
      if (deg[i] == 0) Q.push(i);
    }
    while (!Q.empty()) {
      int x = Q.front(); Q.pop();
      if (SCC[x].size() == 1 && !self[x]) {
        int u = SCC[x][0];
        for (int j = T - t[u]; j >= 0; -- j) {
          dp[x][j + t[u]] = max(dp[x][j + t[u]], dp[x][j] + p[u]);
        }
      }
      else update(x);
      for (auto &y : SCCG[x]) {
        for (int i = 0; i <= T; ++ i) {
          dp[y][i] = max(dp[y][i], dp[x][i]);
        }
        if (-- deg[y] == 0) Q.push(y);
      }
    }
    int ret = 0;
    for (int i = 0; i < scc_cnt; ++ i) {
      for (int j = 0; j <= T; ++ j) {
        ret = max(ret, dp[i][j]);
      }
    }
    return ret;
  }
}
int main() {
  while (scanf("%d%d%d", &N, &M, &T) == 3 && N) {
    for (int i = 0; i < N; ++ i) {
      G[i].clear(); mark[i] = false;
      scanf("%d%d%d", p + i, t + i, k + i);
    }
    for (int i = 0; i < M; ++ i) {
      int u, v; scanf("%d%d", &u, &v);
      -- u, -- v; G[u].push_back(v);
      if (u == v) mark[u] = true;
    }
    printf("%d\n", SCC::solve());
  }
  return 0;
}

Measured memory_bytes: 5364
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<math.h>
#define N 1000
int main(){
	int i,j,k,len,mark;
	char a[105];
	char b[105];
	char c[105];
	while(scanf("%s %s",a,b)!=EOF){
		len=strlen(a);
		for(i=0;i<len;i++){
			mark=0;
			c[0]=a[len-1];
			for(k=0,j=1;k<len-1;j++,k++)
			    c[j]=a[k];
		    c[len]='\0';	    
			for(k=0;k<len;k++){
				a[k]=c[k];
				if(a[k]==b[k]) mark++;
			}   
	        if(mark==len) {
	     	break;
     	    }						
	   }
    if(mark==len) printf("Yes\n");
    else printf("No\n");
}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int n;
string s="a";
void dfs(char a){
    if(s.size()==n) {cout<<s<<endl;return;}
    for(char c='a';c<=char(a+1);c++){
        s+=c;
        dfs(max(c,a));
        s.erase(s.end()-1);
    }
}

int main(){
    cin>>n;
    dfs('a');
}


Measured memory_bytes: 1536
#include <iostream>
#include <fstream>
#include <iomanip>

#include <vector>
#include <set>
#include <bitset>
#include <map>
#include <deque>
#include <string>

#include <algorithm>
#include <numeric>
#include <random>

#include <cstdio>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>

using namespace std;

#define forn(i, n) for (ll i = 0; i < (ll) (n); ++i)
#define sz(a) static_cast<int>((a).size())
#define endl '\n'

using ll = long long;

const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(1e6) + 17;

int n;
ll k;
string s;

bool read() {
    if (!(cin >> s >> k))
        return false;

    return true;
}

void solve() {
    n = sz(s);

    forn (i, n)
        if (s[i] == '1') {
            --k;

            if (k == 0) {
                cout << 1 << endl;
                return ;
            }
        } else {
            cout << s[i] << endl;
            return ;
        }
}

int main() {
    cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >>n;
  vector<int>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  int kotae=0;
  vector<int> iro(9,0);
  for(int i=0;i<n;i++){
    if(a[i]<400){
      iro[0]=1;
    }else if(a[i]<800){
      iro[1]=1;
    }else if(a[i]<1200){
      iro[2]=1;
    }else if(a[i]<1600){
      iro[3]=1;
    }else if(a[i]<2000){
      iro[4]=1;
    }else if(a[i]<2400){
      iro[5]=1;
    }else if(a[i]<2800){
      iro[6]=1;
    }else if(a[i]<3200){
       iro[7]=1;
    }else {
      iro[8]++;
    }
  }
  for(int i=0;i<8;i++){
    kotae+=iro[i];
  }
  int saidai=kotae+iro[8];
  if(kotae==0&&iro[8]!=0){
    kotae=1;
  }
  cout<<kotae<<" "<<saidai<<endl;
}


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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li len[55];
li pat[55];

li solve(li n, li x, li now_p) {
    if (n == 0) {
        return now_p + 1;
    }
    if (x <= 1) {
        return now_p;
    }
    if (x == len[n]) {
        return now_p + pat[n];
    }
    const li mid = (len[n] + 1) / 2;
    if (x < mid) {
        return solve(n - 1, x - 1, now_p);
    }
    // for mid pat
    now_p += pat[n - 1] + 1;
    if (x == mid) {
        return now_p;
    }

    return solve(n - 1, x - mid, now_p);
}

int main() {
    len[0] = 1;
    pat[0] = 1;
    repp(i, 1, 55) {
        len[i] = len[i - 1] * 2 + 3;
        pat[i] = pat[i - 1] * 2 + 1;
    }
    li n, x;
    cin >> n >> x;
    cout << solve(n, x, 0) << endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    string N;
    cin >> N;
    int num = stoi(N);
    int *aN = new int[num];
    string a;
    int inNum;
    for(int i = 0; i < num; ++i)
    {
        cin >> a;
        inNum = stoi(a);
        aN[i] = inNum;
    }
    int result;
    int temp;
    int counter = 0;
    for(int i = -100; i <= 100; ++i)
    {
        for(int n = 0 ; n < num ; n++)
        {
            temp += (aN[n] - i)* (aN[n] -i);
        }
        if(counter == 0)
        {
            result = temp;
        }
        if(result > temp)
            result = temp;
        temp = 0;
        counter++;
    }
    cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MAXN = 1e2 + 5;
const int MAXK = 1e5 + 5;
const int MOD = 1e9 + 7;
int arr[MAXN];
int dp[MAXN][MAXK];
int sum[MAXN][MAXK];
int32_t main(){
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> arr[i];
    for(int i = 0; i < n; i++){
        dp[i][0] = 1;
        sum[i][0] = 1;
    }
    for(int j = 1; j <= k; j++){
        if(j <= arr[0]) dp[0][j] = 1;
        sum[0][j] = (dp[0][j] + sum[0][j - 1]) % MOD;
    }
    for(int i = 1; i < n; i++){
        for(int j = 1; j <= k; j++){
            if(j - arr[i] - 1 >= 0)
                dp[i][j] = ((sum[i - 1][j] - sum[i - 1][j - arr[i] - 1] + MOD)) % MOD;
            else
                dp[i][j] = (sum[i - 1][j])%MOD;
        }
        for(int j = 1; j <= k; j++){
            sum[i][j] = (MOD + dp[i][j] + sum[i][j - 1])%MOD;
        }
    }
    cout << (dp[n - 1][k]) % MOD << '\n';
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  ll sum = 0;
  ll ans = 0;
  rep(i, n) {
    if(a[i] == 0) {
      ans += sum/2;
      sum = 0;
    }
    else sum += a[i];
  }
  ans += sum/2;
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;

const double PI = 3.1415926535897932384626433832795;

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

int gcd(int x, int y) { return y ? gcd(y, x % y) : x; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
int lcm(int x, int y) { return x / gcd(x, y) * y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

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

	int n, t;
	cin >> n >> t;

	vector<int> a(n);
	for (auto &v : a) {
		cin >> v;
	}

	map<int, int> mp;
	int buy = INT_MAX;
	for (int i = 0; i < n; i++) {
		buy = min(buy, a[i]);
		mp[a[i] - buy]++;
	}

	cout << mp.rbegin()->second << endl;
	return 0;
}


Measured memory_bytes: 5376
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.Random;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;


public class Main {
	
	public static void main(String[] args) throws IOException {	
		try(final Scanner sc = new Scanner(System.in)){
			final long X = Math.abs(sc.nextLong());
			final long K = sc.nextLong();
			final long D = sc.nextLong();
			
			final long times = Math.abs(X) / D;
			if(times >= K) {
				System.out.println(X - D * K);
				return;
			}
			
			final long rest_times = K - times;
			if(rest_times % 2 == 0) {
				System.out.println(X - D * times);
			}else{
				System.out.println(D - (X - D * times));
			}
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
		

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}


Measured memory_bytes: 32740
#include <iostream>
#include <iomanip>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <numeric>
#include <bitset>
#include <cstdint>
#include <stdexcept>
using namespace std;

// 整数型

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

// [0,n)を昇順/降順でループ

#define rep(i, n) for (int i = 0; i < static_cast<int>(n); ++i)
#define repd(i, n) for (int i = static_cast<int>(n) - 1; i >= 0; --i)

// [a,b)を昇順/降順でループ

#define FOR(i, a, b) for (int i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define FORD(i, a, b) for (int i = static_cast<int>(b) - 1; i >= static_cast<int>(a); --i)

// デバッグ

#ifdef DEBUG
#include <cassert>
#define my_assert(x) assert(x)
#else
#define my_assert(x)
#define assert(x)
#endif

//////////////// //////////////// //////////////// //////////////// ////////////////
//////////////// //////////////// //////////////// //////////////// ////////////////

constexpr int max_exp = 40;

int main()
{
    // 高速な入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    // 浮動小数の表示の精度
    cout << setprecision(15);

    int n;
    cin >> n;
    i64 a1, a2, x = 0;
    cin >> a1 >> a2;
    rep(i, n - 2)
    {
        i64 b;
        cin >> b;
        x ^= b;
    }
    i64 s = a1 + a2;

    // dは非負整数
    if (s < x or ((s - x) & 1))
    {
        cout << "-1\n";
        return 0;
    }

    i64 d = (s - x) / 2;
    if (d > a1 or (d & x))
    {
        cout << "-1\n";
        return 0;
    }

    i64 y = 0;
    for (int e = max_exp; e >= 0; --e)
    {
        if (not ((x >> e) & 1))
        {
            continue;
        }
        if (d + y + (1LL << e) <= a1)
        {
            y += (1LL << e);
        }
    }

    if (d + y == 0)
    {
        cout << "-1\n";
        return 0;
    }
    cout << a1 - (d + y) << "\n";

    return 0;
}


Measured memory_bytes: 3556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define INF (1LL << 31)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "

int main()
{
    int h1, m1, h2, m2, k; cin >> h1 >> m1 >> h2 >> m2 >> k;

    int ans = 0;
    ans = (h2 - h1)*60 + m2 - m1 - k;

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
const int MOD = 1e9 + 7;

using P = pair<int, int>;
int main() {
    string A, B;
    cin >> A >> B;
    if ((int)A.size() < (int)B.size()) {
        cout << "LESS" << endl;
    } else if ((int)A.size() > (int)B.size()) {
        cout << "GREATER" << endl;
    } else {
        if (A < B) {
            cout << "LESS" << endl;
        } else if (A > B) {
            cout << "GREATER" << endl;
        } else {
            cout << "EQUAL" << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 2 * 1e5 + 5;
const ll mod = 998244353;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    int r;
    cin >> r;
    cout << fixed << setprecision(12) << 2.0 * acos(-1) * r << '\n';
    return 0;
}   

Measured memory_bytes: 3788
"use strict";

const main = arg => {
    const input = arg.trim().split("\n");

    const [N, K] = input[0].split(" ").map(el => parseInt(el));
    let d = []
    let A = []
    let s = new Array(N).fill(true)
    for(let i = 1; i<=K; i++){
        let tmp = input[2*i].split(" ").map(el => parseInt(el))
        for(let el of tmp){
            s[el-1] = false
        }
    }
    let cnt = 0
    for(let el of s){
        if(el === true) cnt++
    }
    console.log(cnt)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));  

Measured memory_bytes: 30392
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>

using namespace std;

const long long LINF = 1e18;
int n, m, p;
int edge[5100][3];
vector<int> side[2600][2];
bool path[2600][2];
long long score[2600];
long long ans;

void bfs1(int u) {
  path[u][0] = true;
  queue<int> q;
  q.push(u);
  while(q.size()) {
    for (int v: side[q.front()][0]) {
      if (path[v][0]) continue;
      q.push(v);
      path[v][0] = true;
    }
    q.pop();
  }
}

void bfs2(int v) {
  path[v][1] = true;
  queue<int> q;
  q.push(v);
  while(q.size()) {
    for (int u: side[q.front()][1]) {
      if (path[u][1]) continue;
      q.push(u);
      path[u][1] = true;
    }
    q.pop();
  }
}


int main()
{
  cin >> n >> m >> p;
  
  for (int i = 0; i < m; i++) {
    int a, b, c;
    cin >> a >> b >> c;
    edge[i][0] = a;
    edge[i][1] = b;
    edge[i][2] = c - p;
    side[a][0].push_back(b);
    side[b][1].push_back(a);
  }
  
  bfs1(1);
  bfs2(n);
  
  for (int i = 2; i <= n; i++) {
    score[i] = -LINF;
  }
  
  for (int loop = 0; loop < n; loop++) {
    for (int i = 0; i < m; i++) {
      int u = edge[i][0], v = edge[i][1], coins = edge[i][2];
      score[v] = max(score[v], score[u] + coins);
    }
  }
  
  ans = max(0LL, score[n]);
  
  for (int loop = 0; loop < n; loop++) {
    for (int i = 0; i < m; i++) {
      int u = edge[i][0], v = edge[i][1], coins = edge[i][2];
      if (score[v] < score[u] + coins) {
        score[v] = score[u] + coins;
        if (path[v][0] and path[v][1]) {
          ans = -1;
        }
      }
    }
  }
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 640
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: Bytes,
        k: usize,
    }

    let n = n.iter().map(|&c| (c - b'0') as usize).collect_vec();
    let l = n.len();

    let mut dp = vec![vec![vec![0; l]; k+1]; 2];
    dp[0][0] = vec![1; l];
    dp[0][0][l-1] = 0;
    dp[0][1][0] = n[0] - 1;
    dp[1][1][0] = 1;
    for i in 1..l {
        for j in 1..=k {
            dp[0][j][i] += dp[0][j-1][i-1] * 9;
            dp[0][j][i] += dp[0][j][i-1];
            if n[i] != 0 {
                dp[0][j][i] += dp[1][j-1][i-1] * (n[i] - 1);
                dp[0][j][i] += dp[1][j][i-1];
                dp[1][j][i] += dp[1][j-1][i-1];
            } else {
                dp[1][j][i] += dp[1][j][i-1];
            }
        }
    }
    println!("{}", dp[0][k][l-1] + dp[1][k][l-1]);
}


Measured memory_bytes: 2172
#include <algorithm>
#include <array>
#include <vector>
#include <iostream>
#include <fstream>
#include <string>
#include <cmath>
#include <functional>
#include <queue>

//AtCoderC++.cpp

using namespace std;

void Show(vector<vector<int>> Ns) {
	for (int i = 0; i < Ns.size(); i++) {
		for (int j = 0; j < Ns[i].size(); j++) {
			if (j == Ns[i].size() - 1) {
				cout << Ns[i][j] << endl;
			} else {
				cout << Ns[i][j] << ",";
			}			
		}
	}
}

void Show(vector<int> N) {
	for (int i = 0; i < N.size(); i++) {
		cout << N[i];
		if (i != N.size() - 1) {
			cout << " ";
		} else {
			cout << endl;
		}
	}
}


int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int Answer = 0;
	int sum;
	for (int i = 1; i <= N; i++) {
		sum = 0;
		int remain = i;
		for (int j = 0; j < 5; j++) {
			sum += remain / (int)pow(10, 4 - j);
			remain %= (int)pow(10, 4 - j);
		}
		if (A <= sum && sum <= B)Answer += i;
	}
	cout << Answer << endl;
}

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

#define int long long int

int32_t main()
{
    int n;
    cin>>n;
    int ans=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        while(x%2==0)ans++,x/=2;
    }
    cout<<ans<<endl;
}

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

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename Iterator>
string Join(const Iterator& cbegin, const Iterator& cend, const string& delim = "")
{
    ostringstream os;
    copy(cbegin, cend, ostream_iterator<string>(os, delim.c_str()));
    string str(os.str());
    if (!str.empty()) {
        str.erase(str.size() - delim.size());
    }
    return str;
}

bool matchWordsByUS(const string& str, vec1<string>& words)
{
    int   start = 0;
    regex ptn("_|$");
    for (sregex_iterator ite(str.cbegin(), str.cend(), ptn), end; ite != end; ++ite) {
        auto&&     m(*ite);
        const auto word(str.substr(start, m.position() - start));
        if (str == word) break;
        if (word.empty()) continue;
        words.push_back(word);
        start = m.position() + 1;  // マッチ箇所を含まない
    }
    return !words.empty();
}

bool matchWordsByCC(const string& str, vec1<string>& words)
{
    int   start = 0;
    regex ptn("[A-Z]|$");
    for (sregex_iterator ite(str.cbegin(), str.cend(), ptn), end; ite != end; ++ite) {
        auto&&     m(*ite);
        const auto word(str.substr(start, m.position() - start));
        if (word.empty()) continue;
        words.push_back(word);
        start = m.position();
    }
    return !words.empty();
}

void ConvUCC(vec1<string>& words)
{
    for (auto& word : words) {
        char& c(word.front());
        c = toupper(c);
    }
}

void ConvLCC(vec1<string>& words)
{
    for (auto ite(words.begin()); ite != words.end(); ++ite) {
        char& c(ite->front());
        if (ite == words.begin()) {
            c = tolower(c);
        }
        else {
            c = toupper(c);
        }
    }
}

void ConvUS(vec1<string>& words)
{
    for (auto& word : words) {
        char& c(word.front());
        c = tolower(c);
    }
}

int main()
{
    while (true) {
        const auto N(cin2var<string>());
        const auto T(cin2var<string>());
        const char t(T.front());
        if (t == 'X') break;
        vec1<string> words;
        matchWordsByUS(N, words) || matchWordsByCC(N, words);
        switch (t) {
        case 'U':
            ConvUCC(words);
            cout << Join(words.cbegin(), words.cend()) << endl;
            break;
        case 'L':
            ConvLCC(words);
            cout << Join(words.cbegin(), words.cend()) << endl;
            break;
        case 'D':
            ConvUS(words);
            cout << Join(words.cbegin(), words.cend(), "_") << endl;
            break;
        default:
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 3244
#pragma GCC optimize(1)
#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include<cstdio>
#include<queue>
#include<vector>
using namespace std;
priority_queue <long long,vector<long long> > q;
long long n,m,x,num,ans=0;
inline int read(){
	char ch=getchar();
	int x=0,f=1;
	while(ch<'0' || ch>'9')	{if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		x=read();
		q.push(x);
	}
	for(int i=1;i<=m;i++){
		num=q.top()/2;
		q.pop();
		q.push(num);
	}
	while(!q.empty()){
		ans+=q.top();
		q.pop();
	}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 1400
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int m;
	cin >> m;
	for (int z = 0; z < m; z++) {
		int x3, y3, w, h, x1, x2, y1, y2, n;
		cin >> x3 >> y3 >> w >> h;
		x1 = x3;
		y1 = y3 + h;
		x2 = x3 + w;
		y2 = y3;
		int sum = 0;
		cin >> n;
		for (int i = 0; i < n; i++) {
			int x, y;
			cin >> x >> y;
			if (x >= x1&&x <= x2&&y <= y1&&y >= y2)
				sum++;
		}
		cout << sum << endl;
	}
}

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

int main() {
  
  int N, K;
  int sum = 0;
  cin >> N >> K;

  for(int i = 0; i < N; i++){
        
        int x;
        cin >> x;
        if( x < K - x )
          sum += 2*x;
        else
          sum += 2*(K-x);
  }

  cout << sum << endl;

}



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

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

    vector<bool> safe(N+1, true);
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;

        safe[a] = false;
    }

    const long long mod = (1E9) + 7;
    vector<long long> dp(N + 5, 0);
    dp[0] = 1;
    for (int i = 0; i < N + 1; i++) {
        if (safe[i] == false)
            continue;

        for (int j = 0; j < 2; j++) {
            dp[i + j + 1] += dp[i];
            dp[i + j + 1] %= mod;
        }
    }

    cout << dp[N] << endl;

    return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A[] = new long[N];
		long sum = 0;
		for (int i=0;i<N;i++) {
			A[i] = sc.nextLong();
			sum +=A[i];
		}
		long min = Long.MAX_VALUE;
		long front= 0;
		for (int i=0;i<N;i++) {
			front +=A[i];
			if (Math.abs(sum - 2*front)<min) {
				min = Math.abs(sum - 2*front);
			}
		}
		System.out.println(min);
	}
}


Measured memory_bytes: 61332
#include<bits/stdc++.h>
#define lson (o<<1)
#define rson (o<<1|1)
#define fi first
#define sc second
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
using namespace std;
const double pi=acos(-1);
const double eps=1e-6;
inline int lowbit(int x){return x&(-x);}
inline int read(){
	int f=1,x=0;char ch;
	do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
	do{x=x*10+ch-'0';ch=getchar();}while(ch>='0'&&ch<='9');
	return f*x;
}
template<typename T> inline T max(T x,T y,T z){return max(max(x,y),z);}
template<typename T> inline T min(T x,T y,T z){return min(min(x,y),z);}
template<typename T> inline T sqr(T x){return x*x;}
template<typename T> inline void checkmax(T &x,T y){x=max(x,y);}
template<typename T> inline void checkmin(T &x,T y){x=min(x,y);}
template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');
do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}
template<typename A,typename B,typename C> inline A fpow(A x,B p,C yql){
	A ans=1;
	for(;p;p>>=1,x=1LL*x*x%yql)if(p&1)ans=1LL*x*ans%yql;
	return ans;
}
struct FastIO{
	static const int S=1310720;
	int wpos;char wbuf[S];
	FastIO():wpos(0){}
	inline int xchar(){
		static char buf[S];
		static int len=0,pos=0;
		if(pos==len)pos=0,len=fread(buf,1,S,stdin);
		if(pos==len)return -1;
		return buf[pos++];
	}
	inline int read(){
		int c=xchar(),x=0;
		while(c<=32&&~c)c=xchar();
		if(c==-1)return -1;
		for(;'0'<=c&&c<='9';c=xchar())x=x*10+c-'0';
		return x;
	}
}io;
//#define read io.read
int main()
{
	int n;
	cin >> n;
	double x[n+1],s=0;
	string u;
	for(int i=1;i<=n;i++)
	{
		cin >> x[i] >> u;
		if(u=="JPY") s+=x[i];
		if(u=="BTC") s+=x[i]*380000;
	}
	cout << s;
	return 0;
}



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

typedef long long ll;

#define p_ary(ary,a,b,i) do { cout << "["; for (int (i) = (a);(i) < (b);++(i)) cout << ary[(i)] << ((b)-1 == (i) ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,m,q;
    cin >> n >> m;
    vector<int> color(n,0),dist(n,-1);
    vector<vector<int>> edges(n);
    for (int i = 0;i < m;++i) {
        int u,v;
        cin >> u >> v;
        u--;v--;
        edges[u].push_back(v);
        edges[v].push_back(u);
    }
    cin >> q;
    vector<int> v(q),d(q),c(q);
    for (int i = 0;i < q;++i) cin >> v[i] >> d[i] >> c[i];
    for (int i = q-1;i >= 0;--i) {
        v[i]--;
        stack<int> st;
        if (color[v[i]] == 0) color[v[i]] = c[i];
        if (dist[v[i]] < d[i]) {
            st.push(v[i]);
            dist[v[i]] = d[i];
        }
        while (!st.empty()) {
            int t = st.top();
            st.pop();
            if (color[t] == 0) color[t] = c[i];
            if (dist[t] != 0) for (int j : edges[t]) {
                if (dist[j] < dist[t]-1) {
                    dist[j] = dist[t]-1;
                    st.push(j);
                }
            }
        }
    }
    for (int i : color) printf("%d\n", i);
    return 0;
}

Measured memory_bytes: 8824
#include "bits/stdc++.h"
using namespace std;

int main() {
	int N, Z, W, A[2000];
	cin >> N >> Z >> W;
	for (int i = 0; i < N; i++) cin >> A[i];
	if (N == 1) cout << abs(A[0] - W);
	else cout << max(abs(A[N - 1] - W), abs(A[N - 2] - A[N - 1]));
}

Measured memory_bytes: 256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 

//result = Math.pow(num1, num3)
//StringBuffer str = new StringBuffer(hoge1);
//String hoge2 = str.reverse().toString();
//map.containsKey(A)

//Map<String, Integer> map = new HashMap<String, Integer>(n);
/*for ( キーのデータ型 key : マップの名前.keySet() ) {
	データのデータ型 data = マップの名前.get( key );
	
	// keyやdataを使った処理;
}*/
//int i = Integer.parseInt(s);
//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
//ArrayList<String> cc = new ArrayList<>(n);
//Collections.sort(list);
//Array.sort(list);
//Arrays.asList(c).contains("a")
//list.set(1,"walk");
public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static Scanner sc = new Scanner(System.in);
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	static int K;
	public static void main(String[] args) {
		int H=sc.nextInt();int W=sc.nextInt();
		int v[][]=new int[H][W];
		String tmp;
		int ctn=0;
		for(int a=0;a<H;a++) {
			tmp=sc.next();
			for(int b=0;b<W;b++) {
				v[a][b]=tmp.charAt(b);
				if(v[a][b]==46) {
					ctn++;
				}
			}
		}
		//# 35 . 46
		Queue<Integer> q1=new ArrayDeque<>();
		Queue<Integer> q2=new ArrayDeque<>();
		Queue<Integer> q3=new ArrayDeque<>();
		for(int a=0;a<H;a++) {
			for(int b=0;b<W;b++) {
				if(v[a][b]==35) {
					q1.add(a);
					q2.add(b);
					q3.add(0);
				}
			}
		}
		int x,y,i;
		int ans=0;
		while(q1.peek()!=null) {
			x=q1.poll();
			y=q2.poll();
			i=q3.poll()+1;
			//p("FIRST"+"      "+x+" "+y);
				for(int b=0;b<4;b++) {
				//	p("b"+b);
					if(x+a1[b]>=0&&y+b1[b]>=0) {
						if(x+a1[b]<H&&y+b1[b]<W) {
						if(v[x+a1[b]][y+b1[b]]==46) {
							q1.add(x+a1[b]);
							q2.add(y+b1[b]);
							q3.add(i);
							ans=Math.max(ans, i);
							v[x+a1[b]][y+b1[b]]=35;
						}
						}
					}
				}
			
		}

		p(ans);
		
		
		
	}	
}


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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'
#define rep(i,n) for(int_fast32_t i = 0; i < ((int_fast32_t)(n)); i++)   // 0-indexed up
#define rep1(i,n) for(int_fast32_t i = 1; i <= ((int_fast32_t)(n)); i++) // 1-indexed up
#define rrep(i,n) for(int_fast32_t i = ((int_fast32_t)(n)-1); i >= 0; i--)  // 0-indexed down
#define rrep1(i,n) for(int_fast32_t i = ((int_fast32_t)(n)); i >= 1; i--)   // 1-indexed down
#define all(x) (x).begin(),(x).end()

using namespace std;

template<typename T>
using vec = vector<T>;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using ll = long long;
using ld = long double;
using vi = vec<int_fast32_t>;
using vl = vec<int_fast64_t>;
using vld = vec<ld>;
using vii = vec<vi>;
using PII = pair<int_fast32_t, int_fast32_t>;

template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<class T,class U> inline bool chmax(T &a, const U &b){if(a<b){a=b;return 1;}return 0;}
template<class T,class U> inline bool chmin(T &a, const U &b){if(a>b){a=b;return 1;}return 0;}

const ld Pi = std::acos(-1.0L);
constexpr ll infll = (1LL<<62)-1;
constexpr int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int START_TIME = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
//    cout << fixed << setprecision(15);

    i32 n; cin >> n;
    vi a(1e5+5);
    rep(i,n) {
        i32 tmp;
        cin >> tmp;
        a[tmp]++;
    }

    i64 s = 0;
    rep(i, a.size()) s += a[i] * i;

    i32 q; cin >> q;
    rep(_, q) {
        i32 b,c;
        cin>>  b >> c;
        if(a[b] != 0) {
            s += (-b*a[b] + c*a[b]);
            a[c] += a[b];
            a[b] = 0;
        }
        cout << s << '\n';
    }


    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-START_TIME)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 4048
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define max(p,q) ((p)>(q)?(p):(q))
#define min(p,q) ((p)<(q)?(p):(q))
#define chmax(a,b) ((a)=(a)>(b)?(a):(b))
#define chmin(a,b) ((a)=(a)<(b)?(a):(b))
#define abs(p) ((p)>=(0)?(p):(-(p)))
#define MOD 1000000007
ll powll(ll a,ll b){ll r=1;rep(i,b){r*=a;}return r;}
#define swap(a,b) do{ll w=(a);(a)=(b);(b)=w;}while(0)
#define swapd(a,b) do{double w=(a);(a)=(b);(b)=w}while(0)
#define in(a) scanf("%lld", &(a))
#define in2(a,b) scanf("%lld %lld",&(a),&(b))
#define in3(a,b,c) scanf("%lld %lld %lld",&(a),&(b),&(c))
#define ind(a) scanf("%lf", &(a))
#define ins(a) scanf("%s", (a))
#define put(a) printf("%lld\n", (a))
#define putd(a) printf("%.15f\n", (a))
//      puts(a) printf("%s\n", a) 文字はこっち
//your code here!
int cmp(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? 1:-1;//昇順ソート 1,2,....9
}
int cmp2(const void *a, const void *b){
    ll A=*(ll *)a, B=*(ll *)b;
    if(A==B)return 0;
    else return A>B ? -1:1;//降順
}

int main(void){
    ll snum[101], tnum[101];
    char s[101], t[101];
    ins(s); ins(t);
    ll N=strlen(s);
    rep(i, N) snum[i] = s[i] - 'a';
    qsort(snum, N, sizeof(ll), cmp);
    rep(i, N) s[i] = 'a' + snum[i];
    N=strlen(t);
    rep(i, N) tnum[i] = t[i] - 'a';
    qsort(tnum, N, sizeof(ll), cmp2);
    rep(i, N) t[i] = 'a' + tnum[i];
    if(strcmp(s,t) < 0) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 128
//author:emre yazicioglu

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
#define fori(a,b,c) for(ll a = b;a < ll(c);a++)
#define ford(a,b,c) for(ll a = b;a >= ll(c);a--)
#define pb push_back

const int N = 2e6 + 7;
ll n,m,k,ans,cur,ar[N];
ll sum,a,b,c,d;
string str;
vector<ll> v;

int main(){

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

	// freopen("../in.txt","r",stdin);
	// freopen("../out.txt","w",stdout);
	string s;
	cin >> n >> s;
	if(n < 3200) cout << "red";
	else cout << s;




}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dwn(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int maxn=105;
const int maxm=7000010;
int f[maxm];
int n,m,x,y,S1[maxn][maxn],S2[maxn][maxn];
int id(int i,int j,int k,int l) {return ((i*(n-x+1)+j)*y+k)*(m-y+1)+l+1;}
int sumx(int k,int l,int r) {return S2[k][r]-S2[k][l-1];}
int sumy(int k,int l,int r) {return S1[r][k]-S1[l-1][k];}
void relax(int& x,int y) {if(x<y) x=y;}
char M[maxn][maxn];
int main() {
	scanf("%d%d",&n,&m);
	rep(i,1,n) scanf("%s",M[i]+1);
	rep(i,1,n) rep(j,1,m) {
		if(M[i][j]=='E') x=i,y=j;
		else if(M[i][j]=='o') S1[i][j]=S2[i][j]=1;
	}
	rep(i,1,n) rep(j,1,m) S1[i][j]+=S1[i-1][j],S2[i][j]+=S2[i][j-1];
	int ans=0;
	rep(u,0,x-1) rep(d,0,n-x) rep(l,0,y-1) rep(r,0,m-y) {
		int res=f[id(u,d,l,r)];ans=max(ans,res);
		if(u!=x-1) relax(f[id(u+1,d,l,r)],res+(x-u-1>d?sumx(x-u-1,max(y-l,r+1),min(y+r,m-l)):0));
		if(d!=n-x) relax(f[id(u,d+1,l,r)],res+(x+d+1<=n-u?sumx(x+d+1,max(y-l,r+1),min(y+r,m-l)):0));
		if(l!=y-1) relax(f[id(u,d,l+1,r)],res+(y-l-1>r?sumy(y-l-1,max(x-u,d+1),min(x+d,n-u)):0));
		if(r!=m-y) relax(f[id(u,d,l,r+1)],res+(y+r+1<=m-l?sumy(y+r+1,max(x-u,d+1),min(x+d,n-u)):0));
	}
	printf("%d\n",ans);
	return 0;
}

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

class Sensha{
public:
  int x;
  int y;
  int dir;
};

int main() {
  int T;
  cin >> T;
  for(int t = 0; t < T; t++) {
    if(t != 0) cout << endl;
    int H, W;
    cin >> H >> W;
    char data[H][W];
    Sensha s;
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
	cin >> data[i][j];
	switch(data[i][j]) {
	case '^':
	  data[i][j] = '.';
	  s.x = j;
	  s.y = i;
	  s.dir = 3;
	  break;
	case '>':
	  data[i][j] = '.';
	  s.x = j;
	  s.y = i;
	  s.dir = 0;
	  break;
	case 'v':
	  data[i][j] = '.';
	  s.x = j;
	  s.y = i;
	  s.dir = 1;
	  break;
	case '<':
	  data[i][j] = '.';
	  s.x = j;
	  s.y = i;
	  s.dir = 2;
	  break;
	}
      }
    }

    int N;
    cin >> N;
    int d[4][2] = {{1,0}, {0,1},{-1,0},{0,-1}};
    for(int i = 0; i < N; i++) {
      char c;
      cin >> c;
      bool zenshin = false;
      switch(c) {
      case 'U':
	s.dir = 3;
	zenshin = true;
	break;
      case 'D':
	s.dir = 1;
	zenshin = true;
	break;
      case 'L':
	s.dir = 2;
	zenshin = true;
	break;
      case 'R':
	s.dir = 0;
	zenshin = true;
	break;
      case 'S':
	for(int l = 1; ; l++) {
	  int bx = s.x + l*d[s.dir][0];
	  int by = s.y + l*d[s.dir][1];
	  if(bx < 0 || bx >= W) break;
	  if(by < 0 || by >= H) break;
	  if(data[by][bx] == '*') {
	    data[by][bx] = '.';
	    break;
	  }
	  if(data[by][bx] == '#') break;
	}
	break;
      }
      if(zenshin) {
	int nx = s.x + d[s.dir][0];
	int ny = s.y + d[s.dir][1];
	if(nx < 0 || nx >= W) continue;
	if(ny < 0 || ny >= H) continue;
	if(data[ny][nx] == '.') {
	  s.x = nx;
	  s.y = ny;
	}
      }
    }

    switch(s.dir) {
    case 0:
      data[s.y][s.x] = '>';
      break;
    case 1:
      data[s.y][s.x] = 'v';
      break;
    case 2:
      data[s.y][s.x] = '<';
      break;
    case 3:
      data[s.y][s.x] = '^';
      break;
    }
    for(int i = 0; i < H; i++) {
      for(int j = 0; j < W; j++) {
	cout << data[i][j];
      }
      cout << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 0
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,a,b) for (int i = a; i < (b); ++i)
#define all(x) (x).begin(),(x).end()
#define YY cout << "Yes" << endl
#define NN cout << "No" << endl
const int INF = 1000000007;
typedef long long ll;
using namespace std;
using Graph = vector<vector<int>>;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a,b); }
int solve(){
  ll a,b,c;
  cin >> a >> b >> c;
  REP(i,1,1e6){
    if((i * a) % b == c){
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
  return 0;
}
int main(){
  // ios::sync_with_stdio(false);cin.tie(nullptr);
  // cout << fixed;cout << setprecision(16) << endl; 
  solve();
  return 0;
} 

Measured memory_bytes: 256