akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
using namespace std;
//ll arr[1000002];
/*ll power(ll x,ll y)
{
    ll res=1;
    while(y>0)
    {
        if(y%2==1)
            res=(res*x)%mod;
        x=(x*x)%mod;
        y=y/2;
    }
    return res;
}*/
bool comp(pair<string,ll>v1,pair<string,ll>v2)
{
    if((v1.first)!=(v2.first))
        return (v1.first)<(v2.first);
    else
        return (v1.second)>(v2.second);
}
int main()
{
  ll n,p,i;
  vector<pair<string,ll> >v;
  map<pair<string,ll>,ll>mp;
  string s;
  cin>>n;
  for(i=1;i<=n;i++)
  {
      cin>>s>>p;
      v.pb({s,p});
      mp[{s,p}]=i;
  }
  sort(v.begin(),v.end(),comp);
  for(i=0;i<v.size();i++)
  {
      cout<<mp[v[i]]<<endl;
  }
}


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

int n, a, b, c, x;
template <class T>
void readVector(int n, vector<T> &v){
	for(int i=0; i<n; ++i){
		T t;
		cin >> t;
		v.push_back(t);
	}
}

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	while(1){
		cin >> n >> a >> b >> c >> x;
		if(n == 0 && a == 0 && b == 0 && c == 0 && x == 0)
			return 0;
		vector<int> y;
		readVector(n, y);
		int t = 0;
		for(int i=0; i<=10000; ++i){
			if(x == y[t]) ++t;
			x = (a * x + b) % c;
			if(t == n){
				cout << i << "\n";
				break;
			}
		}
		if(t < n) cout << "-1\n";
	}
}


Measured memory_bytes: 3132
class BinaryTree {
  constructor(n) {
    this.nodes = [];
    for (let i = 0; i < n; i++) this.nodes[i] = {id: i + 1, parentId: -1, leftId: -1, rightId: -1}
  }

  get root() { return this.nodes.find(n => n.parentId === -1); }

  add(id, leftId, rightId) {
    let n = this.find(id);
    [n.leftId, n.rightId] = [leftId, rightId];
    if (leftId !== -1) this.find(leftId).parentId = id;
    if (rightId !== -1) this.find(rightId).parentId = id;
  }

  find(id) { return this.nodes[id - 1] || {}; }

  getByPostorder() {
    let res = [];
    const postorder = (id) => {
      if (id === -1) return;
      let n = this.find(id);
      postorder(n.leftId);
      postorder(n.rightId);
      res.push(id);
    };
    postorder(this.root.id);
    return res;
  }
}

(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const preOrder = lines.shift().split(' ').map(Number);
  const inOrder = lines.shift().split(' ').map(Number);

  let tree = makeTree(preOrder, inOrder);
  console.log(tree.getByPostorder().join(' '));
})();

function makeTree(preOrder, inOrder) {
  let tree = new BinaryTree(preOrder.length);
  const func = (p, i) => {
    let midId = p[0];
    let midIdx = i.indexOf(midId);
    if (midIdx === -1) return;
    if (midIdx > 0) {
      tree.find(midId).leftId = p[1];
      tree.find(p[1]).parentId = midId;
      func(p.slice(1, midIdx + 1), i.slice(0, midIdx))
    }
    if (midIdx < i.length - 1) {
      tree.find(midId).rightId = p[midIdx + 1];
      tree.find(p[midIdx + 1]).parentId = midId;
      func(p.slice(midIdx + 1), i.slice(midIdx + 1))
    }
  }

  func(preOrder, inOrder);
  return tree;
}



Measured memory_bytes: 15412
s = input()
if 1 <= int(s[:2]) <= 12:
    if 1 <= int(s[2:]) <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if 1 <= int(s[2:]) <= 12:
        print('YYMM')
    else:
        print("NA")


Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define dup(x,y) (((x)+(y)-1) / (y)) //整数型のまま切り上げ演算する
#define PI 3.14159265359
typedef long long LL;
template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> inline T gcd(T x, T y) { if (y == 0) { return x; } else if (x == 0) { return y; }return gcd(y, x % y); }
template<class T> inline T lcm(T x, T y) { return (x * y) / gcd(x, y); }
template<class T> inline vector<T> convert_to_binary_number(T x) { vector<T> binary_num; while (x != 1) { binary_num.push_back(x % 2); x /= 2; } binary_num.push_back(1); return binary_num; }
template<class T> inline void print_vector(vector<T> vec) { for (int i = 0; i < vec.size(); i++) { cout << vec[i] << " "; } cout << endl;}
vector<LL> make_divisors(LL n){vector<LL> divisors;for(int i = 1; i <= sqrt(n); i++) {if(n%i == 0){divisors.push_back(i);if(i != n/i){divisors.push_back(n / i);}}}return divisors;}
const LL MOD = 1e9 + 7;
const LL INF = 1LL << 60;


