akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
using namespace std;

int main() {
	const long long int mod = 1000000007;
	map<long long int, long long int>mp;
	//cout << fixed << setprecision(10);
	long long int  n, m, a[2000], b, c, d, k, h, w, left = 1, right = 0;
	long long int sc, sr, num2, no[1005][1005] = {}, res = 999999999, count = 0, now = 0, mi = 9999999999;

	string str, t;

	cin >> n;
	while (1) {
		res = 9999999999999999;
		if (n == 0) { return 0; }
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		sort(a, a + n);
		for (int i = 0; i < n-1; i++) {
			if (res > a[i + 1] - a[i]) {
				res = a[i + 1] - a[i];
			}
		}
		cout << res << endl;

		cin >> n;
	}
	
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 //Compiler version g++ 6.3.0

 int main()
 {
 	int n;
 	cin >> n;
 	int ans=1;
 	int a;
 	cin >> a;
 	for (int i = 1; i < n; i++){
 		int b;
 		cin >> b;
 		if(a<=b){
 			ans++;
 		}
 		a=max(a,b);
 	}
 	cout << ans << endl;
 }

Measured memory_bytes: 256
N = int(input())
A = [0] + list(map(int, input().split())) + [0]
l = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
suml = sum(l)
for i in range(1,N+1):
    cut = -(abs(A[i] - A[i - 1]) + abs(A[i + 1] - A[i]))
    short = abs(A[i + 1] - A[i - 1])
    ans = suml+cut+short
    print(ans)

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

typedef long long ll;
int main(){
  int n, q, t;
  string name;
  queue<pair<string, int>> Q;
  cin >> n >> q;
  for(int i=0;i<n;i++){
    cin >> name >> t;
    Q.push(make_pair(name,t));
  }
  pair<string, int> u;
  int elaps = 0, a;
  while(! Q.empty()){
    u = Q.front(); Q.pop();
    a = min(u.second, q);
    u.second -= a;
    elaps += a;
    if(u.second >0)
      Q.push(u);
    else
      cout<<u.first << " " <<elaps <<endl;
  }
}



Measured memory_bytes: 6328
from collections import deque

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

b = deque()


for i in range(n):
    if i % 2 == 0:
        b.appendleft(a[i])
    else:
        b.append(a[i])
if n % 2 == 0:
    b = list(b)[::-1]
print(*b)


Measured memory_bytes: 25536
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios::sync_with_stdio(false);cin.tie(nullptr)
#define endl "\n"
#include "string"


int32_t main(){
	boost;
	int t = 1;
	//cin >> t;
	while(t--) {
		int n;
		cin >> n;
		pi a[n + 1];
		for(int i = 1; i <= n; i++) {
			cin >> a[i].ff;
			a[i].ss = i;
		}
		set < int > s;
		s.insert(0);
		s.insert(n + 1);
		int ans = 0;
		sort(a + 1, a + n + 1,greater<pi>());
		s.insert(a[1].ss);
		for(int i = 2; i <= n; i++) {
			s.insert(a[i].ss);
			auto it = s.find(a[i].ss);
			auto ti = it;
			ti--;
			int l = *ti;
			if(ti != s.begin()) {
				ti--;
				l -= *ti;
			}
			else
				l = 0;
			ti = it;
			ti++;
			int r = *ti - *it;
			ans += l * r  * a[i].ff;
			ti = it;
			ti--;
			l = *it - *ti;

			ti = it;	
			ti++;
			r = -*ti;
			ti++;
			if(ti != s.end())
				r += *ti;
			else
				r = 0;
			ans += l * r * a[i].ff;
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 9776
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>
#include <fstream>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
#define watch(a) { cout << #a << " = " << a << endl; }
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

struct state {
  int cost, use, pos;
  state(int c, int u, int p) : cost(c), use(u), pos(p){}
};

vector<int> bfs(vector<vector<pair<int, bool>>>& G, int s, int t, int& shortestLen) {
  vector<int> dist(G.size(), inf), d2cnt(G.size()+1);
  dist[s] = 0;

  queue<state> q;
  q.emplace(0, 0, s);

  while(!q.empty()) {
    const state s = q.front(); q.pop();
    d2cnt[s.cost]++;
    for(auto& e: G[s.pos]) {
      const int next = e.first;
      if(dist[next] > s.cost + 1) {
        dist[next] = s.cost + 1;
        q.emplace(dist[next], 0, next);
      }
    }
  }

  shortestLen = dist[t];
  return d2cnt;
}

int main() {

  int N, M, s, t; cin >> N >> M >> s >> t; s--, t--;
  vector<vector<pair<int, bool>>> G(N);
  rep(i, M) {
    int x, y; cin >> x >> y;
    G[x-1].emplace_back(y-1, false);
    G[y-1].emplace_back(x-1, false);
  }

  int shortestLen;
  auto && d2cnt1 = bfs(G, s, t, shortestLen);
  auto && d2cnt2 = bfs(G, t, s, shortestLen);

  ll ans = 0;

  rep(i, N) {
    if(shortestLen-i-2 >= 0)
      ans += (ll)d2cnt1[i] * d2cnt2[shortestLen-i-2];
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 11792
n,m,*t=map(int,open(0).read().split())
d=[0,0]+[1e18]*n
for l,r,c in sorted(zip(*[iter(t)]*3)):
 for i in range(r,l,-1):
  if d[l]+c<d[i]:d[i]=d[l]+c
  else:break
print(d[-2]%10**18or-1)

Measured memory_bytes: 124200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 7;
const double PI = acos(-1);
int a[N], n, x;
int main() {
	scanf("%d%d", &n, &x);
	for (int i = 0; i < n; i++)scanf("%d", &a[i]);
	sort(a, a + n);
	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
		if (x >= a[i]) {
			ans++;
			x -= a[i];
		}
		else break;
	}
	if (x == a[n - 1])ans++;
	cout << ans << endl;
}

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

int main(){
  int n, a[1000], b[1000], c[1000];
  cin >> n;
  for(int i = 0;i < n; i++) cin >> a[i] >> b[i] >> c[i];
  for(int i = 0;i < n; i++) {
    if(a[i]*a[i]==b[i]*b[i]+c[i]*c[i] || b[i]*b[i]==c[i]*c[i]+a[i]*a[i] || c[i]*c[i]==a[i]*a[i]+b[i]*b[i]){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
int n,a;
string s[234567];
int main(){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>s[i];
        
    }
    sort(s,s+n);
    int i=0;
    while(i<=n){
        if(s[i]!=s[i+1]){
            a++;
        }
        i++;
    }
    cout<<a<<endl;
}


Measured memory_bytes: 10960
def InsertionSort(A, N, g, cnt):
	for i in range(g,N):
		v = A[i]
		j = i-g
		while j >= 0 and A[j] > v:
			A[j+g] = A[j]
			j -= g
			cnt += 1
		A[j+g] = v
	
	return(cnt, A)

N = int(input())
A = [int(input()) for j in range(N)]

cnt = 0
G=[]
G.append(1)

for i in range(100):
	g = 3 * G[i] + 1
	if g >= N:
		break
	else:
		G.append(g)

G.reverse()
m = len(G)
print(m)
print(" ".join(map(str, G)))

for i in range(m):
	cnt, A = InsertionSort(A, N, G[i], cnt)

print(cnt)
Ap = [print(A[i]) for i in range(N)]

Measured memory_bytes: 55276
#include<iostream>
#include<cstdio>
#include<cmath>
#include<bitset>
#include<algorithm>
#include<vector>
using namespace std;
vector<int> list;

int main(){
  int n;
  while(cin>>n,n!=0){
    list.clear();
    for(int i=0;i<n;i++){
      int tmp;
      cin>>tmp;
      list.push_back(tmp);
    }
    sort(list.begin(),list.end());
    long long ans=0;
    long long pre=0;
    for(int i=0;i<n;i++){
      ans+=pre;
      pre=pre+list[i];
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 3184
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100010];

int main() {

    string s;
    cin >> s;

    vector<string> nums;
    for (int i = 0; i < s.length(); i++) {
        nums.push_back(s.substr(i,1));
    }

    ll res = 0;
    ll sum = 0;
    string ssum = "";

    for (int i = 0; i < (1 << (nums.size() - 1)); i++) {

        sum = 0;
        ll tmp = 0;
        ll digit = 1;
        ssum = nums[0];

        for (int j = 0; j < nums.size() - 1; j++) {
            if (i & (1 << j)) {
                sum += stol(ssum);
                ssum = "";
            }
            ssum += nums[j + 1];
        }

        sum += stol(ssum);
        res += sum;   
    }
    
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    N=input()
    YesNo(N==N[::-1])

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include<stdio.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int inf=2147483647;
char str[200010];
int h[200010],to[400010],nex[400010],fa[200010],d[200010],s[200010],f[200010],g[200010],tmp[200010],M;
void add(int a,int b){
	M++;
	to[M]=b;
	nex[M]=h[a];
	h[a]=M;
}
void dfs(int x){
	s[x]=str[x]=='1';
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x]){
			fa[to[i]]=x;
			dfs(to[i]);
			s[x]+=s[to[i]];
		}
	}
}
void dfs1(int x){
	for(int i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x]){
			dfs1(to[i]);
			f[x]=max(f[x],f[to[i]]+1);
		}
	}
}
void dfs2(int x){
	int i,j,M=0,p;
	for(i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x])tmp[++M]=f[to[i]];
	}
	for(i=M-1;i>0;i--)tmp[i]=max(tmp[i],tmp[i+1]);
	tmp[M+1]=-inf;
	p=-inf;
	for(i=h[x],j=1;i;i=nex[i]){
		if(to[i]!=fa[x]){
			g[to[i]]=max(max(p+2,g[x]+1),tmp[j+1]+2);
			p=max(p,f[to[i]]);
			j++;
		}
	}
	for(i=h[x];i;i=nex[i]){
		if(to[i]!=fa[x])dfs2(to[i]);
	}
}
int gao(int x,int y){
	if(fa[y]==x){
		if(s[y]==0)return inf;
		return f[y]+1;
	}else{
		if(s[1]-s[x]==0)return inf;
		return g[x];
	}
}
int main(){
	int n,i,x,y,l,r,mx,se;
	ll ans;
	scanf("%d",&n);
	for(i=1;i<n;i++){
		scanf("%d%d",&x,&y);
		add(x,y);
		add(y,x);
		d[x]++;
		d[y]++;
	}
	scanf("%s",str+1);
	dfs(1);
	dfs1(1);
	dfs2(1);
	ans=0;
	for(x=1;x<=n;x++){
		if(d[x]==1){
			ans+=str[x]=='1';
			continue;
		}
		mx=se=-inf;
		#define gay(t)\
			if(t>=mx){\
				se=mx;\
				mx=t;\
			}else if(t>se)\
				se=t;
		for(i=h[x];i;i=nex[i]){
			if(to[i]==fa[x]){
				gay(g[x])
			}else{
				gay(f[to[i]]+1)
			}
		}
		r=se;
		l=str[x]=='1'?0:inf;
		for(i=h[x];i;i=nex[i])l=min(l,gao(x,to[i]));
		if(l<=r)ans+=r-l+1;
	}
	for(i=2;i<=n;i++){
		x=i;
		if(f[x]<g[x]-1)
			ans+=s[x]!=0;
		else if(f[x]>g[x]-1)
			ans+=(s[1]-s[x])!=0;
		else
			ans++;
	}
	printf("%lld",ans);
}

Measured memory_bytes: 12928
import math
def resolve():
    x = int(input())
    a = 0
    b = 0
    for i in range(1, x):
        if i >math.sqrt(x):
            break
        if x % i == 0:
            a = i
            b = x // a

    print(len(list(str(b))))

if __name__ == '__main__':
    resolve()

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;


#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);    
    
    int N, M; cin >> N >> M;
    vpl data;
    F0R(i, N) {
		ll A, B; cin >> A >> B;
		//sort by increasing date
		data.pb(mp(A, B));
	}
	sort(all(data));
	ll ans = 0;
	
	int nxt = 0;
	priority_queue<ll> pq;

	FOR(i, 1, M+1) {
		while (nxt < N && data[nxt].f == (ll) i) {
			pq.push(data[nxt].s); nxt++;
		}
		if (!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
	}
    
    cout << ans << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by bqi343


Measured memory_bytes: 3696
//ICPC C
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll mod=1e9+7;

int main(){
    vector<int> answers;
    while(1){
        int n,m;
        cin>>n>>m;
        if(n==0&&m==0) break;
        vector<ll> a(n);
        vector<ll> w(m);
        for(int i=0;i<n;i++){
            cin>>a[i];
        }
        for(int i=0;i<m;i++){
            cin>>w[i];
        }

        //既存の分銅で量れる質量
        vector<ll> p;
        for(int i=0;i<pow(3,m);i++){
            ll tmp=i;
            ll val=0LL;
            for(int j=0;j<m;j++){
                int amari=tmp%3;
                if(amari==1){
                    val+=w[j];
                }else if(amari==2){
                    val-=w[j];
                }
                tmp/=3;
            }
            if(val>=0) p.push_back(val);
        }
        sort(p.begin(),p.end());

        //既存の分銅では作れない量のリストを作成
        vector<ll> targets;
        for(auto aim:a){
            if(!binary_search(p.begin(),p.end(),aim)) targets.push_back(aim);
        }
        if(targets.empty()){
            answers.push_back(0);
            continue;
        }

        //各作れない量と量れる量の差の絶対値
        vector<vector<ll>> diff(targets.size(),vector<ll>(p.size()*2));
        for(int i=0;i<targets.size();i++){
            for(int j=0;j<p.size();j++){
                diff[i][j]=abs(targets[i]-p[j]);
                diff[i][p.size()+j]=targets[i]+p[j];
            }
            sort(diff[i].begin(),diff[i].end());
        }

        //targets[0]を作るための追加分銅候補で他のも作れるかを判定
        bool find=false;
        for(int i=0;i<diff[0].size();i++){
            bool flag=true;
            for(int j=1;j<targets.size();j++){
                if(!binary_search(diff[j].begin(),diff[j].end(),diff[0][i])){
                    flag=false;
                    continue;
                }
            }
            if(flag){
                answers.push_back(diff[0][i]);
                find=true; break;
            }
        }

        if(!find) answers.push_back(-1);
      
    }
    for(auto ans:answers){
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 42384
const input=require('fs').readFileSync('/dev/stdin','utf8').split(/[\s]/);const tn=():number=>{const a=input[0];input.shift();return Number(a)};const tnn=(n:number):number[]=>{const a=[];for(let i=0;i<n;i++){a.push(tn())}return a};const ts=():string=>{const a=input[0];input.shift();return String(a)};const tss=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(ts())}return a};const tc=():string=>{let a=input[0].split('');const b=a[0];a.shift();if(a.length>0){input[0]=a.join('')}else{input.shift()}return String(b)};const tcc=(n:number):string[]=>{const a=[];for(let i=0;i<n;i++){a.push(tc())}return a};const to=(...arg)=>{console.log(...arg)};const abs=(a)=>{return Math.abs(a)};const min=(...a)=>{return Math.min(...a)};const max=(...a)=>{return Math.max(...a)};const floor=(a)=>{return Math.floor(a)};const ceil=(a)=>{return Math.ceil(a)};const asc=(ar:number[])=>{return ar.sort((a,b)=>{return a-b})};const desc=(ar:number[])=>{return ar.sort((a,b)=>{return b-a})};const sw=(a,arr:any[],op:'=='|'>='|'>'|'<='|'<'='==')=>{for(let i=0;i<arr.length;i+=2){if(eval(a+op+arr[i]))return arr[i+1];}return arr[arr.length-1]};const near=(n:number,arr:number[]):number=>{let ne=arr[0],ni=0;for(let i=1;i<arr.length;i++){if(Math.abs(n-ne)>Math.abs(n-arr[i])){ne=arr[i];ni=i}}return ni};const gojo=(a:number,b:number):number=>{if(a%b===0)return b;return gojo(b,a%b)};const deduplicate=(a:number[])=>{return Array.from(new Set(a))};const permutation=(arr,n)=>{var arrs,i,j,zensu,results,parts;arrs=[];zensu=arr.length;if(zensu<n){return}else if(n==1){for(i=0;i<zensu;i++){arrs[i]=[arr[i]]}}else{for(i=0;i<zensu;i++){parts=arr.slice(0);parts.splice(i,1)[0];results=permutation(parts,n-1);for(j=0;j<results.length;j++){arrs.push([arr[i]].concat(results[j]))}}}return arrs}
const main=()=>{
  let n=tn(),ans=n;
  let y=n,xx=1,yy=n
  for(let x=1;x<=y;x++){
    y=n/x
    if(Number.isInteger(y)){
      xx=x
      yy=y
    }
  }
  to(xx+yy-2)
}
main()


Measured memory_bytes: 14156
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) throws Exception{
		BufferedReader br = new BufferedReader (new InputStreamReader(System.in));
		String [] oneList = br.readLine().split(" ");
		int co = Integer.parseInt(oneList[0]);
		int limit = Integer.parseInt(oneList[1]);
		int wait = Integer.parseInt(oneList[2]);
		int [] human = new int[co];
		int count = 0;
		while(br.ready()) {
			human[count] = Integer.parseInt(br.readLine());
			count++;
		}
		//human[count] = Integer.parseInt(br.readLine());
		Arrays.sort(human);
		int result = 0;
		int bus = 0;
		int point=human[0]+wait;
		for(int i=0 ;i<co ; i++) {
			int c = human[i];
			if(bus < limit && point >= c ) {
				bus++;
			}else {
              if(bus!=0){
              	result++;
              }
				point = human[i] + wait;
				
                bus=1;
			}
		}
		System.out.println(result+1);
	}
}

Measured memory_bytes: 31840
def smaller(x, y):
	if x < y:
		return x
	return y

N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
sum = 0
for i in range(0, N):
	m = smaller(A[i], B[i])
	sum += m
	A[i] -= m
	B[i] -= m
	m = smaller(A[i+1], B[i])
	sum += m
	A[i+1] -= m
	B[i] -= m
print(sum)

Measured memory_bytes: 82148
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class node
{
	public node parent;
	public node sibling;
	public node rightChild;
	public node leftChild;
	public int id;
	public int depth;
	public int height;
	public int degree;
	
	public override string ToString()
	{
		string result = "node ";
		
		result += id + ": parent = ";
		result += (depth == 0)?  "-1" : parent.id.ToString();
		result += ", sibling = ";
		result += (sibling != null)? sibling.id.ToString() : "-1";
		result += ", degree = " + degree;
		result += ", depth = " + depth;
		result += ", height = " + height + ", ";
		
		if(depth == 0){
			result += "root";
		} else if(degree == 0) {
			result += "leaf";
		} else {
			result += "internal node";
		}
		
		return result;
	}
	
}

public class Test
{
	public static void Main()
	{
		int n = int.Parse(Console.ReadLine());
		
		node[] tree = new node[n];
		
		for(int i = 0; i < n; i++ ){
			int[] A = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
			
			if(tree[A[0]] == null) tree[A[0]]= new node();
			tree[A[0]].id = A[0];
			
			if(A[1] != -1) {
				if(tree[A[1]] == null) tree[A[1]]= new node();
				tree[A[1]].id = A[1];
				tree[A[1]].parent = tree[A[0]];
				tree[A[0]].leftChild = tree[A[1]];
				tree[A[0]].degree++;
				
				if(A[2] != -1) {
					if(tree[A[2]] == null) tree[A[2]] = new node();
					tree[A[1]].sibling = tree[A[2]];
				}
			}
			
			if(A[2] != -1) {
				if(tree[A[2]] == null) tree[A[2]]= new node();
				tree[A[2]].id = A[2];
				tree[A[2]].parent = tree[A[0]];
				tree[A[0]].rightChild = tree[A[2]];
				tree[A[0]].degree++;
				
				if(A[1] != -1) {
					tree[A[2]].sibling = tree[A[1]];
				}
			}
		}
		
		// depth TANSAKU
		node u = tree[0];
		while(u.parent != null){
			u = u.parent;
		}
		List<node> V = new List<node>();
		if(u.rightChild != null)	V.Add(u.rightChild);
		if(u.leftChild != null)		V.Add(u.leftChild);
		while(V.Count != 0) {
			node[] W = V.ToArray();
			V.Clear();
			foreach(node x in W){
				x.depth = x.parent.depth + 1;
				if(x.rightChild != null)	V.Add(x.rightChild);
				if(x.leftChild != null)		V.Add(x.leftChild);
			}
		}
		
		//height TANSAKU
		for(int i = 0; i < n; i++) {
			if(tree[i].degree == 0) {
				continue;
			} else {
				
				u = tree[i];
				V.Clear();
				if(u.rightChild != null)	V.Add(u.rightChild);
				if(u.leftChild != null)		V.Add(u.leftChild);
				
				while(V.Count != 0){
					var W = V.ToArray();
					tree[i].height++;
					V.Clear();
					foreach(node x in W){
						if(x.rightChild != null)	V.Add(x.rightChild);
						if(x.leftChild != null)		V.Add(x.leftChild);
					}
				}
			}
		}
        
        foreach(node t in tree) {
        	Console.WriteLine(t.ToString());
        }
	}
}

Measured memory_bytes: 9248
#include <iostream>

int main(){
  int n, k;
  int ans = 1;
  std::cin >> n >> k;
  for (int i=0; i<n; i++){
    if(ans*2-ans < k)ans *= 2;
    else ans += k;
  }
  
  std::cout << ans << std::endl;
  return 0;
}

Measured memory_bytes: 256
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  string s; readV(s);

  auto b = new bool[](26);
  foreach (c; s) b[c-'a'] = true;

  foreach (i; 0..26)
    if (!b[i]) {
      writeln(dchar(i+'a'));
      return;
    }

  writeln("None");
}


Measured memory_bytes: 2556
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    n %= k;
    n = min(abs(n), abs(n - k));
    cout << n << "\n";
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
signed main(){
    int n;cin >> n;
    int h[n];
    rep(i,n)cin >> h[i];
    reverse(h,h+n);
    int now = 1e10;
    bool ok = true;
    rep(i,n){
        if(now >= h[i]){
            now = h[i];
            continue;
        }
        else if(now+1 == h[i]){
            continue;
        }
        else {
            ok = false;
            break;
        }
        
    }
    if(ok)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int n,m;

bool check(int x)
{
    if (m/x >= n)
        return true;
    return false;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> m;
    int ans = 0;
    for (int i = 1; i*i <= m; ++i)
    {
        if (m%i == 0)
        {
            if (check(i))
                ans = max(ans, i);
            if (check(m/i))
                ans = max(ans, m/i);
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int maxi(int n)
{
    if (n <= 9) return (0);
    
    int b = 1;
    int c = 0;
    int ma = 0;
    while (n > 9){
        c += (n % 10) * b;
        b *= 10;
        n /= 10;
        ma = max(ma, n * c);
    }
    
    return (maxi(ma) + 1);
}

int main()
{
    int Q;
    
    scanf("%d", &Q);
    
    while (Q--){
        int n;
        
        scanf("%d", &n);
        
        printf("%d\n", maxi(n));
    }
    
    return (0);
}

Measured memory_bytes: 1188
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
//#define int long long
template<class T> inline bool chmax(T& a,T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a,T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1e9;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    for (int i = 0; i < N; i++) cin >> B[i];
    
    vector<vector<int>> dp((1<<N)+1, vector<int>(55, INF));
    dp[0][0] = 0;
    
    for (int bit = 0; bit < (1<<N); bit++) {
        
        int done = 0;
        for (int i = 0; i < N; i++) if (bit&(1<<i)) done++;
        int iter = done;
        vector<pair<int, int>> data;
        for (int i = 0; i < N; i++) {
            if (!(bit&(1<<i))) data.emplace_back(i, iter++);
        }
        
        for (int s = 0; s <= 50; s++) {
            if (dp[bit][s] >= INF) continue;
            for (auto p : data) {
                // p.first : もとのindex
                // p.second : ソート後のindex
                int value = -1;
                if (abs(done-p.first)%2 == 0) value = A[p.first];
                else value = B[p.first];
                if (value >= s) {
                    chmin(dp[bit|(1<<p.first)][value], dp[bit][s] + abs(done-p.second));
                }
            }
        }
    }

    int ans = INF;
    for (int s = 0; s <= 50; s++) chmin(ans, dp[(1<<N)-1][s]);
    cout << ((ans == INF) ? -1 : ans) << endl;
    return 0;
}

Measured memory_bytes: 76032
class SegmentTreeDual():
    def __init__(self,arr,op=lambda x,y:y if y != -1 else x,ie=-1):
        self.h = (len(arr)-1).bit_length()
        self.n = 2**self.h
        self.ie = ie
        self.op = op
        self.val = [ie for _ in range(self.n)]
        self.laz = [ie for _ in range(2*self.n)]
        for i in range(len(arr)):
            self.val[i] = arr[i]
    def update(self,left,right,f):
        left += self.n
        right += self.n
        while right - left > 0:
            if right & 1:
                right -= 1
                self.laz[right] = self.op(self.laz[right],f)
            if left & 1:
                self.laz[left] = self.op(self.laz[left],f)
                left += 1
            left >>= 1
            right >>= 1
    def get(self,index):
        res = self.val[index]
        index += self.n
        while index>0:
            res = self.op(res,self.laz[index])
            index //= 2
        return res

import sys
input = sys.stdin.readline

import bisect

N,D,A = map(int,input().split())
monster = [list(map(int,input().split())) for _ in range(N)]

monster.sort()
ans = 0
X = []
H = []
for i in range(N):
    X.append(monster[i][0])
    H.append(monster[i][1])

r = [0 for _ in range(N)]
for i in range(N):
    r[i] = bisect.bisect_left(X,X[i]+2*D+1)

sg = SegmentTreeDual(H,lambda x,y:x+y,0)

for i in range(N):
    hp = sg.get(i)
    if hp <= 0:
        continue
    cnt = -(-hp//A)
    sg.update(i,r[i],-A*cnt)
    ans += cnt

print(ans)


Measured memory_bytes: 119392
import math
n = int(input())
xy = []
for i in range(n):
    XY = list(map(int,input().split()))
    xy.append(XY)
total = 0
for i in range(n - 1):
    for j in range(i + 1,n):
        total += math.sqrt((xy[i][0] - xy[j][0]) ** 2 + (xy[i][1] - xy[j][1]) ** 2)
print(total * 2 / n)

Measured memory_bytes: 9200
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <vector>
#include <algorithm>
#include <map>
int main(){

  int N;
  scanf("%d",&N);
  std::vector<long long > A(N);
  int negative_sign_num = 0;
  long long abs_min = 1000000001;
  long long sum = 0;
  for (int i=0; i<N; i++){
    scanf("%lld",&A[i]);
    sum += abs(A[i]);
    abs_min = std::min(abs_min,abs(A[i]));
    if (A[i]<0){
      negative_sign_num++;
    }
  }
  if (abs_min==0){
    printf("%lld\n",sum);
  } else if (negative_sign_num%2==0){
    printf("%lld\n",sum);
  } else {
    printf("%lld\n",sum-2*abs_min);
  }
  
  return 0;
}


Measured memory_bytes: 1024
def main():
    from collections import Counter, namedtuple

    pt = namedtuple('pt', 'x y')

    def delta(a: pt, b: pt) -> pt:
        x = a.x - b.x
        y = a.y - b.y
        if (x < 0) or (x == 0 and y < 0):
            x = -x
            y = -y
        return pt(x=x, y=y)

    n = int(input())
    if n == 1:
        # deltaが計算できないので、
        # 別処理する
        print(1)
        return

    ps = [pt(*map(int, input().split())) for _ in range(n)]

    c = Counter(
        delta(a, b)
        for i, a in enumerate(ps)
        for j, b in enumerate(ps)
        if i < j
    )

    ma = max(c.values())

    print(n - ma)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3564
#include <iostream>
#include <cmath>

int main(void) {
	unsigned long N;
  	std::cin >> N;
  	unsigned long a = std::sqrt(N) , b;
  	for(; a > 0; --a){
    	if(N%a != 0) continue;
      	b = N/a;
      	break;
    }
  
  	std::cout << a+b-2 << std::endl;
  	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <bitset>
#include <complex>
#include <algorithm>
#include <numeric>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define mp make_pair
#define pb push_back
#define dump(x)  cout << #x << " = " << (x) << endl;
#define forauto(i, a) for(auto i:a)cout << i << " "; puts("");

typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef complex<double> CD;

string aaa(string t) {
	string l = t; SORT(l); REVE(l);
	string s = t; SORT(s);
	int ans = stoi(l) - stoi(s);
	string sans = to_string(ans);
	string ret; ret.assign(4 - sz(sans), '0');
	ret += to_string(ans);
	return ret;
}

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

		VL p(n), j(n - 1);
		rep(i, n)cin >> p[i];
		rep(I, n - 1)cin >> j[I];

		SORT(j); REVE(j);

		LL ans = 0;
		LL psum = accumulate(all(p), 0);
		LL jsum = 0;

		rep(i, n) {
			if (i != 0)jsum += j[i - 1];
			LL sum = (psum + jsum) * (n - i);
			ans = max(ans, sum);
		}

		cout << ans << endl;
	}
}


Measured memory_bytes: 3952
import java.io.*;
import java.util.*;
public class Main{
	public static void main(String[] args)throws Throwable {
		MyScanner sc=new MyScanner();
		PrintWriter pw=new PrintWriter(System.out);
		
		int n=sc.nextInt();
		TreeSet<Integer> set=new TreeSet<Integer>();
		while(n-->0){
			int x=sc.nextInt();
			if(set.contains(x))
				set.remove(x);
			else
				set.add(x);
		}
		pw.println(set.size());
		pw.flush();
		pw.close();
	}
	
	static class MyScanner {
		BufferedReader br;
		StringTokenizer st;
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		String next() {while (st == null || !st.hasMoreElements()) {
			try {st = new StringTokenizer(br.readLine());}
			catch (IOException e) {e.printStackTrace();}}
		return st.nextToken();}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());}
		double nextDouble() {return Double.parseDouble(next());}
		String nextLine(){String str = "";
		try {str = br.readLine();}
		catch (IOException e) {e.printStackTrace();}
		return str;}
	}
}

Measured memory_bytes: 42532
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<string>
#include<iomanip>
#include<cstdio>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define MOD 1000000007
#define MAXS(x,y) (x = max(x,y))
#define MINS(x,y) (x = min(x,y))

using namespace std;

typedef long long int ll;

const ll INF=(ll)1e18;

vector<int> pre, in, post;

int N;
ll K;

vector<ll> a;
vector<int> b;
map<pair<ll, int>, ll> memo;


ll dp(ll k, int s){
  if(memo.count(make_pair(k,s))){
    return memo.at(make_pair(k,s));
  }

//  printf("dp %lld %d\n", k, s);
  if(s < 0)return 0;

  ll ans = 0;
  if(k < (1l<<s)){
    ans += b[s] * (1l<<s);
//    printf("ret %d %lld\n", s,ans);
    ans += dp(k, s-1);
    return ans;
  }else{

    // 1の時
    ll ans1 = (N-b[s]) * (1l<<s);
    ans1 += dp(k - (1l<<s), s-1);

    // 0の時
    ll ans0 = b[s] * (1l<<s);
    ans0 += dp(( 1l << s )-1, s-1);
    ans = max(ans1,ans0);
  }

  memo.insert(make_pair(make_pair(k,s), ans));
  return ans;
}

int main(){
  cin >> N >> K;

  a.resize(N);
  b.resize(50);
  REP(i,50)b[i] = 0;

  REP(i,N)cin >> a[i];


  REP(i,N)REP(j,50){
    if(a[i]&(1l<<j))b[j]+=1;
  }

  // REP(i,50){
  //   printf("%d %d\n", i, b[i]);
  // }

  ll ans = dp(K,49);

  cout << ans << endl;

}



Measured memory_bytes: 1152
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
 
 
using namespace std;
 
double EPS = 1e-10;
 
 
double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}
 
struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}
 
  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }
 
  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }

  point operator / (double d){
    return point(x/d,y/d);
  }
  
  bool operator == ( const point &p ) const {
    return abs(x-p.x) < EPS && abs(y-p.y) < EPS;
  }
};
 
