akhauriyash/Code-Regression huggingface dataset:
import itertools

S = input()
ans = 0
if len(S) == 1:
    print(int(S))
    exit()
for s in itertools.product(range(2), repeat=len(S)-1):
    t = 0
    for i in range(len(S)-1):
        if s[i] == 1:
            ans += int(''.join(S[t:i+1]))
            t = i+1
        if len(S)-2 == i:
            ans += int(''.join(S[t:]))
print(ans)


Measured memory_bytes: 3060
def resolve():
  n = int(input())
  prev = 1e9+1
  ans = 0
  tmp = -1
  h = map(int, input().split())
  for a in h:
    if prev >= a:
      tmp += 1
    else:
      tmp = 0
    prev = a
    ans = max(ans, tmp)
  print(ans)
  return

if __name__ == "__main__":
  resolve()


Measured memory_bytes: 11132
#include <bits/stdc++.h>
#define int long long
#define f(i,n) for(int i=0;i<n;i++)
using namespace std;
main(){
    int x,y,z,n;cin>>x>>y>>z>>n;
    int a[x],b[y],c[z];
    vector<int>r;
    f(i,x)cin>>a[i];sort(a,a+x,greater<int>());
    f(i,y)cin>>b[i];sort(b,b+y,greater<int>());
    f(i,z)cin>>c[i];sort(c,c+z,greater<int>());
    f(i,x)f(j,y)f(k,z)if((i+1)*(j+1)*(k+1)<=n)r.push_back(a[i]+b[j]+c[k]);
    sort(r.begin(),r.end(),greater<int>());
    f(i,n)cout<<r[i]<<'\n';
}

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

vector<vector<int>> x; //normal
vector<vector<int>> y; //reverse
vector<int> order;
bool vis[10005]={};
int com[10005]={};

void dfs1(int now){
	vis[now]=1;
	for (int v:x[now]){
		if (!vis[v])dfs1(v);
	}
	order.push_back(now);
}

void dfs2(int now,int count){
	vis[now]=1;
	for (int v:y[now]){
		if (!vis[v])dfs2(v,count);
	}
	com[now]=count;
}



int main(){
	int n,f;
	cin>>n>>f;
	x.resize(n);
	y.resize(n);
	for (int i=0;i<f;i++){
		int from,to;
		cin>>from>>to;
		x[from].push_back(to);
		y[to].push_back(from);
	}
	
	for (int i=0;i<n;i++){
		if (!vis[i])dfs1(i);
	}
	for (int i=0;i<n;i++)vis[i]=0;
	int count=1;
	for (int i=0;i<n;i++){
		int z=order[n-1-i];
		if (!vis[z])dfs2(z,count);
		count++;
	}
	int q;
	cin>>q;
	for (int i=0;i<q;i++){
		int t1,t2;
		cin>>t1>>t2;
		if (com[t1]==com[t2])cout<<1<<endl;else cout<<0<<endl;
	}
//	cout<<com[0]<<endl;
}


Measured memory_bytes: 4708
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <string>
#define ll long long
using namespace std;

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

	if (a >= 3200) {
		cout << s;
	}
	else {
		cout << "red";
	}

	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
import numba
from numba import njit, b1, i4, i8
from numba.types import Omitted

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

MOD = 1_000_000_007

@njit((i8, i8[:, :]), cache=True)
def main(N, G):
    pow2 = np.empty(1000, np.int64)
    pow2[0] = 1
    for n in range(1, 1000):
        pow2[n] = pow2[n - 1] * 2 % MOD
    # 部分集合 s に対して、s の中に含まれる辺の個数
    dp1 = np.zeros(1 << N, np.int64)
    for b in range(N):
        for a in range(b):
            if G[a, b]:
                s = 1 << a | 1 << b
                dp1[s] += 1
    for n in range(N):
        for s in range(1 << N):
            t = s | 1 << n
            if s == t:
                continue
            dp1[t] += dp1[s]
    # 部分集合 0 in s に対して、0 から出発して s の中を全域に動ける s の中の決め方
    dp2 = np.zeros(1 << N, np.int64)
    for s in range(1 << N):
        if not s & 1:
            continue
        x = pow2[dp1[s]]  # 全体
        t = s
        while t:
            t = (t - 1) & s
            if not t & 1:
                continue
            # s の中の辺を使ったときに、ちょうど可動域が t に一致する場合を求める
            y = dp2[t]
            e1 = dp1[s ^ t]  # 自由に決める
            e2 = dp1[s] - dp1[t] - e1  # 内向きに決めるしかない
            y = y * pow2[e1] % MOD
            x -= y
        dp2[s] = x % MOD
    # 部分集合 1 in s に対して、1 から出発して s の中を全域に動ける s の中に決め方
    dp3 = np.zeros(1 << N, np.int64)
    for s in range(1 << N):
        if not s & 2:
            continue
        x = pow2[dp1[s]]  # 全体
        t = s
        while t:
            t = (t - 1) & s
            if not t & 2:
                continue
            # s の中の辺を使ったときに、ちょうど可動域が t に一致する場合を求める
            y = dp3[t]
            e1 = dp1[s ^ t]  # 自由に決める
            e2 = dp1[s] - dp1[t] - e1  # 内向きに決めるしかない
            y = y * pow2[e1] % MOD
            x -= y
        dp3[s] = x % MOD

    # 答の計算をする
    full = (1 << N) - 1
    ans = pow2[dp1[full]]
    # 1 から出発していける集合がちょうど s
    for s in range(1 << N):
        sc = full ^ s
        if not s & 1:
            continue
        if not sc & 2:
            continue
        t = sc + 1
        while t:
            t = (t - 1) & sc
            if t & 2:
                u = full ^ s ^ t
                # (s,t)-edge の個数
                e = dp1[s | t] - dp1[s] - dp1[t]
                if e:
                    continue
                x = dp2[s] * dp3[t] % MOD  # s, t での決め方
                x = x * pow2[dp1[u]] % MOD  # u 内での決め方
                ans -= x
    return ans % MOD

