akhauriyash/Code-Regression huggingface dataset:
from collections import defaultdict
dic = defaultdict(list)
D = int(input())
C = list(map(int,input().split())) #C[i]AiCを実施しないと下がる満足度
S = [] #S[i][j] i日目にAjcというコンテストを実施した場合に上がる満足度
for i in range(D): #コンテストは0index
    temp = list(map(int,input().split()))
    S.append(temp)
T = [] 
since = [0 for _ in range(26)] #最後に開催されてから何日経ったか。
for i in range(26):
    since[i] += C[i]
for i in range(D):
    contest= max(since)
    idx = since.index(contest)
    T.append(idx)
    dic[idx].append(i)
    #print(idx+1) #1indexに直す。
    for j in range(26):
        if j != idx:
            since[j] += C[j]
        else:
            since[j] = C[j]
for i in range(len(dic)):
    dic[i].sort()

def cycle(T):
    manzoku = 0
    since = [0 for _ in range(26)]
    for i in range(26):
        since[i] += C[i]
    for i in range(D):
        contest = T[i] #0index
        manzoku += S[i][contest]
        for j in range(26):
            if j != contest:
                manzoku -= since[j]
        #print(manzoku)
        for j in range(26):
            if j != contest:
                since[j] += C[j]
            else:
                since[j] = C[j]
    return manzoku
score = cycle(T)
M = 26
DQ = []
for i in range(26):
    for j in range(D):
        DQ.append((j+1,i+1))
for i in range(M):
    #print(dic)
    d,q = DQ[i] #d日目をAqCに変える。
    d-=1;q-=1 #0indexへ
    old = T[d]
    try:
        oscore = nscore*1
    except:
        oscore= score*1
    dic[old].remove(d)
    T[d] = q
    if old == q:
        nscore = oscore
    else:
        impact = S[d][q]-S[d][old] #コンテスト実施による満足度の変化の差
        #print(impact,C[q],C[old])
        if not dic[q]:
            impact += C[q]*(D-d)*(d+1)
        else:
            for j in range(len(dic[q])):
                if d < dic[q][0]:
                    impact += C[q]*(d+1)*(dic[q][0]-d)
                    break
                elif d > dic[q][-1]:
                    impact += C[q]*(D-d)*(d-dic[q][-1])
                    break
                else:
                    if dic[q][j] < d and d < dic[q][j+1]:
                        impact += C[q]*(d-dic[q][j])*(dic[q][j+1]-d)
                        break
        dic[q].append(d)
        dic[q].sort()
        if not dic[old]:
            impact -= C[old]*(D-d)*(d+1)
        else:
            for j in range(len(dic[old])):
                if d < dic[old][0]:
                    impact -= C[old]*(d+1)*(dic[old][0]-d)
                    break
                elif d > dic[old][-1]:
                    impact -= C[old]*(D-d)*(d-dic[old][-1])
                    break
                else:
                    if dic[old][j] < d and d < dic[old][j+1]:
                        impact -= C[old]*(d-dic[old][j])*(dic[old][j+1]-d)
                        break
        nscore = oscore+impact
        if nscore < oscore:
            nscore = oscore
            T[d] = old
            dic[q].remove(d)
            dic[old].append(d)
for ans in T:
    print(ans+1)

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

int main(){

  int MAX_N = 200002;
  int n;
  long long k;
  cin >> n >> k;

  vector<pair<int,long long>> count(MAX_N,pair<int,long long>(0,0));
  vector<int> move(n);
  for(int i=0;i<n;i++){
    int to;
    cin >> to;to--;
    move[i] = to;
  }

  bool flag = 0;
  long long repCount = 0;

  int now=0;
  while(k>0){
    count[now].first++;
    if(count[now].first==1)count[now].second = k;
    if(count[now].first==2 && flag==0){
      flag=1;
      repCount=count[now].second - k;
      k = k%repCount;
      for(int i=0;i<k;i++) now=move[now];
      cout << now+1 << endl;
      break;
    }


    k--;
    now=move[now];
    if(k==0)cout << now+1 << endl;
  }

}

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

int main() {
    int n;
    cin >> n;
    vector<int> w(n,0);
    int sum = 0;
    rep(i,n)cin >> w.at(i),sum+=w[i];
    int minimum = INF;
    int bsum=0;
    rep(i,n-1){
        bsum += w[i];
        minimum = min(minimum,abs(bsum - (sum-bsum)));
    }
    cout << minimum << endl;
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 256
m = input().split()

A = int(m[0])
B = int(m[1])
C = int(m[2])

if A == B:
  if A == C:
    ans = 'No'
  else:
    ans = 'Yes'
else:
  if A == C:
    ans = 'Yes'
  elif B == C:
    ans = 'Yes'
  else:
    ans = 'No'

print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <stack>
#include <climits>
#include <utility>
#include <cmath>

using namespace std;

#define rep(i,n,m) for(int i=n; i<=m; i++)
#define per(i,n,m) for(int i=n; i>=m; i--)
#define printi(x) printf("%d ", x)
#define printiln(x) printf("%d\n", x)
#define printiarray(a,n) for(int i=0; i<n-1; i++){printf("%d ", a[i]);} printf("%d\n", a[n-1])
#define scani(x) scanf("%d", &x)
#define scaniarray(a,n) for(int i=0; i<n; i++){scanf("%d", &a[i]);}
#define scans(str) scanf("%s",str)
#define scanc(ch) scanf("%c", &ch)
#define mk make_pair
#define printd(x) printf("%lf ", x)
#define printdln(x) printf("%lf\n", x)


#define M 1050000
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+(key%(M-1)); }

int find(char str[]){
	int key, i, h;
	key = getKey(str);
	for(i = 0; ; i++ ) {
		h = (h1(key) + i*h2(key)) % M;
		if( strcmp(H[h], str) == 0 ) return 1;
		else if(strlen(H[h]) == 0 ) return 0;
	}
	return 0;
}

int insert(char str[]){
	int key, i, h;
	key = getKey(str);
	for(i = 0; ; i++ ) {
		h = (h1(key) + i*h2(key)) % M;
		if( strcmp(H[h], str) == 0 ) return 1;
		else if(strlen(H[h]) == 0 ) {
			strcpy(H[h],str);
			return 0;
		}
	}
	return 0;
}

