akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//Binary_Indexed_Tree (Range_Sum_Query)
//(1-indexed)
const long long max_n = 1 << 20;
long long n;
long long bit[max_n+1]={0};
//i番目(1-indexed)までの和
long long sum(long long i){
    long long s = 0;
    if(i==0) return 0;
    while(i > 0){
        s += bit[i];
        i -= i & -i;
    }
    return s;
}
//i番目(1-indexed)にxを加える
void add(long long i,long long x){
    while(i <= n){
        bit[i] += x;
        i += i & -i;
    }
}
int main() {
    // your code goes here
    ll i,j,d,a,x[200005],h[200005],r[200005],l[200005],pb=1,ko[200005],ans=0,k;
    vector<pair<ll,ll>> v;
    vector<ll> vx;
    cin >> n >> d >> a;
    d*=2;
    for(i=0;i<n;i++){
        cin >> x[i] >> h[i];
        if(h[i]%a==0) h[i]/=a;
        else h[i]=(h[i]-h[i]%a)/a+1;
        v.push_back({x[i],h[i]});
        vx.push_back(x[i]);
    }
    v.push_back({-1,0});
    vx.push_back(-1);
    sort(v.begin(),v.end());
    sort(vx.begin(),vx.end());
    for(i=1;i<=n;i++){
        x[i]=v[i].first;
        h[i]=v[i].second;
    }
    for(i=1;i<=n;i++){
        auto it=upper_bound(vx.begin(),vx.end(),x[i]+d);
        it--;
        r[i]=(it-vx.begin());
    }
    for(i=1;i<=n;i++){
        while(pb<=r[i]){
            l[pb]=i;
            pb++;
        }
    }
    for(i=1;i<=n;i++){
        k=h[i]-min(sum(i)-sum(l[i]-1),h[i]);
        add(i,k);
        ans+=k;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14828
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <utility>
#include <string>
#include <stack>
#include <regex>
#include <numeric>
#include <queue>
#include <set>

#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;

int main(int argc, char const *argv[])
{
  while (true)
  {
    ll n;
    cin >> n;
    if (n == 0)
      return 0;
    ll mean = 0;
    vector<ll> a(n);
    REP(i, n)
    {
      cin >> a[i];
      mean += a[i];
    }
    ll res = 0;
    REP(i, n)
    {
      if (a[i] * n <= mean)
        res++;
    }
    cout << res << endl;
  }
  return 0;
}



Measured memory_bytes: 3172
#include<cstdio>
#include<cstring>
#define inlien inline
#define retrun return
#define cpnst const
typedef long long ll;
const ll mod=1e9+7;
ll tmp[111111],fac[111111],inv[111111];
inline ll qpow(ll x,ll k)
{ll r=1;for(;k;k>>=1,(x*=x)%=mod)if(k&1)(r*=x)%=mod;retrun r;}
ll F[111111],G[111111],m;
inline void mul(register ll*x,register ll*y)
{
	register int i,ii;
	for(i=0;i<=m;i++)
		for(ii=0;ii<=i;ii++)
			(tmp[i]+=x[i-ii]*y[ii])%=mod;
	for(i=0;i<=m;i++)x[i]=tmp[i],tmp[i]=0;
}
inline void qpow(ll k)
{for(;k;k>>=1,mul(F,F))if(k&1)mul(G,F);}
inline ll Ca(ll n)
{return fac[n*2]*inv[n]%mod*inv[n+1]%mod;}
inline ll Fs(int n,int r)
{
	register int i;
	for(i=0;i<=r;i++)F[i]=Ca(i),G[0]=1;
	m=r,qpow(n);
	ll ret=G[r];
	if(n^1)(ret*=qpow(2,n-2))%=mod;
	return ret;
}
int main()
{
	inv[0]=fac[0]=1;
	register int i;
	for(i=1;i<=100000;i++)fac[i]=fac[i-1]*i%mod;
	for(i=99999,inv[i+1]=qpow(fac[i+1],mod-2);i;i--)
		inv[i]=inv[i+1]*(i+1)%mod;
	int n,k;
	scanf("%d%d",&n,&k),printf("%lld\n",Fs(n-k+1,k-1));
}
/*
Giving the world a better yourself is giving yourself a better world. 
*/

Measured memory_bytes: 2560
#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 SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

vector<int> prime;
vector<int> ls;

void sieve(int N){
    prime.resize(N+1,1);
    prime[0] = prime[1] = 0;
    for(int i=2;i*i<=N;i++){
        for(int j=i*i;j<=N;j+=i){
            prime[j] = 0;
        }
    }
    for(int i=2;i<=N;i++){
        if(prime[i])ls.push_back(i);
    }
}

int main() {
    sieve(int(1e6));
    int n, p;
    vector<int> v;
    while(cin >> n >> p, n>=0){
        int k = upper_bound(ALL(ls),n)-ls.begin();
        v.clear();
        for(int i=0;i<=200;i++){
            for(int j=i;j<=200;j++){
                v.push_back(ls[i+k]+ls[j+k]);
            }
        }
        SORT(v);
        cout << v[p-1] << endl;
    }
    return 0;
}


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

keta=len(bin(max(K,max(A)))[2:])

#２進数の各桁の1と0の数をカウント ただし、左から数えた桁数（100の場合1から）
cnt1=[0]*keta
cnt0=[0]*keta

for i in range(len(A)):
  for j in range(keta):
    if (A[i]>>j)&1:
      cnt1[keta-1-j]+=1
    else:
      cnt0[keta-1-j]+=1

#Kを２進数表記したものを左から桁DP。
#dp[桁数][未満フラグ][0,1を選んだ場合]　その値
Ks=bin(K)[2:].zfill(keta)
dp=[[[0 for i in range(2)] for j in range(2)] for k in range(len(Ks))]
# 桁diと0 or 1を渡すと値を返してくれる
def calc(di,v):
  unit=2**(keta-1-di)
  if v==0:
    return cnt1[di]*unit
  else:
    return cnt0[di]*unit
    
x0=int(Ks[0])
dp[0][0][0]=(0 if x0==1 else calc(0,0))
dp[0][0][1]=(0 if x0==0 else calc(0,1))
dp[0][1][0]=(0 if x0==0 else calc(0,0))
dp[0][1][1]=0

for i in range(1,len(dp)):
  x=int(Ks[i])
  if x==0:
    dp[i][0][0]=dp[i-1][0][0]+dp[i-1][0][1]+calc(i,0)
    dp[i][0][1]=0
  else:
    dp[i][0][0]=0
    dp[i][0][1]=dp[i-1][0][0]+dp[i-1][0][1]+calc(i,1)
  dp[i][1][0]=max(dp[i-1][0][0]*(x==1),dp[i-1][0][1]*(x==1),dp[i-1][1][0],dp[i-1][1][1])+calc(i,0)
  dp[i][1][1]=max(dp[i-1][1][0],dp[i-1][1][1])+calc(i,1)

ans=0
for i in range(2):
  for j in range(2):
    if ans<dp[len(dp)-1][i][j]:
      ans=dp[len(dp)-1][i][j]

print(ans)

# 0と1で多い方を選べればOK。選べるかどうかは桁DPで上から見ていく
# 
# 0001
# 0110
# 0011

# 0100

# 0111
# 0100
# 0000
# 0011

# 1000

# 1111
# 1100
# 1000
# 1011


Measured memory_bytes: 14660
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define all(x) begin((x)), end((x))
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    long double n,m,d;
    cin>>n>>m>>d;
    long double ans = (n-d) * 2 * (m-1) / (n*n);
    if (d==0) {
        ans = (m-1) / n;
    }
    printf("%.10Lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int a,b,c,d=0;cin>>a>>b>>c;
while(true){
    a-=b;
    d+=c;
    if(a<=0)
        break;
}cout<<d<<endl;
return 0;}


Measured memory_bytes: 3604
#pragma GCC optimize("O3")
#pragma GCC target("sse4.1")

#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define fst first
#define snd second
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define ford(i, n) for (int i = ((int)(n) - 1); i >= 0; --i)
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef pair<int, int> pii;
typedef vector<pii> vii;
#define sz(c) (int)(c).size()
#define all(c) (c).begin(), (c).end()

#ifdef LOCAL
#define eprintf(args...) fprintf(stderr, args), fflush(stderr);
#else
#define eprintf(args...) ;
#endif

int n, m;
string s, t;

bool read ()
{
    if (!(cin >> n >> m))
        return false;
    cin >> s >> t;
    return true;
}

ll solve ()
{
    const ll total = ll(n) * m;
    map<ll, char> who;
    forn (i, 2)
    {
        const string cur = (i == 0 ? s : t);
        forn (j, sz(cur))
        {
            auto it = who.find((ll)j * total / sz(cur));
            if (it != who.end() && it -> snd != cur[j])
                return -1;
            else
                who[(ll)j * total / sz(cur)] = cur[j];
        }
    }

    return total / __gcd(n, m);
}

int32_t main()
{
#ifdef LOCAL
    freopen("input.txt", "rt", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
    {
        auto ans = solve();
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n;
long long ans;
char s2[10];
string s[123456],h;
signed main(){
	cin>>n;
	for(int i=0;i<n;i++){
		for(int j=0;j<10;j++)cin>>s2[j];
		sort(s2,s2+10);
		s[i]={s2[0],s2[1],s2[2],s2[3],s2[4],s2[5],s2[6],s2[7],s2[8],s2[9]};
	}
	sort(s,s+n);
	h=s[0];
	int count=1;
	for(int i=1;i<n;i++){
		if(h==s[i])count++;
		else{
			ans+=(count*(count-1))/2;
			h=s[i];
			count=1;
			
		}
	}
	ans+=(count*(count-1))/2;
	cout<<ans<<endl;
}


Measured memory_bytes: 7808
package main

import (
  "fmt"
)

func main() {
  var n, d, x int 
  fmt.Scan(&n, &d, &x)
  for i := 0; i < n; i++ {
    var a int 
    fmt.Scan(&a)
    x += 1 + (d - 1) / a
  }
  fmt.Println(x)
}

Measured memory_bytes: 512
//20190622
#include <iostream>
#include <vector>
using namespace std;

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

    int count = 0;
    int ans=0;

    for(int i=0; i<s.size();i++){
        if(s[i]== 'A' || s[i]=='C' || s[i]=='G' || s[i]=='T'){
            count++;
        }
        else{
            ans = max(count, ans);
            count = 0;
        }
    }
    ans = max(count, ans);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};

const int M_N=200001;

struct UnionFind{
    int par[M_N];
    int rank[M_N];
    int sz[M_N];

    void init(int n){
        for(int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
            sz[i]=1;
        }
    }

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

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

    bool same(int x,int y){
        return find(x)==find(y);
    }
    int get(int x){
        return sz[find(x)];
    }
};

int main(){
    int n,m,k;cin >> n >> m >> k;
    UnionFind uf;
    uf.init(n);
    vector<int> ans(n,n-1);
    for (int i = 0; i < m; i++) {
        int a,b;cin >> a >> b;
        a--,b--;
        uf.unite(a,b);
        ans[a]--;
        ans[b]--;
    }
    vector<int> a(k),b(k);
    for (int i = 0; i < k; i++) {
        cin >> a[i] >> b[i];
        a[i]--,b[i]--;
        if(uf.same(a[i],b[i])){
            ans[a[i]]--;
            ans[b[i]]--;
        }
    }
    for (int i = 0; i < n; i++) {
        ans[i] -= (n-uf.get(i));
    }
    for (int i = 0; i < n; i++) {
        cout << ans[i] << (i==n-1?"\n":" ");
    }
    return 0;
}


Measured memory_bytes: 3584
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
vector<int> al, bl;
int main() {
    int n;
    cin >> n;
    vector<ll> vec;
    int count = 0;
    ll ret = 0;
    for (int i = 1; i <= n; i++) {
        ll a;
        cin >> a;
        if (a < 0) {
            count++;
            a *= -1;
        }
        ret += a;
        vec.push_back(a);
    }
    sort(vec.begin(), vec.end());
    if (count % 2) {
        ret -= vec[0] * 2;
    }
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 4316
#include<bits/stdc++.h>
#define N 3
using namespace std;
typedef unsigned long long ull;
bool im[1010][1010],pa[110][110];
int w,h,p,ans;
vector<ull> used;

void ppp(){
 ull a=0;
 ull roll[1001][1001]={};
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)a=a*N+pa[i][j];
 for(int i=0;i<used.size();i++)
   if(used[i]==a)return;
 used.push_back(a);
 for(int j=0;j<h;j++){
   ull b=0,g=1;
   for(int i=0;i<p;i++)b=b*N+im[j][i],g*=N;
   roll[j][p-1]=b;
   for(int i=p;i<w;i++){
     b=b*N+im[j][i]-im[j][i-p]*g;
     roll[j][i]=b;
   }
 }
 for(int j=p-1;j<w;j++){
   ull b=0,g=1,n=1;
   for(int i=0;i<p;i++)n*=N;
   for(int i=0;i<p;i++)b=b*n+roll[i][j],g*=n;
   if(b==a)ans++;
   for(int i=p;i<h;i++){
     b=b*n+roll[i][j]-roll[i-p][j]*g; 
     if(b==a)ans++;
   }
 }
}

void ch(){
 bool npa[110][110];
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)npa[i][j]=pa[j][p-i-1];
 for(int i=0;i<p;i++)
   for(int j=0;j<p;j++)pa[i][j]=npa[i][j];
}

void ch1(){
 for(int i=0;i<p;i++)
   for(int j=0;j<p/2;j++)swap(pa[i][j],pa[i][p-j-1]);
}

int main(){
 int D[256];
 for(int i='A';i<='Z';i++)D[i]=i-'A';
 for(int i='a';i<='z';i++)D[i]=i-'a'+26;
 for(int i='0';i<='9';i++)D[i]=i-'0'+52;
 D['+']=62,D['/']=63;
 while(cin>>w>>h>>p,w){
   string s;
   used.clear();
   for(int i=0;i<h;i++){
     cin>>s;
     for(int j=0;j<s.size();j++){
       int t=D[s[j]],a=6;
	while(a--)im[i][j*6+a]=t%2,t/=2;
     }
   }
   for(int i=0;i<p;i++){
     cin>>s;
     for(int j=0;j<s.size();j++){
       int t=D[s[j]],a=6;
	while(a--)pa[i][j*6+a]=t%2,t/=2;
     }
   }
   ans=0;
    for(int i=0;i<4;i++){
     ppp();
     ch1();
     ppp();
     ch1();
     ch();
   }
   cout<<ans<<endl;
 }
 return 0;
}

Measured memory_bytes: 10060
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

def main(A, X, Y):
    N = len(A)
    count = np.zeros(N + 1, np.int64)
    covered = np.zeros(N + 1, np.int64)
    for x in A:
        count[x] += 1
        y = x - count[x] + 1
        if y > 0:
            covered[y] += 1
    spell = np.sum(covered[1:] == 0)
    for i in range(len(X)):
        x, y = X[i], Y[i]
        before = A[x - 1]
        after = y
        A[x - 1] = y
        rem = before - count[before] + 1
        count[before] -= 1
        add = after - count[after]
        count[after] += 1
        if rem > 0:
            covered[rem] -= 1
            if not covered[rem]:
                spell += 1
        if add > 0:
            if not covered[add]:
                spell -= 1
            covered[add] += 1
        print(spell)

if sys.argv[-1] == 'ONLINE_JUDGE':
    import numba
    from numba.pycc import CC
    i8 = numba.from_dtype(np.int64)
    signature = (i8[:], i8[:], i8[:])

    cc = CC('my_module')
    cc.export('main', signature)(main)
    cc.compile()

from my_module import main

N, M = map(int, readline().split())
A = np.array(readline().split(), np.int64)
XY = np.array(read().split(), np.int64)
X = XY[::2]
Y = XY[1::2]

main(A, X, Y)

Measured memory_bytes: 54020
#include <iostream>
#include <vector>
#include <utility>

std::vector< std::pair<char,int> > bubbleSort(std::vector< std::pair<char,int> > );
std::vector< std::pair<char,int> > selectionSort(std::vector< std::pair<char,int> >);
bool stable_judge(std::vector< std::pair<char,int> >,std::vector< std::pair<char,int> >);

int main(int argc, char const *argv[]){
	int N;
	std::cin >> N;
	std::vector< std::pair<char,int> > input;

	for (int i = 0; i < N; ++i){
		std::string buff;
		std::cin >> buff;
		input.push_back(std::make_pair(buff[0],buff[1]-'0'));
	}

	std::vector< std::pair<char,int> > bubble = bubbleSort(input);
	std::vector< std::pair<char,int> > select = selectionSort(input);

	for (int i = 0; i < N; ++i){
		std::cout << bubble[i].first << bubble[i].second;
		if(i<N-1)std::cout << " ";
	}
	std::cout << std::endl;

	if(stable_judge(input,bubble)){
		std::cout << "Stable" << std::endl;
	}else{
		std::cout << "Not Stable" << std::endl;		
	}

	for (int i = 0; i < N; ++i){
		std::cout << select[i].first << select[i].second;
		if(i<N-1)std::cout << " ";
	}
	std::cout << std::endl;

	if(stable_judge(input,select)){
		std::cout << "Stable" << std::endl;
	}else{
		std::cout << "Not stable" << std::endl;		
	}


	return 0;
}

std::vector< std::pair<char,int> > bubbleSort(std::vector< std::pair<char,int> > fig){
	for (int i = 0; i < fig.size(); ++i){
		for (int j = fig.size()-1; j > i ; --j){
			if(fig[j].second<fig[j-1].second){
				std::pair<char,int> buff = fig[j];
				fig[j] = fig[j-1];
				fig[j-1] = buff;
			}				
		}
	}
	return fig;
}

std::vector< std::pair<char,int> > selectionSort(std::vector< std::pair<char,int> > fig){
	for (int i = 0; i < fig.size(); ++i){
		int minj = i;
		for (int j = i; j < fig.size(); ++j){
			if(fig[j].second < fig[minj].second){
				minj = j;
			}				
		}
		if(i!=minj){
			std::pair<char,int> buff = fig[i];
			fig[i] = fig[minj];
			fig[minj] = buff;
		}
	}
	return fig;
}

bool stable_judge(std::vector< std::pair<char,int> > before, std::vector< std::pair<char,int> > after){

	while(!before.empty()){

		std::string str_before;
		std::string str_after;
		int fig = after[0].second;

		for (int i = 0; i < before.size(); ++i){
			if(fig==before[i].second){
				str_before += before[i].first;
				before.erase(before.begin() + i);
				i -= 1;
			}
		}

		for (int i = 0; i < after.size(); ++i){
			if(fig==after[i].second){
				str_after += after[i].first;
				after.erase(after.begin() + i);
				i -= 1;
			}
		}
		if(str_before != str_after)return false;
	}
	return true;
}



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

int main() {
	int n; cin >> n;
	vector<int>l(n); for (auto&& x : l)cin >> x;

	long long ans = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i+1; j < n; j++) {
			for (int k = j + 1; k < n; k++) {
				int len = l[i] + l[j] + l[k];
				int maxi = max({ l[i], l[j], l[k] });
				int res = len - maxi;

				if (maxi < res)ans++;
			}
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
N, Q = map(int,input().split())
s = [list(map(int,input().split())) for _ in range(N-1)]
p = [list(map(int,input().split())) for _ in range(Q)]

#各節点の親と自分を頂点とする部分木のカウントの和
parent = [0] * (N+1)
count = [0] * (N+1)
for t in s:
    parent[t[1]] = t[0]
for u in p:
    count[u[0]] += u[1]

dp = [0] * (N+1)
for i in range(1,N+1):
    dp[i] = dp[parent[i]] + count[i]

for i in dp[1:]:
    print(i, end=' ')


Measured memory_bytes: 121312
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n; cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    for(int i=0;i<n;i++){
        cin >> x[i] >> y[i];
    }
    float ans=0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans+=pow((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]), 0.5)*2/n;
        }
    }
    cout << fixed <<setprecision(10) << ans <<endl;
    return 0;
}



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

