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

int Ans=9999999;

bool check2(LL val)
{
	char A[50],B[50];
	sprintf(A,"%lld",val);
	sprintf(B,"%d",Ans);

	int i,n=min(strlen(A),strlen(B));
	bool flag;
	for (i=0;i<n;i++)
	{
		if (A[i]<B[i]) {flag=1; break;}
		if (A[i]>B[i]) {flag=0; break;}
	}
	if (i==n) flag=strlen(A)<=strlen(B);

	printf("? %lld : %c %d %d\n",val,flag^(val<=Ans)?'N':'Y',flag,val<=Ans);

	return !(flag^(val<=Ans));
}

bool check(LL val)
{
	char c;
	printf("? %lld\n",val); fflush(stdout);
	c=getchar();
	while (c!='Y'&&c!='N') c=getchar();
	return c=='Y';
}

bool ten(int val)
{
	if (val==1) return 1;
	return (val%10==0)&&ten(val/10);
}

bool pass(int val)
{
	if (val==1) return 1;
	if (val==1000000000) return 0;
	if (ten(val)) val--;
	return check(val)^check(val*1000000000ll-1ll);
}

int main()
{
#ifdef h10
	freopen("E.in","r",stdin);
	freopen("E.out","w",stdout);
#endif
	if (check(1000000000000000ll))
	{
		LL val=1,checknum=5;
		while (val<=1000000000ll)
		{
			if (check(checknum)) {printf("! %lld\n",val); return 0;}
			val*=10;
			checknum*=10;
			checknum+=5;
		}
	}

	int i,v1=1,v2=9,L,R,mid;

	for (i=1;i<=9;i++)
	{
		if (check(v1)&&check(v2)) L=v1,R=v2;
		v1=v1*10;
		v2=v2*10+9;
	}

	while (L<=R)
	{
		mid=(L+R)>>1;
		if (check(mid*1000ll))
			R=mid-1;
		else
			L=mid+1;
	}
	printf("! %d\n",L);
}


