akhauriyash/Code-Regression huggingface dataset:
from collections import Counter

def main(N):
    lst = []
    for x in range(1, 142):
        for y in range(1, 142):
            for z in range(1, 142):
                r = (x + y) ** 2 + (y + z) ** 2 + (z + x) ** 2
                if r <= 2 * 10 ** 4:
                    if r % 2 == 1:
                        print('奇数')
                    lst.append(r // 2)
                else:
                    break
    c = Counter(lst)
    st = set(lst)

    for n in range(1, N+1):
        if n in st:
            print(c[n])
        else:
            print(0)


if __name__ == '__main__':
    N = int(input())
    main(N)

Measured memory_bytes: 20292
#include <iostream>
#include <cstdio>
#include <cstring>
#include <climits>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <sstream>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

// namespace
using namespace std;
namespace mp = boost::multiprecision;

// types
using pii = pair<int, int>;
using ll = long long int;
using ld = long double;
using mpi = mp::cpp_int;
using mpf = mp::number<mp::cpp_dec_float<1024>>;

// consts
int MOD = 1000000007;  // https://qiita.com/drken/items/3b4fdf0a78e7a138cd9a


int main() {
    int n, m, t, s;
    cin >> n >> m;
    vector<vector<int>> v;
    for (int k = 0; k < m; ++k) {
        cin >> t;
        vector<int> v0;
        for (int i = 0; i < t; ++i) {
            cin >> s;
            v0.push_back(s - 1);
        }
        v.push_back(v0);
    }
    vector<int> p;
    for (int k = 0; k < m; ++k) {
        cin >> t;
        p.push_back(t);
    }

    int ans = 0;
    for (int bit = 0; bit < (1<<n); ++bit) {
        bool flag = true;
        for (int k = 0; k < m; ++k) {
            int c = 0;
            for (auto e: v[k]) if (bit & (1 << e)) ++c;
            if (c % 2 != p[k]) {
                flag = false;
                break;
            }
        }
        if (flag) ++ans;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <queue>
#include <numeric>
#include <climits>
#include <iterator>
#include <iomanip>
#include <bitset>
#include <functional>
using namespace std;
const constexpr int INF = 1e9;
//typedef std::pair<std::string,double> P;

long long N;
string s; 
bool dp[110][301];
void solve(){
    int cntp=0, cntg=0, maxp=0;
    for(int i=0; i<s.size(); ++i){
        if(s[i]=='g'){
            if(cntg>cntp){
                cntp++;
                maxp++;
            }else if(cntg==cntp){
                cntg++;
            }
        }else if(s[i]=='p'){
            if(cntg>cntp){
                cntp++;
            }else if(cntg==cntp){
                cntg++;
                maxp--;
            }
        }
    }
    cout << maxp << endl;
}
int main() {
    cin >> s;
    solve();
	return 0;
}

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

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define ALL(v) (v.begin(),v.end())
#define COUT(x) cout<<(x)<<"\n"

int main(){
    int n,m;
    cin >> n >> m;
    vector<ll> h;
    ll t;
    REP(i,n){
        cin >> t;
        h.push_back(t);
    }
    vector<bool> snuke(n,1);
    int a,b;
    REP(i,m){
        cin >> a >> b;
        if(h[a-1]>h[b-1])snuke[b-1]=0;
        else if(h[a-1]<h[b-1])snuke[a-1]=0;
        else{
            snuke[a-1]=0;
            snuke[b-1]=0;
        }
    }
    int count = 0;
    for(const int x:snuke){
        if(x==1)count++;
    }
    COUT(count);
    return 0;
}

Measured memory_bytes: 4320
#include <bits/stdc++.h>
using namespace std;
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;}

const long long INF = 1LL << 60;

int N; 
long long h[100010];
long long dp[100010];

int main(){
  cin >> N;
  for(int i = 0; i < N; i++) cin >> h[i];
  for(int i = 0; i < 100010; i++) dp[i] = INF;
  
  dp[0] = 0;
  
  for(int i = 1; i < N; i++){
    chmin(dp[i], dp[i-1] + abs(h[i] - h[i - 1]));
    if(i > 1){
      chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
    }
  }
  cout << dp[N - 1] << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <algorithm>

int main(void) {
    std::priority_queue<u_int> heights;

    for (u_int h, i = 0; i < 10; ++i) {
        std::cin >> h;
        heights.push(h);
    }

    for (u_int i = 0; i < 3; ++i) {
        std::cout << heights.top() << std::endl;
        heights.pop();
    }

    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int n;
	cin >> n;

	int l[300];
	for (int i = 0;i < n*2;i++){
		cin >> l[i];
	}

	sort(l,l+n*2);
	int ans = 0;

	for (int i = 0;i < n;i++){
		ans += l[i*2];
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> llP;

int main() {
  int n,X;
  cin>>n>>X;
  int x[n];
  for(int i=0;i<n;i++) cin>>x[i];
  int ans=abs(X-x[0]);
  for(int i=1;i<n;i++){
    int temp=abs(X-x[i]);
    while(temp%ans!=0){
      int a=temp;
      temp=ans;
      ans=a%ans;
    }
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll         = long long;
constexpr ll MOD = 1000000007;
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define REP2(i, x, n) for (ll i = x; i < (n); i++)
const long long INF = numeric_limits<long long>::max();
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() {
    ll A, B, C, X;
    cin >> A >> B >> C >> X;

    ll count = 0;
    for (ll a = 0; a <= A; ++a) {
        for (ll b = 0; b <= B; ++b) {
            ll x = X - (a * 500 + b * 100);
            if (x >= 0 && (x % 50) == 0 && x / 50 <= C) {
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 3600
#include<stdio.h>

int main()
{
    long long n, max1 = 0, max2 = 0, max1_index=-1, max2_index=-1, i, x;
    
    scanf("%lld", &n);
    for(i = 0; i<n; i++){
        scanf("%lld", &x);
        
        if(max1<=x){
            max2 = max1;
            max2_index = max1_index;
            
            max1 = x;
            max1_index = i;
        }
        else if (max2<=x){
            max2 = x;
            max2_index = i;
        }
        
    }
    
    for(i = 0; i<n; i++){
        if(i==max1_index) printf("%lld\n", max2);
        else printf("%lld\n", max1);
    }
    
    
    return 0;
}

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

int main() {
	int n, k,m;
	vector<int> v;
	cin >> n >> k;
	for (int i = 0; i < n; i++) { cin >> m; v.push_back(m); }
	sort(v.begin(), v.end());

	int ans = 0;
	for (int i = 0; i < k; i++) ans = ans + v[i];
		cout << ans << endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<math.h>
using namespace std;

int main(){
    int a, b, x;
    cin >> x >> a >> b;

    a = abs(x - a);
    b = abs(x - b);
    if(a < b){
        cout << "A" << endl;
    }else{
        cout << "B" << endl;
    }
}

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

typedef long long ll;
const int maxn=1e6+7;
const ll inf=1e18;
const int mod=1e9+7;
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define rep(i,n) for (int i=1;i<=(n);i++)
#define rep2(i,a,b) for (int i=(a);i<=(b);i++)

ll ret1 (ll h,ll w)
{
	if (!(h%3)||!(w%3)) return 0;
	else return min(h,w);
}

ll ret2(ll h,ll w)
{
	ll mn1=inf;
	for (int i=1;i<h;i++)
	{
		if (w%2==0&&abs((w/2)*(h-i)-i*w)<mn1) 
		mn1=abs((w/2)*(h-i)-i*w);
		else
		{
			ll a=(w/2)*(h-i),b=(w/2+1)*(h-i),c=i*w;
			//cout<<a<<' '<<b<<' '<<c<<endl;
			ll mn=min(a,min(b,c)),mx=max(a,max(b,c));
			if (mx-mn<mn1) mn1=mx-mn;
		}
	} 
	for (int i=1;i<w;i++)
	{
		if (h%2==0&&abs((h/2)*(w-i)-i*h)<mn1) 
		mn1=abs((h/2)*(w-i)-i*h);
		else
		{
			ll a=(h/2)*(w-i),b=(h/2+1)*(w-i),c=i*h;
			ll mn=min(a,min(b,c)),mx=max(a,max(b,c));
			if (mx-mn<mn1) mn1=mx-mn;
		}
	} 
	return mn1;
}

int main()
{
 	ios::sync_with_stdio(0); cin.tie(0);
 	ll h,w;
 	cin>>h>>w;
 	if (h==2&&w==2) cout<<1<<endl;
 	else
 	{
 		ll ans1=ret1(h,w),ans2=ret2(h,w);
 		//cout<<ans1<<' '<<ans2<<endl;
 		cout<<min(ans1,ans2)<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
# define N 1000000
int main(){
  int top = 1;
  int y, z, x;
  char s[100];
  int stack[N];
  
  while( scanf("%s",s) != EOF ){
    if ( s[0] == '+' ){
      top = top - 1;
      y = stack[top + 1];
      top = top - 1;
      z = stack[top + 1];
      top++;
      stack[top] = z + y ;
     
    } else if ( s[0] == '-' ){
      top = top - 1;
      y = stack[top + 1];
      top = top - 1;
      z = stack[top + 1];
      top++;
      stack[top] = z - y;
    } else if ( s[0] == '*' ){
      top = top - 1;
      y = stack[top + 1];
      top = top - 1;
      z = stack[top + 1];
      top++;
      stack[top] = z * y;
    } else {
      x = atoi(s);
      top++;
      stack[top] = x;
    }
  }

  printf("%d\n",stack[top]);
  return 0;
}

Measured memory_bytes: 556
import copy

MOD = 10 ** 9 + 7

def make_list(*args):
	r = [0] * args[-1]
	for n in args[len(args) - 2::-1]:
		r = [copy.deepcopy(r) for _ in range(n)]
	return r

N = int(input())

dp = make_list(N + 1, 5, 5, 5)
dp[0][0][0][0] = 1

# INIT = 0, A = 1, C = 2, G = 3, T = 4
for n in range(N):
	for i in range(5):
		for j in range(5):
			for k in range(5):
				for l in range(1, 5):
					# AGC
					if j == 1 and k == 3 and l == 2:
						continue
					# GAC
					if j == 3 and k == 1 and l == 2:
						continue
					# ACG
					if j == 1 and k == 2 and l == 3:
						continue
					# A*GC
					if i == 1 and k == 3 and l == 2:
						continue
					# AG*C
					if i == 1 and j == 3 and l == 2:
						continue
					dp[n + 1][j][k][l] += dp[n][i][j][k]
					dp[n + 1][j][k][l] %= MOD

r = 0
for i in range(1, 5):
	for j in range(1, 5):
		for k in range(1, 5):
			r += dp[N][i][j][k]
			r %= MOD

print(r)


Measured memory_bytes: 4028
#include<bits/stdc++.h>
using namespace std;
#define set_null(a,n) memset(a,0,sizeof(a))
#define pi acos(-1)
#define ll long long int
#define fr(a,b) for(int i=a;i<b;i++)

int main()
{
    int n;
    cin>>n;
    ll a[n+1];
    fr(0,n)
    {
        cin>>a[i];
    }
    sort(a,a+n);
    fr(0,n-1)
    {
        if(a[i]==a[i+1])
        {
            cout<<"NO\n";
            return 0;
        }
    }
    cout<<"YES\n";

    return 0;
}



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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int N; cin >> N;
    vector<int> A(N); REP(i,N) cin >> A[i];

    int ans = INF;
    REP(i,N-1){
        ans = min(ans, __gcd(A[i],A[i+1]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3744
def main():
    N, M = map(int, input().split())
    lis = []
    for i in range(N):
        lis.append(list(map(int, input().split())))
    # 最小のコスト順に買っていけばよい
    # 同じコストのときはどうするか
    lis.sort() # 一列目をソート，二列目を対応してくれる，同じ値のときは二列目が低い方を優先
    sum = 0
    count = 0
    flg = False
    for i in range(N):
        if (count+lis[i][1]<M) :
            sum = sum + lis[i][0]*lis[i][1]
            count = count + lis[i][1] # Bi全部
        elif (count+lis[i][1]==M):
            sum = sum + lis[i][0]*lis[i][1]
            count = count + lis[i][1] # Bi全部
            break
        else:
            for j in range(lis[i][1]):
                sum = sum + lis[i][0]
                count = count + 1
                if count==M:
                    flg = True
                    break
        if flg:
            break

    print(sum)
    # print(count)

main()

Measured memory_bytes: 27880
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999999
#define MOD 1000000007
#define fi first
#define sc second

using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef vector<llong> LV;

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


int main() {
	int n,t;cin >> n >> t;
    vector<P> F(n);REP(i,n) cin >> F[i].first >>F[i].second;
    int len = t+3001;
    LV dp(len,0),ndp(len,0);
    sort(F.begin(),F.end());
    REP(i,n){
        REPR(j,len-1){
            int be = j-F[i].fi;
            if((be>=0) && (be<t)){
                if((dp[be]+F[i].sc)>dp[j]) dp[j] = dp[be]+F[i].sc;
            }
            
        }
    }
    llong ans = -1;
    REP(i,len){
        ans = max(ans,dp[i]);
    }
    cout << ans  << endl;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
const int mod = 1000000007;
const int max_n = 200005;
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(){
    ll n;cin >> n;
    set<string> s;
    rep(i,n){
        string t;cin >> t;
        s.ins(t);
    }
    cout << s.size() <<endl;
}

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


int main() {
	int n;

	cin >> n;

	if (n % 2 == 0) {
		cout << ((n*(n - 1)) / 2) - (n / 2) << endl;
		for (int i = 1; i <= n - 1; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (i + j != n + 1) {
					cout << i << " " << j << endl;
				}
			}
		}
	}
	else {
		cout << ((n*(n - 1)) / 2) - ((n - 1) / 2) << endl;
		for (int i = 1; i <= n - 1; i++) {
			for (int j = i + 1; j <= n; j++) {
				if (i + j != n) {
					cout << i << " " << j << endl;
				}
			}
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
//	freopen("input.txt","r",stdin);
	int n;
	scanf("%d",&n);
	int flag=0;
	while(n){
		int x=n%10;
		n/=10;
		if(x==9){
			flag=1;
			break;
		}
	}
	if(flag) puts("Yes");
	else puts("No");
	return 0;
}

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

int main() {
  int r, g, b, num;
  cin >> r >> g >> b;
  num = 100*r + 10*g + b;

  if (num%4==0){
      cout << "YES" << endl;
  }
  else{
      cout << "NO" << endl;
  }

}

Measured memory_bytes: 256
// AtCoder Regular Contest 080 D - Grid Coloring
// 2018.1.12 bal4u

#include <stdio.h>

int map[101][102];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

int main()
{
	int H, W, N, a;
	int r, c, k;
	
	H = in(), W = in(), N = in();
	r = c = k = 0;
	while (N--) {
		a = in(), k++;
		while (a--) {
			map[r][c] = k;
			if (r & 1) { if (--c  < 0) r++, c =   0; }
			else       { if (++c == W) r++, c = W-1; }
		}
	}
	for (r = 0; r < H; r++) {
		printf("%d", map[r][0]);
		for (c = 1; c < W; c++) printf(" %d", map[r][c]);
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map (fun x -> int x)

let a, b, c = readIntArray() |> fun x -> (x.[0], x.[1], x.[2])
[a;b;c]
|> List.sort
|> fun x -> x.[0] + x.[1]
|> printfn "%d"

Measured memory_bytes: 14812
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define ll long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define rep(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define ffor(i,a,b) for(int i = a ; i <= b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
const int N = 1e6;
typedef pair <int, int> pi;
typedef std::vector<int> vi;
typedef std::vector<long long> VI;

/*bool isprime(int a) {
	if (a < 2) return false;
	for (int i = 2; i * i <= a; i++) {
		if (a % i == 0)
			return false;  // 0(n) or 0(n^2) Tell me in the comment section
	}
	retunn true;
}*/



int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	fastIO
	int a, b;
	cin >> a >> b;
	if (a < b) {
		for (int i = 0; i < b; i++) cout << a ;
	} else {
		for (int i = 0; i < a; i++) cout << b ;
	}
}

Measured memory_bytes: 3536
#include"bits/stdc++.h"

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;
typedef priority_queue<int> PQ_DESC;
typedef priority_queue<int, vector<int>, greater<int>> PQ_ASC;
typedef priority_queue<PII> PQ_DESC_PII;
typedef priority_queue<PII, vector<PII>, greater<PII>> PQ_ASC_PII;

#define ALL(c) (c).begin(),(c).end()
#define PB push_back
#define MP make_pair
#define SORT_ASC(c) sort(ALL(c))
#define SORT_DESC(c) sort(ALL(c), greater<typeof(*((c).begin()))>())
#define SIZE(a) int((a).size())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int LARGE_INT = 1e9+100;
const int INF = 2e9+100;
const LL INF_LL = (LL)INF * 300 * 300;
const int MOD = 1e9+7;

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

LL modpow(LL a, LL n) {
    LL res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

LL modinv(LL a) {
    LL b = MOD, u = 1, v = 0;
    while (b) {
        LL t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= MOD;
    if (u < 0) u += MOD;
    return u;
}

LL moddev(LL a, LL b){
	return a * modinv(b) % MOD;
}

void Main()
{
    int n,d,a;
    cin >> n >> d >> a;

    VPII x(n);

    VI r(n);

    REP(i,n){
        cin >> x[i].first >> x[i].second;
        x[i].second = ceil(x[i].second / (double)a);
    }
    SORT_ASC(x);

    VI vt(n);
    REP(i,n){
        vt[i] = x[i].first;
    }

    REP(i,n){
        auto iter = lower_bound(ALL(vt), vt[i]-d-d);
        r[i] = std::distance(vt.begin(), iter);
        //cerr<<r[i] << " ";
    }

    VI m(n,0);
    LL result = 0;

    int idx = 0;
    int sum = 0;
    REP(i,n){
        while(idx != r[i]){
            sum -= m[idx];
            idx++;
        }
        m[i] = max(x[i].second - sum , 0);
        sum += m[i];
        
        result += m[i];
    }

    cout << result << endl;

    

	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

Measured memory_bytes: 4224
#include<stdio.h>
#define MAX 100000
#define SENTINEL 2000000000

struct Card{
    char suit;
    int value;
};

struct Card L[MAX/2+2],R[MAX/2+2];

void merge(struct Card A[], int n, int left, int mid, int right){
    int i,j,k;
    int n1 = mid-left;
    int n2 = right-mid;
    for(i=0;i<n1;i++) L[i] = A[left+i];
    for(i=0;i<n2;i++) R[i] = A[mid+i];
    L[n1].value = R[n2].value=SENTINEL;
    i=j=0;
    for(k=left;k<right;k++){
        if(L[i].value<=R[j].value){
            A[k] = L[i++];
        }else{
            A[k] = R[j++];
        }
    }
}

void mergeSort(struct Card A[],int n, int left, int right){
    int mid;
    if(left+1<right){
        mid=(left+right)/2;
        mergeSort(A,n,left,mid);
        mergeSort(A,n,mid,right);
        merge(A,n,left,mid,right);
        
    }

}

int partition(struct Card A[],int n,int p,int r){
    int i,j;
    struct Card t,x;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++){
        if(A[j].value <= x.value){
            i++;
            t = A[i];
            A[i] = A[j];
            A[j] = t;
        }
    }
    t = A[i+1];
    A[i+1]=A[r];
    A[r]=t;
    return i+1;
}

void quickSort(struct Card A[],int n,int p,int r){
    int q;
    if(p<r){
        q=partition(A,n,p,r);
        quickSort(A,n,p,q-1);
        quickSort(A,n,q+1,r);
    }
}

int main(){
    int n,i,v;
    struct Card A[MAX],B[MAX];
    char S[10];
    int stable=1;
    
    scanf("%d",&n);
    
    for(i=0;i<n;i++){
        scanf("%s %d",S,&v);
        A[i].suit=B[i].suit=S[0];
        A[i].value=B[i].value=v;
    }
    mergeSort(A,n,0,n);
    quickSort(B,n,0,n-1);
    
    for(i=0;i<n;i++){
        if(A[i].suit != B[i].suit) stable = 0;
    }
    
    if(stable == 1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0;i<n;i++){
        printf("%c %d\n",B[i].suit,B[i].value);
    }
    return 0;
}


Measured memory_bytes: 4024
import math
def main():
  A, B = map(int, input().split())
  
  #Nは最大でも１２５０
  
  for n in range(1, 1251):
    if math.floor(n * 0.08) == A and math.floor(n * 0.1) == B:
      print(n)
      return
  print(-1)
    
  
main()

Measured memory_bytes: 9060
#include <iostream>
#include <sstream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <bitset>
#include <functional>
#include <random>
#define REP(_i,_a,_n) for(int _i=_a;_i<=_n;++_i)
#define PER(_i,_a,_n) for(int _i=_n;_i>=_a;--_i)
#define hr putchar(10)
#define pb push_back
#define lc (o<<1)
#define rc (lc|1)
#define mid ((l+r)>>1)
#define ls lc,l,mid
#define rs rc,mid+1,r
#define x first
#define y second
#define io std::ios::sync_with_stdio(false)
#define endl '\n'
#define DB(_a) ({REP(_i,1,n) cout<<_a[_i]<<',';hr;})
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int P = 1e9+7, INF = 0x3f3f3f3f;
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll qpow(ll a,ll n) {ll r=1%P;for (a%=P;n;a=a*a%P,n>>=1)if(n&1)r=r*a%P;return r;}
ll inv(ll x){return x<=1?1:inv(P%x)*(P-P/x)%P;}
inline int rd() {int x=0;char p=getchar();while(p<'0'||p>'9')p=getchar();while(p>='0'&&p<='9')x=x*10+p-'0',p=getchar();return x;}
//head



const int N = 5e3+10;
int n,m,f[N][N],g[N][N],pw[N],ipw[N];

int main() {
	pw[0] = ipw[0] = 1;
	REP(i,1,N-1) ipw[i]=inv(pw[i]=pw[i-1]*2ll%P);
	scanf("%d%d", &n, &m);
	REP(i,1,m) {
		f[1][i] = pw[i];
		g[1][i] = (g[1][i-1]+i)%P;
	}
	REP(i,2,n) REP(j,1,m) {
		f[i][j] = ((j+1ll)*f[i-1][j]+(ll)pw[j-1]*g[i-1][j-1])%P;
		g[i][j] = (g[i][j-1]+(ll)j*ipw[j]%P*f[i][j])%P;
	}
	printf("%d\n", f[n][m]);
}

Measured memory_bytes: 199464
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    string s;
    cin >> s;
    if(s[2] == s[3]){
        if(s[4] == s[5]){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
using namespace std;
#define N 8
string table[N] = {"black", "blue", "lime", "aqua", "red", "fuchsia", "yellow", "white"};
struct Color{ string R, G, B;};

Color colors[N];

int convert(string hex){
    int p = 1, sum = 0;
    for ( int i = hex.size()-1; i >= 0; i--, p *= 16 ){
	sum += p*((isdigit(hex[i]))?(hex[i]-'0'):(hex[i]-'a'+10));
    }
    return sum;
}

double getDistance(Color c1, Color c2){
    int dr = convert(c1.R) - convert(c2.R);
    int dg = convert(c1.G) - convert(c2.G);
    int db = convert(c1.B) - convert(c2.B);
    return sqrt(dr*dr + dg*dg + db*db);
}

main(){
    for ( int i = 0; i < N; i++ ) colors[i].R = colors[i].G = colors[i].B = "00";
    colors[1].B = "ff";
    colors[2].G = "ff";
    colors[3].B = "ff";
    colors[3].G = "ff";
    colors[4].R = "ff";
    colors[5].R = "ff";
    colors[5].B = "ff";
    colors[6].R = "ff";
    colors[6].G = "ff";
    colors[7].R = "ff";
    colors[7].G = "ff";
    colors[7].B = "ff";
    string hex;
    while( cin >> hex && hex != "0"){
	string ans = "";
	double sub = (1<<30);
	Color target;
	target.R = hex.substr(1, 2);
	target.G = hex.substr(3, 2);
	target.B = hex.substr(5, 2);
	for ( int i = 0; i < N; i++ ){
	    double d = getDistance(colors[i], target);
	    if ( d < sub ){
		sub = d;
		ans = table[i];
	    }
	}
	cout << ans << endl;
    }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    vector<int> a(n);
    double ave = 0;
    rep(i, n) {
        cin >> a[i];
        ave += a[i];
    }
    ave /= n;

    double len = INF;
    int ans = 0;
    rep(i, n){
        double tmp = abs(ave - a[i]);
        if(len > tmp){
            len = tmp;
            ans = i;
        }
    }

    cout << ans << "\n";

    return 0;
}


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

using namespace std;

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

    int max = std::max({a, b, c, d, e});
    int min = std::min({a, b, c, d, e});


    cout << ((max - min <= k) ? "Yay!" : ":(");

    return 0;
}

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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

// bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
//     return arg1.first > arg2.first;
// }

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

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

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

    vector<int> p(n);
    for(int in=0;in<n;in++) {
        cin >> p.at(in);
    }

    sort(p.begin(), p.end(), greater<int>());

    p.at(0) /= 2;

    int ans = 0;
    for(int in=0;in<n;in++) {
        ans += p.at(in);
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;

long long solve(long long X, long long K, long long D)
{
	X = abs(X);

	auto K2 = X / D;
	if (K <= K2) {
		return X - K * D;
	}
	else {
		if ((K - K2) % 2 == 0) {
			return X - K2 * D;
		}
		else {
			return (K2 + 1) * D - X;
		}
	}
}

int main()
{
	long long X, K, D;
	cin >> X >> K >> D;
	cout << solve(X, K, D);
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define SORT(a) sort(a.begin(), a.end())
#define RSORT(a) sort(a.rbegin(), a.rend())
#define REP(i, n) for (int i = 0; i < n; ++i)
#define RREP(i, n) for (int i = n; 0 <= i; --i)
#define FOR(i, start, end) for (int i = start; i < end; ++i)
#define RFOR(i, start, end) for (int i = start; end <= i; --i)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1'000'000'007
#define INF32 1'050'000'000
#define INF64 4'000'000'000'000'000'000
using ll = long long;
using namespace std;
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() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int N; cin >> N;
    int Y; cin >> Y;
    int z = 0;
    REP (i, N+1) {
        REP (j, N+1) {
            z = Y - i * 10000 - j * 5000;
            if (z%1000 != 0 || z<0) continue;
            else {
                z /= 1000;
                if (i+j+z != N) continue;
                cout << i << " " << j << " " << z << '\n';
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << '\n';
    return 0;
}



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

#define rep(i, a, b) for (int i = (a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (a); i >= (int)(b); i--)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

template <class T>
bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

template <class T>
void dump_vec(const vector<T>& v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == (int)len - 1 ? "\n" : " ");
    }
}

struct FastIO {
    FastIO() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} FASTIO;

//---------------------------------------------------------------------------------------------------

/// 素集合データ構造: Union Find Tree (Disjoint Set)
struct UnionFind {
    vector<int> _ids; // 添字iが属する集合のID

    UnionFind(int n) {
        _ids.assign(n, -1);
    }

    int root(int x) {
        const auto rx = _ids[x];
        return (rx < 0 ? x : _ids[x] = root(rx));
    }

    // 要素xとyは同じ連結成分に属するか？
    bool connected(int x, int y) {
        return root(x) == root(y);
    }

    // 要素xが属する集合の要素数
    int size(int x) {
        return -_ids[root(x)];
    }

    // 要素xとyを連結
    bool unite(int x, int y) {
        auto rx = root(x), ry = root(y);
        if (rx == ry) return false;

        if (_ids[rx] > _ids[ry]) swap(rx, ry);
        _ids[rx] += _ids[ry];
        _ids[ry] = rx;
        return true;
    }
};

//---------------------------------------------------------------------------------------------------

signed main() {
    int N, Q;
    cin >> N >> Q;
    UnionFind uf(N);
    rep(i, 0, Q) {
        int c, x, y;
        cin >> c >> x >> y;
        if (c == 0) {
            uf.unite(x, y);
        } else {
            cout << (uf.connected(x, y) ? 1 : 0) << "\n";
        }
    }
}



Measured memory_bytes: 3248
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numba
def main():
    @numba.njit('(i8,)', cache=True)
    def solve(n):
        r = 0
        for i1 in range(1, n + 1):
            y = n // i1
            r += y * (y + 1) // 2 * i1
        return r
    no = int(input())
    print(solve(no))

if __name__ == '__main__':
    main()

Measured memory_bytes: 106304
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

//二項係数（nCk mod.p;1<=k<=n<=1e7,pは素数）
template <class T> struct Combination {
    const int MOD = 1000000007;
    vector<T> fac, finv, inv;
    Combination(const int MAX) : fac(MAX), finv(MAX), inv(MAX) {
        fac[0] = fac[1] = 1;
        finv[0] = finv[1] = 1;
        inv[1] = 1;
        for(int i = 2; i < MAX; i++) {
            fac[i] = fac[i - 1] * i % MOD;
            inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
            finv[i] = finv[i - 1] * inv[i] % MOD;
        }
    }
    T comb(int n, int k) {
        if(n < k)
            return 0;
        if(n < 0 || k < 0)
            return 0;
        return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
    }
};

ll power(ll x, ll n) {
    if(n == 0)
        return 1;
    ll res = power(x * x, n / 2);
    if(n & 1)
        res = res * x;
    return res;
}

int main() {
    ll N, P;
    cin >> N >> P;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    ll odd = 0, even = 0;
    rep(i, N) {
        if(A[i] & 1) {
            odd++;
        } else {
            even++;
        }
    }
    Combination<ll> C(100);
    ll res = 0;
    if(P == 0) {
        for(ll i = 0; i <= odd; i++) {
            if(i % 2 == 0) {
                res += C.comb(odd, i) * power(2, even);
            }
        }
        cout << res << endl;
    } else {
        for(ll i = 0; i <= odd; i++) {
            if(i % 2 == 1) {
                res += C.comb(odd, i) * power(2, even);
            }
        }
        cout << res << endl;
    }
    return 0;
}

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

typedef long long ll;

int n,m;

int par[100005]={0};

int find(int x)
{
	return par[x] = (par[x]==x)?x:find(par[x]);
}

int unite(int x,int y)
{
	if(find(x)<find(y))
		par[find(y)] = find(x);
	else
		par[find(x)]=find(y);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin>>n>>m;
	int a[n];
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<100005;i++)
		par[i] = i;
	
	for(int i=0;i<m;i++)
	{
		int u,v;
		cin>>u>>v;
		unite(u,v);
	}
	
	int ans=0;
	
	for(int i=0;i<n;i++)
	{
		if(find(i+1)==find(a[i]))
			ans++;
	}
	cout<<ans;
	
}

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  int n;cin>>n;
  vector<int> a(n);
  rep(i, n)cin>>a[i];

  int t = 0;
  rep(i, n)t^=a[i];

//cout<<t<<endl;

  rep(i, n)cout<<(t^a[i])<<' ';

  return 0;
}

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

int main() {

	long long n;
	cin >> n;

	long long res = 1e18;
	for (long long i = 1; i < 1e6 + 1; ++i) {
		if (n % i == 0) {
			long long j = n / i;
			res = min(res, i + j - 2);
		}
	}

	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long x[1000000];
long long y[1000000];
long double eps[]={1e-4,1e-5,1e-6,1e-7,1e-8,1e-9};
vector<pair<long double,long double> > pos;
long long ret=0;
int n;
long long solve(pair<long double,long double> p)
{
    long long X=0,Y=0;
    for (int i=1;i<=n;i++)
    {
        if (p.first*x[i]+p.second*y[i] > 0)X+=x[i],Y+=y[i];
    }
    return X*X+Y*Y;
}
int main ()
{
    //ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++)
    {
        cin>>x[i]>>y[i];
        pair<long double,long double> A;
        A = {y[i],-x[i]};
        pos.push_back(A);
        for (int j=0;j<6;j++)
        {
            pair<long double,long double> B;
            B = A;
            B.first+=eps[j];
            pos.push_back(B);
            B = A;
            B.first-=eps[j];
            pos.push_back(B);
            B = A;
            B.second+=eps[j];
            pos.push_back(B);
            B = A;
            B.second-=eps[j];
            pos.push_back(B);
        }
        A = {-y[i],x[i]};
        pos.push_back(A);
        for (int j=0;j<6;j++)
        {
            pair<long double,long double> B;
            B = A;
            B.first+=eps[j];
            pos.push_back(B);
            B = A;
            B.first-=eps[j];
            pos.push_back(B);
            B = A;
            B.second+=eps[j];
            pos.push_back(B);
            B = A;
            B.second-=eps[j];
            pos.push_back(B);
        }
    }
    long long ret=0;
    for (auto P:pos)
        ret=max(ret,solve(P));
    cout<<setprecision(20)<<fixed<<sqrtl(ret)<<endl;
}


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

using std::cout;
using std::cin;
using std::endl;

int main() {
	int n, m;
	std::vector<int> a{};
	cin >> n >> m;
	a.resize(n);
	int sum = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
		sum += a[i];
	}
	int di = 4 * m;
	int border = (sum + (di - 1)) / di;
	std::sort(a.begin(), a.end(), std::greater<>{});
	auto mth = a[m - 1];
	bool is_selectable = mth >= border;
	cout << (is_selectable ? "Yes" : "No") << endl;
}


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

using namespace std;

#define M_DEBUG if (1)
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }


/******************************************************************************
	typedef
******************************************************************************/
using lint = long long;
typedef unsigned long long int ullint;




/******************************************************************************
	Main
******************************************************************************/
int main()
{
    int k = 0, n = 0;
    cin >> k >> n;
    assert(k >= 2 && k <= pow(10, 6));
    assert(n >= 2 && n <= 2 * pow(10, 5));

    int a_list[200001] = {0};
    int max_dist = 0;
    rep(i, n) {
        cin >> a_list[i] ;
        if (i == 0) assert(a_list[i] >= 0);
        else assert(a_list[i] >= 0 && a_list[i-1] <= a_list[i]);

        if (i > 0) {
            if (max_dist < a_list[i] - a_list[i-1]) {
                max_dist = a_list[i] - a_list[i-1];
            }
        } else {
            max_dist = a_list[i];
        }
    } 
    if (max_dist < k - a_list[n-1] + a_list[0]) {
        max_dist = k - a_list[n-1] + a_list[0];
    }
	cout << k - max_dist << endl;

	return 0;
}


Measured memory_bytes: 1536
#include <unordered_map>
#include <algorithm>
#include <iostream>
#include <string.h>
#include <cstdlib>
#include <vector>
#include <string>
#include <bitset>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
 
typedef long long ll;
typedef long double ld;
 
const ll MOD = 1e9 + 7, INF = 1e18 + 1;
 
using namespace std;
ll l;

ll grundy (ll height)
{
	return (height & (-height));
}

struct Node
{
	bool leaf;
	Node* to[2];

	Node ()
	{
		leaf = false;
		to[0] = to[1] = NULL;
	}
};

Node* root;

ll n, ptr;
ll s;

void add (string s)
{
	auto x = root;
	for (ll i = 0; i < s.length (); i++)
	{
		if (!x -> to[s[i] - '0']) x -> to[s[i] - '0'] = new Node ();
		x = x -> to[s[i] - '0'];
	}}

void dfs (Node* x, ll h)
{
	if (!x) return;
	ll c = (x -> to[0] != NULL) + (x -> to[1] != NULL);

	if (c == 1) s ^= grundy (h);

	dfs (x -> to[0], h - 1);
	dfs (x -> to[1], h - 1);
}

int main ()
{
	root = new Node ();

	cin >> n >> l;

	for (ll i = 0; i < n; i++)
	{
		string s;
		cin >> s;

		add (s);
	}

	dfs (root, l);

	if (!s || !n) cout << "Bob";
	else cout << "Alice";
}


Measured memory_bytes: 5120
inputs = []
num = STDIN.gets.chomp.to_i
num.times do
  input = STDIN.gets.chomp
  inputs << input.split.map(&:to_i).sort.reverse.map{|i| i**2}
end

inputs.each do |i|
  result = i[0] == i[1] + i[2] ? 'YES' : 'NO'
  puts result
end

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

using namespace std;

using ll = long long;
using ld = long double;

void Solve() {
    int n, q;
    cin >> n >> q;

    vector<tuple<int, int, int>> stx(n);
    for (int i = 0; i < n; ++i) {
        cin >> get<1>(stx[i]) >> get<2>(stx[i]) >> get<0>(stx[i]);
    }
    sort(stx.begin(), stx.end());

    set<pair<int, int>> d;
    for (int i = 0, x; i < q; ++i) {
        cin >> x;
        d.emplace(x, i);
    }

    vector<ll> tm(q, -1);
    for (int i = 0; i < n; ++i) {
        auto first = d.lower_bound(make_pair(get<1>(stx[i]) - get<0>(stx[i]), 0));
        auto end= d.upper_bound(make_pair(get<2>(stx[i]) - get<0>(stx[i]) - 1, q));

        // cout << "i = " << i << endl;
        for (auto it = first; it != end; ++it) {
            // cout << "tm[" << it->second << "] = " << get<0>(stx[i]) + it->first
            //      << endl;
            tm[it->second] = get<0>(stx[i]);
        }
        // cout << endl;

        d.erase(first, end);
    }

    for (int i = 0; i < q; ++i) {
        cout << tm[i] << '\n';
    }
}

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    // cout << setprecision(8) << setiosflags(ios::fixed);

    Solve();

    return 0;
}


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

using namespace std;
using ll = unsigned long long;
using P = pair<ll, ll>;

const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int MAX_N = 10;
const int MAX_W = 110000;
int dp[MAX_N][MAX_W]; // 6 種類だが余裕をもつ

const int CASES = 3;

void solve() {
    int W;
    cin >> W;

    // 品物を列挙 (価値はすべて 1)
    vector<int> weight;
    for (int i = 100; i < 106; i++) weight.push_back(i);
    int n = (int)weight.size();

    // DP初期条件: dp[i][0] = 0
    for (int i = 0; i < MAX_N; ++i) for (int w = 0; w < MAX_W; ++w) dp[i][w] = INF32;
    for (int i = 0; i <= n; ++i) dp[i][0] = 0;

    // DPループ
    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= W; ++w) {
            dp[i + 1][w] = min(dp[i + 1][w], dp[i][w]);
            if (w >= weight[i]) dp[i + 1][w] = min(dp[i + 1][w], dp[i + 1][w - weight[i]] + 1);
        }
    }
    int ans = 1;
    if(dp[n][W] == INF32){
        ans = 0;
    }
    cout << ans << endl;
}

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

    solve();

#endif
    return 0;
}



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

int main(void)
{
    int N;
    int sum = 0;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }
    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}



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

typedef vector<int> vi;
typedef long long int ll;
typedef pair<int,int> pii;
typedef vector<pii > vii;
typedef vector<vi > vvi;


int n, i, a, f, b;
int main() {
    cin >> a >> b;
    if((a+b)%3 == 0 || a%3 == 0 || b%3 == 0)
        puts("Possible"); 
    else
        puts("Impossible");
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <ext/pb_ds/detail/standard_policies.hpp>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int long long 
#define pb push_back
#define ins insert
#define rs resize
#define br break;
#define cont continue;
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vector<int>>
#define si set<ll>
#define sll set<long long>
#define pii pair<ll,ll>
#define pll pair<long long, long long>
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vec vector
#define cend cout<<endl;
#define sc second
#define fr first
#define retz return 0;
#define ll_MAX (ll)(1e9*1e9)
#define ll_MIN (ll)(-1e9*1e9)
#define lb lower_bound
#define ub upper_bound
#define rep(i,a,b)  for(int i=a; i<=b; i++)
#define repd(i,a,b) for(int i=a; i>=b; i--)
#define ps(arr, n) for(int i=1; i<n; i++)arr[i]+=arr[i-1];
#define inp(arr, n)for(int i=0; i<n; i++)cin>>arr[i];
#define out(arr, n)for(int i=0; i<n; i++)cout<<arr[i];
#define inp1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define out1(arr,n,m)for(int i=0; i<n; i++)for(int j=0;j<m;j++)cin>>arr[i][j];
#define loop(q) for(auto it:q)
#define loop1(q) for(auto&it:q)
#define db1 cout << "*" << endl
#define db2 cout << "YES" << endl
using namespace std;
using namespace __gnu_pbds; 
#define oset(X) tree<X,null_type,less<X>, rb_tree_tag, tree_order_statistics_node_update> 
#define roset(X) tree<X,null_type,greater<X>, rb_tree_tag, tree_order_statistics_node_update>  
#define okey order_of_key //lower_bound_set
#define ofind find_by_order
#define cyes cout << "Yes" << endl; 
#define cno cout << "No" << endl;
#define mod (long long)1000000007
#define mod2 (long long)998244353
#define INT_MAX1 900000000
#define MAXN 2000000
#define INF INT_MAX


void solve()
{
    string s;
    cin >> s;
    if(s[1]=='B')
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
}


signed main()
{
    
    speed;
    int t = 1;
    //cin >> t;
    while(t--)
        solve();
}

Measured memory_bytes: 3608
s=input()

r=0
s0=0
s1=0

for x in s:
  if x=="0":
    if s1!=0:
      s1=s1-1
    else:
      s0=s0+1
  else:
    if s0!=0:
      s0=s0-1
    else:
      s1=s1+1


print(len(s)-s0-s1)

Measured memory_bytes: 3188
<?php
fscanf(STDIN, "%d", $a);
fscanf(STDIN, "%d", $b);
fscanf(STDIN, "%d", $c);
fscanf(STDIN, "%d", $x);
 
$kotae = 0;
$a_max = min($a, floor($x/500))*500;
$b_max = min($b, floor($x/100))*100;
$c_max = min($c, floor($x/50))*50;
for ($cur_a = 0; $cur_a <= $a_max; $cur_a+=500) {
  for ($cur_b = 0; $cur_b <= $b_max; $cur_b+=100) {
    for ($cur_c = 0; $cur_c <= $c_max; $cur_c+=50) {
      if ($cur_a + $cur_b + $cur_c == $x){$kotae++;}
    }
  }
}
echo $kotae;
?>

Measured memory_bytes: 3700
import java.util.*;

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

        int n = sc.nextInt();
        int p[][] = new int[n][3];

        for (int i = 0; i < n; i++) {
            p[i][0] = sc.nextInt();
            p[i][1] = sc.nextInt();
            p[i][2] = sc.nextInt();
        }

        int cp[] = {0, 0, 0};
        for (int i = 0; i < n; i++) {
            int t = p[i][0];
            int x = p[i][1];
            int y = p[i][2];

            int dt = t - cp[0];
            int dx = Math.abs(x - cp[1]);
            int dy = Math.abs(y - cp[2]);

            if (dt < dx + dy) {
                System.out.println("No");
                return;
            }

            if (!(dt % (dx + dy) == 0)){
                System.out.println("No");
                return;
            }

            cp[0] = t;
            cp[1] = x;
            cp[2] = y;
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 92224
fun main(args: Array<String>){
    val (K, S) = readLine()!!.split(" ").map { it.toInt() }
    var count = 0L
    for(x in 0..K){
        for(y in 0..K){
            val z = S - x - y
            if(z in 0..K){
                count++
            }
        }
    }
    println(count)
}

Measured memory_bytes: 35988