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

int n, wmax, ans, minw;
vector<int> g[4];
int cap[4];

void solve (int k) {
	if (k == 4) {

		long long total = 0;
		for (int i = 0; i < 4; i++)
			total += (long long)cap[i] * (minw + i);
		if (total > wmax) return;

		int tmp = 0;
		for (int i = 0; i < 4; i++)
			tmp += (cap[i] ? g[i][cap[i] - 1] : 0);
		cerr << tmp << '\n';
		ans = max(ans, tmp);
		return;
	}

	for (int i = 0; i <= (int)g[k].size(); i++) {
		cap[k] = i;
		solve(k + 1);
	}
}

int main() {
	scanf("%d%d", &n, &wmax);
	int w, x;
	scanf("%d%d", &minw, &x);
	g[0].push_back(x);
	
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &w, &x);
		g[w - minw].push_back(x);
	}

	for (int i = 0; i < 4; i++) {
		sort(g[i].begin(), g[i].end());
		reverse(g[i].begin(), g[i].end());
		for (int j = 1; j < (int)g[i].size(); j++)
			g[i][j] += g[i][j - 1];
	}

	ans = 0;	
	solve(0);
	printf("%d\n", ans);
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
using namespace std;

int N;

int main() {
    cin >> N;
    int mx = 0, tmp = 0, b = 0, h;
    for (int i = 0; i < N; i++) {
        cin >> h;
        if (b < h) {
            tmp = 0;
        } else {
            ++tmp;
            mx = max(tmp, mx);
        }
        b = h;
    }
    cout << mx << endl;
}


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

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

  int count = 0;
  int renga = 0;
  for(int i = 0;i < N;i++){
    int a;
    cin >> a;
    if(count + 1 == a){
      count++;
    }else{
      renga++;
    }
  }

  std::cout << (count == 0 ? -1 : renga) << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int x=0,i;
    string s,c="CODEFESTIVAL2016";
    cin>>s;
    for(i=0;i<c.size();i++){
        if(c[i]!=s[i]) x++;
    }
    cout<<x<<endl;
return 0;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
la, ra = map(int, input().split())
for i in range(1, m):
    lm, rm = map(int, input().split())
    overlap = False
    if lm <= la <= rm and lm <= ra <= rm:
        continue
    if la <= lm <= ra:
        la = lm
        overlap = True
    if la <= rm <= ra:
        ra = rm
        overlap = True
    if not overlap:
        print(0)
        exit(0)

print(ra - la + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define  sci(x)   scanf("%d", &x)
#define  scl(x)   scanf("%lld", &x)
#define  scd(x)   scanf("%lf", &x)
#define forn(i,n)   for(ll i=0; i<n; i++)
#define fork(i,n)   for(ll i=1; i<=n; i++)

int main ()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	//CODE TONOY
	string s,s1;
	cin >> s >> s1;
	int x,y;
	int count = 0;
	x = s.length();
	y = s1.length();
	if (abs(x-y)!=1)
	{
		cout << "No\n";
		return 0;
	}
	int loop = min (x,y);
	//cout << loop << endl;
	for (int i=0 ; i<loop ; i++)
	{
		if(s[i]==s1[i])
		count++;
	}
	if (count == loop)
	cout << "Yes" << endl;
	else
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;

int main(void) {
  lld n;
  cin >> n;
  vector<lld> t(200000, 0);
  lld s = 0;
  for (lld i = 0; i < n; i++) {
    lld a;
    cin >> a;
    t[a]++;
    s += a;
  }
  lld q;
  cin >> q;
  for (lld i = 0; i < q; i++) {
    lld b, c;
    cin >> b >> c;
    s = s - t[b] * b + t[b] * c;
    t[c] += t[b];
    t[b] = 0;
    cout << s << "\n";
  }
}

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

using namespace std;

int main(){
	while(1){
	int a,b;
	cin >> a >> b;
	if(a==0){
		break;
	}
	int dp[17][17]={};
	int map[17][17]={};
	int n;
	cin >> n;
	int x,y;
	for(int i=1;i<=n;i++){
		cin >> x >> y;
		map[x][y]=1;
	}
	
	dp[1][0]=1;
	
	for(int i=1;i<=a;i++){
		for(int j=1;j<=b;j++){
			if(map[i][j]==1)
				dp[i][j]=0;
			else
				dp[i][j]=dp[i][j-1]+dp[i-1][j];
		}
	}
	
	cout << dp[a][b] <<endl;
	}
	return 0;
}

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

int f(int n){
    if(n&1)return 3 * n + 1;
    return n/2;
}

int main(){

    int s, a;
    cin>>s;
    a = s;
    map<int,int>mp;
    mp[s]=1;
    for(int i=2;;i++){
        a = f(a);
        if(mp[a]){
            cout<<i<<endl;
            return 0;
        }
        mp[a] = 1;
    }

    return 0;
}

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

int BinarySearch(int *A, int n, int key);

int main() {
  
  int n,q;
  int *S, *T;
  int i,j;
  int count = 0;
  
  scanf("%d",&n);
  S = (int *)malloc(n * sizeof(int));
  for (i=0; i<n; i++)
    scanf("%d", &S[i]);

    scanf("%d",&q);
  T = (int *)malloc(q * sizeof(int));
  for (i=0; i<q; i++)
    scanf("%d", &T[i]);

  for(i=0; i<q; i++){
    count += BinarySearch(S, n, T[i]);
  }

  printf("%d\n", count);
  
  return 0;
}

int BinarySearch(int *A, int n, int key){

  int right;
  int left = 0;
  int mid;

  right = n;

  while(left < right){
    mid = (left + right) / 2;
    if(key == A[mid]) return 1;
    if(key > A[mid]) left = mid + 1;
    else if(key < A[mid]) right = mid;
    
  }
  return 0;
}



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

int main(){
    int x[2], y[2], w[2], h[2], lx = 0, rx = 2001, uy = 2001, dy = 0;
    for(int i = 0; i < 2; i++){
        cin >> x[i] >> y[i] >> w[i] >> h[i];
        lx = max(lx, x[i]);
        rx = min(rx, x[i]+w[i]);
        uy = min(uy, y[i]+h[i]);
        dy = max(dy, y[i]);
    }
    cout << w[0]*h[0]+w[1]*h[1] - 2*max(0,rx-lx)*max(0,uy-dy) << endl;
    return 0;
}


Measured memory_bytes: 3116
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 111111111;
const int c_mINF = -111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };
const int c_div = 1000000007; //10^9 + 7



