akhauriyash/Code-Regression huggingface dataset:
// D - Coloring Edges on Tree
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	vi G(N);//[c]<p>
	vi C;//[i]<c>
	rp(i, 0, N-1){
		int p,c; cin>>p>>c; p--,c--;
		G[c] = p;
		C.push_back(c);
	}

	int K = 1;
	vi colors(N);
	vi next_colors(N, 1);
	rp(c, 1, N){
		int p = G[c];
		int p_color = colors[p];
		int color = next_colors[p];
		if(color == p_color){
			color++;
		}
		colors[c] = color;
		next_colors[p] = ++color;
	}

	for(auto k:next_colors) K = max(K, k-1);
	cout<< K <<endl;
	for(auto c:C) cout<< colors[c] <<endl;
}

Measured memory_bytes: 2168
//------------------------------------------
// C++ templete 
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

#define endl "\n"

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<PII> VP;
//REPEAT
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//container util
//------------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//math
//------------------------------------------
int QP(int a,int b){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int QP(int a,int b,int MOD){int ans=1;do{if(b&1)ans=1ll*ans*a%MOD;a=1ll*a*a%MOD;}while(b>>=1);return ans;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

//debug
//------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//grobal variable
//------------------------------------------
int N,M;
VI Vec;

//動的計画法で役に立つ関数
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

//最大公約数と最小公倍数
ll gcd(ll a, ll b) {
    if(b==0)return a;
    return gcd(b, a%b);
}

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

vector<vector<long long> > comb(int n) {
  vector<vector<long long> > v(n + 1,vector<long long>(n + 1, 0));
  for (int i = 0; i < v.size(); i++) {
    v[i][0] = 1;
    v[i][i] = 1;
  }
  for (int j = 1; j < v.size(); j++) {
    for (int k = 1; k < j; k++) {
      v[j][k] = (v[j - 1][k - 1] + v[j - 1][k]);
    }
  }
  return v;
}

int main() 
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    
    ll N;cin >> N;
    
    ll m=0, a=0, r=0, c=0, h=0;
    REP(i,N)
    {
        string S; cin >> S;
        if (S[0]=='M') m++;
        else if (S[0]=='A') a++;
        else if (S[0]=='R') r++;
        else if (S[0]=='C') c++;
        else if (S[0]=='H') h++;
    }
    ll counter=0;
    vector<ll> V{m,a,r,c,h};
    REP(i, 5)
    {
        REP(j,5)
        {
            if (i > j)
            {
            REP(k,5)
            {
                if (j > k)
                {
                    counter += V[i]*V[j]*V[k];        
                }
            }
            }
        }
    }
    cout << counter << endl;
    return 0;
}



Measured memory_bytes: 256
def gcd(a, b):
    if(a == 0):
        return b
    if(b == 0):
        return a

    if(a < b):
        a, b = b, a
    r = a % b
    while(r != 0):
        a, b = b, r
        r = a % b
    return b

def L(end_i, A):
    if(end_i == 0):
        return 0
    
    a = 0
    for i in range(end_i):
        a = gcd(a, A[i])
    return a


def R(start_i, A, N):
    if(start_i == N - 1):
        return 0

    a = 0
    for i in range(start_i + 1, N):
        a = gcd(a, A[i])
    return a


N = int(input())
A = list(map(int, input().split(' ')))

left = [0] * N
right = [0] * N

for i in range(1, N):
    left[i] = gcd(left[i - 1], A[i - 1])
#print(left)

for i in reversed(range(0, N - 1)):
    right[i] = gcd(A[i + 1], right[i + 1])
#print(right)

M = []
for i in range(N):
    M.append(gcd(left[i], right[i]))
#print(M)

print(max(M))

Measured memory_bytes: 14452
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static char[] line;
	static int pos;

	public static void main(String[] args) {
		int N = sc.nextInt();
		for (int i = 0; i < N; ++i) {
			line = sc.next().toCharArray();
			System.out.println(solve());
		}
	}

	static int solve() {
		pos = 0;
		Node root = parse();
		return root.count();
	}

	static Node parse() {
		++pos;
		Node ret = new Node();
		if (line[pos] != '[') {
			ret.num = line[pos++] - '0';
			while (line[pos] != ']') {
				ret.num *= 10;
				ret.num += line[pos] - '0';
				++pos;
			}
			++pos;
			return ret;
		}
		while (line[pos] == '[') {
			ret.child.add(parse());
		}
		++pos;
		return ret;
	}

	static class Node {
		ArrayList<Node> child = new ArrayList<Node>();
		int num;

		int count() {
			if (child.isEmpty()) return num / 2 + 1;
			int[] n = new int[child.size()];
			for (int i = 0; i < child.size(); ++i) {
				n[i] = child.get(i).count();
			}
			Arrays.sort(n);
			int ret = 0;
			for (int i = 0; i <= child.size() / 2; ++i) {
				ret += n[i];
			}
			return ret;
		}
	}

}

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

using UnWightedGraph = vector<vector<int> >;
template <typename G>
struct StronglyConnectedComponents {
    const G &g;
    UnWightedGraph gg, rg;
    vector<int> comp, order, used;
    StronglyConnectedComponents(G &g)
        : g(g), gg(g.size()), rg(g.size()), comp(g.size(), -1), used(g.size()) {
        for (int i = 0; i < g.size(); i++) {
            for (auto e : g[i]) {
                gg[i].push_back((int)e);
                rg[(int)e].push_back(i);
            }
        }
    }
    int operator[](int k) { return comp[k]; }

