akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const ll inf = 1e18;
int main() {
    ll h, w; cin >> h >> w;
    ll ans = inf;
    if(h%3==0 || w%3==0) {
        ans = 0;
    } else {
        // fix H
        for(int i=1;i<w;i++) {
            vector<ll> vc;
            vc.push_back(h * i);
            vc.push_back((w-i) * (h/2));
            vc.push_back((w-i) * (h-h/2));
            sort(vc.begin(), vc.end());
            ans = min(ans, vc[2] - vc[0]);
        }

        // fix W
        for(int i=1;i<h;i++) {
            vector<ll> vc;
            vc.push_back(w * i);
            vc.push_back((h-i) * (w/2));
            vc.push_back((h-i) * (w-w/2));
            sort(vc.begin(), vc.end());
            ans = min(ans, vc[2] - vc[0]);
        }
        ans = min(ans, w);
        ans = min(ans, h);
    }
    cout << ans;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include <cmath>
#include <limits>
#include <numeric>

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

int main(){
    char s[200005]={};
    scanf("%s",s);
    int len=strlen(s);
    int rem=0;
    int flag=0;
    for(int i=0;i<len;i++){
        //printf("###%d\n",i);
        if(i>=1){
            if(s[i]==s[i-1] && flag==0){
                rem++;
                flag=1;
                i++;
            }
            else{
                flag=0;
            }
        }
    }
    printf("%d\n",len-rem);
    return 0;
}

Measured memory_bytes: 384
from itertools import *

D, G = map(int,input().split())

P = [None]*D
C = [None]*D

for i in range(D) :
    P[i], C[i] = map(int,input().split())

products = product(range(2), repeat=D)

ans = float("inf")

for prod in products :
    prod = list(prod)
    
    A = []
    
    cost = 0
    score = 0
    
    for i in range(len(prod)) :
        if prod[i] == 1 :
            A.append(i)
            cost += P[i]
            score += (i+1)*100*P[i]+C[i]
    
    if score < G :
        for i in range(len(prod)-1,-1,-1) :
            if prod[i] == 1 :
                continue
            
            if score + (i+1)*100*P[i] >= G :
                if G-score < 0 :
                    continue
                cost += (G-score)//((i+1)*100) + ((G-score) % ((i+1)*100) != 0)
                break
            
            else :
                cost += P[i]
                score += (i+1)*100*P[i]+C[i]
    
    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>

int main(void){
	int ans[101], i, a=0, j;
	int stnum;
	double weight, hight;
	
	for(i=0;i<=100;++i){
		ans[i] = 0;
	}
	
	while(scanf("%d,%lf,%lf",&stnum, &weight, &hight)!=EOF){
		if(weight/(hight*hight)>=25){
			ans[a] = stnum;
			a++;
		}
	}
	
	for(j=0;j<a;++j){
		printf("%d\n",ans[j]);
	}
	
	return 0;
}

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

using namespace std;
using ll = long long;

class UnionFind {
public:
  vector<int> par;
  UnionFind(int n) {
    par = vector<int>(n + 1);
    for (int i = 1; i <= n; i++) {
      par[i] = i;
    }
  }
  int root(int x) {
    if (par[x] == x) {
      return x;
    }
    return par[x] = root(par[x]);
  }
  void unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) {
      return;
    }
    par[x] = y;
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
};

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k, l;
  cin >> n >> k >> l;
  auto uf1 = UnionFind(n);
  auto uf2 = UnionFind(n);
  for (int i = 0; i < k; i++) {
    int p, q;
    cin >> p >> q;
    uf1.unite(p, q);
  }
  for (int i = 0; i < l; i++) {
    int r, s;
    cin >> r >> s;
    uf2.unite(r, s);
  }
  map<pair<int, int>, int> mp;
  for (int i = 1; i <= n; i++) {
    mp[make_pair(uf1.root(i), uf2.root(i))]++;
  }
  for (int i = 1; i <= n; i++) {
    if (i < n) {
      cout << mp[make_pair(uf1.root(i), uf2.root(i))] << " ";
    } else {
      cout << mp[make_pair(uf1.root(i), uf2.root(i))] << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 13568
n, c = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(n)]

# 同チャンネルの連続する放送を一つにまとめる
stc.sort(key=lambda x: (x[2], x[0]))
 
imos = [0] * (10**5 + 1)

curr_c = 0
curr_t = 0
for s, t, c in stc:
  if curr_c == c and curr_t == s:
    imos[s] += 1
  else:
    imos[s-1] += 1
  imos[t] -= 1
  curr_t = t
  curr_c = c
  
rui = [0] * (10**5 + 1)

for i in range(10**5):
  rui[i+1] = rui[i] + imos[i]
  
print(max(rui))


Measured memory_bytes: 35432
n, k = map(int, raw_input().split())
ab = {}
for i in range(n):
    l = map(int, raw_input().split())
    if l[0] not in ab:
        ab[l[0]] = [l[1]]
    else:
        ab[l[0]].append(l[1])
key = sorted(ab.keys())
x = 0
for i in key:
    sum = 0
    for j in ab[i]:
        sum += j
    x += sum
    if k <= x:
        print i
        break


Measured memory_bytes: 19884
#include<stdio.h>
#include<stdlib.h>

int partition(int *A,int p,int r){
  int x,i,j,a;
  x=A[r];
  i=p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      a=A[i];
      A[i]=A[j];
      A[j]=a;
    }
  }
  a=A[i+1];
  A[i+1]=A[r];
  A[r]=a;
  return i+1;
}

int main(){
  int n,*A,i,j;

  scanf("%d",&n);
  A=(int *)malloc(n*sizeof(int));
  for(i=0;i<n;i++) scanf("%d",&A[i]);
 
 j=partition(A,0,n-1);

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

  return 0;
}



