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


int main(){
    LL n,m,v,p;cin >> n >> m >> v >> p;
    vector<LL> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    sort(ALL(a));
    LL l = -1,r = n-1;
    while(r - l > 1){
        LL mm = (r + l) / 2;
        LL sum = 0;
        LL t = a[mm] + m;
        for (int i = 0; i <= mm; i++) {
            sum += m;
        }
        int idx = -1;
        for (int i = mm + 1; i < n; i++) {
            if(a[i] <= t){
                sum += t - a[i];
            }
            else{
                idx = i;
                break;
            }
        }
        LL res = m * v - sum;
        LL id = 0;
        if(idx!=-1&&p <= n - idx){
            l = mm;
            continue;
        }
        if(res <= 0){
            r = mm;
            continue;
        }
        for (int i = n-1; i > mm; i--) {
            if(a[i] <= t) res -= a[i] + m - t;
            else res -= m;
            if(res <= 0){
                id = i;
                break;
            }
        }
        if(n - id < p) r = mm;
        else l = mm;
    }
    cout << n - r << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 303
const int mod=998244353;
inline int read(){
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,m,gu,dp[N][N][N],a[N],ans,sum[N],s1[N][N],s2[N<<1][N<<1];
char s[N];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1),m=read();
	s[++n]='0';
	m=min(n,m);
	for(int i=1;i<=n;++i){
		if(s[i]=='0')++gu;
		else ++a[gu+1];
	}
	for(int i=1;i<=gu;++i){
		sum[i]=a[i]+sum[i-1];
	}
	dp[0][0][0]=1;
	for(int i=1;i<=gu;++i){
		for(int k=0;k<=m;++k){
			s1[0][k]=dp[i-1][0][k];
			for(int j=1;j<=n-gu;++j){
				s1[j][k]=(s1[j-1][k]+dp[i-1][j][k])%mod;
			}
		}
		for(int k=sum[i]-a[i];k<=n-gu+min(n-gu,m)-a[i];++k){
			s2[k][0]=dp[i-1][0][k]%mod;
			for(int p=1;p<=k;++p){
				s2[k][p]=(s2[k][p-1]+dp[i-1][p][k-p])%mod;
			}
		}
		for(int j=sum[i];j<=n-gu;++j){
			int lim=min(j,n-sum[i-1]-gu);
			if(lim>a[i]){
				for(int k=0;k<=min(j,m);++k){
					dp[i][j][k]=1LL*(s1[j-(a[i]+1)][k]-s1[j-lim-1][k]+mod)%mod;
				}
			}
			for(int k=0;k<=min(j,m);++k){
				dp[i][j][k]=(dp[i][j][k]+s2[j+k-a[i]][j-max(0,a[i]-k)]-s2[j+k-a[i]][j-a[i]-1])%mod;
				dp[i][j][k]=(dp[i][j][k]<0?dp[i][j][k]+mod:dp[i][j][k]);
			}
		}
	}
	for(int k=0;k<=m;++k){
		ans=(ans+dp[gu][n-gu][k])%mod;
	}
	cout<<ans<<endl;
	return 0;
}



Measured memory_bytes: 31052
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aajisaka
 */

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class BEasyLinearProgramming {
public:
    void solve(istream& cin, ostream& cout) {
      SPEED;
      ll a, b, c, k; cin >> a >> b >> c >> k;
      if (k <= a) {
        cout << k << endl;
      } else if (k <= a+b) {
        cout << a << endl;
      } else {
        cout << a - (k - a - b) << endl;
      }
    }
};