using namespace std;

#define pii pair<int,int>
#define point pair<double,double>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define PI acos(-1)
#define MOD 1e9+7
#define ll long long int
bool B[100005];
vector<pii>A[100005];
map<pii,ll>M;
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=0;i<n-1;i++)
    {
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        A[a].pb(mp(b,c));
        A[b].pb(mp(a,c));
    }
    int q,k;
    scanf("%d %d",&q,&k);
    queue<int>Q;
    queue<ll>D;
    Q.push(k);
    D.push(0);
    B[k]=1;
    while(!Q.empty())
    {
        int tq=Q.front();Q.pop();
        ll td=D.front();D.pop();
        M[mp(k,tq)]=td;
        for(auto x:A[tq])
        {
            if(B[x.fi])continue;
            B[x.fi]=1;
            Q.push(x.fi);
            D.push(td+x.se);
        }
    }
    while(q--)
    {
        int x,y;
        cin>>x>>y;
        cout<<M[mp(k,x)]+M[mp(k,y)]<<endl;
    }
	return 0;
}


Measured memory_bytes: 15616
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
//------------------------------------------------------------

		Scanner sc =new Scanner(System.in);
		int N = sc.nextInt();
		int X = sc.nextInt();
		int min =1000;
		for(int i = 0 ; i < N; i++) {
			int m = sc.nextInt();
			X -= m;
			min = Math.min(m, min);
		}
		int smallDonuts =X/min ;
		int ans = N+smallDonuts;
		System.out.println(ans);
		sc.close();