    void dfs(int idx) {
        if (used[idx]) return;
        used[idx] = true;
        for (int to : gg[idx]) dfs(to);
        order.push_back(idx);
    }

    void rdfs(int idx, int cnt) {
        if (comp[idx] != -1) return;
        comp[idx] = cnt;
        for (int to : rg[idx]) rdfs(to, cnt);
    }

    void build(UnWightedGraph &t) {
        for (int i = 0; i < gg.size(); i++) dfs(i);
        reverse(order.begin(), order.end());
        int ptr = 0;
        for (int i : order) {
            if (comp[i] == -1) rdfs(i, ptr), ptr++;
        }
        t.resize(ptr);
        for (int i = 0; i < g.size(); i++) {
            for (auto &to : g[i]) {
                int x = comp[i], y = comp[to];
                if (x == y) continue;
                t[x].push_back(y);
            }
        }
    }
};

int main() {
    int n, m;
    while (cin >> n, n) {
        vector<double> p(n);
        UnWightedGraph g(n), buff;
        for (int i = 0; i < n; i++) {
            cin >> p[i] >> m;
            for (int j = 0; j < m; j++) {
                int a;
                cin >> a;
                a--;
                g[i].push_back(a);
            }
        }
        StronglyConnectedComponents<UnWightedGraph> scc(g);
        scc.build(buff);
        int k = buff.size();
        vector<bool> root(k, true);
        for (int i = 0; i < n; i++) {
            for (int j : g[i]) {
                if (scc[i] != scc[j]) root[scc[j]] = false;
            }
        }
        double ans = 1.0;
        for (int i = 0; i < k; i++) {
            if (root[i]) {
                double q = 1.0;
                for (int j = 0; j < n; j++) {
                    if (scc[j] == i) {
                        q *= p[j];
                    }
                }
                ans *= 1 - q;
            }
        }
        cout << fixed << setprecision(10) << ans << endl;
    }
    return 0;
}


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

struct LazySegmentTree{
private:
    int n; //葉の数
    vector<ll> node, lazy; //普通のセグ木の配列と遅延配列

public:
    LazySegmentTree(){}
    LazySegmentTree(vector<ll> v){
        int sz = v.size();
        int height = ceil(log2(sz));
        n = pow(2, height);
        node.resize(2*n-1, 0);
        lazy.resize(2*n-1, 0);

        for(int i = 0; i < sz; i++) node[i+(n-1)] = v[i];
        for(int i = n-2; i >= 0; i--) node[i] = node[(i<<1) + 1] + node[(i<<1) + 2];
    }

    void eval(int k, int l, int r){
        if(lazy[k] != 0){
            node[k] += lazy[k];

            if(r-l > 1){
                lazy[(k<<1)+1] += lazy[k]/2;
                lazy[(k<<1)+2] += lazy[k]/2;
            }
            lazy[k] = 0;
        }
    }

    ll getsum(int a, int b, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        //区間に交わりが無い -> 0を返す
        if(b <= l || r <= a) return 0;

        eval(k, l, r);
        //区間を全て覆う -> その区間和を返す
        if(a <= l && r <= b) return node[k];
        //区間に一部交わりがある
        else{
            ll vl = getsum(a, b, (k<<1)+1, l, (l+r)/2);
            ll vr = getsum(a, b, (k<<1)+2, (l+r)/2, r);
            return vl+vr;
        }
    }
    void update(int a, int b, ll v, int k=0, int l=0, int r=-1){
        if(r < 0) r = n;
        //[a,b)にvを足すクエリ
        eval(k, l, r);
        if(b <= l || r <= a) return;
        else if(a <= l && r <= b){
            lazy[k] += (r-l)*v;
            eval(k, l, r); //アクセス後はlazy[k]=0のはずなので、(r-l)*vを足した後に評価が必要
        }
        else{
            update(a, b, v, (k<<1)+1, l, (l+r)/2);
            update(a, b, v, (k<<1)+2, (l+r)/2, r);
            node[k] = node[(k<<1)+1] + node[(k<<1)+2];
        }
    }
};