Measured memory_bytes: 2132
rewards = 0

c, d = input().split(" ")

rewards += 300000 if c == "1" else 0
rewards += 200000 if c == "2" else 0
rewards += 100000 if c == "3" else 0

rewards += 300000 if d == "1" else 0
rewards += 200000 if d == "2" else 0
rewards += 100000 if d == "3" else 0

rewards += 400000 if c == "1" and d == "1" else 0
  
print(rewards)

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

int main() {
    vector<int> a(3);
    for (auto& e : a) cin >> e;
    sort(begin(a), end(a));
    int ans = 1e9;
    do {
        ans = min(abs(a[1] - a[0]) + abs(a[2] - a[1]), ans);
    } while (next_permutation(begin(a), end(a)));
    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
int main(void)
{
  short n;
  std::cin >> n;
  
  short t = n%10;
  
  switch(t)
  {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9: std::cout <<"hon"; break;
    case 0:
    case 1:
    case 6:
    case 8: std::cout <<"pon"; break;
    case 3: std::cout <<"bon"; break;   
  }
  
  return 0;  
}


Measured memory_bytes: 3604
S = gets.to_i
x = Array.new(3)
y = Array.new(3)
x[0] = 0; y[0] = 0;
if S == 10**18
    x[1] = 10**9; y[1] = 0; x[2] = 0; y[2] = 10**9
else
    x[1] = Math.sqrt(S).to_i + 1; y[2] = Math.sqrt(S).to_i + 1;
    a = S - (x[1] * y[2])
    x[2] = 1; y[1] = -a;
end
printf("%d %d %d %d %d %d", x[0], y[0], x[1], y[1], x[2], y[2]);


Measured memory_bytes: 1788
#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()
using namespace std;

int main(){
  int h,w;  cin >> h >> w;
  string s,ss,sss,s_last="";
  for(int i=0;i<w;i++){
    s += ".";
  }
  s_last = s;
  cin >> ss ;
  if(h>1) cin >> sss;
  else sss = s_last;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      int num = 0;
      if(ss.at(j)=='#'){
        printf("#");
      }else{

        if(j!=0){
          if(s.at(j-1)=='#') num++;
          if(ss.at(j-1)=='#') num++;
          if(sss.at(j-1)=='#') num++;
        }

        if(s.at(j)=='#') num++;
        if(sss.at(j)=='#') num++;

        if(j!=w-1){
          if(s.at(j+1)=='#') num++;
          if(ss.at(j+1)=='#') num++;
          if(sss.at(j+1)=='#') num++;
        }

        printf("%d",num);
      }
    }
    puts("");
    s = ss;
    ss = sss;
    if(i==h-2){
      sss = s_last;
      continue;
    }
    if(i<h-1) cin >> sss;
  }

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#define int long long
using namespace std;

int n, t;
int h[100000];
int s[100000];    //s[i] = 人iが1回目を終える時刻

signed main() {
    int i;
    
    cin >> n >> t;
    for (i = 0; i < n; i++) {
        cin >> h[i];
    }
    
    int hsum = 0;
    for (i = 0; i < n; i++) {
        hsum += h[i];
        s[i] = hsum;
    }
    
    for (i = 1; i < n; i++) {
        h[i] = max(h[i], h[i - 1]);
    }
    
    for (i = 0; i < n; i++) {
        if (t < s[i]) {
            cout << 1 << endl;
        }
        else {
            cout << (t - s[i]) / h[i] + 2 << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 4648
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(123456789)
#define LINF (long long int)(123456789012345678)
#define MAX_V 1000

bool check(vector<int> a, int kind){
	//Aではない桁のみを入れてる
	map<int, int> mp;
	int memo = -1;
	//cout<<kind<<endl;
	rep(i,(int)a.size()){
		//cout<<memo<<" ";
		//for(auto itr = mp.begin(); itr != mp.end(); itr++){
			//cout<<"f: "<<itr->first<<" "<<itr->second<<" ";
		//}
		//cout<<endl;
		if(memo == a[i]){
			if(kind == 1){
				return false;
			}
			if((mp.find(memo) == mp.end() ? 1 : mp[memo]) < kind){
				if(mp.find(memo) == mp.end()){
					mp[memo] = 2;
				}else{
					mp[memo]++;
				}			
				continue;
			}else{
				mp.erase(memo);
				int memo2 = memo - 1;
				while(true){
					if(memo2 == 0){
						return false;
					}
					if((mp.find(memo2) == mp.end() ? 1 : mp[memo2]) < kind){
						if(mp.find(memo2) == mp.end()){
							mp[memo2] = 2;
						}else{
							mp[memo2]++;
						}
						break;
					}else{
						mp.erase(memo);
						memo2--;
					}
				}
			}
		}else if(memo > a[i]){
			if(kind == 1){
				return false;
			}
			for(auto itr = mp.begin(); itr != mp.end(); itr++){
				if(itr->first > a[i]){
					//cout<<itr->first<<endl;
					itr++;
					bool finish = false;
					if(itr == mp.end()){
						finish = true;
					}
					itr--;
					//itr++;
					mp.erase(itr);	
					if(finish){
						break;
					}
					//cout<<itr->first<<endl;
				}
			}
			//cout<<"hoge"<<endl;
			memo = a[i];
			//cout<<"hoge"<<endl;
			if((mp.find(memo) == mp.end() ? 1 : mp[memo]) < kind){
				if(mp.find(memo) == mp.end()){
					mp[memo] = 2;
				}else{
					mp[memo]++;
				}			
				continue;
			}else{
				mp.erase(memo);
				int memo2 = memo-1;
				while(true){
					if(memo2 == 0){
						return false;
					}
					if((mp.find(memo2) == mp.end() ? 1 : mp[memo2]) < kind){
						if(mp.find(memo2) == mp.end()){
							mp[memo2] = 2;
						}else{
							mp[memo2]++;
						}
						break;
					}else{
						mp.erase(memo);
						memo2--;
					}
				}
			}
		}else{
			memo = a[i];
		}
	}
	return true;
}

int main(void){
	int n,inp;
	cin>>n;
	vector<int> a;
	rep(i,n){
		cin>>inp;
		a.push_back(inp);
	}
	int down = 1, up = n+1;
	int now;
	while(up - down > 1){
		now = (up+down)/2;
		if(check(a,now)){
			up = now;
		}else{
			down = now;
		}
	}
	if(check(a, down)){
		cout<<down<<endl;
	}else{
		cout<<up<<endl;
	}
	

	return 0;
}






Measured memory_bytes: 1908
s = list(input())
n = len(s)
if s==s[::-1] and s[0:int((n-1)/2)]==s[0:int((n-1)/2)][::-1] and s[int((n+3)/2-1):n]==s[int((n+3)/2-1):n][::-1]:
  print('Yes')
else:
  print('No')


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    string s,t;

    cin>>s>>t;

    int ans=INT32_MAX;
    for(int i=0;i<s.length()-t.length()+1;i++)
    {
        int cur=0;
        for(int j=0;j<t.length();j++)
        {
            if(s[i+j]!=t[j])
            {
                cur++;
            }
        }

        ans=min(ans,cur);
    }

    cout<<ans;
}

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

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

  int flag=0;
  for(int i=-200; i<201; i++){
    for(int j=-200; j<201; j++){
      if(pow(i,5)-pow(j,5)==x){
        cout << i << " " << j << endl;
        flag=1;
        break;
      }
    }
    if(flag==1) break;
  }
}

Measured memory_bytes: 3976
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();
        int ans = 0;
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    if (500 * i + 100 * j + 50 * k == x) {
                        ans++;
                    }
                }
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23508
#include <bits/stdc++.h>
using namespace std;
#define ll long long int