//------------------------------------------------------------
	}
}

Measured memory_bytes: 22996
#define _USE_MATH_DEFINES
 
#pragma GCC optimize("Ofast,no-stack-protector") 
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") 
#pragma GCC optimize("unroll-loops") 
#pragma GCC optimize("fast-math")
  
#include <bits/stdc++.h> 
  
using namespace std;
  
#define $(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define endl '\n'
#define x first
#define y second    
// #define int long long
#define double long double       
#define vec vector            
#define pb push_back
#define pii pair<int, int>
#define pdd pair<double, double> 
#define beg begin
#define print(x) cout << (x) << endl;
  
#ifdef LOCAL
    #define dbg(x) cerr << #x << " = " << x << endl;
#else 
    #define dbg(x)
#endif 
  
template<class T> ostream& operator<<(ostream &str, vector<T> &a) {
    for (auto &i : a) {
        str << i << " ";
    }
    return str;
}
  
template<class T> istream& operator>>(istream &str, vector<T> &a) {
    for (auto &i : a) {
        str >> i; 
    }
    return str;
}
  
template<class T> ostream& operator<<(ostream &str, pair<T, T> &a) {
    str << a.first << " " << a.second;
    return str;
}
  
template<class T> istream& operator>>(istream &str, pair<T, T> &a) {
    str >> a.first >> a.second;
    return str;
}
 
