akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;

li n;
vector<li> edges[200100];


PI bfs(li now, li from, li now_distance) {
    PI res{now_distance, now};
    for (auto && next : edges[now]) {
        if (next == from)continue;
        auto tres = bfs(next, now, now_distance + 1);
        if (tres.F > res.F) {
            res = tres;
        }
    }
    return res;
}

int main() {
    cin >> n;
    rep(i, n - 1) {
        li a, b;
        cin >> a >> b;
        a--;
        b--;
        edges[a].pb(b);
        edges[b].pb(a);
    }

    auto now = bfs(0, -1, 0);
    auto now2 = bfs(now.S, -1, 0);

    cout << (now2.F % 3 != 1 ? "First" : "Second") << endl;



    return 0;
}

Measured memory_bytes: 26752
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,x[100000],y[100000],t[100000];
  bool flag=true;
  cin>>n;
  for(int i=0;i<n;i++) cin>>t[i]>>x[i]>>y[i];

  for(int i=0;i<n;i++){
    if(t[i]<x[i]+y[i]) flag=false;
    if(t[i]%2==0 && (x[i]+y[i])%2!=0) flag=false;
    if(t[i]%2!=0 && (x[i]+y[i])%2==0) flag=false;
  }
  if(flag) cout<<"Yes";
  else cout<<"No";

}


Measured memory_bytes: 1408
function main()
    S,T = reads(String, String)
    c = 0
    tl = length(T)
    sl = length(S)
    for i in 0:sl-tl
        tmpc = 0
        for j in 1:tl
            if T[j] == S[i+j]
                tmpc += 1
            end
        end
        if tmpc > c
            c = tmpc
        end
    end
    println(tl - c)
end

import Base.parse
import Base.StringVector

parse(::Type{String},  str::AbstractString) = str
isdelim(x::UInt8, xs::Set{UInt8}) = x in xs
const delimset = Set([0x0a, 0x20])

function myreaduntil(s::IO, delims::Set{UInt8})::Vector{UInt8}
    out = StringVector(0)
    c::UInt8 = 0x00
    while !eof(s)
        c = read(s, UInt8)
        !isdelim(c, delims) && break
    end
    push!(out, c)
    eof(s) && return out
    while !eof(s)
        c = read(s, UInt8)
        isdelim(c, delims) && break
        push!(out, c)
    end
    return out
end

function readword(io::IO = stdin, delims = delimset)::String
    word = myreaduntil(io, delims)
    i = length(word)
    if i == 0 || word[i] != 0x0a
        return String(word)
    elseif i < 2 || word[i-1] != 0x0d
        return String(resize!(word,i-1))
    else
        return String(resize!(word,i-2))
    end
end

pread(ty) = parse(ty, readword())

reads(tys...)::Tuple{tys...} = Tuple{tys...}(pread(ty) for ty in tys)

function readvec(tys::Tuple , len::Signed)::Tuple{map(x -> Vector{x},tys)...}
    rv = Tuple{map(x -> Vector{x},tys)...}(Vector{ty}(undef,len) for ty in tys)
    for i in 1:len
        for j in 1:length(tys)
            @inbounds rv[j][i] = pread(tys[j])
        end
    end
    rv
end

readvec(ty::Type, len::Signed)::Vector{ty} = @inbounds ty[pread(ty) for i in 1:len]

function readmat(ty::Type, s...)::Matrix{ty}
    v = Matrix{ty}(undef, s...)
    @inbounds for i in 1:s[1]
        v[i,:] = readvec(ty, s[2])
    end
    v
end

main()


Measured memory_bytes: 191444
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

int main(){
  int n,k;
  while(cin>>n>>k){
    if(n==0) break;
    vector<int> seq(n);
    set<string> ans;
    REP(i,n) cin>>seq[i];
    for(int i = 0; i < 1<<n; i++){
      int cnt = 0;
      REP(j,n){
        cnt += (i>>j)&1;
      }
      if(cnt != k) continue;
      vector<int> selected;
      REP(j,n) if((i>>j)&1){
        selected.push_back(seq[j]);
      }
      sort(selected.begin(), selected.end());
      do{
        stringstream ss;
        REP(j,selected.size()) ss << selected[j];
        ans.insert(ss.str());
      }while(next_permutation(selected.begin(), selected.end()));
    }
    printf("%d\n",(int)ans.size());
  }
  return 0;
}

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

int main(){
	int n,i,j;
	int *a;
	long long int sum,max;

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

		a = (int *)malloc(sizeof(a)*n);

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

		max	= -100000*n;
		for(i = 0;i < n;i++){
			sum = 0;
			for(j = i;j < n;j++){
				sum += a[j];
				if(max < sum){
					max = sum;
				}
			}
		}
		printf("%d\n",max);
	}

	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>

typedef long long ll;
typedef unsigned long long ull;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
#define rep(i,n) for(int i = 0;i < ((int)(n));++i)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define SUM(vec) accumulate(all(vec),0LL)
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;}
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);}
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;}
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;}

int ctoi(char c){return c - '0';}

bool isOk(ll key,ll value){
  return key >= value;
}

ll binary_search(vector<ll> a,ll key){
  ll ok = a.size()-1;
  ll ng = 0;

  while(abs(ok - ng) > 1){
    ll mid = (ok + ng) / 2;
    if(isOk(key,a[mid]))ok = mid;
    else ng = mid;
  }
  return ok;
}