bool cmp_x(const point& p, const point& q){
  if(p.x != q.x)return p.x<q.x;
  return p.y < q.y;
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

double norm(point a){
  return sqrt(a.x*a.x+a.y*a.y);
}

double dist(point a,point b){
  return sqrt(pow(a.x-b.x,2)+pow(a.y-b.y,2));
}

vector<point> NV(point a){
  vector<point>res; 
  point b;
  b.x=-a.y, b.y=a.x;
  res.push_back(b);
  b.x=a.y, b.y=-a.x;
  res.push_back(b);

  return res;
}

double areaPol(vector<point> t){
  t.push_back(t[0]);
  int tsz=t.size();
  double area=0;
  for(int i=0;i<tsz-1;i++){
    area+=(t[i].x-t[i+1].x)*(t[i].y+t[i+1].y);
  }
  return abs(area)/2.0;
}

vector<point>N;

bool Binary_search(point x){
  int l=0,r=N.size(),mid=(l+r)/2;
 
  while(r-l>1){
    if(N[mid]==x)return true;
 
    if(x.x < N[mid].x ||(N[mid].x==x.x && x.y < N[mid].y))r=mid;
    else l=mid;
 
    mid=(l+r)/2;
  }
 
  if(N[mid]==x)return true;
  return false;
}

double solve(void){

  double res=0;

  for(int i=0;i<N.size();i++){
    for(int j=i+1;j<N.size();j++){

      vector<point> nv=NV(N[j]-N[i]);
      point a=N[i]+nv[0],b=N[j]+nv[0];

      if(Binary_search(a) && Binary_search(b)){
	vector<point>c;
	c.push_back(N[i]);
	c.push_back(N[j]);
	c.push_back(b);
	c.push_back(a);
	res=max(res,areaPol(c));
      
      }
    }
  }
 return res;
}
 
int main(void){
  int n;
  point in;
 
  while(cin >> n){
    if(n==0)break;

    N.clear();   

    for(int i=0; i<n; i++){
      cin >> in.x >> in.y;
      N.push_back(in);
    }

    sort(N.begin(),N.end(),cmp_x);
    cout << (int)solve() << endl;
  }
 
  return 0;
}

Measured memory_bytes: 1352
import itertools

n = int(input())
nums = [i+1 for i in range(n)]

a = list(map(int, input().split()))
b = list(map(int, input().split()))

i_a = 0
i_b = 0

for i, p in enumerate(itertools.permutations(nums)):
    if a == list(p):
        i_a = i+1
    if b == list(p):
        i_b = i+1

    if i_a and i_b:
        break

print(abs(i_a - i_b))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, m, n) for (ll i = m; i < (n); i++)
#define RFOR(i, m, n) for (ll i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << (ele) << "\n"
#define print10(ele) cout << fixed << setprecision(10) << (ele) << "\n"

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  string s;
  cin >> s;
  if (s[2] == s[3] && s[4] == s[5]) {
    print("Yes");
  } else {
    print("No");
  }
  return 0;
}

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

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

