akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;
const ll mod = 1e9+7;
ll two[100005],three[100005];
// bの逆元求める
ll IE(ll b) {
  ll ret = 1;
  ll M = mod - 2;
  for (; M; b = (b * b) % mod, M >>= 1) {
    if(M & 1) ret = (ret * b) % mod;
  }
  return ret % mod;
}
ll calc(ll n, ll x) {
  return (x * three[n] % mod + n * three[n - 1] % mod) % mod;
}
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int n = s.length();
  two[0] = three[0] = 1;
  FOR(i,1,n+1){
    two[i] = (two[i-1] * 2) % mod;
    three[i] = (three[i-1] * 3) % mod;
  }
  int A[n],QL[n],QR[n],C[n];
  CLR(A);CLR(QL);CLR(QR);CLR(C);
  FOR(i,0,n){
    A[i] = i ? A[i-1] : 0;
    A[i] += s[i] == 'A';
    QL[i] = i ? QL[i-1] : 0;
    QL[i] += s[i] == '?';
  }
  for(int i = n - 1; i >= 0; i--){
    C[i] = i < n - 1 ? C[i+1] : 0;
    C[i] += s[i] == 'C';
    QR[i] = i < n - 1 ? QR[i+1] : 0;
    QR[i] += s[i] == '?';
  }
  ll ans = 0;
  FOR(i,1,n-1){
    if(s[i]=='A'||s[i]=='C') continue;
    //cout << "i:" << i << "   A:" << A[i-1] << " ?:" << QL[i-1] << " C:" << C[i+1] << " ?:" << QR[i+1] << endl;
    ans += calc(QL[i-1], A[i-1]) * calc(QR[i+1], C[i+1]);
    ans %= mod;
  }
  cout << ans % mod << endl;
}

Measured memory_bytes: 3664
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <functional>
#include <string>


using namespace std;
int main()
{
	long long i, j, k, a, b, c, d, X, n, M;
	long long A[100001];
	long long B[200001];
	
	cin >> n;

	for (i = 0; i < n; i++) {
		cin >> A[i];
	}

	sort(A, A + n);

	c = A[n - 1];

	d = A[0];

	for (i = 1; i < n; i++) {
		if (abs(2*d - 2*c / 2) > abs(2*A[i] - 2*c / 2)) {
			d = A[i];
		}
	}

	cout << c << " " << d;

	
	return 0;
}