void solve(); signed main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);                                       
    // freopen("output.txt", "w", stdout);
#endif
    srand(time(0));
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cout.setf(ios::fixed); cout.precision(6);
    solve();   
    return 0;
}

void solve() {
    string s;
    cin >> s;
    if (s == "SUN") {
        print(7);
    }
    else if (s == "MON") {
        print(6);
    }
    else if (s == "TUE") {
        print(5);
    }
    else if (s == "WED") {
        print(4);
    }
    else if (s == "THU") {
        print(3);
    }
    else if (s == "FRI") {
        print(2);
    }
    else {
        print(1);
    }
}




Measured memory_bytes: 256
#!/usr/bin/python3

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


def main():
    N = int(input())
    dp = [0] * 100
    dp[0] = 2
    dp[1] = 1
    for i in range(2, 100):
        dp[i] = dp[i - 1] + dp[i - 2]
    print(dp[N])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3960
#include <bits/stdc++.h>
#define int long long
using namespace std;
int mod = 1000000007;
int inf = INT_MAX;
int m_inf = INT_MIN;
int dp[100001][2];


int32_t main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	std::cout.unsetf ( std::ios::floatfield );
	std::cout.precision(6);
	int a,b;
	cin>>a>>b;
	double x1 = a/0.08,y1 = (a+1)/0.08;
	double x2 = b/0.1,y2 = (b+1)/0.1;	
	double temp;
	/*cout<<x1<<' '<<y1<<'\n';
	cout<<x2<<' '<<y2<<'\n';*/
	if(y2<=x1 || y1<=x2)
	{
		cout<<-1<<'\n';
		return 0;
	}
	for(double i = 1;i<=10000;i++)
	{
		if((int)(0.08*i) == a && (int)(0.1*i) == b)
		{
			cout<<i<<'\n';
			return 0;
		}
	}
	cout<<-1<<'\n';
	
}

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

