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

int main() {
  string T;
  cin >> T;
  int S = T.size();
  string A;
  for (int i = 0; i < (int)S; i++) {
    if (T[i] == '?') {
      A += 'D';
    }
    else {
      A += T[i];
    }
  }
  cout << A << endl;
}

Measured memory_bytes: 3864
#include <bits/stdc++.h>
    #include <math.h>
 
    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846
 
 
    const int M=1e9+7;
    long long mod(long long x){
        return ((x%M + M)%M);
    }
    long long add(long long a, long long b){
        return mod(mod(a)+mod(b));
    }
    long long mul(long long a, long long b){
        return mod(mod(a)*mod(b));
    }
 
    int fact[1000005];
    bool ok=false;
 
    void f(int x){
        if(ok==true)
            return;
        for(int i=1;i*i<=x;i++){
            if(x%i==0){
                int a=i;
                int b=x/i;
                if(a==b){
                    a=i;
                    b=1;
                }
                if(a!=1){
                    if(fact[a]){
                        ok=true;
                        return;
                    }
                    fact[a]++;
                }
                if(b!=1){
                    if(fact[b]){
                        ok=true;
                        return;
                    }
                    fact[b]++;
                }
            }
        }
    }
 
    void solve(){  
        int n;
        cin>>n;
        vector<int>a(n);
        for(int i=0;i<n;i++)
            cin>>a[i];
        int gcd=a[0];
        // cout<<"in "<<ok<<"\n";
        f(a[0]);
        // cout<<"in "<<ok<<"\n";
        for(int i=1;i<n;i++){
            f(a[i]);
            gcd=__gcd(gcd,a[i]);
            // cout<<"in "<<ok<<"\n";
        }
        if(!ok){
            cout<<"pairwise coprime";
        }
        else if(gcd==1){
            cout<<"setwise coprime";
        }
        else{
            cout<<"not coprime";
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        //cout<<fixed;
        //cout<<set
//        freopen("timber_input.txt", "r", stdin);
//        freopen("timber_output.txt", "w", stdout);
        int t=1;
        // cin>>t;
        for(int i=1;i<=t;i++){
//            cout<<"Case #"<<i<<": ";
            solve();
        }
        return 0;
    }

Measured memory_bytes: 7556
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()


void solution(){


	int n, W; cin >> n >> W;

	vector<int> w(n);
	vector<int> v(n);

	int s = 0;

	for(int i = 0; i < n; i++){
		cin >> w[i] >> v[i];
		s += v[i];
	}

	vector<vector<ll>> dp(n + 1, vector<ll>(s + 1, 1e18 + 5));

	dp[0][0] = 0LL;

	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= s; j++){
			dp[i][j] = dp[i-1][j];
			if(j - v[i-1] >= 0)
				dp[i][j] = min(dp[i][j], w[i-1] + dp[i-1][j-v[i-1]]);
		}
	}

	ll ans = 0LL;

	for(int i = 0; i <= s; i++)
		if(dp[n][i] <= W) ans = i;

	cout << ans << endl;




}	


int main(){ 

	fio; // fast input output
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// GOOGLE //
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}

Measured memory_bytes: 83096
N = int(input())
X = []
U = []
result = []
for _ in range(N):
    x, u = input().split()
    X.append(float(x))
    U.append(u)
   


for a, b in zip(X, U):
    if b == "BTC":
        result.append(380000 * a)
    else:
        result.append(a)

print(sum(result))