Measured memory_bytes: 1024
//123 B - Five Dishes 2019/04/06
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int main(){
    vector<int> d(6);
    d[5]=0;
    rep(i ,5) cin >> d[i];
    rep(i ,5){
        int j=i+1;//int tmp;
        while(j>=1 && d[j-1]%10 < d[j]%10 ){
               //tmp=d[i]; d[i]=d[i+1]; d[i+1]=tmp;
               swap(d[j-1],d[j]);
                --j;
            }
        }
    int __time=0;
    rep(i,5){
        if(d[i]%10==0) {__time+=d[i]; d[i]=0; }
    }
    int j=4;
    while(j>=0){
        if(d[j]!=0) {__time+=d[j]; break;}
        --j;
    }
    rep(i ,j) __time+=d[i]+10-d[i]%10;
    cout << __time << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

#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=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const ll mod = 1e9 + 7;
ll dp[311][311][311];

int main(void){
    int n, m;
    cin >> n >> m;
    dp[0][1][0] = 1;
    REP(i,m) REP(j,n+1) REP(k,n+1){
        if (j + k > n) continue;
        dp[i+1][j][k] = (dp[i+1][j][k] + k * dp[i][j][k]) % mod;
        dp[i+1][j+k][0] = (dp[i+1][j+k][0] + j * dp[i][j][k]) % mod;
        dp[i+1][j][k+1] = (dp[i+1][j][k+1] + (n - k - j) * dp[i][j][k]) % mod;
    }

    // FOR(i,1,m){
    //     cout << i << endl;
    //     REP(j,n+1){
    //         REP(k,n+1) cout << dp[i][j][k] << " ";
    //         cout << endl;
    //     }
    //     cout << endl;
    // }
    cout << dp[m][n][0] << endl;

    return 0;
}


Measured memory_bytes: 228864
#include<iostream>
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip>//setprecision
#include<math.h>
#include <functional>
#include<climits>
using namespace std;
#define ll  long long 
#define rep(i, n)        for(ll i=0; i<(ll)(n); ++i)
#define mod 1000000007
  vector<ll>to[1000005];
   ll dp[2000000];
 int gcd(int a, int b)
{
  if (a%b == 0)
{
return(b);
}
else
{
return(gcd(b,a%b));
}
}
int main(){
  ll a,b,c,d;cin>>a>>b>>c>>d;
  rep(i,d+1){
    if(a<b&&b<c){
      cout<<"Yes";
      return 0;
    }
    else if(a<b)c=c*2;
    else b=b*2;
  }
  cout<<"No";
}



Measured memory_bytes: 27076
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long ll;

ll solve(ll a) {
    ll ans = (((a + 1) % 4) >> 1);
    for (ll i = 1; i < 40; ++i) if (max(0LL, a % (1LL << (i + 1)) - (1LL << i) + 1) & 1LL) ans |= (1LL << i);
    return ans;
}

int main() {
    ll a, b;
    scanf("%lld%lld", &a, &b);
    printf("%lld\n", solve(a - 1) ^ solve(b));
    return 0;
}


Measured memory_bytes: 128
#include<cstring>
#include<cstdlib>
#include<cstdio>
#include<cmath>
#include<iostream>
#define N 110000
#define mmod 1000000007
#define LL long long
using namespace std;
struct node{LL y,nex;}a[2*N];
LL to[N],du[N],n,fir[N],len,cnt[N],A[N],num,siz,pre[N],l[N],m,pk[N],nt[N];
LL jc[N],ny[N],two[N],ans;
bool v[N],oc[N],b[N],bb[N],has[N];
void ins(LL x,LL y)
{
	a[++len].y=y;a[len].nex=fir[x];fir[x]=len;
}
void dfs(LL x)
{
	A[++num]=x;
	v[x]=1;
	for(LL k=fir[x];k;k=a[k].nex)
	{
		LL y=a[k].y;
		if(v[y]) continue;
		dfs(y);
	}
}
void find_loop(LL x)
{
	siz=0;
	while(1)
	{
		b[x]=1;
		if(b[to[x]])
		{
			LL st=x;
			do{
				siz++;
				oc[x]=1;
				x=to[x];
			}while(x!=st);
			break;
		}
		x=to[x];
	}
}
void solve(LL x)
{
	num=0;
	dfs(x);
	find_loop(x);
	if(siz==num) {cnt[siz]++;return;}
	for(LL i=1;i<=num;i++)
	{
		LL x=A[i];
		if(oc[x]==0 && oc[to[x]]) {if(has[to[x]]) {ans=0;return;}has[to[x]]=1;}
	}
	for(LL i=1;i<=num;i++)
	{
		LL x=A[i],t=0;
		if(du[x]) continue;
		while(oc[x]==0)
		{
			if(bb[x]) 
			{ans=0;return;}
			bb[x]=1;
			x=to[x];
			t++;
		}
		l[x]=t;
		x=to[x];t=1;
		while(has[x]==0) {t++;x=to[x];}
		pre[x]=t;
	}
	for(LL i=1;i<=num;i++)
		if(l[A[i]]>pre[A[i]]) 
		{ans=0;return;}
		else if(l[A[i]]<pre[A[i]]) ans=ans*2%mmod;
	int oo=1;
}
void make(LL k)
{
	LL tmp=0;
	m=cnt[k];
	pk[0]=1;
	for(LL i=1;i<=m;i++) pk[i]=pk[i-1]*k%mmod;
	if(k%2 && k>1) tmp=two[m];
	else tmp=1;
	for(LL i=1;i<=m/2;i++)
	{
		LL t=jc[m]*ny[m-i*2]%mmod*nt[i]%mmod*ny[i]%mmod*pk[i]%mmod;
		if(k%2 && k>1) t=t*two[m-i*2]%mmod;
		tmp=(tmp+t)%mmod;
	}
	ans=ans*tmp%mmod;
}
int main()
{
	scanf("%lld",&n);
	for(LL i=1;i<=n;i++)
	{
		scanf("%lld",&to[i]);
		ins(i,to[i]);ins(to[i],i);
		du[to[i]]++;
	}
	ans=1;
	for(LL i=1;i<=n;i++) 
	{
		if(v[i]==0) solve(i);
		if(ans==0) {printf("0\n");return 0;}
	}
	jc[0]=jc[1]=ny[0]=ny[1]=two[0]=1;two[1]=2;
	for(LL i=2;i<=n;i++)
	{
		jc[i]=jc[i-1]*i%mmod;
		ny[i]=(LL)(-mmod/i)*ny[mmod%i]%mmod;
		two[i]=two[i-1]*2%mmod;
	}
	for(LL i=1;i<=n;i++) ny[i]=ny[i]*ny[i-1]%mmod;
	nt[0]=1;nt[1]=ny[2];
	for(int i=2;i<=n;i++) nt[i]=nt[i-1]*ny[2]%mmod;
	for(LL i=1;i<=n;i++) if(cnt[i]) make(i);
	ans=(ans+mmod)%mmod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 15488
#include <iostream>
#include <string>
#include <algorithm>
#define	MOD = 1000000007;
using namespace std;

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

	int t[101];
	for (int i = 1; i <= N; i++)
	{
		cin >> t[i];
	}

	int M;
	cin >> M;
	int P[101], X[101];

	for (int i = 1; i <= M; i++)
	{
		cin >> P[i] >> X[i];
	}

	for (int i = 1; i <= M; i++)
	{
		int p = P[i];

		int sum = 0;
		for (int j = 1; j <= N; j++)
		{
			if (P[i] == j)
			{
				sum += X[i];
			}
			else
			{
				sum += t[j];
			}
		}
		cout << sum << endl;
	}

	return 0;
}

Measured memory_bytes: 256
def binarySearch(A, key):
    left = 0
    right = n
    while left < right:
        mid = int((left + right) / 2)
        if A[mid] == key: return 1
        elif key < A[mid]: right = mid
        else: left = mid + 1
    return 0

n = int(input())
S = [int(x) for x in input().split()]
q = int(input())
T = [int(x) for x in input().split()]

if __name__ == '__main__':
    anw = 0
    for i in T:
        if(binarySearch(S, i)): anw += 1
    print(anw)


Measured memory_bytes: 16896
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  int K;
  int ans = 0;
  cin >> N;
  cin >> K;  
  long long P[N];
  for(int i=0;i<N;i++){
    cin >> P[i];
  }
  sort(P, P + N);
  for(int i=0;i<K;i++){
    ans = ans + P[i];
  }  
  cout << ans << endl;
}

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

using namespace std;

#define f first
#define s second
#define pb push_back
#define FILL(a, b) memset(a, b, sizeof(a))

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<pii, int> piii;
typedef vector<int> vi;
typedef vector<pii> vii;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3fLL;
const int MOD = 1e9 + 7;
const int MAX = 250005;

int N;
int comp[25][25];
int dp[25][(1 << 21) + 5];

int solve(int i, int j) {
    int &ans = dp[i][j];
    if (ans == -1) {
        if (i == 0 && j == 0) {
            ans = 1;
        } else {
            ans = 0;
            for (int k = 1; k <= N; k++) {
                if (j & (1 << (k - 1)) && comp[i][k]) {
                    ans = (ans + solve(i - 1, j & ~(1 << (k - 1)))) % MOD;
                }
            }
        }
    }
    return ans;   
}

int main() {
    
    scanf("%d", &N);
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            scanf("%d", &comp[i][j]);
        }
    }

    FILL(dp, -1);
    printf("%d\n", solve(N, (1 << N) - 1));
    
    return 0;
}