int main(){
	double a,b,x;
	cin >> a >> b >> x;
	if(a*a*b/2 <= x) {
			printf("%lf\n", atan(2*(a*a*b-x)/(a*a*a)) * 180 / M_PI);
	} else {
		if(a*a*b-2*x >= 0) {
			printf("%lf\n", atan((a*b*b)/(2*x)) * 180 / M_PI);
		} else {
			printf("%lf\n", atan((2*x)/(a*a*a)) * 180 / M_PI);
		}
	}
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  if(a==7&&b==5&&b==5||b==7&&a==5&&c==5||c==7&&a==5&&b==5)
    cout<<"YES";
  else cout<<"NO";
  return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

public class Main {

    public static void main(String[] args) throws Exception {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }

        int n = Integer.valueOf(mylist.get(0).split(" ")[0]);
        int k = Integer.valueOf(mylist.get(0).split(" ")[1]);

        HashSet<String> hs = new HashSet<String>();
        int cnt = 0;
        while (cnt < k) {
            String arr_temp[] = mylist.get((cnt + 1) * 2).split(" ");
            for (String v : arr_temp) {
                hs.add(v);
            }
            cnt += 1;

        }
        System.out.println(n - hs.size());

    }

}


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

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

    vector<long> P(N);
    for (int i = 0; i < N; i++)
    {
        cin >> P.at(i);
    }

    vector<long> C(N);
    for (int i = 0; i < N; i++)
    {
        cin >> C.at(i);
    }

    long ans = C.at(0);
    for (int j = 0; j < N; j++)
    {
        long point = C.at(j);
        long max = C.at(j);
        int position = P.at(j) - 1;

        int cnt = 1;
        for (int i = 1; i < N && i < K && position != j; i++)
        {
            point += C.at(position);
            if (point >= max)
            {
                max = point;
            }
            position = P.at(position) - 1;
            cnt++;
        }

        if (K > cnt)
        {
            long point2 = point;
            long max2 = point;

            int mod = K % cnt;
            for (int i = 0; i < cnt; i++)
            {
                point2 -= C.at(position);
                if (point2 >= max2)
                {
                    max2 = point2;
                    mod = K % cnt + i + 1;
                }
                position = P.at(position) - 1;
            }

            long max3 = point * ((K / cnt) - 1) + max2;

            max2 = 0;
            point2 = 0;
            for (int i = 0; i < mod; i++)
            {
                point2 += C.at(position);
                if (point2 >= max2)
                {
                    max2 = point2;
                }
                position = P.at(position) - 1;
            }

            max3 += max2;

            if (max3 > max)
            {
                max = max3;
            }
        }

        if (max > ans)
        {
            ans = max;
        }
    }

    cout << ans << endl;

    return 0;
}

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

void north();
void east();
void right();


int status[6];

int main(){
	int n,m,i=0,j=0,k=0;
	int score;
	string input;
	
	
	while(j<5){
	status[0]=1;
	status[1]=2;
	status[2]=3;
	status[3]=4;
	status[4]=5;
	status[5]=6;
	score=1;
	
		cin>>n;
		if(n==0)break;
		
		for(i=0;i<n;i++){
			cin>>input;
			if(input[0]=='N'){north();}
			else if(input[0]=='S'){north();north();north();}
			else if(input[0]=='E'){east();}
			else if(input[0]=='W'){east();east();east();}
			else if(input[0]=='L'){right();}
			else if(input[0]=='R'){right();right();right();}
			score+=status[0];
			
				}
		cout<<score<<endl;
		j++;
	}
	
	return 0;
	}
	
void north(){
	swap(status[0],status[4]);
	swap(status[1],status[5]);
	swap(status[0],status[5]);
}
void east(){
	swap(status[0],status[2]);
	swap(status[5],status[3]);
	swap(status[0],status[5]);
}
void right(){
	swap(status[1],status[2]);
	swap(status[4],status[3]);
	swap(status[1],status[4]);
}



Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n;
  cin >> n;
  if (n == 1) {
    cout << "Hello World" << endl;
    return 0;
  }
  ll a, b;
  cin >> a >> b;
  cout << a + b << endl;


  return 0;
}


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

#define N_size 100000000000

using namespace std;