int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll N, D, A; cin >> N >> D >> A;
    pair<ll,ll> info[N];
    rep(i, N){
        ll x, hp; cin >> x >> hp;
        info[i].first = x; info[i].second = hp;
    }
    sort(info, info+N);
    //iを左端として狙った時,どのモンスターまで含まれるか? -> にぶたん
    ll involve[N];
    rep(i, N){
        ll range = info[i].first + D*2;
        ll ok = -1, ng = N;
        ll m = (ok+ng)/2;
        while(abs(ok-ng) > 1){
            if(info[m].first <= range) ok = m;
            else ng = m;
            m = (ok+ng)/2;
        }
        involve[i] = ok;
    }

    vector<ll> HP(N); rep(i, N) HP[i] = info[i].second;
    LazySegmentTree lst(HP);
    ll ans = 0;
    rep(i, N){
        ll rem = lst.getsum(i, i+1);
        if(rem > 0){
            ll bomb = (rem+A-1)/A;
            ans += bomb;
            lst.update(i, involve[i]+1, -A*bomb);
            //cout << "i: " << i << ", throw " << bomb << " bombs" << endl;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16512
#include <iostream>
#include <vector>
#include <string>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <climits>
#include <map>
#include <functional>
#include <cmath>
#include <cassert>

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<vector<pair<char,int>>> ss(n);
    for (int i = 0; i < n; i++) {
        string s;
        cin >> s;
        for (int j = 0; j < s.size(); j++) {
            ss[i].push_back(make_pair(s[j],count(s.begin(),s.begin()+j,s[j])));
        }
        sort(ss[i].begin(), ss[i].end());
    }
    vector<pair<char,int>> acc = ss[0];
    for (int i = 1; i < n; i++) {
        vector<pair<char,int>> tmp;
        set_intersection(acc.begin(), acc.end(),
                         ss[i].begin(), ss[i].end(),
                         back_inserter(tmp));
        acc = tmp;
    }

    for (auto it = acc.begin(); it != acc.end(); it++) {
        cout << it->first;
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i,m,n,p,r,ans,sum=0;
  int x[1001];
  
  for(;;){
    scanf("%d %d %d", &n, &m, &p);
    if(n==0&&m==0&&p==0) break;

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

    r=sum*(100-p);

    if(x[m-1]!=0){
      ans=r/x[m-1];
    } else if(x[m-1]==0){
      ans=0;
    }

    printf("%d\n", ans);
    sum=0;
  }

  return 0;
}


Measured memory_bytes: 600
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

int readint() {
    return readln.chomp.to!int;
}

int[] readints() {
    return readln.split.map!(to!int).array;
}

void calc(Vec2 p, Vec2 a, Vec2 b) {
    auto ab = b - a;
    auto ap = p - a;

    auto d = ab.normalize().dot(ap);
    auto x = a + ab.normalize() * d;
    writefln("%.8f %.8f", x.x, x.y);
}

void main() {
    auto xs = readints();
    auto p1 = Vec2(xs[0], xs[1]);
    auto p2 = Vec2(xs[2], xs[3]);

    int q = readint();
    for (int i = 0; i < q; i++) {
        auto xy = readints();
        auto p = Vec2(xy[0], xy[1]);
        calc(p, p1, p2);
    }
}

struct Vec2 {
    immutable double x;
    immutable double y;

    this(double x, double y) {
        this.x = x;
        this.y = y;
    }

    Vec2 opAdd(Vec2 other) {
        return Vec2(this.x + other.x, this.y + other.y);
    }

    Vec2 opSub(Vec2 other) {
        return Vec2(this.x - other.x, this.y - other.y);
    }

    Vec2 opMul(double d) {
        return Vec2(this.x * d, this.y * d);
    }

    double dot(Vec2 other) {
        return this.x * other.x + this.y * other.y;
    }

    double cross(Vec2 other) {
        return this.x * other.y - other.x * this.y;
    }

    double mag() {
        return sqrt(magSq());
    }

    double magSq() {
        return this.x * this.x + this.y * this.y;
    }

    Vec2 normalize() {
        auto m = mag();
        if (m != 0 && m != 1)
            return Vec2(this.x / m, this.y / m);
        return this;
    }

    static double distance(Vec2 a, Vec2 b) {
        return (a - b).mag();
    }
}

Measured memory_bytes: 2584
///supercalifragilisticexpialidocious.
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cassert>
#include <cstdlib>
#include <cctype>
#include <ctime>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <numeric>
#include <utility>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <list>
#include <bitset>
#include <complex>
using namespace std;
#define f first
#define s second
#define PB pop_back 
#define pb push_back
#define mp make_pair
#define int long long
#define y1 y_golabi
#define sz(s) (int)s.size()
#define seper(n) setprecision(n)
#define all(v) v.begin(),v.end()
#define mem(a,b) memset(a,b,sizeof a)
#define IOS ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll; 
typedef map<int , int> mii;
typedef pair<int , int> pii; 
typedef map<string , int> msi;
typedef pair<int , string> pis; 
typedef pair<int , pair<int , int> > piii;
const int MAXN = 2e5 + 10;
int n , a[MAXN] , prs[MAXN] , ans;
mii mpp;
int32_t main()
{
	cin >> n;
	for(int i = 0 ; i < n ; i ++)
		cin >> a[i];
	for(int i = 1 ; i <= n ; i ++)
		prs[i] = prs[i - 1] + a[i - 1];
	for(int i = 0 ; i <= n ; i ++)
		mpp[prs[i]] ++;
	for(auto it : mpp)
		if(it.s >= 2)
			ans += it.s * (it.s - 1) / 2;
	return cout << ans << endl , 0;
}



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

using namespace std;

#define int long long

int mod = 1e9 + 7;
int const maxn = 2e6 + 5;
int f[maxn], rev[maxn];

int st(int a, int b) {
    if (b == 0) return 1;
    if (b % 2 == 0) {
        int c = st(a, b / 2);
        return c * c % mod;
    }
    return a * st(a, b - 1) % mod;
}

int answer(int x, int y) {
    int ans = 0;
    if (min(x, y) < 0) return 0;
    for (int i = 0; i <= x; ++i) {
        if (y == 0) {
            ans++;
            if (ans >= mod) ans -= mod;
            continue;
        }
        int s = f[i + 1 + y] * rev[i + 1] % mod;
        s *= rev[y];
        s %= mod;
        ans += s;
        if (ans >= mod) ans -= mod;
    }
    return ans;
}

main() {
#ifdef HOME
    //freopen("input.txt", "r", stdin);
#endif // HOME
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int r1, c1, r2, c2, ans = 0;
    f[1] = 1;
    for (int i = 2; i < maxn; ++i) f[i] = f[i - 1] * i % mod, rev[i] = st(f[i], mod - 2);
    cin >> r1 >> c1 >> r2 >> c2;
    cout << (answer(r2, c2) + answer(r1 - 1, c1 - 1) - answer(r2, c1 - 1) - answer(r1 - 1, c2) + 2 * mod) % mod << '\n';
    return 0;
}



Measured memory_bytes: 31616
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi =vector<vi>;

int main(){
  int K;
  int N;
  cin >>K>>N;
  vi A(N);
  vi B(N);
  for(int i=0;i<N;i++) cin >>A[i];
 
  B[N-1]=K-A[N-1]+A[0];
  for(int i=0;i<N-1;i++) B[i]=A[i+1]-A[i];
  
  sort(B.begin(),B.end());
  int ans=0;
  for(int i=0;i<N-1;i++) ans+=B[i];
  cout << ans <<endl;
}
  



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

struct edge{
	int to;
	int cost;
};

vector<edge> to[20];
int dp[40000][20];
const int INF = 1001001001;

int main(){
	int v,e;
	cin >> v >> e;
	
	rep(i,e){
		int s,t,d;
		cin >> s >> t >> d;
		to[s].push_back(edge{t,d});
	}
	
	int ans = INF;

	rep(i,v){
		rep(i,1<<v){
			rep(j,v){
				dp[i][j] = INF;
			}
		}
		dp[1<<i][i] = 0;
		rep(s, 1<<v){
			rep(j, v){
				if(!(s & (1<<j))) continue;
				for(auto nextv: to[j]){
					if(s == (1<<v)-1 && nextv.to == i){
						ans = min(ans, dp[s][j] + nextv.cost);
					}
					if(s & (1<<nextv.to)) continue;
					dp[s | (1<<nextv.to)][nextv.to] = min(dp[s | (1<<nextv.to)][nextv.to], dp[s][j] + nextv.cost);
				}
			}
		}
	}
	
	if(ans == INF) ans = -1;
	cout << ans << endl;
	
	return 0;
}




Measured memory_bytes: 5696
#include <bits/stdc++.h>
#ifdef LOCAL_DEBUG
#define DEBUG 1
#define CERR if(DEBUG) cerr
#define MACRO(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,NAME,...) NAME
#define pr(...) CERR<<MACRO(__VA_ARGS__,pr10,pr9,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__)<<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define pr9(a,b,c,d,e,f,g,h,i) pr1(a)<<pr8(b,c,d,e,f,g,h,i)
#define pr10(a,b,c,d,e,f,g,h,i,j) pr1(a)<<pr9(b,c,d,e,f,g,h,i,j)
#define prArr(a){CERR<<(#a)<<"={";int i=0;for(auto t:(a))CERR<<(i++?", ":"")<<t;CERR<<"}"<<endl;}
#else
#define DEBUG 0
#define pr(...)
#define prArr(a)
#endif
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE
Int N;
vector<Int> A;
vector<Int> Idx;

Int used[2010][2010];
Int mem[2010][2010];
Int dfs(Int l, Int r, Int i){
  if(i == N) return 0;
  if(used[l][r]++) return mem[l][r];
  Int idx = Idx[i];
  Int a = dfs(l + 1, r, i + 1) + A[idx] * abs(l - idx);
  Int b = dfs(l, r - 1, i + 1) + A[idx] * abs(r - idx);
  Int res = max(a, b);
  return mem[l][r] = res;
}

signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin>>N;
  A.resize(N);
  cin>>A;

  Idx.resize(N); iota(Idx.begin(), Idx.end(), 0);
  sort(Idx.begin(), Idx.end(), [&](Int a, Int b){return A[a] > A[b];});

  Int ans = dfs(0, N-1, 0);
  cout<<ans<<endl;


  return 0;
}


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

void print(string moto);
string reverse(string moto);
string replace(string moto);

int main(){
    string str;
    int n;
    cin>>str;
    cin>>n;
    for(int i=0;i<n;i++){
        string meirei;
        cin>>meirei;
        if(meirei=="print")print(str);
        if(meirei=="reverse")str=reverse(str);
        if(meirei=="replace")str=replace(str);
        }
    return 0;
}

void print(string moto){
    int a,b;
    cin>>a>>b;
    string modori="";
    for(int j=a;j<b+1;j++){
        modori+=moto[j];
    }
    
    cout<<modori<<endl;
}

string reverse(string moto){
    int a,b;
    cin>>a>>b;
    string modori=moto;
    for(int j=a;j<b+1;j++){
        modori[j]=moto[b+a-j];
    }
    return modori;
}

string replace(string moto){
    int a,b;
    cin>>a>>b;
    string koukann;
    cin>>koukann;
    string modori=moto;
    for(int j=a;j<b+1;j++){
        modori[j]=koukann[j-a];
    }
    return modori;
}


Measured memory_bytes: 3232
#include <stdio.h>

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int c1, c2, c3;
  int i;

  while ( scanf ( "%d%d%d", &c1, &c2, &c3 ) == 3 )
  {
    int d[ 11 ] = { 0 };
    int res = 0;

    d[ c1 ] = d[ c2 ]
            = d[ c3 ]
            = 1;

    for ( i = 1; i <= 10; ++i )
    {
      res += !!( !d[ i ] && c1 + c2 + i <= 20 );
    }

    puts ( res > 3 ? "YES" : "NO" );
  }

  return ( 0 );
}

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