Measured memory_bytes: 3064
(defun main()
  (let ((N (read)) (L (read)) (strs nil))
    (loop for str from 0 below N collect
          (setq strs (cons (read) strs)))
    (setq strs (sort strs #'string-lessp))

    (mapcar #'(lambda (x) (format t "~(~a~)" x)) strs)
    (princ '#\newline)))

(main)

Measured memory_bytes: 4324
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli M=1e9+7,N=1e5+5;
lli fact[N];

lli binpow(lli a,lli b) 
{
    if (b == 0) return 1;
    lli res = binpow(a,b/2);
    res= (res*res)%M;
    
    if(b%2) return (res*a)%M;
    return res;
}
 
lli inv(lli a)
{
    return binpow(a,M-2);
}

lli add(lli a, lli b)
{
	lli res = a + b + M;
	return res % M;
}
 
lli mul(lli a, lli b)
{
	lli  res = a * b;
		return res % M;
}
 
lli sub(lli a, lli b)
{
	return (a%M -b%M +M) %M;
}

void pre()
{
    fact[0]=1;
    for(int i=1;i<N;i++)
        fact[i] = mul(fact[i-1], i);
}

lli ncr(lli n, lli r)
{
    return mul(fact[n], inv(mul(fact[n-r], fact[r])));    
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n, k;
    cin>>n>>k;
    lli i, a[n], ans=1, pos=0, neg=0, nowneg=0, nowpeg=0, lastneg=0, lastpos=0, zer=0, canneg=0, cannegrem=0, canpos=0, canposrem=0;
    vector<pair<lli,lli>> v;
    
    for(i=0;i<n;i++) 
    {
        cin>>a[i];
        if(a[i] > 0)      pos++, v.push_back({a[i], 0});
        else if(a[i] < 0) neg++, v.push_back({-1*a[i], 1});
        else              zer++;
    }
    
    if((k == n  && neg % 2) || (pos == 0 && k % 2 && zer == 0))
    {
        sort(a, a+n, greater<lli>());
        for(i=0;i<k;i++) ans = mul(ans, a[i]);
        return cout<<(ans + M) % M, 0;
    }
    if(pos == 0 && k % 2 && zer != 0) return cout<<0, 0;
    
    if(k > v.size()) return cout<<0, 0;
    
    sort(v.begin(), v.end(), greater<pair<lli,lli>>());
    for(i=0;i<k;i++)
    {
        if(v[i].second == 0) ans = mul(ans, v[i].first);
        else                 ans = mul(ans, v[i].first);
        
        if(v[i].second == 1) nowneg++, lastneg = v[i].first;
        else nowpeg++, lastpos = v[i].first;
    }
    // cout<<ans<<" "<<nowneg<<" "<<nowpeg<<endl;
    if(nowneg % 2 == 0) return cout<<ans, 0;
    
    if(nowneg % 2 != 0 && v.size() == k) return cout<<0, 0;
    
    
    
    if(nowpeg == 0)
    {
        for(i=k;i<v.size();i++)
        {
            if(v[i].second == 0)
            {
                ans = mul(ans, inv(lastneg));
                ans = mul(ans, v[i].first);
                return cout<<ans, 0;
            }
        }
        assert(1 == 0);
    }
    
    for(i=k;i<v.size();i++)
    {
        if(v[i].second == 0)
        {
            canpos = max(canpos, v[i].first * lastpos);
        }
        else
        {
            canneg = max(canneg, v[i].first * lastneg);
        }
    }
    
    ans = mul(ans, inv(lastneg));
    ans = mul(ans, inv(lastpos));
    if(canpos >= canneg)
    {
        ans = mul(ans, canpos % M);
        return cout<<ans, 0;
    }
    else
    {
        ans = mul(ans, canneg % M);
        return cout<<ans, 0;
    }
    return 0;
}

Measured memory_bytes: 8472
from heapq import heappush, heappop

K = int(input())

queue = [(1, 1)]
dist = [float('inf')] * K
dist[1] = 1

while queue :
    cost, cur = heappop(queue)
    if cost + 1 < dist[(cur + 1) % K] :
        dist[(cur + 1) % K] = cost + 1
        heappush(queue, (cost + 1, (cur + 1) % K))
    if cost < dist[cur * 10 % K] :
        dist[cur * 10 % K] = cost
        heappush(queue, (cost, cur * 10 % K))
     
print(dist[0])

Measured memory_bytes: 87688
//B
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(v) v.begin(), v.end()

using namespace std;
typedef long long LL;

int main() {
	LL a, b, c, d;
	cin >> a >> b >> c >> d;
	LL ans = max(a * c, max(a * d, max(b * c, b * d)));
	cout << ans << "\n";
}

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

#define ld long double
using namespace std;
typedef long long ll;

ll mod= 1000000007; 

ll fast_power(ll a,ll b,ll mod){
	ll ans=1;
	while(b>0){
	if(b&1){
	ans=(a*ans)%mod;
	}
	b=b>>1;
	a=(a*a)%mod;
	}
	return ans;
	}
	
ll inverse_modulus(ll n,ll mod){
	ll ans;
	ans=fast_power(n,mod-2,mod);
	return ans;
	}
  
ll C(ll n,ll r,ll p)
{
	// p ids mod;
	ll ans=1;
	if(r>n)
	{
		return 0;
		}
	else
	{
		//ans*= () ;
		for(ll i=1;i<=r;i++)
		{
			ll z=inverse_modulus(i,p);
			ans=(ans*(((n-i+1)*z)%p))%p ;
			
			}
		
		}
	return ans;
	}


int main()
{
	//cout<<power(2,1000000000,mod)<<endl;
	//cout<<fast_power(2,1000000000,mod)<<endl;
	//cout<<C(10,3,mod)<<endl;
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.flush();
	ll n,a,b;
	ll ans=0;
	cin>>n>>a>>b;
	ll a1,a2,a3;
	a1=fast_power(2,n,mod);
	a1=a1-1;
	
	a2=C(n,a,mod);
	
	a3=C(n,b,mod);
	
	//cout<<"a2: "<<a2<<"  "<<"a3: "<<a3<<endl;
	ans=(a1-(a2+a3))%mod;
	if(ans<0)
	{
		ans=ans+mod;
		}
	
	cout<<ans<<endl;
	
return 0;
}
	


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  while (n--) {
    int x;
    cin >> x;
    if (x & 1) continue;
    if (x % 3 && x % 5) 
      return (0 & puts("DENIED"));
  }
  puts("APPROVED");
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

int n, m, a[200000];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> n >> m;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = m; i < n; i++)
		cout << ((a[i - m] < a[i]) ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 4436
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;

#define N 100

int main(void){
  int n, A[N];
  int i, j, cnt=0;
  
  scanf("%d", &n);
  for(i=0; i<n; i++) scanf("%d", &A[i]);

  for(i=0; i<n-1; i++){
    for(j=n-1; j>i; j--){
      if(A[j]<A[j-1]){
	swap(A[j], A[j-1]);
	cnt++;
      }
    }
  }

  for(i=0; i<n; i++){
    if(i) printf(" %d", A[i]); 
    else  printf("%d", A[i]);
  }

  printf("\n%d\n", cnt);
  
  return 0;
}



Measured memory_bytes: 3212
n = list(raw_input())
op = ['+', '-']

for o1 in op:
	for o2 in op:
		for o3 in op:
			s = n[0] + o1 + n[1] + o2 + n[2] + o3 + n[3]
			if eval(s) == 7:
				print s + '=7'
				exit(0)



Measured memory_bytes: 2568
import math
import collections
import itertools

def YesNo(Bool):
    if(Bool):
        print("Yes")
    else:
        print("No")
    return

def resolve():

    N=int(input())
    L=list(map(int,input().split()))

    cnt=0
    for i in range(N):
        for j in range(i+1,N):
            for k in range(j+1,N):
                if((L[i]!=L[j] and L[i]!=L[k] and L[j]!=L[k] )and (L[i]<L[j]+L[k])and (L[j]<L[i]+L[k])and (L[k]<L[j]+L[i])):
                    cnt+=1
        
    print(cnt)
resolve()


Measured memory_bytes: 9476
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <cmath>
using namespace std;

#define int long long
#define endl "\n"
#define all(v)  v.begin(),v.end()
#define fir first
#define sec second
#define m_p make_pair
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
#define vecout(v,n) for(int i=0; i<n; i++)cout<<v[i]<<" "; cout<<endl;

const int mod = 1000000007;
const int INF = 2000000015;
const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}
int krag(double xx) {
	return INF - (int)(INF - xx);
}

//x未満の要素数を返す二分探索関数
int b_s(vector<int>&vecxx, int xx) {
	if (xx <= vecxx[0]) { //x以下の要素数を返させる時は"<"に変える
		return 0;
	}
	if (vecxx.back() < xx) { //x以下の要素数を返させる時は"<="に変える
		return vecxx.size();
	}
	int aa1 = 0, aa2 = vecxx.size() - 1, aa3;
	while (aa1 + 1 < aa2) {
		aa3 = (aa1 + aa2) / 2;
		if (vecxx[aa3] >= xx) { //x以下の要素数を返させる時は">"に変える
			aa2 = aa3;
		}
		else {
			aa1 = aa3;
		}
	}
	return aa2;
}


int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
//n個を1個以上のx組のグループに分ける重複組み合わせはcom(n-1,x-1)
//グループが0個でもいいときはnにxを足す

int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}



signed main() {
	int a, b, c,t=0;
	cin >> a >> b >> c;
	if (gcd(a, b) == 1) {
		cout << "YES" << endl;
		return 0;
	}
	if (c % gcd(a, b) != 0) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
}




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

int main(){
  int a,b;
  cin>>a>>b;

  if(a<b) cout<<"a < b"<<endl;
  if(a>b) cout<<"a > b"<<endl;
  if(a==b) cout<<"a == b"<<endl;
 return 0;
}



Measured memory_bytes: 3100
import sys

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

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

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

        if x == y:
            return

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

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

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

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

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

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

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

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

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


# main
N, M = map(int, sys.stdin.readline().strip().split())
edges = []
for _ in range(M):
	a, b = map(int, sys.stdin.readline().strip().split())
	edges.append((a-1, b-1))

ans = 0
for i in range(M):
    uf = UnionFind(N)
    for j, (a, b) in enumerate(edges):
        if i == j:
            continue
        uf.union(a, b)
    # print(uf.group_count())
    if uf.group_count() != 1:
        ans += 1

print(ans)

Measured memory_bytes: 40944
#include <bits/stdc++.h>
#define MOD 1000000007
//for(int i=0; i<n; ++i)
using namespace std;
#define all(c) c.begin(), c.end()
#define watch(x) cout << (#x) << " is " << (x) << endl
#define ll long long

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

    int n;
    cin >> n;
    switch (n % 10)
    {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
        cout << "hon";
        break;
    case 0:
    case 1:
    case 6:
    case 8:
        cout << "pon";
        break;
    case 3:
        cout << "bon";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3652
from heapq import *
import sys; input = sys.stdin.readline
inf = int(1e10)
n, m = map(int, input().split())
x, y = map(int, input().split())
dx, dy = map(int, input().split())
x, y, dx, dy = x-1, y-1, dx-1, dy-1
matrix = [list(input().strip()) for _ in range(n)]
v = [[inf for _ in range(m)] for _ in range(n)]
moves = [(1, 0), (-1, 0), (0, 1), (0, -1)]
def valid(x, y): return (0<=x<n) and (0<=y<m) and (matrix[x][y] != '#')
v[x][y] = 0
q = [(0, (x, y))]
while q:
	d, node = heappop(q)
	for i in moves:
		xx, yy = node[0]+i[0], node[1]+i[1]
		if valid(xx, yy) and v[xx][yy] > d:
			v[xx][yy] = d
			heappush(q, (v[xx][yy], (xx, yy)))
	for i in range(node[0]-2, node[0]+3):
		for j in range(node[1]-2, node[1]+3):
			if valid(i, j) and v[i][j] > d + 1:
				v[i][j] = d + 1
				heappush(q, (v[i][j], (i, j)))
if v[dx][dy] == inf: print(-1)
else: print(v[dx][dy])


Measured memory_bytes: 152844
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    vector<int>v(MAX,INF); int ans=0;
    rep(i,3){int temp; cin>>temp; v[temp]=0;}
    rep(i,MAX)if(v[i]!=INF)ans++;
    cout<<ans<<endl;
}

Measured memory_bytes: 39296
/*input
100000
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=1000005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

ll f[maxn]={1};
ll inv[maxn];

ll cnt[maxn];

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

	for(int i=1;i<maxn;i++) f[i]=f[i-1]*i%MOD;
	for(int i=0;i<maxn;i++) inv[i]=mypow(f[i],MOD-2);

	for(int i=1;i<=n;i++){
		if(i+i<n) cnt[i]=0;
		else cnt[i]=f[i]*f[i-1]%MOD*inv[i+i-n]%MOD;
	}
	ll ans=0;

	for(int i=1;i<=n;i++){
		ans+=i*(cnt[i]-cnt[i-1]+MOD)%MOD;
		if(ans>=MOD) ans-=MOD;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
map<int, vector<int>> g;
map<int, ll> cnt;
map<int, ll> ans;
map<int, bool> visit;

void bfs(int now, ll cost)
{
    visit[now] = true;
    //cerr << now << "," << cnt[now] << endl;
    ans[now] = cost + cnt[now];
    for (auto x : g[now])
    {
        if (visit[x] == false)
        {
            bfs(x, cost + cnt[now]);
        }
    }
}

int main(int argc, char const *argv[])
{
    int n, q;
    cin >> n >> q;
    rep(i, n - 1)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i, q)
    {
        int p, x;
        cin >> p >> x;
        //cerr << "p " << p << " x " << x << endl;
        cnt[p] += x;
    }
    bfs(1, 0);
    rep(i, 1, n + 1)
    {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 77440
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define REPI(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;
using P = pair<long, long>;
using VI = vector<long>;

long par[101010];

void init(long n) {
    for (int i = 0; i < n; i++) par[i] = i;
}

long root(long x) {
    if (par[x] == x) return x;
    return par[x] = root(par[x]);
}

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

void unite(long x, long y) {
    x = root(x);
    y = root(y);
    if (x != y) par[x] = y;
}

long pos[101010];

int main() {
    long n, m;
    cin >> n >> m;
    VI ps(n);
    init(n);
    REP(i,n) {
        cin >> ps[i];
    }

    REP(i,n) {
        pos[ps[i]] = i + 1;
    }

    REP(i,m) {
        long x, y;
        cin >> x >> y;
        unite(x, y);
    }

    long cnt = 0;
    REP(i,n) {
        if (same(i + 1, pos[i + 1])) {
//            cout << i + 1 << " can go to " << pos[i + 1] << endl;
            cnt++;
        }
    }
    cout << cnt << endl;
}


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

using namespace std;

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

#define st first
#define nd second

const int MAXN = 1e6 + 5, inf = 1e9, mod = 1e9 + 7;
const ll INF = 1e18, MOD = 1e15 + 37;
const ld PI = acos(-1);

map<int, bool> is;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout << setprecision(13) << fixed;

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

    int x, n;
    cin >> x >> n;
    for (int i= 0; i < n; ++i) {
        int p;
        cin >> p;
        is[p] = true;
    }

    for (int i = 0; i <= 100; ++i) {
        if (!is[x - i]) {
            cout << x - i << "\n";
            return 0;
        }

        if (!is[x + i]) {
            cout << x + i << "\n";
            return 0;
        }
    }
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(),v.end()
#define puts(i) cout << i << endl
#define INF INT_MAX
#define INFL LLONG_MAX
typedef long long ll;
using namespace std;


int main(){
  ll h;
  cin >> h;

  ll atack,sum=0,s=1;


ll i;
  for(i=1;s<=h;i++){
    s=s*2;
    sum=s/2;
  }

  atack=sum+(sum-1);

  cout << atack << endl;


  }


Measured memory_bytes: 3604
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int N,MOD;
vector<vector<int>> adj;
vector<vector<ll>> dp;

ll Dfs(const int p, const int v){
    ll res = 1;
    for(int i=0; i<adj[v].size(); i++){
        if(adj[v][i] != p){
            dp[v][i] = Dfs(v,adj[v][i]);
            res *= dp[v][i]+1;
            res %= MOD;
        }
    }
    return res;
}

void Rev(const int p, const int v, const ll add){
    for(int i=0; i<adj[v].size(); i++){
        if(adj[v][i] == p){
            dp[v][i] = add;
            break;
        }
    }
    const int deg = adj[v].size();
    vector<ll> l(deg), r(deg);
    for(int i=0; i<deg; i++){
        r[i] = l[i] = (dp[v][i] + 1)%MOD;
    }
    for(int i=1; i<deg; i++){
        l[i] *= l[i-1];
        l[i] %= MOD;
    }
    for(int i=deg-2; i>=0; i--){
        r[i] *= r[i+1];
        r[i] %= MOD;
    }
    for(int i=0; i<deg; i++){
        if(adj[v][i] != p){
            ll add_c = 1;
            if(i != 0){
                add_c *= l[i-1];
                add_c %= MOD;
            }
            if(i != deg-1){
                add_c *= r[i+1];
                add_c %= MOD;
            }
            Rev(v, adj[v][i],add_c);
        }
    }
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> MOD;
    adj.resize(N);
    for(int i=0; i<N-1; i++){
        int x,y;
        cin >> x >> y;
        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
    }
    dp.resize(N);
    for(int v=0; v<N; v++) dp[v].resize(adj[v].size());

    Dfs(-1,0);
    Rev(-1,0,0);

    for(int v=0; v<N; v++){
        ll ans = 1;
        for(ll add : dp[v]) (ans *= (add+1)) %= MOD;
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 27904
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
typedef long long ll;

int main()
{
	ll n;
	cin >> n;
	vector<ll> D(n);
	rep(i,n)D[i]=0;
	rep(i,n)
	{
		ll foo;cin>>foo;
		D[foo] ++;
		if(i>0&&foo==0)
		{
			cout<<0<<endl;
			return 0;
		}
	}

	ll ans=1;
	if(D[0]==0)
	{
		cout<<0<<endl;
		return 0;
	}

	for(ll i = n-1;i>0;i--)
	{
		while(D[i]==0)i--;
	

		rep(jj,D[i])
		{
			ans*=D[i-1];
			ans%=998244353;
		}

	}
	cout<<ans<<endl;

	return 0;
}


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

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

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

  int n, k;
  cin >> n >> k;

  if (n % k == 0) {
    cout << 0 << endl;
  } else {
    cout << 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
bool used[64][64];
string s[64];
int main(){
	int n;	cin>>n;
	while(n--){
		int h,w;	cin>>h>>w;
		for(int i=0;i<h;i++)	for(int j=0;j<w;j++)	used[i][j]=false;
		for(int i=0;i<h;i++)	cin>>s[i];
		map<char,int> u,d,l,r;
		for(int i=0;i<h;i++)	for(int j=0;j<w;j++){
			if(s[i][j]!='.'){
				if(u.find(s[i][j])==u.end())	u[s[i][j]]=i;
				d[s[i][j]]=i;
				if(l.find(s[i][j])==l.end())	l[s[i][j]]=j;
				else 	l[s[i][j]]=min(l[s[i][j]],j);
				if(r.find(s[i][j])==r.end())	r[s[i][j]]=j;
				else 	r[s[i][j]]=max(r[s[i][j]],j);
			}
		}
		bool ok=true;
		int m=l.size();
		while(m){
			bool end=true;
			for(auto it:l){
				char key=it.first;
				int L=it.second;
				int R=r[key],U=u[key],D=d[key];
				//cout<<key<<" "<<U<<"-"<<D<<" "<<L<<"-"<<R<<endl;
				bool ok=true;
				for(int i=U;i<=D;i++){
					for(int j=L;j<=R;j++){
						if(s[i][j]==key||used[i][j])	continue;
						ok=false;
						break;
					}
					if(!ok)	break;
				}
				if(ok){
					m--;
					for(int i=U;i<=D;i++)	for(int j=L;j<=R;j++){
						used[i][j]=true;
					}
					u.erase(key);	d.erase(key);
					l.erase(key);	r.erase(key);
					end=false;
					break;
				}
			}
			if(end){
				cout<<"SUSPICIOUS"<<endl;
				break;
			}
		}
		if(m==0)	cout<<"SAFE"<<endl;
	}
	return 0;
}

Measured memory_bytes: 3168
#include<bits/stdc++.h>
using namespace std;
#define INF 1000000000

int main(){
    int a, b, c; cin >> a >> b >> c;

    int t = 0;
    int T = a + b;   //??¨???

    while(t < 1000){
        
        int temp = (60*t + c) % T;
        if(0 <= temp && temp <= a){
            cout << 60*t + c << endl;
            return 0;
        }

        t++;
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 3100
s = list(input())
k = int(input())

import sys
if len(s) == 1:
    if k == 1:
        print(0)
    else:
        print(k // 2)
    sys.exit(0)

if len(set(s)) == 1:
    print((len(s) * k) // 2)
    sys.exit(0)

count = 0
seq_len = 1
seq_len_array = []
for i in range(0, len(s) - 1):
    if s[i] != s[i+1]:
        seq_len_array.append(seq_len)
        seq_len = 1
    else:
        seq_len += 1
seq_len_array.append(seq_len)
count = sum(s // 2 for s in seq_len_array)
count = count * k

if s[0] == s[-1]:
    count = count - \
            (seq_len_array[0] // 2 + seq_len_array[-1] // 2) * (k - 1) + \
            ((seq_len_array[0] + seq_len_array[-1]) // 2) * (k - 1)
print(count)


Measured memory_bytes: 38432
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;

int main(){ 
   string s;
   cin>>s;
   int flag=1;
   if(s[0]!='A') flag=0;
   int count=0;
   for(int i=2;i<s.size()-1;i++){
      if(s[i]=='C') count++;
   }  
   if(count!=1) flag=0;
   int oomoji=0;
   for(int i=0;i<s.size();i++){
      if(isupper(s[i]))oomoji++;
   }
   if(oomoji!=2) flag=0;

   flag==1? cout<<"AC":cout<<"WA";

   


}

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

public class Main {
    public static void main(String[] args){
    	FastScanner fs = new FastScanner(System.in);
    	String S = fs.next();
    	int len = S.length();
    	if(len == 1) {
    		System.out.println(1);
    		return;
    	}
    	int k = (len+1)/2;
    	int l, r;
    	l = len/2 - 1;
    	if(len % 2 == 0) r = len/2;
    	else r = len/2 + 1;
    	
    	if(len %2 == 1) {
    		if(S.charAt(l)!=S.charAt(l+1)||S.charAt(l+1)!=S.charAt(r)) {
    			System.out.println(k);
    			return;
    		}
    	}
    	while(l>=0&&S.charAt(l) == S.charAt(r)) {
    		k ++;
    		l --;
    		r ++;
    	}
    	System.out.println(k);
    }
}












//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

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

	public int[] nextIntArray(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = nextInt();
		return a;
	}

	public long[] nextLongArray(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nextLong();
		return a;
	}
}


Measured memory_bytes: 25044
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
using namespace std;

#define FOR(i,a,b) for(long long int i=(a);i<(b);i++)
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define ALL(s) (s).begin(),(s).end()

#define PI 3.14159265358479

typedef long long int ll;
typedef vector<long long int> vi;

int main(){
	ll n, a, b, c;
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> a >> b >> c;
		if (pow(c,2)==pow(a,2)+pow(b,2)||pow(a,2)==pow(b,2)+pow(c,2)||pow(b,2)==pow(c,2)+pow(a,2)){
			cout << "YES\n";
		}
		else{
			cout << "NO\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1120
#include<bits/stdc++.h>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (int)(x).size()
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
int main(){
  string s;
  cin>>s;
  ll n=sz(s);
  ll ans=0;
  for(int bit=0;bit<(1<<n-1);bit++){
    ll cu=0;
    for(int i=0;i<n;i++){
      cu*=10;
      cu+=(s[i]-'0');
      if(i!=n-1){
        if(bit&(1<<i)){
          ans+=cu;
          cu=0;
        }
      }
      
    }
    ans+=cu;
  }
  COUT(ans);
}

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<cmath>
#include<bitset>
#include<algorithm>
#include<functional>
#include<climits>
#include<utility>
#include <iomanip>
#include<map>
#include<bitset>


using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define max(a,b) (a>b?a:b)
#define min(a,b) (a<b?a:b)
#define FOR(i,s,e) for (int i = int(s); i < int(e); i++)
#define REP(i,x) FOR(i,0,x)
#define CLR(a) memset((a), 0 ,sizeof(a))

const ll MOD = 1e+9+7;
const double PI  = acos(-1.0);


int main(){
  int n=3;
  int a,b;
  int c[n];
  CLR(c);
  REP(i,n){
    cin>>a>>b;
    c[a-1]++;
    c[b-1]++;
  }
  int odd=0;
  REP(i,4){
    odd+=c[i]%2;
  }
  cout<<(odd<3?"YES":"NO")<<"\n";
  

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alp = "abcdefghijklmnopqrstuvwxyz";
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}
void neg() {cout << -1 << endl;}

//モジュラー逆数
ll modinv(ll n, ll p) {
  ll a = p, u = 1, v = 0;
  while (a) {
    ll t = n / a;
    n -= t * a;
    swap(n, a);
    u -= t * v;
    swap(u, v);
  }
  u %= p;
  if (u < 0) u += p;
  return u;
}

int main() {
  long long x, y, p = 1000000007;
  cin >> x >> y;
  if ((x + y) % 3 != 0) {
    cout << 0 << endl;
    return 0;
  }
  if (x < (x + y) / 3 || y < (x + y) / 3) {
    cout << 0 << endl;
    return 0;
  }
  long long n = (x + y) / 3;
  long long r = min(x - (x + y) / 3, y - (x + y) / 3);
  long long ncr = 1;
  for (long long i = 0; i < r; i++) {
    ncr *= n - i;
    ncr %= p;
  }
  for (long long i = 0; i < r; i++) {
    ncr *= modinv(i + 1, p);
    ncr %= p;
  }
  cout << ncr % p << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================

	ll A, B, K;
	cin >> A >> B >> K;


	if (A >= K) {
		cout << A - K << " " << B;
	}
	else {
		cout << 0 << " " << max(B - (K - A), ll(0));
	}



}


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

using namespace std;
const int maxN=1e5+5;

int fa[maxN];

struct node
{
    int x,y,id;
}a[maxN],b[maxN];

struct edge
{
    int f,t,w;
}e[maxN*2];

bool cmp1(node x1,node x2)
{
    return x1.x<x2.x;
}

bool cmp2(node x1,node x2)
{
    return x1.y<x2.y;
}

bool cmp3(edge x1,edge x2)
{
    return x1.w<x2.w;
}

int find(int x)
{
    if(fa[x]==-1)return x;
    return fa[x]=find(fa[x]);
}

int uni(int f,int t)
{
    f=find(f);t=find(t);
    if(f==t)return 0;
    fa[f]=t;return 1;
}

int main()
{
    int k,n,cnt=0,now=0;
    long long ans=0;
    memset(fa,-1,sizeof(fa));
    scanf("%d",&n);
    for(k=0;k<n;k++)
    {
        scanf("%d%d",&a[k].x,&a[k].y);
        a[k].id=k;b[k].id=k;
        b[k].x=a[k].x;
        b[k].y=a[k].y;
    }
    sort(a,a+n,cmp1);
    sort(b,b+n,cmp2);
    for(k=1;k<n;k++)
    {
        e[cnt].f=a[k-1].id;
        e[cnt].t=a[k].id;
        e[cnt].w=a[k].x-a[k-1].x;
        cnt++;
    }
    for(k=1;k<n;k++)
    {
        e[cnt].f=b[k-1].id;
        e[cnt].t=b[k].id;
        e[cnt].w=b[k].y-b[k-1].y;
        cnt++;
    }
    sort(e,e+cnt,cmp3);
    for(k=0;k<cnt;k++)
    {
        if(uni(e[k].f,e[k].t))
        {
            ans+=e[k].w;
            now++;
        }
        if(now==n-1)break;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 5376
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
#include <algorithm>
#include <vector>
 
using namespace std;
 
class Node {
public:
    int location;
    int l, r;
    //Node() {}
};
 
class Point {
public:
    int id, x, y;
    Point() {}
    Point(int id, int x, int y) :id(id), x(x), y(y) {}
    bool operator<(const Point&p) const {
        return id < p.id;
    }
 
    void print() {
        printf("%d\n", id);
    }
};
 
static const int MAX = 500000;
static const int NIL = -1;
 
int N;
Point P[MAX];
Node T[MAX];
int np;
Point ans[MAX];
int NANS;
 
bool lessX(const Point &p1, const Point &p2) {
    return p1.x < p2.x;
}
 
bool lessY(const Point &p1, const Point &p2) {
    return p1.y < p2.y;
}
 
int makeKDTree(int l, int r, int depth) {
    if (l == r) {
        return NIL;
    }
    int mid = (l + r) / 2;
    int t = np++;
    if (depth % 2 == 0) {
        sort(P + l, P + r, lessX);
    }
    else {
        sort(P + l, P + r, lessY);
    }
    T[t].location = mid;
    T[t].l = makeKDTree(l, mid, depth + 1);
    T[t].r = makeKDTree(mid + 1, r, depth + 1);
 
    return t;
}
 
void find(int v, int sx, int tx, int sy, int ty, int depth) {
    int x = P[T[v].location].x;
    int y = P[T[v].location].y;
 
    if (sx <= x && x <= tx && sy <= y && y <= ty) {
        ans[NANS++] = P[T[v].location];
    }
 
    if (depth % 2 == 0) {
        if (T[v].l != NIL) {
            if (sx <= x) find(T[v].l, sx, tx, sy, ty, depth + 1);
        }
        if (T[v].r != NIL) {
            if (x <= tx) find(T[v].r, sx, tx, sy, ty, depth + 1);
        }
    }
    else {
        if (T[v].l != NIL) {
            if (sy <= y) find(T[v].l, sx, tx, sy, ty, depth + 1);
        }
        if (T[v].r != NIL) {
            if (y <= ty) find(T[v].r, sx, tx, sy, ty, depth + 1);
        }
    }
}
 
int main() {
    int x, y;
    scanf("%d", &N);
    for (int i = 0; i < N; i++) {
        scanf("%d %d", &x, &y);
        P[i] = Point(i, x, y);
        T[i].l = T[i].r = NIL;
    }
 
    np = 0;
 
    int root = makeKDTree(0, N, 0);
 
    int q;
    scanf("%d", &q);
    int sx, tx, sy, ty;
    for (int i = 0; i < q; i++) {
        scanf("%d %d %d %d", &sx, &tx, &sy, &ty);
        NANS = 0;
        find(root, sx, tx, sy, ty, 0);
        sort(ans, ans + NANS);
        for (int j = 0; j < NANS; j++) {
            ans[j].print();
        }
        printf("\n");
    }
 
    return 0;
}


Measured memory_bytes: 13948
#include <cstdio>
#include <cstring>
#define fail return puts("-1"), 0

const int N = 1e5 + 5;

char s[N];

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

Measured memory_bytes: 1408
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f

using namespace std;

const int MOD = 1e9 + 7;

int n;
long long k;


vector<vector<int>> mul(vector<vector<int>> A, vector<vector<int>> B) {
    vector<vector<int>> C(n, vector<int>(n, 0));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            for(int k = 0; k < n; ++k) {
                C[i][j] += ((long long) A[i][k] * B[k][j]) % MOD;
                C[i][j] %= MOD;
            }
        }
    }
    return C;
}

vector<vector<int>> mod_pow(vector<vector<int>> A, long long k) {
    if(k % 2 == 1) {
        if (k == 1) return A;
        return mul(mod_pow(A, k - 1), A);
    } else {
        vector<vector<int>> half = mod_pow(A, k / 2);
        return mul(half, half);
    }
}

void add_self(int & x, int y) {
    x += y;
    if(x >= MOD) x -= MOD;
}

int main(int argc, char *argv[])
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k;
    vector<vector<int>> A(n, vector<int>(n, 0));
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            cin >> A[i][j];
        }
    }
    vector<vector<int>> ans = mod_pow(A, k);
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < n; ++j) {
            add_self(cnt, ans[i][j]);
        }
    }
    cout << cnt << endl;
    return 0;
}



Measured memory_bytes: 2304
#include <iostream>
#include <vector>
#include <cmath>
#include <typeinfo>
#include <set>
#include <bitset>
#include <string>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;



int main(){
  int n;
  string s;
  cin >> n >> s;
  char x;
  int z;
  for(int i=0; i<s.size(); i++){
    z = s[i]+n;
    if(z>=91){
      z -= 26;
    }
    cout << char(z);
  }
  cout << endl;

}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
xyh = [LIST() for _ in range(N)]

ins = (-1,-1,-1)
for x, y, h in xyh:
	if h >= 1:
		ins = (x, y, h)

for i in range(101): # x
	for j in range(101): # y
		H = ins[2]+abs(i-ins[0])+abs(j-ins[1])
		for x, y, h in xyh:
			if max(H-abs(x-i)-abs(y-j), 0) != h:
				break
		else:
			print(i, j, H)
			sys.exit()


Measured memory_bytes: 5192
d=int(input())
c=list(map(int,input().split()))
s=[]
for i in range(d):
    t=list(map(int,input().split()))
    s.append(t)

fuman=[]
for i in range(26):
    fuman.append(c[i]*66795)

for i in range(d):
    p=fuman.index(max(fuman))
    print(p+1)
    q=364-i
    fuman[p]=(q**2+q)*c[p]//2
    for j in range(26):
        if j!=p:
            fuman[j]-=c[j]*(i+1)

Measured memory_bytes: 9400
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")



int main() {


    string s, t; cin >> s >> t;

    int n = s.size();
    int m = t.size();

    int idx = -1;
    for(int i = 0; i < n-m+1; ++i){ //move initial s pos
        bool flg = true;
        for(int j = 0; j < m; ++j){
            if(s[i+j]!='?' && s[i+j] != t[j]) flg = false;
        }

        if(flg) idx = i;    //preserve the latest starting pos
    }

    if(idx == -1) cout << "UNRESTORABLE" << endl;
    else{
        for(int i = idx; i < idx+m; i ++){
            s[i] = t[i-idx];
        }
        rep(i,n){
            if(s[i] == '?') cout << 'a';
            else cout << s[i];
        }
    }
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner scan = new Scanner(System.in);
		int sakoda = scan.nextInt();
		
		if (sakoda == 22) {
			System.out.println("Christmas Eve Eve Eve");
		}else if (sakoda == 23) {
			System.out.println("Christmas Eve Eve");
		}else if (sakoda == 24) {
			System.out.println("Christmas Eve");
		}else if (sakoda == 25) {
			System.out.println("Christmas");
		}
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
#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 long long ll;
const ll INF = 1LL << 60;

vector<ll> dp;
 
void init(ll n) {
    dp.resize(n);
    rep(i, n) dp[i] = i;
}

ll root(ll x) {
    if (dp[x] == x) return x;
    else return dp[x] = root(dp[x]);
}

void unite(ll x, ll y) {
    auto rx = root(x);
    auto ry = root(y);
    dp[ry] = dp[rx];
    root(y);
}

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

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

    ll n, m, k, a, b, c, d;
    cin >> n >> m >> k;

    init(n);
    vector<vector<ll>> direct(n, vector<ll>());
    vector<vector<ll>> block(n, vector<ll>());

    rep(i, m){
        cin >> a >> b;
        --a;
        --b;
        unite(a, b);
        direct[a].push_back(b);
        direct[b].push_back(a);
    }

    rep(i, k){
        cin >> c >> d;
        --c;
        --d;
        block[c].push_back(d);
        block[d].push_back(c);
    }

    map<ll, ll> friend_size;
    vector<ll> roots(n);
    rep(i, n){
        ll r = root(dp[i]);
        ++friend_size[r];
        roots[i] = r;
    }

    rep(i, n){
        ll res = friend_size[roots[i]] - direct[i].size() - 1;
        ll cnt = 0;
        rep(j, block[i].size()){
            if(same(i, block[i][j])) ++cnt;
        }

        cout << res - cnt << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 18176
import heapq

Q = int(input())
ans = 0

L = []
R = []

for _ in range(Q):
    q = list(map(int, input().split()))
    if q[0] == 1:
        l = heapq.heappushpop(L, -q[1])
        r = heapq.heappushpop(R, q[1])
        heapq.heappush(L, -r)
        heapq.heappush(R, -l)
        ans += abs(l + r) + q[2]
    else:
        print(-L[0], ans)


Measured memory_bytes: 19036