akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define ll long long
#define lson (rt<< 1)
#define rson (rt<< 1 | 1)
#define gmid ((l+r)>> 1 )
using namespace std;

const int maxn=20000050;
ll r,c,n,a[5000][5000],dp[4000][4000][5]; 

int main()
{
	cin>>r>>c>>n;
	for(int i=1;i<=n;++i)
	  {
	  	  int x,y,z;
	  	  cin>>x>>y>>z;
	  	  a[x][y]=z;
	  }
    for(int i=1;i<=r;++i) 
      {
      	  for(int j=1;j<=c;++j)
    	    {
      	    	if(j==1)
      	    	{
      	    		dp[i][j][3]=dp[i-1][j][3]+a[i][j];
      	    		dp[i][j][2]=dp[i-1][j][3]+a[i][j];
      	    		dp[i][j][1]=dp[i-1][j][3]+a[i][j];
      	    		dp[i][j][0]=dp[i-1][j][3];
      	    		continue;
      	    	}
      	    	dp[i][j][0]=max(dp[i-1][j][3],dp[i][j-1][0]);
      	    	for(int k=1;k<=3;++k)
      	    	{
      	    		dp[i][j][k]=max(dp[i][j-1][k],dp[i][j-1][k-1]+a[i][j]);
      	    		dp[i][j][k]=max(dp[i][j][k],dp[i-1][j][3]+a[i][j]);
      	    	}
      	    }
      }
      cout<<dp[r][c][3]<<endl;
}


Measured memory_bytes: 447416
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
struct fast_ios { fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; } fast_ios_;
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define Sort(v) sort(v.begin(), v.end())
#define Reverse(v) reverse(v.begin(), v.end())
#define all(v) v.begin(),v.end()
#define SZ(v) ((int)v.size())
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
#define bit(n) (1LL<<(n))
#define debug(x) cout << #x << "=" << x << endl;
#define vdebug(v) { cout << #v << "=" << endl; REP(i_debug, v.size()){ cout << v[i_debug] << ","; } cout << endl; }
#define mdebug(m) { cout << #m << "=" << endl; REP(i_debug, m.size()){ REP(j_debug, m[i_debug].size()){ cout << m[i_debug][j_debug] << ","; } cout << endl;} }
#define pb push_back
#define fi first
#define se second
#define int long long
#define INF 1000000000000000000
template<typename T> istream &operator>>(istream &is, vector<T> &v){ for (auto &x : v) is >> x; return is; }
template<typename T> ostream &operator<<(ostream &os, vector<T> &v){ for(int i = 0; i < v.size(); i++) { cout << v[i]; if(i != v.size() - 1) cout << endl; }; return os; }
template<typename T1, typename T2> ostream &operator<<(ostream &os, pair<T1, T2> p){ cout << '(' << p.first << ',' << p.second << ')'; return os; }
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void chOut(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }

using vec = vector<int>;
using mat = vector<vec>;
using Pii = pair<int, int>;
using v_bool = vector<bool>;
using v_Pii = vector<Pii>;

//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//char d[4] = {'D','R','U','L'};

const int mod = 1000000007;
//const int mod = 998244353;