// definition {{{ 1

// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)

#define Scll(x) scanf("%llu", &x)
#define Scll2(x,y) scanf("%llu%llu", &x, &y)
#define Scll3(x,y,z) scanf("%llu%llu%llu", &x, &y, &z)

#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2

// constants {{{ 2
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
// }}} 2

// systems {{{ 2
#define Rep(x,y) for(int x = 0; x < y; x++)
#define Repe(x,y,z) for(int x = z; x < y; x++)
// }}} 2

// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n");
// }}} 2

// }}} 1

int main() {

    ll a,b,c;
    ll ans = 0;
    Scll3(a,b,c);
    if( c>(a+b) ){
        ans = (a+b)+b+1;
    }else{
        ans = b+c;
    }

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

    return 0;
}



Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int a[3],i,j,min;
	cin>>a[0]>>a[1]>>a[2];
	min=20001;
	for(i=0;i<2;i++){
		for(j=i+1;j<3;j++){
			if(min>a[i]+a[j])min=a[i]+a[j];
		}
	}
	cout<<min<<endl;
	return 0;
}

Measured memory_bytes: 256
using System;

namespace B___Checkpoints
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var n = int.Parse (input[0]);
            var m = int.Parse (input[1]);
            var s = new Tuple<int, int>[n];
            var c = new Tuple<int, int>[m];
            for (var i = 0; i < n; i++)
            {
                input = Console.ReadLine ().Split (' ');
                s[i] = Tuple.Create (int.Parse (input[0]), int.Parse (input[1]));
            }
            for (var i = 0; i < m; i++)
            {
                input = Console.ReadLine ().Split (' ');
                c[i] = Tuple.Create (int.Parse (input[0]), int.Parse (input[1]));
            }
            var min = int.MaxValue;
            var minIA = new int[n];
            for (var i = 0; i < s.Length; i++)
            {
                var minI = 0;
                for (var j = 0; j < c.Length; j++)
                {
                    var x = Math.Abs (s[i].Item1 - c[j].Item1) + Math.Abs (s[i].Item2 - c[j].Item2);
                    if (x < min)
                    {
                        min = x;
                        minI = j + 1;
                    }
                }
                minIA[i] = minI;
                min = int.MaxValue;
            }
            foreach (var p in minIA)
            {
                Console.WriteLine (p);
            }
        }
    }
}