int main()
{
    ll n;
    string s;
    cin >> n >> s;
    for(ll i = 0; i < s.length(); i++){
        if(s[i] + n > 'Z'){
            ll temp = s[i] - 'A';
            temp += n;
            temp %= 26;
            s[i] = temp + 'A';
        }else s[i] += n;
    }
    cout << s << endl;



}

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

int main()
{

	int N, now, num;
	int pnt[10];
	char c[101];

	while( cin >> N, N ) {

		now = 0;
		num = 0;
		for( int i = 0; i < 10; i++ ) pnt[i] = 0;

		cin >> c;

		// a 0
		for( int i = 0; i < 100; i++, now++ ) {

			if( now >= N ) now = 0;

			if( c[i] == 'M' ) pnt[now]++;
			else if( c[i] == 'S' ) { num += pnt[now] + 1; pnt[now] = 0; }
			else if( c[i] == 'L' ) { pnt[now] += num + 1; num = 0; }

		}

		sort( pnt, pnt + N );

		for( int i = 0; i < N; i++ ) cout << pnt[i] << " ";

		cout << num << endl;

	}

	return 0;

}

Measured memory_bytes: 1184
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef vector<int> vec;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

struct BIT {
private:
	vector<int> node; int n;
public:
	BIT(int n_) {
		n = n_; node.resize(n, 0);
	}
	void add(int a, int w) {
		for (int i = a; i < n; i |= i + 1)node[i] += w;
	}
	int sum(int a) {
		int ret = 0;
		for (int i = a - 1; i >= 0; i = (i&(i + 1)) - 1)ret += node[i];
		return ret;
	}
	int sum(int a, int b) {
		return sum(b) - sum(a);
	}
};

void solve() {
	int n;
	string s; cin >> s; n = s.length();
	vector<int> alf(26, 0);
	rep(i, n) {
		alf[s[i] - 'a']++;
	}
	vector<int> h(26, 0);
	rep(i, 26) {
		if (alf[i] % 2) {
			cout << -1 << endl; return;
		}
		h[i] = alf[i] / 2;
	}
	vector<int> a, b;
	vector<int> cnt(26, 0);
	ll ans = 0;
	int x = 0;
	rep(i, n) {
		int id = s[i] - 'a';
		if (cnt[id] < h[id]) {
			a.push_back(id);
			cnt[id]++;
			ans += x;
		}
		else {
			b.push_back(id);
			x++;
		}
	}
	reverse(b.begin(), b.end());
	vector<vector<int>> loc(26);
	rep(i, n / 2) {
		loc[a[i]].push_back(i);
	}
	vector<int> cur(26, 0);
	vector<int> trueloc(n / 2);
	rep(i, n / 2) {
		trueloc[i] = loc[b[i]][cur[b[i]]];
		cur[b[i]]++;
	}
	BIT bi(n/2);
	rep(i, n / 2) {
		int x = trueloc[i];
		ans += bi.sum(x,n/2);
		bi.add(x, 1);
	}
	cout << ans << endl;
}
signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	solve();
	//stop
		return 0;
}



Measured memory_bytes: 7472
#include<iostream>
    #include<cstdio>
    #include<vector>
    #include<algorithm>
    using namespace std;
    const int N = 100010;
    bool pr[N] = {0};
    int ans[N] = {0};
    void initialize()
    {
        pr[0] = 1;
        pr[1] = 1;
        int i,j;
        for(i=2;i<N;i++)
        {
            if(pr[i])
                continue;
            for(j=i*2;j<N;j+=i)
                pr[j] = 1;
        }
        ans[1] = 0;
        for(i=3;i<N;i+=2)
        {
            if(pr[i]==0 && pr[(i+1)/2]==0)
                ans[i] = ans[i-2]+1;
            else
                ans[i] = ans[i-2];
        }
    }
    int main()
    {
        initialize();
        int T;
        scanf("%d",&T);
        while(T--)
        {
            int l,r;
            scanf("%d%d",&l,&r);
            printf("%d\n",ans[r]-ans[l-2]);
        }
    }

