akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <string.h>
#include <bitset>
#include <stack>
#define Endl endl
#define mp make_pair
#define ll long long 
#define pii pair<int,int>
#define pll pair<ll,ll>
#define over(A) {cout<<A<<endl;exit(0);}
#define all(A) A.begin(),A.end()
#define ceil(a,b) ((a-1)/b+1)
#define srand() mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rand(l,r) uniform_int_distribution<int>(l,r)(rng)
typedef unsigned long long ull;
const int inf=1039074182;
using namespace std;
int a[45];
vector <int> vec[45];
int n,m;
int best;
bitset <40> connect[45];

inline int getcost(bitset <40> bit)
{
	int res=0;
	for(int i=0;i<40;i++)
	{
		if(bit[i]) res+=a[i];
	}
	return res;
}

void dfs(int x,int cost,bitset<40> now)
{
//	if(cost!=getcost(now)) cout<<x<<' '<<cost<<' '<<now<<endl;
	int newcost=cost+getcost(connect[x] ^ (now & connect[x]));
	if(newcost>=best) return;
	if(x==n-1)
	{
		best=newcost;
		return;
	}
	bitset <40> t;
	for(int i=0;i<vec[x].size();i++)
	{
		if(now[vec[x][i]]) continue;
		dfs(vec[x][i],newcost,now | connect[x]);
	}
}

int main()
{
//	freopen("input.txt","r",stdin);
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		connect[i][i]=true;
	}
	int x,y;
	for(int i=0;i<m;i++)
	{
		cin>>x>>y;
		x--;
		y--;
		vec[x].push_back(y);
		vec[y].push_back(x);
		connect[x][y]=true;
		connect[y][x]=true;
	}
	int cost=0;
	for(int i=0;i<n;i++)
	{
		if(connect[0][i]) cost+=a[i];
	}
	best=inf;
	dfs(0,0,0);
	cout<<best<<endl;
	return 0;
}


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

typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);i++)
#define rep(i,n) FOR(i,0,n)
#define mset(a,x) memset(a,x,sizeof(a))

ll dp[51][51][3000];

int main() {
    int n, a;
    cin >> n >> a;
    vector<int> x(n);
    for(int& i : x) cin >> i;

    mset(dp, 0);
    dp[0][0][0] = 1;
    FOR(j, 1, n+1){
        FOR(k, 0, j+1){
            FOR(s, 0, 2500+1){
                dp[j][k][s] = dp[j-1][k][s];
                if(k>=1 and s>=x[j-1]){
                    dp[j][k][s] += dp[j-1][k-1][s-x[j-1]];
                }
            }
        }
    }

    ll ans = 0;
    FOR(i,1,n+1) if(a*i < 2510) ans += dp[n][i][a*i];
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 61184
#include <bits/stdc++.h>
using namespace std;
const int maxn = 800;
int c[maxn], s[maxn], f[maxn];
int main() {
	int n;
	cin >> n;
	for(int i= 0; i < n - 1; ++i) cin >> c[i] >> s[i] >> f[i];
	for(int i = 0; i < n - 1; ++i){
		long long now = s[i] + c[i];
		for(int j = i + 1; j < n - 1; ++j){
			long long need = max( (long long)ceil( (now - s[j])*1.0/f[j] ) , 0LL ); //s[i] + x*f[i] >= now
			now = s[j] + need*f[j] + c[j];
		}
		cout << now << endl;
	}
	cout << 0;
	return 0;
}

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

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	
	//d[i][j]:=?????????s1???1?????????~i??????????????§?????¨??????????????¨?????????s2???1?????????~j??????????????§?????¨?????????????????¨????????¢
	//(index???0?????¨??????????????????????????¨???)
	int d[1001][1001]={0};
	
	//????????????????????????0??????????????????????????\?????????????¶???????????????????
	for(int i=0; i<=s1.size(); ++i) d[i][0]=i;
	for(int i=0; i<=s2.size(); ++i) d[0][i]=i;
	
	for(int i=1; i<=s1.size(); ++i){
		for(int j=1; j<=s2.size(); ++j){
			int tmp = d[i-1][j-1];
			if(s1[i-1]!=s2[j-1]) tmp++;
			
			d[i][j] = min(tmp, min(d[i-1][j]+1,d[i][j-1]+1));
		}
	}
	
	printf("%d\n", d[s1.size()][s2.size()]);
}