Measured memory_bytes: 11348
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

    s=str(input())
    ls=len(s)
    if ls%2==1:
        print('No')
    else:
        if s=='hi'*(ls//2):
            print('Yes')
        else:
            print('No')


resolve()

Measured memory_bytes: 38256
// {{{
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#if __cplusplus >= 201103
#include <numeric>
#endif
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORR(i, a, b) for(int i = (a); i >= (b); i--)
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()

//#if __cplusplus >= 201103
typedef long long ll;
//#endif
typedef pair<int, int> P;
typedef pair<int, P> IP;

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

const int INF = 100000000;
//#if __cplusplus >= 201103
const ll LINF = 10000000000000000ll;
//#endif
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
// }}}

ll a, b;

void init()
{
}

void solve()
{
    ll ans = 0;
    do{
        ans++;
        a *= 2;
    }while(a <= b);
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> a >> b;
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define vi vector<int>
#define vvi vector<vector<int> >
#define mii map<int,int>
#define pb push_back
#define pii pair<int,int>
#define mkp make_pair
#define scan(a,n) for(int i =0 ; i<n ; i++) cin>>a[i]
#define print(a,n) for(int i = 0 ; i < n ; i++) cout<<a[i]<<' '
#define mem(a,v) memset(a,v,sizeof(a))
#define loop(i,a,n) for (int i = a; i < n; i++)
#define FastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PRECISION std::cout.unsetf ( std::ios::floatfield );std::cout.precision(15)
double PI=acos(-1.0);
using namespace std;
int mod = 1000000007;
int inf=INT_MAX;
int minf = INT_MIN;

/*int main()
{
    int x;
    cin>>x;
    if(x>=30)
        cout<<"Yes";
    else
        cout<<"No";
}*/

int main()
{
    ll n,d;
    cin>>n>>d;
    int cnt=0;
    while(n--)
    {
        ll x,y;
        cin>>x>>y;
        ll temp=x*x+y*y;
        ll ans=ceil(sqrt(temp));
        //cout<<ans<<endl;
        if(ans<=d)
            cnt++;
    }
    cout<<cnt;
}


Measured memory_bytes: 3700
# A, B = [int(i) for i in input().split(" ")]
# A = int(input())
# As = [int(i) for i in input().split(" ")]
# Ss = ["".join(sorted(input())) for _ in range(N)]

A = input()
m = {"Sunny": "Cloudy",
 "Cloudy": "Rainy",
 "Rainy": "Sunny"}
print(m[A])



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

int main() {
  int n,y,h;
  cin >> n >> y;
  bool jamp = false;
  bool ans = true;
  y = y/1000;
  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      h = n - i - j;
      if(h >= 0 && 10*i + 5*j + h == y){
        cout << i << " " <<  j << " " << h << endl;
        ans = false;
        jamp = true;
        break;
      }
    }
    if(jamp){
      break;
    }
  }
  
  if(ans){
    cout << -1 << " " <<  -1 << " " << -1 << endl;
  }
}

        


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

using ll = long long;

#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 pb push_back
#define mp make_pair
#define fill(x, y) memset(x, y, sizeof(x))
#define even(x) x % 2 == 0
#define odd(x) x % 2 != 0
#define all(x) x.begin(), x.end()
#define pcnt __builtin_popcount
#define buli(x) __builtin_popcountll(x)
#define F first
#define S second
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