bool isPrime(ll n) {
	for (int i = 2; n >= i * i; ++i) {
		if(!(n % i))return false;
	}
  return true;
}
vector<ll> primes(ll n){
  vector<ll> v;
  for (ll i = 2; i*i <= n; ++i) {
    while(n%i==0){
      n/=i;
      v.pb(i);
    }
  }
  if(n != 1)v.pb(n);
  return v;
}


int main() {
  //cin.tie(0); ios::sync_with_stdio(0);
  string s;cin>>s;
  for(int i = 0;i < s.size();i += 2){
    cout<<s[i];
  }
  cout<<endl;
  return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
struct Graph{
  int n;
  vector<vector<int>> edge;
  const int inf = 1e+9+10;

  Graph(int _n){
    n = _n;
    edge.resize(n,vector<int>(n,inf));
  }

  void add(int from,int to,int cost){
    edge[from][to]=cost;
  }

  void wf(){
    rep(k,n){
      rep(i,n){
	rep(j,n){
	  edge[i][j]=min(edge[i][j],edge[i][k]+edge[k][j]);
	}
      }
    }
  }
};

int main()
{
  int n,m,l;cin >> n >> m >> l;
  vector<int> a(m),b(m),c(m);
  rep(i,m) cin >> a[i] >> b[i] >> c[i];
  int q;cin >> q;
  vector<int> s(q),t(q);
  rep(i,q) cin >> s[i] >> t[i];

  Graph gp1(n);
  rep(i,m){
    gp1.add(a[i] - 1, b[i] - 1, c[i]);
    gp1.add(b[i] - 1, a[i] - 1, c[i]);    
  }
  gp1.wf();

  Graph gp2(n);
  rep(i,n){
    rep(j,n){
      if(i == j) continue;
      if(gp1.edge[i][j] <= l){
	gp2.add(i, j, 1);
	gp2.add(j, i, 1);
      }
    }
  }
  gp2.wf();
  rep(i,q){
    if(gp2.edge[s[i] - 1][t[i] - 1] == gp2.inf) cout << -1 << "\n";
    else cout << gp2.edge[s[i] - 1][t[i] - 1] - 1 << "\n";
  }
  
  return 0;
}


Measured memory_bytes: 2432
from heapq import heappush, heappop

N,M = map(int, input().split())
hq = []
for i in input().split():
    heappush(hq, -int(i))

for i in range(M):
    tmp = -heappop(hq) // 2
    heappush(hq, -tmp)

print(-sum(hq))    


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

#define all(x) x.begin(),x.end()
#define fi first
#define sd second
#define lson (nd<<1)
#define rson (nd+nd+1)
#define PB push_back
#define mid (l+r>>1)
#define MP make_pair
#define SZ(x) (int)x.size()

using namespace std;

typedef long long LL;

typedef vector<int> VI;

typedef pair<int,int> PII;

inline int read(){
    int res=0, f=1;char ch=getchar();
    while(ch<'0'|ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){res=res*10+ch-'0';ch=getchar();}
    return res*f;
}

const int MAXN = 200'005;

const int MOD = 1000000007;

void addmod(int& a, int b){a+=b;if(a>=MOD)a-=MOD;}
int mulmod(int a, int b){return 1ll*a*b%MOD;}

template<typename T>
void chmin(T& a, T b){if(a>b)a=b;}

template<typename T>
void chmax(T& a, T b){if(b>a)a=b;}


int main(){
    int x,y;
    x=read();y=read();

    int s=0;
    for(int i=1;i<=y;++i){
        s+=read();
    }

    if(x>=s)cout<<x-s;
    else cout<<-1;

    return 0;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <math.h>
 
int main(void){
    int i,n,s[1000];
    double h,sum;
     
    while(1){
 
        scanf("%d",&n);
        if(!n) break;
         
        sum = 0;
        h = 0;
         
        for(i=0;i<n;i++){
            scanf("%d",&s[i]);
            sum += s[i];
        }
     
        sum /= n;
     
   //     printf("%lf ",sum);
         
        for(i=0;i<n;i++){
            h += pow(s[i]-sum, 2.0);
        }
             
        h /= n;
 
   //     printf("%lf ",h);
 
        printf("%lf\n",pow(h,1.0/2.0));
     
    }
     
    return 0;
}


Measured memory_bytes: 2132
#include <iostream>
#include <cmath>
#include <set>
#include <string>
#include <algorithm>
#include <vector>
#include <bitset>
#include <iomanip>
#include <map>

using std::cin;
using std::cout;
using std::endl;
using std::string;
using std::vector;
using std::bitset;

#define rep(i,n)    for(int i=0; i<(int)n; i++)
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, ll> pll;

void printFixedDouble(double d, int fix) {
    cout << std::fixed;
    cout << std::setprecision(fix) << d << endl;
}

int timestamp = 1;

void search(int index, vector<vector<int> > &graph, vector<int> &dest, vector<int> &fin) {
    if (dest[index - 1] != -1) return;
    dest[index - 1] = timestamp;
    timestamp++;
    for (int& dsts: graph[index - 1]) {
        search(dsts, graph, dest, fin);
    }
    fin[index - 1] = timestamp;
    timestamp++;
}

int main() {
    int n;
    cin >> n;
    vector<vector<int> > graph(n, vector<int>());

    rep(i, n) {
        int index, k;
        cin >> index >> k;
        rep(j, k) {
            int dst;
            cin >> dst;
            graph[index - 1].push_back(dst);
        }
    }

    
    vector<int> dest(n, -1);
    vector<int> fin(n, -1);

    rep(i, n) {
        search(i + 1, graph, dest, fin);
    }

    rep(i, n) {
        cout << i+1 << " " << dest[i] << " " << fin[i] << endl;
    }
}


Measured memory_bytes: 3148
# include <cstdio>
# include <iostream>
# include <cstring>
# include <algorithm>
# include <string>
# include <queue>
# define R register int
# define ll long long
# define pac(a,b) make_pair(a,b)

using namespace std;

const int maxn=200005;
int n,m,h,d[maxn],vis[maxn],f[maxn];
int sx[maxn],sy[maxn],a,b;
ll ans=0;
struct node { int v,id; }X[maxn],Y[maxn];
typedef pair <int,int> pii;
priority_queue <pii,vector<pii>,greater<pii> > q1,q2;

bool cmp (node a,node b) { return a.v<b.v; }

int find (int x) { if(x!=f[x]) return f[x]=find(f[x]); return x; }

int main()
{
    scanf("%d",&n);
    for (R i=1;i<=n;++i)
    {
        scanf("%d%d",&X[i].v,&Y[i].v);
        X[i].id=i;
        Y[i].id=i;
    }
    sort(X+1,X+1+n,cmp);
    sort(Y+1,Y+1+n,cmp);
    for (R i=1;i<n;++i)
		q1.push(pac(X[i+1].v-X[i].v,i)),sx[i]=1;
    for (R i=1;i<n;++i)
        q2.push(pac(Y[i+1].v-Y[i].v,i)),sy[i]=1;
    int s=0;
    for (R i=1;i<=n;++i) f[i]=i;
    while(s!=n-1)
    {
        int x=q1.top().first;
        int y=q2.top().first;
        if(x<y)
        {
            a=q1.top().second;
            q1.pop();
            b=a+sx[a];
			x=X[a].id; y=X[b].id;
			x=find(x),y=find(y);
			if(x!=y) f[x]=y,s++,ans+=X[a+sx[a]].v-X[a].v;
            if(a+sx[a]+1>n) continue;
            sx[a]++;
            q1.push(pac(X[a+sx[a]].v-X[a].v,a));
        }
        else
        {
            a=q2.top().second;
            q2.pop();
            b=a+sy[a];
			x=Y[a].id; y=Y[b].id;
			x=find(x),y=find(y);
			if(x!=y) f[x]=y,s++,ans+=Y[a+sy[a]].v-Y[a].v;
            if(a+sy[a]+1>n) continue;
            sy[a]++;
            q2.push(pac(Y[a+sy[a]].v-Y[a].v,a));
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 7924
import java.util.*;

public class Main {
    public static void main(String args[]) {
        Scanner scn = new Scanner(System.in);
        int w = scn.nextInt();
        int h = scn.nextInt();
        int x = scn.nextInt();
        int y = scn.nextInt();
        int r = scn.nextInt();

        boolean ans1 = (x >= r) && (y >= r);
        boolean ans2 = ((w - x) >= r) && ((h - y) >= r);

        if ((ans1 == true) && (ans2 == true)) {
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }

        scn.close();
    }
}


Measured memory_bytes: 26400
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, a, n) for(ll i = a; i < (ll)(n); i++)
#define memi cout << endl
#define kono(n) cout << fixed << setprecision(n)
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define hina cout << ' '
#define in(n) cin >> n
#define in2(n, m) cin >> n >> m
#define in3(n, m, l) cin >> n >> m >> l
#define out(n) cout << n
const ll mei = (ll)1e9 + 7;

int main(){
  ll a, b, n, s, t, u;
  in(n);
  vector<ll> c(n);
  rep(i, n)
    in(c[i]);
  s = 0; // + or -
  t = c[0]; //hozon
  u = 0;
  a = 1; // kosuu
  rep2(i, 1, n){
    if(s == 0){
      if(c[i] > t){
        s = 1;
        t = c[i];
      }
      else if(c[i] < t){
        s = 2;
        t = c[i];
      }
    }
    else if(s == 1){
      if(c[i] >= t)
        t = c[i];
      else{
        s = 0;
        a++;
        t = c[i];
      }
    }
    else{
      if(c[i] <= t)
        t = c[i];
      else{
        s = 0;
        a++;
        t = c[i];
      }
    }
  }
  out(a);
  memi;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;

int sum_digit(int n){
  if( n == 0 ) return 0;
  else return n%10 + sum_digit(n/10);
}

int main()
{
  int i,N,M; cin >> N >> M;
  vector<int> city(N+1);
  vector<int> a(M),b(M);
  for(i = 0; i < M; i++){
  	cin >> a.at(i) >> b.at(i);
  }
  
  for(i = 0; i < M; i++){
  	city.at(a.at(i))++;
    city.at(b.at(i))++;
  }
  
  for(i = 1; i < N+1; i++){
  	cout << city.at(i) << endl;
  }
}

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

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

// order statistics tree
typedef tree<pii, null_type, less<pii>, rb_tree_tag,
             tree_order_statistics_node_update> indexed_set;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update> order_set;

#define F first
#define S second
#define PB push_back
#define MP make_pair

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()
const int N = 55;
int n, k;
int v[N];
int op[N][N][N];
int lo[N][N][N];
int ans;
int main() {
  cin.tie(0); cin.exceptions(cin.failbit);
  scanf("%d%d", &n, &k);
  lo[0][0][0] = 1e9;
  rep(i, 1, n+1){
    scanf("%d", v+i);
  }

  /*
  // only using popping ops
  for(int i = 0; i <= min(n, k); i++){ // pop left
    if(i > 0){
      op[i][0][0] = op[i-1][0][0] + v[i];
      lo[i][0][0] = min(lo[i-1][0][0], v[i]);
    }
    for(int j = 1; i+j <= min(n, k); j++){ // pop right
      op[i][j][0] = op[i][j-1][0] + v[n-j+1];
      lo[i][j][0] = min(lo[i][j-1][0], v[n-j+1]);
      ans = max(ans, max(op[i][j][0], op[i][0][0]));
    }
  }
  */

  order_set s; // used for calculating the lowest value

  // iterate through possible combinations of operations
  // we assume that pushing back into the deque only happens
  // when we stop adding to our hand
  for(int i = 0; i <= min(n, k); i++){ // pop left into hand

    if(i > 0){

      // keep track of min
      s.insert(v[i]);
      lo[i][0][0] = min(lo[i-1][0][0], v[i]);

      // keep track of highest value
      op[i][0][0] = op[i-1][0][0] + v[i];
      ans = max(ans, op[i][0][0]);
    }

    for(int j = 0; i+j <= min(n, k); j++){ // pop right into hand
      if(j > 0){
        s.insert(v[n-j+1]);

        op[i][j][0] = op[i][j-1][0] + v[n-j+1];
        lo[i][j][0] = min(lo[i][j-1][0], v[n-j+1]);

        ans = max(ans, op[i][j][0]);
      }
      for(int l = 0; i+j+l <= k && l < i+j && (i || j); l++){ // push back into deque
        lo[i][j][l] = *s.find_by_order(l);
        // printf("%d %d %d, lo: %d ", i, j, l, lo[i][j][l]);
        // puts("");

        if(l > 0){
          op[i][j][l] = op[i][j][l-1] - lo[i][j][l-1];
          ans = max(ans, op[i][j][l]);
        }
      }
    }

    // remove all gems from the right
    for(int j = 0; i+j <= min(n, k); j++){
      if(j > 0){
        s.erase(v[n-j+1]);
      }
    }
  }

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


Measured memory_bytes: 1152
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List

readInt = fst . fromJust . BS.readInt
getInt = readInt <$> BS.getLine

main = do
    n <- getInt
    ss <- replicateM n getLine
    putStrLn . unlines $ solve ss

solve ss = [head s | s <- gs , length s == l]
    where gs = group $ sort ss
          l = maximum $ map length gs

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

#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT_ON(bit, i) (bit & (1LL << i))

typedef long long LL;
template<typename T> using V = std::vector<T>;
template<typename T> using VV = std::vector<std::vector<T>>;
template<typename T> using VVV = std::vector<std::vector<std::vector<T>>>;
template<typename T> using VVVV = std::vector<std::vector<std::vector<std::vector<T>>>>;

template<class T> inline T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> inline void print(T x) { std::cout << x << std::endl; }
template<class T> inline void print_vec(const std::vector<T> &v) { for (int i = 0; i < v.size(); ++i) {  if (i != 0) {std::cout << " ";} std::cout << v[i];} std::cout << "\n"; }
template<class T> inline bool inside(T y, T x, T H, T W) {return 0 <= y and y < H and 0 <= x and x < W; }
template<class T> inline double euclidean_distance(T y1, T x1, T y2, T x2) { return sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)); }
template<class T> inline double manhattan_distance(T y1, T x1, T y2, T x2) { return abs(x1 - x2) + abs(y1 - y2); }
template<typename T> T &chmin(T &a, const T &b) { return a = std::min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = std::max(a, b); }
template<class T> inline std::vector<T> unique(std::vector<T> v) {
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    return v;
}
// 初項s, 交差dのn個の数列の和
long long sum_of_arithmetic_progression(long long s, long long d, long long n) {
    return n * (2 * s + (n - 1) * d) / 2;
}

const int INF = 1 << 30;
const double EPS = 1e-9;
const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy4 = {0, -1, 0, 1}, dx4 = {1, 0, -1, 0};
const std::vector<int> dy8 = { 0, -1, 0, 1, 1, -1, -1, 1 }, dx8 = { 1, 0, -1, 0, 1, 1, -1, -1 };

using namespace std;

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

    int N, W;
    cin >> N >> W;

    V<int> w_list(N), v_list(N);
    FOR(i, 0, N) {
        cin >> w_list[i] >> v_list[i];
    }

    VV<LL> dp(N + 1, V<LL>(W + 1, -INF));
    dp[0][0] = 0;
    FOR(i, 0, N) {
        int w = w_list[i];
        int v = v_list[i];

        FOR(j, 0, W + 1) {
            if (dp[i][j] == -INF) {
                continue;
            }

            // not use
            chmax(dp[i + 1][j], dp[i][j]);

            // use
            if (j + w <= W) {
                chmax(dp[i + 1][j + w], dp[i][j] + v);
            }
        }
    }
    print(MAX(dp[N]));

	return 0;
}

Measured memory_bytes: 80256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
ll c[500001];
ll n,q,cnt;
int vis[500001];
ll l,r;
int B=720;
pair<int ,pair<int,int> > query[500001];
int ans[500001];


bool compare(pair<int ,pair<int,int> > a, pair<int ,pair<int,int> > b){
    if(a.first/B==b.first/B){
    return a.second.first<b.second.first;
    }
    return a.first<b.first;
}

void add(int x){
    if(vis[x]==0){
        ++cnt;
    }
    ++vis[x];
}

void subtract(int x){
    if(vis[x]==1){
        --cnt;
    }
    --vis[x];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    cin>>q;
      for(int i=0;i<n;i++){
          cin>>c[i];
          --c[i];
          vis[i]=0;
    }
    for(int i=0;i<q;i++){
        cin>>l>>r;
        --l,--r;
        query[i]={l,{r,i}};
    }
     sort(query,query+q,compare) ;
     l=0,r=-1;
     cnt=0;
     for(int i=0;i<q;i++){
         while(r<query[i].second.first){
            r++;
            add(c[r]);
         }
         while(r>query[i].second.first){
             subtract(c[r]);
             r--;
         }
         while(l<query[i].first){
             subtract(c[l]);
             l++;
         }
         while(l>query[i].first){
             l--;
             add(c[l]);
         }
         ans[query[i].second.second]=cnt;
     }
     for(int i=0;i<q;i++){
         cout<<ans[i]<<'\n';
     }
    return 0;
}


Measured memory_bytes: 17464
import math
import sys

def main():
    while True:
        d,e = map(int,input().split())
        ans = sys.maxsize
        if not d and not e:
            return
        for x in range(d+1):
            y = d-x
            ans = min(ans, abs(math.sqrt(float(x)**2+float(y)**2)-e))
        print(ans)

if __name__ == '__main__':
    main()



Measured memory_bytes: 5680
s = input()
n = len(s)
s = list(s)
all_num = n * (n-1)/2
for i in range(97,123):
  tyouhuku = s.count(chr(i))
  all_num -= tyouhuku * (tyouhuku - 1) /2
  
print(int(all_num) + 1)
  


Measured memory_bytes: 4840
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;
ll MOD = 1e9+7;
//LLONG_MIN



int main(void){
	ll N,a[101],b=0,x;
	cin>>N;
	rep(i,N){
		cin>>a[i];
		b+=a[i];
	}
	if(b%N==0){
		x=b/N;
	}else{
		if(double(b)/N - double(b/N)<0.5){
			x=b/N;
		}else{
			x=b/N+1;
		}
	}
	ll ans=0;
	rep(i,N)ans+=(a[i]-x)*(a[i]-x);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for(int i = a; i < b; i++)
#define REP_(i, a, b) for(int i = a; i <= b; i++)
#define sl(n) scanf("%lld", &n);
#define si(n) scanf("%d", &n);
#define RepAll(a) for(auto x: a)
#define cout(ans) cout << ans << endl;
typedef long long ll;
/**
 *    This code has been written by YueGuang, feel free to ask me question. Blog: http://www.yx.telstudy.xyz
 *    created:
 */
using namespace std;
int main(){
    string a, b;
    cin >> a >> b;
    if(a.size()> b.size()){
        for(int i = 0; i < b.size(); i++){
            cout << a[i] << b[i];
        }
        for(int i = b.size(); i < a.size(); i++){
            cout << a[i];
        }
        cout << '\n';
    }
    if(b.size()> a.size()){
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << b[i];
        }
        for(int i = a.size(); i < b.size(); i++){
            cout << b[i];
        }
        cout << '\n';
    }
    if(a.size() == b.size()){
        for(int i = 0; i < a.size(); i++){
            cout << a[i] << b[i];
        }
        cout << '\n';

    }
}


Measured memory_bytes: 256
D = gets.to_i
C,*S = (0..D).map{gets.split.map &:to_i}
R,L,M,N = 0..25,[-1]*26,2,10
I = R.select{|i| C[i]==0}
1 < I.size && S.each {|s|
  z=99; I.each {|i| if i<z; z=i elsif s[z]<s[i]; s[z] = 0; z = i else s[i] = 0 end}
}
def F(d,n)
  n = D-d if n > D-d
  s,t = S[d],[0]*26
  i = R.max_by(M){|i| t[i] = n*C[i]*(d-L[i]) + s[i] }
  x = t[i[0]]
  i = n < 2 ? i[0] : i.max_by {|i|
    l,L[i] = L[i],d
    c = t[i] + (F(d+1,n-1)>>5)
    L[i] = l
    x < c ? x=c : c
  }
  (x<<5) + i
end
D.times { p 1+i=F(_1,N)&31; L[i]=_1 }

Measured memory_bytes: 14628
//بسم الله الرحمن الرحيم
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define el << endl
#define PI 3.141592653589793238
#define _test_ int t; cin >> t; while(t--)
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define file() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout)
ll gcd ( ll  a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }
int dx[]={0,0,+1,-1,+1,-1,-1,+1};
int dy[]={+1,-1,0,0,+1,-1,+1,-1};
///*......................*//* LET'S BEGIN (-_^) *//*............................///
const int mx= 1e5+123;
string n;
int a,b;
map<int,int>m;

void generate()
{
    for(int i=1;i<=9;i++)
        for(int j=i;j<=9;j++)
            m[i*j]++;
}

void _case_()
{
    cin >> a;
    if(m[a]) cout << "Yes\n";
    else cout << "No\n";
}



int main()
{
    optimize();
    generate();
    //_test_
    _case_();
}

///////////*  N A Y E M  *///////////

Measured memory_bytes: 3660
n=input()
a=map(int, raw_input().split())
if max(a)-min(a)>=2:
	print "No"
	exit()
if max(a)==min(a):
	print "Yes" if a[0]==n-1 or a[0]*2<=n else "No"
else:
	one_cnt=a.count(min(a))
	more_cnt=min(a)+1-one_cnt
	print "No" if one_cnt+more_cnt*2>n or more_cnt<=0 else "Yes"

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

int main(){
    int N;
    cin >> N;
    double A;
    double ans = 0;
    for (int i = 0;i < N;i++){
        cin >> A;
        ans += 1 / A;
    }
    ans = 1 / ans;
    cout << setprecision(20) << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <string.h>
#include <ctype.h>
#include <algorithm>

using namespace std;

int main() {
  string s,t;
  cin >> s >> t;

  if(t.size() == s.size() + 1) {
    for(int i = 0; i < s.size(); i++) {
      if(s[i] == t[i]) continue;
      else cout << "No" << endl; goto Exit;
    }
  }
  else {
    cout << "No" << endl; 
    goto Exit;
  }

  cout << "Yes" << endl;
  Exit:;
}

Measured memory_bytes: 3620
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<queue>
#include<string>
#define ll long long
using namespace std;

const int maxn = 2e5+5;
int a[maxn];

int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    int goal = 1;
    for(int i=1;i<=n;i++)
    {
        if(a[i]==goal) goal++;
    }
    if(goal!=1)printf("%d\n",n-goal+1);
    else printf("-1\n");
    return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007, INF=(1LL<<60);
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

long long modpow(long long a, long long n) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    ll n = s.length();
    vector<ll> a(n+1, 0LL), c(n+2, 0LL), le(n+1, 0LL), ri(n+2, 0LL);
    s = " " + s;
    for(int i=1;i<=n;i++){
    	if(s[i] == 'A') a[i]++;
    	if(s[i] == '?') le[i]++;
    	a[i] += a[i-1];
    	le[i] += le[i-1];
    }
    for(int i=n;i>=1;i--){
    	if(s[i] == 'C') c[i]++;
    	if(s[i] == '?') ri[i]++;
    	c[i] += c[i+1];
    	ri[i] += ri[i+1];
    }
    ll ans = 0;
    for(int i=1;i<=n;i++){
    	if(s[i] == '?' || s[i] == 'B'){
    		ll num1, num2;
    		num1 = (modpow(3LL, le[i-1]) * a[i-1]) % mod;
    		num1 += (le[i-1] * modpow(3LL, le[i-1] - 1)) % mod;
    		num2 = (modpow(3LL, ri[i+1]) * c[i+1]) % mod;
    		num2 += (ri[i+1] * modpow(3LL, ri[i+1] - 1)) % mod;
    		num1 %= mod;
    		num2 %= mod;
    		ans += (num1 * num2)% mod;
    		ans %= mod;
    	}
    }
    cout << ans << endl;
    return 0;
}


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

int main(){
  ll n,a,ans=0;
  cin>>n;
  vector<int> vec(n);
  rep(i, n){
    cin>>vec[i];
  }
  rep(i,n-1){
    if(vec[i+1]-vec[i]>=0)continue; 
    else{ans+=-vec[i+1]+vec[i];
         vec[i+1]=vec[i];
         
        }
  }
  cout<<ans;
}

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

int main() {
  int n, a, b;
  cin >> n >> a >> b;
  if ((b - a) % 2 == 0)
    cout << "Alice" << endl;
  else
    cout << "Borys" << endl;
  
}

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

bool f(int n, vector<int>& a, map<int, int>& mp)
{
  if (mp.count(0) > 0 && mp[0] == n) {
    return true;
  }
  if (mp.size() > 3 || n % 3 != 0) {
    return false;
  }
  if (mp.size() == 3) {
    int x = 0;
    for (auto&& e : mp) {
      x ^= e.first;
      if (mp[e.first] != n / 3) {
        return false;
      }
    }
    return x == 0;
  }
  if (mp.size() == 2) {
    return mp[0] == n / 3;
  }
  return false;
}

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  map<int, int> mp;
  for (auto&& e : a) {
    cin >> e;
    mp[e]++;
  }
  cout << (f(n, a, mp) ? "Yes" : "No") << endl;
}


Measured memory_bytes: 4224
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Integer_Text_IO; use Ada.Integer_Text_IO;

procedure Solve is
   A : Integer;
   B : Integer;
begin
   Get (A);
   Get (B);
   if B*2 >= A then
      Put_Line ("0");
   else
      Put_Line (Integer'Image (A-B*2));
   end if;
end Solve;

Measured memory_bytes: 3676
a = [int(i) for i in input().split(" ")]
num = 0
for m in range(1, a[0]+1):
    for d in range(10, a[1]+1):
        d_1 = list(str(d))
        if int(d_1[0]) >= 2 and int(d_1[1]) >= 2 and int(d_1[0])*int(d_1[1]) == m:
            num += 1
print(num)

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

int main(){
    string N;
    cin >> N;
    int len = N.size() -1 ;
    if(N[len] == '3'){
        cout << "bon";
    }else if(N[len] == '0' || N[len] == '1' || N[len] == '6' || N[len] == '8'){
        cout << "pon";
    }else{
        cout << "hon";
    }
}

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

int main(){
  int w,h,n;
  cin >> w >> h >> n;
  vector<int> x(n);
  vector<int> y(n);
  vector<int> a(n);
  int dx,dy;
  int p,q,r,s;
  dx = 0;
  dy = 0;
  rep(i,n) cin >> x[i] >> y[i] >> a[i];
  rep(i,n){
    if(a[i] == 1){
      p = x[i];
      dx = max(dx,p);
    }
    if(a[i] == 2){
      q = x[i];
      w = min(w,q);
    }
    if(a[i] == 3){
      r = y[i];
      dy = max(dy,r);
    }
    if(a[i] == 4){
      s = y[i];
      h = min(h,s);
    }
  }
  if(w<dx || h<dy) cout << 0 << endl;
  else cout << (w-dx) * (h-dy) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define INF 100000000
typedef long long ll;

int main(){
    VL a(3);
    cin>>a[0]>>a[1]>>a[2];
    sort(a.begin(),a.end());
    cout<<a[2]*10+a[1]+a[0]<<endl;
    return 0;
}

Measured memory_bytes: 256
import math
def main():
  X=int(input())
  Xtgt=100
  i=0
  sFlag=True
  while(sFlag):
    i=i+1
    Xtgt=math.floor(Xtgt*(1+0.01))
    if(Xtgt>=X):
      print(i)
      sFlag=False
  
if __name__=='__main__':
  main()

Measured memory_bytes: 63248
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		try(Scanner sc = new Scanner(System.in)){
			double x1 = sc.nextDouble();
			double y1 = sc.nextDouble();
			double x2 = sc.nextDouble();
			double y2 = sc.nextDouble();
			
			double dx = x1-x2;
			double dy = y1-y2;
			
			System.out.println(Math.sqrt(dx*dx+dy*dy));
		}
	}
}


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

int main(void) {
	string moji;
	int p;

	getline(cin, moji);
	p= moji.size();
	for (int i = 0; i <= p; i++) {
		if (moji[i] == '\n')break;
		if ((moji[i] >= 65) && (moji[i] <= 90)) {
			moji[i] += 32;
		}
		else if ((moji[i] >= 97) && (moji[i] <= 122)) {
			moji[i] -= 32;
		}
	}
		cout << moji<<"\n";
	return 0;
}

Measured memory_bytes: 3228
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
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 sc second
#define fr first
#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(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=b-1;i>=a;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, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; 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 N,A[200007],ans[200007];
vector<vector<ll>> E(200007);
vector<ll> V;
vector<ll> dp(200007,INF);

ll binaly(ll key){
  ll ok=0,ng=V.size();
  while(ok<ng){
    ll mid = (ok+ng)/2;
    if(dp[mid]<key){ 
      ok = mid+1; 
    }
    else{
      ng = mid;
    }
  }
  return ok;
}

void dfs(ll key,ll mae){
  V.pb(A[key]);
  ll X,Y;
  X=binaly(A[key]);
  Y=dp[X];
  dp[X] = A[key];
  ans[key]=lower_bound(dp.begin(), dp.end(), INF ) - dp.begin();
  rep(i,E[key].size()){
    if(E[key][i]!=mae){
      dfs(E[key][i],key);
    }
  }
  V.pop_back();
  dp[X]=Y;
}

int main(){
  cin >> N;
  rep(i,N){
    cin >> A[i+1];
  }
  V.clear();
  rep(i,N-1){
    ll X,Y;
    cin >> X >> Y;
    E[X].pb(Y);
    E[Y].pb(X);
  }
  dfs(1,0);
  rep(i,N){
    cout << ans[i+1] << endl;
  }
}

Measured memory_bytes: 34528
def solve():
    N = int(raw_input())
    X = [0] * N
    Y = [0] * N
    for i in range(N):
        X[i], Y[i] = (int(_) for _ in raw_input().split())
    ##
    m = 31
    d = [0] * m
    tmp = 1
    for i in range(m - 1, -1, -1):
        d[i] = tmp
        tmp *= 2
    ##
    quo = (X[0] + Y[0]) % 2
    if quo == 0:
        d.append(1)
        m += 1
    modes = [''] * N
    for i in range(0, N):
        tmp_x = X[i]
        tmp_y = Y[i]
        if (tmp_x + tmp_y) % 2 != quo:
            print '-1'
            return 0
        for j in range(m):
            leng = d[j]
            if abs(tmp_x) > abs(tmp_y):
                if tmp_x > 0:
                    modes[i] += 'R'
                    tmp_x -= leng
                else:
                    modes[i] += 'L'
                    tmp_x += leng
            else:
                if tmp_y > 0:
                    modes[i] += 'U'
                    tmp_y -= leng
                else:
                    modes[i] += 'D'
                    tmp_y += leng

    print str(m)
    for i in range(m):
        print d[i],
    print
    for i in range(N):
        print modes[i]

if __name__ == '__main__':
    solve()


Measured memory_bytes: 2820
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
#define REP(i,n) for (int i = 1; i < (int)(n); i++)
template<class T> bool chmin(T &a, T b) {if(a>b) {a=b;return 1;}return 0;}
using namespace std;
using vint = vector<int>;
using vvint = vector<vector<int>>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<int,int>;
const ll inf = 1e18;

// union-find
vint par;
vint depth;
vll size;

void init (int n) {
    rep(i,n) {
        par[i] = i;
        depth[i] = 0;
        size[i] = 1;
    }
}

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

void unite(int x, int y) {
    x = find(x);
    y = find(y);
    if (x == y) return;
    if (depth[x] < depth[y]) {
        par[x] = y;
        size[y] += size[x];
    }
    else {
        par[y] = x;
        size[x] += size[y];
        if (depth[x] == depth[y]) {
            depth[x]++;
        }
    }
}

bool same(int x, int y) {return find(x) == find(y);}

int main() {
    ll n, m;
    cin >> n >> m;
    vint a(m), b(m);
    rep(i,m) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        a[i] = x; b[i] = y;
    }
    par.resize(n);
    depth.resize(n);
    size.resize(n);
    init(n);
    ll sum = n*(n-1)/2;
    vll ans(m+1);
    for (int i = m; i >= 1; i--) {
        if (i == m || same(a[i],b[i])) {ans[i] = sum; continue;}
        sum -= size[find(a[i])]*size[find(b[i])];
        ans[i] = sum;
        unite(a[i],b[i]);
    }
    REP(i,m+1) cout << ans[i] << endl;
}

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