Measured memory_bytes: 205056
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      int n,num=0;
      cin >> n;
      vector<int> button(n);
      for (int i=0; i<n; i++){
        cin >> button.at(i);
      }
      num = button.at(0);
      bool done=false;
      for (int i=0; i<n; i++){
        if(num == 2){
          cout << i+1;
          done = true;
          break;
        }
        else
          num = button.at(num-1);
      }
      if(done == false) cout << -1;
    }

Measured memory_bytes: 640
A, B, C = map(int, input().split())
#kA%Bの数列になる
#AをBで割ったあまりはB-1以下になる
#(k+B)A%B = (kA+BA)%B = kA%B + BA%B = kA%B
for i in range(1, B+1):
    if A*i%B == C:
        print('YES')
        exit()
print('NO')


Measured memory_bytes: 9152
#include <bits/stdc++.h>
using namespace std;
using namespace std::chrono;
#define idfc ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
//#define ll long long
#define pb emplace_back
#define mp make_pair
#define nt _int128
#define ld long double
long double PI =3.14159265358979323846;
using ll = long long;



const ll modo=998244353;
const ll inf=LONG_LONG_MAX;
const ll ms=(2e5)+5;



vector<int> a;
vector<int> b;

int main()
{
    idfc;
    int n;
    cin>>n;
    int i;int e;
    for(i=1;i<=n;i++)
    {
        cin>>e;
        a.pb(e);
        cin>>e;
        b.pb(e);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());

    if(n&1)
    {
        int ii=((n+1)/2)-1;
      //  cout<<ii<<" "<<a[ii]<<" "<<b[ii]<<"\n";
        int ans=b[ii]+1-a[ii];
        cout<<ans;
    }
    else{
        int i1=(n/2)-1;
        int i2=n/2;
        int ans=b[i1]+b[i2]+1-a[i1]-a[i2];
        cout<<ans;
    }

    return 0;
}

Measured memory_bytes: 5136
#include<cstdio>
#include<cstring>
#include<iostream>

const int maxn=1e5+5;

typedef unsigned long long LL; 

int w[100+5];

int v[100+5];

LL dp[100+5][maxn];

LL max(LL a,LL b) { return a>b?a:b; }

int main(){
	
	int n,weight; scanf("%d %d",&n,&weight);

	for(int i=1;i<=n;i++) scanf("%d %d",&w[i],&v[i]);

	memset(dp,0,sizeof(dp));

	LL ans=0;

	for(int i=1;i<=n;i++){
	
		for(int j=0;j<=weight;j++){
	
			dp[i][j]=dp[i-1][j]; // 空转移 
	
			if(j-w[i]>=0){

				dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]]+v[i]);

			}
			if(i==n) ans=max(ans,dp[i][j]);
		}
	}

	std::cout<<ans<<"\n";

	return 0;

}

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


int main() {

	int n;
	cin >> n;
	int* board = new int[n];
	for (int i = 0; i < n; i++) cin >> board[i];

	int ans = 0;

	while (true) {

		for (int i = 0; i < n; i++) {
			if (board[i] % 2) {
				cout << ans << endl;
				return 0;
			}
		}


		for (int i = 0; i < n; i++) board[i] /= 2;

		ans++;
	}

	return 0;
}

Measured memory_bytes: 256
ENV[Z='RUBY_THREAD_VM_STACK_SIZE']||exec({Z=>?5*8},'ruby',$0);def f(i,c)(h=(H[i].map{|e|f e,i}.max||0)+1)>=K&&c!=1&&(h=0;$r+=1);h end;N,K,Q,*A=`dd`.split.map &:to_i;H=Hash.new{|h,k|h[k]=[]};2.upto(N){|i|H[A[i-$r=2]]<<i};f 1,1;p$r--~Q/Q

Measured memory_bytes: 225300
#include <cstdio>

int main()
{
	char s[4];
	scanf("%s", s);
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R')
		printf("3\n");
	else if (s[0] == 'R' && s[1] == 'R' )
		printf("2\n");
	else if (s[1] == 'R' && s[2] == 'R' )
		printf("2\n");
	else if (s[0] == 'S' && s[1] == 'S' && s[2] == 'S')
		printf("0\n");
	else
		printf("1\n");
	return 0;

}


Measured memory_bytes: 1660
#include <iostream>
#include <vector>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n) - 1; 0 <= i; --i)
#define rep(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
using ll = long long;
using arr = vector<ll>;
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