int mygcd(long long x,long long y){
    if(x <= y){
        if(x == 0)
            return y;
        else
            return mygcd(y%x,x);      
    }else{
        if(y == 0)
            return x;
        else
        {
            return mygcd(y,x%y);
        }
        
    }
}

int main(){
    long long N;
    cin >> N;
    long long min_gcd = N_size;
    vector<long long> A(N);

    for(long long i = 0;i < N;i++){
        cin >> A.at(i);
    }

    for(long long i = 0;i < N - 1;i++){
        if(min_gcd > mygcd(A.at(i),A.at(i+1)))
            min_gcd = mygcd(A.at(i),A.at(i+1));
        if(min_gcd == 1)
            break;

    }

    cout << min_gcd << endl;

    

}

Measured memory_bytes: 1024
N = int(input())

simoniketa = int(str(N)[-2:])
more_100 = int(str(N)[:-2] + "00")
#print(simoniketa)

#print(simoniketa/5)
#print(more_100)

if more_100 >= simoniketa/5 * 100:
  print(1)
else:
  print(0)

Measured memory_bytes: 38256
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

using ll = long long;
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  if(n % 1000 == 0) {
    cout << 0 << endl;
    return 0;
  }
  cout << 1000 - n % 1000 << endl;
  return 0;
}


Measured memory_bytes: 3648
use std::io::Read;

macro_rules! get {
      ($t:ty) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.trim().parse::<$t>().unwrap()
          }
      };
      ($($t:ty),*) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              let mut iter = line.split_whitespace();
              (
                  $(iter.next().unwrap().parse::<$t>().unwrap(),)*
              )
          }
      };
      ($t:ty; $n:expr) => {
          (0..$n).map(|_|
              get!($t)
          ).collect::<Vec<_>>()
      };
      ($($t:ty),*; $n:expr) => {
          (0..$n).map(|_|
              get!($($t),*)
          ).collect::<Vec<_>>()
      };
      ($t:ty ;;) => {
          {
              let mut line: String = String::new();
              std::io::stdin().read_line(&mut line).unwrap();
              line.split_whitespace()
                  .map(|t| t.parse::<$t>().unwrap())
                  .collect::<Vec<_>>()
          }
      };
      ($t:ty ;; $n:expr) => {
          (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
      };
}

fn main() {
    let mut buf = String::new();

    let (h, w) = get!(usize, usize);
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.chars();

    let mut table: Vec<Vec<char>> = Vec::new();

    for _ in 0..h {
        let mut lrt: Vec<char> = (0..w + 1).map(|_| iter.next().unwrap()).collect();
        table.push(lrt);
    }

    let mut ans = "Yes";

    if h < 2 || w < 2 {
        if buf.contains('#') {
            println!("No");
        } else {
            println!("Yes");
        }
        return;
    }

    for i in 0..h {
        for j in 0..w {
            // 塗対象でなければ無視
            if table[i][j] == '.' {
                continue;
            }

            let up = if i != 0 { table[i - 1][j] } else { '.' };
            let down = if i != h - 1 { table[i + 1][j] } else { '.' };
            let left = if j != 0 { table[i][j - 1] } else { '.' };
            let right = if j != w - 1 { table[i][j + 1] } else { '.' };

            if up == '.' && down == '.' && left == '.' && right == '.' {
                ans = "No";
                break;
            }
        }
    }

    println!("{}", ans);
}


Measured memory_bytes: 4352
use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

fn main() {
    input! {
        n: usize,
        mut plan: [String; n],  // Vec<(i32, i32, i32)>
    }
    let mut ac = 0;
    let mut wa = 0;
    let mut tle = 0;
    let mut re = 0;
    for r in plan {
        if r == "AC" {
            ac += 1;
        } else if r == "WA" {
            wa += 1;
        } else if r == "TLE" {
            tle += 1;
        } else if r == "RE" {
            re += 1;
        }
    }
    println!("AC x {}", ac);
    println!("WA x {}", wa);
    println!("TLE x {}", tle);
    println!("RE x {}", re);
}


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

int n;
int m;

vector<int> v[100002];

int dp[100002];

deque<pair<int, int> > d;


int main(){
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		int a, b;
		scanf("%d%d", &a, &b);
		a--;
		b--;
		v[b].push_back(a);
	}
	dp[0] = 0;
	int cut = 0;
	int cnt = 0;
	for (int i = 1; i < n; i++){
		sort(v[i].begin(), v[i].end());
		int can = 0;
		if (v[i].size()){
			can = v[i].back() + 1;
		}
		if (cut < can){
			cut = i;
			cnt++;
		}
	}
	cout << cnt << endl;
	return 0;
}

Measured memory_bytes: 4864
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;
const int INF= 1e9+5;
typedef long long ll;

