akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define add(x,y) e[x].push_back(y)
using namespace std;
inline int rd() {
	char ch=getchar(); int i=0,f=1;
	while(!isdigit(ch)) {if(ch=='-')f=-1; ch=getchar();}
	while(isdigit(ch)) {i=(i<<1)+(i<<3)+ch-'0'; ch=getchar();}
	return i*f;
}
const int N=2e5+50;
vector <int> e[N];
vector <int> e2[N];
int n,tot,a[N],b[N],p0[N],p1[N],id[N];
struct data{
	int p,id;
	friend inline bool operator <(data a,data b) {
		return a.p<b.p || (a.p==b.p && a.id<b.id);
	}
}u[N];
inline void build(int k,int l,int r) {
	p0[k]=++tot; p1[k]=++tot;
	if(l==r) {
		add(p0[k],(a[id[l]]==l?b[id[l]]:a[id[l]]));
		add((a[id[l]]==l?b[id[l]]:a[id[l]]),p0[k]);
		add(l,p1[k]); add(p1[k],l);
		return;
	}
	int mid=(l+r)>>1;
	build(k<<1,l,mid); build(k<<1|1,mid+1,r);
	e[p0[k]].push_back(p0[k<<1]);
	e[p0[k]].push_back(p0[k<<1|1]);
	e[p1[k<<1]].push_back(p1[k]);
	e[p1[k<<1|1]].push_back(p1[k]);
}
inline void inc(int k,int l,int r,int L,int R,int v1,int v2) {
	if(L<=l&&r<=R) {
		e2[v1].push_back(p0[k]); e2[p1[k]].push_back(v2);
		return;
	} int mid=(l+r)>>1;
	if(R<=mid) inc(k<<1,l,mid,L,R,v1,v2);
	else if(L>mid) inc(k<<1|1,mid+1,r,L,R,v1,v2);
	else inc(k<<1,l,mid,L,R,v1,v2),inc(k<<1|1,mid+1,r,L,R,v1,v2);
}
int bl[N],scc,st[N],top,low[N],dfn[N],ins[N],ind;
inline int find1(int l,int r,int v) {
	int ans=r+1;
	while(l<=r) {
		int mid=(l+r)>>1;
		if(u[mid].p>=v) ans=mid, r=mid-1;
		else l=mid+1;
	} return ans;
}
inline int find2(int l,int r,int v) {
	int ans=l-1;
	while(l<=r) {
		int mid=(l+r)>>1;
		if(u[mid].p<=v) ans=mid,l=mid+1;
		else r=mid-1;
	} return ans;
}
inline void dfs(int x) {
	dfn[x]=++ind; low[x]=ind;
	st[++top]=x; ins[x]=1;
	for(auto v:e[x]) {
		if(!dfn[v]) dfs(v), low[x]=min(low[x],low[v]);
		else if(ins[v]) low[x]=min(low[x],dfn[v]);
	}
	for(auto v:e2[x]) {
		if(!dfn[v]) dfs(v), low[x]=min(low[x],low[v]);
		else if(ins[v]) low[x]=min(low[x],dfn[v]);
	}
	if(low[x]==dfn[x]) {
		int u; ++scc;
		do {
			u=st[top--];
			ins[u]=0; bl[u]=scc;
		} while(u!=x);
	}
}
inline bool check(int v) {
	ind=0; scc=0; top=0;
	for(int i=1;i<=tot;i++) e2[i].clear(), dfn[i]=0;
	for(int i=1;i<=n;i++) {
		int l=find1(1,a[i]-1,u[a[i]].p-v+1), r=find2(a[i]+1,2*n,u[a[i]].p+v-1);
		if(l<a[i]) inc(1,1,2*n,l,a[i]-1,a[i],b[i]);
		if(a[i]<r) inc(1,1,2*n,a[i]+1,r,a[i],b[i]);
		l=find1(1,b[i]-1,u[b[i]].p-v+1), r=find2(b[i]+1,2*n,u[b[i]].p+v-1);
		if(l<b[i]) inc(1,1,2*n,l,b[i]-1,b[i],a[i]);
		if(b[i]<r) inc(1,1,2*n,b[i]+1,r,b[i],a[i]);
	}
	for(int i=1;i<=tot;i++) if(!dfn[i]) dfs(i);
	for(int i=1;i<=n;i++) if(bl[a[i]]==bl[b[i]]) return false;
	for(int i=2*n+1;i<=tot;i+=2) if(bl[i]==bl[i+1]) return false;
	return true;
}
int main() {
	n=rd();
	for(int i=1;i<=n;i++) {
		u[i*2-1]=(data){rd(),i};
		u[i*2]=(data){rd(),i};
	} 
	sort(u+1,u+2*n+1);
	for(int i=1;i<=2*n;i++) ((!a[u[i].id])?(a[u[i].id]):(b[u[i].id]))=i, id[i]=u[i].id;
	build(1,1,tot=n*2);
	int l=1, r=1e9, ans=0;
	while(l<=r) {
		int mid=(l+r)>>1;
		if(mid<=10) {
			int xl;
			++xl;
		}
		if(check(mid)) ans=mid, l=mid+1;
		else r=mid-1;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 45824
h, w = gets.chomp.split.map &:to_i
ans = Array.new(h+2).map{Array.new(w+2 ,"#")}

h.times do |i|
  x = gets.chomp.chars
  w.times do |k|
    ans[i+1][k+1] = x[k]
  end
end


(h+2).times do |i|
  (w+2).times do |k|
    print ans[i][k]
  end
  print "\n"
end


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

ans = float("inf")
a, b = 0, 0
while True:
    a += 1
    b = n - a

    if b <= 0:
        break

    ans = min(ans, sum(map(lambda x: int(x), str(a))) + sum(map(lambda x: int(x), str(b))))

print(ans)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
int main(){
    ll A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;
    P ans = P(100 * A, 0);
    for(ll a = 0; 100 * a * A <= F; a++){
        for(ll b = 0; 100 * a * A + 100 * b * B <= F; b++){
            ll water = 100 * a * A + 100 * b * B;
            for(ll c = 0; water + c * C <= F; c++){
                for(ll d = 0; water + c * C + d * D <= F; d++){
                    ll suger = c * C + d * D;
                    if(water / 100 * E < suger) continue;
                    if(ans.second * (water + suger) < suger * ans.first) ans = P(water + suger, suger);
                }
            }
        }
    }
    cout << ans.first << " " << ans.second << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int a, b;
    cin >> a >> b;

    cout << (a + b + 1) / 2 << endl;
    return 0;
}

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

int main(){
    string a,b,c;
    cin >> a >> b >> c;
    int i=0,j=0,k=0;
    char t='a';
    while(true){
        if(t=='a'){
            i++;
            if(i>a.size()){
                t='A';
                break;
            }
            t=a.at(i-1);
        }
        if(t=='b'){
            j++;
            if(j>b.size()){
                t='B';
                break;
            }
            t=b.at(j-1);
        }
        if(t=='c'){
            k++;
            if(k>c.size()){
                t='C';
                break;
            }
            t=c.at(k-1);
        }
    }
    cout << t << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	char a;
	cin>>a;
	if(a=='A'){
		cout<<'T';
	}else if(a=='T'){
		cout<<'A';
	}else if(a=='C'){
		cout<<'G';
	}else{
		cout<<'C';
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
	char str[2][205];
	int n;
	int x;
	scanf("%s",str[0]);
	while(str[0][0] != '-'){
		scanf("%d",&n);
		for(int i=0;i<n;i++){
			scanf("%d",&x);
			strcpy(str[(i+1)%2],&str[i%2][x]);
			str[i%2][x] ='\0';
			strcat(str[(i+1)%2],str[i%2]);
		}
		printf("%s\n",str[(n)%2]);
		scanf("%s",str[0]);
	}
	return 0;
}


Measured memory_bytes: 2116
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ld pi = 3.141592653589793238;

/*bool IsPrime(ll num) {
	if (num < 2) return false;
	else if (num == 2) return true;
	else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2) {
		if (num % i == 0) { // 素数ではない
			return false;
		}
	}
	// 素数である
	return true;
}*/
/*ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}*/
/*ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}*/
/*ll modpow(ll x, ll y, ll mod) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}*/
/*ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}*/
//printf("%.10f\n", n);

ll par[2134567];//親
ll depth[2134567];//木の深さ
//n要素で初期化
void init(ll n) {
	for (int i = 0; i <= n; i++) {
		par[i] = i;
		depth[i] = 0;
	}
}
//木の根を求める
ll find(ll x) {
	if (par[x] == x) {
		return x;
	}
	else {
		return par[x] = find(par[x]);
	}
}
//xとyの属する集合を併合
void unite(ll x, ll y) {
	x = find(x); y = find(y);
	if (x == y) { return; }
	if (depth[x] < depth[y]) {
		par[x] = y;
	}
	else {
		par[y] = x;
		if (depth[x] == depth[y])depth[x]++;
	}
}
//xとyが同じ集合に属するか否か
bool same(ll x, ll y) {
	return find(x) == find(y);
}
ll test[2345678];
signed main() {
	string s, t;
	ll n, m, k, a, b, c, cnt = 0, ans = 0;
	cin >> n >> m; init(n + m);
	rep(i, m) {
		cin >> a >> b; unite(a, b);
	}
	rep2(i, n) {
		test[find(i)]++; ans = max(ans, test[find(i)]);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    int n;cin>>n;
    vector<int> v(n);
    for(int i=0;i<n;i++)cin>>v[i];
    vector<int> dp(n,0);
    
    for(int i=1;i<n;i++){
        if(i==1)dp[i]=abs(v[i]-v[i-1]);
        else dp[i]=min(dp[i-1]+abs(v[i-1]-v[i]),dp[i-2]+abs(v[i]-v[i-2]));
    }
    cout<<dp[n-1]<<endl;
}

Measured memory_bytes: 3964
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define DBG cout << '!' << endl;
#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

int main()
{
	int n;
	
	cin >> n;
	
	vector<ll> v;
	
	REP(i,n)
	{
		ll tmp;
		cin >> tmp;
		v.PB(tmp);
	}
	
	sort(ALL(v));
	ll a = 0,b = 0;
	REP(i,n-1)
	{
		if(v[i] == v[i+1] && v[i] >= a)
		{
			b = a;
			a = v[i];
			i++;
		}
	}
	
	cout << a*b << endl;
	
	
	return 0;
}

Measured memory_bytes: 1400
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DEBUG_OUTPUT_ENABLED 1
	#define DBG(X) dout << #X << "=" << (X) << '\n';
	#define SAY(X) dout << (X) << '\n';
#else
	#define DEBUG_OUTPUT_ENABLED 0
	#define DBG(X) 42;
	#define SAY(X) 42;
#endif

#define dout   debug::instance

using namespace std;

template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
namespace debug {
	struct DebugStream {
		private:
			bool is_first;
		public:
			DebugStream(bool _is_first): is_first(_is_first) {}
			template<typename T> DebugStream operator<<(const T& value) const {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				cout << value;
				return DebugStream(false);
			};

			template<typename T> DebugStream printArray(T* l, T* r) {
				assert(DEBUG_OUTPUT_ENABLED);
				if(is_first) cout << "[DBG] ";
				while(l != r) {
					cout << (*l);
					++l;
					if(l == r) {
						cout << '\n';
					} else {
						cout << ' ';
					}
				}
				return DebugStream(false);
			}
	};
	DebugStream instance(true);
};

using ll = long long int;
using ull = unsigned long long int;
using ld  = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }
const int MAXN = 2007;
vector<int> G[MAXN];
int n;
int dist[MAXN], Q[MAXN], head;
void BFS(int src) {
	for(int v = 0; v < n; ++v) dist[v] = INT_INF;
	dist[src] = 0;
	head = 0;
	Q[head++] = src;
	for(int j = 0; j < head; ++j) {
		int v = Q[j];
		for(auto& u: G[v]) {
			if(dist[u] > dist[v] + 1) {
				dist[u] = dist[v] + 1;
				Q[head++] = u;
			}
		}
	}
}
void addEdge(int v, int u) {
	G[v].emplace_back(u);
	G[u].emplace_back(v);
}
int cnt[MAXN];
void solve() {
	cin >> n;
	int x = fetch<int>() - 1;
	int y = fetch<int>() - 1;
	addEdge(x, y);
	for(int i = 0; i < n - 1; ++i) addEdge(i, i + 1);
	for(int src = 0; src < n; ++src) {
		BFS(src);
		for(int v = 0; v < n; ++v) ++cnt[dist[v]];
	}
	for(int k = 1; k < n; ++k) cout << (cnt[k] / 2) << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long
#define str string
#define pb push_back
#define optimizator ios_base::sync_with_stdio(0);
using namespace std;
int main(){
	optimizator;
	str a;
	cin>>a;
	int h=a.size();
	while(h--){
		cout<<'x';
	}
}

Measured memory_bytes: 256
N, K = map(int, input().split())
p = list(map(int, input().split()))

e = [0] * N

for i in range(N):
    e[i] = (p[i] + 1) / 2

total = sum(e[0:K])
ans = total

for i in range(N - K):
    total += e[i + K] - e[i]
    if total > ans:
        ans = total

print(ans)


Measured memory_bytes: 25060
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

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

    int n;
    cin >> n;

    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());

    ll r = 0;
    for (int i = 1; i < n; i++) {
        r += a[i / 2];
    }

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 3988
#include <cstdio>
int a, b;
int main()
{
	scanf("%d%d", &a, &b);
	if (a <= 0 && 0 <= b)
		puts("Zero");
	else if (b < 0 && (b - a + 1 & 1))
		puts("Negative");
	else
		puts("Positive");
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#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 rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
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 (a>b) { a=b; return 1; } return 0; }

//comb(n,r)=nCr
ll comb(ll n, ll r) {
    ve_vel v(n + 1,vel(n + 1, 0));
    rep(i,v.size()) {
        v[i][0] = 1;
        v[i][i] = 1;
    }
    rep(j,v.size()) rep1(k,j) v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    return v[n][r];
}

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

    int N; cin >> N;
    vel A(N); rep(i,N) cin >> A[i];

    ll ans = 0;
    ll x = 0;
    map<ll,int> mp;
    rep(i,N) {
    mp[x]++;
    x += A[i];
    ans += mp[x];
    }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 14336
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cstring>
#include <cmath>
#include <climits>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <array>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define io() ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define fi first
#define se second
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define v(T) vector<T>
#define p(T, N) pair<T, N>
#define ii p(int, int)
#define vi v(int)
#define vii v(p(int, int))
#define vvi v(v(int))
#define vl v(long long)
#define vll v(p(long long, long long))
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define qsort(a) sort(all(a))
#define qsortd(a) sort(all(a), greater<>())
#define qsortf(a, f) sort(all(a), f)
#define qsortsi(v) sort(v.begin(), v.end(), [](pair<int, int> aoeui, pair<int, int> boeui){return aoeui.se < boeui.se;})
#define pb(n) push_back(n)
#define eb(n) emplace_back(n)
#define pp(a, b) emplace_back(make_pair(a, b))
#define elif else if
#define fori(i, n) for(ll i = 0; i < n; i++)
#define foris(i, a, b) for(ll i = a; i < b; i++)
#define forise(i, a, b) for(ll i = a; i <= b; i++)
#define ford(i, n) for(ll i = n; i >= 0; i--)
#define fords(i, a, b) for(ll i = a; i >= b; i--)
#define fordse(i, a, b) for(ll i = a; i > b; i--)
#define forr(i, a) for (auto &i: a)
#define rev(a) reverse(a.begin(), a.end())
#define revf(a, b, c) (reverse(a.begin() + b, a.begin() + c))
#define digits(i) (int)((log(i)/(log(10))+1)
#define umap unordered_map
#define nl '\n'
#define fileio(in, out) freopen(in, "r", stdin); freopen(out, "w", stdout)
const int mod = 1000000007;

int N, K;
vi arr;

int main() {
  io();
  cin >> N >> K;
  fori(i, N) {
    int a;
    cin >> a;
    arr.pb(a);
  }
  
  qsortd(arr);
  int ret = 0;
  fori(i, K) {
    ret += arr[i];
  }
  
  cout << ret;
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> //Ithea Myse Valgulious
namespace chtholly{
typedef long long ll;
#define re0 register int
#define rec register char
#define rel register ll
#define gc getchar
#define pc putchar
#define p32 pc(' ')
#define pl puts("")
/*By Citrus*/
inline int read(){
  int x=0,f=1;char c=gc();
  for (;!isdigit(c);c=gc()) f^=c=='-';
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return f?x:-x;
  }
template <typename mitsuha>
inline bool read(mitsuha &x){
  x=0;int f=1;char c=gc();
  for (;!isdigit(c)&&~c;c=gc()) f^=c=='-';
  if (!~c) return 0;
  for (;isdigit(c);c=gc()) x=(x<<3)+(x<<1)+(c^'0');
  return x=f?x:-x,1;
  }
template <typename mitsuha>
inline int write(mitsuha x){
  if (!x) return 0&pc(48);
  if (x<0) x=-x,pc('-');
  int bit[20],i,p=0;
  for (;x;x/=10) bit[++p]=x%10;
  for (i=p;i;--i) pc(bit[i]+48);
  return 0;
  }
inline char fuhao(){
  char c=gc();
  for (;isspace(c);c=gc());
  return c;
  }
}using namespace chtholly;
using namespace std;
int state,n=read(),m=read();
ll ans;
 
struct yuu{
ll a[3];
void duit(){
  for (int i=0;i<3;++i) read(a[i]);
  }
bool operator <(const yuu &h) const{
  ll sum1=0,sum2=0;
  for (int i=0;i<3;++i){
    int t=state&(1<<i)?1:-1;
    sum1+=a[i]*t;
    sum2+=h.a[i]*t;
    }
  return sum1>sum2;
  }
}koyume[1010];
 
ll work(){
int i,j,k;ll res=0;
sort(koyume+1,koyume+n+1);
for (i=1;i<=m;++i){
  for (j=0;j<3;++j){
    int t=state&(1<<j)?1:-1;
    res+=koyume[i].a[j]*t;
    }
  }return res;
}
 
int main(){
int i,j;
for (i=1;i<=n;++i) koyume[i].duit();
for (i=0;i<8;++i) state=i,ans=max(ans,work());
write(ans);
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;

internal class Program {
    static void Main() => CustomMain();

    static void Solve() {
        int a, b;
        ReadMulti(out a, out b);
        var ans = IsEven(a * b) ? "Even" : "Odd";
        WriteAnswer(ans);
    }


    static void CustomMain() {
#if DEBUG
        // ファイルからテストケースを読み込む
        ChangeStdIn();
        // 時間計測
        var stopwatch = new Stopwatch();
        stopwatch.Start();
#endif
        // 出力高速化
        var streamWriter = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
        Console.SetOut(streamWriter);
        // 回答
        Solve();
#if DEBUG
        stopwatch.Stop();
        Console.WriteLine(stopwatch.Elapsed);
#endif
        Console.Out.Flush();
    }

    static string ReadString() => Console.ReadLine().Trim();
    static int ReadInt() => int.Parse(ReadString());
    static long ReadLong() => long.Parse(ReadString());
    static float ReadFloat() => float.Parse(ReadString());
    static double ReadDouble => double.Parse(ReadString());

    static string[] ReadStringArray() => ReadString().Split(' ');
    static int[] ReadIntArray() => Array.ConvertAll(ReadString().Split(' '), int.Parse);
    static long[] ReadLongArray() => Array.ConvertAll(ReadString().Split(' '), long.Parse);
    static float[] ReadFloatArray() => Array.ConvertAll(ReadString().Split(' '), float.Parse);
    static double[] ReadDoubleArray() => Array.ConvertAll(ReadString().Split(' '), double.Parse);

    static T TypeConversion<T>(string s) {
        if (typeof(T) == typeof(int)) {
            return (T) Convert.ChangeType(int.Parse(s), typeof(T));
        } else if (typeof(T) == typeof(long)) {
            return (T) Convert.ChangeType(long.Parse(s), typeof(T));
        } else if (typeof(T) == typeof(double)) {
            return (T) Convert.ChangeType(double.Parse(s), typeof(T));
        } else {
            return (T) Convert.ChangeType(s, typeof(T));
        }
    }

    static void ReadMulti<T, U>(out T a, out U b) {
        var str = ReadStringArray();
        a = TypeConversion<T>(str[0]);
        b = TypeConversion<U>(str[1]);
    }

    static void ReadMulti<T, U, V>(out T a, out U b, out V c) {
        var str = ReadStringArray();
        a = TypeConversion<T>(str[0]);
        b = TypeConversion<U>(str[1]);
        c = TypeConversion<V>(str[2]);
    }

    static void WriteAnswer(object ans) => Console.WriteLine(ans);

    static bool IsOdd(long num) {
        return (num & 1) == 1;
    }

    static bool IsEven(long num) {
        return (num & 1) == 0;
    }

    static long GCD(long a, long b) {
        return b != 0 ? GCD(b, a % b) : a;
    }


    static void ChangeStdIn() {
        var path = "./../../TestCase.txt";
        var exStdIn = new System.IO.StreamReader(path);
        Console.SetIn(exStdIn);
    }
}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>

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

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 50;

int main() {
	int h,w;cin>>h>>w;
	string s[N];
	rep(i,h) cin>>s[i];
	int dh[]={1,0,-1,0};
	int dw[]={0,1,0,-1};
	bool flag=true;
	rep(i,h) {
		if(!flag) break;
		rep(j,w) {
			if(!flag) break;
			if(s[i][j]=='.') continue;
			bool b_flag=false;
			rep(k,4) {
				if(i+dh[k]<0||i+dh[k]>h-1) continue;
				if(j+dw[k]<0||j+dw[k]>w-1) continue;
				if(s[i+dh[k]][j+dw[k]]=='#') b_flag=true;
			}
			if(!b_flag) flag=false;
		}
	}
	if(flag) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
    	Scanner s=new Scanner(System.in);
      	int n=s.nextInt();
		      long[] dams=new long[n];
		      for(int i=0;i<n;i++)dams[i]=s.nextInt();
		      long sum=0;
		      for(int i=0;i<n-1;i++){
		    	if(i%2==0)sum+=dams[i]*2;
		        else sum-=dams[i]*2;
		      }
		      long tempsum=sum+dams[n-1]*2;
		      tempsum/=2;
		      long[] mountains=new long[n];
		      mountains[0]=tempsum;
		      for(int i=1;i<n;i++){
		      	mountains[i]=dams[i-1]*2-mountains[i-1];
		      }
		      for(int i=0;i<n;i++){
		      	System.out.print(mountains[i]+" ");
		      }
     }
}

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

int INF = 1'000'000'000;

int main(){
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for (int i = 0; i < n; i++) cin >> h[i];
    vector<int> ans(n, INF);
    ans[0] = 0;
    for (int i = 0; i < n; i++){
        for (int j = i + 1; j < min(n, i + k + 1); j++){
            ans[j] = min(ans[j], ans[i] + abs(h[i] - h[j]));
        }
    }
    cout << ans.back() << endl;
}

Measured memory_bytes: 1024
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
int n,k,a[10000],cnt;
long long sum=0;
cin>>n>>k;
cnt=n;
for(int i=0;i<n;i++)
cin>>a[i];
sort(a,a+n);
reverse(a,a+n);
for(int i=0;i<n;i++)
{if(sum+a[i]<k)
 sum+=a[i];
 else
 cnt=n-i-1;}
cout<<cnt; 
system("pause"); 
return 0;
}

Measured memory_bytes: 504
#include<stdio.h>
const int MAX_V = 10000;
int prime[10001];
int main(){
	int i, k, n;
	for(i = 2;i <= MAX_V; i++){
		prime[i] = 1;
	}
	for(i = 2;i * i <= MAX_V; i++){
		if(prime[i]){
			for(k = 2 * i; k <= MAX_V; k += i){
				prime[k] = 0;
			}
		}
	}
	scanf("%d", &n);
	while(n != 0){
		for(i = n; i >= 5; i--){
			if(prime[i]){
				if(prime[i-2]){
					printf("%d %d\n", i-2, i);
					break;
				}
			}
		}
		scanf("%d", &n);
	}
	return 0;
}

Measured memory_bytes: 1816
#include <bits/stdc++.h>
    using namespace std;
    int main(){
    	string s;
    	int k;
    	cin>>k>>s;
    	if(k>=s.size()){
    		cout<<s<<endl;
    	}
    	else{
    		for(int i=0;i<k;i++){
    			cout<<s[i];
    		}
    		cout<<"..."<<endl;
    	}
      return(0);
    }

Measured memory_bytes: 3600
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007

n = I()




def recur(c, i):
    if c < i:
        return c
    ret = 1
    while ret * i <= c:
        ret *= i
    else:
        return min((recur(c - ret, 6) + 1), (recur(c - ret, 9) + 1))



print(min(recur(n, 6), recur(n, 9)))

Measured memory_bytes: 44892
const input = require("fs").readFileSync("/dev/stdin", "utf8");
const nums = input.split(' ').map(n => parseInt(n));
const calcNums = [
    nums.reduce((a, b) => a + b),
    nums.reduce((a, b) => a - b),
    nums.reduce((a, b) => a * b),
]

console.log(Math.max(...calcNums));

Measured memory_bytes: 7372
#include "bits/stdc++.h"
#define ll long long
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
using namespace std;



int main(){
ll N;
cin>>N;
vector<ll> p(N);
for(ll i=0;i<N;i++){
cin>>p[i];
}
ll c=0;
for(ll i=0;i<N;i++){
if(p[i]!=i+1){
  c++;
}
}

if(c<=2){
  cout<<"YES"<<endl;
}
else
cout<<"NO"<<endl;

return 0;
}


Measured memory_bytes: 256
S=list(input())
l=len(S)

ans='Yes'
if l%2==0:
  h=int(l/2)
  for i in range(0,h):
    if S[2*i]=='L':
      ans='No'
      break
  for i in range(0,h):
    if S[2*i+1]=='R':
      ans='No'
      break
elif l==1:
  if S[0]=='L':
    ans='No'
else:
  h=int((l+1)/2)
  for i in range(1,h):
    if S[2*i-1]=='R':
      ans='No'
      break
  for i in range(0,h):
    if S[2*i]=='L':
      ans='No'
      break

print(ans)

Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = l[0], M = l[1];
            var S = Console.ReadLine();
            var T = Console.ReadLine();

            var lcm = Lcm(N, M);
            var addN = (int)(lcm / N);
            var addM = (int)(lcm / M);

            var nIndex = 0;
            var mIndex = 0;
            var rnIndex = 0;
            var rmIndex = 0;
            while (rnIndex < N && rmIndex < M)
            {
                if (nIndex == mIndex && S[rnIndex] != T[rmIndex])
                {
                    Console.WriteLine(-1);
                    return;
                }

                if (nIndex <= mIndex)
                {
                    nIndex += addN;
                    rnIndex++;
                }

                if (mIndex < nIndex)
                {
                    mIndex += addM;
                    rmIndex++;
                }
            }

            Console.WriteLine(lcm);
        }

        static long Gcd(long a, long b)
        {
            if (b > a) return Gcd(b, a);
            if (b == 0) return a;
            return Gcd(b, (a % b));
        }

        static long Lcm(long a, long b)
        {
            return a * b / Gcd(a, b);
        }
    }
}