Measured memory_bytes: 1152
#include<iostream>
using namespace std;
 
int main()
{
    long Q,H,S,D;
    cin >> Q >> H >> S >> D;
    long N;
    cin >> N;
    long min,min1;
    if(2*Q<H) min=2*Q;
    else min=H;
    if(2*min<S) min=2*min;
    else min=S;
    if(2*min<D) min1=2*min;
    else min1=D;
    long long sum;
    if(N%2==0) sum=(N/2)*min1;
    else sum=((N-1)/2)*min1+min;
    cout << sum << endl ;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <numeric>
#include <string>
#include <bitset>
#include <functional>

using ld = long double;
using vld = std::vector<ld>;
using vvld = std::vector<vld>;
using vvvld = std::vector<vvld>;
using ll = long long;
using vll = std::vector<ll>;
using vvll = std::vector<vll>;
using vvvll = std::vector<vvll>;
using pll = std::pair<ll, ll>;
using vpll = std::vector<pll>;
using str = std::string;
using vstr = std::vector<str>;

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

constexpr ld PI = 3.141592653589793L;
constexpr ld EPS = std::numeric_limits<ld>::epsilon();

ll gcd(ll n, ll m) { return m ? gcd(m, n % m) : n; }
ll lcm(ll n, ll m) { return n / gcd(n, m) * m; }
bool is_prime(ll n) {
    if (n == 1) return false;
    for (ll i = 2; i * i <= n; i++)
        if (n % i == 0) return false;
    return true;
}

/*------------------------------------------------------------------------*/

void solve();

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    std::cout << std::setprecision(15);

    solve();
}

void solve() {
    ll n, k;
    std::cin >> n >> k;

    vll p(n);
    for (ll i = 0; i < n; i++)
        std::cin >> p[i];

    std::sort(p.begin(), p.end());

    ll ans = std::accumulate(p.begin(), p.begin() + k, 0LL);

    std::cout << ans << '\n';
}


Measured memory_bytes: 3632
import java.util.*;
import static java.lang.System.*;
import java.math.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		
		for (int i=0; i<n; i++) {
			BigInteger a = new BigInteger(sc.next());
			BigInteger b = new BigInteger(sc.next());
			BigInteger c = a.add(b);
			if (a.toString().length()>80 || b.toString().length()>80 || c.toString().length()>80) {
				out.println("overflow");
			}
			else {out.println(c);}
		}
	}
}


Measured memory_bytes: 26368
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int D,N; cin>>D>>N;

    if(N==100) N++;
    int ans=pow(100,D)*N;
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
typedef long long LL;
int n;
LL f[6], ans;
char c[19];
int main()
{
	scanf("%d",&n);
	for(int i = 1; i <= n; i++)
	{
		scanf("%s", c);
		if(c[0] == 'M')
			f[0]++;
		if(c[0] == 'A')
			f[1]++;
		if(c[0] == 'R')
			f[2]++;
		if(c[0] == 'C')
			f[3]++;
		if(c[0] == 'H')
			f[4]++;
	}
	for(int i = 0; i < 5 ;i++)
		for(int j = i + 1; j < 5; j++)
			for(int k = j + 1; k < 5; k++)
				ans += f[i] * f[j] * f[k];
	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
vector<ll> l, p;

ll f(int N, ll X){
    ll ret = 0;
    if(N == 0) ret = 1;
    else if(X == 1) ret = 0;
    else if(1 < X && X <= l[N-1] + 1){
        ret = f(N-1,X-1);
    }else if(X == l[N-1] + 2){
        ret = p[N-1] + 1;
    }else if(l[N-1] + 2 < X){
        ret = p[N-1] + 1 + f(N-1, X-l[N-1]-2);
    }
    return ret;
}

int main(){
    int N;  ll X;
    cin >> N >> X;

    l = vector<ll>(N+1, 0);
    p = vector<ll>(N+1, 0);
    l[0] = 1;  p[0] = 1;
    for(int i=0; i<N; i++){
        l[i+1] = 2*l[i] + 3;
        p[i+1] = 2*p[i] + 1;
    }
    cout << f(N, X) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(obj)   (obj).begin(),(obj).end()

#define debug(var)  do{std::cout << __LINE__ << "> " << #var << ": ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

void Main() {
	int N; cin >> N;
	vi h(N);
	REP(i, N) cin >> h[i];

	vi dp(N, numeric_limits<int>::max());
	dp[0] = 0;
	REP(i, N - 1) {
		dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
		if (i < N - 2) dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));	
	}
	cout << dp[N - 1] << endl;
}

int main() {
    cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}


Measured memory_bytes: 1024
n=int(input())
ans=[]
isPrime=[True for i in range(55555+1)]
for i in range(2, 55555+1):
    if isPrime[i]:
        if str(i)[-1]=='3':
            ans.append(i)
            if len(ans)==n:
                break
        for j in range(2*i, 55555+1, i):
            isPrime[j]=False

for i in ans:
    print(i)

Measured memory_bytes: 3608
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

int main(void){
  int n;
  cin >> n;
  double t, a;
  cin >> t >> a;
  double h[n];
  int ans;
  double temp_diff = 1000000;
  for(int i =0; i < n; i++){
    cin >> h[i];
    if(abs(t-h[i]*0.006-a) < temp_diff){
      ans = i;
      temp_diff = abs(t-h[i]*0.006-a);
    }
  }
  cout << ans+1 << endl;

  
  return 0;
}

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