int main(){
  string s;
  cin>>s;
  string ans=s;
  for(int i=0;i<3;i++){
    if(s[i]=='9')ans[i]='1';
    if(s[i]=='1')ans[i]='9';
  }
  cout<<ans<<endl;
      
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main(){
  char ch,a;
  scanf("%c",&ch);
  a='\n';
  while(!(a==ch)){
    if(islower(ch)){
      printf("%c",toupper(ch));}
    else printf("%c",tolower(ch));
    scanf("%c",&ch);
    }
  printf("%c",a);
  return 0;}

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

int main(){
  int a,b,array[101],c,i,d;
  cin>>a>>b>>c>>d;
  if(a<=c){
    if(b>c){
      if(d>b){
      cout<<b-c;
      }else{
        cout<<d-c;
      }
    }else{
      cout<<0;
    }
  }else{
    if(d>a){
      if(b>d){
      cout<<d-a;
      }else{
        cout<<b-a;
      }
    }else{
      cout<<0;
    }
  }
  cout<<endl;
}
      
  


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <string>
using namespace std;
#define ll long long int

int main(){ 
  int n;cin >> n;
  double ans = 0;
  for(int i = 0; i < n; ++i){
    double x;string u;
    cin >> x >> u;
    if(u == "BTC") x *= 380000;
    ans += x;  
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const* argv[])
{
	int n;
	cin >> n;
	int a = n / 1000;
	int b = (n / 100) % 10;
	int c = (n / 10) % 10;
	int d = n % 10;
	int w[2];
	w[0] = 1;
	w[1] = -1;
	for(int i = 0; i < 2; i++){
			for(int j = 0; j < 2; j++){
					for(int k = 0; k < 2; k++){
							int res = a + w[i] * b + w[j] * c + w[k] * d;
							if(res == 7){
									cout << a << (i == 0 ? "+" : "-") << b << (j == 0 ? "+" : "-") << c << (k == 0 ? "+" : "-") << d << "=7" << endl;
									return 0;
							}
					}
			}
	}
	return 0;
}


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

int main() {
  ll n,ans = 0;
  cin >> n;
  for(int i = 1;i <= n;i++){
    if(i%3 != 0 && i%5 != 0) ans += i;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3580
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#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 999999999
using namespace std;

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

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


int main(){
	ios::sync_with_stdio(false);

	int w, n;
	int a, b;
	char s;

	cin >> w;
	cin >> n;

	vi bar(w);

	REP(i, w)
		bar[i] = i + 1;

	while (n!=0){
		cin >> a >> s >> b;



		swap(bar[a - 1], bar[b - 1]);
		n--;
	}

	REP(i, w)
		printf("%d\n", bar[i]);
}

Measured memory_bytes: 3224
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int n = scanner.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; ++i) {
			a[i] = scanner.nextInt();
		}
		for (int i = n - 1; i >= 0; --i) {
			System.out.print(a[i]);
			if (i != 0) System.out.print(' ');
		}
		System.out.println();
	}
}



Measured memory_bytes: 26092
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define MP make_pair
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
#define SET(a,c) memset(a,c,sizeof(a))

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

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll INF = INT_MAX/3;
const ll MOD = 1000000007;
const double EPS = 1e-14;
const int dx[] = {1,0,-1,0} , dy[] = {0,1,0,-1};

ll modPow(ll a,ll b,ll MOD){
    ll p = 1;
    while( b ){
        if( b&1 ){
            p = (p*a) % MOD;
        }
        a = (a*a)%MOD;
        b >>= 1;
    }
    return p;
}

int main(){

    int H,W,A,B;
    ll fact[200001],inv[200001];
    scanf("%d %d %d %d",&H,&W,&A,&B);

    fact[0] = 1;
    inv[0] = 1;
    REP(i,H+W){
        fact[i+1] = (i+1)*fact[i]%MOD;
        inv[i+1] = modPow(fact[i+1],MOD-2,MOD);
    }

    ll ans = 0;

    FOR(i,B,W){
        ll temp = fact[H-A-1+i];
        temp = (temp*inv[H-A-1])%MOD;
        temp = (temp*inv[i])%MOD;

        temp = (temp*fact[A-1 + W-i-1])%MOD;
        temp = (temp*inv[A-1])%MOD;
        temp = (temp*inv[W-i-1])%MOD;

        ans = (ans+temp)%MOD;
    }

    cout << ans << endl;
        return 0;
}




Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> mat;
#define FOR(i,a,b) for(int i=(a);i<(int)(b);++i)
#define rep(i,n) FOR(i,0,n)
#define mset(a,x) memset(a,x,sizeof(a))

const int MOD = int(1e9 + 7);

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

    ll power = 1;
    for(int i = 1; i <= n; i++) {
        power *= i;
        power %= MOD;
    }

    cout << power << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
	int i, n, b, f;
	char a[1010];
	for(cin >> n; n; n--, b = 0, f = 0){
		for(cin >> a, i = 0; a[i] != '\0'; i++){
			b += (int)(a[i] - '0');
			if(b > 9) b = b - 9;
			else f = !f;
		}
		if(f) cout << "Audrey wins."<< endl;
		else cout << "Fabre wins." << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <set>

using namespace std;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	int odd = 0;

	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] % 2 != 0 && i % 2 != 0) {
			odd++;
		}
	}
	cout << odd << endl;
}

Measured memory_bytes: 3592
#include <algorithm>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <string>
#include <vector>
#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 FORSTEP(i, start, end, step) for (int i = start; i < end; i += step)
#define ALL(a) a.begin(), a.end()
#define MOD(a) a %= 1000000007
typedef long long ll;
const int INF32 = 2147483647;
const ll INF64  = 9223372036854775807;
using namespace std;

template <class T> inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

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

    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];

    ll dp[N + 10][W + 10] = {};
    REP(i, N) {
        REP(sum, W + 1) {
            if (sum - w[i] >= 0)
                chmax(dp[i + 1][sum], dp[i][sum - w[i]] + v[i]);
            chmax(dp[i + 1][sum], dp[i][sum]);
        }
    }

    cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 86144
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_DEPRECATE

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <cfloat>
#include <ctime>
#include <cassert>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <list>
#include <iomanip>
#include <fstream>


using namespace std;
const int MODULO = 1000000007; // check!!!
const int INF = 100000000; //1e8

typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

#define FOR(i,n) for(int i = 0; i < (n); i++)
#define sz(c) ((int)(c).size())
#define ten(x) ((int)1e##x)
#define tenll(x) ((ll)1e##x)

int main(){
	int n,m;
	while(cin>>n>>m,n||m){
		vector<vector<int> >v(n,vector<int>(m));
		FOR(i,n) FOR(j,m) cin>>v[i][j];
		vector<Pii> s(m);
		FOR(i,m) s[i].second = i+1,s[i].first = n;
		FOR(i,n) FOR(j,m){
			s[j].first -= v[i][j];
		}
		stable_sort(s.begin(),s.end());
		FOR(i,m) printf("%d%c",s[i].second,i==m-1?'\n':' ');
	}
}

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

using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vd = vector<double>;
using vvd = vector<vd>;