// these functions return the position of result of Binary Search.
#define LB(s, t, x) (int) (lower_bound(s, t, x) - s)
#define UB(s, t, x) (int) (upper_bound(s, t, x) - s)

ll qp(ll a, ll b, int mo) { ll ans = 1; do { if (b & 1) ans = 1ll * ans * a % mo; a = 1ll * a * a % mo; } while (b >>= 1); return ans; }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts>
auto make_v(size_t a, size_t b, Ts... ts) { return vector<decltype(make_v<T>(b, ts...))>(a, make_v<T>(b, ts...)); }
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }
// auto dp = make_v<int>(4, h, w);
// fill_v(dp, 0);

const ll INF_LL = (1ll << 60);
const int INF_INT = (int)1e9;
const ll MOD_CONST = (ll)(1e9 + 7);

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; }

inline tuple<ll, ll> rotate45(tuple<ll, ll> p) { ll x = get<0>(p), y = get<1>(p); return tuple<ll, ll>(x + y, x - y); }

int main(void)
{
	cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(20);

	ll A, B, C; cin >> A >> B >> C;
	ll K; cin >> K;
	ll ans = 0, p = 0;
	if (A >= B and A >= C) p = A, ans = B + C;
	else if (B >= A and B >= C) p = B, ans = A + C;
	else p = C, ans = A + B;
	REP(i, K) p *= 2;
	cout << p + ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

def main():
	n,k=MI()
	li=[LI() for _ in range(n)]
	#print(li)

	ans=10**20

	X=[]
	Y=[]

	for x,y in li:
		X.append(x)
		Y.append(y)
	X.sort()
	Y.sort()
	#print(X,Y)

	for i in range(n):
		for ii in range(i+1,n):
			for j in range(n):
				for jj in range(j+1,n):
					cnt=0
					for x,y in li:
						if X[i]<=x<=X[ii] and Y[j]<=y<=Y[jj]:
							cnt+=1
					#print(i,ii,j,jj,X[i],X[ii],Y[j],Y[jj],cnt,ans)
					if cnt>=k:
						ans=min(ans,(X[ii]-X[i])*(Y[jj]-Y[j]))

	print(ans)












if __name__ == "__main__":
	main()


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;


int main() {
  int N; cin >> N;
  int A[N][N] = {};
  rep(i,N) {
    int num; cin >> num;
    rep(j,num) {
      int x, y; cin >> x >> y; x--;
      A[i][x] = y ? 1 : -1;
    }
  }

  int result = 0;
  rep(i,(1<<N)) {
    int t[N] = {}; rep(j,N) t[j] = (i&(1<<j)) ? 1 : -1;
    int count = 0; rep(j,N) if (i&(1<<j)) count++;
    bool ok = true;
    rep(j,N) {
      if (t[j]!=1) continue;
      rep(k,N) {
        if (A[j][k]==1&&t[k]!=1) ok = false;
        if (A[j][k]==-1&&t[k]!=-1) ok = false;
      }
    }
    // rep(j,N) cout << t[j] << " "; cout << endl;
    if (ok) result = max(result, count);
  }
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 256
x,a,b = map(int,input().split())
A= 1
syoumikigen = A + a
B = A + b
safe = syoumikigen + x
out = safe + 1
if B <= syoumikigen:
    print("delicious")
elif syoumikigen < B <= safe:
    print("safe")
else:
    print("dangerous")  




Measured memory_bytes: 2940
/*
@author: sharrad99
*/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld double
#define mp make_pair
#define ff first
#define ss second
#define mll map<ll,ll>
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define mod 1000000007
#define INF 10000000010
vector<vector<ll> > d(300,vector<ll>(300,INF));
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n,m,l;
	cin>>n>>m>>l;
	for(ll i=0;i<n;i++){
		d[i][i]=0;
	}
	for(ll i=0;i<m;i++){
		ll u,v,c;
		cin>>u>>v>>c;
		--u,--v;
		d[u][v]=c;
		d[v][u]=c;
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			for(ll k=0;k<n;k++){
				d[j][k]=min(d[j][k],(d[j][i]+d[i][k]));
			}
		}
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			d[i][j]=d[i][j]<=l ? 1:INF;
		}
	}
	for(ll i=0;i<n;i++){
		for(ll j=0;j<n;j++){
			for(ll k=0;k<n;k++){
				d[j][k]=min(d[j][k],(d[j][i]+d[i][k]));
			}
		}
	}
	ll q;
	cin>>q;
	while(q--){
		ll s,t;
		cin>>s>>t;
		--s,--t;
		ll res=(d[s][t]==INF) ? -1:d[s][t]-1;
		cout<<res<<"\n";
	}
}

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

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
static const double EPS = 1e-12;
static const double PI = acos(-1.0);

#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define ALL(a) (a).begin(), (a).end()
#define DEBUG(x) cout << #x << ": " << x << endl

void solve(long long L, long long R, long long d) {
  ll ans = 0;
  FOR(i, L, R + 1) {
    if (i % d == 0) {
      ans++;
    }
  }
  cout << ans << endl;
}

int main() {
  long long L;
  scanf("%lld", &L);
  long long R;
  scanf("%lld", &R);
  long long d;
  scanf("%lld", &d);
  solve(L, R, d);
  return 0;
}