#define READ                freopen("in.txt", "r", stdin)
#define WRITE               freopen("out.txt", "w", stdout)

#define si(a)               scanf("%d", &a)
#define sii(a,b)            scanf("%d %d", &a, &b)
#define siii(a,b,c)         scanf("%d %d %d", &a, &b, &c)

#define CLR(a)              memset(a, 0, sizeof(a))
#define SET(a)              memset(a, -1, sizeof(a))

#define PI                  acos(-1.0)

#define pb                  push_back
#define mp                  make_pair
#define SORT(v)             sort(v.begin(), v.end())
#define REV(v)              reverse(v.begin(), v.end())
#define FOR(i, n)           for(int i=0; i<n; i++)
#define FOR1(i, n)          for(int i=1; i<=n; i++)
#define ROF(i, n)           for(int i=n-1; i>=0; i--)
#define ROF1(i, n)          for(int i=n; i>=1; i--)
#define LOOP(i, x, y)       for(int i=x; i<=y; i++)
#define fastIO()            ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);


typedef long long              LL;
typedef unsigned long long     ULL;
typedef vector<int>            VI;
typedef pair<int, int>         PII;
typedef pair<string, int>      PSI;
typedef pair<char, int>        PCI;

const int MAX = 100005;
const LL LMAX = 12158598925;
const double eps = 1e-9;
const int INF = 0x3f3f3f3f;

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

int arr[MAX];
LL dp[MAX];


LL solve(int pos)
{
    if(pos == 1) return 0;
    if(dp[pos] != -1) return dp[pos];

    LL ret = solve(pos-1) + abs(arr[pos] - arr[pos-1]);
    if(pos-2 > 0)
        ret = min(ret, solve(pos-2) + abs(arr[pos] - arr[pos-2]));

    return dp[pos] = ret;
}