signed main() {
  BEasyLinearProgramming solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

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

//Common
using namespace std;using f64 = double;using i64=long long;using u64=unsigned long long;
template<typename T> using Arr=vector<T>;template<typename T> using Func=function<T>;template<typename T> using Str=basic_string<T>;
#define hfor(v, s, e) for(int v=(s);(s)<=v&&v<(e);++v)//half-opened range
#define hfori(v, s, e) for(int v=(e)-1;(s)<=v&&v<(e);--v)//inversion
#define hforo(v, s, e) int v=(s);for(;(s)<=v&&v<(e);++v)//out declaration
#define hforoi(v, s, e) int v=(e)-1; for(;(s)<=v&&v<(e);--v)
#define cfor(v, s, e) hfor(v,(s),(e)+1)//closed range
#define cfori(v, s, e) hfori(v,(s),(e)+1)
#define cforo(v, s, e) hforo(v,(s),(e)+1)
#define cforoi(v, s, e) hforoi(v,(s),(e)+1)
#define rep(v,x) hfor(v,0,(x))
#define repi(v,x) hfori(v,0,(x))
#define repo(v,x) hforo(v,0,(x))
#define all(x) (x).begin(),(x).end()
#define pushb push_back
#define pushf push_front
#define popb pop_back
#define popf pop_front
#define empl emplace
#define emplb emplace_back
#define emplf emplace_front
#define fi first
#define se second
#define cxp constexpr
#define PQ std::priority_queue

//Math
template<typename T> cxp T inf() { return numeric_limits<T>::max() / 2; }
template<typename T> inline T sq(T x){return x*x;}
cxp int lgc(int x){return 64-__builtin_clzll(x-1);}
cxp int lgf(int x){return 63-__builtin_clzll(x);}
int rd(int lb, int ub){static mt19937 rng(time(0)^i64(new int)); return uniform_int_distribution<int>(lb, ub-1)(rng);}
int rd(int ub=inf<int>()){return rd(0,ub);}
const f64 pi=acosl(-1), eps=1e-10;

//IO
template<typename T>ostream& operator<<(ostream& s, const Arr<T>& a) {for(auto i:a) cout<<i<<' '; return s;}
int getint(){int x;cin>>x;return x;}
char getchr(){char x;cin>>x;return x;}
#ifndef DEBUG
	//#pragma GCC optimize ("Ofast") //somtimes it become more slower
	auto __PRE_RUN__=(ios::sync_with_stdio(0), cin.tie(0), cout.tie(0),(cout<<fixed<<setprecision(11)), 0);
#endif

//Misc
int sz(const auto& x){return x.size();}
auto split(auto s, auto p){
	Arr<decltype(s)> ret;
	auto it1=s.begin();
	for(auto it2=it1; (it2 = find(it1,s.end(),p)) != s.end(); it1=it2+1)
		ret.pushb({it1, it2});
	ret.pushb({it1,s.end()});
	return ret;
}
template<typename T> T rev(const T& a){return {a.rbegin(),a.rend()};}
Arr<int> range(int n){ Arr<int> ret(n); rep(i,n)ret[i]=i; return ret; }
struct defer{ defer(auto f):f(f){} ~defer(){f();} function<void()> f; };
#define defer(x) auto _##__COUNTER__ = defer([&](){x;});
#define lam(expr, ...) [&](__VA_ARGS__){return expr;}
#define reduce accumulate

#define endl '\n'//not interactive?
#define int i64//MLE?
using pint = pair<int,int>;
using tint = tuple<int,int,int>;

signed main(){
	int n; cin>>n;
	cout<<"Christmas ";
	rep(i,25-n)
		cout<<"Eve ";

	return 0;
}



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

struct node {
    node():p(-1),l(-1),r(-1){}
    int p, l, r;
};

void preorder(node t[], int id) {
    if(id==-1) return;
    cout<<' '<<id;
    preorder(t, t[id].l);
    preorder(t, t[id].r);
}
void inorder(node t[], int id) {
    if(id==-1) return;
    inorder(t, t[id].l);
    cout<<' '<<id;
    inorder(t, t[id].r);
}
void postorder(node t[], int id) {
    if(id==-1) return;
    postorder(t, t[id].l);
    postorder(t, t[id].r);
    cout<<' '<<id;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    node t[25];
    cin>>n;
    for(int i=0; i<n; i++) {
        int id, l, r;
        cin>>id>>l>>r;
        t[id].l=l;
        t[id].r=r;
        if(l!=-1) t[l].p=id;
        if(r!=-1) t[r].p=id;
    }
    int root;
    for(root=0; root<n&&t[root].p!=-1; root++);
    cout<<"Preorder\n";
    preorder(t, root);
    cout<<"\nInorder\n";
    inorder(t, root);
    cout<<"\nPostorder\n";
    postorder(t, root);
    cout<<'\n';
    return 0;
}

Measured memory_bytes: 1204
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <algorithm>
#include <unordered_map>
#define int                long long
#define pb                 push_back
#define pi                 pair<int,int>
#define vi                 vector<int>
#define all(v)             v.begin(),v.end()
#define MOD                1000000007
#define F                  first
#define S                  second
#define FOR(i,r)           for(int i=0;i<r;i++)
#define REP(i,l,r)         for(int i=l;i<r;i++)
#define RER(i,l,r)         for(int i=l;i>=r;i--)
#define print(v)           for(auto i : v)cout << i << ' ';
#define FASTIO             ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mem(arr,k)         memset(arr,k,sizeof(arr));
#define pii                acos(-1.0)
#define PI                 3.1415926535897932385
#define Sin(a)             sin((pi*a)/180)
#define test()             int x;cin >> x;while(x--)
using namespace std;
const int maxn = (int)2e3+5;
vector<int>g[maxn];
int dist[maxn][maxn];
void bfs(int src){
	queue<int>q;
	q.push(src);
	vector<int>vis(maxn,0),dis(maxn,0);
	vis[src]=1;
	dis[src]=0;
	while(!q.empty()){
		int nd = q.front();
		q.pop();
		for(auto i : g[nd]){
			if(vis[i])
				continue;

			dis[i] = dis[nd]+1;
			dist[src][i] = dis[i];
			vis[i] = 1;
			q.push(i); 
			
		}
	}
}
int32_t main(){


	FASTIO;
	int n,x,y;
	cin >> n >> x >> y;
	REP(i,1,n){
		g[i].pb(i+1);
		g[i+1].pb(i);
	}
	g[x].pb(y);
	g[y].pb(x);
	mem(dist,0);
	map<int,int>res;
	for(int i=1;i<=n;i++){
		bfs(i);
	}
	for(int i=1;i<=n;i++){
		for(int j=i+1;j<=n;j++){
			int d = dist[i][j];
			res[d]++;
		}
	}
	for(int i=1;i<n;i++){
		cout << res[i] << endl;
	}
    return 0;

}

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

int main() {



//write code hare

	int x, y;
	cin >> x >> y;


	int min = (x * 2);
	int max = (x * 4);

	if (y >= min && y <= max) {

		if (y % 2 == 0) {
			cout << "Yes";
		}
		else {
			cout << "No";
		}

	}
	else
	{
		cout << "No";
	}


}

Measured memory_bytes: 3116
#include<bits/stdc++.h>
using namespace std;
int f[3001][3001];
char s[3001],t[3001];
void fun(int x,int y){
	if(x==0||y==0)
		return;
	if(s[x-1]==t[y-1])
		fun(x-1,y-1);
	else if(f[x][y-1]>f[x-1][y])
		fun(x,y-1);
	else fun(x-1,y);
	if(s[x-1]==t[y-1])
		cout << s[x-1];
}       
int main(){
	int i,j,len_s,len_t;
	cin >> s >> t;
	len_s=strlen(s);
	len_t=strlen(t);
	for(i=0;i<=len_s;i++)
		for(j=0;j<=len_t;j++)
			f[i][j]=0;
	for(i=1;i<=len_s;i++){
		for(j=1;j<=len_t;j++){
			if(s[i-1]!=t[j-1])
				f[i][j]=max(f[i-1][j],f[i][j-1]);
			else
				f[i][j]=f[i-1][j-1]+1;
		}
	}    
	fun(len_s,len_t);
	return 0;
}        

Measured memory_bytes: 35584
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))
from collections import Counter
n = int(input())
A = inpl()