#define pb push_back
#define rep(i, n) for(int i = 0; i < (n); i++)
#define FOR(i, a, n) for(int i = a; i < (n); i++)
#define mod (ll)(1e9+7)
#define int ll

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

signed main() {
	ll n, a, b, aa = 0, bb = 0, result = 1000000000;
  cin >> n;
  for(int i = 1; i <= n / 2; i++) {
    a = i, b = n - a;
    aa = bb = 0;
    while(a > 0) {
      aa += a % 10;
      a /= 10;
    }
    while(b > 0) {
      bb += b % 10;
      b /= 10;
    }
    result = min(result, aa + bb);
  }
  cout << result << endl;
}

Measured memory_bytes: 256
s = gets.chomp.split('').map{|c| 1<<(c.ord-97)}
N = s.length
hash = Hash.new(10**9)
hash[0] = 0
dp = Array.new(N, 0)
sum = 0
cand = 26.times.map{|i| 1<<i} + [0]
N.times do |i|
    sum ^= s[i]
    dp[i+1] = dp[i] + 1
    cand.each do |c|
        dp[i+1] = hash[sum^c] + 1 if dp[i+1] > hash[sum^c] + 1
    end
    hash[sum] = dp[i+1] if hash[sum] > dp[i+1]
end
puts dp[N]

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