Measured memory_bytes: 668
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define watch(x) cout<<(#x)<<"="<<(x)<<'\n'
#define mset(d,val) memset(d,val,sizeof(d))
#define setp(x) cout<<fixed<<setprecision(x)
#define forn(i,a,b) for(int i=a;i<b;i++)
#define fore(i,a,b) for(int i=a;i<=b;i++)
#define pb push_back
#define F first
#define S second
#define INF ll(1e18)
#define MOD 998244353
#define pqueue priority_queue
#define fbo find_by_order
#define ook order_of_key
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef long double ld;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

#define MAXN 100005

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	int n,m; cin>>n>>m;
	ll a[n];
	ll sum=0;
	forn(i,0,n){
		cin>>a[i]; sum+=a[i];
	}
	
	sort(a,a+n, greater<ll>());
	
	int cnt=0;
	forn(i,0,n){
		if(a[i]<ceil(sum*1.0L/(4*m))) break;
		cnt++;
	}
	
	if(cnt>=m) cout<<"Yes\n";
	else cout<<"No\n";
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<cstring>

using namespace std;

#ifdef LDEBUG
#define debug(x) cout << #x << ":" << x << endl
#else
#define debug(...)
#endif

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

typedef unsigned long long u64;
typedef long long i64;

int n;
int a[100005];

int l[100005];
int r[100005];

int gcd(int a, int b) {
        if ( a < b ) swap(a,b);

        if (a % b == 0 ) return b;

        return gcd(b, a % b);
}

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

        cin >> n;
        REP(i, n)
                cin >> a[i];

        l[0] = a[0];
        REP(i,n) {
                if (i==0) continue;
                l[i] = gcd(l[i-1], a[i]);
        }

        r[n-1] = a[n-1];
        REP(i,n) {
                if (i==0) continue;
                r[n-1 - i] = gcd(r[n-1 -i+1], a[n-1 -i]);
        }

        int k = 0;
        REP(i,n) {
                if (i == 0) {
                        k = max(k, r[1]);
                        continue;
                }
                if (i == n-1) {
                        k = max(k, l[n-2]);
                        continue;
                }
                k = max(k,gcd(l[i-1], r[i+1]));
        }

        cout << k << endl;

        return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;

   class Main{
      public static void main(String args[]){
         Scanner sc =new Scanner(System.in);
        
         int  r  =sc.nextInt();
         int  c  =sc.nextInt();
         int[][]x=new int[r][c];
         int  g  =0;
         
         for(int i=0;i<r;i++){
            for(int j=0;j<c;j++) {
               x[i][j]=sc.nextInt();
            }
         }
         
         for(int i=0;i<r;i++){
            int gr =0;
            for(int j=0;j<c;j++){
               System.out.print(x[i][j]+" ");
               gr +=x[i][j];
               g  +=x[i][j];
            }
            System.out.println(gr);
         }
         
         for(int j=0;j<c;j++){
            int gc=0;
            for(int i=0;i<r;i++){
               gc +=x[i][j];
            }
            System.out.print(gc+ " ");
         }
         System.out.println(g);
      }
   }



Measured memory_bytes: 41448
def gp(u,parent):
	if parent[u] != u: parent[u] = gp(parent[u], parent)
	return parent[u] 
n,m = map(int, raw_input().split())
parent = {i:i for i in range(1,n+1)}
size = {i:1 for i in range(1,n+1)}
for _ in range(m):
	u,v = map(int, raw_input().split())
	pu,pv = gp(u,parent), gp(v,parent)
	if pu != pv:
		parent[pv] = pu
		size[pu] += size[pv]
print max(size.values())


Measured memory_bytes: 114724
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    private static boolean debug = false;
    private static boolean elapsed = true;

    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);

    private int N;
    private int K;
    private int[] a;

    private void solve(Scanner sc) {
        N = sc.nextInt();
        K = sc.nextInt();
        a = new int[N];
        long sum = 0;
        for (int i = 0; i < N; ++i) {
            a[i] = sc.nextInt();
            sum += a[i];
        }

        if (sum < K) {
            _out.println(N);
            return;
        }

        Arrays.sort(a);

        long ans = 0;
        int left = 0;
        int right = N;
        while (left < right) {
            int c = (left + right) / 2;
            boolean flg = true;
            if (a[c] < K) {
                boolean[][] dp = new boolean[N][K];
                dp[0][0] = true;
                if (c != 0) {
                    dp[0][a[0]] = true;
                }
                for (int i = 1; i < N; ++i) {
                    dp[i][0] = true;
                    for (int j = 0; j < K; ++j) {
                        if (i != c && a[i] <= j) {
                            dp[i][j] = dp[i - 1][j] || dp[i - 1][j - a[i]];
                        } else {
                            dp[i][j] = dp[i - 1][j];
                        }
                    }
                }
                flg = false;
                for (int i = K - a[c]; i < K; ++i) {
                    if (dp[N - 1][i]) {
                        flg = true;
                        break;
                    }
                }
            }
            if (flg) {
                right = c;
            } else {
                ans = c + 1;
                left = c + 1;
            }
        }

        _out.println(ans);
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();

        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();

        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

Measured memory_bytes: 208300
A,B=map(int,input().split())

# 偶数Nに対して N xor N+1 は必ず1。
# （最下位1ビットだけが異なるから）

cnt1=0
restA=(A%2==1)
restB=(B%2==0)
cnt1=((B-(restB))-(A-(not restA)))//2

print((A*restA)^(cnt1%2)^(B*restB))

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

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

    int n,m;
    cin>>n>>m;

    int l=1,r=n;

    for(int i=0;i<m;i++)
    {
        int il,ir;
        cin>>il>>ir;

        l=max(l,il);
        r=min(r,ir);
    }

    cout<<max(0,r-l+1)<<"\n";

    return 0;
}


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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/21  Problem: ABC 060 D / Link: http://abc060.contest.atcoder.jp/tasks/abc060_d  ----- */


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

	LL N, W; cin >> N >> W;
	vector<LL> w(N), v(N);
	for (int i = 0; i < N; ++i) {
		cin >> w[i] >> v[i];
	}
	auto chmin = [](LL &a, const LL b) {
		a = min(a, b);
	};
	auto chmax = [](LL& a, const LL b) {
		a = max(a, b);
	};


	vector<VVL>dp(N + 1, VVL(N + 1, VL(3 * (N - 1) + 1, -LINF)));
	dp[0][0][0] = 0;
	FOR(i, 0, N) {
		FOR(k, 0, N) {
			FOR(add, 0, 3 * (N - 1) + 1) {
				if (dp[i][k][add] == -LINF)continue;
				int wi = w[i] - w.front();
				chmax(dp[i + 1][k][add], dp[i][k][add]);
				chmax(dp[i + 1][k + 1][add + wi], dp[i][k][add] + v[i]);
			}
		}
	}
	LL ans = 0;
	FOR(k, 0, N+1) {
		FOR(add, 0, 3 * (N - 1) + 1) {
			LL ws = w.front()*k + add;
			if(ws<=W)
			chmax(ans, dp[N][k][add]);
		}
	}

	cout << (ans) << "\n";

	return 0;
}


Measured memory_bytes: 24704
#include <iostream>

using namespace std;

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

    int Sn = 0;
    int n = N;
    while(n / 10)
    {
        Sn += (n % 10);
        n /= 10;
    }
    Sn += n;

    cout << (N % Sn ? "No" : "Yes") << endl;

    return 0;
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = INT_MAX / 2; const ll INF = LLONG_MAX / 2;
//template end