C1 = Counter(A[::2])
C2 = Counter(A[1::2])

S1 = sorted(C1.items(), key=lambda x: x[1], reverse=True) + [[0, 0]]
S2 = sorted(C2.items(), key=lambda x: x[1], reverse=True) + [[0, 0]]

if S1[0][0] != S2[0][0]:
    print(n - S1[0][1] - S2[0][1])
else:
    print(n - max(S1[1][1] + S2[0][1], S1[0][1] + S2[1][1]))

Measured memory_bytes: 21176
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <iomanip>
#include <bitset>
#include <cassert>
using namespace std;

typedef long long ll;



int main() {
	int n; cin >> n;
	vector<int> p(n);
	for (int i = 0; i < n; i++) cin >> p[i];
	sort(p.begin(), p.end());
	int s = 0;
	for (int i = 0; i < n - 1; i++) s += p[i];
	cout << s + p.back() / 2 << endl;
	return 0;
}


Measured memory_bytes: 256
line = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]

k = int(input())

print(line[k-1])


Measured memory_bytes: 2940
import sys
import math

from collections import defaultdict
from collections import deque
def load(vtype=int):
    return vtype(input().strip())
def load_list(seplator=" ", vtype=int):
    return [vtype(v) for v in input().strip().split(seplator)]
def exit():
    import sys
    sys.exit(0)
def perm_sub(li, used):
    if len(li) == len(used):
        return [deque()]
    k = []
    for i in range(len(li)):
        if i in used:
            continue
        used.add(i)
        sub_list = perm_sub(li, used)
        for sub in sub_list:
            sub.appendleft(li[i])
        k.extend(sub_list)
        used.discard(i)
    return k
def perm_li(li):
    return perm_sub(li, set())
def perm_n(n):
    return perm_sub(list(range(n)), set())
def join_i(li, sep=""):
    return sep.join([str(e) for e in li])
def li2n(li):
    n, base = 0, 1
    for i in range(len(li)-1, -1, -1):
        n += li[i] * base
        base *= 10
    return n
def sli2ili(li):
    return [int(s) for s in li] 
def prime_list(n):
    li = [i for i in range(2, n+1)]
    for i in range(len(li)):
        if li[i] >= int(math.sqrt(n)):
            break
        if li[i] == -1:
            continue
        for j in range(i+1, len(li)):
            if li[j] % li[i] == 0:
                li[j] = -1
    return [n for n in li if n != -1]
def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        r = a % b
        if r == 0: return b
        a, b = b, r
def lcm(a, b):
    return int(a * b / gcd(a,b))
def all_subset(li):
    s = []
    n = len(li)
    for bit in range(0, (1<<(n+1))):
        ss = set()
        for i in range(0, n):
            if (bit & (1 << i)):
                ss.add(li[i])
        s.append(ss)
    return s
def factorial(n):
    if n == 1:
        return 1
    return n * factorial(n-1)
def mCn(m, n):
    def factorial_ntimes(m, n):
        r = 1
        while n:
            r *= m
            m -= 1
            n -= 1
        return r
    return int(factorial_ntimes(m, n) / factorial(n))

s = load(str)
if s[2] == s[3] and s[4] == s[5]:
    print('Yes')
else:
    print('No')

    



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

int main() {
  int N;
  cin >> N;
  
  vector <int> house(N);
  
  for (int i = 0; i < N; i++)
    cin >> house.at(i);
  sort(house.begin(),house.end());
  
  cout << house.at(N-1) - house.at(0) << endl;
  
  }

Measured memory_bytes: 256
import sys 
from collections import deque,defaultdict
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
N = int(readline())
graph = [[] for _ in range(N+1)]
AB = []
for i in range(N-1):
    a,b = map(int,readline().split())
    AB.append((a,b))
    graph[a].append(b)
    graph[b].append(a)
    
dist = [-1] * (N+1)
dist[1] = 0
COL = defaultdict()
q = deque([(1,0)])
max_col = 0

def bfs(max_col):
    while q:
        x,pre_col = q.popleft()
        c = 1
        for nx in graph[x]:
            if dist[nx] != -1:
                continue
            if c == pre_col:
                c += 1
            COL[(x,nx)] = c
            dist[nx] = 1
            q.append((nx,c))
            max_col = max(max_col,c)
            c += 1
    return max_col  

max_col = bfs(max_col)
print(max_col)
for a,b in AB:
    if (a,b) in COL:
        print(COL[(a,b)])
    else:
        print(COL[(b,a)])

Measured memory_bytes: 47508
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
using namespace std;
int main()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    #endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    string s;
    cin>>s;
    ll sum=0;
    for(auto x:s)
    {
        sum+=(x-'0');
    }    
    if(sum%9==0) cout<<"Yes";
    else cout<<"No";
    return 0;
}

Measured memory_bytes: 3780
#include <stdio.h>
int main(void){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
    int n=0,count=0;
    for(n=a;n<=b;n++){
        if(c%n==0){
          count++;  
        }
    }
    printf("%d\n",count);
    return (0);
}



Measured memory_bytes: 2108
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

const int MOD = 1e9+7;

int main() {
  string S;
  cin >> S;
  vector<vector<int>> dp(S.size()+1, vector<int>(13));
  dp[0][0] = 1;
  rep(i, S.size()) {
    if(S[i] == '?') {
      rep(j, 10) {
        rep(k, 13) {
          int tmp = (k*10+j)%13;
          dp[i+1][tmp] += dp[i][k];
          dp[i+1][tmp] %= MOD;
        }
      }
    } else {
      rep(j, 13) {
        int tmp = (j*10+(S[i]-'0'))%13;
        dp[i+1][tmp] += dp[i][j];
        dp[i+1][tmp] %= MOD;
      }
    }
  }
  cout << dp[S.size()][5] << endl;
  return 0;
}

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