int main(){
    int i, n, h;
    char str[L], com[9];
    for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
    scanf("%d", &n);
    
    for ( i = 0; i < n; i++ ){
	scanf("%s %s", com, str);
	
	if ( com[0] == 'i' ){
	    insert(str);
	} else {
	    if (find(str)){
		printf("yes\n");
	    } else {
		printf("no\n");
	    }
	}
    }

    return 0;
}


Measured memory_bytes: 17112
def freq(my_list):
    count = {} 
    for i in my_list: 
        count[i] = count.get(i, 0) + 1
    return count

n = int(input())
l = list(map(int, input().split()))
s,f = sum(l), freq(l)
for _ in range(int(input())):
    x, y = map(int, input().split())
    if x in f:
        v = f[x]
        if y in f:
            f[y]+=v
            f.pop(x)
        else:
            f[y]=f.pop(x)
        s += (y-x)*v
    print(s)

Measured memory_bytes: 20696
#include <stdio.h>
#include <math.h>
int main(void){
    double x,h,high,s;
    while(scanf("%lf %lf",&x,&h)!=EOF){
        if(x==0&&h==0){
            break;
        }
        high=sqrt(h*h+(x/2)*(x/2));
        s=x*x+x*high/2*4;
        printf("%f\n",s);
        
        
        
    }
    
    
}



Measured memory_bytes: 1984
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
  int n;
  int c[500]={};
  int s[500]={};
  int f[500]={};
  int ans[500]={};
  cin >> n;
  for(int i=0; i<n-1; i++){
      cin >> c[i] >> s[i] >> f[i];
  }

  for(int i=0; i<n-2; i++){
    int now=i;
    ans[now]=s[i]+c[i];
       //ans==11
    for(int j=i; j<n-2; j++){
        if(ans[now]<s[j+1]){//次の駅に早くついたとき
          ans[now]=s[j+1]+c[j+1];

        }else{
          int k=0;         //先に出発したとき
          for(k=0; s[j+1]+k*f[j+1]<ans[now]; k++){
          }
          ans[now]=s[j+1]+k*f[j+1]+c[j+1];
        }
    }

  }

  for(int j=0; j<n-2; j++){
    cout << ans[j] << endl;
  }
  cout << s[n-2]+c[n-2] << endl;
  cout << '0' << endl;
  return 0;
}


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

int main(void){
    int n;
    string s="No"; 
    cin >> n;
    int ans = 0,flag=0;
    rep(i,n){
        int x,y;
        cin >> x >> y;
        if(x==y){
            ans++;
        }
        else ans = 0;
        if(ans==3) flag = 1;
    }
    if(flag) s ="Yes";
    cout << s << endl;
}


Measured memory_bytes: 3624
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<set>
#define db double
#define LL long long
#define inf 0x3f3f3f3f
#define N 600005
using namespace std;
int gi()
{
    int res=0,s=1; char ch;
    for(ch=getchar();(ch<'0'||ch>'9')&&ch!='-';ch=getchar());
    if(ch=='-') s=-1,ch=getchar();
    for(;ch>='0'&&ch<='9';ch=getchar()) res=res*10+ch-48;
    return res*s;
}
int n,fa[N],father[N],v[N]; LL ans;
struct node{
    LL w,s; int x;
    node(LL aa=0,LL bb=0,int xx=0) {w=aa,s=bb,x=xx;}
    bool operator < (const node &o) const {
	if(w*o.s!=s*o.w) return w*o.s<s*o.w;
	return x<o.x;
    }
}q[N];
set<node>st;
int findfa(int x) {return x==fa[x]?x:fa[x]=findfa(fa[x]);}
int main()
{
    n=gi();
    for(int i=2;i<=n;++i) father[i]=gi();
    for(int i=1;i<=n;++i) v[i]=gi(),fa[i]=i;
    for(int i=1;i<=n;++i) 
	st.insert(q[i]=node(v[i],1,i));
    int cnt=n;
    node tmp;
    while(!st.empty()) {
	tmp=*st.begin(); st.erase(tmp);
	int y=findfa(father[tmp.x]);
	if(!y) continue;
	ans+=(tmp.s-tmp.w)*q[y].w;
	st.erase(q[y]);
	node e=tmp;
	e.w+=q[y].w; e.s+=q[y].s; e.x=++cnt;
	fa[cnt]=cnt; fa[y]=cnt; fa[findfa(tmp.x)]=cnt;
	father[cnt]=father[y]; father[tmp.x]=cnt;
	q[cnt]=e;
	st.insert(e);
    }
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 33280
#include <iostream>
#include <string>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;

int main(int argc, char* argv[]){
	int N;
	int A;

	scanf("%d", &N);
	int count[200005] = {};

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

	for(int i=1; i<N+1; i++){
		printf("%d\n", count[i]);
	}

	return 0;
}





Measured memory_bytes: 4604
#include <iostream>
using namespace std;
int main(void)
{
    int W,H,x,y,r;
    
    cin >> W >> H >> x >> y >> r;
    
    if(x - r < 0 || x + r > W || y - r < 0 || y + r > H)
    {
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    
}



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

using namespace std;

int max(int a, int b)
{
    if(a>b) return a; return b;
}

int max(int a, int b, int c)
{
    int d = max(a, b);
    return max(c, d);
}

long lis_fast(long *arr, long n)
{
    vector<long> parent(n, -1);
    vector<long> lis_actual;
    lis_actual.push_back(arr[0]);

    for(long i=1; i<n; i++)
    {
        long ind = lower_bound(lis_actual.begin(), lis_actual.end(), arr[i]) - lis_actual.begin();
        if(ind < lis_actual.size()) lis_actual[ind] = arr[i];
        else lis_actual.push_back(arr[i]);
        parent[i] = lis_actual[ind-1];
    }

    // for(long )

    return lis_actual.size();
}

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

    int n; cin>>n;

    vector<int> dp(3);

    for(int day=0; day<n; day++)
    {
        vector<int> dp_new(3, 0);
        vector<int> activ(3);
        for(int j=0; j<3; j++) cin>>activ[j];

        for(int i=0; i<3; i++)
        {
            for(int j=0; j<3; j++)
            {
                if(i!=j)
                {
                    dp_new[j] = max(dp_new[j], dp[i]+activ[j]);
                }
            }
        }
        dp = dp_new;
    }

    cout<<max(dp[0], dp[1], dp[2])<<endl;

    return 0;
}

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

int main()
{
    ll N, K, M;
    cin >> N >> K;
    M = min(N % K, K - N % K);
    cout << M << endl;
    return 0;
}

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 <deque>
#include <bitset>
#include <algorithm>
#include <complex>
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;

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;
const int N = 3010;

const int M = 600010;
ll fact[M], invf[M];

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

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

ll powll(ll x, ll y){
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    return (x * powll(y,mod-2)) % mod;
}

ll nPr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(fact[n], invf[n-r]);
}