Measured memory_bytes: 5108
#include<bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) \
  for (ll i = static_cast<int>(a); i < static_cast<int>(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, ) (__VA_ARGS__)  // NOLINT
#define chmax(x, a)  do { x = max(x, a); } while(0)
#define chmin(x, a)  do { x = min(x, a); } while(0)

using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<ll,ll> PLL;

// Segment Tree {{{
template <typename T>
class SegTree {
 private:
    int _n;
    T _init_val;
    std::vector<T> _data;
    std::function<T(T, T)> _f;

    T _query(int a, int b, int k, int l, int r) {
        // [a b)と[l r]が交差しない
        if (r <= a || b <= l) return _init_val;

        // [a b)が[l r]を含む
        if (a <= l && r <= b) return _data[k];

        T vl = _query(a, b, k*2+1, l, (l+r)/2);
        T vr = _query(a, b, k*2+2, (l+r)/2, r);

        return _f(vl, vr);
    }

 public:
    SegTree(int n, T init_val, std::function<T(T, T)> f) {
        _init_val = init_val;
        _n = 1;
        _f = f;

        while (_n < n)
            _n *= 2;
        _data.resize(2 * _n, init_val);
    }

    T get(int k) {
        return _data[k + _n - 1];
    }

    void update(int k, T a) {
        k += _n-1;
        _data[k] = a;
        while (k > 0) {
            k = (k-1)/2;
            _data[k] = _f(_data[k*2+1], _data[k*2+2]);
        }
    }

    // [a b)の範囲でfを適用
    T query(int a, int b) {
        return _query(a, b, 0, 0, _n);
    }

    // 先頭からチェックし，はじめてxを満たしたインデックス
    int lower_bound(T x) {
        return _lower_bound(x, 0);
    }

    int _lower_bound(T x, int k) {
        if (k >= _n-1) {
            return k - (_n - 1);  // 葉
        } else if (_data[k] < x) {
            return _n;  // 該当なし
        } else if (x <= _data[k * 2 + 1]) {
            return _lower_bound(x, k * 2 + 1);
        } else {
            return _lower_bound(x - _data[k * 2 + 1] , k * 2 + 2);
        }
    }
};
// }}}

typedef tuple<ll, ll, ll> T; // {l, r, idx}
ll N, Q;
vector<ll> a;
vector<T> q;
SegTree<ll> st(600000, 0, [](ll a, ll b) { return a+b;});
vector<ll> lastApp(600000, -1);
vector<ll> ans(600000, -1);

int main() {
  cin >> N >> Q;
  a.resize(N);
  q.resize(Q);
  rep(i, N) {
    cin >> a[i];
  }
  rep(i, Q) {
    ll l, r;
    cin >> l >> r;
    l--, r--;
    q[i] = make_tuple(l,r,i);
  }
  sort(begin(q), end(q), [](const auto &x, const auto &y) {
      ll l1 = get<0>(x), r1 = get<1>(x);
      ll l2 = get<0>(y), r2 = get<1>(y);

      if (r1 != r2) {
        return r1 < r2;
      } else {
        return l1 < l2;
      }
      });

  ll i = -1;
  for (auto e : q) {
    ll l = get<0>(e);
    ll r = get<1>(e);
    ll idx = get<2>(e);
    for (ll j = i + 1; j <= r; j++) {
      if (lastApp[a[j]] != -1) {
        st.update(lastApp[a[j]], 0);
      }
      st.update(j, 1);
      lastApp[a[j]] = j;
    }
    i = r;
    ans[idx] = st.query(l, r + 1);
  }
  rep(idx, Q) {
    cout << ans[idx] << endl;
  }
  return 0;
}


Measured memory_bytes: 45164
#include <iostream>

using namespace std;

int main() {
	int ans = 0;
	char ch;


	for (int i = 0; i < 4; i++) {
		cin >> ch;
		switch (ch) {
		case '+':
			ans++;
			break;
		case '-':
			ans--;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
using ll = long long;

struct segtree{
	using D = int;
	D inf = 1e9;

	int N;
	vector<D> val;

	segtree(){}
	segtree(int n){
		N=1;
		while(N<n) N*=2;
		val.assign(N*2,inf);
	}
	D getval(int k){
		k+=N;
		D res = inf;
		while(k){
			chmin(res,val[k]);
			k/=2;
		}
		return res;
	}
	void changemin(int a,int b,D d){
		a+=N,b+=N;
		while(a<b){
			if(a&1){
				chmin(val[a],d);
				a++;
			}
			if(b&1){
				b--;
				chmin(val[b],d);
			}
			a/=2,b/=2;
		}
	}
};


int N;
ll K;
const int MN = 100010;
ll inf = 1e18;
ll A[MN],F[MN];
ll B[MN];
using P = pair<ll,ll>;

ll solve(vector<P> vp){
	int N = vp.size();
	if(N==0) return 0;
	vector<ll> xs;
	xs.pb(0);
	xs.pb(K);
	rep(i,N){
		xs.pb(vp[i].fs);
		xs.pb(vp[i].sc);
	}
	sort(all(xs));
	xs.erase(unique(xs.begin(),xs.end()),xs.end());
	auto getid = [&](ll x){
		return lower_bound(all(xs),x) - xs.begin();
	};
	int X = xs.size();
	segtree seg(X);

	vector<ll> dpl(N,inf),dpr(N,inf);
	for(int i=N-1;i>=0;i--){
		int l = getid(vp[i].fs), r = getid(vp[i].sc);
		{
			int j = seg.getval(l);
			if(j>1e8){
				dpl[i] = 0;
			}else{
				ll dis = vp[j].fs - vp[i].fs;
				if(dis<0) dis += K;
				dpl[i] = dpl[j] + dis;
			}
		}
		{
			int j = seg.getval(r);
			if(j>1e8){
				dpr[i] = 0;
			}else{
				ll dis = vp[j].fs - vp[i].sc;
				if(dis<0) dis += K;
				dpr[i] = dpl[j] + dis;
			}
		}
		if(l<=r){
			seg.changemin(0,l,i);
			seg.changemin(r+1,X,i);
		}else{
			seg.changemin(r+1,l,i);
		}
	}
	ll res = inf;
	rep(i,N){
		int l = getid(vp[i].fs), r = getid(vp[i].sc);
		{
			int j = seg.getval(l);
			if(j>i) chmin(res,dpl[i]);
		}
		{
			int j = seg.getval(r);
			if(j>i) chmin(res,dpr[i]);
		}
	}
	return res;
}

int main(){
	cin>>N>>K;
	rep(i,N){
		cin>>A[i];
		int b;
		cin>>b;
		F[i] = b==2;
	}
	rep(i,N){
		if(!F[i] && A[i]*2>K){
			puts("-1");
			return 0;
		}
	}
	rep(i,N){
		B[i+1] = B[i] + A[i]*2;
	}

	vector<P> vp;
	rep(i,N) if(!F[i]){
		ll l = ((-B[i])%K+K)%K;
		ll r = ((-B[i+1])%K+K)%K;
		vp.pb(P(l,r));
	}
	ll ans = B[N] + solve(vp);
	cout<<ans<<endl;
}

Measured memory_bytes: 10864
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
using namespace std;
using LL = long long;

int main(void)
{
	int n;
	cin >> n;
	int ans = 0;
	switch (n)
	{
	case 0:case 2:ans = 1; break;
	case 1:ans = 2; break;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3104
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n)]
        self.size = [1 for i in range(n)]

    def root(self, x):
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.root(self.parent[x])
            return self.parent[x]

    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            self.parent[x] = y
            self.size[y] += self.size[x]

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

    def count(self, x):
        return self.size[self.root(x)]

N, M = map(int, input().split())
AB = [list(map(lambda x: int(x)-1, input().split())) for _ in range(M)]
ans = 0
for i in range(M):
    un = UnionFind(N)
    for j in range(M):
        if i != j:
            un.unite(AB[j][0], AB[j][1])
    if un.count(0) != N:
        ans += 1
print(ans)


Measured memory_bytes: 9144
#include<iostream>
#include<string>
#include<cstring>
#include<map>
#include<vector>
using namespace std;
int array[51];
int main(){
  int M,N;
  vector<int> v;
  while(cin>>M >>N){
    if(N==0&&M==0){
      break;
    }
    for(int k=0;k<M;k++){//初期化
      array[k]=k+1;
    }
    int p=0,c=0;
    for(int i=0;i<N;i++){
      cin >>p >>c;

      for(int a=0;a<p-1;a++){//上保存
	v.push_back(array[(M-1)-a]);
      }

      for(int t=0;t<c;t++){//下を上へ
	array[(M-1)-t]=array[(M-1)-(p-1)-t];

      }

      for(int l=0;l<p-1;l++){//上を下へ
	array[(M-1)-c-l]=v.front();
	v.erase(v.begin());

      }

      /*
      for(int g=M-1;g>=0;g--){//配列確認
	cout << array[g] <<endl;
	}*/



    }
      cout << array[M-1] <<endl; 
  }
  
  return 0;
}

Measured memory_bytes: 1220
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BTag {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll a, v, b, w; cin >> a >> v >> b >> w;
      ll t; cin >> t;
      if (a == b) {
        cout << "YES" << endl;
        return;
      }
      if (v <= w) {
        cout << "NO" << endl;
        return;
      }
      ll d = abs(a-b);
      ll dv = v - w;
      if (t*dv >= d) {
        cout << "YES" << endl;
      } else {
        cout << "NO" << endl;
      }
    }
};

signed main() {
  BTag solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 3636
N,M,K = map(int, input().split())
mod = 998244353


def make_fact(n):#0~nの階乗を求める
    fact = [1]*(n+1)
    for i in range(1, n+1):
        fact[i] = fact[i-1]*i%mod
    return fact
fact = make_fact(N) #＠
def make_fact_inv(n):#0~nの階乗のmodに関する逆元を求める
    fact_inv = [1]*(n+1)
    fact_inv[n] = pow(fact[n], mod-2, mod)#フェルマーの小定理
    for i in range(n, 0, -1):
        fact_inv[i-1] = fact_inv[i]*i%mod
    return fact_inv
fact_inv = make_fact_inv(N)#＠
def comb(n, k):#nCk
    return fact[n]*fact_inv[k]*fact_inv[n-k]%mod

bekizyo = [1] * N

for i in range(1, N):
    bekizyo[i] = bekizyo[i-1] * (M - 1) % mod



ans = 0

for i in range(K + 1):
    ans += comb(N-1, i) * M * bekizyo[N-i-1]
    ans %= mod

print(ans)

Measured memory_bytes: 75248
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;

int main(){
    ll n;
    cin>>n;
    ll k;
    cin>>k;
    V<ll> w(n),d(n);
    V<P> p(n);
    rep(i,n){
        cin>>w[i]>>d[i];
        p[i]=P(w[i],d[i]);
    }
    sort(all(p));
    ll left=-1,right=9e18+9e16;
    while(right-left>1){
        ll mid=(left+right)/2;
        ll cnt=0;
        rep(i,n){
            if(mid>=p[i].ft) cnt+=(mid-p[i].ft)/p[i].sc+1;
            if(cnt>=k) break;
        }
        if(cnt>=k) right=mid;
        else left=mid;
    }
    cout<<right<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
/*
V,P(大文字)使用不可
乗算の際にオーバーフローに注意せよ！(適切にmodをとれ)
制約をよく読め！
(全探索できるなら全探索しろ)
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'\n'
*/

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

using namespace std;

int main()
{
    int m;
    cin >> m;
    long long c,d;
    stack<int> s;
    long long res=0;
    for(int i=0;i<m;i++)
    {
        cin >> d >> c;
        if(d==0) s.push(0);
        else if((c*d)%9) s.push((c*d)%9);
        else s.push(9);
        c--;
        vector<long long> dp(10,0);
        for(int j=1;j<=9;j++)
        {
            int now;
            if(d==0) now=0;
            else if((j*d)%9) now=(j*d)%9;
            else now=9;
            dp[j]=dp[j-1]+1;
            if(now+d>9) dp[j]++;
        }
        res+=(dp[9]*(c/9)+dp[c%9]);
    }
    while(s.size()>1)
    {
        int b=s.top();
        s.pop();
        int a=s.top();
        s.pop();
        if(a+b<=9) s.push(a+b);
        else
        {
            s.push((a+b)/10);
            s.push((a+b)%10);
        }
        res++;
    }
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1024
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = getLine >> readLine >>= print . solve

solve :: [Int] -> Int
solve = check 0 0 
    where
        check acc p (x : xs)
            | p <= x = check (acc + 1) x xs
            | otherwise = check acc p xs
        check acc _ _ = acc

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine

Measured memory_bytes: 380
int main() {
  int n, m, l;
  scanf("%d %d %d\n", &n, &m, &l);

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

  int b[100 * 100];
  for (int i = 0; i < m * l; i++) {
      scanf("%d", &b[i]);
  }

  for (int i = 0; i < n; i++) {
    for (int j = 0; j < l; j++) {

      long c = 0;
      for (int k = 0; k < m; k++) {
        c += a[i * m + k] * b[k * l + j];
      }
      printf("%ld", c);

      if (j < l - 1) {
        putchar(' ');
      } else {
        putchar('\n');
      }

    }
  }
}


Measured memory_bytes: 2112
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define rRep(i,a,b) for(int i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
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; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
    for(auto i=begin(v); i != end(v); ++i){
        if(i !=begin(v)) os << ' ';
        os << *i;
    }
    return os;
}

ll ans[507];

int main() {
    ll N,C[507],S[507],F[507],t=0;
    cin >> N;
      rep(i,N-1){
        cin >> C[i] >> S[i] >> F[i];
      }
      rep(j,N-1){
        t=0;
        Rep(i,j,N-1){
          if(t<S[i]){
            t=S[i];
          }
          if(t%F[i]!=0){
            t=t+(F[i]-(t%F[i]));
          }
          t+=C[i];
        }
        cout << t << endl;
      }
    cout << 0 << endl;
}

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

int main(void){
  int n, l;
  cin >> n >> l;

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

  sort(s.begin(), s.end());

  for(int i = 0; i < n; i++){ cout << s[i]; }
  cout << endl;

  return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int>vec (N);
  for (int i = 0; i < N; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  int sumA = 0;
  for (int i = 0; i < N; i += 2){
    sumA += vec.at(i);
  }
  int sumB = 0;
  for (int i = 1; i < N; i += 2){
    sumB += vec.at(i);
  }
  cout << sumA - sumB << endl;
}



Measured memory_bytes: 3632
def cin; gets.split.map(&:to_i) end
def cout(*x); puts x.join(" ") end

# exit if $0 != __FILE__

n = gets.chop
puts 'A' if n == 'T'
puts 'T' if n == 'A'
puts 'G' if n == 'C'
puts 'C' if n == 'G'


Measured memory_bytes: 1788
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);

	String[] line = sc.nextLine().split(" ");
	int[] hindo = new int[line.length];
	int max = 0;
	int maxLen = 0;
	for(int i=0; i<line.length; i++){
	    if(line[i].length()>max){max = line[i].length(); maxLen = i;}
	    for(int j=i; j<line.length; j++){
		if(line[i].equals(line[j])){
		    hindo[j]++;
		}
	    }
	}

	max = 0;
	for(int i=0; i<hindo.length; i++){
	    if(hindo[i]>max){max = i;}
	}

	System.out.println(line[max]+" "+line[maxLen]);
    }
}

Measured memory_bytes: 12000
n = input()
b_l = []
for i in range(8):
  b = bin(i)[2:]
  le = len(b)
  b_l.append((3 - le)*"0" + b)


    

s_l = [int(n[i]) for i in range(4)]
    
for b in b_l:
  ans = s_l[0]
  f = 0
  b_s_l = ["+" if b[i] == "0" else "-" for i in range(3)]
  for i in range(3):
    if b_s_l[i] == "+":
      ans += s_l[i+1]
    else:
      ans -= s_l[i+1]
  if ans == 7:
    print(str(s_l[0]) + b_s_l[0] + str(s_l[1]) + b_s_l[1] + str(s_l[2]) + 
          b_s_l[2] + str(s_l[3]) + "=7") 
    break

Measured memory_bytes: 3064
#include <bits/stdc++.h>
            #include<iostream>
            #include<cstdio>
            #include<vector>
            #include<queue>
            #include<map>
            #include<cstring>
            #include<string>
            #include <math.h>
            #include<algorithm>
        //    #include <boost/multiprecision/cpp_int.hpp>
            #include<functional>
          #define int long long
            #define inf  1000000007
            #define pa pair<int,int>
    #define ll long long
            #define pal pair<ll,ll>
            #define ppa pair<int,pa>
             #define ssa pair<string,int>
            #define  mp make_pair
            #define  pb push_back
            #define EPS (1e-10)
            #define equals(a,b) (fabs((a)-(b))<EPS)
     
            using namespace std;
     
            class Point{
            	public:
            	double x,y;
            	Point(double x=0,double y=0):x(x),y(y) {}
            	Point operator + (Point p) {return Point(x+p.x,y+p.y);}
            	Point operator - (Point p) {return Point(x-p.x,y-p.y);}
            	Point operator * (double a) {return Point(x*a,y*a);}
            	Point operator / (double a) {return Point(x/a,y/a);}
            	double absv() {return sqrt(norm());}
            	double norm() {return x*x+y*y;}
            	bool operator < (const Point &p) const{
            		return x != p.x ? x<p.x: y<p.y;
            	}
            	bool operator == (const Point &p) const{
            		return fabs(x-p.x)<EPS && fabs(y-p.y)<EPS;
            	}
            };
            typedef Point Vector;
     
            struct Segment{
            Point p1,p2;
            };
     
        double hen(Vector a){
        if(fabs(a.x)<EPS && a.y>0) return acos(0);
        else if(fabs(a.x)<EPS && a.y<0) return 3*acos(0);
        else if(fabs(a.y)<EPS && a.x<0) return 2*acos(0);
        else if(fabs(a.y)<EPS && a.x>0) return 0.0;
        else if(a.y>0) return acos(a.x/a.absv());
        else return 2*acos(0)+acos(-a.x/a.absv());
     
        }
     
int gcd(int v,int b){
	if(v>b) return gcd(b,v);
	if(v==b) return b;
	if(b%v==0) return v;
	return gcd(v,b%v);
}
            double dot(Vector a,Vector b){
            	return a.x*b.x+a.y*b.y;
            }
            double cross(Vector a,Vector b){
            	return a.x*b.y-a.y*b.x;
            }
        
            //----------------kokomade tenpure------------

    signed  main(){
string s;
    	cin>>s;
    	int d=0;
    	int i=1;
    	int l=s.length();
    	while(1){
    		if(s.length()<=2) break;
    		while(1){
    			if(i==s.length()-1) break;
    			if(s[i-1]==s[i+1]){
    				i++;
    				continue;
    			}	
    			break;
    		}
    		if(i==s.length()-1) break;
    //		cout<<i<<endl;
    		string t=s.substr(0,i);
    		t += s.substr(i+1);
    		s=t;
    		d++;
    //		cout<<s<<endl;
    		i=max(i-1,1ll);
    	}
    	d=l-s.length();
    //	cout<<d<<endl;
    	if(d%2==1) cout<<"First"<<endl;
    	else cout<<"Second"<<endl;
    	
    //	cout<<ans<<endl;
    	
    //	printf("%.10f\n",ans);
    	return 0;
    }

Measured memory_bytes: 616
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn fact(n: u64) -> u64 {
    let mut ret = 1;
    for m in 1..(n + 1) {
        ret = ret * m % 1_000_000_007;
    }
    return ret
}

fn main() {
    input! {
        n: i64, m: i64
    }
    if (n - m).abs() > 1 {
        println!("{}", 0);
    } else if n == m {
        let f = fact(n as u64);
        let ans = f * f * 2 % 1_000_000_007;
        println!("{}", ans);
    } else {
        let max = if n > m { n } else { m };
        let ans = fact(max as u64) * fact((max - 1) as u64) % 1_000_000_007;
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
data class Edge(val a: Int, val b: Int)
class UnionFind(val n: Int) {
    sealed class Node {
        class Root(val count: Int) : Node()
        class NonRoot(val parent: Int) : Node()
    }

    private val nodes = Array<Node>(n) { Node.Root(1) }

    data class RootInfo(val idx: Int, val body: Node.Root)

    private fun root(x: Int): RootInfo {
        val node = nodes[x]
        return when (node) {
            is Node.Root -> RootInfo(x, node)
            is Node.NonRoot -> {
                val rootInfo = root(node.parent)
                nodes[x] = Node.NonRoot(rootInfo.idx)
                rootInfo
            }
        }
    }

    fun same(x: Int, y: Int): Boolean {
        return root(x).idx == root(y).idx
    }

    fun unite(x: Int, y: Int) {
        val rx = root(x)
        val ry = root(y)
        if (rx.idx == ry.idx) return

        // rxをryにつける
        nodes[rx.idx] = Node.NonRoot(ry.idx)
        nodes[ry.idx] = Node.Root(rx.body.count + ry.body.count)
    }

    fun sameCount(x: Int): Int {
        return root(x).body.count
    }


}

fun <A, B> Iterable<A>.scan(z: B, op: (B, A) -> B): MutableList<B> {
    var acc = z
    val accList = mutableListOf(z)
    for (x in this) {
        acc = op(acc, x)
        accList.add(acc)
    }
    return accList
}

fun Iterable<Long>.cumSum(): MutableList<Long> {
    return this.scan(0L) { x, y -> x + y }
}


fun main(args: Array<String>) {
    val (nVertex, nEdge) = readLine()!!.split(" ").map(String::toInt)
    val edges = Array(nEdge) {
        val (a, b) = readLine()!!.split(" ").map(String::toInt)
        Edge(a - 1, b - 1)
    }

    val uf = UnionFind(nVertex)
    edges.reverse()

    val diffList = edges.map {
        if (uf.same(it.a, it.b)) {
            0L
        } else {
            val diff = uf.sameCount(it.a).toLong() * uf.sameCount(it.b).toLong()
            uf.unite(it.a, it.b)
            diff
        }
    }

    val allCount = nVertex.toLong() * (nVertex - 1) / 2
    val result = diffList.cumSum().take(nEdge).map { allCount - it }.reversed()

    result.forEach { println(it) }
}

Measured memory_bytes: 79536
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <iostream>
#include <math.h>
#include <map>
#include <set>
using namespace std;
int main ()
{
	int n;
	scanf("%i",&n);
	int a[n+1],sum=0,maks=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%i",&a[i]);
		if(a[i]>maks)	maks=a[i];
	}
	/*int p=sum/n,r=0,t=0;
	for(int i=1;i<=n;i++)
	{
		r+=(a[i]-p)*(a[i]-p);
	}
	for(int i=1;i<=n;i++)
	{
		t+=(a[i]-p+1)*(a[i]-p+1);
	}
	printf("%i",min(r,t));*/
	int r=0,mn=1e9;;
	for(int i=1;i<=maks;i++)
	{
		for(int j=1;j<=n;j++)
		{
			r+=(a[j]-i)*(a[j]-i);
		}
		if(r<mn)
		{
			mn=r;
		}
		r=0;
	}
	printf("%i",mn);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e9
typedef long long ll;
typedef pair<ll,ll> P;

int n;

set<int>g[110];

int main(void){
    ll n,p,a,odd=0,even=0;
    cin>>n>>p;
    for(ll i=0;i<n;i++){
        cin>>a;
        if(a%2==0)even++;
        else odd++;
    }
    if(p==0){
        ll ans=1;
        for(ll i=0;i<even;i++)ans*=2;
        if(odd==0){
            cout<<ans<<endl;
        }
        else{
            for(ll i=0;i<odd-1;i++)ans*=2;
            cout<<ans<<endl;
        }
    }
    else{
        if(odd==0){
            cout<<0<<endl;
            return 0;
        }
        else{
            ll ans=1;
            for(ll i=0;i<even;i++)ans*=2;
            for(ll i=0;i<odd-1;i++)ans*=2;
            cout<<ans<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String args[])throws Exception
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        PrintWriter pw=new PrintWriter(System.out);
        int n=Integer.parseInt(br.readLine());
        int cnt[]=new int[1000001];
        HashSet<Integer> hs=new HashSet<>();
        String str[]=br.readLine().split(" ");
        int arr[]=new int[n];
        for(int i=0;i<n;i++)
        {
            arr[i]=Integer.parseInt(str[i]);
            cnt[arr[i]]+=1;
            hs.add(arr[i]);
        }
        if(cnt[1]==1)
        pw.println(1);
        else if(cnt[1]>1)
        pw.println(0);
        else
        {
            int ans=0;
            for(int i:hs)
            {
                if(cnt[i]==1)
                {
                    boolean got=true;
                    for(int j=2;j<=1000;j++)
                    {
                        if(i%j==0)
                        {
                            if(j!=i&&(cnt[j]>0||cnt[i/j]>0))
                            {
                                got=false;
                                break;
                            }
                        }
                    }
                    if(got)
                    ans++;
                }
            }
            pw.println(ans);
        }
        pw.flush();
        pw.close();
    }
}

Measured memory_bytes: 76128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll  = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

void solve() {
    string s; cin >> s;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        if(s[i] == '+')++ans;
        else --ans;
    }
    cout<<ans << endl;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int n;
int m;
string t;
char buf[114514];
string des[114514];
bool dp[5001][1 << 12];
 
int main() {
  while (1) {
    scanf("%d%d", &n, &m);
    if (n == 0 && m == 0) return 0;
 
    for (int i=0; i<n; i++) {
      scanf(" %s", buf);
      des[i] = buf;
    }
 
    t = "";
    for (int i=0; i<m; i++) { 
      scanf(" %s", buf);
      t += buf;
    }
 
    int lim = 1 << n;
    fill(dp[0], dp[t.size()+1], false);
    for (int i=0; i<t.size(); i++) {
      for (int g=0; g<n; g++) {
        int prev = i+1-des[g].size();
        if (prev < 0) continue;
        if (t.substr(prev, des[g].size()) != des[g]) continue;
 
        for (int st=0; st<lim; st++) {
          if (st >> g & 1) continue;
          dp[i+1][st|(1<<g)] |= dp[prev][st];
        }
        dp[i+1][1<<g] = true;
      }
    }
 
    int ans = 0;
    for (int i=0; i<=t.size(); i++) {
      if (dp[i][lim-1]) ans++;
    }
    printf("%d\n", ans);
  }
}

Measured memory_bytes: 24184
#include <stdio.h>

int main(void){
   int N, i, j, k, v;

   scanf("%d", &N);

   int A[N];

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

   for(i = 0; i < N; i++) {
      v = A[i];
      j = i - 1;
   while (j >= 0&&A[j] > v){
      A[j + 1] = A[j];
      j--;
   }
   A[j + 1] = v;


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

   }



   return 0;
}


Measured memory_bytes: 2080
import java.io.*;
public class Main{
	public static void main(String[] args)throws Exception{
		BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
		StringBuilder sb=new StringBuilder();
		String str=input.readLine();
		int n=Integer.parseInt(str);
		String str2=input.readLine();
		String[] arr=str2.split(" ");
		int[] number=new int[n];

		for(int i=0;i<n;i++){
			number[n-i-1]=Integer.parseInt(arr[i]);
		}
		for(int i=0;i<number.length;i++){
			sb.append(number[i]);
			if(!(i==n-1)){
			sb.append(" ");
			}
		}
	
		
		System.out.println(sb);
	}
}

Measured memory_bytes: 24220
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);

        int a = stdIn.nextInt();
        int b = stdIn.nextInt();

        if (a < b)
            System.out.println("a < b");
        if (a > b)
            System.out.println("a > b");
        if (a == b)
            System.out.println("a == b");
    }
}


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

int main(){
  int x,y;
  cin>>x>>y;
  int pnt=0;
  if(x==1){
    pnt+=300000;
  }
  if(x==2){
    pnt+=200000;
  } 
  if(x==3){
    pnt+=100000;
  }
  if(y==1){
    pnt+=300000;
  }
  if(y==2){
    pnt+=200000;
  } 
  if(y==3){
    pnt+=100000;
  } 
  if(x==1 && y==1){
    pnt+=400000;
  }
  cout<<pnt<<endl;
}




Measured memory_bytes: 3636
#include <iostream>
#include <stack>
#include <stdio.h>
 
#define BUF_SIZE 120000
 
using namespace std;
 
int main(){
 
    int n;
    scanf("%d",&n);
 
    int S[n];
 
    for(int i = 0; i < n; i++){
        scanf("%d",&S[i]);
    }
 
    int q;
    scanf("%d",&q);
 
    int count = 0;
    int tmp;
 
    for(int i = 0; i < q; i++){
        scanf("%d",&tmp);
        for(int k = 0; k < n; k++){
            if(tmp == S[k]){
                count++;
                break;
            }
        }
    }
 
    printf("%d\n",count);
 
}


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

int ansf(int n,int m,int large){
	double h = large/2;
	if(n>=h){n=large+1-n;}
	if(m>=h){m=large+1-m;}
	int d=min(n,m)%3;
	if(d==0){d=3;}
	cout<<d<<endl;
}

int main() {
int size;
cin>>size;
int time;
cin>>time;
for(int i = 1;i<=time;i++){
	int a,b;
	cin>>a>>b;
	ansf(a,b,size);
}
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
int prime[300000],p;
int mark[1000002];
void sieve(){
	int i,j,limit=sqrt(1000000*1.)+2;
	mark[1]=1;
	for(i=4;i<=1000000;i+=2)mark[i]=1;

	prime[p++]=2;
	for(i=3;i<=1000000;i+=2){
		if(!mark[i]){
			prime[p++]=i;
			if(i<=limit){
				for(j=i*i;j<=1000000;j+=i*2){
					mark[j]=1;
				}
			}
		}
	}
}
int main()
{
	sieve();
	int t,n,i;
	cin>>t;
	for(i=0;i<300000;i++){
		if(prime[i]==t||prime[i]>t){
			cout<<prime[i]<<endl;
			return 0;
		}
	}
	
	return 0;
}

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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
#define ITER(it,a) for(__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a,value, sizeof(a))

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PII;

const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000 + 7;
const LL LINF = INF * (LL) INF;

const int MAX = 333;

int DP[MAX][MAX][MAX];
string s;

int get(int l, int r, int k)
{
//	cout<<l<<' '<<r<<' '<<k<<endl;
	if (l > r) return 0;

	if (DP[l][r][k] != -1) return DP[l][r][k];
	
	int res = 0;
	
	if (s[l] == s[r])
	{
		int add = 1;
		if (l != r) add++;
		res = max(res, get(l+1, r-1, k) + add);
	}
	
	res = max(res, get(l+1, r, k));
	res = max(res, get(l, r-1, k));
	
	if (k)
	{
		int add = 1;
		if (l != r) add++;
		res = max(res, get(l+1, r-1, k-1) + add);
	}
	
	return DP[l][r][k] = res;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);
	
	cin>>s;
	int k;
	cin>>k;
	
	FILL(DP, -1);
	
	int res = get(0, SZ(s)-1, k);
	cout<<res<<endl;
}


Measured memory_bytes: 144512
#include <stdio.h>
#include <math.h>

int main(void){
    int i,j,n;
    double x[100],y[100],d,md;

    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%lf",&x[i]);
    for(i=0;i<n;i++) scanf("%lf",&y[i]);

    for(i=0;i<4;i++){
        md=0.0;
        for(j=0;j<n;j++){
            d=fabs(x[j]-y[j]);
            switch(i){
                case 0:
                md+=d;
                break;
                case 1:
                md+=d*d;
                break;
                case 2:
                md+=d*d*d;
                break;
                case 3:
                if(md<d) md=d;
                break;
            }
        }

        switch(i){
            case 1:
            printf("%lf\n",sqrt(md));
            break;
            case 2:
            printf("%lf\n",cbrt(md));
            break;
            default:
            printf("%lf\n",md);
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 676
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
import java.util.Stack;

//Map of Ninja House
public class Main{

	class R{
		int id, door;
		List<Integer> adj;
		public R(int id, int door) {
			this.id = id;
			this.door = door;
			adj = new ArrayList<Integer>();
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while(T--!=0){
			R room[] = new R[101];
			Stack<R> v = new Stack<R>();
			int ID = 1;
			int x = sc.nextInt();
			room[ID] = new R(ID, x);
			R now = room[ID];
			v.push(room[ID]);
			ID++;
			for(;;){
				x = sc.nextInt();
				if(x==0)break;
				while(v.peek().door==0)v.pop();
				now = v.peek();
				if(x>0){
					R next = new R(ID, x);
					now.adj.add(ID); next.adj.add(now.id);
					next.door--;
					now.door--;
					room[ID] = next;
					v.push(next);
					now = next;
					ID++;
				}
				else{
					R r = v.get(v.size()-1+x);
					r.adj.add(now.id); now.adj.add(r.id);
					now.door--;
					r.door--;
				}
			}
			for(int i=1;i<ID;i++){
				System.out.print(i+" ");
				Collections.sort(room[i].adj);
				for(int j=0;j<room[i].adj.size();j++)System.out.print(room[i].adj.get(j)+(j==room[i].adj.size()-1?"\n":" "));
			}
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <vector>
#include <utility>
#define llint long long
#define inf 1e18

using namespace std;
typedef pair<llint, llint> P;

llint n, k;
vector<P> ans;

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

  cin >> n >> k;
  if(k > (n-1)*(n-2)/2){
    cout << -1 << endl;
    return 0;
  }

  for(int i = 1; i <= n-1; i++) ans.push_back(P(i, n));
  for(int i = 1; i <= n-1; i++){
    for(int j = 1; j <= n-1; j++){
      if(i >= j || k >= (n-1)*(n-2)/2) continue;
      ans.push_back(P(i, j));
      k++;
    }
  }
  cout << ans.size() << endl;
  for(int i = 0; i < ans.size(); i++){
    cout << ans[i].first << " " << ans[i].second << endl;
  }

  return 0;
}


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

#define ll long long
using namespace std;


void solve()
{
	int A,B,C,K;
	cin>>A>>B>>C>>K;
	int ans = 0;
	while(A>=B)
	{
		B*=2;
		++ans;
	}
	while(B>=C)
	{
		C*=2;
		++ans;
	}
	
	if(ans > K)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
}


int main()
{
	//xyz();
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//int T;
	//cin>>T;
	//while(T--)
		solve();
		
	return 0;
}


Measured memory_bytes: 3644
/* ex3_4
   key_tree */

#include <stdio.h>

// Nを1-9で割った商が1-9かつ余りが0になればよい
int main(void) {
  int N;
  scanf("%d", &N);
  int i = 1;
  // 1-9まで調べる
  while(i < 10){
    int quotient = N / i;
    int remainder = N % i;
    //商が1-9かつ余り0
    if(quotient >= 1 && quotient <= 9 && remainder == 0){
      printf("Yes\n");
      break;/*当てはまったらwhile脱出*/
    }
    i += 1;
  }
  if(i == 10){
    printf("No\n");
  }
  return 0;
}


Measured memory_bytes: 128
n, k = map(int, input().split())
A = list(map(lambda x: int(x)-1, input().split()))

history = [-1]*n
ans = []
cur = 0
for i in range(n):
    if history[cur] != -1:
        init_cnt = history[cur]
        loop_cnt = i - history[cur]
        break
    history[cur] = i
    ans.append(cur+1)
    cur = A[cur]

loop = k if k <= init_cnt else init_cnt+((k-init_cnt) % loop_cnt)
print(ans[loop])

Measured memory_bytes: 32284
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<functional>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(n);i++)

int vx[]={1,0,-1,0};
int vy[]={0,1,0,-1};
int ice[92][92];

int dfs(int y,int x){
	if(ice[y][x]==0)return 0;
	int res=0;
	ice[y][x]=0;
	for(int i=0;i<4;i++){
		res = max(res,1+dfs(y+vy[i],x+vx[i]));
	}
	ice[y][x]=1;
	return res;
}
int main(){
	int w,h;
	while(cin>>w>>h,w||h){
		memset(ice,0,sizeof(ice));
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++)cin>>ice[i][j];
		}
		int ans=0;
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				ans = max(ans,dfs(i,j));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}

Measured memory_bytes: 1200
//Problem A
#include<bits/stdc++.h>
using namespace std;
int rd(){
    int a=0;char ch=getchar();
    while(!isdigit(ch))ch=getchar();
    while(isdigit(ch))a=(a<<1)+(a<<3)+(ch^48),ch=getchar();
    return a;
}

int a,b,c;

int main(){
    scanf("%d%d%d",&a,&b,&c);
    int mx=max(a,max(b,c));
    printf("%d",mx*10+a+b+c-mx);
    return 0;
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.BitSet;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {

		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			m = scanner.nextInt();
			n = scanner.nextInt();
			if ((m | n) == 0)
				break;
			M = new HashMap<Pair, Integer>();
			h = 1;
			a = new int[n][m];
			pairs = new Pair[24];
			for (int i = 0; i < n; i++)
				for (int j = 0; j < m; j++) {
					int t = scanner.nextInt();
					if (t == 0) {
						a[i][j] = -1;
					} else if (t == 1) {
						pairs[h] = new Pair(i, j);
						a[i][j] = h++;
					} else {
						pairs[0] = new Pair(i, j);
						a[i][j] = 0;
					}
				}
			BitSet bit = new BitSet();
			bit.set(0);
			System.out.println(slove(0, bit));
		}
	}

	private int slove(int cur, BitSet bit) {
		Pair p = new Pair(cur, bit);
		if (M.containsKey(p))
			return M.get(p);
		int res = 0;
		for (int[] mo : move) {
			int y = pairs[cur].y;
			int x = pairs[cur].x;
			while (true) {
				y += mo[0];
				x += mo[1];
				if (!isOK(y, x))
					break;
				if (a[y][x] == 0)
					if (bit.cardinality() == h) {
						return res + 1;
					}
				
				if (a[y][x] >= 1) {
					if (bit.get(a[y][x]))
						continue;
					BitSet newbit = (BitSet) bit.clone();
					newbit.set(a[y][x]);
					res += slove(a[y][x],newbit);
					break;
				}
			}
		}
		M.put(p, res);
		return res;
	}

	private boolean isOK(int y, int x) {
		if (0 <= y && y < n && 0 <= x && x < m)
			return true;
		return false;
	}

	class Pair {
		int y, x;
		BitSet bit;

		public Pair(int y, BitSet bit) {
			super();
			this.y = y;
			this.bit = bit;
		}

		@Override
		public int hashCode() {
			final int prime = 31;
			int result = 1;
			result = prime * result + getOuterType().hashCode();
			result = prime * result + ((bit == null) ? 0 : bit.hashCode());
			result = prime * result + y;
			return result;
		}

		@Override
		public boolean equals(Object obj) {
			if (this == obj)
				return true;
			if (obj == null)
				return false;
			if (getClass() != obj.getClass())
				return false;
			Pair other = (Pair) obj;
			if (!getOuterType().equals(other.getOuterType()))
				return false;
			if (bit == null) {
				if (other.bit != null)
					return false;
			} else if (!bit.equals(other.bit))
				return false;
			if (y != other.y)
				return false;
			return true;
		}

		public Pair(int y, int x) {
			super();
			this.y = y;
			this.x = x;
		}

		private Main getOuterType() {
			return Main.this;
		}

	}

	int m, n, h;
	Pair[] pairs;
	int[][] a;
	int[][] move = { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };
	Map<Pair, Integer> M;
}

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

#define  SZ(items) (int)items.size()
#define  CLR(a)  memset(a,0,sizeof(a))
#define  SET(a)  memset(a,-1,sizeof(a))

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

template <class T> inline T gcd(T a, T b) { while (b) { a = a%b; swap(a, b); } return a; }




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

	int a, b, c;
	cin >> a >> b >> c;

	int res = min(b / a, c);

	cout << res << endl;


	return 0;
}


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

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pint;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 998244353;

int main() {
    int h, w; cin >> h >> w;
    vector<string> s(h); rep(i, h) cin >> s[i];
    
    vector<vector<int>> dp(h, vector<int>(w, INF));
    if (s[0][0] == '#') dp[0][0] = 1;
    else dp[0][0] = 0;
    rep(i, h) rep(j, w) {
        if (j+1 < w) {
            if (s[i][j] == '.' && s[i][j+1] == '#') {
                dp[i][j+1] = min(dp[i][j+1], dp[i][j] + 1);
            } else {
                dp[i][j+1] = min(dp[i][j+1], dp[i][j]);
            }
        }

        if (i+1 < h) {
            if (s[i][j] == '.' && s[i+1][j] == '#') {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j] + 1);
            } else {
                dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
            }
        }
    }

    cout << dp[h-1][w-1] << endl;
    return 0;
}


    


Measured memory_bytes: 256