int main()
{
//    READ;
//    WRITE;
    int n; si(n);
    memset(dp, -1, sizeof dp);

    FOR1(i, n) si(arr[i]);

    LL res = solve(n);

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 4480
class UnionFindPathCompression():
    def __init__(self, n):
        self.parents = list(range(n))
        self.size = [1] * n
    
    def find_root(self, x):
        if self.parents[x] == x:
            return x
        else:
            self.parents[x] = self.find_root(self.parents[x])
            return self.parents[x]
    def make_union(self, x, y):
        x = self.find_root(x)
        y = self.find_root(y)
        
        if x == y : return
        self.size[x] += self.size[y]
        self.parents[y] = x

def main():
    n, m = map(int, input().split())
    uf = UnionFindPathCompression(n)
    for _ in range(m):
        a, b = map(int, input().split())
        uf.make_union(a - 1, b - 1)
    
    ans = max(uf.size)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 18324
integer N,K
integer,allocatable,dimension(:)::x
integer l,r
integer ans,subans
read*,N,K
allocate(x(N))
read*,x
ans=huge(ans)
do i=1,N-K+1
  l=x(i);r=x(i+k-1)
  subans=min(abs(l),abs(r))+(r-l)
  ans=min(ans,subans)
end do
print"(I0)",ans
end

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

using namespace std;

int main(int argc, char *argv[]) {
	int N, A;
	cin >> N >> A;

	int yen500 = N / 500;
	int yen1 = N - (500 * yen500);

	cout << ((yen1 <= A) ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
// C - 怪文書 / Dubious Document
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;

#define MOD 1000000007
#define rp(i,n) for(int i=0;i<(n);i++)
#define irp(i,n) for(int i=(n);i>=0;i--)
#define up(i,s,e,d) for(int i=(s);i<(e);i+=(d))
#define dw(i,s,e,d) for(int i=(s);i>(e);i-=(d))
// #define in(x) cin>>(x)
#define ot(x) cout<<(x)
#define ote(x) cout<<(x)<<endl
#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define vecmax(v) (*max_element(v.begin(),v.end()))
#define range(v,x) (iota((v).begin(),(v).end(),(x)))
void bye(auto x, int code=0){cout<<(x)<<endl;exit(code);}
// int in(){int x;cin>>x;return x;}
int in(){int x;scanf("%d",&x);return x;}
// template<class T> T in(){T x;cin>>x;return x;}

void vprn(vector<int> &v){ for(int i=0;i<v.size();i++) cout<<v[i]<<(i<v.size()-1?",\t":"\n"); }
void vvprn(vector<vector<int>> &vv){ for(auto v:vv) vprn(v); }

// template<class T> void vprn(T &v, string s, string m, string e)
// {cout<<s;for(int i=0;i<v.size();i++)cout<<v[i]<<m;cout<<e;}
// template<class T> void vvprn(T &vv, string s, string m, string e)
// {for(auto v:vv) vprn(v,s,m,e);}

#define otreal(n,p) cout<<fixed<<setprecision(p)<<(n)

int main(){
	int n; cin>>n;
	// vector<string> S(n);
	vvi S(n,vi(26));
	// map<int,int> m;
	// ote('z'-'a');
	up(i,0,n,1){
	// 	// cin>>S[i];
		string s; cin>>s;
		// ote(s);
		for(auto e:s){
			// ote(e);
			S[i][e-'a']++;
		}
	}

	// vvprn(S);

	string ans;
	rp(i,26){
		int mini = 1e9;
		rp(j,n){
			if(mini>S[j][i]){
				mini = S[j][i];
			}
		}
		rp(k,mini){
			ans += i+'a';
		}
	}

	ote(ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define MOD 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define ALL(v) v.begin(), v.end()
typedef long long ll;

int main(){
    string s;
    cin >> s;
    if(s=="ABC")cout<< "ARC" <<endl;
    else cout << "ABC" << endl;
    return 0;

}


Measured memory_bytes: 3608
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const double EPS = 1e-9;

#include <climits>
template<class T = int, int INF = INT_MAX>
struct SegmentTree {
    vector<T> node;
    vector<int> node_i;
    int n;
    explicit SegmentTree(vector<T> a) {
        int n_ = a.size();
        n = 1;
        while(n < n_) n <<= 1;
        node.resize(2 * n - 1, INF);
        node_i.resize(2 * n - 1, INF);
        for(int i = 0; i < n_; i++) {
            node[n - 1 + i] = a[i];
            node_i[n - 1 + i] = i;
        }
        for(int i = n - 2; i >= 0; i--) {
            node_i[i] = node[2 * i + 1] < node[2 * i + 2] ? node_i[2 * i + 1] : node_i[2 * i + 2];
            node[i] = min(node[2 * i + 1], node[2 * i + 2]);
        }
    }
    explicit SegmentTree(int n_): SegmentTree(vector<T>(n_, INF)) {}
    void update(int i, T x) {
        i = n - 1 + i;
        node[i] = x;
        while(i > 0) {
            i = (i - 1) / 2;
            node_i[i] = node[2 * i + 1] < node[2 * i + 2] ? node_i[2 * i + 1] : node_i[2 * i + 2];
            node[i] = min(node[i * 2 + 1], node[i * 2 + 2]);
        }
    }
    pair<int, T> find(int a, int b, int k = 0, int l = 0, int r = 0) {
        if (l == 0 && r == 0) r = n;
        if (r <= a || b <= l) return make_pair(-1, INF);
        if (a <= l && r <= b) return make_pair(node_i[k], node[k]);

        pair<int, T> vl = find(a, b, 2 * k + 1, l, (l + r) / 2);
        pair<int, T> vr = find(a, b, 2 * k + 2, (l + r) / 2, r);
        return vl.second < vr.second ? vl : vr;
    }
};

int main() {
    int N, Q;
    cin >> N >> Q;
    SegmentTree<int, INT_MAX> seg(N);
    for (int q = 0; q < Q; q++) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            seg.update(x, y);
        } else {
            cout << seg.find(x, y + 1).second << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 5232
#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; cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    sort(all(a), greater<ll>());
    ll al = 0, bo = 0;
    rep(i,0,n){
        if(~i & 1)al += a[i];
        else bo += a[i];
    }

    cout << al - bo << endl;
}

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

class A
{
	static void Main()
	{
		Console.ReadLine();
		var r = new List<int>();
		foreach (var j in Console.ReadLine().Split().Select(int.Parse))
		{
			if (j - 1 > r.Count) { Console.WriteLine(-1); return; }
			r.Insert(j - 1, j);
		}
		foreach (var x in r) Console.WriteLine(x);
	}
}


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

int main()
{
  long N,i,r,d,mvs,temp,s;
  cin >> N;
  mvs = N;
  s = int(sqrt(N));
  for(i=1;i<=s;i++){
    r = N%i;
    if(r==0){
      d = N/i;
      temp = d+i-2;
      if(temp<mvs){
        mvs = temp;
      }
    }
  }
  cout << mvs << endl;
  return 0;
}

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

bool near(int &t, int &a, int &x, int &y) {
  return abs(t-x*0.006 - a) < abs(t-y*0.006 - a);
}

int main() {
  int n, t, a; cin >> n >> t >> a;
  vector<int> height(n);
  for (auto &h : height) cin >> h;
  int idx = 0;
  for (int i=0; i<n; ++i) {
    if (near(t, a, height[i], height[idx])) {
      idx = i;
    }
  }
  cout << idx+1 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
	int n,m,d,i,j,k,ans=0;
	scanf("%d %d %d",&n,&m,&d);
	char a[n][m+1];
	for(i=0;i<n;i++){
		scanf("%s",a[i]);
	}
	
//?¨???????
	for(i=0;i<n;i++){
		for(j=0;j<m-d+1;j++){
			if(a[i][j]=='.'){
				for(k=1;k<d;k++){
					if(a[i][j+k]!='.')break;
				}
				if(k==d)ans++;
			}
		}
	}
//?????????
	for(i=0;i<m;i++){
		for(j=0;j<n-d+1;j++){
			if(a[j][i]=='.'){
				for(k=1;k<d;k++){
					if(a[j+k][i]!='.')break;
				}
				if(k==d)ans++;
			}
		}
	}
	
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 1868
using System;
using System.Linq;

namespace C_sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();

                if (line == "0")
                {
                    break;
                }

                var digits = line.ToCharArray().Select(x => int.Parse(x.ToString()));
                var ans = digits.Sum();

                Console.WriteLine(ans);
            }
        }
    }
}



Measured memory_bytes: 16368
#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
 
const int N = 18;
 
int n;
vector <int> a, ans[1 << 18];
 
void add(vector <int> &c, int x){
    c.push_back(x);
    sort(c.rbegin(), c.rend());
    while(c.size() > 2) c.pop_back();
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    a.resize(1 << n);
    for(auto &i : a) cin >> i;
    for(int i = 0 ; i < (1 << n) ; i++){
        add(ans[i], a[i]);
    }
    for(int j = 0 ; j < n ; j++){
        for(int i = 1 ; i < (1 << n) ; i++){
            if((i >> j) & 1){
                for(auto &k : ans[i ^ (1 << j)]){
                    add(ans[i], k);
                }
            }
        }
    }
    int res = 0;
    for(int i = 1 ; i < (1 << n) ; i++){
        res = max(res, ans[i][0] + ans[i][1]);
        cout << res << "\n";
    }
}


Measured memory_bytes: 18432
// failed to generate code

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

#define MAX_N 200001

long long par[MAX_N]; // 親
long long rankuf[MAX_N]; // 木の深さ
// n要素で初期化
void init(long long n) {
	for (long long i = 0; i < n; i++) {
		par[i] = i;
    rankuf[i] = 0;
	}
}
// 木の根を求める
long long find(long long x) {
	if (par[x] == x) {
		return x;
	} else {
		return par[x] = find(par[x]);
	}
}
// xとyの属する集合を併合
void unite(long long x, long long y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (rankuf[x] < rankuf[y]) {
		par[x] = y;
	} else {
		par[y] = x;
		if (rankuf[x] == rankuf[y]) rankuf[x]++;
	}
}
// xとyが同じ集合に属するか否か
bool same(long long x, long long y) {
	return find(x) == find(y);
}

int main(){
	ll N, M;
	cin >> N >> M;	
	vector<ll> K(N);
	vector<vector<ll>> L(N);
	ll k = 0;
	init(200001);
	rep(i,N) {
		cin >> K[i];
		K[i];
		k += K[i];
		rep(j, K[i]) {
			ll a;
			cin >> a;
			a--;
			L[i].push_back(a);
			unite(i,a+N);
			// cout << i << " " << a+N << " " << find(i) << " " << find(a+N) << endl;
		}
	}
	bool flg = true;
	repn(i,N-1) {
		if (!same(0,i)) {
			flg = false;
			// cout << i << endl;
		}
	}
	if (flg) cout << "YES" << endl; else cout << "NO" << endl;
}


Measured memory_bytes: 9600
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<stdlib.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
using namespace std;

typedef pair<int, int> P;

bool pc1(const P& firstElof, const P& secondElof)
{//first降順
	return firstElof.first > secondElof.first;
}
bool pc2(const P& firstElof, const P& secondElof)
{//first昇順
	return firstElof.first < secondElof.first;
}
bool pc3(const P& firstElof, const P& secondElof)
{//second降順
	return firstElof.second > secondElof.second;
}
bool pc4(const P& firstElof, const P& secondElof)
{//second昇順
	return firstElof.second < secondElof.second;
}


int main() {
	int n, m;
	cin >> n >> m;
	vector<int>x(m);
	for (int i = 0; i < m; i++) {
		cin >> x[i];
	}
	sort(x.begin(), x.end());
	if (m > n) {
		vector<int>dif(m - 1);
		for (int i = 0; i < m - 1; i++) {
			dif[i] = abs(x[i] - x[i + 1]);
		}
		int sum = std::accumulate
		(dif.begin(), dif.end(), 0);
		sort(dif.begin(), dif.end());
		reverse(dif.begin(), dif.end());
		for (int i = 0; i < n - 1; i++) {
			sum -= dif[i];
		}
		cout << sum << endl;
	}
	else {
		cout << 0 << endl;
	}
}




Measured memory_bytes: 1024
let inputString = '';

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});
process.stdin.on('end', function() {
    const input = inputString.replace(/\s*$/, '')
        .split('\n')
        .map(str => str.replace(/\s*$/, ''));

    printNodes(Number(input.shift()), input);
});