int main() {

	char S[10];
	scanf("%s", S);

	if (S[0] == 'S') {
		printf("Cloudy");
	}
	if (S[0] == 'C') {
		printf("Rainy");
	}
	if (S[0] == 'R') {
		printf("Sunny");
	}


}






Measured memory_bytes: 128
from collections import defaultdict
from operator import itemgetter

n = int(input())

s_dict = defaultdict(int)
for _ in range(n):
    s = input()
    s_dict[s] += 1

def multisort(xs, specs):
    for key, reverse in reversed(specs):
        xs.sort(key=itemgetter(key), reverse=reverse)
    return xs

s_list = multisort(list(s_dict.items()), ((1, True), (0, False)))
count_max = s_list[0][1]
for s, count in s_list:
    if count < count_max:
        break
    print(s)

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

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

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

const int mod = 1e9 + 7;


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

	bool fl = true;
	rep(i, s.size()){
		if((i+1) % 2 == 0){
			if(s[i] == 'R'){
				fl = false;
			}
		}else{
			if(s[i] == 'L'){
				fl = false;
			}
		}
	}

	if(fl == true){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int n, k, s[100000], index = 0, tmp = 0, max;
	char c, c2 = '1';
	scanf("%d %d", &n, &k);
	getchar();

	for (int i = 0; i < n; i++) {
		c = getchar();
		if (c == c2) {
			tmp++;
		}
		else {
			c2 = c;
			s[index] = tmp;
			index++;
			tmp = 1;
		}
	}
	s[index] = tmp;
	index++;
	s[index] = 0;

	tmp = 0;
	k *= 2;
	for (int i = 0; i <= k && i < index; i++) {
		tmp += s[i];
	}
	max = tmp;
	for (int i = 1 + k; i < index; i += 2) {
		tmp += s[i] + s[i+1];
		tmp -= s[i-k] + s[i-k-1];
		if (tmp > max) {
			max = tmp;
		}
	}
	printf("%d", max);
}

Measured memory_bytes: 512
#include <cstdio>
#include <stack>
#include <map>
#include <queue>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <bitset>
#include <math.h>
#include <string.h>
#include <stdio.h>
#include <queue>
#define F first
#define S second
#define MP make_pair
#define INF 1e9
#define MOD 1000000007
using namespace std;
typedef long long LL;
typedef pair<LL, LL> P;
typedef pair<P, P> PP;

inline int in() {
	int temp = 0;
	scanf("%d", &temp);
	return temp;
}

int n = in(), k = in();
P taxi[5001];
vector<int> road[5001];
int town[5001];
priority_queue<P> pq;
bool flag[5001];
void bfs(int s, int mey)
{
	memset(flag, 0, sizeof(flag));
	queue<P> que;
	mey -= taxi[s].S;
	que.push(MP(s, 0));
	flag[s] = true;
	while (!que.empty()) {
		P p = que.front();
		que.pop();
		if (p.S == taxi[s].F)
		{
			continue;
		}
		for (int i = 0; i < road[p.F].size(); i++)
		{
			if (!flag[road[p.F][i]])
			{
				if (town[road[p.F][i]] < mey)
				{
					town[road[p.F][i]] = mey;
					pq.push(MP(mey, road[p.F][i]));
				}

				que.push(MP(road[p.F][i], p.S + 1));
				flag[road[p.F][i]] = true;
			}
		}
	}
}

void dijkstra()
{
	pq.push(MP(0, 1));
	while (!pq.empty())
	{
		P p = pq.top();
		pq.pop();
		bfs(p.S, p.F);
	}
}
int main()
{
	for (int i = 1; i <= n; i++)
	{
		taxi[i] = make_pair(in(), in());
	}
	for (int i = 0; i < k; i++)
	{
		int a = in(), b = in();
		road[a].push_back(b);
		road[b].push_back(a);
	}
	fill(town, town + 5001, -INF);
	dijkstra();
	cout << -town[n] << endl;
}

Measured memory_bytes: 3740
/*

* author:mel0n
* le epic style 
*
*

*/

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0)
#define lli long long int
#define pi pair<int,int>
#define all(x) (x).begin(),(x).end()

using namespace std;



int main()
{
fast;
lli n,k;
cin>>n>>k;

vector <lli> v(n);
for(int i=0;i<n;i++)
	cin>>v[i];
sort(v.begin(),v.end());
lli sum=0;
for(int i=0;i<k;i++)
	sum+=v[i];
cout<<sum<<endl;

return 0;
}



Measured memory_bytes: 3620
import sys
sys.setrecursionlimit(1000000)

input = sys.stdin.readline

class UnionFieldTree(object):
    def __init__(self, n):
        '''1-indexed'''
        self.parent = [i for i in range(n+1)] 
        self.size = [0] + [1] * n

    def merge(self, a, b):
        '''merge b into a'''
        a = self.root(a)
        b = self.root(b)
        self.parent[b] = self.parent[a]
        self.size[a] += self.size[b]

    def root(self, a):
        parent = self.parent[a]
        if parent == a:
            return a
        r = self.root(parent)
        self.parent[a] = r
        return r
    
    def same_group(self, a, b):
        return self.root(a) == self.root(b)


def main():
    N, M = map(int, input().split())
    AB = [map(int, input().split()) for _ in range(M)]
    
    uf = UnionFieldTree(N)

    v_sum = N*(N-1)//2
    ans = [v_sum]

    for a, b in reversed(AB):
        if not uf.same_group(a, b):
            ra = uf.root(a)
            rb = uf.root(b)
            v_sum -= uf.size[ra] * uf.size[rb]
            uf.merge(a, b)
        ans.append(v_sum)

    [print(a) for a in reversed(ans[:M])]


