akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<climits>
#include<queue>
#include<stack>
	
int main(){
	long long k;
	int n=50;
	std::cin>>k;
	
	std::vector<long long> aList(n);
	for(int i=0; i<n; i++)
		aList[i]= n-i-1;

	long long quot= k/n;
	long long sur= k%n;

	for(int i=0; i<n; i++)
		aList[i]= aList[i]+ quot;

	if(sur!=0)
		aList[sur-1]= aList[0]+1;

	std::cout<<n<<std::endl;
	for(int i=0; i<n; i++)
		std::cout<<aList[i]<<" ";

	std::cout<<std::endl;
	return 0;
	
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Board vector<vector<int>>
using namespace std;
int d[5] = {0,-1,0,1,0};

int v[20][20];
int max_deep;
int w,h;

int dfs(int x, int y, int z){
	if(z > max_deep) return max_deep;
	int ret = max_deep;
	for(int i=0;i<4;i++){
		int ax = x;
		int ay = y;
		if(v[ax + d[i]][ay + d[i+1]] == 1) continue;
		while(ax >= 0 && ax < w && ay >= 0 && ay < h && v[ax][ay]%2 == 0){
			ax += d[i];
			ay += d[i+1];
		}
		if(ax < 0 || ax >= w || ay < 0 || ay >= h){
			continue;
		}
		if(v[ax][ay] == 3){
			return max_deep=z;
		}
		if(v[ax][ay] == 1){
			v[ax][ay] = 0;
			ret = min(ret,dfs(ax - d[i], ay - d[i+1], z+1));
			v[ax][ay] = 1;
		}
	}
	return ret;
}

int solve(){
	pair<int,int> start;
	max_deep = 11;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			cin >> v[j][i];
			if(v[j][i] == 2) start = make_pair(j,i);
		}
	}
	int ans = dfs(start.first,start.second,1);
	if(ans == 11) ans = -1;
	cout << ans << endl;
}

int main(){
	while(cin >> w >> h,w > 0 && h > 0){
		solve();
	}
}



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

int main() {
	int num;
	cin >> num;
	if (num % 10 == 3) {
		cout << "bon";
	}
	else if (num % 10 == 0 || num % 10 == 1 || num % 10 == 6 || num % 10 == 8) {
		cout << "pon";
	}
	else {
		cout << "hon";
	}
	return 0;
}

Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int l,r,d;
    cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r; i++) {
        if(i%d == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3596
//BISMILLAHIR RAHMANIR RAHEEM
                                      //ALLAH IS WATCHING ME
#include<bits/stdc++.h>
#define IOS   ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//Sequence Containers : vector,deque,list....
#define vc    vector<char>
#define vi    vector<long long>
#define vs    vector<string>
#define dqi   deque<int>
#define dqc   deque<char>
#define lii   list<int>
#define lic   list<char>
#define pb    push_back
#define pf    push_front
#define pff() pop_front()
#define pbb() pop_back()

//Container Adaptors : queue,priority_queue, stack....
#define sti   stack<int>
#define stc   stack<char>

//Associative Containers : map,set....
#define mpll  map<long long ,long long>
#define mps   map<string,int>
#define mpi   map<int,int>
#define si    set<int>
#define sc    set<char>
#define msi   multiset<long long>
#define ll     int_least64_t
#define ses   "\n"
#define X     first
#define Y     second
#define boro  1e18
#define POSITIVE(n) ((n) < 0 ? 0 - (n) : (n))
using namespace std;
// Find max/min element of map
bool compare(const pair<int, int>&a, const pair<int, int>&b)
{
   return a.second<b.second;
}
//Convert int to string
template <typename T>
string to_str(T str)
{
    stringstream stream;
    stream << str;
    return stream.str();
}

//main function is here
int main(){
ll n;
cin>>n;
cout<<pow(n,3);
}



//Alhamdulillah


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define Rep(i, N) for(int i = 0; i < N; i++)
#define Reps(i, x, N) for(int i = x; i < N; i++)

typedef pair<int, int> Pi;
#define fi first
#define se second

const int LLINF = 1LL << 60;

signed main()
{
  int N, Q;
  
  while(cin >> N >> Q, N || Q) {
    
    Pi cnt[105];
    Rep(i, 105) cnt[i] = Pi(0LL, -i);
    
    int M, A;
    Rep(i, N) {
      cin >> M;
      Rep(j, M) {
	cin >> A;
	cnt[A].fi++;
      }
    }
    
    sort(cnt + 1, cnt + 105, greater<Pi>());
    
    if(cnt[1].fi >= Q) cout << -cnt[1].se << endl;
    else cout << 0 << endl;
    
  }
  return 0;
}

Measured memory_bytes: 2984
#include <stdio.h>

int main(void){
	char c[102];
	int count = 0 , n , i , flag;
	while(scanf("%s" , &c[1])!=EOF){
		flag = 0;
		for(n=1;c[n+1]!='\0';n++);
		if(n==1) {
			count++;
			continue;
		}else if(n%2==0){
			for(i=1;i<=n/2;i++){
				if(c[i]!=c[n+1-i]){
					flag = 1;
					break;
				}
			}
			if(flag == 0) count++;
		}else{
			for(i=1;i<=(n-1)/2;i++){
				if(c[i]!=c[n+1-i]){
					flag = 1;
					break;
				}
			}
			if(flag == 0) count++;
		}
		
	}
	printf("%d\n" , count);
	return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    static final long MOD = 1_000_000_000 + 7;

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            solve(in);
        }
    }

    private static void solve(Scanner in) {
        int S = in.nextInt();
        int hh = S / 3600;
        int mm = (S % 3600) / 60;
        int ss = S % 60;
        System.out.println(hh + ":" + mm + ":" + ss);
    }
}