Measured memory_bytes: 3656
while True:
    a,op,b=input().split()
    if op == '+':
        r = int(a)+int(b)
    elif op == '-':
        r = int(a)-int(b)
    elif op == '*':
        r = int(a)*int(b)
    elif op == '/':
        r = int(a)//int(b)
    elif op == '?':
        break;
    print(r)


Measured memory_bytes: 5596
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define str to_string
#define endl "\n"
#define PI 3.141592653589
using namespace std;
using lint = long long;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

//AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC(*'ω'*)AC
int main(){
    int n,ans=0;cin>>n;
    vector<string> s(n);
    vector<int> t(n);
    for(int i=0;i<n;i++)cin>>s[i]>>t[i];
    string st;cin>>st;
    bool sleep=false;
    for(int i=0;i<n;i++){
        if(!sleep){
            if(s[i]==st)sleep=true;
        }
        else{
            ans+=t[i];
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3552
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
const LL MOD = 1000000007LL;
vector<int> G[100000];
bool in[100000];
int main() {
	int N, M;
	cin >> N >> M;
	int s, t;
	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b; a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
		s = a;
		t = b;
	}
	in[s] = in[t] = 1;
	deque<int> Q;
	Q.push_back(s);
	Q.push_back(t);
	while (1) {
		bool update = 0;
		for (int to : G[s]) {
			if (in[to]) continue;
			Q.push_front(to);
			in[to] = 1;
			s = to;
			update = 1;
			break;
		}
		if (!update) break;
	}
	while (1) {
		bool update = 0;
		for (int to : G[t]) {
			if (in[to]) continue;
			Q.push_back(to);
			in[to] = 1;
			t = to;
			update = 1;
			break;
		}
		if (!update) break;
	}
	cout << Q.size() << endl;
	cout << Q.front() + 1; Q.pop_front();
	while (!Q.empty()) {
		cout << " " << Q.front() + 1; Q.pop_front();
	}
	cout << endl;
}

Measured memory_bytes: 6784
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	long double r, ans;
	cin >> r;
	ans = 3.1415926 * r * 2;
	cout << setprecision(10) << fixed << ans << "\n";

	return 0;
}


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

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

class unionfind {
public:
    vector<int> par;
    int n;
    unionfind(int m) : n(m), par(vector<int>(m, -1)) {}
    int find(int i) {
        if (par[i] < 0) return i;
        return par[i] = find(par[i]);
    }
    bool same(int i, int j) {
        return find(i) == find(j);
    }
    int size(int i) {
        return -par[find(i)];
    }
    void unite(int i, int j) {
        if (find(i) == find(j)) return;
        if (size(i) < size(j)) swap(i, j);
        int I = find(i), J = find(j);
        par[I] += par[J];
        par[J] = I;
    }
};

int mod = 1000000007;
int dp[100005][2];

main() {
    dp[0][0] = 1;
    int n, m; cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
        dp[i][1] = dp[i - 1][0] + dp[i - 1][1];
        if (i >= m) {
            dp[i][1] += mod;
            dp[i][1] -= dp[i - m][0];
        }
        rep (k, 2) dp[i][k] %= mod;
    }
    int ans = 1;
    rep (i, n) {
        ans *= 2;
        ans %= mod;
    }
    cout << (((ans += 2 * mod) -= (dp[n][0] + dp[n][1])) %= mod) << endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> v(2*n);
    for(int i=0; i<2*n; ++i) {
        v[i] = i+1;
    }
    for(int i=0; i<m; ++i) {
        int k; cin >> k;
        vector<int> tmp(2*n);
        if(k == 0) {
            for(int j=0; j<n; ++j) {
                tmp[2*j] = v[j];
                tmp[2*j+1] = v[j+n];
            }
        } else {
            for(int j=0; j<2*n; ++j) {
                tmp[j] = v[(k+j)%(2*n)];
            }
        }
        v = move(tmp);
    }
    for(auto x : v) {
        cout << x << endl;
    }
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define int long long
using namespace std;
using P = pair<int, int>;
using ll = long long;
using prique = priority_queue<int>;
const ll INF = LLONG_MAX/3;

/*-----Library-----*/

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

struct UnionFind {
    vector<int> par; // 親ノード
    vector<int> rank; // ランク
    vector<int> sizeuf; //要素数
    UnionFind(int n = 1) {
        init(n);
    }

    void init(int n = 1) {
        par.resize(n); rank.resize(n); sizeuf.resize(n);
        for (int i = 0; i < n; ++i) {
            par[i] = i;
            rank[i] = 0;
            sizeuf[i]=1;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            return par[x] = r;
        }
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y);
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        sizeuf[x]+=sizeuf[y];
        return true;
    }

    int size(int x){
        return sizeuf[root(x)];
    }
};

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

long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}
//コンビネーション
/*
long long 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;
}
 */
/*-----Library-----*/
const int MOD=1234567;
int n,k;
bool isOK(int p){
	int sum=0;
	rep(i,n){
		sum+=p;
		p/=2;
		if(p==0)break;
	}
	return sum<=k;
}
signed main(){
	cin>>n>>k;
	int l=0,r=k+1;
	while(abs(l-r)>1){
		int mid=(l+r)/2;
		if(isOK(mid))l=mid;
		else r=mid;
	}
	cout<<l<<endl;
}