N, M = map(int, readline().split())
G = np.zeros((N, N), np.int64)
for _ in range(M):
    a, b = map(int, readline().split())
    a, b = a - 1, b - 1
    G[a, b] = 1
    G[b, a] = 1

print(main(N, G))

Measured memory_bytes: 107344
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <time.h>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iomanip>
using namespace std;


int main()
{
    int n, t;
    cin >> n;
    int x[n];
    int y[n];
    double total = 0, root, max = 0;

    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < n; i++) {
        cin >> y[i];
        if (abs(x[i] - y[i]) > max) max = abs(x[i] - y[i]);
    }

    for (int j = 1; j < 4; j++){
        for (int i = 0; i < n; i++) {
            total += pow(abs(x[i] - y[i]), j);
        }
        root = 1.0 / j;
        printf("%.10f\n", pow(total, root));
        total = 0;
    }
    printf("%.10f\n", max);
    return 0;
}

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

int main() {
  int A, B, C, D;
  int L, R;
  cin >> A >> B >> C >> D;
  
  L = A + B;
  R = C + D;
  
 // cout << x << endl << y <<endl;
 
	  if (L > R){
	    cout << "Left" << endl;
	  }
 	 else if (L < R)  {
     	 cout << "Right" << endl;
    	}
  	else if (L == R) {
      	cout << "Balanced" << endl;
  }
}