const printNodes = (size, nodeInfoArr) => {
  const nodeArr = Array
    .from({ length: size }, generateInitialValue);
  const rootCandidates = {};
  for (let i=0; i<size; i++) {
    const [
      id,
      leftChild,
      rightChild,
    ] = nodeInfoArr[i]
      .split(' ')
      .map((s) => Number(s));

    let type = 'leaf';

    if (leftChild !== -1) {
      type = 'internal node';
      nodeArr[id].degree++;
      nodeArr[leftChild].parent = id;
      nodeArr[leftChild].sibling = rightChild;
      delete rootCandidates[leftChild];
    }

    if (rightChild !== -1) {
      type = 'internal node';
      nodeArr[id].degree++;
      nodeArr[rightChild].parent = id;
      nodeArr[rightChild].sibling = leftChild;
      delete rootCandidates[rightChild];
    }

    nodeArr[id].leftChild = leftChild;
    nodeArr[id].rightChild = rightChild;
    nodeArr[id].type = type;

    if (nodeArr[id].parent === -1) {
      rootCandidates[id] = true;
    } else {
      delete rootCandidates[id];
    }

    // console.log(`i: ${i}, ${JSON.stringify(nodeArr[id])}`);
  }

  // console.log(Object.keys(rootCandidates));
  const rootId = Object.keys(rootCandidates)[0];
  nodeArr[rootId].type = 'root';

  fillDepth(rootId, nodeArr);

  fillHeight(nodeArr);

  nodeArr.forEach(printNode);
};

const generateInitialValue = (_, index) => {
  return {
    id: index,
    leftChild: -1,
    rightChild: -1,
    parent: -1,
    sibling: -1,
    degree: 0,
    depth: 0,
    height: 0,
    type: 'leaf',
  };
};

const fillDepth = (id, nodeArr, depth = 0) => {
  nodeArr[id].depth = depth;
  const {
    leftChild,
    rightChild,
  } = nodeArr[id];
  if (leftChild !== -1) {
    fillDepth(leftChild, nodeArr, depth + 1);
  }
  if (rightChild !== -1) {
    fillDepth(rightChild, nodeArr, depth + 1);
  }
};

const fillHeight = (nodeArr) => {
  for (let i=0; i<nodeArr.length; i++) {
    const { id } = nodeArr[i];
    nodeArr[id].height = getHeight(id, nodeArr);
  }
}