int main()
{
	char a[10],b[10],c[10];
	string s=" ";
	cin>>a>>b>>c;
	s+=toupper(a[0]);
	s+=toupper(b[0]);
	s+=toupper(c[0]);
	cout<<s<<endl;
}


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

int main(){
  int n,m,a,b,cost,time,k,p,q,r;
  int t[100][100],c[100][100];

  for(;;){
    cin >> n >> m;
    if(!n && !m)break;

    for(int i=0;i<m;i++){
      for(int j=0;j<m;j++){
	if(i==j){
	  t[i][j] = 0;
	  c[i][j] = 0;
	}else{
	  t[i][j] = 1000000;
	  c[i][j] = 1000000;
	}
      }
    }

    for(int i=0;i<n;i++){
      cin >> a >> b >> cost >> time;
      t[a-1][b-1] = time;
      t[b-1][a-1] = time;
      c[a-1][b-1] = cost;
      c[b-1][a-1] = cost;
    }

    for(int x=0;x<m;x++){
      for(int i=0;i<m;i++){
	for(int j=0;j<m;j++){
	  t[i][j] = min(t[i][j],t[i][x] + t[x][j]);
	  c[i][j] = min(c[i][j],c[i][x] + c[x][j]);
	}
      }
    }

    cin >> k;
    for(int i=0;i<k;i++){
      cin >> p >> q >> r;
      if(r)cout << t[p-1][q-1] << endl;
      else cout << c[p-1][q-1] << endl;
    }
  }
}

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