signed main(){

    int N; cin >> N;
    mat D(N, vec(2));
    REP(i, N) cin >> D[i][0] >> D[i][1];

    bool ans = false;
    REP(i, N - 2){
        if(D[i][0] == D[i][1] && D[i + 1][0] == D[i + 1][1] && D[i + 2][0] == D[i + 2][1]) ans = true;
    }
    chOut(ans, "Yes", "No");

    return 0;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define INF 2e9
typedef long long ll;
typedef pair<int, int> P;

int main() {
    int n; cin >> n;
    vector<int> h(n);
    rep(i, n) cin >> h[i];

    rep(i, n-1) {
        //if (h[i] >= h[i+1]) {
        if (i == 0 || h[i-1] < h[i]) h[i]--;
            if (i == 0) {
                if (h[i] > h[i+1]) {
                    cout << "No" << endl;
                    return 0;
                }
            }
            else if (h[i] > h[i+1] || h[i-1] > h[i]) {
                cout << "No" << endl;
                return 0;
            }
        //}
    }

    cout << "Yes" << endl;

}

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

typedef long long lint;
typedef long double louble;

template<typename T1,typename T2> inline T1 max(T1 a,T2 b){return a<b?a:b;}
template<typename T1,typename T2> inline T1 min(T1 a,T2 b){return a<b?b:a;}

namespace ae86
{
	const int bufl = 1<<15;

	char buf[bufl],*s=buf,*t=buf;

	inline int fetch()
	{
		if(s==t){t=(s=buf)+fread(buf,1,bufl,stdin);if(s==t)return EOF;}
		return *s++;
	}

	inline int ty()
	{
		int a=0,b=1,c=fetch();
		while(!isdigit(c))b^=c=='-',c=fetch();
		while(isdigit(c))a=a*10+c-48,c=fetch();
		return b?a:-a;
	}
}
using ae86::ty;

const int _ = 200007;

int n,H,W;
vector<int> los[_];

int main()
{
	H=ty(),W=ty(),n=ty();
	for(int i=1,a,b;i<=n;i++)a=ty(),b=ty(),los[a-1].emplace_back(b-1);
	for(int i=1,now=0;i<H;i++)
	{
		sort(los[i].begin(),los[i].end());
		if(los[i].empty() || los[i][0]>now+1)now++;
		else if(los[i][0]<=now){printf("%d\n",i);return 0;}
	}
	printf("%d\n",H);

	return 0;
}


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

using namespace std;

#define int long long
#define PB push_back
typedef pair<int, int> pii;
static const int INF = 1LL<<61;
 
inline double dis(pii &p1, pii &p2) {
  double a = abs(p1.first - p2.first), b = abs(p1.second - p2.second);
  return sqrt(a * a + b * b);
}

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

  int n;

  while (cin >> n, n) {
    pii ps[3005];
    for (int i = 0; i < n; ++i) {
      int x, y;
      cin >> x >> y;
      ps[i] = pii(x, y);
    }
    sort(ps, ps + n);

    int res = 0;
    for (int i = 0; i < n; ++i) {
      for (int j = i + 1; j < n; ++j) {
	if (i == j) continue;
	for (int k = -1; k < 2; k += 2) {
	  int dx = k * abs(ps[i].second - ps[j].second), dy = k * abs(ps[i].first - ps[j].first);
	  bool flg = false;
	  pii temp[2] = {pii(ps[i].first + dx, ps[i].second + dy), pii(ps[j].first + dx, ps[j].second + dy)};

	  for (int i2 = 0; i2 < 2;  ++i2) {
	    int l = 0, r = n;
	    while (1 <= r - l) {
	      int cur = (l + r) / 2;
	      if (ps[cur] == temp[i2]) {
		goto end;
	      }

	      if (ps[cur] < temp[i2]) l = cur + 1;
	      else r = cur;
	    }
	    flg = true;
	  end:;
	  }

	  if (flg) continue;

	  double seg = dis(ps[i], ps[j]);
	  res = max(res, (long long) (seg * seg + 0.00000001));
	}
      }
    }

    cout << res << endl;
  }
  
  return 0;
}

Measured memory_bytes: 1240
import java.io.*;
import java.util.*;

class Main{
    public static void main(String[] args){
	BufferedReader sc=new BufferedReader(new InputStreamReader(System.in));
	try {
	    while(true){
		int n = Integer.valueOf(sc.readLine()), sum = 0;
		if(n==0)
		    break;
		for(int i=0; i<n/4; i++)
		    sum+=Integer.valueOf(sc.readLine());
		System.out.println(sum);
	    }
	}catch(Exception e){
	    System.out.println("Error");
	}
    }
}

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

using namespace std;

#define fi first
#define se second
#define eb emplace_back
#define mt make_tuple
#define all(x) (x).begin(), (x).end() 
#define MOD 1000000007

typedef long long ll;
typedef pair <int, int> ii;
typedef pair <ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef long double ld;

const ll INF=LLONG_MAX;
const int mxn=1e5+5;
int a[mxn];
ll sum=0;
map<int,int>mp;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    //freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
	int n; cin >> n;
	for(int i=0; i<n; i++){
		cin >> a[i];
		sum += a[i];
		mp[a[i]]++;
	}
	int q; cin >> q;
	while(q--){
		int prev, now;
		cin >> prev >> now;
		int dx = now-prev;
		int cnt = mp[prev];
		mp[prev]=0;
		sum += dx*cnt;
		mp[now]+=cnt;
		cout << sum << '\n';
	}
}
	
// READ & UNDERSTAND
// ll, int overflow, array bounds, memset(0)
// special cases (n=1?), n+1 (1-index)
// do smth instead of nothing & stay organized
// WRITE STUFF DOWN


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