int main(){
  string a, b;
  cin >> a >> b;
  if(((a[0] =='H')+(b[0]=='H'))%2==0){
    cout << 'H' << endl;
  }else{
    cout << 'D' << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int N;
  cin >> N;
  int height[N];
  for(int i = 0;i<N;i++){
  	cin >> height[i];  }
  int max=0;
  int counter=0;
  for(int k=0;k<N;k++){
	if(max<=height[k]){
    	max = height[k];
 
      ++counter; 
    } 	
  }
  cout << counter <<endl;
  return 0;
}


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


int main() {
  int a1,a2,a3; cin >> a1 >> a2 >> a3;
  int ans = max({a1,a2,a3}) - min({a1,a2,a3});
  cout << ans << endl;

  return 0;

}

Measured memory_bytes: 256
function gets(str){
  this._s = str.split("\n");
  this._y = 0;
};
gets.prototype = {
  a: function(f){
    var s = this._s, y = this._y, r;
    if(typeof s[y] === "string")s[y] = s[y].split(" ").reverse();
    r = s[y].pop();
    if(!s[y].length)this._y++;
    return f?r:+r;
  },
  l: function(f){
    var s = this._s[this._y++].split(" ");
    return f?s:s.map(a=>+a);
  },
  m: function(n,f){
    var s = this._s, y = this._y, r = [], i = 0;
    if(f)for(;i < n; i++)r[i] = s[y+i].split(" ");
    else for(;i < n; i++)r[i] = s[y+i].split(" ").map(a=>+a);
    this._y += n;
    return r;
  },
};
var o=new gets(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var m = o.a();
  var X = o.a();
  var Y = o.a();
  var x = o.l();
  var y = o.l();
  x = Math.max(...x);
  y = Math.min(...y);
  if(y > Y)y = Y;
  return x < y  && X < y ? "No War":"War";
}

Measured memory_bytes: 21064
#include<bits/stdc++.h>
#define inf 1000000000000
#define int long long int
#define hell (int)(1e9+7)

using namespace std;

vector <int> a(200005),dp(200005),adj[200005];

void dfs(int s,int p,set <int> &v){
    bool flag=false;
    int y=-1;
    if(v.empty()||a[s]>*v.rbegin()){
        v.insert(a[s]);
        flag=true;
    }
    else{
        auto it=v.lower_bound(a[s]);
        y=*it;
        v.erase(it);
        v.insert(a[s]);
    }
    dp[s]=v.size();
    for(int x:adj[s]){
        if(x!=p)
            dfs(x,s,v);
    }
    v.erase(a[s]);
    if(!flag)
        v.insert(y);
}

void solve(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=1;i<n;i++){
        int u,v;
        cin>>u>>v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    set <int> v;
    dfs(1,-1,v);
    for(int i=1;i<=n;i++)
        cout<<dp[i]<<"\n";
}

signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t;
    //cin>>t;
    t=1;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 34492
import Control.Monad
import Data.List

solve = count . scanl' f 0
  where
    f n [a, b] = if a < n then n else b
    count = length . nub . tail

readN = map read . words <$> getLine

main = do
  [n, m] <- readN
  rs <- replicateM m readN
  print $! solve . sortOn last $ rs


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

int main() {
  int N,k,n=1;
  cin>>N>>k;
  for(int i=0;i<N;i++){
    if(2*n>n+k)n+=k;
    else n*=2;
  }
  cout<<n<<endl;
}

Measured memory_bytes: 3632
//This code was made by Chinese_zjc_.
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<map>
#include<queue>
#define int long long
#define INF 0x3fffffffffffffff
using namespace std;
int n,k,a[200002],b[200002];
signed main()
{
	std::ios::sync_with_stdio(false);
	cin>>n>>k;
	for(int i=1;i<=n;++i)
	{
		cin>>a[i];
	}
	for(int j=1;j<=k;++j)
	{
		for(int i=1;i<=n;++i)
		{
			++b[max(1ll,i-a[i])];
			--b[min(n+1,i+a[i]+1)];
		}
		for(int i=1;i<=n;++i)
		{
			a[i]=b[i]+a[i-1];
			b[i]=0;
		}
		bool flag=true;
		for(int i=1;i<=n;++i)
		{
			if(a[i]!=n)
			{
				flag=false;
				break;
			}
		}
		if(flag)
		{
			break;
		}
	}
	for(int i=1;i<=n;++i)
	{
		cout<<a[i]<<' ';
	}
	return 0;
}


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

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << endl;
    return 0; 
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define M 1000000007
#define sz(a) (ll)a.size()
#define pll pair<ll,ll>
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define sep(i,a,b) for(ll i=(ll)a;i>=(ll)b;i--)
#define mll map<ll,ll>
#define vl vector<ll>
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(a) a.begin(),a.end()
#define F first
#define S second
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin>>n;
    ll a=0,p;
    rep(i,0,n)
    {
    	cin>>p;
		a^=p;    
    }
    if(a==0)
    	cout<<"Yes\n";
    else
    	cout<<"No\n";
}


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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;
const ll MOD = 1e9 + 7;


int main() {
    int h, w; cin >> h >> w;
    int n; cin >> n;
    V<int> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];

    V<V<int> > ans(h);
    int x = 0, y = 0, ite = 0;
    bool r = true;
    for(int i = 0; i < h * w; i++){
        if(i != 0 && (x == w || x == 0)){
            y++;
            r = !r;
        }
        if(r){
            ans[y].push_back(ite + 1);
            a[ite]--;
            x++;
        }else{
            ans[y].push_back(ite + 1);
            a[ite]--;
            x--;
        }

        if(a[ite] == 0) ite++;
    }

    for(int i = 0; i < h; i++){
        if(i & 1) reverse(ALL(ans[i]));
        for(int j = 0; j < w; j++){
            if(j != w - 1) cout << ans[i][j] << " ";
            else cout << ans[i][j] << endl;
        }
    }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; }return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; }return 0; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