int main(){
    string s,t; cin>>s>>t;
    int n=s.size(),m=t.size();
    ll nxt[100010][26]; Fill(nxt,INF);
    rep(i,0,n)nxt[i][s[i]-'a']=0LL;
    rrep(i,2*n,0)rep(j,0,26){
        chmin(nxt[(i-1+n)%n][j],nxt[i%n][j]+1LL);
    }
    ll ans=0;
    rep(i,0,m){
        ll val=nxt[ans%n][t[i]-'a'];
        cerr<<val<<endl;
        if(val==INF){
            printf("-1");
            return 0;
        }
        ans+=val+1;
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 20864
#include <iostream>

using namespace std;

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

    int A,B,K,f=0;
    cin >> K >> A >> B;
    for (int i=A; i<=B; i++) {
        if (i%K==0) {
            cout << "OK\n";
            f=1;
            break;
        }
    }
    if (f==0) cout << "NG\n";
    return 0;
}


Measured memory_bytes: 3636
H,W = list(map(int,input().split()))
s = [list(map(int,input().split())) for i in range(H)]
data = []
cnt = 0
for i in range(H-1):
    for j in range(W):
        if s[i][j] % 2 != 0:
            cnt += 1
            s[i+1][j] += 1
            data.append([i+1,j+1,i+2,j+1])




for j in range(W-1):
    if s[H-1][j] % 2 != 0:
        cnt += 1
        s[H-1][j+1] += 1
        data.append([H,j+1,H,j+2])

print(cnt)

for i in data:
    print(i[0],i[1],i[2],i[3])

Measured memory_bytes: 31592
N,Q = map(int,input().split())
S = input()
l = [0] * Q
r = [0] * Q
a = 0
b = [0]
for i in range(Q):
    l[i],r[i] = map(int,input().split())

for i in range(N-1):
    
    if S[i] == 'A' and S[i+1] == 'C':

        a += 1
        b.append(a)

    else:

        b.append(a)

for i in range(Q):

    print(b[r[i]-1]-b[l[i]-1])

Measured memory_bytes: 14160
N = int(input())
a = [0]*(N+1)

for i in range(1, N+1):
    a[i] = int(input())

dp = [False]*(N+1)

ans = 0
ind = 1
while True:
    if ind == 2:
        print(ans)
        break
    else:
        if dp[ind]:
            print(-1)
            break
        else:
            dp[ind] = True
            ans += 1
            ind = a[ind]


Measured memory_bytes: 7668
#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define modn 1000000007

#define SZ 1005
using namespace std;
ll b[SZ], t[SZ], p[SZ], tota[SZ];
int n,m;
ll fn(int x, int y, int z)
{
    for(int i=0; i<n; i++) tota[i] = b[i]*x + p[i]*y + t[i]*z;
    sort(tota, tota+n, greater<ll>());
    return accumulate(tota, tota+m, 0LL);
}
int main()
{
    cin>>n>>m;
    for(int i=0; i<n; i++)
        cin>>b[i]>>t[i]>>p[i];
    if(m == 0)
    {
        cout<<0<<endl;
        return 0;
    }
    ll ans = -1;
    ans = max(ans, fn(-1, -1, -1));
    ans = max(ans, fn(-1, -1, 1));
    ans = max(ans, fn(-1, 1, -1));
    ans = max(ans, fn(-1, 1, 1));
    ans = max(ans, fn(1, -1, -1));
    ans = max(ans, fn(1, -1, 1));
    ans = max(ans, fn(1, 1, -1));
    ans = max(ans, fn(1, 1, 1));
    cout<<ans<<endl;
    return 0;
}


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

typedef long long int lli;
typedef unsigned long long int ulli;
typedef pair<int,int> pii;

#define ones(x) __builtin_popcount(x)
#define onesl(x) __builtin_popcountl(x)
#define onesll(x) __builtin_popcountll(x)

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define scn(n) scanf("%d",&n)
#define scnll(n) scanf("%lld",&n)
#define scn2(n,m) scanf("%d%d",&n,&m)
#define scn3(n,m,w) scanf("%d%d%d",&n,&m,&w)
#define scn2ll(n,m) scanf("%lld%lld",&n,&m)
#define atoz(v) v.begin(),v.end()
#define ratoz(v) v.rbegin(),v.rend()
#define Fill(a,v) memset(a,v,sizeof(a))
#define sz(v) v.size()
#define fi first
#define se second
#define inf 1e9
#define pi acos(-1.0)
#define sqr(x) x*x
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define ten(n) (int)1e##n
#define tenll(n) (lli)1e##n
#define mod 1000000007
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int Set(int N,int pos)
{
    return N=N | (1<<pos);
}
int reset(int N,int pos)
{
    return N = N & ~(1<<pos);
}
bool check(int N,int pos)
{
    return (bool)(N & (1<<pos));
}

///priority_queue< int, vector< int >, greater< int > > minHeap;

void mor(){cout<<"NO"; exit(0);}

#define N 100005

vector<pii>tree[N];
int color[N];


void dfs(int x, int p=-1 , lli sum = 0){
   // cout<<x<<" "<<color[x]<<" "<<endl;
    for(pii u : tree[x]){

        if(u.fi == p)continue;

        if((u.se+sum)%2==0) color[u.fi] = 1;
        dfs(u.fi,x , u.se+sum);
    }
}

int main()
{
    ///freopen("output.txt","w",stdout);
    ///freopen("input.txt","r",stdin);

    ///FastIO;
    int n;
    scn(n);

    for(int i=1; i<n; i++){
        int x,y,w;
        scn3(x,y,w);
        tree[x].pb({y,w});
        tree[y].pb({x,w});
    }
    color[1] = 1;
    dfs(1);

    for(int i=1; i<=n; i++)printf("%d\n",color[i]);

    return 0;
    ///return main();
}

///sin and cos expect input in radians not degrees. so use , sin(degrees * pi / 180)


Measured memory_bytes: 8320
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pll pair<ll,ll>
#define pb push_back
#define mp(x, y) make_pair((x), (y))
#define F first
#define S second
#define I insert
#define vll vector<ll>
#define vbl vector<bool>
#define vvll vector<vll>
#define vld vector<ld>
#define vb vector<bool>
#define vc vector<char>
#define vpll vector<pll>
#define all(x) (x).begin(), (x).end()

template<class T> ostream& operator<<(ostream &os, vector<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T> ostream& operator<<(ostream &os, set<T> V){
	os << "[ ";
	for(auto v  : V) os << v << " ";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, map<T , R> V){
	os << "[ ";
	for(auto v  : V) os << "(" << v.first << ":" << v.second << ")";
	return os << " ]";
}
template<class T , class R > ostream& operator<<(ostream &os, pair<T , R> V){
	return os << "(" << V.first << "," << V.second << ")";
}

#define cerr cout
#define TRACE
#ifdef TRACE
    #define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " : " << arg1 << endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " : " << arg1<<" | ";
        __f(comma+1, args...);
    }
    clock_t clk=clock();
    #define checktime() cout<<"\nTime Elapsed : "<<float(clock()-clk)/CLOCKS_PER_SEC<<endl
#else
    #define trace(...);
    #define checktime();
#endif

const ll Mod = 1e9 + 7;
// const ll Mod = 998244353;
const ll MAXN = 1e6;

void solve(){
    string s;cin>>s;
    if(s=="ABC") cout<<"ARC\n";
    else cout<<"ABC\n";
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout<<fixed<<setprecision(25);

    ll t=1;
    // cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
using namespace std;

int main(){
  int n,k;
  cin >> k>>n;
  k=min(0,k-10);
  cout << n-100*k << endl;
}



Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define sz(x) ((int)(x).size())
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i, N) cin >> L[i];
  sort(all(L));

  int ans = 0;
  rep(ia, N - 2) {
    repp(ib, ia + 1, N - 2) {
      int a = L[ia], b = L[ib];
      int wa = a + b, sa = b - a;
      auto iterR = lower_bound(all(L), wa);
      int posR = distance(L.begin(), iterR);
      auto iterL = upper_bound(all(L), sa);
      int posL = distance(L.begin(), iterL);
      chmax(posL, ib + 1);
      ans += posR - posL;
    }
  }
  cout << ans << endl;
  // rep(ia, N) {
  //   rep(ib, N) {
  //     if (ia == ib)
  //       continue;
  //     int a = L[ia], b = L[ib];
  //     int wa = a + b, sa = abs(a - b);

  //     auto iterR = lower_bound(all(L), wa);
  //     int posR = distance(L.begin(), iterR);
  //     auto iterL = upper_bound(all(L), sa);
  //     int posL = distance(L.begin(), iterL);

  //     int temp = posR - posL;
  //     if (posL <= ia && ia < posR)
  //       temp--;
  //     if (posL <= ib && ib < posR)
  //       temp--;
  //     ans += temp;
  //   }
  // }
  // ans /= 6;

  // cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC target("avx2")
#pragma GCC optimize("O3")

# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

inline void Input_Output () {
	//freopen(".in", "r", stdin);
   //freopen(".out", "w", stdout);
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 1e7 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
 
int n, m, k;
int cur;

int mult (int a, int b) {
	return (a * (ll)b) % mod;
}

int bpow (int a, int b) {
	int res = 1;
	while (b > 0) {
		if (b & 1) res =mult(res, a);
		a = mult(a, a);
		b /= 2;
	}
	return res;
}

ll f[N];

 main () {
   SpeedForce;
	cin >> n >> m;
	int k = abs(n - m);
	cur = -1;
	for (ll i = 0; i <= 1e7; i ++) {
		ll X = i * 3;
		ll Y = i * 3;

		if (n > m) X += k * 2, Y += k;
		else X += k, Y += k * 2;

		if (X == n && m == Y) {
			cur = i;
			break;
		}
	}       
	if (cur == -1) {
		cout << 0;
		exit(0);
	}
	
	int n = cur + cur + k;
	k += cur;
	f[0] = 1;
	for (int i = 1; i <= n; i ++) {
		f[i] = mult(f[i - 1], i);
	}
	ll res = f[n];
	res = mult(res, bpow(f[k], mod - 2));
	res = mult(res, bpow(f[n - k], mod - 2));

	cout << res;

   return Accepted;
}

// B...a

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

int main() {
  string a, b; cin >> a >> b;
  if( (a[0] == 'H'&& b[0] == 'H') || (a[0]=='D' && b[0] =='D') ) {
    cout << 'H' << endl;
  } else {
    cout << 'D' << endl;
  }

  return 0;
}


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

using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = (ll)(n) - 1; i >= 0; i--)
#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF (1LL << 62)

#define PI (acos(-1))
#define print(x) cout << x << endl
 
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 countDigit(ll n) { return floor(log10(n) + 1); } 
typedef pair <ll,ll> P;
static const ll dy[4] = {0,1,0,-1}, dx[4] = {1,0,-1,0};

template <typename T> 
ostream& operator<<(ostream& os, const vector<T>& v) 
{ 
    for (int i = 0; i < (int)v.size(); ++i) { 
        os << v[i]; 
        if (i != (int)v.size() - 1) 
            os << " "; 
    } 
    return os; 
} 

ll nCrModp(ll n, ll r, ll p)
{
    ll C[r+1];
    memset(C, 0, sizeof(C));

    C[0] = 1;

    for (ll i = 1; i <= n; i++)
    {
        for (ll j = min(i, r); j > 0; j--)
            C[j] = (C[j] + C[j-1])%p;
    }
    return C[r];
}

int main()
{
    ll H,W;
    cin >> H >> W;
    vector<vector<bool>> mize(H, vector<bool>(W, false));
    
    rep(i,H) {
        string tmp;
        cin >> tmp;
        rep(j, W) {
            if (tmp[j] == '.') {
                mize[i][j] = true;
            }
        }
    }

    ll ans = 0;
    rep(i, H) {
        rep(j, W) {
            if (mize[i][j]) {
                vector<vector<bool>> tmp(H, vector<bool>(W, false));
                rep(i, H) {
                    rep(j, W) {
                        tmp[i][j] = mize[i][j];
                    }
                }
                vector<vector<ll>> mat(H, vector<ll>(W, INF));
                queue<P> que;
                que.push(P(i, j));
                mat[i][j] = 0;
                while(!que.empty()) {
                    P cur = que.front();
                    que.pop();
                    rep(k, 4) {
                        ll x = cur.first + dx[k];
                        ll y = cur.second + dy[k];
                        if (x >= 0 && y >= 0 && x < H && y < W && mize[x][y] && mat[x][y] == INF) {
                            que.push(P(x,y));
                            mat[x][y] = mat[cur.first][cur.second] + 1;
                        }
                    }
                }
                ll ma = 0;
                rep(s, H) {
                    rep(t, W) {
                        if (mat[s][t] != INF) {
                            ma = max(mat[s][t], ma);
                        }
                    }
                }
                ans = max(ans, ma);
            }
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 60;

long long n, k;
long long cnt[N];
long long ans;
long long memo[N][2];

long long f(int bit, int t) {
  if (bit < 0) return 0;
  if (memo[bit][t] != -1) return memo[bit][t];
  if (t == 0) {
    if (!(k & (1ll << bit))) return memo[bit][t] = (1ll << bit) * (cnt[bit]) + f(bit - 1, t);
    long long ans = (1ll << bit) * (cnt[bit]) + f(bit - 1, 1);
    ans = max(ans, (1ll << bit) * (n - cnt[bit]) + f(bit - 1, t));
    return memo[bit][t] = ans;
  } else {
    return memo[bit][t] = (1ll << bit) * max(cnt[bit], n - cnt[bit]) + f(bit - 1, t);
  }
}

int main() {
  cin >> n >> k;
  memset(memo, -1, sizeof memo);
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    for (int j = 0; j < N; j++) {
      cnt[j] += ((x & (1ll << j)) > 0);
    }
  }
  cout << f(N - 1, 0) << endl;
  return 0;
}


Measured memory_bytes: 384
num = int(input())

tarou = 0
hanako = 0
for i in range(num):
  s = input().rstrip().split(' ')
  taroucard = str(s[0])
  hanakocard = str(s[1])
  if taroucard > hanakocard:
    tarou += 3
  elif taroucard == hanakocard:
    tarou += 1
    hanako += 1
  elif taroucard < hanakocard:
    hanako += 3
print(str(tarou) + " " + str(hanako))


Measured memory_bytes: 5600
def EW(x, char):
    re = 0
    if x == char:
        re = 1
    return re
        
def main(num, string):
    e = list(map(lambda x:EW(x, 'E'), string))
    w = list(map(lambda x:EW(x, 'W'), string))
    
    for i in range(1, num):
        w[i] = w[i-1] + w[i]
        e[num - i -1] = e[num - i  - 1] + e[num - i]
    
    w.insert(0, 0)
    w.insert(num+1,0)
    e.insert(0, 0)
    e.insert(num+1, 0)
    cnt = num
    for i in range(1, num + 1):
        tmp = w[i-1] + e[ i + 1]
        if tmp < cnt:
            cnt = tmp
    return cnt

num = int(input())
string = input()
 
print(main(num, string))

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int N, K;
    cin >> N >> K;
    vector<double> P(N);
    rep(i, N) {
        double p;
        cin >> p;
        P[i] = (p + 1) / 2.0;
    }

    vector<double> S(N + 1);
    rep(i, N) S[i + 1] = S[i] + P[i];
    double ans = 0;
    rep(i, N) {
        int j = min(N, i + K);
        chmax(ans, S[j] - S[i]);
    }

    printf("%.12f\n", ans);
}


Measured memory_bytes: 3328
n = int(input())
s = input()

sf = []
mod = 1000000007

if(s[0]=='W'):
    sf.append(999999999)
else:
    sf.append(0)
for i in range(2*n-1):
    if(s[i]==s[i+1]):
        sf.append(1-sf[-1])
    else:
        sf.append(sf[-1])

if(sum(sf)==n):
    count=0
    ans=1
    for i in range(2*n):
        if(sf[2*n-1-i]==1):
            count+=1
        else:
            ans= (ans*count)%mod
            count-=1
    for i in range(n):
        ans = (ans*(i+1))%mod
    print(ans)
else:
    print(0)

Measured memory_bytes: 53472
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;

namespace SolutionCS
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int K = int.Parse(s[1]);
            int Q = int.Parse(s[2]);

            int[] v = new int[N];

            for (int i = 0; i < Q; i++)
            {
                int k = int.Parse(Console.ReadLine());
                v[k-1]++;
            }

            for (int i = 0; i < N ; i++)
            {
                if (K - Q + v[i] > 0)
                {
                    Console.WriteLine("Yes");
                }
                else
                {
                    Console.WriteLine("No");
                }
            }
        }
    }
}