Measured memory_bytes: 256
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lld;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
#define dme cout<<"-1"<<endl;return 0
const int mod=1000000007;
const int big=1e9+10;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
//19:04~
int main(void){
	llint ans=0;
	int n,i,j,k;cin>>n;
	llint di[300][300]={0};
	for(i=0;i<n;i++){
		for(j=0;j<n;j++){
			cin>>di[i][j];
		}
	}
	for(i=0;i<n;i++){
		for(j=0;j<i;j++){
			for(k=0;k<n;k++){
				if(di[i][j]>di[i][k]+di[k][j]){dme;}
				if(i==k||j==k){continue;}
				if(di[i][j]==di[i][k]+di[k][j]){ans-=di[i][j];break; }
			}
			ans+=di[i][j];
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>

using namespace std; 


const int N = 1e5 + 5; 
int n;
int s[N];
int t[N];
int ans; 
int s2[N];
int t2[N]; 
map<int, int> cnt1;
map<int, int> cnt2;
map<int, int> par; 
int solve1(int x)
{
	if (par[x] == x)
	{
		return x; 
	}
	return par[x] = solve1(par[x]); 
}

void solve2(int x,int y)
{
	x = solve1(x);
	y = solve1(y); 
	if (x != y)
	{
		par[y] = x; 
	}
}

int main()
{
	cin >> n; 
	for (int i = 1; i <= n; i++) 
	{
		cin >> s[i]; 
	}
	for (int i = 1; i <= n; i++) 
	{
		cin >> t[i]; 
	}
	for (int i = 1; i <= n; i++)
	{
		s[n + 1] ^= s[i]; 
		t[n + 1] ^= t[i]; 
	}
	for (int i = 1; i <= n + 1; i++)
	{
		par[s[i]] = -1; 
		par[t[i]] = -1; 
	}
	for (int i = 1; i <= n + 1; i++)
	{ 
		cnt1[s[i]]++;
	}
	for (int i = 1; i <= n + 1; i++) 
	{
		cnt2[t[i]]++;
	}
	for (int i = 1; i <= n; i++) 
	{
		if (cnt2[t[i]]!=cnt1[t[i]])
		{
			cout << -1; 
			return 0; 
		}
	}
	bool check = true; 
	for (int i = 1; i <= n + 1; i++) 
		if (s[i] != t[i]) 
		{
			check = false; 
		}
	if (check)
	{
		cout << 0; 
		return 0; 
	}
	for (int i = 1; i <= n + 1; i++)
	{
		if (s[i] != t[i] || i == n + 1)
		{
			if (i != n + 1) 
			{
				ans++; 
			}
			if (par[s[i]] == -1) 
			{
				par[s[i]] = s[i]; 
			}
			if (par[t[i]] == -1) 
			{
				par[t[i]] = t[i]; 
			}
			if (i != n + 1) 
			{
				solve2(s[i],t[i]); 
			}
		}
	}
	for (auto &it : par) 
	{
		if (solve1(it.first) == it.first) 
		{
			ans++; 
		}
	}
	cout << ans - 1; 
}



Measured memory_bytes: 16768
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

struct mint {
  LL x; 
  mint(LL x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(LL t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;//factに階乗を計算、ifactはその各々に対する逆元
  combination(LL n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (LL i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (LL i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(LL n,LL k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

LL N,K;

LL ans = 0;

void solve(){
	if(K>=N-1) K=N-1; 
	mint cases = 0;
	combination c(N+2);
	for(int i=0;i<=K;i++){
		cases += c(N,i)*c(N-1,N-i-1);
	}
	ans = cases.x;
}
 
int main(){
    cin >> N >> K;
 
    solve();

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

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

using namespace std;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define stl_repr(itr, x) for (auto itr = x.rbegin(); itr != x.rend(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

using llong = long long int;

const static int MOD = 1000000007;
const static int IINF = INT_MAX;
const static llong LINF = LLONG_MAX;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

template<typename T> T my_gcd(T a, T b) {
    return (a ? my_gcd(b % a, a) : b);
}
template<typename T> T my_lcm(T a, T b){
    return a * b / my_gcd(a, b);    
}

const int MAX = 999999;

llong fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int x, y;
    cin >> x >> y;
    if ((2 * y - x) % 3 != 0 || (2 * x - y) % 3 != 0) {
    	cout << 0 << endl;
    	return 0;
    }

    COMinit();
    int n = (2 * y - x) / 3, m = (2 * x - y) / 3;
    cout << COM(n + m, n) << endl;

    return 0;
}

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

int main()
{
	int a,b;
	cin>>a>>b;
	if((a*b)%2==0)
		cout<<"Even"<<endl;
	else
		cout<<"Odd"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long int ans=0,n,k;
    cin>>n>>k;
    if(k==0){
        cout<<n*n;
        return 0;
    }
    for(int i=n;i>k;--i)
        ans+=(n/i)*(i-k) + ((n/i)*i + k <=n ? n-(n/i)*i - k+1 : 0);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  int n;
  cin>>n;
  int x[n],y[n],h[n];
  vector<pair<int,pair<int,int>>> hxy(n);
  REP(i,n){
    cin>>x[i]>>y[i]>>h[i];
    hxy.push_back(make_pair(h[i],make_pair(x[i],y[i])));
  }
  sort(hxy.begin(),hxy.end(),greater<pair<int,pair<int,int>>>());
  
  int H;
  int cx,cy,ans;
  bool flag;
  REP(i,101){
    REP(j,101){
      REP(k,n){
        flag = true;
        if(k==0){
          H = hxy[k].first + abs(i-hxy[k].second.first) + abs(j-hxy[k].second.second);
        }else{
          //if(hxy[k].first==0)continue;
          if(max(0,H-abs(i-hxy[k].second.first)-abs(j-hxy[k].second.second))==hxy[k].first){
            continue;
          }else{
            flag = false;
          }
        }
        if(!flag)break;
      }
      if(flag){
        cx = i;
        cy = j;
        ans = H;
      }
    }
  }
  
  cout<<cx<<' '<<cy<<' '<<ans;
  return 0;
}


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

int main()
{
    int n;
    long long h=0;
    cin>>n;
    long long a[n];
    for(int i=0; i<n; ++i)
        cin>>a[i];
    for(int i=1; i<n; ++i)
    {
        if(a[i-1]>a[i])
           {
                h+=a[i-1]-a[i];
                a[i]=a[i-1];
           }
    }
    cout<<h;
    return 0;
}

Measured memory_bytes: 5208
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  string s;
  cin >> s;
  set<string> kind;
  string memo;
  int l = s.size();
  l = min(5LL,l);
  
  rep(i,0,l){
    rep(j,0,s.size()-i){
      memo = s.substr(j,i+1);
      kind.insert(memo);
    }
  }
  
  int n;
  cin >> n;
  rep(i,0,n-1) kind.erase(*begin(kind));
  
  cout << *begin(kind) << endl;
}


Measured memory_bytes: 1664
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int H = Integer.parseInt(sc.next());
        int W = Integer.parseInt(sc.next());
        int h = Integer.parseInt(sc.next());
        int w = Integer.parseInt(sc.next());
        System.out.println(H*W-h*W-w*H+h*w);
        sc.close();
    }
    
}

Measured memory_bytes: 21844
N,K=map(int,input().split())
A=list(map(int,input().split()))
dp=[[-1]*2 for i in range(46)]
dp[45][0]=0
for d in range(44,-1,-1):
    mask=1<<d
    num=0
    for i in range(N):
        if A[i]& mask: num+=1

    if dp[d+1][1]>=0:
        dp[d][1]=max(dp[d][1],dp[d+1][1]+mask*max(num,N-num))#決まっているところでは0でも1でもOK
    if dp[d+1][0]>=0:
        if K &mask:#d桁目が1のとき
            dp[d][1]=max(dp[d][1],dp[d+1][0]+mask*num)#0にする、決まってないところー＞決まってるところ
            dp[d][0]=max(dp[d][0],dp[d+1][0]+mask*(N-num))#1にする、決まっていないところー＞決まっているところ
        else:
            dp[d][0]=max(dp[d][1],dp[d+1][0]+mask*num)#0にする、決まってないところー＞決まってないところ
print(max(dp[0][0],dp[0][1]))


Measured memory_bytes: 14620
import Control.Monad
import Data.List
import qualified Data.Map as Map
import Data.Maybe

--main :: IO()
main = do
  n <- readLn :: IO Int
  ts <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
  let
    tree = makePLR ts
    parents = clean $ makeParents tree
    siblings = clean $ makeSibling tree
    degrees = clean $ makeDegree tree
    depths = map (measureDepth parents) [0..(n-1)]
    heights = map (measureHeight tree) [0..(n-1)]
    --printTree :: Int -> IO()
    printTree id = putStrLn ("node " ++ (show id)
      ++ ": parent = " ++ p ++ ", sibling = " ++ s
      ++ ", degree = " ++ (show deg) ++ ", depth = " ++ (show dep)
      ++ ", height = " ++ (show h) ++ ", " ++ kind)
        where
          p = show $ search id parents
          s = show $ search id siblings
          Just deg = Map.lookup id $ Map.fromList degrees
          dep = depths !! id
          h = heights !! id
          kind = if dep == 0 then "root"
            else if deg == 0 then "leaf"
            else "internal node"
  mapM_ printTree [0..(n-1)]

clean = sort . filter (\(id, _) -> id /= -1)

search :: Int -> [(Int, Int)] -> Int
search id dic = if (isNothing target) then -1 else val
  where
    target = Map.lookup id $ Map.fromList dic
    Just val = target

makePLR :: [[Int]] -> [(Int, Int, Int)]
makePLR [] = []
makePLR (t:ts) = (id, l, r):(makePLR ts)
  where (id:l:r:_) = t

makeParents :: [(Int, Int, Int)] -> [(Int, Int)]
makeParents [] = []
makeParents (t:ts) = (l, p):(r, p):makeParents ts
  where (p, l, r) = t

makeSibling :: [(Int, Int, Int)] -> [(Int, Int)]
makeSibling [] = []
makeSibling (t:ts) = (l, r):(r, l):makeSibling ts
  where (p, l, r) = t

makeDegree :: [(Int, Int, Int)] -> [(Int, Int)]
makeDegree [] = []
makeDegree (t:ts) = (p, (count l) + (count r)):makeDegree ts
  where
    (p, l, r) = t
    count x = if x == -1 then 0 else 1

measureDepth :: [(Int, Int)] -> Int -> Int
measureDepth parents id = if (length target) == 0 then 0 else (1 + measureDepth parents (snd $ head target))
  where
    target = filter (\(tid, _) -> tid == id) parents

measureHeight :: [(Int, Int, Int)] -> Int -> Int
measureHeight [] _ = -1
measureHeight plr id = if (length target) == 0 then -1 else (1 + height)
  where
    target = filter (\(tid, _, _) -> tid == id) plr
    (p, l, r) = head target
    height = max (measureHeight plr l) (measureHeight plr r)



Measured memory_bytes: 4228
#include <iostream>
#include <vector>


int main(){
	std::vector<std::vector<int>> obstacle;
	std::vector<std::vector<int>> road;
	int a,b;

	while(std::cin >> a >> b){
		if(a ==0 && b == 0)break;
		int obstacleNum;
		std::cin >> obstacleNum;

		std::vector<std::vector<int>> obstacle(a+1, std::vector<int>(b+1, 0));
		std::vector<std::vector<int>> road(a+1, std::vector<int>(b+1, 0));

		int tmp_a,tmp_b;
		for(int i = 0;i < obstacleNum; ++i) {
			std::cin >> tmp_a >> tmp_b;
			obstacle[tmp_a][tmp_b] = 1;
		}
		for (int i = 1; i <= a; ++i){
			for (int j = 1; j <= b; ++j){
				if(i == 1 && j == 1)road[i][j] = 1;
				else if(obstacle[i][j] == 1) road[i][j] = 0;
				else road[i][j] = road[i-1][j] + road[i][j-1];
			}
		}

		std::cout << road[a][b] << std::endl;

	}
	return 0;
}

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

int main(){
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for(int i=0; i<n; i++) scanf("%d", &a[i]);

	int l=0, r=1e9+1;
	while(r-l>1){
		int mid = (l+r)/2;
		int cnt = 0;
		for(int i=0; i<n; i++){
			cnt += (a[i]+mid-1)/mid - 1;
		}
		if(cnt>k) l = mid;
		else r = mid;
	}
	printf("%d\n", r);
	return 0;
}



Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
map<char,long>m;
int main(){
    int n;
    cin>>n;
    string a[100005];
    for(int i=1;i<=n;i++){
        string y;
        cin>>y;
        m[y[0]]++;
    }
    unsigned long res=0;
    char c[6]={'M','A','R','C','H'};
    for(int i=0;i<=2;i++){
        for(int j=i+1;j<=3;j++){
            for(int k=j+1;k<=4;k++){
                res+=m[c[i]]*m[c[j]]*m[c[k]];
            }
        }
    }
    cout<<res;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()

int main() {
  //
  int n;
  cin >> n;
  set<int> s;
  rep(i, n) {
    int a;
    cin >> a;
    set<int>::iterator it = s.find(a);
    if (it == s.end()) {
      s.insert(a);
    } else {
      s.erase(it);
    }
  }
  cout << s.size() << endl;
  return 0;
}


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

public class Main {

	Scanner sc = new Scanner(in);
	
	char[] eq;
	char[] eq1, eq2;
	boolean[] as = new boolean[11];
	boolean[] check = new boolean[11];
	
	boolean flag;
	void calc(int depth) {
		if (depth == 11) {
			boolean a, b;
			eq = eq1;
			index = 0;
			a = F();
			eq = eq2;
			index = 0;
			b = F();
//			out.println(a);
//			out.println(b);
//			out.println();
			if (a != b)
				flag = false;
		} else {
			if (flag) {
				as[depth] = false;
				calc(depth+1);
				as[depth] = true;
				calc(depth+1);
			}
		}
	}
	
	int index;
	int token;
	final int VAL = '%';
	boolean value;
	void gettoken() {
		int ch = eq[index++];
		if (ch == '+' || ch == '*' || ch == '(' || ch == ')') {
			token = ch;
			return;
		} else if (ch == '-') {
			if (eq[index] == '>') {
				index++;
				token = '>';
				return;
			} else {
				token = ch;
				return;
			}
		} else {
			token = VAL;
			switch(ch) {
			case 'T':
				value = true; break;
			case 'F':
				value = false; break;
			case 'a':
				value = as[0]; break;
			case 'b':
				value = as[1]; break;
			case 'c':
				value = as[2]; break;
			case 'd':
				value = as[3]; break;
			case 'e':
				value = as[4]; break;
			case 'f':
				value = as[5]; break;
			case 'g':
				value = as[6]; break;
			case 'h':
				value = as[7]; break;
			case 'i':
				value = as[8]; break;
			case 'j':
				value = as[9]; break;
			case 'k':
				value = as[10]; break;
			}
		}
	}
	
	boolean F() {
		boolean v, vnext;
		int savetoken;
		gettoken();
		if (token == VAL) {
			return value;
		} else if (token == '-') {
			return !F();
		} else if (token == '(') {
			v = F();
			gettoken();
			savetoken = token;
			vnext = F();
			gettoken();
			if (token != ')') out.println("err");
			if (savetoken == '+') {
				return v || vnext;
			} else if (savetoken == '*') {
				return v && vnext;
			} else if (savetoken == '>') {
				if (!v) return true;
				else return vnext;
			}
			
		}
		out.println("err");
		return false;
	}
	
	void run() {
		String s;
		StringTokenizer st;
		while (true) {
			s = sc.nextLine();
			if (s.equals("#"))
				break;
			st = new StringTokenizer(s,"=");
			eq1 = st.nextToken().toCharArray();
			eq2 = st.nextToken().toCharArray();
			flag = true;
			calc(0);
			if (flag)
				out.println("YES");
			else
				out.println("NO");
//			out.println();
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 24936
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def naive(N):
    NN = int(N ** 0.5 + 1) + 1
    count = 0

    for a in range(1, N):
        for b in range(1, N // a + 1):
            if N - a * b > 0:
                count += 1
    return count


def main():
    from builtins import int, map
    N = int(input())
    print(naive(N))

        

if __name__ == '__main__':
    main()


Measured memory_bytes: 68880
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "
int main(){
    int n;cin>>n;
    vector<int> v(n),c(n);
    rep(i,n)cin>>v[i];
    rep(i,n)cin>>c[i];
     int ans =0;
     rep(i,n){
         if(v[i]-c[i]>0)ans+=v[i]-c[i];
     }
     co(ans);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define p pair<int,int>
#define P pair<p,p>
using namespace std;

int a[50][50][50][50];
int x[4] = { -1,0,0,1 }, y[4] = { 0,-1,1,0 };
int S[50][50];
signed main() {
	int b, c;
	while (cin >> c >> b, b | c) {
		memset(a, 0x3f, sizeof(a));
		int d, e, f, g; cin >> e >> d >> g >> f; d--; e--; f--; g--;
		a[d][e][f][g] = 0;
		for (int i = 0; i < b; i++) {
			for (int j = 0; j < c; j++) {
				scanf("%d", &S[i][j]);
			}
		}
		queue<P>Q;
		Q.push(P(p(d,e),p(f,g)));
		while (Q.size()) {
			P t = Q.front(); Q.pop();
			if (a[t.first.first][t.first.second][t.second.first][t.second.second] >= 100)break;
			if (t.first.first == t.second.first&&t.first.second == t.second.second) {
				cout << a[t.first.first][t.first.second][t.second.first][t.second.second] << endl;
				goto l;
		}
			for (int i = 0; i < 4; i++) {
				int j = 3 - i;
				p n, m; n = t.first; m = t.second;
				n.first += x[i]; n.second += y[i];
				m.first += x[j]; m.second += y[j];
				if (n.first < 0 || n.first >= b || n.second < 0 || n.second >= c||S[n.first][n.second]==1) {
					n.first -= x[i]; n.second -= y[i];
				}
				if (m.first < 0 || m.first >= b || m.second < 0 || m.second >= c||S[m.first][m.second]==1) {
					m.first -= x[j]; m.second -= y[j];
				}
				if (a[n.first][n.second][m.first][m.second] == 1061109567) {
					a[n.first][n.second][m.first][m.second] = a[t.first.first][t.first.second][t.second.first][t.second.second]+1;
					Q.push(P(p(n.first,n.second),p(m.first,m.second)));
				}
			}
		}
		puts("NA");
	l:;
	}
}

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

int a[200];
int main() {
	int n;
	while (~scanf("%d", &n)) {
		int ans = 0, cnt = 0;
		rep(i, n)scanf("%d", &a[i]);
		sort(a, a + n);
		rep(i, n) {
			ans += cnt + a[i];
			cnt += a[i];
		}
		printf("%d\n", ans);
	}
}

Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a=0,n,p;
    cin>>n;
    for (int i=1;i<=n;i++){
        cin>>p;
        a+=p;
    }
    if (a%2==0){
        cout<<"YES";
    }else{
        cout<<"NO";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double PI = acos(-1);

int main() {
  cout << fixed << setprecision(20);
  int A,B,H,M;
  cin >> A >> B >> H >> M;
  double RA = ((double) (H * 60 + M) / 2);
  double TA = RA * (M_PI / 180);
  double AX = A * sin(TA);
  double AY = A * cos(TA);
  double RB = M * 6;
  double TB = RB * (M_PI / 180); 
  double BX = B * sin(TB);
  double BY = B * cos(TB);
  cout << sqrt(pow(AX - BX, 2) + pow(AY - BY, 2)) << endl;
}


Measured memory_bytes: 4072
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
//ll mod = 998244353;
#define rep(i,n) for(int i = 0; i < (n); ++i)

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

ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}

int main() {
    int n;
    cin >> n;
    vector<ll> t(n);
    rep(i, n) cin >> t[i];
    ll ans = t[0];
    for (int i = 1; i < n; ++i) {
        ans = lcm(ans, t[i]);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
#include <string>
#define MAX 100007
#define scn1(a) scanf("%d", &a);
#define scn2(a, b) scanf("%d %d", &a, &b);
#define scn3(a, b, c) scanf("%d %d %d", &a, &b, &c);
#define lscn1(a) scanf("%lli", &a);
#define lscn2(a, b) scanf("%lli %lli", &a, &b);
#define lscn3(a, b, c) scanf("%lli %lli %lli", &a, &b, &c);
#define prnt(a) printf("%d\n", a);
#define forr(i, a, n) for(int i=a;i<n;i++)
#define nl puts("");
#define PB push_back
#define enl cout << "\n";
#define CHK(a) cout << (#a) << " = " << (a) << endl;
typedef long long int ll;
using namespace std;
void arraychk(int a[],int n) {for(int i=0;i<n;i++)cout<<a[i]<<" ";enl;}
#define LOOPCHK(a, n) arraychk(a, n);

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll tt=1;
    // cin >> tt;
    for(int cse=1; cse<=tt; cse++)
    {
        ll i=0, j=0, k=0, l=0, m=0,
        n=0, x=0, y=0, ans=0, sum=0;
        ll a[5]={0};
        forr(i, 1, 5) cin >> a[i];
        ans = a[1]*a[3];
        ans = max(ans , a[1]*a[4]);
        ans = max(ans , a[2]*a[4]);
        ans = max(ans , a[2]*a[3]);
        // cout << "Case " << cse <<  ":";
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3688
#include<cstdio>
#include<cmath>
 
//#include<iostream>
using namespace std;
 
int main(){
    float  x1, y1, x2, y2, x3, y3, xp, yp;
	float  x12, y12, x23, y23, x31, y31, x1p, y1p, x2p, y2p, x3p, y3p;

	while( ~scanf("%f%f%f%f%f%f%f%f" , &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp)){
		x12=x2-x1; y12=y2-y1;
		x23=x3-x2; y23=y3-y2;
		x31=x1-x3; y31=y1-y3;
		x1p=xp-x1; y1p=yp-y1;
		x2p=xp-x2; y2p=yp-y2;
		x3p=xp-x3; y3p=yp-y3;

		if((x12*y1p-y12*x1p>0 && x23*y2p-y23*x2p>0 && x31*y3p-y31*x3p>0) ||
			(x12*y1p-y12*x1p<0 && x23*y2p-y23*x2p<0 && x31*y3p-y31*x3p<0))
					 printf("YES\n");
		else		printf("NO\n");
	}

    return 0;
}

Measured memory_bytes: 1036
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll mod = 1000000007;

ll r(ll x, ll y) {
  if (y == 0) return 1;
  else if (y % 2 == 0) return r(x, y/2) * r(x, y/2) % mod;
  else return x * r(x, (y-1)/2) % mod * r(x, (y-1)/2) % mod;
}
  
int main() {
  int a, b, c,d;
  cin >> a >> b >> c >>d;
  int Ta = c / b;
  if (c%b!=0) {
    Ta++;
  }
  int Tb = a / d;
  if (a%d!=0) {
    Tb++;
  }
  if (Ta>Tb) {
    cout << "No" <<endl;
  }
  else {
    cout << "Yes" <<endl;
  }
} 


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long a,b,c,d,e,f,ans1=0,ans2=0,sugar,water;
  double nodo=0;
  cin >> a >> b >> c >> d >> e >> f;
  for(int i=0;i*100*a<=f;i++){
    for(int j=0;i*100*a+j*100*b<=f;j++){
      for(int k=0;i*100*a+j*100*b+k*c<=f;k++){
        for(int l=0;i*100*a+j*100*b+k*c+l*d<=f;l++){
          if((i*a+j*b)*e>=k*c+l*d and i+j+k+l){
            water=i*100*a+j*100*b;
            sugar=k*c+l*d;
            if(nodo<=(double)(100*(sugar))/(double)(water+sugar)){
              nodo=(double)(100*(sugar))/(double)(water+sugar);
              ans1=water+sugar;
              ans2=sugar;
            }
          }
        }
      }
    }
  }
  cout << ans1 << " " << ans2 << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=200005,M=998244353;
int n,k,p[N],i,a[N],q[N];
long long tree[N],m[N],ans[N];
long long qpow(long long a,long long b)
{
	long long s=a,ans=1;
	while(b)
	{
		if(b&1)
			ans=ans*s%M;
		s=s*s%M;
		b>>=1;
	}
	return ans;
}
void modify(int x,int y)
{
	while(x<=n)
	{
		tree[x]+=y;
		x+=-x&x;
	}
}
int Query(int x)
{
	long long s=0;
	while(x)
	{
		s+=tree[x];
		x-=-x&x;
	}
	return s%M;
}
void dfs(int l,int r)
{
	if(l==r)
		return;
	int mid=l+r>>1,i;
	long long s=0,tot=0;
	for(i=l;i<=mid;++i)
	{
		modify(p[i],m[i]);
		tot=(tot+m[i])%M;
	}
	for(i=r;i>mid;--i)
	{
		ans[i]=(ans[i]+s)%M;
		s=(s+tot-Query(p[i]))%M;
	}
	for(i=l;i<=mid;++i)
		modify(p[i],-m[i]);
	s=0;
	for(i=mid+1;i<=r;++i)
		modify(p[i],1);
	for(i=l;i<=mid;++i)
	{
		s=(s+Query(p[i])*m[i])%M;
		ans[i]=(ans[i]+s)%M;
	}
	for(i=mid+1;i<=r;++i)
		modify(p[i],-1);
	dfs(l,mid);
	dfs(mid+1,r);
}
int main()
{
	scanf("%d %d",&n,&k);
	for(i=1;i<=n;++i)
	{
		scanf("%d",&p[i]);
		q[p[i]]=i;
	}
	long long in=qpow(k,M-2);
	long long iw=in*(k-1)%M;
	long long iiw=qpow(iw,M-2);
	for(i=1;i<=n;++i)
		m[i]=in*qpow(iw,n-max(i,k))%M;
	dfs(1,n);
	long long s=((n-k)*qpow(2,M-2)%M*(k-1)%M+1ll*k*(k-1)/2%M*qpow(2,M-2))%M;
	for(i=n-k;i>=1;--i)
		s=(s+ans[i+k-1]*qpow(iiw,n-i-k+1))%M;
	cout<<(s%M+M)%M;
}


Measured memory_bytes: 9916
#include<stdio.h>
#define max 1000000

int n,A[max+1];

void maxHeapify(int);

int main(){

  int i;

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }

  for(i=n/2;i>=1;i--){
    maxHeapify(i);
  }

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

void maxHeapify(int i){
  int l,r,king,tmp=0;
  l = 2*i;
  r = 2*i+1;

  if(l <= n && A[l] > A[i]) king = l;
  else king = i;
  if(r <= n && A[r] > A[king]) king = r;

  if(king != i){
    tmp = A[i];
    A[i] = A[king];
    A[king] = tmp;
    maxHeapify(king);
  }
  
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a=0,b;
    string s;
    cin>>s;
    for(int i=0;i<3;i++){
        if(s[i]=='A')
            a++;
        if(s[i]=='B')
            b++;
    }
        if(a==3||b==3)
            cout<<"No";
        else
            cout<<"Yes";

}


Measured memory_bytes: 256
import fractions
A,B,C,D = list(map(int,input().split()))
l = (C*D)//fractions.gcd(C,D)
a = [(A-1)//C,(A-1)//D,(A-1)//l]
#print(a)
b = [B//C,B//D,B//l]
#print(b)
c = [b[0]-a[0],b[1]-a[1],b[2]-a[2]]
print(B-A+1-c[0]-c[1]+c[2])

Measured memory_bytes: 5048
#include <bits/stdc++.h>
using namespace std;
#define ll  long long
#define PII pair<ll,ll>
#define VI  vector<ll>
#define VB  vector<bool>
#define VVI vector<vector<ll>>
#define VS  vector<string>
#define VP  vector<PII>
#define lf(i,a,b) for(ll i=a;i<=b;i++)
#define lr(i,a,b) for(ll i=a;i>=b;i--)
#define lfl(i,v) for(ll i=0;i<v.size();i++)
#define lrl(i,v) for(ll i=(ll)(v.size())-1;i>=0;i--)
#define chk2(a,b) cout<<"check :  "<<a<<" "<<b<<endl
#define chk3(a,b,c) cout<<"check :  "<<a<<" "<<b<<" "<<c<<endl
#define chk4(a,b,c,d) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<endl
#define chk5(a,b,c,d,e) cout<<"check :  "<<a<<" "<<b<<" "<<c<<" "<<d<<" "<<e<<endl
#define lb(v,k)  lower_bound(v.begin(),v.end(),k)-v.begin()
#define ub(v,k)  upper_bound(v.begin(),v.end(),k)-v.begin()
#define mod 1000000007
#define pb push_back
#define pf push_front
#define m_p make_pair
#define fi first
#define se second
#define sz size()
#define sort(v) sort(v.begin(),v.end())
ll n,k;
VVI v;
ll dp[100005][3]; 
ll fun(ll ind,ll t)
    {   if(ind>n)
            return 0;
        if(dp[ind][t]!=-1)
            return dp[ind][t];
        ll maxi=0;
        lf(j,0,2)
        {   if(t!=j)
            {   maxi=max(maxi,v[ind][j]+fun(ind+1,j));
            }
        }
        return dp[ind][t]=maxi;
    }
int main()
{   cin>>n;
    v=VVI(n+1,VI(3,0));
    lf(i,1,n)
    {   lf(j,0,2)
            cin>>v[i][j];
    }
    memset(dp,-1,sizeof(dp));
    cout<<max(fun(1,0),max(fun(1,1),fun(1,2)))<<endl;    
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#define rep(I,n) for (int I = 0; I < (n); ++I)
#define FOR(I,k,n) for(int I=(k);I<(n);++I)
using namespace std;
typedef long long ll;
 
int main() {
    
    string ans;
    string s;
    cin >> s;
    
    if(s=="ABC"){
        
        ans="ARC";
    }
    
    else{
        
        ans="ABC";
    }
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3636
#include <cstdio>

int gcd(int , int );

int main(){
    int n;
    scanf("%d", &n);
    int a[n];
    for(int i = 0; i < n; i++){
        scanf("%d", &a[i]);
    }

    int ans = a[0];
    for(int i = 1; i < n; i++){
        ans = gcd(ans, a[i]);
    }

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

    return 0;
}

int gcd(int a, int b){
    if(a < b){
        return gcd(b, a);
    }else{
        int r = a % b;
        while(r != 0){
            a = b;
            b = r;
            r = a % b;
        }

        return b;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define inf 2000000000
#define infLL 2000000000000000000
#define MAX 100005
#define sf(a) scanf("%d", &a)
#define sfl(a) scanf("%lld", &a)
#define pf(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define Case(t) printf("Case %d: ", t)
#define pii pair<int, int>
#define MOD 1000000007
#define mod 1000000007
#define PI acos(-1.0)
#define eps 1e-9
#define mem(a, b) memset(a, b, sizeof(a))

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

inline int Set(int N, int pos){return N=N | (1<<pos);}
inline int Reset(int N, int pos){return N=N & ~(1<<pos);}
inline bool Check(int N, int pos){return (bool)(N & (1<<pos));}

inline void normal(ll &a) { a %= mod; (a < 0) && (a += mod); }
inline ll modMul(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a * b) % mod; }
inline ll modAdd(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); return (a + b) % mod; }
inline ll modSub(ll a, ll b) { a %= mod, b %= mod; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while (p) { if (p & 1LL) r = modMul(r, b); b = modMul(b, b); p >>= 1LL; } return r; }
inline ll modInverse(ll a) { return modPow(a, mod - 2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll fast_exp(ll x, ll n, ll m)
{
    ll res = 1;
    while(n>0)
    {
        if(n%2==1)
            res = (res * x) % m;
        x = (x * x) % m;
        n/=2;
    }
    return res%m;
}

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}

clock_t t_Start;
void Start()
{
    t_Start = clock();
}
void End()
{
    double Time = (double)(clock()-t_Start)/CLOCKS_PER_SEC;
    error(Time);
}

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet;
typedef tree<int,null_type,greater<int>,rb_tree_tag,tree_order_statistics_node_update>orderedSet1;

int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    //Start();

    int h, a;
    cin>>h>>a;
    cout<<ceil((double)h/(double)a)<<endl;

    //End();
    return 0;
}


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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair



int N, M, Q;

int L[200000], R[200000];
int imo[501][501];

void prepare() {
    // imo.assign(N+1, vi(N+1, 0));
    // mset(imo, 0);

    rep(i,M){
        int from = L[i], to = R[i];
        ++imo[from][to];
    }

    for (int r=N; r>0; --r){
        rep1(c,N) {
            imo[r][c] += imo[r][c-1];
        }
        if (r < N) {
            rep(c,N+1)
                imo[r][c] += imo[r+1][c];
        }
    }
#ifdef DEBUG
    for (int r=1;r<=N;++r) {
        for (int c=1;c<=N;++c) {
            fprintf(stderr, " %2d", imo[r][c]);
        }
        fprintf(stderr, "\n");
    }
#endif
}


int main() {
    scanf("%d %d %d", &N, &M, &Q);
    rep(i,M) {
        scanf("%d %d", &L[i], &R[i]);
    }

    prepare();

    rep(i,Q) {
        int p,q;
        scanf("%d %d", &p, &q);
        printf("%d\n", imo[p][q]);
    }
    return 0;
}


Measured memory_bytes: 3456
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int h,w,a,b;
    cin>>h>>w>>a>>b;
    for(int i=0;i<b;i++){
        for(int j=0;j<w;j++){
            if(j<a)cout<<0;
            else cout<<1;
            if(j==w-1)cout<<endl;
        }
    }
    for(int i=b;i<h;i++){
        for(int j=0;j<w;j++){
            if(j<a)cout<<1;
            else cout<<0;
            if(j==w-1)cout<<endl;
        }
    }
}


Measured memory_bytes: 1280
import scala.io.StdIn

object Main extends App {

  val s = StdIn.readLine()
  val K = StdIn.readLine().toInt
  val r = {
    for (i <- 0 until s.size;
         j <- 1 to s.size - i; if j <= K)
      yield s.substring(i, i + j)
  }.distinct.sorted.apply(K - 1)

  println(r)
}


Measured memory_bytes: 74980
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define int long long
constexpr long long INF = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N;
    cin>>N;
    int x=N;
    int ans=0;
    for(int i=2;i*i<=N;i++){
        int co=0;
        while(x%i==0){
            co++;
            x/=i;
        }
        int j=1;
        while(co>0){
            co-=j;
            j++;
            if(co>=0)ans++;
        }

        if(x==1){
            break;
        }
    }
    if(x!=1) ans++;

    cout << ans << endl;

    



}


Measured memory_bytes: 3652
#include <cstdio>
#include <iostream>
#include <string>

using namespace std;

int main() {
    string s, t;
    t = "abcdefghijklmnopqrstuvwxyz";
    cin >> s;
    sort(s.begin(), s.end());
    for (int i = 0; i < t.length(); i++) {
        if (s.find(t[i]) == string::npos) {
            printf("%c\n", t[i]);
            return 0;
        }
    }
    printf("None\n");
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

void Suhaib_Sawalha (){

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

    int ans = 1e9;
    for (int i = 0 ; i < n ; ++i)
        ans = min (ans, abs(a[n]-a[i] - a[i]));
    cout << ans;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 3604