Measured memory_bytes: 3104
#include<stdio.h>
#include<string.h>
int h,w;//hang,lie
char canvas[105][105];
int d[105][105];
int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
void dfs(int x,int y)
{
    char a = canvas[x][y];
    d[x][y]=1;
    for(int i=0;i<4;i++)
    {
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx>=0&&nx<h&&ny>=0&&ny<w&&d[nx][ny]==0&&canvas[nx][ny]==a)
        {
            dfs(nx,ny);
        }
    }
}
int main()
{

    int i,j;
    int a,b;
    while(scanf("%d%d",&h,&w)!=EOF && h!=0 && w!=0)
    {
        int res=0;
        memset(d,0,sizeof(d));
        getchar();
        for(i=0; i<h; i++)
        {
            for(j=0; j<w; j++)
            {
                scanf("%c",&canvas[i][j]);
            }
            getchar();
        }


        ///scanf("%d%d",&a,&b);
        //printf("before %d\n",res);
        for (i = 0; i < h; i++)
        {
            for (j = 0; j < w; j++)
            {
                if (d[i][j]!=1)
                {
                    dfs(i,j);
                    ++res;
                }
            }
        }
       // printf("after %d\n",res);
//        for(i=0; i<h; i++)
//        {
//            for(j=0; j<w; j++)
//            {
//                printf("%d",d[i][j]);
//            }
//            printf("\n");
//        }

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



Measured memory_bytes: 2376
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <cmath>

using namespace std;
#define PI 3.1415926535897932384626433832795
#define MOD (1000000007)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define swap(a, b, type) { type _tmp = a; a = b; b = _tmp; }
typedef long long ll;
typedef unsigned long long ull;

string ss[100];

int main()
{
	int N, M, ans = 0;
	string s, t;
	map<string, int> ms, mt;

	cin >> N;
	rep(i, N) {
		cin >> s;
		ss[i] = s;
		if (ms.count(s) == 0) ms[s] = 1;
		else ms[s]++;
	}

	cin >> M;
	rep(i, M) {
		cin >> t;
		if (mt.count(s) == 0) mt[t] = 1;
		else mt[t]++;
	}

	rep(i, N) {
		if (mt.count(ss[i]) == 0) ans = max(ans, ms[ss[i]]);
		else ans = max(ans, ms[ss[i]] - mt[ss[i]]);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int r=sc.nextInt(),g=sc.nextInt(),b=sc.nextInt(),n=sc.nextInt(),count=0;
    for(int i=0;i<=n;i++) {
    	for(int j=0;j<=n-i;j++) {
    		if((n-(i*r+j*g))%b==0 && n-(i*r+j*g)>=0)count++;
    		//System.out.print(n-(i*r+j*g)+" ");
    	}
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

int main(){
    string s;
    cin >> s;
    ll a_local = 0;
    ll z_local = 0;

    for (ll i = 0; i < s.size(); i++){
        if (s[i] == 'A'){
            a_local = i;
            break;
        }
    }

    for (ll i = s.size()-1; i>=0; i--){
        if (s[i] == 'Z'){
            z_local = i;
            break;
        }
    }

    cout << z_local-a_local+1 << endl;
}

Measured memory_bytes: 640
#include<stdio.h>
int binarySearch(int key,int n,int A[]){
  int left=0;
  int right = n;
  int mid;
  while(left < right){
    mid=(left + right)/2;
    if(A[mid]==key)return 1;
    else if(key<A[mid])right=mid;
    else left = mid +1;
  }
  return 0;
}
int main(){
  int A[1000000];
  int n,i,q,k,sum=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&k);
    if(binarySearch(k,n,A)!=0)sum++;
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2128
/********** BiSmIlLaHiR rAhMaNiR rAhIm ***********\
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
*$*                                             *$*
*$*    ||||||||  ||||||||  ||||||||  ||||||||   *$*
*$*    ||    ||  ||           ||     ||         *$*
*$*    ||||||||  ||||||||     ||     ||||||     *$*
*$*    ||    ||        ||     ||     ||         *$*
*$*    ||    ||  ||||||||  ||||||||  ||         *$*
*$*                                             *$*
*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*$*
\*************** DIIT(17th batch) ****************/

#include<bits/stdc++.h>
#define ll long long int
#define ul unsigned long long int
#define pf printf
#define sf scanf
#define fs first
#define ss second
#define endl "\n"
#define pb push_back
#define makep make_pair
#define MOD 1000000007
#define PI acos(-1.0)
#define PII pair<ll , ll>
#define ki_ase(x,y) cout<<x<<" "<<y<<endl;
#define SIZE 200000000
#define fio() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
ll fx[]={1,0,-1,0,-1,-1,1,1};
ll fy[]={0,1,0,-1,-1,1,-1,1};


int main()
{
    fio();
    
    ll n,m,i;
    cin>>n>>m;
    ll a[n];
    ll l=1,r=0;
    for ( i = 0; i < n; i++)
    {
        cin>>a[i];
        r=max(a[i],r);
    }
    while(l<r){
        ll mid=(l+r)/2;
        ll cnt=0;
        for(i=0;i<n;i++){
            cnt+=(a[i]+mid-1)/mid;
            cnt--;
        }
        if(cnt>m)
            l=mid+1;
        else
            r=mid;
    }
    cout<<l<<endl;
    return 0;
}

Measured memory_bytes: 5088
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

bool f1 = false;
string s;

int main()
{
	cin >> s;
	for (int i = 0; i < s.length(); i++)
	{
		if (s[i] == 'C') f1 = true;
		if (f1 && s[i] == 'F') return cout << "Yes\n", 0;
	}
	cout << "No\n";
	return 0;
}

Measured memory_bytes: 256