int main()
{
    int H, W, i, j;
    for (;;) {
        cin >> H >> W;
        if ((H == 0) && (W == 0))
            break;
        for (i = 0; i < H; i++) {
            for (j = 0; j < W; j++) {
                if ((i + j) % 2 == 0)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007
int main(){
    int n,m;
    cin>>n>>m;
    int a[30][30]={};
    rep(i,n){
        int k;
        cin>>k;
        for(int j=0;j<k;j++){
            cin >> a[i][j];
            //cout<<a[i][j]<<" ";
        }
        //cout<<endl;
    }
    map<int,int> p;
    rep(i,n){
        for(int j=0;j<30;j++){
            if(a[i][j]!=0){
            p[a[i][j]]++;
            //cout<<"food:"<<a[i][j]<<endl;
            }
            //
        }
    }
    int ans=0;
    for(auto c:p){
        int food = c.first;
        int count = c.second;
        //cout<<"food"<<food<<":"<<count<<endl;
        if(count==n){
            ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second
#define debug(x) cerr<<#x<<" "<<x<<endl;
#define f(i,n) for(ll i=0; i<n; i++)
#define f1(i,n) for(ll i=1; i<=n; i++)
#define fr(i,n) for(ll i=n-1; i>=0; i--)
#define f1r(i,n) for(ll i=n; i>0; i--)
#define mst(arr,val) memset(arr,val,sizeof(arr))
#define all(x) x.begin(),x.end()

typedef long long int ll;
typedef pair<ll,ll> pii;
ll M=1e9+7;
ll M2=998244353;
void show(vector<ll> v)
{
    for(int i=0; i<v.size(); i++)
        cout<<v[i]<<" ";
    cout<<"\n";
}
void showrev(vector<ll> v)
{
    for(int i=0; i<v.size(); i++)
        cout<<v[v.size()-i-1]<<" ";
    cout<<"\n";
}
void showarr(ll arr[],ll n)
{
    for(ll i=0; i<n; i++)
        cout<<arr[i]<<" ";
    cout<<"\n";
}
void showpv(vector<pair<ll,ll> > v)
{
    f(i,v.size())
        cout<<"("<<v[i].ff<<","<<v[i].ss<<")"<<" ";
    cout<<"\n";
}
void showmap(map<ll,ll> m)
{
    for(auto i:m)
        cout<<" ("<<i.ff<<","<<i.ss<<") ";
    cout<<"\n";
}
int main()
{
    IOS
    ll T = 1,Q=1;
    //cin>>T;

    while(T--)
    {
        ll n;   cin>>n;
        ll a[n],dp[n];
        f(i,n)
            cin>>a[i];
        dp[0] = 0;
        dp[1] = abs(a[1]-a[0]);
        for(ll i=2; i<n; i++)
        {
            dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
        }
        cout<<dp[n-1];
    }
    return 0;
}


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

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

    if(max(A,C) - min(A,C) <= D){
        cout << "Yes" << endl;
    }
    else if(max(A,B) - min(A,B) <= D && max(B,C) - min(B,C) <= D){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

int main() {
  char aft[26];

  aft[0] = 'X'; aft[1] = 'Y'; aft[2] = 'Z';
  for(int i = 0; i < 23; i++) aft[i+3] = 'A'+i;

  string str; cin >> str;
  
  for(int i = 0; i < str.length(); i++)
    str[i] = aft[str.at(i)-'A'];

  cout << str << endl;
    
  return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define has(c,i) ((c).find(i) != end(c))
#define DBGDO(X) ({ if(1) cerr << "DBGDO: " << (#X) << " = " << (X) << endl; })

char a = 'A', b = 'B';

void sim(string s, ll iters = 80) {
	ll n = sz(s);
	while (iters--) {
		cout << s << endl;
		ll i = 0, di = 1;
		while (i >= 0 && i < n) {
			if (s[i] == a) di = -di;
			if (s[i] == a) s[i] = b; else s[i] = a;
			i += di;	
		}
	}
}

char neg(char c) {
	if (c == a) return b;
	return a;
}

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

	ll n, k; cin >> n >> k;
	string s; cin >> s;
//	for (char &c: s) if (c == 'A') c = a; else c = b;
//	sim(s);
	
	ll i = 0, flip = 0;
	
	while (k--) {
		char c = flip ? neg(s[i]) : s[i];

		if (c == a) {
			s[i] = neg(s[i]);
		} else {
			flip = !flip;
			i++;
			s.pb(flip ? b : a);
		}
		if (i == n) k %= 2;
	}	
	if (flip) for (char &c: s) c = neg(c);
	cout << s.substr(i) << endl;
}



Measured memory_bytes: 1176
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
#include<functional>
using namespace std;

#define ll long long
#define MOD 1000000007
#define INF (1<<30)
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	ll N, M; cin >> N >> M;
	vector<pair<ll, ll>> ab(N+1), cd(M+1);
	for (int i = 1; i <= N;i++)cin >> ab[i].first >> ab[i].second;
	for (int i = 1; i <= M;i++) cin >> cd[i].first >> cd[i].second;
	for (int i = 1; i <= N;i++) {
		ll minv = INF, ans = -1;
		for (int j = 1; j <= M;j++) {
			ll man = abs(ab[i].first - cd[j].first) + abs(ab[i].second - cd[j].second);
			if (man < minv) {
				minv = man;
				ans = j;
			}
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 256
A,B,C,X,Y = map(int, input().split())
cost = 0
if X == Y:
    cost = X*min(A+B, 2*C)
if X < Y:
    cost = X*min(A+B, 2*C)
    R = Y-X
    cost += R*min(B, 2*C)
if Y < X:
    cost = Y*min(A+B, 2*C)
    R = X-Y
    cost += R*min(A, 2*C)
print(cost)

Measured memory_bytes: 3064
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <climits>
#include <queue>
#include <map>
#include <string>
#include <iostream>
using namespace std;
map<string,int> dp;
int dir[4]={-1,1,-4,4};
void bfs()
{
    string t="01234567";
    dp[t]=0;
    queue<string> que;
    que.push(t);
    while(!que.empty())
    {
        int p=0;
        string t=que.front();que.pop();
        for(int i=0;i<8;i++)
            if(t[i]=='0')
        {
            p=i; break;
        }
        for(int i=0;i<4;i++)
        {
            int n=p+dir[i];
            if(n<0||n>7||(p==3&&i==1)||(p==4&&i==0)) continue;
            string next = t;
            swap(next[n],next[p]);
            if(dp.find(next)==dp.end())
            {
                dp[next]=dp[t]+1;
                que.push(next);
            }
        }
    }
}
int main()
{
    bfs();
    string line;
    while (getline(cin, line))
    {
        line.erase(remove(line.begin(), line.end(), ' '), line.end());
        cout << dp[line] << endl;
    }
    return 0;
}

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

int main() {
  string s,t,u;
  int a,b;

  cin >> s >> t >> a >> b >> u;

  if(s.compare(u) == 0){
    a--;
  }else{
    b--;
  }

  cout << a << " " << b << endl;
}

Measured memory_bytes: 256
s = input().rstrip().split()
t = list(map(lambda x:int(x),s))

if(abs(t[0] - t[2]) <=t[3] or (abs(t[0]-t[1]) <= t[3] and  abs(t[1] -t[2]) <= t[3])):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3316