ll n, a[100010];
int main()
{
  cin >> n;
  REP(i,n) cin >> a[i], a[i]++;
  reverse(a, a + n);

  vector<ll> dp(n + 1, INF);
  REP(i, n) {
    *upper_bound(dp.begin(), dp.end(), a[i]) = a[i];
  }
  cout << lower_bound(dp.begin(), dp.end(), INF) - dp.begin();
  return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
int main(void)
{
	int a,b,c,x,i,j,k,cnt=0;
	scanf("%d %d %d %d",&a,&b,&c,&x);
	for(i=0;i<=a;i++)
	{
		for(j=0;j<=b;j++)
		{
			for(k=0;k<=c;k++)
			{
				if((i*500+j*100+k*50)==x)
				{
					cnt++;
				}
			}
		}
	}
	printf("%d",cnt);
	return 0;
 } 

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
void __print(int x) {cout << x;}
void __print(long x) {cout << x;}
void __print(long long x) {cout << x;}
void __print(unsigned x) {cout << x;}
void __print(unsigned long x) {cout << x;}
void __print(unsigned long long x) {cout << x;}
void __print(float x) {cout << x;}
void __print(double x) {cout << x;}
void __print(long double x) {cout << x;}
void __print(char x) {cout << '\'' << x << '\'';}
void __print(const char *x) {cout << '\"' << x << '\"';}
void __print(const string &x) {cout << '\"' << x << '\"';}
void __print(bool x) {cout << (x ? "true" : "false");}
template<typename T, typename V>
void __print(const pair<T, V> &x) {cout << '{'; __print(x.first); cout << ','; __print(x.second); cout << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __print(i); cout << "}";}
void _print() {cout << "\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cout << ", "; _print(v...);}
#define debug(x...) cout << #x << " = "; _print(x)
typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
#define rep(i,a,b) for (ll i = (a); i < (b); ++i)
#define per(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define all(x) begin(x), end(x)
#define mp make_pair 
#define pb push_back
#define ff first
#define ss second
#define fast ios_base::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL) 
const int mod = 1e9 + 7, mxn = 1e5 + 1;

ll add(ll x, ll y){
    return (x + y)%mod;
}

ll mul(ll x, ll y){
    return (x * y)%mod;
}

int solve(){
    int n;
    cin>> n;
    vll v(n), suff(n);
    rep(i, 0, n)
        cin>> v[i];
    suff[n - 1] = v[n - 1];
    per(i, 0, n - 1)
        suff[i] = add(suff[i + 1], v[i]);
    ll ans = 0;
    rep(i, 0, n - 1)
        ans = add(ans, mul(v[i], suff[i + 1]));
    cout<<ans<< "\n";
    return 0;
}
//Counting problems: Sometimes easier to find complement of the answer
 
int main()
{
    fast;
    int t = 1;
    //cin>> t;
    while(t--){  
        solve();
    }
    return 0;
}
//v.clear(), vis.clear(); vis.resize(n + 1, 0), v.resize(n + 1);
 
/*  inv[1] = 1; // inv is ll
    for(int i=2; i<=mxn; ++i)
        inv[i]=mod-mod/i*inv[mod%i]%mod;*/
        
// lower bound   >=  
// upper bound   >
// vector<int>().swap(vec); //free memory from vec


Measured memory_bytes: 6344
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
    map<string,int>mp;
    int n;
    cin>>n;
    rep(i,n){
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<mp.size()<<endl;
    
    return 0;
}

Measured memory_bytes: 19224
#include <iostream>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <cmath>
#include <tuple>
#include <map>
#include <unordered_map>
#include <queue>
using namespace std;
typedef long long ll;

int main(int argc, char *argv[])
{
    int n, i, target;
	int u, v, w;
	cin >> n;
	queue<int> q;
	vector<int> answer(n, -1);
	vector< vector<int> > path(n), cost(n);
	for (i = 0; i < n - 1; i++) {
		cin >> u >> v >> w;
		u--;
		v--;
		path[u].push_back(v);
		path[v].push_back(u);
		cost[u].push_back(w);
		cost[v].push_back(w);
	}

	q.push(0);
	answer[0] = 0;
	
    while (!q.empty()) {
		target = q.front();
		q.pop();

		for (i = 0; i < path[target].size(); i++) {
			if (answer[path[target][i]] != -1)
				continue;
			answer[path[target][i]] = (cost[target][i] + answer[target]) % 2;
			q.push(path[target][i]);
		}
	}

	for (i = 0; i < n; i++)
		cout << answer[i] << endl;
	return 0;
}


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

typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++)cin >> a[i];

    int mi,mij,cou=0;

    for(int i=0;i<n;i++){
        mi=a[i];
        mij=i;
        for(int j=i;j<n;j++){
            if(mi>a[j]){
                mij=j;
                mi=a[j];
            }
        }
        if(i!=mij){
            swap(a[i],a[mij]);
            cou++;
        }
    }
    for(int i=0;i<n;i++)cout << a[i] << (i!=n-1?" ":"\n");
    cout << cou << endl;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
/* テンプレートここまで */

int main() {
  int N; cin >> N;
  vector<ll> a(N); 
  ll ans = 0;
  ll plus = 0;
  ll minus = 0;
  ll zero = 0;
  REP(i, N){
    cin >> a[i];
    ans += abs(a[i]);
    if(a[i] >= 0 ) plus++;
    if (a[i] <=  0) minus++;
  }
  sort(ALL(a));

  if(N == plus){
    ans -= 2*a[0];
    cout << ans << endl;
    ll tmp = a[0];
    REP(i, N-2){
      cout << tmp << " " << a[i+1] << endl;
      tmp -= a[i+1];
    }

    cout << a[N-1] << " " << a[N-1] - ans << endl;
    return 0;
  }

  if(N == minus){
    ll tmp = a[N-1] - a[N-2];
    ans += 2*a[N-1];
    cout << ans << endl;
    cout << a[N-1] << " " << a[N-2] << endl;

    REP(i, N-2){
      cout << tmp << " " << a[i] << endl;
      tmp -= a[i];
    }
    return 0;
  }

  cout << ans << endl;
  ll tmp = a[0];
  while(plus >=2){
    cout << tmp << " " << a[N-plus] << endl;
    
    tmp -= a[N-plus];
    plus--;
  }
  
  ll tmp2 = a[N-1];
  cout << tmp2 << " " << tmp << endl; 
  tmp = -tmp+tmp2;
  FOR(i, 1,  N){
    if(a[i] >=0 ) continue;
    cout << tmp << " " <<  a[i] << endl;
    tmp -= a[i];
  }
}


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

int main(void)
{
  int N;
  ll A[A_MAX];
  cin >> N;
  for(int i=0; i<N; i++)
  {
    cin >> A[i];
  }
  int count=0;	// 2割回数
  while(true)
  {
    bool exist_odd = false;	// A[i]に一つでも奇数があればtrue
    for(int i=0; i<N; i++)
    {
      if(A[i]%2 == 0)
      {
        A[i] /= 2;
      }
      else
      {
        exist_odd = true;
        break;
      }
    }
    if(exist_odd == 1)break;
    count++;
  }
  cout << count << endl;
  return 0;
}

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
const int inf=1000000001;
const ll INF=1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};