Measured memory_bytes: 17600
while True:
    num = int(input())
    if num == 0:
        break
    G = set()
    for _ in range(num):
        i, j = [int(x) for x in input().split()]
        G.add((i,j))
    m = int(input())
    x, y = 10, 10
    if (x,y) in G:
        G.remove((x,y))

    for _ in range(m):
        d, c = input().split()
        c = int(c)
        for i in range(c):
            if d == "N":
                y += 1
            elif d == "S":
                y -= 1
            elif d== "E":
                x += 1
            else:
                x -= 1
            if (x,y) in G:
                G.remove((x,y))
                
    if G:
        print("No")
    else:
        print("Yes")






Measured memory_bytes: 5624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}



int main() {
    string S;
	cin >> S;
	int N = S.length();
	
	ll ans = 0;
	rep(bit, 1 << (N - 1)) {
		ll sm = 0;
		ll a = S[0] - '0';
		rep(i, N - 1) {
			if (bit & (1 << i)) {
				sm += a;
				a = 0;
			}
			a = a * 10 + S[i + 1] - '0';
		}
		sm += a;
		ans += sm;
	}
	cout << ans << endl;
}

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

using ll = long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

#define REP(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define FORR(i,a,b) for(int i=(b)-1; i>=(a); i--)

#define ALL(v) (v).begin(), (v).end()
#define CHMAX(a,b) a=max(a,b)
#define CHMIN(a,b) a=min(a,b)

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl

int n,m;
int h[252];
pair<int,pii> es[252*252];
int ids[252];

int dat[252];
void init(){
    fill(dat,dat+252,-1);
}
int root(int x){
    return dat[x]<0 ? x : dat[x]=root(dat[x]);
}
bool unite(int a, int b){
    a=root(a);b=root(b);
    if(a==b)return false;
    dat[a] += dat[b];
    dat[b] = a;
    return true;
}

int main(){
    while(true){
        scanf("%d%d",&n,&m);
        if(n+m==0)break;
        REP(i,n)scanf("%d",h+i);
        REP(i,m){
            int a,b,c;
            scanf("%d%d%d",&a,&b,&c);
            --a;--b;
            es[i] = make_pair(c,pii(a,b));
        }
        REP(i,n)ids[i] = i;
        sort(ids,ids+n,[&](int i,int j){return h[i]<h[j];});
        int t = -1;
        REP(i,n+1){
            int tt = i==0 ? 0 : h[ids[i-1]];
            int z = 0;
            REP(i,n)if(h[i]>tt)z=i;
            int cnt = 0;
            REP(i,n)if(h[i]>tt)cnt++;
            init();
            REP(i,m){
                int a = es[i].second.first;
                int b = es[i].second.second;
                if(h[a]<=tt || h[b]<=tt)continue;
                unite(a,b);
            }
            if(-dat[root(z)]==cnt){
                t = tt;
            }else{
                break;
            }
        }
        if(t==-1){
            puts("0");
            continue;
        }
        REP(i,n)if(h[i]>t)h[i]=t+1;
        sort(es,es+m,[&](pair<int,pii> a, pair<int,pii> b){
            int ta = min(h[a.second.first],h[a.second.second]);
            int tb = min(h[b.second.first],h[b.second.second]);
            if(ta != tb)return ta > tb;
            return a.first < b.first;
        });
        init();
        int ans = 0;
        REP(i,m){
            if(unite(es[i].second.first, es[i].second.second)){
                ans += es[i].first;
            }
        }
        if(-dat[root(0)]!=n)ans=0;
        printf("%d\n",ans);
    }
    return 0;
}