main()




Measured memory_bytes: 61228
// ABC177D Friends

#include<stdio.h>
int par[200001];//親
int siz[200001];//サイズ

void ini(int n){ //初期化
  for(int i=1;i<=n;i++){
    par[i] = i;
    siz[i] = 1;
  }
}
int root(int x){ //根を返す
  if(par[x] == x) return x;
  else return par[x] = root(par[x]);
}

void uni(int x, int y){ //くっつける
  x = root(x);
  y = root(y);
  if(x != y){
    siz[x] += siz[y];
    par[y] = x;
  }
}

int size(int x){ //サイズを返す
  return siz[root(x)];
}

int max(int x, int y){
  if(x>=y) return x;
  else return y;
}

int main(void){
  int n,m,a,b,ma=0;
  scanf("%d %d",&n,&m);
  ini(n);
  for(int i=0;i<m;i++){
    scanf("%d %d",&a,&b);
    uni(a,b);
  }
  for(int i=1;i<=n;i++){
    ma = max(ma,size(i));
  }
  printf("%d",ma);
  return 0;
}

Measured memory_bytes: 3604
from heapq import heappop, heappush

N, M = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(N)]

X.sort(reverse=True)
ans = 0
pq = []
for n in range(M + 1):
    while X and X[-1][0] <= n:
        a, b = X.pop()
        heappush(pq, -b)

    if pq:
        ans -= heappop(pq)

print(ans)


Measured memory_bytes: 94788
s = input()
cnt_a = 0
cnt_b = 0
cnt_c = 0
for i in s:
    if i == "a":
        cnt_a += 1
    elif i == "b":
        cnt_b += 1
    else:
        cnt_c += 1
if max(cnt_a, cnt_b, cnt_c) - min(cnt_a, cnt_b, cnt_c) <= 1:
    print("YES")
else:
   print("NO")

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int

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

   sort(a.rbegin(), a.rend());

   ll ans=0;
   rep(i, n){
      if(i==0);
      else ans+= a[i/2];
   }

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


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