int main() {
	int n, m, i;
	cin >> n >> m;
	vi a(m), b(m);
	vi from_a, to_b;
	for (i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		if (a[i] == 1) {
			from_a.push_back(b[i]);
		}
		if (b[i] == n) {
			to_b.push_back(a[i]);
		}
	}
	sort(from_a.begin(), from_a.end());
	sort(to_b.begin(), to_b.end());
	bool flag = 0;
	for (i = 0; i < from_a.size(); i++) {
		flag = binary_search(to_b.begin(), to_b.end(), from_a[i]);
		if (flag) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

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

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

	ll X;
	cin>>X;

	ll a = X / 500;
	ll rem = X % 500;

	ll b = rem / 5;

	cout<< a* 1000 + b * 5 <<endl;

	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

mod = 1000000007

lcm = {}
ps = []
for i in range(n): 
    ai = a[i]
    p = 2
    ps.append({})
    while p * p <= ai:
        if ai % p == 0:
            ps[i][p] = 0
            while ai % p == 0:
                ps[i][p] += 1
                ai //= p
            lcm[p] = max(lcm.get(p, 0), ps[i][p])
        p += 1
    if ai > 1:
        ps[i][ai] = 1
        lcm[ai] = max(lcm.get(ai, 0), ps[i][ai])

lcmv = 1
for p in lcm:
    lcmv = (lcmv * (p ** lcm[p])) % mod

def inv(p, k):
    k = mod - k - 1
    ret = 1
    b = p
    while k > 0:
        if k % 2 == 1:
            ret = (ret * b) % mod
        b = (b * b) % mod
        k //= 2
    return ret

ret = 0
for i in range(n):
    prod = lcmv
    for p in ps[i]:
        prod = (prod * inv(p, ps[i][p])) % mod
    ret = (ret + prod) % mod

print(ret)
        


Measured memory_bytes: 12268
#include <iostream>
#include <string>
#include <map>

using namespace std;

int main(void) {
	string str;
	cin >> str;

	int len = str.length();
	map<char,int> counter;
	for (int i = 0; i < len; ++i) {
		++counter[str[i]];
	}

	long long count = 1;
	int all = len-1;
	for (int i = 0; i < len-1; ++i) {
		count += all - counter[str[i]] + 1;
		--counter[str[i]];
		--all;
	}

	cout << count << endl;

	return 0;
}


Measured memory_bytes: 640
def solve(k):

    if k <= 9:
        return k
    cnt = 9
    tmp = [1, 2, 3, 4, 5, 6, 7, 8, 9]
    tmp_new = []
    while True:
        for p in tmp:
            m = p % 10
            if m == 0:
                tmp_new.append(p * 10)
                cnt += 1
                if cnt == k:
                    return tmp_new[-1]
                tmp_new.append(p * 10 + 1)
                cnt += 1
                if cnt == k:
                    return tmp_new[-1]
            elif m == 9:
                tmp_new.append(p * 10 + 8)
                cnt += 1
                if cnt == k:
                    return tmp_new[-1]
                tmp_new.append(p * 10 + 9)
                cnt += 1
                if cnt == k:
                    return tmp_new[-1]
            else:
                tmp_new.append(p * 10 + m - 1)
                cnt += 1
                if cnt == k:
                    return tmp_new[-1]
                tmp_new.append(p * 10 + m)
                cnt += 1
                if cnt == k:
                    return tmp_new[-1]
                tmp_new.append(p * 10 + m + 1)
                cnt += 1
                if cnt == k:
                    return tmp_new[-1]
        tmp = tmp_new
        tmp_new = []

    return 0


def main():
    k = int(input())
    res = solve(k)
    print(res)


def test():
    assert solve(15) == 23
    assert solve(1) == 1
    assert solve(13) == 21
    assert solve(100000) == 3234566667


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 6344
#include <iostream>
using namespace std;
int main(){
	int n;
	int fish[20]={0};
	cin>>n;
	for(int i=0;i<n;i++){
		int a,v;
		cin>>a>>v;
		fish[a-1]=v;
	}
	int max=fish[0],b=0;
	for(int j=1;j<20;j++){
		if(max<fish[j]){
			max=fish[j];
			b=j;
		}
	}
	cout<<b+1<<" "<<max<<endl;
	return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
using namespace std;
int gcd(int a,int b){
    if(b==0) return a;
    return gcd(b,a%b);
}
int n,m,cnt=INF,o,p,aa[220000],cntl=0,ab[220][220],ac[220],a;
pair<int,int> pp[220000];
string s,sa,ss[220000];
char c,cc[220000];
queue<int> que;
signed main(){
    cin>>n>>m>>o;
    rep(i,n){
        cin>>aa[i];
        rep(j,m){
            cin>>ab[i][j];
        }
    }
    rep(i,pow(2,n)){
        rep(j,m){
            ac[j]=0;
        }
        a=0;
        p=i;
        rep(j,n){
            if(p%2==1){
                a+=aa[j];
                rep(k,m){
                    ac[k]+=ab[j][k];
                }
            }
            p/=2;
        }
        rep(j,m){
            if(ac[j]<o){
                goto asd;
            }
        }
        cnt=min(cnt,a);
        asd:;
    }
    if(cnt==INF){
        cout<<-1;
    }else{
        cout<<cnt;
    }
}

Measured memory_bytes: 11024
N, M, Q = map(int, input().split())

LR = [list(map(int, input().split())) for _ in range(M)]
PQ = [list(map(int, input().split())) for _ in range(Q)]


def rectangle_sum(n):
    table = [[0 for _ in range(n + 1)] for _ in range(n + 1)]

    for l, r in LR:
        table[l][r] += 1

    for y in range(n + 1):
        for x in range(1, n + 1):
            table[y][x] += table[y][x - 1]

    for y in range(1, n + 1):
        for x in range(n + 1):
            table[y][x] += table[y - 1][x]
    return table


t = rectangle_sum(N)
for p, q in PQ:
    tmp = t[q][q] - t[q][p - 1] - t[p - 1][q] + t[p - 1][p - 1]
    print(tmp)

Measured memory_bytes: 77248
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

int main()
{
    char data[300];
    char temp[300];

    while(1){
        scanf("%s", &data);
        //printf("data:%s\n", data);
        if(data[0] == '-'){
            break;
        }else{
            int m;
            int h;
            scanf("%d", &m);
            //printf("m:%d\n", m);

            for(int i=0; i<m; i++){
                scanf("%d", &h);
                //printf("h:%d\n", h);

                for(int j=0; j<h; j++){
                    temp[j] = data[j];
                }
                //printf("0temp:%s\n", temp);

                for(int j=0; j<strlen(data)-h; j++){
                    data[j]=data[h+j];
                }
                //printf("1data:%s\n", data);

                for(int j=0; j<h; j++){
                    data[strlen(data)-h + j] = temp[j];
                }               
                //printf("2data:%s\n", data);

            }
            printf("%s\n", data);
        }
    }

    return 0;
}


Measured memory_bytes: 2092
#include <cstdio>

int main()
{
  int n;
  scanf("%d", &n);
  double sum = 0;
  for (int i = 0; i < n; ++i)
  {
    int a;
    scanf("%d", &a);
    sum += 1 / double(a);
  }
  printf("%.8f\n", 1 / sum);
  return 0;
}

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

struct Node{
    int key;
    struct Node *next,*prev;
};

typedef struct Node Node;

Node *nil;

Node *listSearch(int);
void init();
void printList();
void deleteNode(Node*);
void deleteFirst();
void deleteLast();
void deleteKey(int);
void insertKey(int);

int main(){
    int key,n,i;
    char command[11];

    scanf("%d",&n);

    init();

    for(i=0;i<n;i++){
        scanf("%s%d",command,&key);

        if(command[0]=='i') insertKey(key);
        else if(command[0]=='d'){
            if(command[6]=='F') deleteFirst();
            else if(command[6]=='L') deleteLast();
            else deleteKey(key);
        }
    }

    printList();

    return 0;
}

Node *listSearch(int key){
    Node *current=nil->next;

    while(current!=nil&&current->key!=key){
        current=current->next;
    }

    return current;
}

void init(){
    nil=(Node*)malloc(sizeof(Node));

    nil->next=nil;
    nil->prev=nil;
}

void printList(){
    int i;
    Node *current=nil->next;

    for(i=0;;i++){
        if(current==nil) break;
        if(i==0) printf("%d",current->key);
        else printf(" %d",current->key);
     
        current=current->next;
    }
    printf("\n");

}

void deleteNode(Node *x){
    if(x==nil) return;

    x->prev->next=x->next;
    x->next->prev=x->prev;

    free(x);
}

void deleteFirst(){
    deleteNode(nil->next);
}

void deleteLast(){
    deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insertKey(int key){
    Node *x=(Node*)malloc(sizeof(Node));

    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}


Measured memory_bytes: 32940
#include <stdio.h>
 
int main(void) {
     
    int w, lw = 4280;
    int w1 = 1150,
        w2 = 1250,
        w3 = 1400;
     
    while(1){
        scanf("%d", &w);
        if(w == -1)     break;
         
        if(w <= 10)          w = w1;
        else if(w <= 20) w = w1 + (w - 10) * 125;
        else if(w <= 30) w = w1 + w2 + (w - 20) * 140;
        else                w = w1 + w2 + w3 + (w - 30) * 160;
 
        printf("%d\n", lw - w);
    }
     
    return 0;
}

Measured memory_bytes: 600
N,T = map(int,input().split())
t = list(map(int,input().split()))
start = 0
end = T
ans = 0
for i in range(N-1):
    if t[i]+T < t[i+1]:
        ans += end-start
        start = t[i+1]
    end = t[i+1]+T
ans += end-start
print(ans)


Measured memory_bytes: 25196
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,k,i,c=0;
  cin>>n>>k;
  int a[n];
  for(i=0;i<n;i++)
  {
    cin>>a[i];
    if(a[i]>=k)
    {
      c++;
    }
  }
  cout<<c;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int Gcd(int a, int b){
  if(a >= b){
	if(a % b == 0){
	  return b;
	}
	return Gcd(b, a%b);
  }else{
	if(b % a == 0){
	  return a;
	}
	return Gcd(a, b%a);
  }
}

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

  int a, b;
  cin >> a >> b;
  
  cout << Gcd(a, b) << endl;
  return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
int n;
double x;
string s;
double ans=0;
signed main(){
	cin>>n;
	rep(i,n){
		cin>>x>>s;
		if(s=="JPY")ans+=x;
		else ans+=x*380000;
	}
	printf("%.12lf\n",ans);
	return 0;
}


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

int main()
{
  int n,k;
  cin>>n>>k;
  
  vector<int> h(n);
  for(int i=0;i<n;i++)
    cin>>h[i];
  
  vector<int> memo(n,1000000000);
  memo[0]=0;
  memo[1]=abs(h[1]-h[0]);
  
  for(int i=2;i<n;i++)
  {
    int j=i-1;
    if(k==1)
      memo[i]=memo[i-1]+abs(h[i]-h[i-1]);
    else
    {
      do
      {
      	memo[i]=min(memo[i],min(memo[j]+abs(h[i]-h[j]),memo[j-1]+abs(h[i]-h[j-1])));
      	j--;
      }while(i-j<k&&j>0);
    }
  }
  cout<<memo[n-1]<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <deque>


using namespace std;

typedef long long ll;
typedef vector<vector<int> > Graph;


int main(){
    int N;
    
    cin>>N;
    
    string s;
    cin>>s;
    ll popcount=0;
    
    for(int i=0;i<N;++i){
        if(s[i]=='1')++popcount;
    }
    //cout<<"popcount:"<<popcount<<endl;
    
    int pA[N];
    int mA[N];
    int a=1;
    ll pnum=0;
    ll mnum=0;
    
    for(int i=N-1;i>=0;--i){
        //cout<<a<<" ";
        pA[i]=a%(popcount+1);
        a=(a*2)%(popcount+1);
    }
    //cout<<endl;
    /*
     for(int i=0;i<N;++i){
        cout<<pA[i]<<" ";
    }
     */
    //cout<<endl;
    for(int i=0;i<N;++i){
        if(s[i]=='1'){
            pnum+=pA[i];
        }
    }
    pnum=pnum%(popcount+1);
    //cout<<"pnum:"<<pnum<<endl;
    int b=1;
    if(popcount!=1){
        for(int i=N-1;i>=0;--i){
            //cout<<b<<" ";
            mA[i]=b%(popcount-1);
            b=(b*2)%(popcount-1);
            
        }
        
        for(int i=0;i<N;++i){
            if(s[i]=='1'){
                mnum+=mA[i];
            }
        }
        mnum=mnum%(popcount-1);
        //cout<<"mnum:"<<mnum<<endl;
    }
    //cout<<endl;
    /*
     for(int i=0;i<N;++i){
     cout<<mA[i]<<" ";
     }
     */
    // cout<<endl;

    
    
    for(int i=0;i<N;++i){
        int count=1;
        if(s[i]=='0'){
            ll tmp=(pnum+pA[i])%(popcount+1);
            //cout<<"tmp1_1:"<<tmp<<endl;
            while(tmp>0){
                tmp=tmp%(__builtin_popcountll(tmp));
                //cout<<"tmp1:"<<tmp<<endl;
                ++count;
            }
        }else if(s[i]=='1'){
            if(popcount!=1){
                ll tmp=(mnum-mA[i])%(popcount-1);
                tmp=tmp>=0?tmp:(popcount-1+tmp);
                //cout<<"tmp2_2:"<<tmp<<endl;
                while(tmp>0){
                    tmp=tmp%(__builtin_popcountll(tmp));
                    //cout<<"tmp2:"<<tmp<<endl;
                    ++count;
                }
            }else{
                
                --count;
            }
        }
          cout<<count<<endl;
    }
}



Measured memory_bytes: 5276
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int H[100010];
int cnt[100010];
int main()
{
	int N, M;
	cin >> N >> M;
	for (int i = 0; i < N; i++) cin >> H[i];
	for (int i = 0; i < M; i++) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		cnt[A] = max(cnt[A], H[B]);
		cnt[B] = max(cnt[B], H[A]);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (H[i] > cnt[i]) ans++;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4412
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>

using namespace std;

int main()
{    
    int n, m, q;
    cin >> n >> m >> q;
    
    vector<vector<int>> a(n, vector<int>(n));
    
    for (int i = 0; i < m; i++) {
        int l, r;
        cin >> l >> r;
        
        a[l-1][r-1]++;
    }
    
    for (int i = 0; i < n; i++) {
        for (int j = 1; j < n; j++) {
            a[i][j] += a[i][j-1];
        }
    }
    
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        
        int sum = 0;
        
        for (int j = l-1; j <= r-1; j++) {
            sum += a[j][r-1];
        }
        
        cout << sum << endl;
    }
}


Measured memory_bytes: 1920
import java.util.*;
class Main {
    public static void main(String[] args) {
	Scanner sc = new Scanner(System.in);
	int H = sc.nextInt();
	int W = sc.nextInt();
	char[][] maze = new char[H+2][W+2];

	for(int i = 1; i<H+1; i++) {
	    String str = sc.next();
	    for(int j = 1; j<W+1; j++) {
		maze[i][j] = str.charAt(j-1);
	    }
	}

	long[][] way = new long[H+2][W+2];
	way[H][W] = 1;
	for(int i = H; i>0; i--) {
	    for(int j = W; j>0; j--) {
		if(maze[i][j] == '#') {
		    way[i][j] = 0;
		}else if(i== H && j == W) {
		    way[H][W] = 1;
		}else{
		    way[i][j] = way[i+1][j] + way[i][j+1];
		    way[i][j] %= 1000000000+7;
		}
	    }
	}
	System.out.println(way[1][1]);

    }
}

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

int main() {
    //
    int n, m, k;
    bool chk = false;

    cin >> n >> m >> k;

    for (int x = 0; x <= n; x++) {
        for (int y = 0; y <= m; y++) {
            if (m * x + n * y - x * y * 2 == k) {
                chk = true;
                break;
            }
        }
        if (chk == true) break;
    }

    if (chk == true)
        cout << "Yes";
    else
        cout << "No";
    //
}


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

#define rep(i, a, b) for(int i = (a); i < (b); ++i)
#define per(i, a, b) for(int i = (b)-1; i >= (a); --i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fst first
#define snd second

template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

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

int main() {
  cin.tie(0)->sync_with_stdio(0);
  cin.exceptions(cin.failbit);

  int n;
  cin >> n;

  ll ans= 0;
  rep(i,1,n+1) {
    if (i%3 !=0 and i%5!=0) ans += i;
  }
  cout<<ans<<'\n';
}

Measured memory_bytes: 3648
th = Math::PI * 60 / 180
@cos60 = 0.5
@sin60 = Math.sin(th)

class Point
  def initialize(x:, y:)
    @x = x.to_r
    @y = y.to_r
  end

  def to_s
    "#{x.to_f} #{y.to_f}"
  end

  attr_reader :x, :y
end

def koch(d, a, b)
  return if d == 0

  s = Point.new(
    x: (2 * a.x + 1 * b.x) / 3,
    y: (2 * a.y + 1 * b.y) / 3
  )
  t = Point.new(
    x: (1 * a.x + 2 * b.x) / 3,
    y: (1 * a.y + 2 * b.y) / 3
  )
  u = Point.new(
    x: (t.x - s.x) * @cos60 - (t.y - s.y) * @sin60 + s.x,
    y: (t.x - s.x) * @sin60 + (t.y - s.y) * @cos60 + s.y
  )

  koch(d - 1, a, s)
  puts s

  koch(d - 1, s, u)
  puts u

  koch(d - 1, u, t)
  puts t

  koch(d - 1, t, b)
end

n = gets.chomp.to_i
p1 = Point.new(x: 0, y: 0)
p2 = Point.new(x: 100, y: 0)

puts p1
koch(n, p1, p2)
puts p2


Measured memory_bytes: 7108
N = int(input())
ans = [0] * N
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            n = x**2 + y**2 + z**2 + x*y + y*z + z*x
            if n <= N:
                ans[n-1] += 1
for i in range(N):
    print(ans[i])

Measured memory_bytes: 9144
#include<bits/stdc++.h>
 
using namespace std;
 
int main(){

  string s;
  cin>>s;
  int c1=0,c2=0;
  int ptr1=0;
  int ptr2=1;
  for(int i=0;i<s.size();i++){
  	if(ptr1 != s[i]-'0'){
    	c1++;
    }
    
    ptr1 = !ptr1;
    
    if(ptr2 != s[i]-'0'){
    	c2++;
    }
    
    ptr2=!ptr2;
  }
  
  cout<<min(c1,c2);
  
  
  
	
}

Measured memory_bytes: 512
N = int(input())
F = []
for i in range(N):
    A = list(map(int, input().split()))
    F.append(A[::-1])

P = []
for i in range(N):
    A = list(map(int, input().split()))
    P.append(A)

result = float("inf")*(-1)
for i in range(1, 2**10):
    ans = 0
    for l in range(N):
        c = 0
        for j in range(10):
            if ((i>>j) & 1):
                if F[l][j] == 1:
                    c += 1
        ans += P[l][c]
    result = max(ans, result)
print(result)


Measured memory_bytes: 9148
/*
 * atcoder/abc132_2nd/d.cpp
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
template <class T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template <class T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
#define MOD 1000000007
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%MOD+MOD)%MOD){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%MOD+MOD)%MOD; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=MOD) x-=MOD; return *this;}
  mint& operator-=(const mint& a){ if((x+=MOD-a.x)>=MOD) x-=MOD; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=MOD; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
ostream & operator << (ostream & out, mint const & v) {
  out << v.x;
  return out;
}

/* nCk */
template<class T> struct BiCoef {
    vector<T> fact_, inv_, finv_;
    constexpr BiCoef() {}
    constexpr BiCoef(int n) noexcept : fact_(n, 1), inv_(n, 1), finv_(n, 1) {
        init(n);
    }
    constexpr void init(int n) noexcept {
        fact_.assign(n, 1), inv_.assign(n, 1), finv_.assign(n, 1);
        for(int i = 2; i < n; i++){
            fact_[i] = fact_[i-1] * i;
            inv_[i] = -inv_[MOD%i] * (MOD/i);
            finv_[i] = finv_[i-1] * inv_[i];
        }
    }
    constexpr T com(int n, int k) const noexcept {
        if (n < k || n < 0 || k < 0) return 0;
        return fact_[n] * finv_[k] * finv_[n-k];
    }
    constexpr T fact(int n) const noexcept {
        if (n < 0) return 0;
        return fact_[n];
    }
    constexpr T inv(int n) const noexcept {
        if (n < 0) return 0;
        return inv_[n];
    }
    constexpr T finv(int n) const noexcept {
        if (n < 0) return 0;
        return finv_[n];
    }
};

/*
 * 連続する青がi個である場合の数 i <- 1<=i<=K
 *
 * 区別のない青K個をk個に分割する方法はKHk = K-1Ck-1(区別なし、あり、1以上）
 * 区別のない赤N-K個をしきりk-1の位置左右+2合計k+1に配置する方法は、
 * しきりの位置には確実に置くのでN-K-(k-1) = N-K-k+1 (N-K-k+1)H(k+1)
 * M = N-K-k+1とおくと、
 * M個をk+1個に分割する方法は、M+k+1-1 C k+1-1 = M+k C k = N-K+1 C 
 */
int N, K;
BiCoef<mint> bc;
void solve() {
  cin >> N >> K;
  bc.init(2001);
  for (int k=1; k<=K; k++) {
    cout << bc.com(K-1, k-1) * bc.com(N-K+1, k) << endl;
  }
}
int main() {
  // cout.precision(15); cout << fixed;

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define MOD (long long) 1000000007
using namespace std;
typedef vector<long long> VI;
typedef vector<VI> VVI;

long inv_mod(long a,long long mod){
	long m = mod - 2;
	long long p = a;
	a = 1;
	while (m != 0){
		if (m & 1) {
			a = (a * p) % mod;
		}
		p = (p * p) % mod;
		m >>= 1;
	}
	
	return a;
}

VI nCr_all(long n){
    VI comb(2,0);
    if (n == 0) return comb;
    long long up = n;
    long long down = 1;
    long flg = 0;
    comb[0] = 1;
    comb[1] = up;
    if (n == 1) return comb;
    FOR(i,2,(n/2)+1){
    	comb.push_back((((((comb[i-1] + (flg * MOD)) % MOD) * (up - i + 1)) % MOD) * inv_mod((down + i - 1),MOD)));
    }

    VI comb_rev;
    RREP(i,comb.size()-1) comb_rev.push_back(comb[i]);

    if (n % 2) {
    	REP(i,comb_rev.size()) comb.push_back(comb_rev[i]);
    } 
    else {
    	FOR(i,1,comb_rev.size()) comb.push_back(comb_rev[i]);
    }
    return comb;
}

int main(void){
	long n;
	long a,first,second;
	cin >> n;
	vector<long> pos(n,0);
	REP(i,n+1) {
		cin >> a;
		if (pos[a-1] != 0) {
			second = i+1;
			first = pos[a-1];
		}
		pos[a-1] = i+1;
	}

	VI ans = nCr_all(n+1);
	//dump1d_arr(ans);
	VI minas = nCr_all(first-second+n);
	FOR(i,1,minas.size()) ans[i+1] -= minas[i];
	ans[1] -= 1;

	FOR(i,1,ans.size()) {
		ans[i] %= MOD;
		if (ans[i] < 0) ans[i] += MOD;
		cout << ans[i] << endl;
	}
	

	return 0;
}

Measured memory_bytes: 3820
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	x,y = readline() |> split |> parseMap
	if x*y<0
		println(abs(x+y)+1)
	elseif x<=y
		println(y-x)
	elseif y == 0 || x == 0
		println(x-y+1)
	else
		println(x-y+2)
	end
end

main()

Measured memory_bytes: 110208
x=int(input())
d={}
for a in range(10000000000000000000000000):
  aa=a**5
  m=x-aa
  if m in d:print(a,d[m]);exit()
  d[-aa]=a

  aa=-aa
  m=x-aa
  if m in d:print(a,d[m]);exit()
  d[-aa]=-a

Measured memory_bytes: 9132