Measured memory_bytes: 3512
#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>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n): d(n,-1) {}
  int root(int x) {
    if (d[x] < 0) return x;
    return d[x] = root(d[x]);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return root(x) == root(y);}
  int size(int x) { return -d[root(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    deg[a]++;
    deg[b]++;
    uf.unite(a,b);
  }
  rep(i,k) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,n) {
    int ans = uf.size(i)-1-deg[i];
    for (int u : to[i]) {
      if (uf.same(i,u)) --ans;
    }
    printf("%d%c", ans, i==n-1?'\n':' ');
  }
  return 0;
}


Measured memory_bytes: 9236
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stdio.h>
#include<deque>
#include<map>
#include<queue>
#include<cmath>

typedef long long ll;

#define debug(x) cout << #x << '=' << x << endl;
#define debug_arr(a, n) for(ll i = 0; i < n; i++)cout << a[i] << ' '
#define inf 100000000000
#define loop(i,n) for(ll i = 0; i < n; i++)
#define graph vector<vector<ll>>
#define P pair<ll,ll>

using namespace std;

int l[2000][2000],r[2000][2000],a[2000][2000],u[2000][2000];
bool isWall[2000][2000];

int main(){
    int h,w;
    char tmp;

    cin >> h >> w;

    scanf("%c",&tmp);
    loop(i,h){
        loop(j,w){
            scanf("%c",&tmp);
            if(tmp == '.'){
                isWall[i][j] = false;
            }else{
                isWall[i][j] = true;
            }
        }
        scanf("%c",&tmp);
    }

    loop(i,h){
        loop(j,w){
            if(isWall[i][j]){
                l[i][j] = 0;
                a[i][j] = 0;
            }
            else{
                if(j != 0){
                    l[i][j] = l[i][j-1] + 1;
                }else{
                    l[i][0] = 1;
                }
                if(i != 0){
                    a[i][j] = a[i-1][j] + 1;
                }else{
                    a[0][j] = 1;
                }
            }
        }
    }

    for(int i = h-1; i >= 0; i--){
        for(int j = w-1; j >= 0; j--){
            if(isWall[i][j]){
                r[i][j] = 0;
                u[i][j] = 0;
            }
            else{
                if(j != w-1){
                    r[i][j] = r[i][j+1] + 1;
                }else{
                    r[i][w-1] = 1;
                }
                if(i != h-1){
                    u[i][j] = u[i+1][j] + 1;
                }else{
                    u[i][j] = 1;
                }
            }
        }
    }

    int result = 0, score;
    loop(i,h){
        loop(j,w){
            score = l[i][j] + r[i][j] + a[i][j] + u[i][j];
            result = max(score, result);
        }
    }

    cout << result - 3 << endl;
    return 0;
}