namespace ABC114C
{
    public class Judge753
    {
        long GivenMaxNumber;
        public Judge753(long x)
        {
            GivenMaxNumber = x;
        }

        public int Judge(string GivenNumber)
        {
            var ret = 0;
            if (long.Parse(GivenNumber) > GivenMaxNumber)
            {
                return 0;
            }
            var temp = GivenNumber.Skip(1).Distinct().OrderBy(x => x).ToArray();
            if (temp.Count() == 3 && temp[0] == '3' && temp[1] == '5' && temp[2] == '7')
            {
                ret = 1;
            }
            ret += Judge(GivenNumber + "3");
            ret += Judge(GivenNumber + "5");
            ret += Judge(GivenNumber + "7");
            return ret;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            var givenN = int.Parse(Console.ReadLine());
            Judge753 judge = new Judge753(givenN);
            var ans = judge.Judge("0");
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 17480
S = input()

l = len(S)
S_list = list(map(int, S))

ans = 0

for i in range(l):
    num = int(S_list[-i-1])

    for j in range(i+1):
        ans += num * (10 ** (j)) * (2 ** (max(l-1-j-1, l-1-i)))

print(ans)


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

int main () {
    int a,b,c,d;
    cin >> a >> b >> c >> d;

    string result;
    while (true) {
        c -= b;
        if (c <= 0) {
            result = "Yes";
            break;
        }
        a -= d;
        if (a <= 0) {
            result = "No";
            break;
        }
    }
    cout << result << endl;
}

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

const int MAX_N = (int)1e5 + 5;
int cnt[MAX_N];
const ll MOD = (int)1e9 + 7LL;

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

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

  bool ok = true;
  if (N % 2 != 0) {
    if (cnt[0] != 1) ok = false;
    for (int i = 2; i < N; i += 2) {
      if (cnt[i] != 2) ok = false;
    }
  } else {
    for (int i = 1; i < N; i += 2) {
      if (cnt[i] != 2) ok = false;
    }
  }

  ll res = 0LL;
  if (ok) {
    res = 1LL;
    for (int i = 0; i < N / 2; ++i) {
      res = (res * 2LL) % MOD;
    }
  }
  cout << res << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  double rev = 0.0;
  rep(i, n){
    int a;
    cin >> a;
    rev += 1.0 / a;
  }
  cout << 1.0 / rev << endl;
  
  return 0;
}

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

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

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<pair<T, T>>& vp) {
	for (int i = 0; i < vp.size(); ++i) {
		s << "(" << vp[i].first << "," << vp[i].second << ")" << ( i+1 == vp.size() ? "" : ",\t" );
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code
int main(int argc, char const* argv[])
{
	int a,b,c,d;
	cin >> a >> b >> c >> d;
	if (a != c) {
		cout << 1 << endl;
	} else {
		cout << 0 << endl;
	}

	return 0;
}



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

#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()

typedef long long ll;

const char nl = '\n' ;
const ll MOD = 1e9 + 7;


int main()
{
   ios_base::sync_with_stdio(0); cin.tie(0);
   int a, b;
   string s;
   cin >> a >> b >> s;
   if(a+b+1 != s.size() || s[a] != '-')
   {
      cout << "No" << nl;
      return 0;
   }
   for(int i = 0; i < s.size(); i++)
   {
      if(i == a) continue;
      if(s[i] < '0' || s[i] > '9')
      {
         cout << "No" << nl;
         return 0;
      }
   }
   cout << "Yes" << nl;
   return 0;
   return 0;
}


Measured memory_bytes: 3676
#include <iostream>
#include <vector>
#include <string>


using namespace std;

int main(){
    string S;
    cin >> S;

    int S_size = S.length();

    int count_A = 0; //0101010...
    int count_B = 0; //10101010...
    for(int i = 0; i < S_size; i += 2){
        if (S[i] == '0'){
            count_B += 1;
        }
        else
        {
            count_A += 1;
        }
    }
    for(int i = 1; i < S_size; i += 2){
        if (S[i] == '0'){
            count_A += 1;
        }
        else
        {
            count_B += 1;
        }
    }

    int count;

    if (count_A < count_B){
        count = count_A;
    }else
    {
        count = count_B;
    }
    
    cout << count << endl;
}


Measured memory_bytes: 512