const getHeight = (id, nodeArr) => {
  const {
    leftChild,
    rightChild,
  } = nodeArr[id];

  let leftHeight = 0;
  if (leftChild !== -1) {
    leftHeight = getHeight(leftChild, nodeArr) + 1;
  }

  let rightHeight = 0;
  if (rightChild !== -1) {
    rightHeight = getHeight(rightChild, nodeArr) + 1;
  }

  return Math.max(leftHeight, rightHeight);
};

const printNode = (node) => {
  console.log(`node ${node.id}: parent = ${node.parent}, sibling = ${node.sibling}, degree = ${node.degree}, depth = ${node.depth}, height = ${node.height}, ${node.type}`);
};


Measured memory_bytes: 16360
#include <iostream>
using namespace std;
int main(void){
	int n,max_id,max_value,id,a,b;

	while(true){
		scanf("%d",&n);
		if(n == 0)break;

		max_value = -1;

		for(int i = 0; i < n; i++){
			scanf("%d %d %d",&id,&a,&b);
			if(max_value < a + b){
				max_value = a + b;
				max_id = id;
			}
		}
		printf("%d %d\n",max_id,max_value);
	}

    return 0;
}



Measured memory_bytes: 3124
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll LCM(ll a,ll b){return (a*b)/GCD(a,b);}
 
//const int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
//const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main()
{
	string s;
	cin >> s;
	if (s[0] != s[1] and s[0] != s[2] and s[1] != s[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]

    x = II()
    def checkP(x):
        if x == 2 or x == 3:
            return True
        for i in range(3,int(x**0.5+1),2):
            if x % i == 0:
                return False
        return True
    
    if x == 2:
        print(2)
        return
    if x % 2 == 0:
        x += 1
    while True:
        if checkP(x):
            print(x)
            return
        else:
            x += 2


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
// Problem : A - Air Conditioner
// Contest : AtCoder - AtCoder Beginner Contest 174
// URL : https://atcoder.jp/contests/abc174/tasks/abc174_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#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,b,a) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
 
#define bug(x) cout<<#x<<"="<<x<<endl; 
#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()
#define ins insert
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ld pii=3.14159265359; 
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 200001; //check the limits, dummy
 
int main() 
{
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int X;
	cin>>X;
	if(X>=30)
		cout<<"Yes";
	else
		cout<<"No";
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

Measured memory_bytes: 3640
#include <stdio.h>

const int mod = 1000000007;

void add(int &a, int b)
{
	a += b;
	if (a >= mod)
		a -= mod;
}

void mul(int &a, int b)
{
	a = (long long)a * b % mod;
}

int omit[5050][5050],cat[5050],dono[13][5050],tmp[5050];
int N; char S[5050];

int main()
{
	scanf ("%d %s",&N,S);
	int l = 0;
	while (S[l]) l++;

	omit[0][0] = 1;
	for (int i=1;i<=N;i++){
		for (int j=0;j<i;j++){
			add(omit[i][j+1],omit[i-1][j]);
			add(omit[i][j+1],omit[i-1][j]);
			if (j - 1 >= 0) add(omit[i][j-1],omit[i-1][j]);
			else add(omit[i][0],omit[i-1][j]);
		}
	}

	cat[0] = 1;
	for (int i=1;i<=N;i++){
		for (int j=0;j<i;j++){
			int u = cat[j]; mul(u,cat[i-j-1]);
			add(cat[i],u);
		}
	}
	for (int i=1;i<=N;i++){
		for (int j=0;j<i;j++) mul(cat[i],2);
	}

	for (int i=0;i<=N/2;i++) dono[0][i] = cat[i];
	for (int k=1;k<13;k++){
		for (int i=0;i<=N/2;i++) for (int j=0;i+j<=N/2;j++){
			int u = dono[k-1][i];
			mul(u,dono[k-1][j]);
			add(dono[k][i+j],u);
		}
	}

	cat[0] = 1;
	for (int i=1;i<=N/2;i++) cat[i] = 0;
	for (int k=0;k<13;k++) if (l & (1 << k)){
		for (int i=0;i<=N/2;i++) tmp[i] = 0;
		for (int i=0;i<=N/2;i++) for (int j=0;i+j<=N/2;j++){
			int u = dono[k][i];
			mul(u,cat[j]);
			add(tmp[i+j],u);
		}
		for (int i=0;i<=N/2;i++) cat[i] = tmp[i];
	}

	int ans = 0;
	for (int i=0;i<N;i++){
		int v = omit[i][0];
		if (i + l <= N && (N - i - l) % 2 == 0){
			int u = cat[(N-i-l)/2];
			mul(u,v);
			add(ans,u);
		}
	}
	printf ("%d\n",ans);

	return 0;
}

Measured memory_bytes: 67328
n = gets.to_i

x=y=t=0
ans = 'Yes'

$<.each_with_index do |line|
  nt, nx, ny = line.split.map(&:to_i)
  time     = nt - t
  shortest = (nx-x).abs + (ny-y).abs
  
  unless time >= shortest && (time%2 == shortest%2)
      ans = 'No'
      break
  end
  
  t, x, y = nt, nx, ny
end

puts ans


Measured memory_bytes: 1788
n, k = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))

ans = -10**18

for i in range(n):
    tmp_score = 0
    pos = i
    cycle = 0
    for l in range(k):
        pos = p[pos]-1
        tmp_score += c[pos]
        ans = max(ans,tmp_score)
        cycle += 1
        if pos == i: break
    q,r = divmod(k,cycle)
    if r == 0 and q > 1:
        r = cycle
        q -= 1
    tmp_score *= q
    ans = max(ans,tmp_score)
    for _ in range(r):
        pos = p[pos]-1
        tmp_score += c[pos]
        ans = max(ans,tmp_score)        
print(ans)


Measured memory_bytes: 74320