template<class V> class BIT {
    int n; vector<V> bit;
#define def 0
public:
    BIT() {}  // [L, R) 半開区間・0-indexed
    BIT(int _n) { init(_n); }
    void init(int _n) { n = 1; while (n < _n)n *= 2; bit.resize(n, def); }
    V operator[](int e) { V s = 0; e++; while (e) s += bit[e - 1], e -= e & -e; return s; }
    void add(int e, V v) { e++; while (e <= n) bit[e - 1] += v, e += e & -e; }
    int lower_bound(V val) {
        V tv = 0; int i, ent = 0; for (i = n - 1; i >= 0; i--)
            if (tv + bit[ent + (1 << i) - 1] <= val)tv += bit[ent + (1 << i) - 1], ent += (1 << i); return ent;
    }
    V sum(int L, int R) {
        assert(0 <= L); assert(R <= n); assert(L <= R);
        V res = 0; if (R) res += operator[](R - 1); if (L) res -= operator[](L - 1); return res;
    }
    V sum(int R) { return sum(0, R); }
    void clear() { bit.clear(); }
    int size() { return n; }
};

int main() {
    init();

    string s;
    int k;
    cin >> s >> k;
    int n = s.length();
    vector<priority_queue<int, VI, greater<int>>> alph(26);
    FOR(i, 0, n)alph[s[i] - 'a'].push(i);

    BIT<int> bit(n); 
    FOR(i, 0, n)bit.add(i, 1);

    string ans = "";
    FOR(i, 0, n)FOR(j, 0, 26)if (!alph[j].empty()) {
        int itr = alph[j].top();
        int cost = bit.sum(itr);
        if (cost <= k) {
            alph[j].pop();
            bit.add(itr, -1);
            ans += ('a' + j);
            k -= cost;
            break;
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 5436
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    int K = k*2;
    vector<P> X(n);
    string c;
    rep(i, n) {
        char cc;
        cin >> X[i] >> cc;
        c += cc;
    }
    vvi fieldb(K, vi(K)), fieldw(K, vi(K));
    rep(i, n) {
        X[i].first %= K;
        X[i].second %= K;
        fieldb[X[i].first][X[i].second] += (c[i] == 'B');
        fieldw[X[i].first][X[i].second] += (c[i] == 'W');
    }

    int ans = 0;
    vvi sumb(K+1, vi(K+1)), sumw(K+1, vi(K+1));
    rep(i, K) rep(j, K) {
        sumb[i+1][j+1] = sumb[i][j+1] + sumb[i+1][j] - sumb[i][j] + fieldb[i][j];
        sumw[i+1][j+1] = sumw[i][j+1] + sumw[i+1][j] - sumw[i][j] + fieldw[i][j];
    }
    rep(i, k) rep(j, k) {
        vi x(4), y(4);
        x[1] = i;
        y[1] = j;
        x[2] = i+k;
        y[2] = j+k;
        x[3] = y[3] = K;
        int now = 0;
        now += 2*sumb[i][j] + 2*sumb[x[2]][y[2]] - 2*sumb[i][y[2]] - 2*sumb[x[2]][j] + sumb[i][K] + sumb[K][j] + sumb[K][K] - sumb[x[2]][K] - sumb[K][y[2]];
        now -= 2*sumw[i][j] + 2*sumw[x[2]][y[2]] - 2*sumw[i][y[2]] - 2*sumw[x[2]][j] + sumw[i][K] + sumw[K][j] - sumw[x[2]][K] - sumw[K][y[2]];
        ans = max(ans, now);
        now = 0;
        now += 2*sumw[i][j] + 2*sumw[x[2]][y[2]] - 2*sumw[i][y[2]] - 2*sumw[x[2]][j] + sumw[i][K] + sumw[K][j] + sumw[K][K] - sumw[x[2]][K] - sumw[K][y[2]];
        now -= 2*sumb[i][j] + 2*sumb[x[2]][y[2]] - 2*sumb[i][y[2]] - 2*sumb[x[2]][j] + sumb[i][K] + sumb[K][j] - sumb[x[2]][K] - sumb[K][y[2]];
        ans = max(ans, now);
    }

    cout << ans << endl;
}

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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fill(a,v) memset(a,v,sizeof(a))
#define d1(a) cout << a << "\n"
#define d2(a,b) cout << a << " " << b << "\n"
#define d3(a,b,c) cout << a << " " << b << " " << c << "\n"
#define d4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << "\n"
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

int32_t main(){
	fast;
	int h,w;
	cin >> h >> w;
	int x = h*w;
	x = (x + 1)/2;
	
	if(h == 1 || w == 1)  x = 1;
	cout << x;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <deque>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const int MOD = 1000000007;
class UnionFind {
public:
	vector <ll> par;
	vector <ll> siz;
	UnionFind(ll sz_): par(sz_), siz(sz_, 1LL) {
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	void init(ll sz_) {
		par.resize(sz_);
		siz.assign(sz_, 1LL);
		for (ll i = 0; i < sz_; ++i) par[i] = i;
	}
	ll root(ll x) {
		while (par[x] != x) {
			x = par[x] = par[par[x]];
		}
		return x;
	}
	bool merge(ll x, ll y) {
		x = root(x);
		y = root(y);
		if (x == y) return false;
		if (siz[x] < siz[y]) swap(x, y);
		siz[x] += siz[y];
		par[y] = x;
		return true;
	}
	bool issame(ll x, ll y) {
		return root(x) == root(y);
	}
	ll size(ll x) {
		return siz[root(x)];
	}
};
int main(){
	ll n,m;
	cin >> n >> m;

	ll ans = -1;
	UnionFind uf(n);
	for(ll i = 0;i < m;i++){
		ll a,b;
		cin >> a >> b;
		a--,b--;
		uf.merge(a,b);
	}

	for(ll i = 0;i < n;i++){
		ans = max(ans,uf.size(i));
	}
	cout << ans << endl;
}


Measured memory_bytes: 6424
#include <iostream>
#include <cmath>
#include <vector>
#include <limits>
#include <algorithm>
#include <functional>
#include <cstdio>
#include <iomanip>
using namespace std;

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

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

	cout << a / b << " " << a % b << " " << fixed << setprecision(6) << static_cast<double>(a) / b << endl;
}


Measured memory_bytes: 3280
#include <iostream>

using namespace std;

int main()
{
    int n;
    int data[205];

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

    int ans = 0;
    while (1) {
        int i = 0;
        while ( data[i] % 2 == 0 && i < n) {
            data[i] /= 2;
            i++;
        }

        if ( i < n ) {
            break;
        }
        ans++;
    }

    printf("%d\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
#define MAXN 1000
int n,m;
LL ans;
LL a[MAXN+5][3];
LL sum[8][MAXN+5];
int main() {
	scanf("%d %d",&n,&m);
	for(int i=1;i<=n;i++)
		for(int j=0;j<3;j++)
			scanf("%lld",&a[i][j]);
	for(int i=1;i<=n;i++)
		for(int j=0;j<(1<<3);j++)
			for(int k=0;k<=2;k++)
				if((1<<k)&j)
					sum[j][i]+=a[i][k];
				else sum[j][i]-=a[i][k];
	for(int i=1;i<8;i++) {
		LL sum1=0,sum2=0;
		sort(sum[i]+1,sum[i]+n+1);
		for(int j=1;j<=m;j++)
			sum1+=sum[i][j],sum2+=sum[i][n-j+1];
		ans=max(ans,max(abs(sum1),abs(sum2)));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,n,m) for(int i=(n);i<(m);i++)
#define REP(i,n) FOR(i,0,n)
#define REPR(i,n) for(int i=(n);i>=0;i--)
#define all(vec) vec.begin(),vec.end()
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using P=pair<ll,ll>;
using PP=pair<ll,P>;
using vp=vector<P>;
using vpp=vector<PP>;
using vs=vector<string>;
#define fi first
#define se second
#define pb push_back
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
const ll MOD=1000000007LL;
const int INF=1<<30;
const ll LINF=1LL<<60;
int main(){
    string st;
    cin>>st;
    int t=0;
    REP(i,st.size()){
        if(st[i]=='+'){
            t++;
        }else{
            t--;
        }
    }
    cout<<t<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>

const int N = 1000000 + 10;

int n, g[N];
char s[N], t[N];

int main() {
  scanf("%d %s %s", &n, s + 1, t + 1);
  if (strcmp(s + 1, t + 1) == 0) return puts("0"), 0;
  for (int i = n, j = n; i > 0; --i) {
    j = std::min(j, i);
    while (j && s[j] != t[i]) --j;
    if (!j) return puts("-1"), 0;
    g[i] = j;
  }
  int ans = 1;
  static int q[N];
  int f = 0, r = 0;
  for (int i = n; i > 0; --i) {
    if (g[i] == g[i - 1]) continue;
    while (f < r && q[f] - (r - f) >= i) ++f;
    q[r++] = g[i];
    if (g[i] < i) ans = std::max(ans, r - f + 1);
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 9984
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vvin=vector<vector<int>>;
using vvll=vector<vector<long long>>;
using vstr=vector<string>;
using vvstr=vector<vector<string>>;
using vch=vector<char>;
using vvch=vector<vector<char>>;
using vbo=vector<bool>;
using vvbo=vector<vector<bool>>;
using vpii=vector<pair<int,int>>;
using pqsin=priority_queue<int,vector<int>,greater<int>>;
#define mp make_pair
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,s,n) for(int i=(s);i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define decp(n) cout<<fixed<<setprecision((int)n)
const ll inf=1e9+7;
const ll INF=1e18;
const ll mod=9982453;

ll modpow(ll a,ll n,ll m=inf){
    ll res=1;
    while(n){
        if(n&1)res=res*a%m;
        a=a*a%m;
        n>>=1;
    }
    return res;
}

int main(){
    ll n;cin>>n;
    ll tmp=modpow((ll)10,n)-(ll)2*modpow((ll)9,n)+modpow((ll)8,n);
    while(tmp<0)tmp+=inf;
    cout<<tmp<<endl;
}

Measured memory_bytes: 3672
#include <cstdio>
#include <string>

using namespace std;

#define COUNT 5

int main(void){
  int a,b,c,d,e;
  long long int n;
  long long int capa[COUNT];
  int i;
  scanf("%lld",&n);
  for(i=0; i<COUNT; i++){
    scanf("%lld", &capa[i]);
  }
  long long int minCapa = capa[0];
  for(i=1; i<COUNT; i++){
    if(capa[i]<minCapa){
      minCapa = capa[i];
    }
  }

  long long int durationAtMinCapa = (n+minCapa-1)/minCapa;
 
  printf("%lld\n",durationAtMinCapa+4);
  fflush(stdout);

  return 0;
}



Measured memory_bytes: 128
/* 実行時間1s制限の場合10^6 1,000,000 : 余裕をもって間に合う10^7
  10,000,000 : おそらく間に合う10^8 100,000,000 : 非常にシンプルな処理
  でないと厳しい
 */
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#include <bits/stdc++.h>
#define M_PI 3.14159265358979323846
using namespace std;

typedef long long ll; // long longはデータモデル(LLP64, LP64, ...)によらず64bit.
ll gcd(ll a, ll b) {return b ? gcd(b, a%b) : a;}  // Greatest Common Divisor ユークリッドの互除法（aが長辺）
vector<pair<ll,int>> factorize(ll n) {            // a,bの公約数 = GCD(a, b)の約数
    vector<pair<ll,int>> res;
    for (ll i = 2; i*i <= n; i++) { // √nまで探せばよい
        if (n%i) continue;
        res.emplace_back(i, 0);     // 割り切れたら
        while (n%i == 0) {
            n /= i;
            res.back().second++;
        }
    }
    if (n != 1) res.emplace_back(n, 1); // この時点で1でなかったら、残りは素数.
    return res;
}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}         // Least Commont Multiple オーバーフローしないように先に割る
ll ceil(ll a, ll b) {return (a+b-1)/b;}

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

int main(int argc, char* argv[])
{
#ifdef LOCAL
    // 以降 cin の入力元が 'xxx.txt' になる
    // std::ifstream in(argv[1]);
    //std::cin.rdbuf(in.rdbuf());
    //std::ifstream in(string(argv[0]) + ".txt");
    std::ifstream in("in.txt");
    std::cin.rdbuf(in.rdbuf());
#endif

    int a, b, c;
    cin >> a >> b >> c;

    if (a==b) cout << c;
    if (a==c) cout << b;
    if (b==c) cout << a;


    return 0;
}

/*
  - 1e9 : 10^9
  - container一般
    - 合計
      accumulate(a.begin(), a.end(), 0LL)  0LLはオーバーフロー用
  - vector
    vector<int> A(N, 0); // 0で初期化(省略可)
    vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));  // 2次元配列初期化
    - loop
      for  (int i = 0; i < A.size(); i++) {}
      for  (int elem : A) {}
    - sort
      std::sort(v.begin(), v.end());  // 昇順
      std::sort(v.begin(), v.end(), std::greater<int>()); //降順
      - vector<vector<int>> cnt(h, vector<int>(w))
    - sort(struct)
        struct st_t {
            string name;
            int p;
            bool operator<(const st_t& another) const {
                if (name == another.name)
                {
                    return p > another.p;
                }
                return name < another.name;
            }
        };
        vector<st_t> st(n);
        sort(st.begin(), st.end());
  - pair
    - pairのソートの定義 : firstが優先的に比較。同じだったらsecond。
    - pair<pair<string,int>,int> p[110];
      std::sort(p,p+a);
        こうすると、first.first -> first.second -> secondの順にソートされる
    - sort
      - sort(a.begin(), cb.end(), greater<pair<int, int>>());
  - map
    - for (auto x : map) {}  // x.first:key  x.second:value.
  - priority_queue<int> q;
    - q.top()に最大値が入っている
  - string
    - loop
      for (char& c : s) {}
 */



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <set>
#include <map>
#include <bitset>
#include <deque>
#include <numeric>
using namespace std;
using ll = long long;
using itn = int;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll dp[100010];

ll gcd(ll c, ll d) {
    if (d == 0)
        return c;

    return gcd(d, c % d);
}

ll lcm(ll c, ll d) {
    return c * d / gcd(c, d);
}

int main() {

    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll s;

    s = lcm(c, d);

    ll count1;
    ll count2;
    ll ans;

    count1 = b - (b / c + b / d - b / s);
    count2 = a-1 - ((a-1) / c + (a-1) / d - (a-1) / s);
    
    ans = count1 - count2;
    

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
#96d 高速化
N = int(input())     

#以下の条件を満たす, 長さ N の数列 a1,a2,...,aN を 1つ出力してください.
#1. ai (1≤i≤N)は 55 555以下の素数である.
#2. a1,a2,...,aN の値はすべて異なる.
#3. a1,a2,...,aN からどの異なる 5 個の整数を選んでも, この合計は合成数になる. 

#1、2は小さい方から素数を列挙すればOK
#3.は末尾が1になるもののみにすれば、末尾桁が5になるので合成数になる
#　…末尾が1なのが55555までに55個もあるか…ある。1408個あるらしい。
#  ∴末尾が1な素数をN個出せばOK

sieved_number_set = set() #素数でない数のset
ans = []

n = 55555

#素数を小さい方から列挙 
for i in range(2,n+1):
    if i not in sieved_number_set:
        
        exclude_list = [i*j for j in range(1,1+(n)//i)]
        sieved_number_set = sieved_number_set | set((exclude_list))
        
        #末尾が1な数なら数列に追加
        str_i = str(i)
        if str_i[-1]=="1":
            ans.append(i)
            if len(ans)==N:
                break

print(' '.join(map(str,ans)))

Measured memory_bytes: 11108
N,M = [int(x) for x in input().split()]
X = [int(x) for x in input().split()]
X.sort()
X_dis = []
for i in range(len(X)-1):
    X_dis.append(X[i+1]-X[i])
X_dis.sort(reverse=True)
print(sum(X_dis[N-1:]))
    


Measured memory_bytes: 13832
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
int n, d[100005][2];
int a[100005];
signed main(){
	cin >> n;
	for(int i = 1 ; i <= n ; i ++)
		cin >> a[i];
	d[1][0] = a[1];
	for(int i = 2 ; i <= n ; i ++){
		d[i][0] = d[i - 1][0] + a[i];
		d[i][1] = d[i - 1][0] - 2*a[i - 1] - a[i];
		if(i > 2){
			d[i][0] = max(d[i][0], d[i - 1][1] + a[i]);
			d[i][1] = max(d[i][1], d[i - 1][1] + 2*a[i - 1] - a[i]);
		}
	}
	cout << max(d[n][0], d[n][1]);
}

Measured memory_bytes: 2560
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <utility>

using namespace std;

int main()
{
    int n, k;
    cin>>n>>k;
    if (n%k==0) cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef map<ll, ll> mpii;
typedef unordered_map<ll, ll> umpii;

#define pb(v) push_back(v)
#define all(v) v.begin(), v.end()
#define upb(v, key) (upper_bound(all(v), key) - v.begin())
#define lob(v, key) (lower_bound(all(v), key) - v.begin())

ll inf = 1e9;
ll INF = inf * 1ll * inf;
ll mod = 1e9 + 7;
double eps = 1e-9;
const ld pi = ld(3.1415926535897932384626433832795);
ll dr[] = {-1, 0, 0, 1};
ll dc[] = {0, 1, -1, 0};

void mod_add(ll &a, ll b) {
  a += b;
  if(a > mod) a -= mod;
}
void mod_sub(ll &a, ll b) {
  a -= b;
  if(a < 0) a += mod;
}
void mod_mul(ll &a, ll b) {
  a = (a * b) % mod;
}
template<class TH> void _dbg(const char *sdbg, TH h){ cerr<<sdbg<<'='<<h<<endl; }
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')cerr<<*sdbg++;
  cerr<<'='<<h<<','; _dbg(sdbg+1, a...);
}
template<class T> ostream &operator<<(ostream& os, vector<T> V) {
  os << "["; for (auto vv : V) os << vv << ","; return os << "]";
}
template<class L, class R> ostream &operator<<(ostream &os, pair<L,R> P) {
  return os << "(" << P.st << "," << P.nd << ")";
}
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)

/*...................................................*/
vvi g, dp;
ll fn(ll u, ll p, ll c) {
  ll &res = dp[u][c];
  if(res != -1) 
  return res;
  res = 1;

  for(auto to: g[u]) 
  if(to != p) {
    if(!c) {
      mod_mul(res, fn(to, u, 1));
    }
    else {
      mod_mul(res, (fn(to, u, 0) + fn(to, u, 1)) % mod);
    }
  }     
  return res;
}

int main()
{
  ios_base::sync_with_stdio(false), cin.tie(NULL);
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  
  ll t, n, m, i, j, k, q, u, v;
  // cin >> t;
  // ll tc = t;
  t = 1;
  while (t--)
  {
    cin >> n;
    dp.assign(n, vi(2, -1));
    g.assign(n, vi());
    for(i = 0; i < n - 1; i++) {
      cin >> u >> v;
      u--, v--;
      g[u].push_back(v);
      g[v].push_back(u);
    }
    cout << (fn(0, 0, 0) + fn(0, 0, 1)) % mod << '\n';
    // debug(dp);
    // cout << "Case #" << tc - t << ": ";

    cout << '\n';
  }
  return 0;
}

Measured memory_bytes: 18176
import java.util.*;
import java.io.*;

public class Main {
    BufferedReader br;
    PrintWriter out;
    StringTokenizer stok;

    String nextToken() throws IOException {
        while (stok == null || !stok.hasMoreTokens()) {
            String s = br.readLine();
            if (s == null) {
                return null;
            }
            stok = new StringTokenizer(s);
        }
        return stok.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    char nextChar() throws IOException {
        return (char) (br.read());
    }

    String nextLine() throws IOException {
        return br.readLine();
    }

    void solve() throws IOException {
        int n = nextInt();
        int[] a = new int[n];
        int[] b = new int[n];
        int[] c = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = nextInt();
        }
        for (int i = 0; i < n; i++) {
           c[i] = nextInt();
        }
        Arrays.sort(a);
        Arrays.sort(b);
        Arrays.sort(c);
        int i = 0;
        int j = 0;
        int k = 0;
        long ans = 0;
        long[] kek = new long[n];
        while (j < n) {
            while (k < n && c[k] <= b[j]) {
                k++;
            }
            kek[j] = n - k;
            j++;
        }

        for (int l = n - 2; l >= 0 ; l--) {
            kek[l] += kek[l + 1];
        }

        j = 0;
        while (i < n) {
            while (j < n && b[j] <= a[i]) {
                j++;
            }
            if (j < n)
            ans += kek[j];
            i++;
        }
        out.println(ans);
    }

    void run() throws IOException {
        // br = new BufferedReader(new FileReader("dragons.in"));
        //out = new PrintWriter("dragons.out");
        // br = new BufferedReader(new FileReader("input.txt"));
        // out = new PrintWriter("output.txt");
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        br.close();
        out.close();
    }

    public static void main(String[] args) throws IOException {
        // Locale.setDefault(Locale.US);
        new Main().run();
    }
}

Measured memory_bytes: 55628
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define reps(i,n) for (int i=1;i<=(n);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rreps(i,n) for (int i=(n);i>0;i--)
#define all(v) (v).begin(),(v).end()
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>
template<class T> inline bool chmin(T &a, T b) {if (a>b) {a = b; return 1;} return 0;};
template<class T> inline bool chmax(T &a, T b) {if (a<b) {a = b; return 1;} return 0;};
typedef long long int ll;
const long long INF = 1LL << 60;


int main(){
  int N; cin >> N;
  vector<vector<string>> vec(11);
  vec[1].push_back("a");

  reps(i,N){
    for (auto s : vec[i-1]){
      int d = 0;
      rep(j,s.size()) chmax(d,s[j]-'a');
      for (int k=0;k<=d+1;k++){
        char ss = 'a'+k;
        vec[i].push_back(s+ss);
      }
    }
  }
  rep(i,vec[N].size()){
    cout << vec[N][i] << endl;
  }



  
  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 8224
S = input()

n = 'N' in S
s = 'S' in S
e = 'E' in S
w = 'W' in S

if (n and s) or (n==False and s==False):
    if (e and w) or (e==False and w==False):
        print('Yes')
    else:
        print('No')
else:
    print('No')

Measured memory_bytes: 3060