Measured memory_bytes: 26316
#include<bits/stdc++.h>
#define mo 998244353
using namespace std;
int n,m,i,j,k,x,y,book[20005],zhan[20005],flag,f[2005][2005];
int top,nex[20005],to[20005],fir[20005];
int lj(int u,int v){
	top++;
	nex[top]=fir[u];
	fir[u]=top;
	to[top]=v;
}
long long read(){
	long long xx=0,flagg=1;
	char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')
		ch=getchar();
	if(ch=='-'){
		flagg=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		xx=xx*10+ch-'0';
		ch=getchar();
	}
	return xx*flagg;
}
void pus(long long xx,int flagg){
	if(xx>=10)
		pus(xx/10,0);
	putchar(xx%10+'0');
	if(flagg==1)
		putchar(' ');
	if(flagg==2)
		putchar('\n');
	return;
}
void ss(int v){
	if(flag!=0)
		return;
	if(book[v]!=0){
		flag=book[v];
		return;
	}
	top++;
	book[v]=top;
	zhan[top]=v;
	for(int top1=fir[v];top1;top1=nex[top1])
		ss(to[top1]);
	if(flag!=0)
		return;
	book[v]=0;
	zhan[top]=0;
	top--;
}
int main(){
	n=read();m=read();
	for(i=1;i<=m;i++){
		x=read();y=read();
		f[x][y]=1;
		lj(x,y);
	}
	for(i=1;i<=n;i++)
		if(flag==0)
			ss(i);
	if(flag==0){
		printf("-1\n");
		return 0;
	}
	for(i=1;i<=top-flag+1;i++)
		zhan[i]=zhan[i+flag-1];
	top=top-flag+1;
	for(i=1;i<=n;i++)
		book[i]=0;
	for(i=1;i<=top;i++)
		book[zhan[i]]=i;
	while(1){
		flag=0;
		for(i=1;i<=top;i++){
			for(j=1;j<=top;j++)
				if(i+1!=j&&(i!=top||j!=1)){
					if(f[zhan[i]][zhan[j]]==1){
						flag=1;
						if(j<i){
							for(k=1;k<=i-j+1;k++)
								zhan[k]=zhan[j+k-1];
							top=i-j+1;
						}
						else{
							for(k=1;;k++){
								zhan[i+k]=zhan[j+k-1];
								if(j+k-1==top){
									top=i+k;
									break;
								}
							}
						}
					}
					if(flag==1)
						break;
				}
			if(flag==1)
				break;
		}
		if(flag==0)
			break;
	}
	pus(top,2);
	for(i=1;i<=top;i++)
		pus(zhan[i],2);
	return 0;
}

Measured memory_bytes: 7552
n = int(input())
F = []
# for _ in range(n):
#     f = list(map(int, input().split()))
#     # print(f)
#     F.append([\
#         [f[0],f[1]],\
#         [f[2],f[3]],\
#         [f[4],f[5]],\
#         [f[6],f[7]],\
#         [f[8],f[9]]\
#     ])

for _ in range(n):
    f = list(map(int, input().split()))
    F.append(f)

# print(*F,sep='\n')

P = []
for _ in range(n):
    p = list(map(int, input().split()))
    P.append(p)

# print(*P,sep='\n')

def c(i, open_my_shop):
    ret = 0
    for j in range(10):
        if open_my_shop>>j & 1: #open my shop
            if F[i][j]: # open your shop
                ret += 1
    return ret

ans = -10*10000000*10
# for i in range(1, 1<<10): # [0~1,1~1] 10bit
#     s = 0
#     for j in range(10): # open time zone
#         if i>>j & 1: # my shop (j+1) open
#             for k in range(n): # your shop
#                 ck = c(k, i)
#                 s += P[k][ck]
#     ans = max(ans ,s)

for i in range(1, 1<<10): # [0~1,1~1] 10bit
    s = 0
    for j in range(n): # your shop
        cj = c(j, i)
        s += P[j][cj]
    ans = max(ans ,s)

print(ans)


Measured memory_bytes: 3188
{-# LANGUAGE ScopedTypeVariables, FlexibleContexts #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Maybe
import Data.Ord
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  n :: Z <- getInt
  as :: [Z] <- getInts
  let
    bs = sort $ zip as [1..]
    go (a,i) = do
      l <- gets (maybe 0 id . S.lookupLT i)
      r <- gets (maybe (n+1) id . S.lookupGT i)
      modify (S.insert i)
      return $ a * (i-l) * (r-i)
    ans = sum $ evalState (mapM go bs) S.empty
  print $ ans



 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "Yes"
yesNo False = "No"

printList :: (Show a) => [a] -> IO ()
printList = putStrLn . unwords . map show

readLnList :: (Read a) => IO [a]
readLnList = map read . words <$> getLine


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 55676
#include <iostream>
using namespace std;
int main(){
	int x,a,b;
	cin >> x >> a >> b;
	int y=x+a;
	if(b<=a)
		cout <<"delicious"<<endl;
	else if(y>=b)
		cout <<"safe"<<endl;
	else 
		cout<<"dangerous"<<endl;
	return 0;
}

Measured memory_bytes: 256
import numpy as np
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
A, B, H, M = map(int, input().split())
if H > 12:
    H -= 12
p = np.pi
min_ang = 2 * p * (M / 60)
hour_ang = 2 * p * (H / 12)
hour_ang += (1 / 6) * p * (M / 60)

mid = abs(hour_ang - min_ang)
mid = min(mid, 2 * p - mid)

ans = A ** 2 - 2 * A * B * np.cos(mid) + B ** 2
print(ans ** .5)

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

vector<vector<int>> G(101);
int d[101] = {}, f[101] = {};

void dfs(int from, int& time) {
    if (d[from] == -1) {
        time++;
        d[from] = time;

        for (auto v: G[from]) dfs(v, time);

        time++;
        f[from] = time;
    }
}

int main() {
    int N;
    cin >> N;
    
    rep(i, N) {
        int u, k, vj;
        cin >> u >> k;
        rep(j, k) {
            cin >> vj;
            G[u].push_back(vj);
        }
    }

    int time=0;
    rep(i, N+1) d[i] = -1;
    for (int i=1; i<=N; i++) {
        if (d[i] == -1) dfs(i, time);
    }
    
    for (int i=1; i<=N; i++) {
        cout << i << " " << d[i] << " " << f[i] << endl;
    }

    return 0;
}




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

int main()
{
	int ko = 0;
	int gr = 0;
	int sum = 0;
	int minm = 1000;

	int koh = 0;
	//vector<int> koh;
	cin >> ko >> gr;
	//koh.resize(ko);

	if (ko < 2 || ko>100)ko=100;
	//if (gr < 1 || gr>1000)gr=1000;

	for (int i = 0; i < ko; ++i) {
		cin >> koh;
		sum += koh;
		if (minm > koh) {
			minm = koh;
		}
	}

	if (sum > 100000)sum= 100000;

	cout << ko+(gr-sum)/minm;


	return 0;
}

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

int main() {
  int I, K, R;
  cin >> K >> R;
  
    if (K>=10) {
      I=R;
      cout << I << endl;
    }
    else {  
      I=R+100*(10-K);
 
    cout << I << endl;
    }
}


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

xy = [input() for _ in range(N)]

cnt = 0

result = 'No'

for D in xy:
  list = D.split()
  if list[0] == list[1]:
    cnt = cnt + 1
    if cnt == 3:
      result = 'Yes'
      break
  else:
    cnt = 0
print(result)

Measured memory_bytes: 9180
//
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)