ll nCr(ll n, ll r){
    if (n < r || r < 0) return 0;
    return mul(mul(fact[n], invf[r]), invf[n-r]);
}

ll calc(ll x, ll y){
    if (y < 0) return 0;
    return nCr(x + y, x);
}


ll solve(int h, int w, vector<PL> p){
    vector<string> s(h, string(w, '.'));
    for (PL pl : p){
        s[pl.first][pl.second] = '#';
    }

    REP(i,h) cout << s[i] << endl;
 
    VVL dp(h, VL(w));
    dp[0][0] = 1;
    REP(i,h) REP(j,w){
        if (i < h - 1 && s[i + 1][j] == '.'){
            dp[i+1][j] = (dp[i+1][j] + dp[i][j]) % mod;
        }
        if (j < w - 1 && s[i][j + 1] == '.'){
            dp[i][j+1] = (dp[i][j+1] + dp[i][j]) % mod;
        }
    }
    return dp[h-1][w-1];
}

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    vector<PL> p(n);
    REP(i,n){
        int r = in() - 1, c = in() - 1;
        p[i] = P(r, c);
    }
    // vector<PL> p;
    // REP(i,h) REP(j,w){
    //     if (i + j == 0 || i + j == h + w - 2) continue;
    //     if (rand() % n == 0) p.push_back(PL(i, j));
    // }
    // n = p.size();
    // ll ansp = solve(h, w, p);

    p.push_back(P(h - 1, w - 1));
    n++;

    fact[0] = invf[0] = 1;
    FOR(i,1,M-1){
        fact[i] = (fact[i-1] * i) % mod;
        invf[i] = divll(invf[i-1], i);
    }

    sort(ALL(p));

    VL dp(n);
    REP(i,n){
        dp[i] = calc(p[i].first, p[i].second);
        REP(j,i){
            dp[i] = (dp[i] - (dp[j] * calc(p[i].first - p[j].first, p[i].second - p[j].second)) % mod + mod) % mod;
        }
    }

    cout << dp[n-1] % mod << endl;

    // cout << ansp << endl;


    return 0;
}


Measured memory_bytes: 9728
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <queue>
#include <utility>
#include <vector>

#define MAX_N (100000L)
#define MAX_M (100000L)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  long N, M, as[MAX_N], bs[MAX_N];
  scanf("%ld %ld", &N, &M);
  for (long i = 0; i < N; i++) {
    scanf("%ld %ld", &as[i], &bs[i]);
  }

  // stuff in pairs and sort by a
  vector<pair<long, long>> abs;
  for (long i = 0; i < N; i++) {
    abs.push_back(make_pair(as[i], bs[i]));
  }
  sort(abs.begin(), abs.end());

  // solve
  long ans = 0;
  long i_cur = 0;
  priority_queue<long> que;
  for (long t = 1; t <= M; t++) {
    // put in queue
    while (i_cur < N && abs[i_cur].first <= t) {
      que.push(abs[i_cur].second);
      i_cur++;
    }
    // take out from queue
    if (!que.empty()) {
      const long b = que.top();
      que.pop();
      ans += b;
      // printf("b = %ld\n", b);
    }
  }
  printf("%ld\n", ans);

  return 0;
}


Measured memory_bytes: 5104
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n, m;
	cin >> n >> m;
	
	vector< vector<int> > G(n);
	for(int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	
	vector<int> dist(n, 1e9 + 1);
	queue<int> q;
	dist[0] = 0;
	q.push(0);
	
	while( !q.empty() ) {
		int now = q.front();
		q.pop();
		
		for(auto& v : G[now]) {
			if( dist[v] > dist[now] + 1 ) {
				dist[v] = dist[now] + 1;
				q.push(v);
			}
		}
	}
	
	if( dist[n - 1] == 2 ) cout << "POSSIBLE" << endl;
	else cout << "IMPOSSIBLE" << endl;
	
	return 0;
}


Measured memory_bytes: 16060
h,w,a,b = map(int,input().split())
a= min(w-a,a)
b = min(h-b,b)
for i in range(h):
    if i+1<=b:
        print("0"*a + "1"*(w-a))
    else:
        print("1"*a + "0"*(w-a))


Measured memory_bytes: 3956
#include <stdio.h>

using namespace std;

struct Node{
	Node(){
		left_child = right_child = parent = 0;
		data = 0;
	}
	Node *left_child,*right_child,*parent;
	long long data;
};

class Tree{
public:
	Tree(){
		root = new Node();
		num_of_node = 0;
	}
	void insert(long long insert_data){
		if(num_of_node == 0){
			root->data = insert_data;
			num_of_node++;
		}else{
			Node* tmp = root;
			while(true){
				if(tmp->data < insert_data){
					if(tmp->right_child == 0){
						tmp->right_child = new Node();
						tmp->right_child->data = insert_data;
						tmp->right_child->parent = tmp;
						num_of_node++;
						break;
					}else{
						tmp = tmp->right_child;
					}
				}else{
					if(tmp->left_child == 0){
						tmp->left_child = new Node();
						tmp->left_child->data = insert_data;
						tmp->left_child->parent = tmp;
						num_of_node++;
						break;
					}else{
						tmp = tmp->left_child;
					}
				}
			}
		}
	}

	void print(){
		inORDER(root);
		printf("\n");
		preORDER(root);
		printf("\n");
	}

private:

	Node* root;
	int num_of_node;

private:
	void preORDER(Node* node){
		printf(" %lld",node->data);
		if(node->left_child != 0) preORDER(node->left_child);
		if(node->right_child != 0) preORDER(node->right_child);
	}

	void inORDER(Node* node){
		if(node->left_child != 0) inORDER(node->left_child);
		printf(" %lld",node->data);
		if(node->right_child != 0) inORDER(node->right_child);
	}
};


int main(){
	int m;
	long long insert_data;
	char order[7];
	Tree tree;

	scanf("%d",&m);

	for(int i = 0; i < m; i++){
		scanf("%s",order);
		if(order[0] == 'i'){
			scanf("%lld",&insert_data);
			tree.insert(insert_data);
		}else{
			tree.print();
		}
	}
}

Measured memory_bytes: 24472
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y, int m) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= m;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y, int m) {
	if (y > x)return 0;
	return kai(x, y, m) * mod_pow(kai(y, y, m), m - 2, m) % m;
}

int n;
vector<int> vec[100010];
int d[100010];

void dfs(int v, int p) {
	if ((v == 1 && (int)vec[v].size() == 1) || (1 < v && (int)vec[v].size() == 2)) {
		for (int i = 0; i < (int)vec[v].size(); i++) {
			if (vec[v][i] == p)continue;
			dfs(vec[v][i], v);
			d[v] = d[vec[v][i]] + 1;
		}
	}
	else {
		int k = 0;
		for (int i = 0; i < (int)vec[v].size(); i++) {
			if (vec[v][i] == p)continue;
			dfs(vec[v][i], v);
			k ^= d[vec[v][i]] + 1;
		}
		d[v] = k;
	}
}

signed main() {
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b; cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
	}
	dfs(1, 0);
	if (d[1])cout << "Alice" << endl;
	else cout << "Bob" << endl;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
const int mod = 1e9 + 7;
#define int long long int

int32_t main() {
    IOS ;
    // int t ; cin >> t ; while(t--) {}
    int n ; cin >> n ; 
    int a=1, b=1, c=1 ; 
    for(int i=1; i<=n; i++) 
    a = (a*10)%mod, b = (b*9)%mod, c = (c*8)%mod ;
    
    cout << ((a-2*b+c)%mod + mod) % mod ;
    
    return 0 ;
}


Measured memory_bytes: 3632
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<utility>

using namespace std;

int main(){
    int n, ans = 0;
    cin >> n;
    string str, t;
    vector<pair<string, string>> s;
    for(int i = 0; i < n; i++){
        cin >> str;
        s.push_back({str, str});
    }
    cin >> t;
    for(int i = 0; i < n; i++){
        int iq = 0;
        while((iq = s[i].first.find("?", 0)) != string::npos){
            s[i].first.replace(iq, 1, "a");
            s[i].second.replace(iq, 1, "z");
        }
    }
    int l = n + 1, r = 1;
    for(int i = 0; i < n; i++){
        if(s[i].first <= t) r++;
        if(s[i].second >= t) l--;
    }
    for(int i = l; i <= r; i++){
        cout << i;
        if(i != r) cout << " ";
    }
    cout << endl;
    return 0;
}

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

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define FOR(i ,a, b) for (int i = a ; i <= b ; i++)
#define sz(a) int(a.size())
#define cuti(a) cout << a << endl;
#define cutii(a,b) cout << a << " " << b << endl;
#define cutiii(a,b,c) cout << a << " " << b << " " << c << endl;
#define vec(a) vector<int > a;

template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }

typedef long long LL;
typedef pair<int ,int > pii;
typedef pair<string ,int > psi;
typedef pair<string ,string > pss;
typedef pair<LL, LL> pLL;

const long long oo = 1e9 + 7;
const double PI = acos(-1.0);

double DEG_to_RAD(double d) { return d * PI / 180.0; }

int n;
int a[123456];
int mini;

int main(){
//    freopen("test.txt","r",stdin);
    mini = oo;
    cin >> n;
    for (int i =1 ; i <= n; i++) {
        cin >> a[i];
        if ( a[i] % 2 == 1) {
            cout << 0 << endl;
            return 0;
        }
    }
    int ans = 0;
    for (int i =1 ;i<= 100; i++) {
        ans++;
        for (int j = 1; j <= n ; j++) {
            if ( a[j] % 2 == 1) {
                cout << ans-1 << endl;
                return 0;
            } else {
                a[j] /= 2;
            }
        }
    }
}


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

int main(){
  int n; cin >>n; int cnt=1;
  int x; cin >>x;
  for(int i=1; i<n; i++)
  {
    int f; cin >>f;
    if(f<x){cnt++; x=f;}
  }
  cout <<cnt;
return 0;}

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

string S, ans;