Measured memory_bytes: 13664
N, A, B = gets.split.map(&:to_i)
def sum_digits(number)
  sum = 0
  while number > 0
    sum += number % 10
    number /= 10
  end
  sum
end
puts (1..N).select { |number| A <= sum_digits(number) && sum_digits(number) <= B }.reduce(:+)

Measured memory_bytes: 1916
#include<iostream>
using namespace std;
int main(){
	int N,A,minN=1000000,sum=0;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>A;
		if(A<=minN){
			sum++;
			minN=A;
		}
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int cnt[]=new int[n];
		for(int i=0;i<n;i++) {
			cnt[i]=0;
		}
		for(int i=0;i<m;i++) {
			cnt[scan.nextInt()-1]+=1;
			cnt[scan.nextInt()-1]+=1;
		}
		scan.close();
		for(int i=0;i<n;i++) {
			System.out.println(cnt[i]);
		}

	}
}

Measured memory_bytes: 21844
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;



ll N,A;
ll X[55];
ll dp[55][2505];


int main(){

	scanf("%lld %lld",&N,&A);

	for(int i = 0; i < N; i++){

		scanf("%lld",&X[i]);
	}

	for(int i = 0; i <= N; i++){
		for(int k = 0; k < 2505; k++){

			dp[i][k] = 0;
		}
	}


	dp[0][0] = 1;

	for(int i = 0; i < N; i++){
		for(int k = i; k >= 0; k--){
			for(int num = 0; num+X[i] < 2505; num++){
				if(dp[k][num] == 0)continue;

				dp[k+1][num+X[i]] += dp[k][num];
			}
		}
	}

	ll ans = 0;

	for(ll i = 1; i <= N && A*i < 2505; i++){

		ans += dp[i][A*i];
	}

	printf("%lld\n",ans);

	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        std::cin.tie(0);
        ios::sync_with_stdio(false);
        cout.precision(20);
    }
} fast;