Measured memory_bytes: 66688
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define pb push_back
#define mp make_pair
#define in insert
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define mod 1000000007
#define sz(v) (int)(v.size())
#define all(x) x.begin(), x.end()
#define prec fixed << setprecision(12)
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define test int t; cin >> t; while(t--)

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef set<int> si;
typedef map<int, int> mii;
typedef vector<pii> vpi;

void solve() {
	int n;
	cin >> n;
	map<string, int> mp;
	rep(i, 1, n) {
		string s;
		cin >> s;
		mp[s]++;
	}
	cout << "AC x " << mp["AC"] << "\n";
	cout << "WA x " << mp["WA"] << "\n";
	cout << "TLE x " << mp["TLE"] << "\n";
	cout << "RE x " << mp["RE"] << "\n";
}

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


#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	// test
	solve();

	return 0;
}

Measured memory_bytes: 3668
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int w = sc.nextInt();
		int d = sc.nextInt();
		List<Pair> list = new ArrayList<>();
		for(int i = 1; i < h + 1; i++) {
			for(int j = 1; j < w + 1; j++) {
				list.add(new Pair(sc.nextInt(), j, i));
			}
		}
		list.sort(Comparator.comparing(Pair::getNum));
		int[] x = new int[h * w + 1];
		int[] y = new int[h * w + 1];
		int[] sum = new int[h * w + 1];
		for(int i = 1; i < h * w + 1; i++) {
			x[i] = list.get(i - 1).getX();
			y[i] = list.get(i - 1).getY();
			if(i - d > 0) {
				sum[i] = sum[i - d] + Math.abs(x[i] - x[i - d]) + Math.abs(y[i] - y[i - d]);
			} else {
				sum[i] = 0;
			}
		}
		int q = sc.nextInt();
		for(int i = 0; i < q; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			int ans = sum[r] - sum[l];
			System.out.println(ans);
		}
	}

}

class Pair {
	private int x;
	private int y;
	private int num;

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

	public int getNum() {
		return num;
	}

	public void setNum(int num) {
		this.num = num;
	}

	public int getX() {
		return x;
	}

	public void setX(int x) {
		this.x = x;
	}

	public int getY() {
		return y;
	}

	public void setY(int y) {
		this.y = y;
	}

}

Measured memory_bytes: 107368
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
#define inf 1000000000
const int maxn = 1e5 + 5;
vector<int> G[maxn];
int l[maxn],r[maxn];
int id[maxn];
bool flag;
void solve(int v = 0,int p = -1)
{
	l[v] = -inf - 1;
	r[v] = inf + 1;
	if(id[v] != -1)
	{
		l[v] = r[v] = id[v];
	}
	for(int i = 0;i < G[v].size(); ++i)
	{
		int to = G[v][i];
		if(to != p)
		{
			solve(to,v);
			if(l[to] < -inf / 2)
			{
				continue;
			}
			if(l[v] < -inf / 2)
			{
				l[v] = l[to] - 1;
				r[v] = r[to] + 1;
			}
			else
			{
				if(abs(l[to]) % 2 == abs(l[v]) % 2)
				{
					flag = 0;
					return;
				}
				l[v] = max(l[v],l[to] - 1);
				r[v] = min(r[v],r[to] + 1);
			}
		}
	}
	if(l[v] > r[v])
	{
		flag = 0;
	}
}
void make(int v = 0,int p = -1)
{
	if(v == 0 && id[v] == -1)
	{
		id[v] = l[v];
	}
	for(int i = 0;i < G[v].size(); ++i)
	{
		int to = G[v][i];
		if(to != p)
		{
			if(id[to] == -1)
			{
				if(l[to] <= id[v] - 1
					&& id[v] - 1 <= r[to])
				{
					id[to] = id[v] - 1;
				}
				else
				{
					id[to] = id[v] + 1;
				}
			}
			make(to,v);
		}
	}
}
int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	for(int i = 0;i < n - 1; ++i)
	{
		int a,b;
		scanf("%d%d",&a,&b);
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	memset(id,-1,sizeof(id));
	int k;
	cin>>k;
	while(k--)
	{
		int v,p;
		scanf("%d%d",&v,&p);
		v--;
		id[v] = p;
	}
	flag = 1;
	solve();
	if(!flag)
	{
		printf("No\n");
		return 0;
	}
	make();
	printf("Yes\n");
	for(int i = 0;i < n; ++i)
	{
		printf("%d\n",id[i]);
	}
	return 0;
}

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

int main(){
  int a,b,d;
  int n;

  while(cin >> a >> b >> n){
    int sum = 0;
    a *= 10;

    for(int i = 0 ; i < n ; i++){
      sum += (a / b) % 10;
      a %= b;
      a *= 10;
    }

    cout << sum << endl;
  }

  return 0;
}

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