int main() {
	int N;
	cin >> N >> S;
	string pattern[4] = {"SS", "SW", "WS", "WW"};
	for (auto pa : pattern) {
		ans = pa;
		for (int i = 1; i <= N-2; i++) {
			if ((ans[i] == 'S' && S[i] == 'o') || (ans[i] == 'W' && S[i] == 'x')) {
				ans += ans[i-1];
			}
			else {
				ans += ans[i-1] == 'S' ? 'W' : 'S';
			}
		}

		bool flag_first;
		if ((S[0] == 'o' && ans[0] == 'S') || (S[0] == 'x' && ans[0] == 'W')) {
			if (ans[1] == ans[N-1]) flag_first = true;
			else flag_first = false;
		}
		else if ((S[0] == 'o' && ans[0] == 'W') || (S[0] == 'x' && ans[0] == 'S')) {
			if (ans[1] != ans[N-1]) flag_first = true;
			else flag_first = false;
		}

		bool flag_last;
		if ((S[N-1] == 'o' && ans[N-1] == 'S') || (S[N-1] == 'x' && ans[N-1] == 'W')) {
			if (ans[0] == ans[N-2]) flag_last = true;
			else flag_last = false;
		}
		else if ((S[N-1] == 'o' && ans[N-1] == 'W') || (S[N-1] == 'x' && ans[N-1] == 'S')) {
			if (ans[0] != ans[N-2]) flag_last = true;
			else flag_last = false;
		}

		if (flag_first && flag_last) {
			break;
		}
		else {
			ans = "-1";
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n;
	cin >> n;
	long long int arr[n], sum = 0, x = 0, mod = 1000000007;
	for (int i = 0; i < n; i++) {
		cin >> arr[i];
		sum += arr[i];
		sum %= mod;
	}
	x = 0;
	for (int i = 0; i < n - 1; i++) {
		sum = (sum - arr[i] + mod) % mod;
		x = ((x % mod) + ((sum % mod) * (arr[i] % mod)) % mod) % mod;
	}
	cout << x << endl;
}


Measured memory_bytes: 5160
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

ll d;
int digit;
int st=0;
int tmp[30];
ll res;
ll zero[20];

ll labs(ll v){
	if(v<0LL)return -v;
	return v;
}

void func(int v,ll now){
	if(v==(digit)/2 && now==d){
		ll all=1;
		for(int i=0;i<v;i++){
			if(i==0){
				if(tmp[i]>=0)all*=(ll)9-abs(tmp[i]);
				else all*=(ll)10-abs(tmp[i]);
			}else all*=(ll)10-abs(tmp[i]);
			if(all<0)while(1);
		}
		if((digit+1)%2==0)all*=10LL;
		res+=all;
	}
	if(v==(digit)/2)return;
	if(labs(now-d)>=labs(zero[digit-v]))return;
	for(int i=-9;i<=9;i++){
		if(v==0 && i==9)continue;
		tmp[v]=i;
		ll nex=now;
		nex+=(ll)i*zero[digit-1-v];
		nex-=(ll)i*zero[v];
		func(v+1,nex);
	}
}

void func2(int v,int sta,ll now){
	if(v==(digit)/2 && now==d){
		ll all=1;
		for(int i=0;i<v;i++){
			if(i==0){
				if(tmp[i]>=0)all*=(ll)9-abs(tmp[i]);
				else all*=(ll)10-abs(tmp[i]);
			}else all*=(ll)10-abs(tmp[i]);
			if(all<0)while(1);
		}
		if((digit+1)%2==0)all*=10LL;
		res+=all;
	}
	if(v==(digit)/2)return;
	
	for(int i=-9;i<=9;i++){
		if(v==0 && i==9)continue;
		if(v==sta && i==0)continue;
		if(v==sta && abs(i)>1)continue;
		tmp[v]=i;
		ll nex=now;
		nex+=(ll)i*zero[digit-1-v];
		nex-=(ll)i*zero[v];
		func2(v+1,sta,nex);
	}
}

int main(void){
	scanf("%lld",&d);
	zero[0]=1;
	for(int i=0;i<18;i++){
		zero[i+1]=zero[i]*10LL;
	}
	digit=0;
	ll dd=d;
	while(dd>0){
		digit++;
		dd/=10LL;
	}
	dd=d;
	int digit2=digit;
	for(;digit<=digit2*2;digit++){
		func(0,0);
	}
	printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        x: i64,
    }

    let pow5: Vec<i64> = (0i64..120).map(|x| x.pow(5)).collect();
    for (a, a5) in pow5.iter().enumerate() {
        for (b, b5) in pow5.iter().enumerate() {
            if a5 - b5 == x {
                println!("{} {}", a, b);
                return;
            }
            if a5 + b5 == x {
                println!("{} -{}", a, b);
                return;
            }
        }
    }
}


Measured memory_bytes: 2160
#include <cstdio>
#define LL long long
#define Int register int
using namespace std;
int main()
{
	LL p;
	scanf("%lld", &p);
	LL l, r;
	scanf("%lld %lld", &l, &r);
	if (l % p == 0)
		return ! printf("OK");
	LL PL = (l / p + 1) * p;
	if (PL <= r)
		printf("OK");
	else printf("NG");
	return 0;
}

Measured memory_bytes: 3232
#include <cstdio>
int N;
int F[100][14];
int P[100][15];
int main(){
	scanf ("%d", &N);
	for (int i = 0; i < N ; i ++){
		for (int j = 0; j < 10; j ++) scanf ("%d", &F[i][j]);
	}

	for ( int i =0; i < N ; i ++)
		for( int j =0; j < 11; j ++)
			scanf("%d", &P[i][j]);

	int res = -(1 << 30);
	for ( int b =1; b < (1 << 10); b ++){
		int cc =0;
		for ( int i =0; i < N ; i ++){
			int c =0;
			for ( int j =0; j <10; j ++)
				if(( b >> j &1)&& F [ i ][ j ])
					c++;
			cc += P [ i ][ c ];
		}
		if(res < cc) res = cc;
	}
	printf("%d\n" , res );
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
using namespace std;

const int N=1e6+5;

void solve()
{
    int x;
    cin>>x;
    if(x>=30) cout<<"Yes";
    else cout<<"No";
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    //int t;
    //cin>>t;
    //while(t--)
        solve();
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

vector<P> bridges;
vector<ll> ans;


class UnionFind {
public:
    // 親の番号を格納する。親だった場合-size
    vector<int> parents;

    UnionFind(int n) {
        parents = vector<int>(n, -1);
    }

    // aがどのグループに属しているか
    int root(int a) {
        if (parents[a] < 0) {
            return a;
        }
        return parents[a] = root(parents[a]);
    }

    int size(int a) {
        return -parents[root(a)];
    }

    // aとbをくっつける
    bool connect(int a, int b) {
        int ra = root(a);
        int rb = root(b);
        if (ra == rb) {
            return false;
        }
        // 大きいほうにA
        if (size(ra) < size(rb)) {
            swap(ra, rb);
        }
        parents[ra] += parents[rb];
        parents[rb] = ra;
        return true;
    }

};

int main() {
    int n, m;
    cin >> n >> m;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        bridges.emplace_back(a, b);
    }
    // 1番目から順に崩落するということは、
    // m番目から順に建築されるのと同義
    reverse(bridges.begin(), bridges.end());

    // 最初にすべての島は独立している
    for (int i = 0; i < n; i++) {
        set<int> group;
        group.insert(i);
    }
    ans.push_back((ll)n * ((ll)n - 1) / 2);

    UnionFind uf(n);

    for (int i = 0; i < m; i++) {
        auto bridge = bridges[i];

        int first = uf.root(bridge.first);
        int firstSize = uf.size(first);
        int second = uf.root(bridge.second);
        int secondSize = uf.size(second);

        bool b = uf.connect(first, second);
        if (!b) {
            ll end = *(ans.end() - 1);
            ans.push_back(end);
            continue;
        }

        ll end = *(ans.end() - 1);
        ll diff  = firstSize * secondSize;
        ans.push_back(end - diff);
    }
    ans.pop_back();
    reverse(ans.begin(), ans.end());
    for (auto a : ans) {
        cout << a << endl;
    }

}



Measured memory_bytes: 3444
#include <stdio.h>

int main(void) {
    int i, j;
    
    for(i = 1; i < 10; i++) {
        for(j = 1; j < 10; j++) {
            printf("%dx%d=%d\n", i, j, i * j);
        }
    }
    
    return(0);
}

Measured memory_bytes: 524
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <cstring>
#include <cmath>

using namespace std;

int main(int args, char *argc[]){
  int n;
  while(cin>>n){
    if(n==0) return 0;
    map<char,char> table;
    for(int i=0;i<n;i++){
      char a,b;
      cin>>a>>b;
      table.insert(make_pair(a,b));
    }

    cin>>n;
    for(int i=0;i<n;i++){
      char a;
      cin>>a;
      if(table.count(a)!=0)
        cout<<table[a];
      else
        cout<<a;
    }
    cout<<endl;
    }
  return 0;
}


Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define fo(i,n) for(int i=0;i<n;i++)
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
int main(){
    int a,b,c;cin>>a>>b>>c;
    if(a%2!=0||c%2!=0||b%2!=0){
        cout << 0;return 0;
    }
    else if(a==b&&b==c){
        cout << -1;return 0;
    }
    else{
        int cnt =0;
        while(a%2==0&&b%2==0&&c%2==0){
            int y =b,z =a;
            a=b/2 + c/2; b=c/2+z/2;c=z/2 +y/2;
            ++cnt;
        }
        cout << cnt;
    }
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

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

int main() {
	int x, y;
	cin >> x >> y;	
		
	if(y % 2 == 1 || 4 * x < y || 2*x > y) cout << "No" << endl;
	else cout << "Yes" << endl;
  
	return 0;
}

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

typedef long long ll;

const int INF = 1e9;
vector<ll> h(100005,0);
vector<ll> dp(100005,INF);
int main() {
	int N;
	cin>>N;
	rep(i,N)cin>>h[i];
	dp[0] = 0;
	rep(i,N){
		dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
		dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
	}
	cout<<dp[N-1]<<endl;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main(void) {
	ll a, b;
	cin >> a >> b;
	printf("%lld\n", a * b);
	return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define PI pair<int,int>
#define ff first
#define ss second
#define endl '\n'
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
//#include "debug.cpp"

int32_t main()
{
	boost;
    int n;
    cin>>n;
    int ans=0;
    map<pair<int,int>,int>mp;
    for(int i=1;i<=n;i++){
    	string s=to_string(i);
    	mp[{s[0]-'0',s.back()-'0'}]++;
    }
    for(int i=1;i<10;i++)
        for(int j=1;j<10;j++)
            ans+=mp[{i,j}]*mp[{j,i}];
    cout<<ans<<endl;
}

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

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


    long long int len = s.length();
    if( len == 1 ){
        cout << 0 << endl;
        return 0;
    }


    long long int ans = 0;
    for( int i = 0, j = len-1; i < j; ++i, --j ){
        if( s[i] == s[j] ) continue;
        else if( s[i] == 'x' ){ ++ans; ++j; }
        else if( s[j] == 'x' ){ ++ans; --i; }
        else { cout << -1 << endl; return 0; }
    }


    cout << ans << endl;

    return 0;
}

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

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

typedef long long ll;
typedef pair<int, int> P;

const int MAX = 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

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

    int ans = 0;
    char c = 'A';
    rep(i, N) {
        if (S[i] != c) {
            ans++;
            c = S[i];
        }
    }

    cout << ans << endl;
}

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

int main() {
    int d, n, m, c;
    int i;
    
    cin >> d >> n;
    if ( d == 0 ) {
        m = 1;
    } else if ( d == 1 ) {
        m = 100;
    } else {
        m = 10000;
    }
    
    c = 0;
    i = 0;
    while (c < n) {
        i++;
        
        if ( i % m == 0 && i % (m*100) != 0 ) {
            c++;
        }
    }
    
    cout << i << endl;
    
    return (0);
}

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


int main(){
  while(true){
    int n;
    cin>>n;
    if(n==0){
      break;
    }
    int avn=n-2,s[n],total=0;
    for(int k=0;k<n;k++){
      cin>>s[k];
      total=total+s[k];
    }
    int max=0,min=1000;
    for(int i=0;i<n;i++){
      if(s[i]>max){
	max=s[i];
      }
      if(s[i]<min){
	min=s[i];
      }
    }
    total=total-max-min;
    total=total/avn;
    cout<<total<<endl;
  }

  return 0;
}

Measured memory_bytes: 1160
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import os
import sys
import itertools
import math
from collections import Counter, defaultdict

class Main(object):
    
    def __init__(self):
        pass

    def solve(self):
        '''
        insert your code
        '''
        n = input()
        ids = Counter()
        for i in range(n):
            ids[raw_input()] += 1
        m = input()
        opened = False
        for i in range(m):
            log = raw_input()
            if ids[log] == 0:
                print 'Unknown ' + log
            elif opened:
                opened = not opened
                print 'Closed by ' + log
            else:
                opened = not opened
                print 'Opened by ' + log
            
        
        return None

if __name__ == '__main__':
    m = Main()
    m.solve()

Measured memory_bytes: 4700
#include <iostream>
#include <queue>

using namespace std;

struct Edge{
	int to,dist;
	Edge(){}
	Edge(int t,int d):to(t),dist(d){}
};
typedef vector<vector<Edge> > Graph;

int main()
{
	for(int n,m,p,a,b;cin>>n>>m>>p>>a>>b,n|m|p|a|b;){
		vector<int> ts(n);
		for(int i=0;i<n;i++)
			cin>>ts[i];
		Graph g(m);
		for(int i=0;i<p;i++){
			int from,to,dist; cin>>from>>to>>dist;
			g[from-1].push_back(Edge(to-1,dist));
			g[to-1].push_back(Edge(from-1,dist));
		}
		
		vector<vector<double> > times(m,vector<double>(1<<n,1<<29));
		vector<vector<int> > flgs(m,vector<int>(1<<n));
		times[a-1][0]=0;
		for(;;){
			int cv=-1,cb=-1;
			for(int i=0;i<m;i++)
				for(int j=0;j<(1<<n);j++)
					if(!flgs[i][j] && (cv==-1 || times[i][j]<times[cv][cb]))
						cv=i,cb=j;
			if(cv==-1)
				break;
			flgs[cv][cb]=1;
			
			for(int i=0;i<g[cv].size();i++){
				Edge e=g[cv][i];
				for(int j=0;j<n;j++){
					double t=times[cv][cb]+(double)e.dist/ts[j];
					if(!(cb&1<<j) && times[e.to][cb|1<<j]>t)
						times[e.to][cb|1<<j]=t;
				}
			}
		}
		
		double res=1<<29;
		for(int i=0;i<times[b-1].size();i++)
			res=min(res,times[b-1][i]);
		if(res==(1<<29))
			cout<<"Impossible"<<endl;
		else{
			cout.precision(3);
			cout<<fixed<<res<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
#define x real()
#define y imag()

double eps = 1e-9;

string ccw(P a,P b,P c){
  P ab=b-a,ac=c-a;
  P k=ac*conj(ab);
  if(k.y>eps)return "COUNTER_CLOCKWISE";
  if(k.y<-eps)return "CLOCKWISE";
  if(k.x<-eps)return "ONLINE_BACK";
  if(abs(ab)+eps<abs(ac))return "ONLINE_FRONT";
  return "ON_SEGMENT";
}
 
int main(){
  double x0,y0,x1,y1,x2,y2;
  cin>>x0>>y0>>x1>>y1;
  P a(x0,y0);
  P b(x1,y1);
  int n;
  cin>>n;
  while(n--){
    cin>>x2>>y2;
    P c(x2,y2);
    cout<< ccw(a,b,c) <<endl;
  }
  return 0;
}

Measured memory_bytes: 1252
#!/usr/bin/env python3

from collections import deque

S = str(input())
Q = int(input())
# print(S, Q)

is_reverse = False

d = deque()
d.append(S)
# print(d)

for i in range(Q):
    query = list(input().split())
    # print(query)
    if int(query[0]) == 1:
        # print("reverse")
        # Sを反転
        is_reverse = not is_reverse
    else:
        if int(query[1]) == 1:
            # Sの先頭にC_iを追加
            if is_reverse:
                d.append(query[2])
            else:
                d.appendleft(query[2])
        else:
            # Sの末尾にC_iを追加
            if is_reverse:
                d.appendleft(query[2])
            else:
                d.append(query[2])

if is_reverse:
    print("".join(d)[::-1])
else:
    print("".join(d))


Measured memory_bytes: 67544
from sys import stdin
from itertools import combinations

readline = stdin.readline


def nl():
    """
    空白区切り行入力を`int iter`に変換
    """
    return map(int, readline().split())


def main():
    n, d = nl()
    res = 0
    xs = [
        tuple(nl())
        for i in range(n)
    ]
    for i, j in combinations(xs, 2):
        c = .0
        for a, b in zip(i, j):
            c += (a - b) ** 2
        c = c ** (1/2)
        if c == int(c):
            res += 1
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
loop do
  n, r = gets.chomp.split(' ').map(&:to_i)
  if (n | r) == 0
    break
  end
  
  ary = Array.new(n)
  (n).downto(1) do |i|
    ary[n-i] = i
  end

  r.times do 
    p, c = gets.chomp.split(' ').map(&:to_i)
    del = ary.slice!(p-1, c)
    ary = del + ary
  end
  puts ary[0]
end

Measured memory_bytes: 9200
# abc120_a.py
# https://atcoder.jp/contests/abc120/tasks/abc120_a

# A - Favorite Sound /
# 実行時間制限: 2 sec / メモリ制限: 1024 MB
# 配点 : 100点

# 問題文
# 高橋くんは、自動販売機でジュースを買ったときの音が好きです。
# その音は 1回 A円で聞くことができます。
# 高橋くんは B円持っていますが、お気に入りの音を C 回聞くと満足するため、B 円で最大 C回まで聞けるだけ聞きます。
# 高橋くんはお気に入りの音を何回聞くことになるでしょうか。

# 制約
#     入力は全て整数である。
#     1≤A,B,C≤100

# 入力
# 入力は以下の形式で標準入力から与えられる。
# A B C

# 出力
# 高橋くんはお気に入りの音を何回聞くことになるか出力せよ。

# 入力例 1
# 2 11 4

# 出力例 1
# 4

# 高橋くんは 8円以上持っているのでお気に入りの音を 4回聞いて満足します。

# 入力例 2
# 3 9 5

# 出力例 2
# 3

# 高橋くんが満足できないこともあります。

# 入力例 3
# 100 1 10

# 出力例 3
# 0


def calculation(lines):
    # line = lines[0]
    # N = int(lines[0])
    A, B, C = list(map(int, lines[0].split()))
    # values = list(map(int, lines[1].split()))
    # values = list()
    # for i in range(N):
    #     values.append(int(lines[i+1]))

    result = (B // A)
    if result > C:
        result = C

    return [result]


# 引数を取得
def get_input_lines(lines_count):
    lines = list()
    for _ in range(lines_count):
        lines.append(input())
    return lines


# テストデータ
def get_testdata(pattern):
    if pattern == 1:
        lines_input = ['2 11 4']
        lines_export = [4]
    if pattern == 2:
        lines_input = ['3 9 5']
        lines_export = [3]
    if pattern == 3:
        lines_input = ['100 1 10']
        lines_export = [0]
    return lines_input, lines_export


# 動作モード判別
def get_mode():
    import sys
    args = sys.argv
    if len(args) == 1:
        mode = 0
    else:
        mode = int(args[1])
    return mode


# 主処理
def main():
    import time
    started = time.time()
    mode = get_mode()
    if mode == 0:
        lines_input = get_input_lines(1)
    else:
        lines_input, lines_export = get_testdata(mode)

    lines_result = calculation(lines_input)

    for line_result in lines_result:
        print(line_result)

    # if mode > 0:
    #     print(f'lines_input=[{lines_input}]')
    #     print(f'lines_export=[{lines_export}]')
    #     print(f'lines_result=[{lines_result}]')
    #     if lines_result == lines_export:
    #         print('OK')
    #     else:
    #         print('NG')
    # finished = time.time()
    # duration = finished - started
    # print(f'duration=[{duration}]')


# 起動処理
if __name__ == '__main__':
    main()


Measured memory_bytes: 9012
mod = 1000000007
size = 50
f = []
invf = []
def inv(n):
  global mod,size
  if n == 1:
    return 1
  k = [0 for i in range(size)]
  a,b,u = mod,n,size
  for i in range(size):
    k[i],a,b = a//b,b,a%b
    if b == 0:
      u = i
      break
  y0,y1 = 1,-k[0]
  for i in range(1,u):
    y0,y1 = y1,y0-k[i]*y1
  while y1 < 0:
    y1 += mod
  return y1%mod
def comb(n,k):
  global mod,f,invf
  if k < 0 or k > n:
    return 0
  if n == 0 and k == 0:
    return 1
  if n == 0:
    return 0
  return (f[n]*((invf[k]*invf[n-k])%mod))%mod
def init(n):
  global mod,f,invf
  f = [0 for i in range(n+1)]
  invf = [0 for i in range(n+1)]
  f[0],invf[0] = 1,1
  for i in range(1,n+1):
    f[i] = (f[i-1]*i)%mod
    invf[i] = inv(f[i])
  
n,a,b,c = map(int,input().rstrip().split())
init(2*n)
m = 0
for k in range(n):
  m = (m+comb(n+k,n)*(pow(a,n,mod)*pow(b,k,mod)+pow(a,k,mod)*pow(b,n,mod))*inv(pow(100-c,n+k+1,mod)))%mod
print((m*n*100)%mod)

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

int n;
vector<string> v, w;
string t;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n;
	v.resize(n);
	for(auto &i:v){
		cin >> i;
		w.push_back(i);
	}
	cin >> t;
	for(int i=0; i<n; ++i){
		for(size_t j=0; j<v[i].size(); ++j){
			if(v[i][j] == '?'){
				v[i][j] = 'a';
				w[i][j] = 'z';
			}
		}
	}
	sort(v.begin(), v.end());
	sort(w.begin(), w.end());
	vector<int> a;
	for(int i=lower_bound(w.begin(), w.end(), t)-w.begin(); i<upper_bound(v.begin(), v.end(), t)-v.begin()+1; ++i) a.push_back(i+1);
	for(size_t i=0; i<a.size(); ++i)
		cout << a[i] << " \n"[i+1==a.size()];
}

Measured memory_bytes: 1408
let n, a, b, c, d, e = Scanf.scanf " %d %d %d %d %d %d" @@ fun a b c d e f -> a, b, c, d, e, f
let m = List.fold_left min a [a; b; c; d; e]
let _ = (n + m - 1) / m + 4 |> Printf.printf "%d\n"

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <map>

using namespace std;

class CDice {
private:
	map<int, int> surface;
    vector<int> dispNumber;
	vector<vector<int>> right =
		{{-1, 2, 4, 1, 3, -2}, {3, -1, 0, 5, -2, 2}, {1, 5, -1, -2, 0, 4}, {4, 0, -2, -1, 5, 1}, {2, -2, 5, 0, -1, 3},  {-2, 3, 1, 4, 2, -1}};
	int GetRightIndex(int top, int front) {
	return right[top][front];
	};
public:
	CDice() {};
	CDice(map<int, int> mp, vector<int> vc) { SetSurface(mp, vc); };
	~CDice() {};
	void SetSurface(map<int, int> mp, vector<int> vc) { surface = mp; dispNumber = vc; };
	void TurnN();
	void TurnE();
	void TurnW();
	void TurnS();
	int GetTop() { return surface[0]; };
	int GetRight(int top, int front) {
		int i = GetRightIndex(surface[top], surface[front]);	


		return dispNumber[i]; };
	//	return surface[GetRightIndex(top, front)]; };
};

void CDice::TurnN()
{
	map<int, int> tmp = surface;
	tmp[0] = surface[1];
	tmp[1] = surface[5];
	tmp[2] = surface[2];
	tmp[3] = surface[3];
	tmp[4] = surface[0];
	tmp[5] = surface[4];
	surface = tmp;
}

void CDice::TurnE()
{
	map<int, int> tmp = surface;
	tmp[0] = surface[3];
	tmp[1] = surface[1];
	tmp[2] = surface[0];
	tmp[3] = surface[5];
	tmp[4] = surface[4];
	tmp[5] = surface[2];
	surface = tmp;
}

void CDice::TurnW()
{
	map<int, int> tmp = surface;
	tmp[0] = surface[2];
	tmp[1] = surface[1];
	tmp[2] = surface[5];
	tmp[3] = surface[0];
	tmp[4] = surface[4];
	tmp[5] = surface[3];
	surface = tmp;
}

void CDice::TurnS()
{
	map<int, int> tmp = surface;
	tmp[0] = surface[4];
	tmp[1] = surface[0];
	tmp[2] = surface[2];
	tmp[3] = surface[3];
	tmp[4] = surface[5];
	tmp[5] = surface[1];
	surface = tmp;
}

int main()
{
	map<int, int> in;
	vector<int> vc(6);
	for (int i = 0; i < 6; i++){
		int tmp;
		cin >> tmp;
		in[tmp] = i;
		vc[i] = tmp;
	}

	CDice dice(in, vc);

	int numQ; // q
	cin >> numQ;

	int front, top;
	for (int i = 0; i < numQ; i++) {
		cin >> front >> top;
		cout << dice.GetRight(front, top) << endl;
	}

	return 0;
}



Measured memory_bytes: 3168