int main() {
    int n, m; cin >> n >> m;
    string s; cin >> s;
    vector<vector<int>> g(n);
    for(int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        g[a - 1].push_back(b - 1);
        g[b - 1].push_back(a - 1);
    }

    vector<vector<int>> cnt(n, vector<int>(2));
    vector<bool> removed(n);
    queue<int> que;
    for(int v = 0; v < n; ++v) {
        for(auto to : g[v]) {
            cnt[v][s[to] == 'B'] += 1;
        }
        if(cnt[v][0] == 0 || cnt[v][1] == 0) {
            que.push(v);
            removed[v] = true;
        }
    }
    while(!que.empty()) {
        const int v = que.front();
        que.pop();
        for(auto to : g[v]) {
            if(removed[to]) continue;
            cnt[to][s[v] == 'B'] -= 1;
            if(cnt[to][s[v] == 'B'] == 0) {
                que.push(to);
                removed[to] = true;
            }
        }
    }

    if(find(begin(removed), end(removed), false) != end(removed)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 21124
# from scipy.sparse.csgraph import floyd_warshall
import itertools


def warshal_floyd(d):
    # d[i][j] := iからjへの最短距離
    for k in range(N):
        for i in range(N):
            for j in range(N):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    # "今現在求まっているiからjへの最短距離"と"今現在求まっているiからkへの最短距離 + 今現在求まっているkからjへの最短距離 の和"を比較する
    return d


N, M, R = map(int, input().split())  # N個の町, M本の道, R個の町を訪れることになった
town = list(map(lambda x: int(x)-1, input().split()))
distant = [[float('inf')]*N for _ in range(N)]
for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    distant[a][b] = c
    distant[b][a] = c
for i in range(N):
    distant[i][i] = 0

warshal_floyd(distant)
# print(distant)  # Rは最大8だから全てを試しても大丈夫
ans = 10**9
for x in itertools.permutations(town):
    x = list(x)
    now = x[0]
    tmp = 0
    for i in range(1, len(x)):
        tmp += distant[now][x[i]]
        now = x[i]
    ans = min(ans, tmp)
print(ans)


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

void solve() {
    int N, C;
    cin >> N >> C;
    int D[C][C], c[N][N];
    for (int i = 0; i < C; i++) {
        for (int j = 0; j < C; j++) {
            cin >> D[i][j];
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            cin >> c[i][j];
            c[i][j] -= 1;
        }
    }
    //s[i][j] (x+y)%3=iのマスをjに塗り替えた時のDの和
    int s[3][C];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < C; j++) {
            s[i][j] = 0;
        }
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            for (int k = 0; k < C; k++) {
                s[(i + j) % 3][k] += D[c[i][j]][k];
                //cout << i << " " << " " << j << " " << k << " " << s[(i + j) % 3][k] << endl;
            }
        }
    }
    int ans = 1e9;
    for (int i = 0; i < C; i++) {
        //cout << i << " " << s[0][i] << endl;
        for (int j = 0; j < C; j++) {
            if (i == j) continue;
            for (int k = 0; k < C; k++) {
                if (i == k || j == k) continue;
                ans = min(ans, s[0][i] + s[1][j] + s[2][k]);
                //cout << i << " " << " " << j << " " << k << " " << ans << endl;
            }
        }
    }
    cout << ans << endl;
    return;
}

int main() {
    solve();
}

Measured memory_bytes: 1280
s = str(input())
t = str(input())

ans_ind = -1
for i in range(len(s)-len(t)+1):
    for j in range(0,len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            pass
        else:
            break
    else:
        ans_ind = i

if ans_ind == -1:
    print('UNRESTORABLE')
else:
    ans = ''
    for i in range(len(s)):
        if ans_ind <= i < ans_ind + len(t):
            ans += t[i-ans_ind]
        else:
            if s[i] == '?': ans += 'a'
            else: ans += s[i]
    print(ans)

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

int main(){
	int n;
	static bool c[1000000]={true};
	static int t[1000000];t[0] = 0;
	for(int i = 2;i < 1000000;i++){
		for(int j = 2;i*j < 1000000;j++){
			c[i*j] = true;
		}
		t[i]=t[i-1]+!c[i];
	}
	for(int n;cin>>n;n++){
		cout << t[n] << endl;
	}
	return 0;
}

Measured memory_bytes: 7964
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        n: usize,
    }

    let mut prev =-1_i64;
    let mut curr = 2_i64;
    for _ in 1..=n {
        let tmp = curr;
        curr += prev;
        prev = tmp;
    }
    println!("{}", curr);

}


Measured memory_bytes: 2108
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#define int long
#define ll long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define IOS cin.tie(0); ios::sync_with_stdio(false)
const int INF = 1e9;
using namespace std;