int main(){
	int N; cin>>N;
	int maxN = 0;
	rp(i,1,N+1){
		int j = i;
		int num = 1;
		// printf("j %d\n",j);//
		while(j%2==0){
			num <<= 1;
			j /= 2;
			// printf("j %d\n",j);//
			// if(num>100) break;//
		}
		maxN = max(maxN, num);
		// puts("--");//
	}
	ote(maxN);
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;
int main()
{
  int N, A, B;
  cin >> N >> A >> B;

  int sum = 0;
  int sumsum = 0;

  for (int i = 1; i <= N; i++) {
    sum = 0;
    int n = i;
    while(true){
      if(n/10 == 0){
        sum+=n%10;
        break;
      }else{
        sum+=n%10;
        n/=10;
      }
    }
    if(sum >= A && sum <= B)
      sumsum+=i;
  }
  cout << sumsum << endl;
  return 0;
}


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

int main(){
  int k;
  cin >> k;
  int a[1000001];
  a[1] = 7 % k;
  for(int i=2; i<=k; i++) a[i] = (a[i-1] * 10 + 7) % k;
  for(int i=1; i<=k; i++){
    if(a[i] == 0){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 7440
import java.util.*;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        long a[] = new long[n];
        HashMap<Long, Integer> map = new HashMap<>();
        for(int i = 0; i < n; i++){
            a[i] = scanner.nextInt();
        }
        long ans = 0;
        for(int i = 0; i < n; i++){
            long req = i-a[i];
            ans += map.getOrDefault(req,0);
            map.put(i+a[i], map.getOrDefault(i+a[i],0)+1);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 66080
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <map>
#include <set>

#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)

typedef long long int64;

using namespace std;

int main() {
	ios_base::sync_with_stdio(0);
	int n;
	cin >> n;
	for (int a = 1; a <= 9; ++a) {
	    if (n % a != 0) {
		    continue;
		}
		int b = n / a;
		if (b > 9) continue;
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char s[5];
	scanf("%s",s);
	if(s[0]=='M')printf("6\n");
	if(s[0]=='S'){
		if(s[1]=='A')printf("1\n");
		else printf("7\n");
	}
	if(s[0]=='T'){
		if(s[1]=='U')printf("5\n");
		else printf("3\n");
	}
	if(s[0]=='F')printf("2\n");
	if(s[0]=='W')printf("4\n");
}

Measured memory_bytes: 128
#include<cstdio>
#include<algorithm>
#include<queue>

const int MAX_V=100000;
const int INF=1000000000;

using namespace std;
typedef pair<int,int> P;
struct edge{int to; int cost;};
vector<edge> G[MAX_V];
priority_queue<P,vector<P>,greater<P> > q;
int d[MAX_V];

void init(int v,int e,int r){
    for(int i=0;i<e;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        edge ed;
        ed.cost=c;
        ed.to=b;
        G[a].push_back(ed);
    }
    fill(d,d+v,INF);
    d[r]=0;
}

void dijkstra(int r){
    q.push(P(0,r));
    while(!q.empty()){
        P p=q.top();
        q.pop();
        int v=p.second;
        if(d[v]<p.first) continue;
        for(int i=0;i<G[v].size();i++){
            edge e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                q.push(P(d[e.to],e.to));
            }
        }
    }
}

int main(){
    int v,e,r;
    scanf("%d %d %d",&v,&e,&r);
    init(v,e,r);
    dijkstra(r);
    for(int i=0;i<v;i++){
        if(d[i]==INF) printf("INF\n");
        else printf("%d\n",d[i]);
    }
}

Measured memory_bytes: 11184
#include<bits/stdc++.h>
using namespace std;
double dp[3005][3005] = {0};
double P[3005];

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

    dp[0][0] = 1;

    for (int i=1; i<=n; i++)
    {
        for (int j=0; j<=n; j++)
        {
            if (j==0) dp[i][j] = dp[i-1][0]*(1-P[i-1]);
            else dp[i][j] = dp[i-1][j-1]*P[i-1] + dp[i-1][j]*(1-P[i-1]);
        }
    }

    double ans = 0;
    for (int j=n/2+1; j<=n; j++) ans += dp[n][j];
    printf("%.10f\n", ans);

    return 0;
}


Measured memory_bytes: 70656
'use strict';
(function(input){
  input=input.trim().split(/\n/).map(str=>str.split(/\s+/).map(x=>x-0));
  const N=input[0][0];
  const M=input[0][1];
  input.shift();
  
  const Node=function(idx){
    var t=this;
    t.index=idx;
    t.children=[];
    t.scanned=false;
    t.height=0;
  }
    
  const nodes=new Array(N+1).fill(0).map((x,i)=>new Node(i));
  //console.log(nodes);
  input.forEach(function(xy){
    var p=xy[0],c=xy[1];
    nodes[p].children.push(nodes[c]);
  });
  //console.log(nodes);
  var ans=0;
  var stack=[];
  var i=1;
  while(i<=N){
    //console.log('大');
    if(nodes[i].scanned){
      ans=Math.max(ans,nodes[i].height);
      i++;
      continue;
    }
    stack.push(i);
    while(stack.length>0){
      //console.log('中');
      let t=nodes[stack[stack.length-1]];
      //console.log(stack);
      if(t.children.length===0){
        t.scanned=true;
        stack.pop();
        continue;
      }
      let lastChild=t.children[t.children.length-1];
      if(lastChild.scanned){
        t.height=Math.max(t.height,lastChild.height+1);
        t.children.pop();
      }else{
        stack.push(lastChild.index);
      }
    }
    nodes[i].scanned=true;
  }
  //console.log(nodes);
  console.log(ans);
})(require('fs').readFileSync('/dev/stdin','utf8'));


Measured memory_bytes: 70208
//---------------------------------------------------------------
#include <bits/stdc++.h>
using namespace std;
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cassert>
//---------------------------------------------------------------
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define SIZE 100005
#define INF 1e18
#define all(x) x.begin(),x.end()
#define fi first
#define se second
#define vec vector
using pint = pair<int,int>;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
//---------------------------------------------------------------
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double pi = acos(-1);
//---------------------------------------------------------------
const int mod = 1e9+7;
struct mint {
int64_t x;
mint(int64_t x=0):x((x%mod+mod)%mod){}
mint operator-() const { return mint(-x);}
mint& operator+=(const mint a) {if ((x += a.x) >= mod) x -= mod;return *this;}
mint& operator-=(const mint a) {if ((x += mod-a.x) >= mod) x -= mod;return *this;}
mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
mint operator+(const mint a) const { return mint(*this) += a;}
mint operator-(const mint a) const { return mint(*this) -= a;}
mint operator*(const mint a) const { return mint(*this) *= a;}
mint pow(int64_t t) const {if (!t) return 1;mint a = pow(t>>1);a *= a;if (t&1) a *= *this;return a;}
mint inv() const { return pow(mod-2);}
mint& operator/=(const mint a) { return *this *= a.inv();}
mint operator/(const mint a) {return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
//↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓

map<ll,ll> mp;

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

    int n;
    cin>>n;

    for(int i=2;i<=n;i++){
        int k=i;
        for (int j=2;j*j<=k;j++){
            int ex=0;
            while (k%j==0) {
                k/=j;
                ex++; 
            }
            mp[j]+=ex;
        }
        if(k!=1){mp[k]++;}
    }

    ll ans=1;
    for(auto x:mp){
        auto key=x.second;
        ans*=(key+1);
        ans%=mod;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3660
#include<iostream>
using namespace std;
static const int N = 100;
int main(){
  int M[N][N];
  int n,u,k,v;
  cin >> n;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) M[i][j]=0;
  }
  for(int i=0;i<n;i++){
    cin >> u >> k;
    u--;
    for(int j=0;j<k;j++){
      cin >> v;
      v--;
      M[u][v]=1;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(j) cout<<" ";
      cout << M[i][j];
    }
    cout << endl;
  }
  return 0;
}



Measured memory_bytes: 3120
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func gcd(x, y int) int {
	tmp := x % y
	if tmp > 0 {
		return gcd(y, tmp)
	} else {
		return y
	}
}

func lcm(x, y int) int {
	return x * y / gcd(x, y)
}

func main() {
	abcd := strings.Fields(nextLine())
	a, _ := strconv.Atoi(abcd[0])
	b, _ := strconv.Atoi(abcd[1])
	c, _ := strconv.Atoi(abcd[2])
	d, _ := strconv.Atoi(abcd[3])

	cDiv := b/c - (a-1)/c

	dDiv := b/d - (a-1)/d

	saishou := lcm(c, d)
	lcmDiv := (b / saishou) - ((a - 1) / saishou)

	fmt.Println(b - a + 1 - (cDiv + dDiv - lcmDiv))

}


Measured memory_bytes: 640
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define M 1046527

char H[M][14];

int h1(int key){
    return key%M;
}

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

int h(int key ,int i){
    return (h1(key)+i*h2(key))%M;
}

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

long long getkey(char str[]){
    long long sum=0,p=1;
    
    for(int i=0;i<strlen(str);i++){
        sum+=p*(getchar(str[i]));
        p*=5;
    }
    return sum;
}

int insert(char str[]){
    int i;
    long long j,key=getkey(str);
    for(i=0;;i++){
        j=h(key,i);
        if(strcmp(H[j],str)==0)return 1;
        else if(strlen(H[j])==0){
            strcpy(H[j],str);
            return 0;
        }
        
    }
    return 0;
}

int find(char str[]){
    long long key,j;
    key=getkey(str);
    for(int i=0;;i++){
        j=h(key,i);
        if(strcmp(H[j],str)==0)return 1;
        else if(strlen(H[j])==0)return 0;
        
    }
    return 0;
}

int main(){
    int n;
    cin>>n;
    char com[6],str[14];
    for(int I=0;I<n;I++){
        scanf("%s%s",com,str);
        if(com[0]=='i'){
            insert(str);
        }
        else if(com[0]=='f'){
            if(find(str))cout<<"yes"<<endl;
            else cout<<"no"<<endl;
        }
    }
}






Measured memory_bytes: 17452
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t;
    cin>>a>>b;
    if(a>=13) cout<<b;
    else if(a>=6 && a<=12) cout<<b/2;
    else cout<<"0";
}

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

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

void move(int& x, int& y, int d, int k)
{
	x+=dx[d]*k;
	y+=dy[d]*k;
	
	if(x<=0) x=1;
	if(y<=0) y=1;
	if(x>C) x=C;
	if(y>R) y=R;
}

int main()
{
	while(cin >> C >> R, (C||R))
	{
		int x=1,y=1,d=1,k;
		string c;
		while(1)
		{
			cin >> c;
			if(c=="FORWARD")
			{
				cin >> k;
				move(x,y,d,k);
			}
			if(c=="BACKWARD")
			{
				cin >> k;
				move(x,y,(d+2)%4, k);
			}
			if(c=="LEFT")
			{
				d=(d+3)%4;
			}
			if(c=="RIGHT")
			{
				d=(d+1)%4;
			}
			if(c=="STOP") break;
		}
		
		cout << x << " " << y << endl;
	}
}

Measured memory_bytes: 0
import sys
input = sys.stdin.readline

def readlines(n):
    for _ in range(n):
        x, y, h = map(int, input().split())
        yield x, y, h

def h_check(lines, cx, cy):
    for x, y, h in lines:
        if h > 0:
            yield h + abs(x - cx) + abs(y - cy)

def match(cx, cy, H, lines):
    for x, y, h in lines:
        yield max(H - abs(x - cx) - abs(y - cy), 0) == h

def main():
    n = int(input())
    lines = list(readlines(n))
    for cx in range(101):
        for cy in range(101):
            res = set(h_check(lines, cx, cy))
            if len(res) == 1:
                H = res.pop()
                if all(match(cx, cy, H, lines)):
                    print(cx, cy, H)
                    return

main()



Measured memory_bytes: 3064
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>




int main(int argc, const char * argv[]){
    
    //Input
    int i, j , n ,q;
    
    int dp[40001];
    
    memset(dp, 0x00, sizeof(dp));
    dp[0] = 1;
    
    scanf("%d", &n);
    int A[n];
    for(i=0; i< n;i++){
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    int M[q];
    for(i=0; i< q;i++){
        scanf("%d", &M[i]);
    }
    
    //??°???????????§??????
    for (i = 0; i < n; i++) {
        for (j = 40000; j >= 0; j--) {
            if (dp[j] == 1 && j + A[i] <= 40000) {
                dp[j + A[i]] = 1;
            }
        }
    }
    
    for (i=0; i<q; i++) {
        if (dp[M[i]] == 1) {
            printf("yes\n");
        }
        else{
            printf("no\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 1172
#include <iostream>
using namespace std;
int from1[200005];
int toN[200005];
int main( void )
{
  ios::sync_with_stdio(false);
  int N, M, a, b;
  cin >> N >> M;
  for( int i=0; i<M; i++ ){
    cin >> a >> b;
    if( a == 1 ) from1[b] = 1;
    if( b == 1 ) from1[a] = 1;
    if( a == N ) toN[b] = 1;
    if( b == N ) toN[a] = 1;
  }

  for( int i=1; i<=N; i++ ){
    if( from1[i] && toN[i] ){
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP2(i, x, n) for (int i = x; i < (n); i++)
#define ALL(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
int main()
{
    vector<vector<int>> A(3, vector<int>(3, 1));
    int N;
    vector<int> b;
    REP(i, 3)
    {
        REP(j, 3)
        {
            cin >> A[i][j];
        }
    }
    cin >> N;
    REP(i, N) {
        int bb;
        cin >> bb;
        REP(i, 3) {
            REP(j, 3) {
                if (bb == A[i][j]) {
                    A[i][j] = 0;
                }
            }
        }
    }
    int a1 = A[0][0] + A[0][1] + A[0][2];
    int a2 = A[1][0] + A[1][1] + A[1][2];
    int a3 = A[2][0] + A[2][1] + A[2][2];
    int a4 = A[0][0] + A[1][0] + A[2][0];
    int a5 = A[0][1] + A[1][1] + A[2][1];
    int a6 = A[0][2] + A[1][2] + A[2][2];
    int a7 = A[0][0] + A[1][1] + A[2][2];
    int a8 = A[0][2] + A[1][1] + A[2][0];

    if (a1 * a2 * a3 * a4 * a5 * a6 * a7 * a8 == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n, q;
    cin >> n >> q;
    priority_queue<pair<int, pii>> pq;
    vector<pair<int, pii>> stx;
    for (int i = 0; i < n; ++i) {
        int s, t, x;
        cin >> s >> t >> x;
        s -= x;
        t -= x;
        stx.push_back({s, {t, x}});
    }
    vl d(q);
    for (int i = 0; i < q; ++i) {
        cin >> d[i];
    }
    sort(stx.begin(), stx.end());
    int idx = 0;
    for (int i = 0; i < q; ++i) {
        while (idx != n && stx[idx].first <= d[i]) {
            auto t = stx[idx];
            pq.push({-t.second.second, {t.first, t.second.first}});
            idx++;
        }
        while (pq.size() != 0 && pq.top().second.second <= d[i]) {
            pq.pop();
        }
        if (pq.size() == 0)
            cout << -1 << "\n";
        else
            cout << -pq.top().first << "\n";
    }
    return 0;
}

Measured memory_bytes: 9584
use std::error::Error;
use std::io;

pub fn main() {
    if let Err(_e) = run() {
        panic!("failed.");
    }
}

fn run() -> Result<(), Box<dyn Error>> {
    let mut input = String::new();
    io::stdin().read_line(&mut input)?;
    let n = input.trim().parse::<i32>()?;
    input.clear();
    io::stdin().read_line(&mut input)?;
    let s = input.clone();
    input.clear();
    if s.trim().len() > n as usize {
        let cs: Vec<char> = s.chars().collect();
        let result: String = cs.clone().as_slice()[0..n as usize].into_iter().collect();
        println!("{}...", result);
    } else {
        println!("{}", s);
    }
    Ok(())
}


Measured memory_bytes: 2124
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <deque>
#include <queue>
#include <stack>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <iomanip>
#define ull unsigned long long
#define ll long long
#define pb push_back
#define tle ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int mod = 998244353;
const int mxn = 2e5 +7;
int _,n,m,t,k,u,v,ans,cnt,ok,lim;
ll w[mxn] , cost[mxn] ,  far[mxn] , siz[mxn];
char ch;
#define lc now<<1
#define rc now<<1|1
string str ;
struct node {ll l,r,val,lazy,mx,mn;}p[mxn<<4];
int a[mxn];
int calc()
{

}
int main()
{tle;
    int Case = 1 ;
    int a,b,c;
    cin>>a>>b>>c;
    ans = 0 ;
    for(int i=max(a,b);i>=1;i--)
    {
        if(a%i==0 && b%i==0)
        {
            c--;
            if(c==0)
            {
                cout<<i<<endl;
                return 0 ;
            }

        }
    }
}

Measured memory_bytes: 2304
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;

public class Main {

  static int n;
  static long ans;
  static List<Integer> a;

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

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    PrintWriter out = new PrintWriter(System.out);

    String[] in = br.readLine().split(" ");
    n = Integer.parseInt(in[0]);

    br.close();

    //n = 10000;
    int rtn = 100;

    a = new ArrayList<>();

    for (int i = 1; i <= n; i++) {
      int tmp = 0;
      for (int x = 1; x <= rtn; x++) {
        if(x * x > i) break;
        for (int y = x; y <= rtn; y++) {
          if(x * x + y * y > i) break;
          for (int z = y; z <= rtn; z++) {
            if(x * x + y * y + z * z > i) break;
            int result = x * x + y * y + z * z + x * y + y * z + z * x;
            if(result == i) {
              if(x == y && y == z){
                tmp++;
              }else if(x == y || y == z || z == x){
                tmp += 3;
              }else{
                tmp += 6;
              }
            }
          }
        }
      }
      a.add(tmp);
    }

    a.stream().forEach(out::println);

    out.flush();
  }
}

Measured memory_bytes: 35460
import math

def f():
    for x, y, r in W:
        A = (tx-x)**2 + (ty-y)**2 - r**2
        B = (sx-x)**2 + (sy-y)**2 - r**2
        if A * B < 0:
            print 'Safe'
            break
        elif 0 < A and 0 < B:
            if tx == sx:
                d = abs(x-tx)
            else:
                P = abs((sy-ty)*x - (sx-tx)*y - (sy-ty)*tx + (sx-tx)*ty)
                Q = math.sqrt((sy-ty)**2 + (sx-tx)**2)
                d = P / Q
            if d <= r:
                if (tx-sx)*(x-sx) + (ty-sy)*(y-sy) > 0:
                    if (sx-tx)*(x-tx) + (sy-ty)*(y-ty) > 0:
                        print 'Safe'
                        break
    else:
        print 'Danger'
   
while True:
    N = input()
    if N == 0: break
    W = [map(int, raw_input().split()) for i in range(N)]
    for i in range(input()):
        tx, ty, sx, sy = map(int, raw_input().split())
        f()

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

int main() {
  int N, L;
  cin >> N >> L;//食べたリンゴはL+i-1が最も0と近いような番号i
  int sum = 0;
  int mini = 10000;
  int x;
  rep (i, N){
    mini = min(mini, abs(L+i));//miniは食べたリンゴの味（完璧なアップルパイからこれを引けばよい）
    if (mini == abs(L+i)) x = i;// miniは絶対値になってしまっているので、iの情報を取り出す
  }
  rep(i, N) sum += L+i;
  sum -= L+x;
  cout << sum << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())

a = n%10

if a == 2 or a == 4 or a == 5 or a == 7 or a == 9:
    print("hon")
elif a  == 0 or a == 1 or a == 6 or a == 8:
    print("pon")
else:
    print("bon")

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

using namespace std;

typedef long long ll;
typedef pair<ll,ll> pii;

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int N = (int)1e5 + 9;
vector<pii> L[N];

int main(){
  fastIO;
  int n, m;
  cin >> n >> m;
  int l, r, c;
  for(int i = 1; i <= m; i ++ ){
    cin >> l >> r >> c;
    L[l].push_back(mp(r, c));
  }
  priority_queue<pii, vector<pii>, greater<pii>> ff;
  ff.push(mp(0ll, 1));
  ll mx;
  for(int i = 1; i <= n; i ++ ){
    while(!ff.empty() && i > ff.top().se){
      ff.pop();
    }
    if(ff.empty()){
      cout << "-1\n";
      return 0;
    }
    mx = ff.top().fi;
    if(i == n){
      cout << mx << "\n";
      return 0;
    }
    for(auto x : L[i]){
      ff.push(mp(mx + x.se, x.fi));
    }
  }
  return 0;
}

Measured memory_bytes: 7288
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>

#define pb push_back
#define mp make_pair

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef unsigned long long ull;
typedef long long ll;

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

  ull sum = 0;
  vi c;
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    c.pb(k);

    sum += k;
  }

  sort(c.begin(), c.end());

  if (sum == x) {
    cout << n << endl;
  } else if (sum < x) {
    cout << n-1 << endl;
  } else {
    int count = 0;

    for (int i = 0; i < n && x >= c.at(i); ++i) {
      x -= c.at(i);
      count++;
    }

    cout << count << endl;
  }

  return 0;
}


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

using namespace std;

bool bigger(const string &s1, const string &s2)
{
	if (s1.size() != s2.size()) return s1.size() > s2.size();
    for (int i = 0; i < (int) s1.size(); ++i) if (s1[i] != s2[i]) {
        return s1[i] > s2[i];
    }
    return false;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    set<int> a;
    for (int i = 0; i < m; ++i) {
        int x;
        cin >> x;
        a.insert(x);
    }
    vector<int> match = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
    map<int, char> t;
    for (auto x: a) {
        t[match[x]] = x + '0';
    }
	string dp[n+100];
	for (int i = 0; i < n; ++i) if (i == 0 || dp[i] != "") {
		for (auto &kv: t) {
			string s = dp[i] + kv.second;
			if (bigger(s, dp[i+kv.first])) {
				dp[i+kv.first] = s;
			}
		}
	}
	cout << dp[n] << endl;
    return 0;
}


Measured memory_bytes: 44928
main(){
  unsigned int i,j,a,b,c;
  while(scanf("%d %d",&a,&b)!=-1){
    if(a<b){
      c=a;
      a=b;
      b=c;
    }
    for(i=1;a%(b/i);)
      for(i++;b%i;i++);
    for(j=1;b/i*j%a||b/i*j%b;j++);
    printf("%d %d\n",b/i,b/i*j);
  }
  return 0;
}

Measured memory_bytes: 408
#include <bits/stdc++.h>
// iostream is too mainstream
#include <cstdio>
// bitch please
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <cmath>
#include <iomanip>
#include <time.h>
#define dibs reserve
#define OVER9000 1234567890
#define ALL_THE(CAKE,LIE) for(auto LIE =CAKE.begin(); LIE != CAKE.end(); LIE++)
#define tisic 47
#define soclose 1e-8
#define chocolate win
// so much chocolate
#define patkan 9
#define ff first
#define ss second
#define abs(x) ((x < 0)?-(x):x)
#define uint unsigned int
#define dbl long double
#define pi 3.14159265358979323846
using namespace std;
// mylittledoge

#ifdef DONLINE_JUDGE
	// palindromic tree is better than splay tree!
	#define lld I64d
#endif

int main() {
	cin.sync_with_stdio(0);
	cin.tie(0);
	cout << fixed << setprecision(10);
	int N;
	cin >> N;
	vector< pair<int,int> > As(N);
	vector<int> A(N);
	for(int i =0; i < N; i++) {
		cin >> As[i].ff;
		A[i] =As[i].ff;
		As[i].ss =i;}
	vector< vector<int> > G(N);
	for(int i =0; i < N-1; i++) {
		int a,b;
		cin >> a >> b;
		G[--a].push_back(--b);
		G[b].push_back(a);}
	sort(begin(As),end(As));
	vector<int> win(N,-1);
	for(int i =0; i < N; i++) {
		ALL_THE(G[As[i].ss],it) if(win[*it] == 0 && A[*it] != As[i].ff) win[As[i].ss] =1;
		if(win[As[i].ss] == -1) win[As[i].ss] =0;}
	bool st =false;
	for(int i =0; i < N; i++) if(win[i] == 1) {
		if(st) cout << " ";
		st =true;
		cout << i+1;}
	cout << "\n";
	return 0;}

// look at my code
// my code is amazing


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define int long long
#define log(x,b) (log(x)/log(b))
using namespace std;

int32_t main()
{
    int a,b,x;
    cin>>a>>b>>x;
    if(b==0)cout<<1<<endl;
    else if(a==0)cout<<b/x+1<<endl;
    else{
        a--;
        cout<<b/x-a/x<<endl;
    }

    return 0;
}


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

typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)

int main() {
  int n,k;
  int count=0;
  cin >> n >> k;
  vint com(n);
  rep(i,n) cin >> com.at(i);
  rep(i,n){
    if (k <= com.at(i)){
      count++;
    }
  }
  cout << count << endl;
    
  return 0;
  
}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int N,M;
int deg [100001];

int main()
{
	scanf("%d%d",&N,&M);
	FOR(i,0,M){
		int u,v;
		scanf("%d%d",&u,&v);
		deg [u]++;
		deg [v]++;
	}

	bool ans = true;
	FOR(i,1,N + 1){
		ans &= deg [i] % 2 == 0;
	}
	printf("%s\n",ans ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 640
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]

t = x = y = 0
for t2,x2,y2 in src:
    dt = t2 - t
    d = abs(x-x2) + abs(y-y2)
    if dt < d or dt%2 != d%2:
        print('No')
        exit()
    t,x,y = t2,x2,y2
print('Yes')


Measured memory_bytes: 17312
# -*- coding: utf-8 -*-
"""
D - Face Produces Unhappiness
https://atcoder.jp/contests/abc140/tasks/abc140_d

"""
import sys

import re

def solve(N, K, S):
    x = len(re.findall(r'RL', S))
    y = (S[0] == 'L') + (S[-1] == 'R')
    ans = N - 2 * x - y
    exe = min(x, K)
    K -= exe
    ans += 2 * exe
    while K and y:
        ans += 1
        K -= 1
        y -= 1
    return min(ans, N-1)


def main(args):
    N, K = map(int, input().split())
    S = input()
    ans = solve(N, K, S)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])


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

int main (){
  string a;
  int ans,max;
  max = 0;
  cin >> a;
  for (int i=0;i<a.size();i++){
  	if (a.at(i) == 'A'||a.at(i) == 'T'|| a.at(i) == 'G'||a.at(i) == 'C'){
      ans = ans + 1;
    	if (ans > max)
         	max = ans;
    }
    if(!(a.at(i) == 'A'||a.at(i) == 'T'|| a.at(i) == 'G'||a.at(i) == 'C')){
      ans = 0;
    }
  }
  cout << max << endl;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
//# pragma GCC optimize("Ofast")
# define pb push_back
# define ll long long
# define fi first
# define se second
# define all(vc) vc.begin(),vc.end()
# define forn(i, n) for (int i = 0; i < int(n); i++)
# define ford(i, n) for (int i = int(n) - 1; i >= 0; i--)
# define fore(i, l, r) for (int i = int(l); i < int(r); i++)
# define fors(i, s) for (int i = 0; s[i]; i++)
# define in freopen("input.txt", "r", stdin)
# define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define time cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
  
using namespace std;
  
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 3e5 + 7;
 
int main()
{      
	speed;
	int a, b;
	cin >> a >> b;
	for ( int i = 1; i <= 3; i++ ) {
		if ( i != a && i != b ) {
			cout << i;
			return 0;
		}
	}
	time; 
}

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

using ll = long long;
using vi = vector<int>;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define PB push_back

struct edge{int to;};
using graph = vector<vector<edge>>;

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

    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 << 2 * a + b - k << endl;
    
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
typedef vector<long long int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vvvi> vvvvi;
const long long int MOD=1e9+7;

string get_str(int& p,string& s){
  string res="";
  while(isalpha(s[p])){
    res+=s[p];
    p++;
  }
  return res;
}

const int MAX_LEN=300;

int main(){
  int na,nt,ng,nc;
  cin>>na>>nt>>ng>>nc;
  int m;
  cin>>m;
  vector<string> line(m);
  cin.ignore(1);
  for(int i=0;i<m;i++){
    getline(cin,line[i]);
  }
  vector<vector<int>> code(m);
  map<string,int> dic;

  map<char,int> DNA_MAP;
  DNA_MAP['A']=1;
  DNA_MAP['T']=2;
  DNA_MAP['G']=4;
  DNA_MAP['C']=8;
  
  for(int i=m-1;i>=0;i--){
    int p=0;
    string& s=line[i];
    string name=get_str(p,line[i]);
    dic[name]=i;
    assert(s[p]==':');
    p++;
    assert(s[p]==' ');
    p++;
    while(p<s.size() && code[i].size()<MAX_LEN){
      if(s[p]=='['){
	p++;
	string str=get_str(p,line[i]);
	assert(line[i][p]==']');
	p++;
	int val=0;
	for(int j=0;j<str.size();j++){
	  val|=(DNA_MAP[str[j]]);
	}
	code[i].push_back(val);
	p++;
      }
      else{
	string str=get_str(p,line[i]);
	p++;
	int index=dic[str];
	assert(i<index);
	code[i].insert(code[i].end(),code[index].begin(),code[index].end());
      }
    }
  }

  if(code[0].size()!=na+nt+ng+nc){
    cout<<0<<endl;
    return 0;
  }
  else{
    vvvvi dp(code[0].size()+1,vvvi(na+1,vvi(nt+1,vi(ng+1,0LL))));
    dp[0][0][0][0]=1;
    for(int i=1;i<=code[0].size();i++){
      for(int j=0;j<=na;j++){
	for(int k=0;k<=nt;k++){
	  for(int l=0;l<=ng;l++){
	    //renew dp[i][j][k][l]
	    int val=code[0][i-1];
	    if(val%2){
	      if(j-1>=0) dp[i][j][k][l]+=dp[i-1][j-1][k][l];
	    }
	    val/=2;
	    if(val%2){
	      if(k-1>=0) dp[i][j][k][l]+=dp[i-1][j][k-1][l];
	    }
	    val/=2;
	    if(val%2){
	      if(l-1>=0) dp[i][j][k][l]+=dp[i-1][j][k][l-1];
	    }
	    val/=2;
	    if(val%2){
	      dp[i][j][k][l]+=dp[i-1][j][k][l];
	    }
	    dp[i][j][k][l]%=MOD;
	  }
	}
      }
    }

    cout<<dp[code[0].size()][na][nt][ng]<<endl;
  }

}

Measured memory_bytes: 205076
#include<stdio.h>
int main(){
  int a,b,i,M=1e9+7;
  long long s,d[100010]={1,1};
  for(i=1;i<100005;i++)d[i]=(d[i-1]*i)%M;
  scanf("%d %d",&a,&b);
  s=(d[a]*d[b])%M;
  if(a-b<-1||1<a-b)s*=0;
  if(a==b)s=(s*2)%M;
  printf("%lld\n",s);
  return 0;
}


Measured memory_bytes: 896
#include <cstdio>
#include <cstring>

using namespace std;

int main(void){
	int max, cnt[100], x, i;
	memset(cnt,0,sizeof(cnt));
	while(scanf("%d",&x) != EOF){
		cnt[x - 1]++;
	}
	max = 0;
	for(i = 0;i < 100;i++){
		if(max < cnt[i]){
			max = cnt[i];
		}
	}
	for(i = 0;i < 100;i++){
		if(max == cnt[i]){
			printf("%d\n",i + 1);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <set>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <string>
#include <sstream>
#include <algorithm>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <cmath>
using namespace std;
#define dbg(x) cerr << #x " = " << x <<endl;

char num[10];
bool use[10]; //1 cannot        0 can
int check(int num)
{
	int _num = num;
	while(_num > 0)
	{
		if(use[_num%10])
		{
			return 1;
		}
		_num /= 10;
	}
	return 0;
}

int main()
{
	int n, k;
	cin >> n >> k;
	for(int i = 0; i < k; i++)
	{
		int num;
		cin >> num;
		use[num] = 1;
	}
	while(check(n))
	{
		n++;
	}
	cout << n;
	
}

Measured memory_bytes: 256