int main() {
	int a,b,c,d;
  	cin>>a>>b>>c;
   if(a!=b&&b!=c&&a!=c)
  cout<<3<<endl;
  else if(a==b&&b==c)
    cout<<1<<endl;
  else
    cout<<2<<endl;

}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int L;
  int n,e=0;
  scanf("%d",&L);

  for(n=0;L>=2<<n;n++)
    if(L&1<<n)
      e++;

  printf("%d %d\n",n+1,e+2*n);
	
  e=0;
  for(int i=0;L>=2<<i;i++){
    printf("%d %d %d\n",i+1,i+2,0);
    printf("%d %d %d\n",i+1,i+2,1<<i);
    if(L&1<<i){
      printf("%d %d %d\n",i+1,n+1,(1<<n)+((1<<i)-1)&L);
      //      printf("%d %d %d\n",i+1,n+1,(1<<n)+e);
      e+=1<<i;
    }
  }
}


Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int x = sc.nextInt();
        ArrayList<Integer> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            list.add(sc.nextInt());
        }
        int min = Collections.min(list);
        Collections.sort(list);
        int tmp = x;
        for (int i = 0; i < n; i++) {
            tmp -= list.get(i);
        }
        int ans = n;
        while(true) {
            if(tmp < 0) {
                System.out.println(ans - 1);
                return;
            } else {
                tmp -= min;
                ans++;
            }
        }
    }
}

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

using namespace std;


string S;
int len;


int main()
{

	vector<int> ans;

	cin >> S;
	len = S.length();
	ans = vector<int>(len,0);

	bool rl = true;
	
	int rc = 0, lc = 0;
	int li = -1;

	for (int i = 0; i < len + 1; i++) {
		if ( i==len || S.at(i) == 'R') {
			if (i!=len && li == -1) {
				rc++;
			}
			else {
				ans.at(li-1) = (rc + 1) / 2 + (lc) / 2;
				ans.at(li) = (rc) / 2 + (lc+1) / 2;

				rc = 1;
				lc = 0;
				li = -1;
			}

		}else{
			if (li != -1) {
				lc++;
			}
			else {
				li = i;
				lc++;
			}
		}
	}

	for (int i = 0; i < len; i++) {
		cout << ans.at(i);

		if (i < len - 1) {
			cout << " ";
		}
	}
	cout << endl;


	return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>

#define INF 100100100

using namespace std;

int main()
{
    int N;
    vector<int> t;
    vector<int> cumt;
    vector<int> v;
    t.push_back(0);
    cumt.push_back(0);
    cumt.push_back(0);
    v.push_back(0);
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        int ti;
        cin >> ti;
        ti *= 2;
        t.push_back(ti);
        cumt.push_back(cumt[i + 1] + ti);
    }
    for (int i = 0; i < N; i++)
    {
        int vi;
        cin >> vi;
        v.push_back(vi * 2);
    }
    t.push_back(0);
    v.push_back(0);
    cumt.push_back(*(cumt.end() - 1));

    int T = *(cumt.end() - 2);

    int vs = 0.0;
    int ve;
    int ans = 0;
    for (int i = 0; i < T; i++)
    {
        int minv = INF;
        for (int j = 0; j < N + 3; j++)
        {
            int limv;
            int curt = i + 1;
            if (curt <= cumt[j])
            {
                limv = v[j] + cumt[j] - curt;
            }
            else if (cumt[j] <= curt && curt <= cumt[j + 1])
            {
                limv = v[j];
            }
            else if (cumt[j + 1] <= curt)
            {
                limv = v[j] + curt - cumt[j + 1];
            }

            minv = min(minv, limv);
        }
        if (vs + 1 <= minv)
        {
            ve = vs + 1;
        }
        else if (vs == minv)
        {
            ve = vs;
        }
        else
        {
            ve = vs - 1;
        }
        ans += vs + ve;
        vs = ve;
    }

    cout << setprecision(15) << ans / 8.0 << endl;

    return 0;
}

Measured memory_bytes: 632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    int N; cin >> N;
    vector<int> A(N); for (auto& x : A) cin >> x;

    ll ans = 0;
    for (int i = 0; i < N; i++) {
        if ((A[i] > i) || (i != 0 && A[i] - A[i-1] >= 2)) {
            cout << -1 << endl;
            return 0;
        }
        if (A[i] == 0) continue;
        ans += (A[i] == A[i-1] + 1) ? 1 : A[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 1024
import java.io.InputStream;
import java.io.PrintStream;
import java.util.Scanner;

public class Main {
	InputStream in = System.in;
	PrintStream out = System.out;

	public void _main(String[] args) {
		Scanner sc = new Scanner(in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();


		out.println(Math.min(b/a, c));

		sc.close();

	}

	public static void main(String[] args) {
		new Main()._main(args);
	}

}


Measured memory_bytes: 23636
#include<iostream>
#include<algorithm>
#include<map>

using namespace std;

int y, x;

int ab(int x){
	return -x;
}

int calc(int x){
	int ret = 1e9 + 41;

	if(x < y){
		ret = min(ret, y - x);
	}
	if(x <= ab(y)){
		ret = min(ret, 1 + ab(y) - x);
	}
	if(-x <= y){
		ret = min(ret, 1 + y - (-x));
	}
	if(-x <= ab(y)){
		ret = min(ret, 2 + ab(y) - (-x));
	}

	return ret;
}

int main(){
	scanf("%d %d",&x,&y);
	printf("%d\n",calc(x));




	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c && a == c) {
        cout << 1 << endl;
    }
    else if (a == b || b == c || a == c) {
        cout << 2 << endl;
    }
    else {
        cout << 3 << endl;
    }
}

Measured memory_bytes: 256