/* define */
#define FOR(I, X, Y) for (long long(I) = (X); (I) < (Y); (I)++)
#define REP(I, X, Y) for (long long(I) = (Y)-1; (I) >= (X); (I)--)
#define ALL(X) (X).begin(), (X).end()
#define pb push_back
#define COUNT(V, X)                           \
    (upper_bound((V).begin(), (V).end(), X) - \
     lower_bound((V).begin(), (V).end(), X))
#define debug(x) cerr << #x << ':' << x << endl;
#define DEBUG(v)                             \
    {                                        \
        cerr << #v << ':';                   \
        for (auto xv : v) cerr << xv << ' '; \
        cerr << endl;                        \
    }
#define Yes(X) cout << (X ? "Yes" : "No") << endl;
#define YES(X) cout << (X ? "YES" : "NO") << endl;
#define ctoi(C) (C - '0')
#define pow2(x) ((long long)((long long)1 << x))

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int, int>;
using pl = pair<long long, long long>;
template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1, 0, -1, 0};
const long long dy[] = {0, 1, 0, -1};
const long long dx8[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dy8[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long dx9[] = {1, 1, 0, -1, -1, -1, 0, 1, 0};
const long long dy9[] = {0, 1, 1, 1, 0, -1, -1, -1, 0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T1, typename T2>
inline bool chmin(T1 &a, const T2 &b) {
    if (a > b) a = b;
    return a > b;
}
template <typename T1, typename T2>
inline bool chmax(T1 &a, const T2 &b) {
    if (a < b) a = b;
    return a < b;
}
long long max(long long x, int y) {
    return max(x, (long long)y);
}
long long max(int x, long long y) {
    return max((long long)x, y);
}
long long min(long long x, int y) {
    return min(x, (long long)y);
}
long long min(int x, long long y) {
    return min((long long)x, y);
}

/* library */

/* main */

signed main() {
    ll N;
    cin >> N;
    ll ans = LINF;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ans = min(ans, i + N / i - 2);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val k = sc.nextInt()

    val dic = mutableSetOf<Int>()

    for (i in 0 until k) {
        if (a + i <= b) {
            dic.add(a + i)
        }
        if (b - i >= a) {
            dic.add(b - i)
        }
    }
    dic.sorted().joinToString("\n").let(::println)
}


Measured memory_bytes: 36040
#!/usr/bin/env python3
import sys


def solve(A: int, B: int, C: int, K: int):
    ans = 0
    for x, y in ((1, A), (0, B), (-1, C)):
        z = min(y, K)
        ans += x * z
        K -= z
    return ans



# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    C = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    print(solve(A, B, C, K))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()


Measured memory_bytes: 9208
#include <iostream>
#include <algorithm>
#include <cmath>
using namespace std;
int main () {
	int n; 
	cin >> n;
	string ans = "APPROVED";
	for(int i = 0; i < n; i++) {
		int cur;
		cin >> cur;
		if(cur % 2 == 0) {
			bool flag = false;
			if(cur % 5 == 0) flag = true;
			if(cur % 3 == 0) flag = true;
			if(flag == false) ans = "DENIED";
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 888
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<iostream>
#include<queue>
#include<stack>
#include<cstring>
#include<string>
using namespace std;
typedef long long LL;
int a[30];
bool ok;
int main(){
		string s;
		cin >> s;
		for(int i = 0;i < s.size();i++){
			a[s[i]-'a']++;	
			}
		for(int i = 0;i <= 26;i++){
			if(a[i]%2)ok=1;	
			}
		if(ok)puts("No");
		else puts("Yes");
		return 0;
	}

//

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

using namespace std;

int cnt[108000];
int n, m, u, v;

int main(){
  cin >> n >> m;
  for(int i = 0;i < m;i++){
    cin >> u >> v;
    cnt[u] ^= 1;
    cnt[v] ^= 1;
  }
  for(int i = 1;i <= n;i++){
    if(cnt[i]){
      cout << "NO" << endl;
      return 0;
    }
    
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 1272
#include <iostream>
#include <vector>
#include <climits>


using namespace std;


using ll = long long;


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

    for (ll i = 0; i < N; i++) {
        cin >> A[i];
    }

    ll ans = LONG_LONG_MAX;
    for (ll p = 1; p <= 100; p++) {
        ll s = 0;
        for (auto x : A) {
            s += (x - p) * (x - p);
        }
        ans = min(ans, s);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	N := readint()
	D := readint()
	ok := 0
	for i := 0; i < N; i++ {
		x := readint()
		y := readint()
		if D*D >= x*x+y*y {
			ok++
		}
	}
	fmt.Println(ok)
}

const (
	iobufsize = 1 * 1024 * 1024 // 1 MB
)

var stdinsc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, iobufsize), iobufsize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func readint() int {
	stdinsc.Scan()
	v, err := strconv.Atoi(stdinsc.Text())
	if err != nil {
		panic(err)
	}
	return v
}

func readstr() string {
	stdinsc.Scan()
	return stdinsc.Text()
}

func pow(x, y int) int {
	if y < 1 {
		return 1
	}
	return x * pow(x, y-1)
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}


Measured memory_bytes: 5864
N,K=map(int,input().split())
A=list(map(int,input().split()))
mod = 10**9+7

if K==1:print(0)
else:
  factorial=[1 for i in range(N+1)]
  for i in range(1,N+1):
    if i==1:factorial[i]=1
    else:factorial[i] = factorial[i-1]*i % mod
  
  def comb(n,k):
    return factorial[n]*pow(factorial[n-k]*factorial[k], -1, mod)

  A1=sorted(A)
  A2=A1[::-1]
  
  ans=0
  for i in range(N-K+1):
    ans += (A2[i]-A1[i])*comb(N-i-1,K-1)
  ans %= mod

  print(ans)

Measured memory_bytes: 20152
N = int(input())
A = list(map(int, input().split()))

B = [0] + A + [0]
total = 0

for i in range(1, N + 2):
    total += abs(B[i] - B[i - 1])

for i in range(1, N + 1):
    b = B[i]
    b_next = B[i + 1]
    b_prev = B[i - 1]
    ans = total - (abs(b - b_prev) + abs(b_next - b)) + abs(b_next - b_prev)
    print(ans)


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

using namespace std;
using ll = long long;
#define endl '\n'
#define all(v) v.begin(), v.end()

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (auto& v : a) cin >> v;
    unordered_map<int, int> table;
    ll sum = 0;
    for (auto v : a) {
        sum += v;
        table[v]++;
    }
    int q, b, c;
    cin >> q;
    while(q--) {
        cin >> b >> c;
        int x = table[b];
        sum += x * (c - b);
        cout << sum << endl;
        table[b] = 0;
        table[c] += x;
    }
}


Measured memory_bytes: 7464
import java.util.*;

public class Main {
    public static void main(String args[]) {

        Scanner sc = new Scanner(System.in);

        int s = sc.nextInt();

        int upper = s / 100;
        int lower = s % 100;

        if ((upper == 00) & (01 <= lower & lower <= 12)){
            System.out.print("YYMM");
        }else if ((13 <= upper & upper <= 99) & (01 <= lower & lower <= 12)){
            System.out.print("YYMM");
        }else if ((01 <= upper & upper <= 12) & (lower == 00)){
            System.out.print("MMYY");
        }else if ((01 <= upper & upper <= 12) & (13 <= lower & lower <= 99)){
            System.out.print("MMYY");
        }else if ((01 <= upper & upper <= 12) & (01 <= lower & lower <= 12)){
            System.out.print("AMBIGUOUS");
        }else{
            System.out.print("NA");
        }




    }
}


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

int main()
{
    int n;
    int t_point = 0;
    int h_point = 0;
    cin >> n;
    string str1, str2;

    for (int i = 0; i < n; i++) {
        cin >> str1 >> str2;

        int result = str1.compare(0, 100, str2);
        if (result > 0) {
            t_point += 3;
        }
        else if (result == 0) {
            t_point++;
            h_point++;
        }
        else {
            h_point += 3;
        }
    }
    cout << t_point << " " << h_point << endl;
}


Measured memory_bytes: 3204
/* AtCoder コピペ */
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repEq(i, n) for (int i = 0; i <= (int)(n); i++)
#define repVector(i, v) for (auto i = v.begin(); i != v.end(); ++i)

#define ifBetween(n, a, b) if (n > a && n < b)
#define ifBetweenEq(n, a, b) if (n >= a && n <= b)

int main() {
	int a, b;
  	cin >> a >> b;
  	
  	int result = a - 2 * b;
  	cout << (result <= 0 ? 0 : result) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define int               long long
#define pb                push_back
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define fr                first
#define sc                second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll

template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.fr>>a.sc;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.fr<<" "<<a.sc;return out;}
template<typename T,typename T1>T amax(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T amin(T &a,T1 b){if(b<a)a=b;return a;}

const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

const int N=0;



void solve(){
	int n,m,k;
	cin>>n>>m>>k;
	
	rep(x,0,n+1){
		rep(y,0,m+1){
			int c = x*m + y*n - 2*x*y;
			if(k==c){
				cout<<"Yes";
				return;
			}
			
		}
	}
	cout<<"No";
}
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 3648
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    if((a==5 && b==5 && c==7) || (a==5 && b==7 && c==5) || (a==7 && b==5 && c==5)){
      System.out.println("YES");
    }else{
      System.out.println("NO");
    }
  }
}

Measured memory_bytes: 21972
//
//  main.cpp
//  temp
//
//  Created by tolemy on 2019/08/04.
//  Copyright © 2019 tolemy. All rights reserved.
//

#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    
    int a, b;
    cin >> a >> b;
    
    int a1 = a + b;
    int a2 = a - b;
    int a3 = a * b;
    
    int max = a1;
    if(max < a2) max = a2;
    if(max < a3) max = a3;
    
    cout << max;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define repeat(i,a,b) for(int i=(a),i##__end=(b);i<i##__end;i++)
#define repeat_back(i,a,b) for(int i=(b)-1,i##__end=(a);i>=i##__end;i--)
#define mst(a,x) memset((a),(x),sizeof(a))
#define pii pair<int,int>
#define N 1000010
#define mod 2147483647
#define int ll
string s;
int n,x[10],y[10],f[10],cnt=0;
double ans=0;
double dis(int x,int y){return sqrt(x*x+y*y);}
void dfs(int k,int pre,double now){
	if(k==n){
		cnt++;
		ans+=now;
		return;
	}
	repeat(i,0,n)
	if(!f[i]){
		f[i]=1;
		dfs(k+1,i,now+dis(x[pre]-x[i],y[pre]-y[i]));
		f[i]=0;
	}
}
signed main(){
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin>>n;
	repeat(i,0,n)cin>>x[i]>>y[i];
	repeat(i,0,n){
		f[i]=1;
		dfs(1,i,0);
		f[i]=0;
	}
	printf("%.10lf\n",ans/cnt);
	return 0;
}

Measured memory_bytes: 256
import itertools

n, p = map(int, input().split())
a = list(map(int, input().split()))

even = list(filter(lambda x: x%2 == 0, a))
odd = list(filter(lambda x: x%2, a))

fact = [0]
r = 1
for i in range(1, 100):
    r *= i
    fact.append(r)

def c(a, b):
    if a == b: return 1
    return fact[a] / (fact[a - b] * fact[b])
if p == 0:
    e = 2**len(even)
    r = 1
    for i in range(2, len(odd) + 1, 2):
        r += c(len(odd), i)
    print(int(r * e))

if p == 1:
    e = 2**len(even)
    r = 0
    for i in range(1, len(odd) + 1, 2):
        r += c(len(odd), i)
    print(int(r * e))


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


int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  struct cake { lint x, y, z; };
  vector<cake> a(n);
  for (int i = 0; i < n; i++) {
    lint x, y, z; cin >> x >> y >> z;
    a[i] = cake({x, y, z});
  }
  lint res = -1e18;
  for (int b = 0; b < (1 << 3); b++) {
    int xs = !!(b & 1) * 2 - 1;
    int ys = !!(b & 2) * 2 - 1;
    int zs = !!(b & 4) * 2 - 1;
    auto f = [&](auto c, auto d) {
      return xs * c.x + ys * c.y + zs * c.z > xs * d.x + ys * d.y + zs * d.z;
    };
    sort(a.begin(), a.end(), f);
    lint tmp = 0;
    for (int i = 0; i < m; i++) {
      tmp += xs * a[i].x + ys * a[i].y + zs * a[i].z;
    }
    res = max(res, tmp);
  }
  cout << res << '\n';
  return 0;
}

Measured memory_bytes: 256