int main(void){
    string S;
    LL K;
    cin >> S >> K;

    vector<LL> runlen;
    LL len = 1;
    for(int i = 1; i < S.size(); i++) {
        if(S[i] != S[i-1]){
            runlen.push_back(len);
            len = 1;
        }else{
            len++;
        }
    }
    runlen.push_back(len);

    LL ans = 0;
    // S一つの時
    for (int i = 0; i < runlen.size(); i++){
        ans += runlen[i] / 2;
    }

    if(runlen.size() == 1){
        cout << S.size() * K / 2 << endl;
    } else if(S[0] == S[S.size() - 1] and runlen.size() != 1) {
        LL connection_part = runlen[0] + runlen[runlen.size() - 1];
        runlen.pop_back();
        runlen.erase(runlen.begin());
        runlen.push_back(connection_part);

        LL tmp = 0;
        for(int i = 0; i < runlen.size(); i++) {
            tmp += runlen[i] / 2;
        }

        cout << ans + (K-1) * tmp << endl;
    } else {
        cout << ans * K << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;

int main(){
  string s;
  cin >> s;
  
  if (s[0]==s[1] && s[0]==s[2]) dunk("No");
  else dunk("Yes");
  
}

Measured memory_bytes: 256
while 1:
    try:
        n=float(input())
        if n>91:
            print("heavy")
        elif n>81:
            print("light heavy")
        elif n>75:
            print("middle")
        elif n>69:
            print("light middle")
        elif n>64:
            print("welter")
        elif n>60:
            print("light welter")
        elif n>57:
            print("light")
        elif n>54:
            print("feather")
        elif n>51:
            print("bantam")
        elif n>48:
            print("fly")
        else:
            print("light fly")
    except:break


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

int main(){
    string s; cin>>s;
    int n=s.size();
    ll ans=0;
    for(int bit=0;bit<pow(2,n-1);bit++){
        ll tmp=s[0]-'0';
        for(int i=0;;i++){
            if(i==n-1){
                ans+=tmp;
                break;
            }
            if(bit&(1<<(n-i-2))){
                ans+=tmp;
                tmp=s[i+1]-'0';
            }else{
                (tmp*=10)+=s[i+1]-'0';
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <cstdio>

//FILE *fin = fopen("a.in", "r"), *fout = fopen("a.out", "w");
#define fin stdin
#define fout stdout

#define MAXN 200009

int n;
char s[MAXN + 10];

int main() {
    fgets(s + 1, MAXN + 5, fin);
    while (s[n + 1] != '\n')
        n++;
    s[n + 1] = 'B';
    s[n + 2] = 'B';

    int poz = 1;
    long long ans = 0;
    while (poz <= n) {
        int unde = poz;
        while (s[poz] == 'A' || (s[poz] == 'B' && s[poz + 1] == 'C'))
            poz += 1 + (s[poz] == 'B');
        int cnt = 0;
        for (int i = poz - 1; i >= unde; i--) {
            if (s[i] == 'B')
                cnt++;
            else if (s[i] == 'A')
                ans += cnt;
        }
        poz++;
    }

    fprintf(fout, "%lld\n", ans);

    fclose(fin);
    fclose(fout);
    return 0;
}


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


void solve(long long N, long long M, long long K, std::vector<long long> A, std::vector<long long> B){

  vector<long long> Atab(N+1, LLONG_MAX);
  vector<long long> Btab(M+1, LLONG_MAX);

  Atab[0] = 0;
  for(long long i = 1; i <= N; i++){
    Atab[i] = Atab[i-1] + A[i-1];
    if(Atab[i] > K) break;
  }

  Btab[0] = 0;
  for(long long i = 1; i <= M; i++){
    Btab[i] = Btab[i-1] + B[i-1];
    if(Btab[i] > K) break;
  }

  long long mymax = 0;
  for(long long i = 0; i <= N; i++){
    if(Atab[i] > K) break;

    auto it = upper_bound(Btab.begin(), Btab.end(), K-Atab[i]);
    mymax = max(mymax, i + distance(Btab.begin(), it-1));
  }

  cout << mymax << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
  scanf("%lld",&N);
  long long M;
  scanf("%lld",&M);
  long long K;
  scanf("%lld",&K);
  std::vector<long long> A(N);
  for(int i = 0 ; i < N ; i++){
    scanf("%lld",&A[i]);
  }
  std::vector<long long> B(M);
  for(int i = 0 ; i < M ; i++){
    scanf("%lld",&B[i]);
  }
    solve(N, M, K, std::move(A), std::move(B));
    return 0;
}


Measured memory_bytes: 9576
n,m=map(int,input().split())
edge=[n*[0]for _ in range(n)]
for i in range(m):
	a,b=map(int,input().split())
	a-=1
	b-=1
	edge[a][b]=edge[b][a]=1
from itertools import permutations
ans=0
for i in permutations([j for j in range(1,n)],n-1):
	f=True
	t=[0]+list(i)
	for j in range(1,n):
		if edge[t[j-1]][t[j]]==0:f=False
	if f:ans+=1
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main(){
    int n,m;
    cin >> n >> m;
    int in,out;
    int box[n];
    int red[n];
    red[0] = 1;
    for(int i = 0;i < n;i++){
        box[i] = 1;
        red[i] = 0;
    }
    red[0] = 1;
    for(int i = 0;i < m;i++){
        cin >> out >> in;

        if(red[out - 1] == 1){
            red[in - 1] = 1;
        }
        if(box[out - 1] == 1){
            red[out - 1] = 0;
        }
        box[out - 1]--;
        box[in - 1]++;
    }
    int num = 0;
    for(int j = 0;j < n;j++){
        if(box[j] > 0 && red[j] == 1){
            num++;
        }
    }
    cout << num << endl;


}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll n,m,arr[1000],cnt=0;
     mem(arr,0);
     cin>>n>>m;
     for(int i=0;i<n;i++)
     {
         ll kk,v;
         cin>>kk;
         for(int i=0;i<kk;i++)
         {
             cin>>v;
             arr[v]++;
         }
     }
     for(int i=1;i<=m;i++)
     {
         if(arr[i]==n)
            cnt++;
     }
     cout<<cnt<<endl;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    int a,b;
    char op;
    while (1){
        cin >> a >> op >> b;
        if (op == '?') break;
        if (op == '+') cout << a+b << endl;
        else if (op == '-') cout << a-b << endl;
        else if (op == '*') cout << a*b << endl;
        else if (op == '/') cout << a/b << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
#include <iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  
  int arr[n];
  
  long long int cnt=0;
  
  for(int i=0;i<n;i++)
  {
    cin>>arr[i];
    
    if(arr[i]%2 && (i+1)%2)
      cnt++;
  }
  
  cout<<cnt<<endl;
}

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

char str[22];
int c,n;
#define oops {printf("WA");return 0;}
int main(){
    scanf("%s",str),n=strlen(str);
    if(str[0]!='A')oops
    int f=1;
    for(int i=2;i<n-1;i++)if(str[i]=='C')f=0;
    if(f)oops
    for(int i=0;i<n;i++)if('a'<=str[i]&&str[i]<='z')++c;
    if(c+2!=n)oops
    printf("AC");
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31))

ll n,t;
ll a[2010],m[2010];
ll ans=INF;

int main(){
	scanf("%lld%lld",&n,&t);
	rep(i,0,n)scanf("%lld",a+i);
	rep(i,0,n)m[i]=INF;
	
	rep(k,0,n){
		rep(i,0,n)m[i]=min(m[i],a[(i-k+n)%n]);
		ll temp=0;
		rep(i,0,n)temp+=m[i];
		ans=min(ans,temp+k*t);
	}
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
  int A,B,K;
  cin >>A>>B>>K;
  int count=0;
  int ans=0;
  for(int i=B;i>0;i--){
    if(A%i==0 && B%i==0){
      count++;
    }
    if(count==K){
      ans=i;
      break;
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    int R[n];
    for(int i = 0; i < n; i++){
        cin >> R[i];
    }
    int maxv = R[1] - R[0];
    int minv = R[0];
    
    for(int j = 1; j < n; j++){
        if(maxv < R[j] - minv) maxv = R[j] - minv;
        if(minv > R[j]) minv = R[j];
    }
    
    cout << maxv << endl;
}


Measured memory_bytes: 3884
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

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

  ll n;
  cin >> n;
  vl a(3*n);
  rep(i, 3*n) {
    cin >> a[i];
  }

  sort(a.rbegin(), a.rend());
  ll ans = 0;
  rep(i, n) {
    ans += a[i*2+1];
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include<stdio.h>
int main(){
int a,b;
scanf("%d", &a);
scanf("%d", &b);
 
if(a<b){
printf("a < b\n",a,b);
}else if(a>b){
printf("a > b\n",a,b);
}else{
printf("a == b\n",a,b);
}

return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int n){
    int l = 0, r = 0;
    for (ll i = 1; i*(i+1)/2 <= n; ++i) {
        ll x = n-i*(i+1)/2;
        if(x%i == 0){
            l = x/i, r = i;
        }
    }
    cout << l+1 << " " << r << "\n";
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int h,w;
string s[10];

int main(){
	cin.sync_with_stdio(false);
	cin>>h>>w;
	rep(i,h)cin>>s[i];
	int l=0,u=0;
	bool ok=true;
	rep(i,h)rep(j,w){
		if(s[i][j]=='#'){
			if(i<u||j<l)ok=false;
			maxch(u,i);
			maxch(l,j);
		}
	}
	if(ok)cout<<"Possible"<<endl;
	else cout<<"Impossible"<<endl;
	return 0;
}


Measured memory_bytes: 256
K, N = map(int,input().split())
A = list(map(int,input().split()))

L = []
for i in range(N):
  if i == 0:
    L.append(A[0]+(K-A[N-1]))
  else:
    L.append(A[i]-A[i-1])

print(K-max(L))

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

using namespace std;

typedef pair<int, int> P;
typedef long long int LL;
#define MOD 1000000007

int main() {
    int n, m;
    cin >> n >> m;
    vector<LL> x(n), y(m);
    for (int i = 0; i < n; i++) {
        cin >> x[i];
    }
    for (int i = 0; i < m; i++) {
        cin >> y[i];
    }

    LL lx = 0, ly = 0;
    for (int i = 0; i < n - 1; i++) {
        lx += (x[i + 1] - x[i]) * (i + 1) * (n - 1 - i);
        lx %= MOD;
    }
    for (int i = 0; i < m - 1; i++) {
        ly += (y[i + 1] - y[i]) * (i + 1) * (m - 1 - i);
        ly %= MOD;
    }

    cout << lx * ly % MOD << endl;

    return 0;
}


Measured memory_bytes: 1920
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<math.h>
#include<list>
#include<complex>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define vtype(type) vector<type>
#define vvtype(type) vector<vector<type>>
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;


ll const MOD = 1e9 + 7;
ll mod_p(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return (x + y + MOD) % MOD;
}

ll mod_m(ll x, ll y) {
	x %= MOD;
	y %= MOD;
	return x * y%MOD;
}

ll mod_pow(ll x, ll t) {
	x %= MOD;
	if (t == 0) {
		return 1;
	}
	else {
		ll v = mod_pow(x, t / 2);
		if (t % 2 == 0) {
			return v * v % MOD;
		}
		else {
			return v * v%MOD * x %MOD;
		}
	}
}

ll mod_inv(ll x) {
	return mod_pow(x, MOD - 2);
}

struct edge
{
	long long to; ll name;
	bool operator<(const edge& rhs) const {
		return name > rhs.name;
	}
};

ll const MAX = 1e5 + 5;
vvtype(edge) G(MAX);

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	if (b - a <= 2) {
		cout << 1 + n << endl;
		return 0;
	}
	else {
		if (a - 1 > n) {
			cout << 1 + n << endl;
			return 0;
		}
		else {
			n -= a - 1;
			ll t = a + (b - a)*(n / 2);
			if (n % 2) {
				t++;
			}
			cout << t << endl;
		}
	}

}

Measured memory_bytes: 2560
N, M = list(map(int, input().split()))
K, A = [0] * N, [0] * N
for i in range(N):
    K[i], *A[i] = list(map(int, input().split()))
k = set(i for i in range(1, M + 1))
ki = k.intersection(*A)
print(len(ki))

Measured memory_bytes: 3060
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#define REP(i, n) for(int i=0;i<n;++i)
#define INF 100000000
#define ll long long

using namespace std;

typedef pair<int, int> P;

ll int n, k;

ll int f(int m){
  ll int tmp=0;
  tmp += (n / m) * (m - k);
  int a;
  a = n % m;
  if(a >= k){
    tmp += a - k + 1;
  }

  return tmp;
}

int main(){
  cin >> n >> k;
  ll int tmp=0;
  if(k == 0){
    tmp += n * n;
  }else{
  	for(int i=k+1; i<n+1; ++i){
      tmp += f(i);
    }
  }

  printf("%lld\n", tmp);
  
  return 0;
}

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

int main(void){
  int N, M;
  cin >> N >> M;
  int max = N + 100;
  int min = 0;
  for(int cnt = 0; cnt < M; ++cnt){
    int l, r;
    cin >> l >> r;
    if(min < l){
      min = l;
    }
    if(r < max){
      max = r;
    }
  }
  int ans = max - min + 1;
  if(ans > N) ans = N;
  if(ans < 0) ans = 0;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(x) x.begin(),x.end()
#define DBG(x) cout<<#x<<":"<<x<<endl
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> PP;
const ll p = 1e9+7;
const ll INF = 1LL << 60;
#define MAX_N 1<<18
#define int long long
int n,dat[2*(MAX_N)-1];

//INT＿MAXで初期化
void init(int n_){
  n=1;
  while(n<n_)n*=2;
  for(int i=0;i<2*n-1;i++)dat[i]=INT_MAX;
}

//k番目の要素をaに変更
void update(int k,int a){
  k+=n-1;
  dat[k]=a;
  while(k>0){
    k=(k-1)/2;
    dat[k]=min(dat[k*2+1],dat[k*2+2]);
  }
}

//[a,b)の最小値を求める
int query(int a,int b,int k=0,int l=0,int r=n){
  if(r<=a||b<=l)return INT_MAX;
  if(a<=l&&r<=b)return dat[k];
  else{
    int vl=query(a,b,k*2+1,l,(l+r)/2);
    int vr=query(a,b,k*2+2,(l+r)/2,r);
    return min(vl,vr);
  }
}

signed main(){
    ll cc,h[222222],c[222222];
    cin>>cc;
    init(cc+1);
    for(int i=0;i<cc;i++)cin>>h[i];
    for(int i=0;i<cc;i++){
	 cin>>c[i];
	 ll ma=query(0,h[i]);
	 if(ma==INT_MAX)ma=0;
	 update(h[i],(ma-c[i]));
    }
    cout<<-query(0,cc+1)<<endl;
    return 0;
  }


Measured memory_bytes: 7680
#include <iostream>
#include <string>

using namespace std;

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

int main(void)
{
	string s;
	cin >> s;
	int n = (int)s.length();
	if ((s[0] == s[n - 1]) != (n % 2)) cout << "First" << endl;
	else cout << "Second" << endl;
	return 0;
}

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

#ifdef LOCAL
#define debug(var) cerr << (#var) << " = " << (var) << endl;
#else
#define debug(var)
#endif

void init() {
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}

const int N = 2e5+23;
int a[N];
int n;

long long check(long long p) {
  for (int i = 0; i < n; ++i) {
    p = p/a[i]*a[i];
    if (p < a[i]);
  }
  return p;
}

void solve() {
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", a+i);
  }
  long long lo = 1, hi = 1e16;
  while (lo+1 < hi) {
    long long mid = lo+(hi-lo)/2;
    if (check(mid) >= 2) hi = mid;
    else lo = mid;
  }
  if (check(hi) != 2) {
    printf("-1");
    return;
  }
  printf("%lld ", hi);
  lo = hi-1; hi = 1e16;
  while (lo+1 < hi) {
    long long mid = lo+(hi-lo)/2;
    if (check(mid) > 2) hi = mid;
    else lo = mid;
  }
  printf("%lld", lo);
}

int main() {
  int t = 1; //scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}


Measured memory_bytes: 4212
// AtCoder ABC140: B - 
// 2019.9.7 bal4u

#include <stdio.h>

int N;
int A[25], B[25], C[25];

int main()
{
	int i, ans;
	
	scanf("%d", &N);
	for (i = 1; i <= N; i++) scanf("%d", A+i);
	for (i = 1; i <= N; i++) scanf("%d", B+i);
	for (i = 1; i < N; i++) scanf("%d", C+i);
	ans = 0; for (i = 1; i <= N; i++) {
		ans += B[A[i]];
		if (i < N && A[i]+1 == A[i+1]) ans += C[A[i]];
	}
	printf("%d\n", ans);
	return 0;
}


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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    cin >> s >> t;
    Yn(t.substr(0, t.size()-1) == s)

}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
long long n,a[100000009],k,i;
int main()
{
  cin>>n;
  for(k=1;k<=n;k++)
  {
    cin>>a[k];
  }
  sort(a+1,a+1+n);
  for(k=1;k<=n;k++)
  {
    if(a[k]==a[k+1])
    {
      cout<<"NO";
      return 0;
    }
  }
  cout<<"YES";
}

Measured memory_bytes: 1792
n=int(input())
l=[]
for i in range(n):
  a,b=input().split()
  l.append([a,int(b)])
x=input()
s=0
cnt=0
for i in range(n):
  s+=l[i][1]
for i in range(n):
  if l[i][0]==x:
    print(s-cnt-l[i][1])
    exit()
  cnt+=l[i][1]

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
#include <math.h>
#define ll unsigned long long int
using namespace std;

int main(){
	string s;
	cin >> s;
	for (int i = s.length() - 1; i >= 0; i--)	cout << s.at(i);

	cout << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
#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 fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)
template<class T> bool chmax(T &a,  T b) {if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a,  T b) {if(a>b){a=b; return 1;} return 0;}
bool Add(int &a,int b){a = (a + b) % MOD;}
void myprint(int* A,int A_num){
   REP(i,A_num) cout << A[i] << " ";
   cout << endl;
}

const int n_max = 200006;

signed main(){
    string s;
    cin >> s;
    int n = s.size();
    int nagasa[n + 1];
    nagasa[n] = 0;
    bool vis[26];
    REP(i,26) vis[i] = false;
    int cnt = 0;
    REPR(i,n-1){
        if(vis[s[i] - 'a'] == false){
            cnt ++;
            vis[s[i] - 'a'] = true;
            if(cnt == 26){
                nagasa[i] = nagasa[i+1] + 1;
                cnt = 0;
                REP(i,26) vis[i] = false;
            }
            else{
                nagasa[i] = nagasa[i+1];
            }
        }
        else{
            nagasa[i] = nagasa[i+1];
        }
    }

    int tugi[n_max][26];
    int ids[26];
    REP(i,26) ids[i] = 0;
    REP(i,n){
        FOR(j,ids[s[i] - 'a'],i+1){
            tugi[j][s[i] - 'a'] = i;
        }
        ids[s[i] - 'a'] = i + 1;
    }
    REP(i,26){
        FOR(j,ids[i],n) tugi[j][i] = n;
    }








    int idx = 0;
    while(1){
        REP(i,26){
            if(tugi[idx][i] == n){
                cout << moji[i] <<endl;
                return 0;
            }
            if( nagasa[tugi[idx][i] + 1] == nagasa[idx] - 1){
                cout << moji[i];
                idx = tugi[idx][i] +  1;
                break;
            }
        }
    }
}

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

#define int long long
#define rep(i,l,r) for(int i=(int)(l);i<(int)(r);i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)x.size())
template<class T>bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,T b){if(a>b){a=b;return 1;}return 0;}

typedef vector<int> vi;
typedef vector<vi> vvi;

/*{
  }*/

const int inf = 1LL<<60;

struct edge{
  int to, rev, cap;
  edge(int t, int r, int c) : to(t), rev(r), cap(c){}
};

vector<edge> es[10010];
bool vis[10010];

void add_edge(int from, int to, int cap){
  es[from].emplace_back(to, sz(es[to]), cap);
  es[to].emplace_back(from, sz(es[from])-1, cap);
}

int dfs(int v, int t, int f){
  if(v == t) return f;
  vis[v] = true;
  for(auto &e : es[v]){
    if(vis[e.to] or e.cap <= 0) continue;
    int d = dfs(e.to, t, min(f, e.cap));
    if(d > 0){
      e.cap -= d;
      es[e.to][e.rev].cap += d;
      return d;
    }
  }
  return 0;
}

int max_flow(int s, int t){
  int flow = 0;
  while(1){
    memset(vis, false, sizeof(vis));
    int f = dfs(s, t, inf);
    if(f == 0) return flow;
    flow += f;
  }
}

signed main(){
  int H, W;
  cin >> H >> W;

  vector<string> s(H);
  rep(i, 0, H) cin >> s[i];

  int S = 0, T = 1;
  auto node_y = [&](int y){ return 2+y; };
  auto node_x = [&](int x){ return 2+H+x; };

  rep(i, 0, H) rep(j, 0, W){
    if(s[i][j] == 'S'){
      add_edge(S, node_y(i), inf);
      add_edge(S, node_x(j), inf);
    }else if(s[i][j] == 'T'){
      add_edge(T, node_y(i), inf);
      add_edge(T, node_x(j), inf);
    }else if(s[i][j] == 'o'){
      add_edge(node_x(j), node_y(i), 1);
    }
  }

  int ans = max_flow(S, T);
  if(ans >= inf) cout << -1 << endl;
  else cout << ans << endl;

  return 0;
}



Measured memory_bytes: 1152
#include<stdio.h>
int main(void){
  int max,min,a,b,c,d,e,f,i,j;
int n[9999];
j=0;
scanf(" %d", &i);
while(j<i){
scanf(" %d %d %d",&a,&b,&c);

if(a>b){
  if(a>c){
    max=a;
  min=b*b+c*c;}
  else max=c;}
 else if(b>c)
   max=b;
     else max=c;
//printf("%d\n%d %d %d %d\n",max,a*a,b*b,c*c,max*max);
 if(a*a+b*b+c*c==2*max*max)
   n[j]=1;
 else n[j]=0;
 j++;}
for(j=0;j<i;j++){
  if(n[j])
    printf("YES\n");
  else 
    printf("NO\n");
 }
return 0;
}

Measured memory_bytes: 0
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>
#include <iterator>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = 1ll << 60;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	ll n;
	cin >> n;

	println((n + 1)/ 2);
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(int argc,char** argv){
  string s;
  int ret = 0;
  cin >> s;
  for(int i = 0 ; i < s.length() ; i++){
    char tmp = s[i];
    if(tmp == '+'){ ret++; }
    if(tmp == '-'){ ret--; }
  }
  cout << ret << endl;

  return 0;
}


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



int main() {
   int n, k;
   cin >> n >> k;
   vector<int> d(k);
   vector<vector<int>> a(k, vector<int>(n));
   for (int i=0; i<k; i++) {
      cin >> d[i];
      for (int j=0; j<d[i]; j++) {
         cin >> a[i][j];
      }
   }
   int ans = 0;
   int ind = 0;
   for (int i=1; i<=n; i++) {
      ind = 0;
      for (int j=0; j<k; j++) {
         for (int l=0; l<n; l++) {
            if (i == a[j][l]) ind++;
         }
      }
      if (ind == 0) ans++;
   }
   cout << ans << endl;
   return 0;
}

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

#define int ll
#define sync ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
#define ends ' '
#define die(x) return cout << x << endl, 0
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
#define debug(x) cerr << #x << ": " << x << endl
#define debugP(p) cerr << #p << ": {" << p.first << ", " << p.second << '}' << endl
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const ll INF = 1e9, MOD = 998244353;
 
/////////////////////////////////////////////////////////////////////
 
const int N = 1e6 + 5;

int P[N];
bool MARK[N];

void DFS(int v) {
	MARK[v] = true;
	if (!MARK[P[v]]) DFS(P[v]);
}

int32_t main() {
 
	sync;

	int n; cin >> n;
	vector<pii> A, B;
	for (int i = 1; i <= n; i++) {
		int a; cin >> a;
		A.push_back(make_pair(a, i));
	}
	for (int i = 1; i <= n; i++) {
		int b; cin >> b;
		B.push_back(make_pair(b, i));
	}
	sort(all(A));
	sort(all(B));
	for (int i = 0; i < n; i++) if (A[i].first > B[i].first) die("No");
	for (int i = 0; i < n - 1; i++) if (A[i + 1].first <= B[i].first) die("Yes");
	for (int i = 0; i < n; i++) P[A[i].second] = B[i].second;
	DFS(1);
	for (int i = 1; i <= n; i++) if (!MARK[i]) die("Yes");
	cout << "No" << endl;


	return 0;
}


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

using namespace std;
#define int long long
#define INF ((10e9)+7)
#define pb push_back
int H,W;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N;
    cin>>N;
    vector<double>P(N+1);
    for(int i=1;i<=N;i++)
    {
        cin>>P[i];
    }
    vector<vector<double> >dp(N+1,vector<double> (N+1,0));
    //dp(i,j) means  j heads after i throws
    for(int i=0;i<=N;i++)
    {
        dp[0][i]=0;
    }
    dp[0][0]=1;
    
    for(int i=1;i<=N;i++)
    {
        for(int j=0;j<=i;j++)
        {
            if(j-1>=0)
            dp[i][j]=dp[i-1][j-1]*P[i];
            
            dp[i][j]+=dp[i-1][j]*(1-P[i]);
        }
    }
    
    int cnt=N/2;
    cnt++;
    double ans=0;
    for(int i=cnt;i<=N;i++)
    {
        ans+=dp[N][i];
    }
    printf("%.10f",ans);
    
    return 0;
    
}

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

const int INF = 1e9;
const int MAX_H = 100;
const int MAX_W = 100;

class Node{
public:
    int cost;
    int h, w;
    bool right;
    
    Node(int cost, int h, int w, bool right): cost(cost), h(h), w(w), right(right){};
    
    bool operator < (const Node &r) const {
        return cost > r.cost;
    }
};

int W, H;
char field[MAX_H][MAX_W];
int d[MAX_H][MAX_W][2];

int solve(){
    for(int i=0; i<MAX_H; i++)
        for(int j=0; j<MAX_W; j++)
            for(int k=0; k<2; k++)
                d[i][j][k] = INF;
    
    priority_queue<Node> que;
    
    for(int i=0; i<W; i++) if(field[H-1][i] == 'S'){
        que.push(Node(0, H-1, i, false));
        d[H-1][i][false] = 0;
        
        que.push(Node(0, H-1, i, true));
        d[H-1][i][true] = 0;
    }
    
    while(!que.empty()){
        Node v = que.top(); que.pop();
        if(field[v.h][v.w] == 'T')
            return d[v.h][v.w][v.right];
        
        if(d[v.h][v.w][v.right] < v.cost) continue;
        
        for(int dh=-3; dh<4; dh++){
            for(int dw=-3; dw<4; dw++){
                int nh = v.h + dh;
                int nw = v.w + dw;
                bool ns = v.right^true;
                
                if(nh<0 || H<=nh || nw<0 || W<=nw) continue;
                if(abs(nh-v.h) + abs(nw-v.w) > 3) continue;
                if(!((v.right && nw < v.w) || (!v.right && v.w < nw))) continue;
                if(field[nh][nw] == 'X' || field[nh][nw] == 'S') continue;
                
                int cost;
                if(field[nh][nw] == 'T')
                    cost = 0;
                else
                    cost = field[nh][nw] - '0';
                
                if(cost + v.cost < d[nh][nw][ns]){
                    d[nh][nw][ns] = cost + v.cost;
                    que.push(Node(d[nh][nw][ns], nh, nw, ns));
                }
            }
        }
    }
    
    return -1;
}

int main(){
    while(cin >> W >> H, W|H){
        for(int h=0; h<H; h++)
            for(int w=0; w<W; w++)
                cin >> field[h][w];
        
        cout << solve() << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (long long int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
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 long long INF = 1LL << 60;
int cnt = 0;
int main()
{
    int n, m;
    cin >> n >> m;
    int n_ans, m_ans;
    n_ans = n >= 2 ? n * (n - 1) / 2 : 0;
    m_ans = m >= 2 ? m * (m - 1) / 2 : 0;
    cout << m_ans + n_ans << endl;

    return 0;
}


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

using namespace std;

struct Card{
    char suit;
    int value;
};

void PrintList(struct Card A[], int N)
{
    for (int i = 0; i < N; ++i)
    {
        if (i > 0)
            cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

void SelectionSort(struct Card A[], int N)
{
    for (int i = 0; i < N; ++i)
    {
        int minj = i;
        for (int j = i; j < N; ++j)
        {
            if (A[j].value < A[minj].value)
                minj = j;
        }
        if (A[i].value != A[minj].value)
        {
            swap(A[i], A[minj]);
        }
    }
}

void BubbleSort(struct Card A[], int N)
{
    bool flag = 1;
    for (int i = 0; flag; ++i)
    {
        flag = 0;
        for (int j = N - 1; j >= i+1; --j)
        {
            if (A[j].value < A[j - 1].value)
            {
                swap(A[j], A[j - 1]);
                flag = 1;
            }
        }
    }
}

bool JudgeStable(struct Card c_stable[], struct Card c_judged[], int n){
    for(int i=0;i<n;++i){
        if(c_stable[i].suit != c_judged[i].suit) return false;
    }
    return true;
}

int main()
{
    int n;
    cin >> n;
    Card c1[n], c2[n];
    for (int i = 0; i < n; ++i){
        cin >> c1[i].suit >> c1[i].value;
        c2[i] = c1[i];
    }
    BubbleSort(c1, n);
    PrintList(c1, n);
    cout << "Stable" << endl;
    SelectionSort(c2, n);
    PrintList(c2, n);
    if(JudgeStable(c1,c2,n)) cout << "Stable" << endl;
    else   cout << "Not stable" << endl;


    return 0;
}


Measured memory_bytes: 3104
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <functional>
#include <utility>
#include <numeric>
using namespace std;
typedef long long ll;

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

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

  vector<int> A(N);

  for(int i = 0;i < N;i++)cin >> A[i];

  if(N == 1){
    if(K == A[0])cout << "POSSIBLE" << endl;
    else cout << "IMPOSSIBLE" << endl;
    return 0;
  } 

  int g = gcd(A[0],A[1]);
  for(int i = 0;i < N;i++){
    g = gcd(g,A[i]);
  }

  int mx = *max_element(A.begin(),A.end());
  if(K % g == 0 && K <= mx)cout << "POSSIBLE" << endl;
  else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 640
import sys
from collections import defaultdict

sys.setrecursionlimit(10**5)

N, K = map(int, input().split())
a_bs = [tuple(map(int, input().split())) for _ in range(N - 1)]

def culc_tree(t, used_num):
    tree[t][1] = False
    global answer
    k = K - used_num
    answer = (answer * k) % (10 ** 9 + 7)
    childs = [next_ for next_ in tree[t][0] if tree[next_][1]]
    for i, child in enumerate(childs, 2):
        culc_tree(child, i)


tree = defaultdict(lambda: [[], True])
for a, b in a_bs:
    tree[a][0].append(b)
    tree[b][0].append(a)

answer = K
tree[1][1] = False
for i, child in enumerate(tree[1][0], 1):
    culc_tree(child, i)
print(answer)

Measured memory_bytes: 128008
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <time.h>
#include <math.h>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <iterator>
#include <sstream>
#include <string>
#include <bitset>
using namespace std;
#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
#define rep(i, n) FOR(i, 0, n)
#define FIN(V) cout<<V<<endl
#define pb push_back
#define INF (1 << 28)

template<typename T>
void remove(vector<T>& vector, unsigned int index){
vector.erase(vector.begin() + index);
}

typedef pair<int, int> P;
typedef long long ll;
typedef priority_queue<int> pq;
int StrToInt(string);
string IntToStr(int);
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};

//[x][y]
int h,w;
int state[100][100];
int maxd = 0;

void dfs(int x, int y, int depth){
	rep(k,4){
		int nx = x+dx[k];
		int ny = y+dy[k];
		if(nx < 0 || ny < 0)continue;
		if(state[nx][ny] != 1)continue;
		state[nx][ny] = 0;
		dfs(nx, ny, depth+1);
		state[nx][ny] = 1;
	}
	maxd = max(maxd, depth);
}

int main(void){
	while(cin >> w >> h, w|h){
		fill_n(*state, 100*100,-1);
		maxd = 0;

		rep(i,h)rep(j,w)cin >> state[j][i];
		rep(i,h)rep(j,w){
			if(state[j][i] == 1)
				dfs(j, i, 0);
		}
		cout << maxd << endl;
	}
	return 0;
}



int StrToInt(string s){
	stringstream ss;
	ss << s;
	int val;
	ss >> val;
	return val;
}
string IntToStr(int i){
	stringstream ss;
	ss << i;
	return ss.str();
}

Measured memory_bytes: 1208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int H, N;
ll sum = 0;

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

  int A;
  for(int i = 0; i < N; i++){
    cin >> A; sum += A;
  }

  if(H <= sum) cout << "Yes" << endl;
  else cout << "No" <<endl;

  return 0;



}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

/**
 * Built using CHelper plug-in Actual solution is at the top
 */

public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		Task solver = new Task();
		solver.solve(1, in, out);
		out.close();
	}

	static class Task {
		public void solve(int testNumber, InputReader in, PrintWriter out) {
			int N = in.nextInt();
			int X = in.nextInt();
			int[] m = new int[N];
			for(int i = 0; i < N; i++) {
				m[i] = in.nextInt();
				X -= m[i];
			}
			Arrays.sort(m);
			out.println(m.length + X / m[0]);
		}
	}
		
	static class InputReader {
		public BufferedReader reader;
		public StringTokenizer tokenizer;

		public InputReader(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream), 32768);
			tokenizer = null;
		}

		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(reader.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 21460
n,d=map(int,input().split())
x=[0]*n
y=[0]*n
for i in range(n):
    x[i],y[i]=map(int,input().split())
    
icnt=0
d2=d*d
for i in range(n):
    if x[i]**2+y[i]**2<=d2:
        icnt+=1
print(icnt)

Measured memory_bytes: 24632
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdbool.h>
#include<assert.h>
typedef long long ll;
typedef long double ld;
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define rrep(i,l,r)for(ll i=(l);i>=(r);i--)
#define INF (1LL<<60)
#define MOD1 1000000007
#define MOD2 998244353
#define MAX_N (1 << 17)
#define YES printf("Yes\n")
#define NO printf("No\n")
#define PN printf("\n")
#define charsize 100005 //10^5+5

void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a= c;}
ll max2(ll a,ll b){return a>=b?a:b;}
ll min2(ll a,ll b){return a>=b?b:a;}
ll min3(ll a, ll b, ll c){return (a<=b && a<=c) ? a : b<=c ? b : c;}
ll max3(ll a, ll b, ll c){return (a>=b && a>=c) ? a : b>=c ? b : c;}
ll minn(ll n, ll a[n]){ll b=INF;rep(i,0,n) b=min2(b,a[i]);return b;}
ll maxn(ll n, ll a[n]){ll b=-INF;rep(i,0,n) b=max2(b,a[i]);return b;}
ll ABS(ll a){return a>=0?a:(-a);}
ll POW(ll a, ll b){ll c=1;rep(i,0,b) c*=a;return c;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
ll mod_MOD1(ll n){n+= n<0?((-n)/MOD1+1)*MOD1:0; return n%=MOD1;}
ll mod_p(ll n ,ll p){n+= n<0?((-n)/p+1)*p:0; return n%=p;}
ll change_into_num(char s[] , ll len, ll p){ return !p ? 0 : POW(10,p-1)*(s[len-p]-'0') + change_into_num(s,len,p-1); }

int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}

typedef struct{ ll a , b;}fr;
int cmp1( const void *p, const void *q ) { return ((fr*)p) ->a - ((fr*)q)->a;}
int cmp2( const void *p, const void *q ) { return ((fr*)q) ->a - ((fr*)p)->a;}
void strsortup(fr*a,int n){qsort(a,n,sizeof(fr),cmp1);}
void strsortdown(fr*a,int n){qsort(a,n,sizeof(fr),cmp2);}

int main(void){
    // char ;
    ll n,k,s;
    // ll ans=0;
    scanf("%lld%lld%lld",&n,&k,&s);
    // ll [n];
    if(s==POW(10,9)){
        rep(i,0,k){
            printf("%lld",POW(10,9));
            if(i!=n-1) printf(" ");
        }
        rep(i,k,n){
            printf("%lld",POW(10,9)-1);
            if(i!=n-1) printf(" ");            
        }
        PN;
        return 0;
    }
    rep(i,0,k){
        printf("%lld",s);
        if(i!=n-1) printf(" ");
    }
    rep(i,k,n){
        printf("%lld",s+1);
        if(i!=n-1) printf(" ");        
    }
    PN;

    
    // printf("%lld\n");
    return 0;
}


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

#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++)


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

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
    int a,b,ans;
    scanf("%d%d",&a,&b);
    ans=max(a+b,a-b);
    ans=max(ans,a*b);
    printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256