signed main() {
    int N; cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];
    int ans=0;
    sort(L.begin(),L.end());
    for(int i=0;i<N-1;i++){
        for(int j=i+1;j<N;j++){
            int a=lower_bound(L.begin(),L.end(),L[i]+L[j])-L.begin();
            if(a-j-1>0) ans+=a-j-1;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
//
//AtCoder Beginner Contest 125
//D
//https://atcoder.jp/contests/abc125/tasks/abc125_d
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <ctime>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <functional>
#include <cassert>
#include <bitset>
#include <numeric>

using namespace std;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SIZE(x) (int)(x).size()
#define SIZEL(x) (ll)(x).size()
#define MSG(a) cout << #a << " " << a << endl;

using ll = long long;
using ld = long double;
using Graph = vector<vector<int>>;

const double PI = 3.14159265358979323846;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }    //最大公約数
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }            //最小公倍数

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

    vector<int> a(n);
    
    int mCnt=0;
    int mMax=1e9*-1;
    int pMin=1e9;
    REP(i, n) {
        cin >> a[i];
        if (a[i]<0) {
            mCnt++;
            mMax = max(mMax, a[i]);
        }else{
            pMin = min(pMin, a[i]);
        }

    }

    ll ans=0;
    REP(i,n) ans+=abs(a[i]);
    if (mCnt%2==1){
        ans -= 2*min(pMin, abs(mMax));
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3788
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		sc.close();
		int ans = x<a?0:10;
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
def gcd(a,b)
  if b == 0  
    return a
  end  
  gcd(b, a % b)
end  

n,x = gets.split.map(&:to_i)
xs  = gets.split.map{|e| e.to_i - x}
d = xs[0]
xs.each do |e|
    d = gcd(d,e)
end
puts d.abs


Measured memory_bytes: 8452
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n;
set<ll> sl;

int main() {
	cin >> n;
	rep(i, n) {
		ll d;
		cin >> d;
		sl.insert(d);
	}
	cout << sl.size() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}


bool isdisconnect(vector<vector<int>>& root){
    int n = root.size();
    queue<int> q;
    vector<bool> visited(n, false);
    visited[0] = true;
    q.push(0);

    while(!q.empty()){
        auto now = q.front(); q.pop();
        for (auto next: root[now]){
            if (visited[next]) continue;
            q.push(next); visited[next] = true;
        }
    }

    for(auto x: visited){
        if(!x) return true;
    }
    return false;
}

int main()
{
    int n, m;
    cin >> n >> m;
    vector<P> root_master;
    rep(i, m){
        int a, b; cin  >> a >> b; a--;b--;
        root_master.emplace_back(a,b);
    }
    int ans = 0;
    rep(i, m){
        vector<vector<int>> root(n);
        rep(j, m){
            if (j == i) continue;
            int from = root_master[j].first;
            int to = root_master[j].second;
            root[from].push_back(to);
            root[to].push_back(from);
        }
        ans += isdisconnect(root);
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int h, w; cin >> h >> w;
  string s[100];
  for(int i = 0; i < h; i++) {
    cin >> s[i];
  }
  for(int i = 0; i < h; i++) {
    for(int j = 0; j < w; j++) {
      if(s[i][j] != '#') continue;
      int f = 0;
      for(int d = 0; d < 4; d++) {
        int ni = i + dy[d];
        int nj = j + dx[d];
        if(ni < 0 || h <= ni || nj < 0 || w <= nj) continue;
        if(s[ni][nj] == '#') f = 1;
      }
      if(!f) return (cout << "No" << endl, 0);
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<iostream>
 
using namespace std;
int main(){
 int num[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  
  int K;
  cin >> K;
  
  cout << num[K-1] << endl;
  
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define ll long long int
#define vi vector<int>
#define vl vector<ll>
#define ppi pair<int,int>
#define ppl pair<ll,ll>
#define all(x) x.begin(),x.end()
#define ii int,int 
#define ff first    
#define ss second
#define forn(i,a,b) for(int i=a;i<b;i++)
#define forr(i,a,b) for(int i=a;i>=b;i--)
#define forv(i,m) for(auto i : m)
#define imx INT_MAX
#define imn INT_MIN
#define inf LONG_MAX
#define minf LONG_MIN
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define sze size()
#define rvs reverse 
#define itr iterator 
#define pre cout<<fixed<<setprecision(10);
#define umap unordered_map
#define uset unordered_set

/*
#define MODM(a,b,md) ((a%md)*(b%md))%md
#define MODA(a,b,md) ((a%md)+(b%md))%md
#define ull unsigned long long int
#define si short int
*/

/*
bool compare(int a,int b) {return a > b;}
bool compare1(ppi a,ppi b) {return a.ff > b.ff;}
bool compare2(ppi a,ppi b) {return a.ss < b.ss;}
ll Npower(ll a,ll b) {ll product = 1; while(b){if(b&1){product = product*a;}a = a*a;b = b>>1;} return product;}
ll power(ll a,ll b,ll md) {ll product = 1; while(b){if(b&1){product = MODM(product,a,md);}a = MODM(a,a,md);b = b>>1;} return product%md;}
ll GCD(ll a,ll b) {return b==0 ? a:GCD(b,a%b);}
ll LCM(ll a,ll b) {return (a/GCD(a,b))*b; }
*/


int main()
{
    fast

    int n;
    cin>>n;

    string str = "Christmas ";

    int a = 25-n;
    while(a--)
    {
        str += "Eve ";
    }

    cout<<str;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(int argc, const char * argv[]) {
    // insert code here...
    map<string, int> m;
    map<string,int>::iterator ite;
    int N;
    cin>>N;
    for(int i=0;i<N;i++){
        string ch;
        cin>>ch;
        ite=m.find(ch);
        //要素の削除
        m.erase(ch);
        if(ite==m.end()){
            m.insert(make_pair(ch, 1));
        }else{
            m.insert(make_pair(ch, ite->second+1));
        }
    }
    int N2;
    cin>>N2;
    for(int i=0;i<N2;i++){
        string ch;
        cin>>ch;
        ite=m.find(ch);
        //要素の削除
        m.erase(ch);
        if(ite==m.end()){
            m.insert(make_pair(ch, -1));
        }else{
            m.insert(make_pair(ch, ite->second-1));
        }
    }
    
    int MAX=0;
    //要素全てのループ
    for(ite = m.begin();ite!=m.end();ite++){
        MAX=max(MAX,ite->second);
    }
    cout<<MAX<<endl;
    return 0;
}


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

int main(){
  string S;
  cin >> S;
  
  string before="ATGC";
  string after="TACG";
  
  char ans='A';
  
  for (int i=0;i<before.size();++i){
    if (S[0] == before[i]) ans=after[i];
  }
  cout << ans << endl;
}
//直大さんの別解その1
    


Measured memory_bytes: 256
def main():
    from collections import deque

    N = int(input())
    A = input().split()

    ret = deque()
    head_is_0 = 1
    for x in A:
        if head_is_0:
            ret.append(x)
        else:
            ret.appendleft(x)
        head_is_0 ^= 1

    if head_is_0 == 0:
        ret.reverse()
    print(*ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 24516
#include<bits/stdc++.h>
using namespace std;
#define int ll
#define all(a) a.begin(),a.end()
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<int>
#define pi pair<int,int>
#define mp make_pair
 
#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif
 
const int mod=1e9+7;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
int mul(int a,int b)
{
	return ((a)*1ll*(b))%mod;
}
 
void add(int &a,int b)
{
	a+=b;
	if(a>=mod)a-=mod;
}
 
int sub(int a,int b){
	a-=b;
	if(a<0){
		a+=mod;
	}
	return a;
}
 
int powz(int a,int b)
{
	int res=1;
	while(b)
	{
		if(b&1){
			res=mul(res,a);
		}
		b/=2;
		a=mul(a,a);
	}
	return res;
}
 
template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
	input>>x.F>>x.S;
	return input;
}
 
template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
	for(auto& i:x)
		input>>i;
	return input;
}
 
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
	for(auto& i:x)
		output<<i<<' ';
	return output;
}
 
const int N=1000002;

void solve(){
	ll h;
	cin>>h;
	ll fnd=1;
	while(fnd<=h){
		fnd*=2;
	}
	cout<<fnd-1;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int tc=1;
	//~cin>>tc;
	for(int _=0;_<tc;_++){
		//~ cout<<"Case #"<<_+1<<": ";
		solve();
		if(_!=tc-1)
		cout<<"\n";
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,sum=0;
  cin >> n >> k;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin >> a[i];
  }
  sort(a,a+n);
  for(int i=0;i<k;i++)
  {
    sum = sum + a[i];
  }
  cout << sum << endl;
  return 0;
}


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

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

    int a, b, c;
    a = b = c = 0;

    for(int i = 0;i < s.size();i++){
        if(s[i] == 'a'){
            a++;
        }else if(s[i] == 'b'){
            b++;
        }else{
            c++;
        }
    }

    if(max(a, max(b, c)) - min(a, min(b, c)) <= 1){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }

    return 0;
}



Measured memory_bytes: 512
#include <cstdio>
#include <cmath>
#include <vector>
#include <iostream>
#include <map>
#include <queue>
#include <cstring>
#include <algorithm>
using namespace std;
#define mst(a,b) memset((a),(b),sizeof(a))
#define rush() int T;scanf("%d",&T);while(T--)
#define f(i,a,b) for(int i=a;i<=b;i++)

typedef long long ll;
const int maxn = 1005;
const ll mod = 1e9+7;
const ll INF = 1e15;
const double eps = 1e-9;

int n,m,r;
ll dis[maxn][maxn];
int place[maxn];
int order[maxn];

void floyd()
{
    for(int k=1;k<=n;k++)
    for(int i=1;i<=n;i++)
    for(int j=1;j<=n;j++)
    {
        dis[i][j]=min(dis[i][j],dis[i][k]+dis[k][j]);
    }
}


ll solve(int *a)
{
    int pre=place[a[0]];
    ll cnt=0;
    for(int i=1;i<r;i++)
    {
        int now=place[a[i]];
        cnt+=min(dis[pre][now],dis[now][pre]);
        pre=now;
    }
    return cnt;
}

int main()
{
    while(~scanf("%d%d%d",&n,&m,&r))
    {
        for(int i=0;i<r;i++)
        {
            scanf("%d",&place[i]);
        }
        for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
        {
            if(i==j) dis[i][j]=0;
            else dis[i][j]=INF;
        }
        int x,y,w;
        for(int i=0;i<m;i++)
        {
            scanf("%d%d%d",&x,&y,&w);
            if(dis[x][y]>(ll)w)
            {
                dis[x][y]=dis[y][x]=(ll)w;
            }
        }
        floyd();
        for(int i=0;i<r;i++)
        {
            order[i]=i;
        }
        ll ans=INF;
        do
        {
            ans=min(ans,solve(order));
        }
        while(next_permutation(order,order+r));
        printf("%lld\n",ans);
    }
    return 0;
}


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

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

long long lcm(long long a, long long b){
  long long GCD = gcd(a, b);
  return a/GCD*b;
}
  
int main(){
  int n; cin >> n;
  long long ans=1;
  for(int i=0;i<n;++i){
    long long t; cin >> t;
    ans = lcm(ans, t);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n=gets.to_i
m=nil
$<.sort.chunk(&:to_s).map{|r| [r[0],r[1].size] }.each_with_index.sort_by{|r,i| i-n*r[1] }.each{|r|
  break if r[0][1]!=m||=r[0][1]
  print r[0][0]
}

Measured memory_bytes: 42204
#include<bits/stdc++.h>
using namespace std;
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

#define pb push_back
#define F first
#define S second

#define all(v) v.begin(),v.end()
#define allr(v) v.rbegin(),v.rend()
#define int long long
#define ll long long
const int M=1e9+7;

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

int expo(int x, int y) {int res=1;x=x%M;while(y>0){if(y&1)res=(1ll*res*x)%M;
	y=y>>1;x=(1ll*x*x)%M;} return res;}
	

signed main(){
	gearup;
	int t = 1;
	//cin >> t;
	while(t--){
		long double l;
		cin >> l;
		long double ans = pow(l / 3, 3);
		cout << fixed << ans; 
	}
	return 0;
}

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

int main(){
  ll a;
  string b;
  cin >> a >> b;
  int b2 = (b[0] - '0')*100 + (b[2] - '0')*10 + b[3] - '0';
  ll ans = a*b2/100;
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string.h>
#include <string>
#include <algorithm>
#include <math.h>
using namespace std;

void b_judge_status_summary(void) {
	int n;
	string s[100000];
	cin >> n;
	for (int i = 0; i < n; i++)cin >> s[i];
	int ac_cnt = 0;
	int wa_cnt = 0;
	int tle_cnt = 0;
	int re_cnt = 0;
	for (int i = 0; i < n; i++) {
		string ss = s[i];
		if (ss[0] == 'A') ac_cnt++;
		else if (ss[0] == 'W') wa_cnt++;
		else if (ss[0] == 'T') tle_cnt++;
		else                   re_cnt++;
	}

	cout << "AC x " << ac_cnt << endl;
	cout << "WA x " << wa_cnt << endl;
	cout << "TLE x " << tle_cnt << endl;
	cout << "RE x " << re_cnt << endl;
}

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

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

typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl

const int maxn = 1e6 + 5;

int n, k, a[maxn];
int tot, ans;


bool can(int x) {
  int cost = 0;
  vector<int> v(n);
  for (int i=0; i<n; i++) {
    v[i] = a[i]%x;
  }
  sort(v.begin(), v.end());
  int l = 0;
  int r = n-1;
  while (l < r) {
    int dx = min(v[l], x-v[r]);
    cost += dx;
    v[l]-=dx; v[l]%=x;
    v[r]+=dx; v[r]%=x;
    if (v[l]==0) l++;
    if (v[r]==0) r--;
  }

  //cout<<x<<": "<<cost<<endl;
  return cost <= k;
}

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

  cin>>n>>k;
  for (int i=0; i<n; i++) {
    cin>>a[i];
    tot += a[i];
  }

  for (int f=1; f*f<=tot; f++) {
    if (tot%f==0) {
      if (can(f)) {
	ans = max(ans, f);
      }
      if (tot/f!=f && can(tot/f)) {
	ans = max(ans, tot/f);
      }
    }
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	int m = a[0];
	int g = a[0];
	for(int i = 1; i < n; i++){
		m = max(a[i], m);
		g = __gcd(a[i], g);
	}
	if(m>=k&&k%g==0) cout << "POSSIBLE";
	else cout << "IMPOSSIBLE";
}

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

int main()
{
	int n;
	cin >> n;
	auto c = vector<int>(n);
	auto s = vector<int>(n);
	auto f = vector<int>(n);

	for (size_t i = 0; i < n; i++)
	{
		cin >> c[i] >> s[i] >> f[i];
	}
	for (size_t i = 0; i < n; i++)
	{
		auto t = 0;
		for (size_t j = i; j < n-1; j++)
		{
			if (t < s[j]) t = s[j];
			else if (t % f[j] == 0);
			else t = t + f[j] - t % f[j];
			t += c[j];
		}
		cout << t << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
#define repo(i, n) for(int i=1; i<=n; i++)
#define INF 1001001001
#define INFll 100100100100100
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;

using namespace std;
using ull = unsigned long long;
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;

int main(){
  int n, ans=0;
  ll d;
  cin >> n >> d;
  ll dd=d*d;

  rep(i, n){
    ll x, y;
    cin >> x >> y;
    ll xx=x*x, yy=y*y;
    if(xx+yy<=dd){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3644
let id x = x

let rec read () =
  try
    let x = Scanf.scanf "%f\n" id in x :: read ()
  with
    End_of_file -> []

let _ = 
  let lst = read () in
  let f (l, m) x = ((if l = 0.0 then x else max l x), (if m = 0.0 then x else min m x)) in
  let mx, mn = List.fold_left f (0.0, 0.0) lst in
  Printf.printf "%f\n" (mx -. mn)

Measured memory_bytes: 2228
#include <iostream>
#include <vector>
#include <iomanip>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <bits/stdc++.h>


using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long ll;



//abc110
//c1とc2を選択、置き換える
//それぞれが1対1に対応していればよい
//S[i] == S[j]ならば、T[i]== T[j]
//T[i] == T[j]ならば、S[i]== S[j]
int main() {

    string S;
    cin >> S;

    string T;
    cin >> T;

    string res = "Yes";

    ll tmp1,tmp2;

    // -'a'する
    char taiouS[26] = {};
    char taiouR[26] = {};
    REP(i,S.size())
    {
        tmp1 = S[i] - 'a';
        if(taiouS[tmp1] == 0)
        {
            //登録
            taiouS[tmp1] = T[i];
        }
        else
        {
            if(taiouS[tmp1] != T[i])
            {
                res = "No";
                break;
            } 
        }

        tmp2 = T[i] - 'a';
        if(taiouR[tmp2] == 0)
        {
            //登録
            taiouR[tmp2] = S[i];
        }
        else
        {
            if(taiouR[tmp2] != S[i])
            {
                res = "No";
                break;
            } 
        }
    }

    cout << res << endl;

    return 0;

}

Measured memory_bytes: 776
#![allow(unused_imports)]

mod pcl {

}




fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let s = s.as_bytes();
    if s[2] == s[3] && s[4] == s[5] {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
import math
from functools import reduce

def my_gcd(*N):
    return reduce(math.gcd, N)

N, X = map(int,input().split())
C = list(map(int,input().split()))

if X not in C:
	C.append(X)
C.sort()

D = []
for i in range(len(C)-1):
	D.append(C[i+1] - C[i])

print(my_gcd(*D))

Measured memory_bytes: 20488
import java.util.*;

public class Main {
  public static void main(String[] args) {
          Scanner sc = new Scanner(System.in);
          int num = sc.nextInt();
    	  int count = 0;
          List<Integer> list = new ArrayList<>();
          while (num > 0){
              list.add(num % 10);
              num /= 10;
            }
          for(int a : list) {
            if(a == 1){
              count++;
        }
          }
            System.out.println(count);
          }
    }

Measured memory_bytes: 21844
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x;
  cin >> x;
  int i,j,ans=0;
  for(j=1;j<40;j++){
    int sum=1*j;
    for(i=2;i<11;i++){
      sum=sum*j;
      if(sum<=x){
        ans=max(sum,ans);
      }else{
        break;
      }
    }
  }
  cout << ans;
}
      

Measured memory_bytes: 256
while True:
    a,op,b=input().split()
    a=int(a)
    b=int(b)
    if op == '?':
        break
    
    if op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(a//b)
        


Measured memory_bytes: 5592
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#include<deque>
#include <regex>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
#define _GLIBCXX_DEBUG
using namespace std;
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; }
const long long INF = 1LL << 60;
typedef long long ll;
const ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	ll cnt = 0;
	cin >> s;
	vector<char>sp;
	rep(i, s.length())sp.push_back(s[i]);
	for (ll i = 0; i < sp.size()/2; i++) {
		if (s[i] != s[sp.size() - 1 - i])cnt++;
		else continue;
	}
	cout << cnt << endl;
}




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

using namespace std;

using int64 = long long;
//const int mod = (int) (1e9 + 7);
const int mod = 998244353;

const int64 infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;


template< typename T1, typename T2 >
ostream &operator<<(ostream &os, const pair< T1, T2 > &p) {
  os << p.first << " " << p.second;
  return os;
}

template< typename T1, typename T2 >
istream &operator>>(istream &is, pair< T1, T2 > &p) {
  is >> p.first >> p.second;
  return is;
}

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

template< typename T >
istream &operator>>(istream &is, vector< T > &v) {
  for(T &in : v) is >> in;
  return is;
}

template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

template< typename T = int64 >
vector< T > make_v(size_t a) {
  return vector< T >(a);
}

template< typename T, typename... Ts >
auto make_v(size_t a, Ts... ts) {
  return vector< decltype(make_v< T >(ts...)) >(a, make_v< T >(ts...));
}

template< typename T, typename V >
typename enable_if< is_class< T >::value == 0 >::type fill_v(T &t, const V &v) {
  t = v;
}

template< typename T, typename V >
typename enable_if< is_class< T >::value != 0 >::type fill_v(T &t, const V &v) {
  for(auto &e : t) fill_v(e, v);
}

template< typename F >
struct FixPoint : F {
  FixPoint(F &&f) : F(forward< F >(f)) {}

  template< typename... Args >
  decltype(auto) operator()(Args &&... args) const {
    return F::operator()(*this, forward< Args >(args)...);
  }
};

template< typename F >
inline decltype(auto) MFP(F &&f) {
  return FixPoint< F >{forward< F >(f)};
}


int main() {
  int N, Q;
  cin >> N;
  vector< int > A(N);
  cin >> A;
  cin >> Q;

  vector< int64 > be(101010);
  int64 sum = 0;
  for(int i = 0; i < N; i++) {
    sum += A[i];
    be[A[i]]++;
  }

  while(Q--) {
    int b, c;
    cin >> b >> c;
    sum -= be[b] * b;
    sum += be[b] * c;
    be[c] += be[b];
    be[b] = 0;
    cout << sum << "\n";
  }
}

Measured memory_bytes: 4512
#include <cstdio>
#include <algorithm>    
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <cstring>
#include <cmath>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int uii;
typedef pair<int,int> pii;
typedef unsigned long long uLL; 
typedef vector<int> vii; 
//__int128
const int maxn = 2e5;
int a[maxn], v[maxn];

int main(int argc, char const *argv[])
{
#ifndef ONLINE_JUDGE
	// freopen("in.txt", "r", stdin);
	// freopen("out.txt", "w", stdout);
#endif
	int n;
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n;
	for(int i = 0; i < n; ++i){
		cin >> a[i];
	}
	int res = 0;
	for(int i = 0; i < n; ++i){
		cin >> v[i];
		if(a[i] - v[i] > 0){
			 res += a[i] - v[i];
		}
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    flg=1
    s=STR()
    n=len(s)
    c=0
    if s[0]=='A' and 'C' in s[2:n-1]:
        if s.count('C')==1:
            c=s.index('C')
        else:
            flg=0
    else:
        flg=0
    
    for i in range(n):
        if i==0 or i==c:
            pass
        else:
            if s[i].islower():
                pass
            else:
                flg=0
    if flg==1:
        print('AC')
    else:
        print('WA')
    
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	ll n,m;
	cin>>n>>m;
	vector<P> g(n);
	rep(i,n){
		cin>>g[i].fi>>g[i].se;
	}
	sort(begin(g),end(g));
	ll ans=0;
	rep(i,n){
		if(g[i].se<=m){
			ans+=g[i].fi*g[i].se;
			m-=g[i].se;
		}else{
			ans+=g[i].fi*m;
			break;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(char &c){
  int i;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i;
  int sz = 0;
  for(;;){
    i = my_getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = my_getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
struct MY_WRITER{
  char buf[1048576];
  int s;
  int e;
  MY_WRITER(){
    s = 0;
    e = 1048576;
  }
  ~MY_WRITER(){
    if(s){
      fwrite_unlocked(buf, 1, s, stdout);
    }
  }
}
;
MY_WRITER MY_WRITER_VAR;
void my_putchar_unlocked(int a){
  if(MY_WRITER_VAR.s == MY_WRITER_VAR.e){
    fwrite_unlocked(MY_WRITER_VAR.buf, 1, MY_WRITER_VAR.s, stdout);
    MY_WRITER_VAR.s = 0;
  }
  MY_WRITER_VAR.buf[MY_WRITER_VAR.s++] = a;
}
inline void wt_L(char a){
  my_putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    my_putchar_unlocked('-');
  }
  while(s--){
    my_putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
template<class S, class T> int HammingDistance(int N, S A[], T B[]){
  int i;
  int res = 0;
  for(i=(0);i<(N);i++){
    if(A[i] != B[i]){
      res++;
    }
  }
  return res;
}
int As;
int Bs;
char A[1002];
char B[1002];
int main(){
  int i;
  int res = 1073709056;
  As = rd(A);
  Bs = rd(B);
  for(i=(0);i<(As-Bs+1);i++){
    chmin(res, HammingDistance(Bs, A+i, B));
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20200906-1

// --- original code ---
// int As, Bs;
// char A[1002], B[1002];
// 
// {
//   int res = int_inf;
//   rd(A@As, B@Bs);
//   rep(i,As-Bs+1) res <?= HammingDistance(Bs, A+i, B);
//   wt(res);
// }


Measured memory_bytes: 3600
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

typedef struct node {
  int x;
  struct node* prev;
  struct node* next;
} list;
list* head;
list* tail;

list* newnode(int x) {
  list* res = (list*)malloc(sizeof(list));
  res->x = x;
  res->prev = NULL;
  res->next = NULL;
  return res;
}

void deletenode(list* p) {
  p->prev->next = p->next;
  p->next->prev = p->prev;
  free(p);
}

void insert(int x) {
  list* p = newnode(x);
  p->next = head->next;
  p->prev = head;
  head->next->prev = p;
  head->next = p;
}

void delete(int x) {
  list* p;
  for(p = head->next; p != head; p = p->next) {
    if(p->x == x) {      
      deletenode(p);
      break;
    }
  }
}

void deleteFirst() {
  deletenode(head->next);
}

void deleteLast() {
  deletenode(tail->prev);
}

void print() {
  list* p;
  int izryt = 0;
  for(p = head->next; p != tail; p = p->next) {
    if(izryt) printf(" ");
    printf("%d", p->x);
    izryt = 1;
  }
  puts("");
}

int main() {
  int n;
  int i;
  char com[256];
  int x;
  head = newnode(-1);
  tail = newnode(-1);
  head->next = head->prev = tail;
  tail->prev = tail->next = head;
  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf("%s", com);
    if(strcmp(com, "insert") == 0) {
      scanf("%d", &x);
      insert(x);
    } else if(strcmp(com, "delete") == 0) {
      scanf("%d", &x);
      delete(x);
    } else if(strcmp(com, "deleteFirst") == 0) {
      deleteFirst();
    } else if(strcmp(com, "deleteLast") == 0) {
      deleteLast();
    }    
  }
  print();
  return 0;
}

Measured memory_bytes: 31788