#define out(a) cout << a << endl
#define out1(a) cout << a
#define in(a) cin >> a
#define in2(a, b) cin >> a >> b
#define in3(a, b, c) cin >> a >> b >> c
#define rep(i, N) for (ll i = 0; i < (ll)N; i++)
#define rep1(i, N) for (ll i = 1; i <= (ll)N; i++)
#define repi(i, j, N) for (ll j = (ll)i + 1; j < (ll)N; j++)
#define all(v) v.begin(), v.end()

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;
constexpr ll mod = 1e9 + 7;

void solve();

int main()
{
    solve();
}

void solve()
{
    int a, b;
    in2(a, b);
    int ans = -1;
    rep1(i, 1250)
    {
        if (a == i * 8 / 100 && b == i * 10 / 100)
        {
            ans = i;
            break;
        }
    }
    out(ans);
}

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

#define rep(i, first, to) for(ll i = first; i < to; ++i)

using namespace std;
typedef long long ll;

int *mid, *o;
bool binary_search (int* left, int* right, const int value) {
	o = left;
	mid = left + (right - left) / 2;
	if (left == right) {
		return false;
	}
	else if (*mid == value) {
		return true;
		//return sizeof(mid - o) / sizeof(int);
	}else if (value < *mid) {
		right = mid;
	} else if (*mid < value) {
		left = mid + 1;
	}
	return binary_search(left, right, value);
}

int s[(int)1e5], t[(int)5e4];
int n, q;
void solve() {
	cin >> n;
	rep(i, 0, n) {
		cin >> s[i];
	}
	cin >> q;
	rep(i, 0, q) {
		cin >> t[i];
	}
	int ans = 0;
	rep (i, 0, q) {
		if (binary_search(s, s + n, t[i])) {
			++ans;
		}
	}
	cout << ans << endl;
}
void test() {
	int a[] = {3, 4, 5};
	cout << binary_search(a, a + 3, 3) << endl;
}

int main() {
	//test();
	solve();
	return 0;
}

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

using namespace std;

char mp[1000][1000];
char e[2][2];

int dx[4] = {-1, 0, -1, 0}, dy[4] = {-1, -1, 0, 0};
char a[3] = {'J', 'O', 'I'};

int main()
{
	int h, w; cin >> h >> w;

	for (int i = 0; i < h; ++i) cin >> mp[i];

	for (int i = 0; i < 2; ++i) cin >> e[i];

	int sum = 0;

	for (int i = 0; i < h - 1; ++i) {
		for (int j = 0; j < w - 1; ++j) {
			if (mp[i][j] == e[0][0] && mp[i][j + 1] == e[0][1] && mp[i + 1][j] == e[1][0] && mp[i + 1][j + 1] == e[1][1]) {
				sum++;
			}
		}
	}

	int ans = sum;

	for (int i = 0; i < h; ++i) {
		for (int j = 0; j < w; ++j) {
			int sum2 = sum;

			char tmp = mp[i][j];

			int cnt = 0;

			for (int k = 0; k < 4; ++k) {
				int y = i + dy[k], x = j + dx[k];
				if (y < 0 || x < 0 || y + 1 >= h || x + 1 >= w) continue;
				if (mp[y][x] == e[0][0] && mp[y][x + 1] == e[0][1] && mp[y + 1][x] == e[1][0] && mp[y + 1][x + 1] == e[1][1]) {
					cnt++;
				}
			}

			sum2 -= cnt;
			
			for (int k = 0; k < 3; ++k) {
				mp[i][j] = a[k];

				int cnt2 = 0;

				for (int l = 0; l < 4; ++l) {
					int y = i + dy[l], x = j + dx[l];
					if (y < 0 || x < 0 || y + 1 >= h || x + 1 >= w) continue;
					if (mp[y][x] == e[0][0] && mp[y][x + 1] == e[0][1] && mp[y + 1][x] == e[1][0] && mp[y + 1][x + 1] == e[1][1]) {
						cnt2++;
					}
				}

				cnt = max(cnt, cnt2);
			}

			sum2 += cnt;

			mp[i][j] = tmp;

			ans = max(ans, sum2);
		}
	}

	cout << ans << endl;
}

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

using namespace std;

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

    int n = 1;
    while ((1 << n) <= l) {
        n++;
    }

    vector<int> a(0), b(0), c(0);
    for (int i = 0; i < n - 1; i++) {
        a.push_back(i);
        b.push_back(i + 1);
        c.push_back(0);

        a.push_back(i);
        b.push_back(i + 1);
        c.push_back(1 << i);
    }

    for (int i = n - 2, j = l; i >= 0; i--) {
        if ((1 << (n - 1)) + (1 << i) <= j) {
            a.push_back(i);
            b.push_back(n - 1);
            c.push_back(j - (1 << i));
            j -= (1 << i);
        }
    }

    int m = a.size();

    cout << n << " " << m << endl;
    for (int i = 0; i < m; i++) {
        cout << a[i] + 1 << " " << b[i] + 1 << " " << c[i] << endl;
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define H 252
#define NIL -1
typedef struct node{
  int k;
  int pk;
  int lk;
  int rk;
}Node;

int n;
int A[H];

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

  for(i=1;i<=n;i++){
    printf("node %d: ",i);
    printf("key = %d, ",A[i]);
    if(A[parent(i)]!=0){
      printf("parent key = %d, ",A[parent(i)]);
    }
    if(A[left(i)]!=0){
      printf("left key = %d, ",A[left(i)]);
    }
    if(A[right(i)]!=0){
      printf("right key = %d, ",A[right(i)]);
    }
    printf("\n");
  }
    
}

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}





Measured memory_bytes: 2104
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans = 0;
  for(int i = 1; i <= n;i+=2){
    int count = 0;
    for(int j = 1;j <= i;j++){
      if(i%j == 0)count++;
    }
    if(count == 8) ans++;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256