int H, W;
char s[10000];
int num[10000];
void solve(int count) {
  bool H_div2 = H % 2 == 0;
  bool W_div2 = W % 2 == 0;
  if (H_div2 && W_div2) {
    for (int i = 0; i < count; i++) {
      if (num[i] % 4 != 0) {
        cout << "No" << endl;
        return;
      }
    }
    cout << "Yes" << endl;
  } else if (!H_div2 && !W_div2) {
    int div4[4] = {0, 0, 0, 0};
    for (int i = 0; i < count; i++) {
      div4[num[i] % 4]++;
    }
    if (div4[1] + div4[3] <= 1 && (div4[2] + div4[3]) * 2 <= H + W - 1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    int div4[4] = {0, 0, 0, 0};
    int even;
    if (H_div2) {
      even = H;
    } else {
      even = W;
    }
    for (int i = 0; i < count; i++) {
      div4[num[i] % 4]++;
    }
    if (div4[1] == 0 && div4[3] == 0 && div4[2] * 2 <= even) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

int main() {
  cin >> H >> W;
  for (int h = 0; h < H; h++) {
    string input;
    cin >> input;
    for (int w = 0; w < W; w++) {
      s[W * h + w] = input[w];
    }
  }
  int size = H * W;
  sort(s, s + size);
  char before = s[0];
  int count = 0;
  for (int i = 0; i < size; i++) {
    if (s[i] != before) {
      count++;
      before = s[i];
    }
    num[count]++;
  }
  count++;
  solve(count);

  return 0;
}


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

int n;

int solve(string s){
  int cur=1;
  if(isdigit(s[cur])){
    int ret=s[cur]-'0';
    cur++;
    while(isdigit(s[cur])){
      ret=ret*10+(s[cur]-'0');
      cur++;
    }
    return ret/2+1;
  }
  else{
    vector<int> v;
    stack<int> st;
    for(int i=1; i<s.length(); i++){
      if(s[i]=='['){
	st.push('[');
      }
      if(s[i]==']'){
	st.pop();
	if(st.empty()){
	  v.push_back(solve(s.substr(cur, i-cur)));
	  cur=i+1;
	}
      }
    }
    sort(v.begin(), v.end());
    int ret=0;
    for(int i=0; i<v.size()/2+1; i++)
      ret+=v[i];
    return ret;
  }
}

int main(){
  cin>>n;
  for(int i=0; i<n; i++){
    string s;
    cin>>s;
    cout<<solve(s)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1296
import numpy as np
N,L = map(int,input().split())
aji_all = aji_all = N*L + (N-1)*N/2
aji_list = np.arange(L,L+N,1)
idx = np.argmin(np.abs(aji_list))
ans = aji_all - aji_list[idx]
print(int(ans))

Measured memory_bytes: 14284
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//Private Teacher
public class Main{

	long augumentPath(int v, int t, long f, long[][] cap, boolean[] used){
		if(v==t)return f;
		used[v] = true;
		for(int i=0;i<cap[v].length;i++){
			if(cap[v][i]>0 && !used[i]){
				long d = augumentPath(i, t, Math.min(f, cap[v][i]), cap, used);
				if(d>0){
					cap[v][i] -= d;
					cap[i][v] += d;
					return d;
				}
			}
		}
		return 0;
	}
	
	long maxFlow(int s, int t, long[][] cap){
		long flow = 0;
		int n = cap.length;
		boolean[] used = new boolean[n];
		while(true){
			Arrays.fill(used, false);
			long f = augumentPath(s, t, Long.MAX_VALUE, cap, used);
			if(f==0)return flow;
			flow += f;
		}
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		String[] day = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
		Map<String, Integer> ref = new HashMap<String, Integer>();
		for(int i=0;i<7;i++)ref.put(day[i], i);
		for(;;){
			int n = sc.nextInt();
			long W = sc.nextLong();
			if((n|W)==0)break;
			long[][] cap = new long[n+9][n+9];
			for(int i=1;i<=7;i++)cap[0][i]=W;
			long s = 0;
			for(int i=0;i<n;i++){
				long t = sc.nextLong();
				s += t;
				cap[i+8][n+8] = t;
				int c = sc.nextInt();
				while(c--!=0)cap[ref.get(sc.next())+1][i+8] = W;
			}
			System.out.println(maxFlow(0, n+8, cap)==s?"Yes":"No");
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#include<sstream>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	int n,m;
	cin>>n>>m;
	vi in(n);
	rep(i,n)scanf("%d",&in[i]);
	sort(all(in));
	in.pb(inf);
	while(m--){
		int a;scanf("%d",&a);
		int ma=0;
		int c=in[0]/a+1;
		while(1){
			int t=lower_bound(all(in),c*a)-in.begin();
			if(t==0)continue;
			ma=max(ma,in[t-1]%a);
			if(t==n)break;
			c++;
		}
		printf("%d\n",ma);
	}
}

Measured memory_bytes: 3380
fun main(args: Array<String>) {
    var s = readLine()!!
    val t = readLine()!!

    if (s == t) {
        println("Yes")
        return
    }

    fun String.rotate() = drop(length - 1) + take(length - 1)

    for (i in 1..s.length) {
        s = s.rotate()
        if (s == t) {
            println("Yes")
            return
        }
    }
    println("No")
}

Measured memory_bytes: 33564
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 200005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
vector<int>ed[N];
int n;
int v[N];
vector<int>lis;
int ans[N];
void dfs(int i,int p){
	int id=lower_bound(lis.begin(), lis.end(), v[i])-lis.begin();
	int f=0;
	int tmp;
	if(id==lis.size()){
		f=1;
		lis.pb(v[i]);
	}
	else{
		tmp=lis[id];
		lis[id]=v[i];
	}
	ans[i]=lis.size();
	for(int j:ed[i]){
		if(j==p)continue;
		dfs(j,i);
	}
	//cout<<i<<": ";
	//for(int j:lis)cout<<j<<" ";cout<<"\n";
	if(!f)lis[id]=tmp;
	else lis.pop_back();
}
void solve(){
	cin>>n;
	rep(i,n)cin>>v[i+1];
	rep(i,n-1){
		int u,v;
		cin>>u>>v;
		ed[u].pb(v);
		ed[v].pb(u);
	}
	dfs(1,0);
	for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

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

using namespace std;
int gcd( int m, int n )
{
	while( m != n )
	{
		if ( m > n ) m = m - n;
		else         n = n - m;
	}
	return m;
}
int main(){
  int W,H,C;
  cin>>W>>H>>C;
  int squares=gcd(W,H);
  cout<<W/squares*H/squares*C<<endl;

  return 0;
}

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

using namespace std;

int main() {
	
	int L[3];
	int T[4] = {0};
	bool f = 0;
	
	while( cin >> L[0] >> L[1] >> L[2]) {
	
	sort(L, L+3);
	
	if( L[0] + L[1] <= L[2] ) f = 1;
	if(f) continue;
	
	if( L[0] * L[0] + L[1] * L[1] 
	== L[2] * L[2] )
	T[1]++;
	
	else if(L[0] * L[0] + L[1] * L[1] 
	> L[2] * L[2] )
	T[2]++;
	
	else
	T[3]++;
	
	T[0]++;
	}

	cout << T[0] << " " << T[1] << " " << T[2] << " " << T[3] << "\n";
	return 0;
}



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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define UB upper_bound
#define LB lower_bound
#define PB push_back
#define mp make_pair
#define F first
#define S second
#define be(a) (a).begin(),(a).end()
#define deb(x) cout<< #x <<" "<<endl;
#define deb2(x, y) cout<< #x <<" "<< x <<endl<< #y <<" "<<y<<endl
#define fo(i, n) for(long long i=0; i<n; i++)
#define Fo(i, n, k) for(long long i=k; i<n; i++)
#define mod 1000000007
#define int long long

typedef long long ll;

void fileIO()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
 
typedef vector<pair<int, int>> vll;
typedef unordered_map<int, int> ump;



bool sortbysecdesc(const pair<int, int> &a, 
                    const pair<int, int> &b) 
{ 
    return a.second>b.second;
}

vector<vector<int>> dp(100001, vector<int>(2, -1));

bool stones(vector<int>A, int k, int chance)
{
    int &ans = dp[k][chance];
    if(ans != -1) return ans;
    if(k<=0){ans = abs(1-chance); return ans;}
    else
    {
        int winner = chance;
        for(int i = 0; i<A.size(); i++)
        {
            if(k>=A[i])
            {
                int temp = stones(A, k-A[i], abs(chance-1));
                if(temp == winner) {ans = winner; return ans;}
            }
             
        }

        ans = abs(1-winner);
        return ans;
    }
    
}



int32_t main()
{
    IOS;
    fileIO();
    int T;
    T = 1;
    //cin>>T;

    while(T--)
    {
        int n, k;
        cin>>n>>k;
        vector<int> A(n);
        for(int i = 0; i<n; i++) cin>>A[i];

        int res = stones(A, k, 0);

        if(res == 0) cout<<"First\n";
        else cout<<"Second\n";
        


    }
    
    return 0;
}



Measured memory_bytes: 102424
#include<iostream>
using namespace std;
int main()
{
	int tree,spectors;
	cin>>tree>>spectors;
	int sum=0;
	sum=tree/(1+spectors*2); 
	if(tree%(1+spectors*2)!=0)
	{
		cout<<sum+1;
	}
	else
	{
		cout<<sum;
	}
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = list(input())

a = [chr(i) for i in range(65, 65+26)]
b = [chr(i) for i in range(65+N, 65+26)]
for i in range(N):
    b.append(a[i])

a_dict = {}
for i in range(len(a)) :
    a_dict[a[i]] = b[i]
for i in range(len(S)) :
    S[i] = a_dict[S[i]]

print(''.join(S))

Measured memory_bytes: 3064
# 目指すグリッドは
# ABCABCABC..
# BCABCABCA..
# CABCABCAB..
# ABCABCABC..
# ...
# N = 500なので総マス数は250000
# 色の種類は30種類
# すべてのマスをあまりごとに3グループに分ける
# 各グループにおいて、各色が何マスずつあるかを計算する。250000回
# 長さ30の配列 * 3になるのであとは変更先の色をすべて試す。30 * 3回
# 隣あったマスを同じ色にすることができないため、
# グループごとに候補を3位まで用意し、3 * 2 * 1は6通りをすべて試す。
# 3位と4位がタイのときはどっちを取っても大丈夫

N,C = map(int,input().split())

D = [[0]*C for i in range(C)] # 違和感
for i in range(C):
  D[i] = list(map(int,input().split())) # 色は0-indexで指定
  # D[i][j]で、iをjに変えるときの違和感を算出

# print(D)

groups = [[0]*C for i in range(3)]

for i in range(N):
  line = list(map(int,input().split()))
  for j in range(len(line)):
    groups[(i+j)%3][line[j] - 1] += 1

# groups[i(グループ名)][j(色 0-index)] = 該当する個数 が出来た。
# 各グループに対して、各色に塗り替えたときの違和感を計算する
pattern = [[[0]*2 for j in range(C)] for i in range(3)]
# pattern[i(グループ名)][j(色 0-index))] = 対象の色に塗り替えたときの違和感
# 30 * 30 = 900, 900 * 3 = 2700

for i in range(len(groups)):
  # グループごとのループ
  for j in range(C):
    # 変更後の色j
    iwakan = 0 # 色jに変えるときの違和感を累積
    for k in range(len(groups[i])):
      # グループiには色kがいくつあるか
      iwakan += groups[i][k] * D[k][j]
    pattern[i][j][0] = iwakan
    pattern[i][j][1] = j # あとで並び替えるため、何色に変えるかをメモしておく

for i in range(len(pattern)):
#  print("bef",pattern[i])
  pattern[i] = sorted(pattern[i],key = lambda x:x[0])
#  print("after",pattern[i])

ans = 10 ** 9 + 7
for a in range(3): # グループ1が何位の数字を使うか
  for b in range(3): # 同2
    if pattern[0][a][1] == pattern[1][b][1]:
      continue
    for c in range(3): # 同3
      if pattern[0][a][1] == pattern[2][c][1]:
        continue
      if pattern[1][b][1] == pattern[2][c][1]:
        continue
      val = pattern[0][a][0] + pattern[1][b][0] + pattern[2][c][0]
      if val < ans:
        ans = val
print(ans)
    


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

int main() {

  string S;
  cin >> S;

  if (S[0] == S[1] && S[1] == S[2]) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }

  return 0;

}

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

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

	int n = N;
	int c = n % 10;
	n /= 10;
	int b = n % 10;
	n /= 10;
	int a = n % 10;

	if ((a == b) && (b == c)) {
		cout << N << endl;
		return 0;
	}

	bool flg = true;
	if (a == b) {
		if (b < c) { flg = false; }
	} else if (a < b) {
		flg = false;
	} else if (a > b) {
		if (a < c) { flg = false; }
	}

	if (!flg) { ++a; }
	cout << a << a << a << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rep2(i, b) for (int i = 0; i < b; i++)
#define repl(i, a, b) for (ll i = a; i <= b; i++)
#define ppi pair<int, int>
#define scl(n) scanf("%d", &n);
#define pcl(n) printf("%d\n", n)
#define pcl1(n) printf("%lld ", n)
#define FastRead                  \
	ios_base::sync_with_stdio(0); \
	cin.tie(0)
bool comp(ppi a, ppi b)
{
	return a.first < b.first;
}

int main()
{
	ll x, y;
	cin >> x >> y;
	if (x == 1)
	{
		if (y == 4 || y == 2)
		{
			cout << "Yes\n";
		}
		else
			cout << "No\n";
	}
	else
	{
		if (x >= y)
		{
			cout << "No\n";
		}
		else
		{
			bool cnt=0;
			ll i=0LL,n;
			while(i<=x)
			{
				n=x-i;
				if(2*i+4*n==y)
				{
					cnt=1;
					break;
				}
				i++;
			}
			if(cnt) cout<<"Yes\n";
			else cout<<"No\n";
		}
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int K, S;
  cin >> K >> S;
  int ans =0;
  for (int i=0; i <= K; i++){
      for (int j=0; j<= K; j++){
        if( S-i-j >= 0 && S-i-j<= K) ans++;
      }
  }
  
  cout << ans << endl; 
  
} 


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

using namespace std;

#define MAX 55000
#define INF 1e9
typedef long long Int;

int main(){
  Int a,b,d;
  while(cin >> a >> b >> d, a){
    Int x,y;
    Int ansx,ansy,min1,min2;
    ansx = ansy = min1 = min2 = INF;
    for(x = 0 ; x < MAX ; x++){
      Int ax = a*x;
      y = (ax+d) % b;
      if(ax+d >= b && y == 0){
        y = (ax+d)/b;
        if(x+y < min1){
          min1 = x+y;
          ansx = x;
          ansy = y;
        }else if(x+y == min1 && ax+b*x < min2){
          min2 = ax+b*x;
          ansx = x;
          ansy = y;
        }
      }
    }
    for(y = 0 ; y < MAX ; y++){
      Int by = b*y;
      x = (by+d) % a;
      if(by+d >= a && x == 0){
        x = (by+d)/a;
        if(x+y < min1){
          min1 = x+y;
          ansx = x;
          ansy = y;
        }else if(x+y == min1 && a*x+by < min2){
          min2 = a*x+by;
          ansx = x;
          ansy = y;
        }
      }
    }
    for(y = 0 ; y < MAX ; y++){
      Int by = b*y;
      x = (d-by) % a;
      if(d-by >= a && x == 0){
        x = (d-by)/a;
        if(x+y < min1){
          min1 = x+y;
          ansx = x;
          ansy = y;
        }else if(x+y == min1 && a*x+by < min2){
          min2 = a*x+by;
          ansx = x;
          ansy = y;
        }
      }
    }
    cout << ansx << " " << ansy << endl;
  }
  return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP0(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define RREP0(i,n) for(int i=n-1; i>=0; --i)
#define RREP1(i,n) for(int i=n; i>=1; --i)

#define SORT(c) sort((c).begin(),(c).end())
#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define CLR(a) memset((a), 0 ,sizeof(a))

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

const int INTINF = 2147483647;
const LL LLINF = 9223372036854775807;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MAX = 100000;
const int NIL = -1;

int gcd(int a,int b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int n,m,q;
VI G[MAX];
int color[MAX];


void dfs(int r, int c) {
  stack<int> S;
  S.push(r);
  color[r] = c;
  while ( !S.empty() ) {
    int u = S.top(); S.pop();
    REP0( i, G[u].size() ){
      int v = G[u][i];
      if ( color[v] == NIL ) {
        color[v] = c;
        S.push(v);
      }
    }
  }
}


void assignColor(){
  int id=1;
  REP0(i,n) color[i]=NIL;
  REP0(u,n) if (color[u]==NIL) dfs(u, id++);
  //連結成分ごとにdfsしcoloring
}


void input(){
  std::cin >> n >> m;
  int s,t;
  REP0(i,m){
    std::cin >> s >> t;
    G[s].PB(t);
    G[t].PB(s);
  }
}


void output() {
  std::cin >> q; int s,t;
  REP0(i,q){
    std::cin >> s >> t;
    if (color[s]==color[t]) {
      std::cout << "yes" << '\n';
    }else{
      std::cout << "no" << '\n';
    }
  }
}


int main(int argc, char const *argv[]) {
  input();
  assignColor();
  output();
  return 0;
}



Measured memory_bytes: 8808
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


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



    ll a, b;
    cin >> a >> b;
    ll ans = 0;
    set<ll> aa, bb;

    if (a % 2 == 0) {
        aa.insert(2);
        while (a % 2 == 0) a /= 2;
    }


    if (b % 2 == 0) {
        bb.insert(2);
        while (b % 2 == 0) b /= 2;
    }

    for (ll i = 3; i < sqrt(a) + 1; i += 2) {
        if (a % i == 0) {
            aa.insert(i);
            while (a % i == 0) a /= i;
        }
    }

    for (ll i = 3; i < sqrt(b) + 1; i += 2) {
        if (b % i == 0) {
            bb.insert(i);
            while (b % i == 0) b /= i;
        }
    }

    if (a > 1) aa.insert(a);
    if (b > 1) bb.insert(b);
    for (ll e : aa) {
        ans += (bb.find(e) != bb.end());
    }

    cout << ans + 1;
}

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

#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;

void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}

template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}

template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto i=begin(c);i!=end(c);++i)
		os<<(i==begin(c)?"":" ")<<*i;
	return os<<']';
}

constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;

void prev(int n,int k,vi& a)
{
	if(a.back()==1)
		a.pop_back();
	else{
		a.back()--;
		while(a.size()<n)
			a.push_back(k);
	}
}

int main()
{
	#ifndef _GLIBCXX_DEBUG
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	constexpr char endl='\n';
	#endif

	for(int k,n;cin>>k>>n&&k|n;){
		vi res(n);
		if(k%2==0){
			res[0]=k/2;
			repi(i,1,n) res[i]=k;
		}
		else{
			rep(i,n) res[i]=(k+1)/2;
			rep(i,n/2) prev(n,k,res);
		}
		rep(i,res.size()) cout<<res[i]<<"\n "[i+1<res.size()];
	}
}


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

const int MAX_N = 2e5+10;
const int MOD = 1e9+7;
int a[MAX_N],b[MAX_N];
ll dp[MAX_N],sum[MAX_N];
int n;

void solve()
{
    n = unique(a+1,a+n+1)-(a+1);
	dp[0] = 1LL; 
	sum[a[1]] = 1LL;
	for(int i=1; i<=n; i++){
		dp[i] = sum[a[i]];
		if(i!=n)(sum[a[i+1]]+=dp[i])%=MOD;
	}
	printf("%lld\n",dp[n]);
}

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

Measured memory_bytes: 7516
#include<bits/stdc++.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <limits.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <string>
#include <functional>
#include <vector>
#include <numeric>
#include <deque>
#include <bitset>
#include <iostream>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<int, int> pi;
const int mod = 1e9 + 7;

string s;
lint fact[2000002], invf[2000002];
lint ipow[2000002];

lint c(int x, int y){
	return fact[x] * (invf[y] * invf[x-y] % mod) % mod;
}

lint p(int x){
	return ipow[x];
}

struct query{
	int x, y, idx;
};

vector<query> q;
int ret[2000002];

lint fpow(int x, int y){
	lint ret = 1, piv = x;
	while(y){
		if(y&1) ret *= piv;
		piv *= piv;
		ret %= mod;
		piv %= mod;
		y >>= 1;
	}
	return ret;
}

int solve(int x, int y){
	if(y < x/2){
		lint ret = mod - fpow(26, x);
		for(int i=x; i>x-y; i--){
			ret += c(x, i) * ipow[i];
			ret %= mod;
		}
		return (mod - ret) % mod;
	}
	lint ret = 0;
	for(int i=0; i<=x-y; i++){
		ret += c(x, i) * ipow[i];
		ret %= mod;
	}
	return ret;
}
int main(){
	fact[0] = invf[0] = ipow[0] = 1;
	for(int i=1; i<=2000001; i++){
		fact[i] = fact[i-1] * i % mod;
		ipow[i] = ipow[i-1] * 25 % mod;
		invf[i] = fpow(fact[i], mod - 2);
	}
	int Q;
	cin >> Q >> s;
	int n=s.length();
	int len=n+Q;
    printf("%d\n", solve(len, (int)s.size()));

}


Measured memory_bytes: 52168
#include <stdio.h>

int main(){
	int N,Q;
	int i;
	int cnt;
	
	scanf("%d %d",&N,&Q);
	
	char S[N];
	int l[Q];
	int r[Q];
	int ac[N];
	
	scanf("%s",&S);
	
	for(i=0;i<Q;i++){
		scanf("%d %d",&l[i],&r[i]);
	}
	
	cnt=0;
	ac[0]=0;
	for(i=1;i<N;i++){
		if(S[i-1]=='A' && S[i]=='C'){
			cnt++;
			ac[i]=cnt;
		}else{
			ac[i]=cnt;
		}
	}
	
	for(i=0;i<Q;i++){
		printf("%d\n",ac[r[i]-1]-ac[l[i]-1]);
	}
	
	return 0;
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define speed() ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sz(x) (int)(x).size()
#define _USE_MATH_DEFINES
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    speed();
    int A, B, M; cin >> A >> B >> M;
    int a[A], b[B];
    rep(i, 0, A) cin >> a[i];
    rep(i, 0, B) cin >> b[i];
    int amount = *min_element(a, a+A) + *min_element(b, b+B);
    rep(i, 0, M) {
        int x, y, c; cin >> x >> y >> c;
        x--; y--;
        amount = min(amount, (a[x] + b[y]) - c);
    }
    cout << amount << endl;
    return 0;
}

Measured memory_bytes: 1024
// ConsoleApplication字典单词问题.cpp: 定义控制台应用程序的入口点。
//
#include <stdio.h>
#include<stdlib.h>
#include<string.h>
void change1(char s[], int m)
{
	char c;
	int i;
	int flag;

	for (c='a'; c<='z'; c++)
	{
		flag = 0;
		for (i = 0; i < m; i++)
		{
			if (s[i] == c)
			{
                         flag = 1;
				break;
			}
		}
		if (flag == 0)
		{
			break;
		}
	}
	s[m] = c;
	s[m + 1] = 0;
}
void change2(char s[])
{
	int i;
	int j;
	//char c;
	char c='z'+1;

	for (i = 24; i >= 0; i--)
	{
		//c = 'z' + 1;
		for (j = 25; j > i; j--)
		{
			if (s[i]< s[j])
			{
				if(c>s[j])
				c = s[j];
			}
		}
		if (c != 'z'+1)
		{
			s[i] = c;
			s[i + 1] = 0;
			return;
		}
	}
}
int main()
{
	char s[30];
	int i;
	int n;

	//printf("000\n");
	gets(s);
	//printf("000\n");
	n = strlen(s);
	//printf("000\n");
	if (n != 26)
	{
		change1(s, n);
		puts(s);
	}
	else if (strcmp(s, "zyxwvutsrqponmlkjihgfedcba")==0)
	{
		//printf("000\n");
		printf("-1");
	}
	else
	{
		//printf("000\n");
		change2(s);
		//printf("000\n");
		puts(s);
	}

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;using ll=long long;using vi=vector<int>;using vvi=vector<vi>;using vl=vector<ll>;using vvl=vector<vl>;using P=pair<int,int>;using PL=pair<ll,ll>;using vp=vector<P>;using vpl=vector<PL>;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/2;constexpr int INF=inf<int>,MOD=1000000007;constexpr ll LINF=inf<ll>;
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...)_ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n)for(int i=n-1;i>=0;--i)
#define REPA(i,v)REP(i,(v).size())
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define bit(n)(1ll<<(n))
#define F first
#define S second
#define endl '\n'
#define cho(n,a,b)cout<<((n)?a:b)<<endl
void YES(int n){cho(n,"YES","NO");}void Yes(int n){cho(n,"Yes","No");}void Poss(int n){cho(n,"Possible","Impossible");}
void _print(ostream&){}template<class T,class...U>void _print(ostream&s,const T&t,const U&...u){s<<t<<(sizeof...(u)?' ':'\n');_print(s,u...);}
template<class...T>void print(const T&...t){_print(cout,t...);}template<class...T>void dprint(const T&...t){_print(cerr,t...);}
#ifndef LOCAL
struct osd{template<class T>osd&operator<<(const T&t){return*this;}};osd cer_;
#define dprint(...)
#define cerr cer_
#endif
template<class T>bool chmax(T&a,const T&b){bool x=a<b;x?a=b:b;return x;}template<class T>bool chmin(T&a,const T&b){bool x=a>b;x?a=b:b;return x;}
template<class T,class U>ostream&operator<<(ostream&o,const pair<T,U>&p){return o<<p.F<<' '<<p.S;}
template<class T,class U>istream&operator>>(istream&i,pair<T,U>&p){return i>>p.F>>p.S;}
template<class T>class iterable{static false_type c(string v);template<class U>static auto c(U v)->decltype(all(v),true_type());static false_type c(...);public:const static bool value=decltype(c(declval<T>()))::value;};
template<class T,typename=enable_if_t<iterable<T>::value>>ostream&operator<<(ostream&o,const T&v){for(auto&&i:v)o<<i<<' ';return o;}
template<class T>istream&operator>>(istream&i,vector<T>&v){for(T&j:v)i>>j;return i;}
template<class T>vector<T>&operator<<(vector<T>&v,const T&t){v.push_back(t);return v;}
template<class T>set<T>&operator<<(set<T>&v,const T&t){v.insert(t);return v;}
template<class T>multiset<T>&operator<<(multiset<T>&v,const T&t){v.insert(t);return v;}
double deg(double rad){return rad*180/3.1415926535897932384626;}
int main(){
    cin.tie(0);ios::sync_with_stdio(0);
    cout<<setprecision(11);
    double a,b,x;

    cin>>a>>b>>x;
    x/=a;
    if(a*b<=x*2){
        double c=(a*b-x)*2/a;
        cout<<deg(atan2(c,a))<<endl;
        return 0;
    }
    double c=x/b*2;
    cout<<deg(atan2(b,c))<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <fstream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <string.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	//fixed<<setprecision(3)
    string s;
  cin>>s;
  if(s=="ABC")cout<<"ARC";
  else cout<<"ABC";
	return 0;
}

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

int main(){
    ll a,b;
    cin>>a>>b;
    int ans=0;
    while(1){
        ans++;
        a*=2;
        if(a>b)break;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long i64;
const int MAX = 1e6 + 10;
const int MOD = 1e9 + 7;
const int oo = 1e9;

bool check(i64 d, i64 n){
	while(n % d == 0)n /= d;
	return n % d == 1;
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	#define endl '\n'
	i64 n;
	cin >> n;
	i64 ans = 0;
	for(i64 d = 2;  d * d <= n; d++){
		if(n % d == 0){
			if(d * d != n)ans += check(n / d, n);
			ans += check(d, n);
		}
		else if(d * d <= n -1 && (n -1) % d == 0){
			ans += 1;
			if(d * d != n - 1)ans += 1;
		}
	}
	if(n == 2)cout << 1 << endl;
	else cout << ans + 2 << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
using ull=unsigned long long int;
using P=pair<ll,ll>;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
int n,m;
cin>>n>>m;
ll sum=0;
V<ll> a(n);
for(int i=0;i<n;i++){
  cin>>a[i];
  sum+=a[i];
} 
sum=(sum+(4*m)-1)/(4*m);
int cnt=0;
for(int i=0;i<n;i++){
  if(sum<=a[i])cnt++;
}
if(cnt>=m)cout<<"Yes"<<"\n";
else cout<<"No"<<"\n";
}

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

int main()
{
    /*int n;
    cin>>n;
    int a[maxc];
    int l=0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            a[l++]=i;
            a[l++]=n/i;
        }
    }
    sort(a,a+l);
    for(int i=0;i<l;i++)
        cout<<a[i]<<" ";
    cout<<endl;*/
    ll n,m;
    cin>>m>>n;
    ll a[maxc];
    ll l=0;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            a[l++]=i;
            a[l++]=n/i;
        }
    }
    sort(a,a+l);
    for(int i=0;i<l;i++){
        if(m<=a[i]){
            m=a[i];
            break;
        }
    }
    //cout<<"n="<<n<<" m="<<m<<endl;
    cout<<n/m<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys, math
from functools import lru_cache
sys.setrecursionlimit(10**9)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]

# unionfind
class Uf:
    def __init__(self, N):
        self.p = list(range(N))
        self.rank = [0] * N
        self.size = [1] * N

    def root(self, x):
        if self.p[x] != x:
            self.p[x] = self.root(self.p[x])

        return self.p[x]

    def same(self, x, y):
        return self.root(x) == self.root(y)

    def unite(self, x, y):
        u = self.root(x)
        v = self.root(y)

        if u == v: return

        if self.rank[u] < self.rank[v]:
            self.p[u] = v
            self.size[v] += self.size[u]
            self.size[u] = 0
        else:
            self.p[v] = u
            self.size[u] += self.size[v]
            self.size[v] = 0

            if self.rank[u] == self.rank[v]:
                self.rank[u] += 1

    def count(self, x):
        return self.size[self.root(x)]

def main():
    N, M = mi()

    if M == 0:
        print(1)
        return
        
    A, B = i2(M)

    uf = Uf(N)
    for i in range(M):
        uf.unite(A[i]-1, B[i]-1)

    print(max(uf.count(i) for i in range(N)))
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 63124
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<cstring>
using namespace std;
long long int mod = 1e9 + 7;
template <class T>
void inputV(vector<T> &x, int n){
  for(int i=0; i<n; i++) cin >> x[i];
}

int n;
long long int x;
long long int b[60];
long long int p[60];

void init() {
  b[0] = 1; p[0] = 1;
  for(int i=1; i<=n; i++){
    b[i] = 2*b[i-1] + 3;
    p[i] = 2*p[i-1] + 1;
  }
}

long long int f(int n, long long int x) {
  if(x == 0) return 0;
  else if(n == 0){
    return 1;
  } else if(x <= 1 + b[n-1]) {
    return f(n-1, x-1);
  } else {
    return p[n-1] + 1 + f(n-1, x-2-b[n-1]);
  }
}

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

  init();
  cout << f(n, x) << endl;

  return 0;
}

Measured memory_bytes: 256
s = input().split()
s_=s[0]
t=s[1]
s = input().split()
a=int(s[0])
b=int(s[1])
s = input().split()
if s[0] in s_:
    print(a-1,b)
elif s[0] in t:
    print(a,b-1)
else:
    print(a,b)

Measured memory_bytes: 3060
import sys
s = input()
target = "keyence"

if s == target:
    print("YES")
    sys.exit()
for i in range(len(s)):
    for j in range(i, len(s)):
        st = s[:i] + s[j:]
        if st == target:
            print("YES")
            sys.exit()

print("NO")

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

bool tsort(vector<int> &S, const vector<vector<int>> &edges) {
    int V = edges.size();

    vector<int> indeg(V, 0);
    for(int i = 0; i < V; ++i) {
        for(int to : edges[i]) ++indeg[to];
    }

    stack<int> done;
    for(int i = 0; i < V; ++i) {
        if(indeg[i] == 0) done.push(i);
    }

    while(!done.empty()) {
        int cur = done.top();
        done.pop();
        S.push_back(cur);
        for(int to : edges[cur]) {
            --indeg[to];
            if(indeg[to] == 0) done.push(to);
        }
    }

    return S.size() == V;
}

int pp(int a, int b) {
    return max(a, b) + 1000 * min(a, b);
}

static const int MAX_NN = 1000000;
int dp[MAX_NN] = {};

int main() {
    int N;
    cin >> N;
    vector<vector<int>> edges(MAX_NN);
    for(int i=0; i<N; ++i) {
        int prev;
        cin >> prev;
        --prev;
        for(int j=1; j+1<N; ++j) {
            int next;
            cin >> next;
            --next;
            edges[pp(i, prev)].push_back(pp(i, next));
            prev = next;
        }
    }

    vector<int> order;
    if(!tsort(order, edges)) {
        cout << -1 << endl;
        return 0;
    }

    for(int i=0; i<MAX_NN; ++i) {
        int cur = order[i];
        for(int to : edges[cur]) {
            dp[to] = max(dp[to], dp[cur] + 1);
        }
    }

    int res = 0;
    for(int i=0; i<MAX_NN; ++i) {
        res = max(res, dp[i]);
    }
    cout << res + 1 << endl;
}

Measured memory_bytes: 50812