akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include<list>
#include <algorithm>
#include <string>
#include <math.h>
#include<map>
#include <utility>
#include <cstring>
#include <iomanip>
#include<queue>
using namespace std;
#define REP(i,k,n) for(int i=k;i<n;i++)
 
#define INF 1000000000
typedef long long  ll;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
#define MOD 1000000007

template<typename T>
int vector_finder(std::vector<T> vec, T number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

template<typename T>
T gcd(T a,T b){
	if(b>0){
		return gcd(b, a % b);
	}else{
		return a;
	}
}

template<typename T>
T lcm(T a,T b){
	T g = gcd(a, b);
	return a /g* b ;
}

void clear( std::queue<pair<int,int> > &q )
{
   std::queue<pair<int,int> > empty;
   std::swap( q, empty );
}
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return false;
        }
    }

    // 素数である
    return true;
}
template<typename T>
int  GetDigit(T num){
    int digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}

template<typename T>
std::vector<T> enum_div(T n)//nの約数を列挙
{
	std::vector<T> ret;
	for(T i=1 ; i*i<=n ; ++i)
	{
		if(n%i == 0)
		{
			ret.push_back(i);
			if(i!=1 && i*i!=n)
			{
				ret.push_back(n/i);
			}
		}
	}
	return ret;
}


class DisjointSet{
    public:
        vector<int> rank, p;

        DisjointSet(){
        }

        DisjointSet(int size){
            rank.resize(size, 0);
            p.resize(size, 0);
            for (int i = 0; i < size;i++){
                makeSet(i);
            }
        }
        void makeSet(int x){
            p[x] = x;
            rank[x] = 0;
        }

        bool same(int x,int y){
            return findSet(x) == findSet(y);
        }
        void unite(int x,int y){
            link(findSet(x), findSet(y));
        }
        void link(int x,int y){
            if(rank[x]>rank[y]){
                p[y] = x;
            }else{
                p[x] = y;
                if(rank[x]==rank[y]){
                    rank[y]++;
                }
            }
        }
        int findSet(int x){
            if(x!=p[x]){
                p[x] = findSet(p[x]);
            }
            return p[x];
        }
};


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

    ll a[3*N];

    REP(i,0,3*N){
        cin >> a[i];
    }
    sort(a, a + 3*N);
    ll ans = 0;
    for (int i = 0, j = 3 * N - 2; i < N; i++, j -= 2)
    {

        ans += a[j];
    }
    cout << ans << endl;
}

Measured memory_bytes: 2560
//In The Name Of God
#include <bits/stdc++.h>
#define F first
#define S second
#define mp make_pair
#define L(x) (2*(x))
#define R(x) ((2*(x))+1)
#define pii pair<int, int>
#define pb push_back
using namespace std;
const int N = 1e5 + 5, Mod = 1e9 + 7, P = 727, Lg = 17, TOF = 1900;

int main(){
      ios_base::sync_with_stdio(0); cin.tie(0);
      int n, a, b; cin >> n >> a >> b;
      int f1 = 0, f2 = 0, f3 = 0;
      for(int i = 1; i <= n; i++){
            int x; cin >> x;
            if(x <= a)
                  f1++;
            if(x > a && x <= b)
                  f2++;
            if(x > b)
                  f3++;
      }
      return cout << min(min(f1, f2), f3), 0;
}



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

#define int long long
#define IOS ios::sync_with_stdio(false); cin.tie(nullptr);                                                        
#define endl "\n"

int32_t main()
{
	IOS;
	#ifdef LOCAL
	freopen("input.txt","rt",stdin);
	#endif

	int n;
	cin >> n;
	for(int i = 1; i <= 9; i++)
	{
	 	for(int j = 1; j <= 9; j++)
	 	{
	 	 	if(i*j == n)
	 	 		return cout <<"Yes",0;
	 	}
	}
    cout <<"No\n";
	#ifdef LOCAL
	cerr << "Time elapsed : " << 1.0*clock()/CLOCKS_PER_SEC << " s.\n";
	#endif
    return 0;
}   

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>

using namespace std;

typedef long long LL;

#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define rep(i,n) for (int i = 0; i < (n); ++i)

const int MOD = 1000000007;

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

    LL ans = 0;
    rep(i, N) {
        int h;
        cin >> h;
        if (K <= h) {
            ++ans;
        }
    }


    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <cmath>
#include <algorithm>

using namespace std;


int main() {
    int X = 0;
    cin >> X;
    if (X >= 30) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
}


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

const int MAXN = 100005;

long long INF = 1e15;
int x, y, z, N;
struct point {
	long long a, b;
	friend bool operator < (const point &a, const point &b)
	{ return a.a > b.a; } 
} pt[MAXN];

int main()
{
	ios::sync_with_stdio(false);
	srand(time(0));
	cin >> x >> y >> z;
	N = x+y+z;
	long long ans = 0;
	for (int i = 1; i <= N; i++) {
		long long u, v, t;
		cin >> u >> v >> t;
		pt[i] = (point) {v-u, t-u};
		ans += u;
	}
	sort(pt+1, pt+N+1);
	static long long b[MAXN];
	static priority_queue<long long,vector<long long >,greater<long long> > que;
	static priority_queue<long long> del;
	long long cur = 0;
	for (int i = z+y+2; i <= N; i++) del.push(pt[i].b);
	for (int i = z+y+1; i >= y+1; i--) {
		que.push(pt[i].b), cur += pt[i].b;
		while (!del.empty() && que.top() < del.top()) {
			long long u = que.top(), v = del.top();
			que.pop(), del.pop();
			que.push(v), del.push(u);
			cur += v-u;
		}
		int need = z-(i-1-y);
		while (que.size() > need) cur -= que.top(), del.push(que.top()), que.pop();
		b[i] = cur;
		// cerr << i << "," << cur << endl;
	}
	// i --> z-(i-1-y) = z+y+1-i >= 0 , i-1-y >= 0
	while (!que.empty()) que.pop();
	cur = 0;
	long long pre = 0;
	for (int i = 1; i <= y; i++) que.push(pt[i].a-pt[i].b), cur += pt[i].a-pt[i].b, pre += pt[i].b;
	long long tot = cur+pre+b[y+1];
	// cerr << ans << endl;
	// for (int i = 1; i <= N; i++) cerr << pt[i].a << " " << pt[i].b << endl;
	for (int i = y+1; i <= z+y; i++) {
		pre += pt[i].b;
		cur += pt[i].a-pt[i].b;
		que.push(pt[i].a-pt[i].b);
		cur -= que.top();
		que.pop();
		tot = max(tot, pre+cur+b[i+1]);
		// cerr << tot << " " << pre << " " << cur << " " << b[i+1] << endl;
	}
	cout << tot+ans << endl;
	return 0;
}


Measured memory_bytes: 3320
import sys
n=int(input())
if n==0:
    print(0)
    sys.exit()
ans=""
for i in range(2**31):
    a=(-2)**i
    if (n//a)%2==1:
        ans="1"+ans
        n-=a
        if n==0:
            print(ans)
            break
    else:
        ans="0"+ans

Measured memory_bytes: 3060
#line 1 "DPL_2_A.cpp"
#include <cstdio>
#include <algorithm>
#include <tuple>
#include <utility>

#line 1 "~/git/library/utility/literals.cpp"



/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }


#line 1 "~/git/library/utility/make/pre17/vector.cpp"
/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */

#ifndef H_make_vector
#define H_make_vector

#line 10 "~/git/library/utility/make/pre17/vector.cpp"
#include <type_traits>
#include <vector>

namespace detail {
  template <typename Tp, size_t N>
  std::vector<Tp> make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N == 1), Tp const&>::type x
  ) {
    return std::vector<Tp>(sizes[0], x);
  }
  template <typename Tp, size_t N>
  auto make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N > 1), Tp const&>::type x
  ) {
    size_t size = sizes[N-1];
    sizes.pop_back();
    return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
        size, make_vector<Tp, N-1>(sizes, x)
    );
  }
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x = Tp()) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

#endif  /* !defined(H_make_vector) */
#line 8 "DPL_2_A.cpp"

int main() {
  size_t v, e;
  scanf("%zu %zu", &v, &e);

  std::vector<std::vector<std::pair<size_t, int>>> g(v);
  for (size_t i = 0; i < e; ++i) {
    size_t s, t;
    int d;
    scanf("%zu %zu %d", &s, &t, &d);
    g[s].emplace_back(t, d);
  }

  int const inf = 1e9;
  auto dp = make_vector({1_zu << v, v}, inf);
  dp[0][0] = 0;
  for (size_t i = 0; i < (1_zu << v); ++i) {
    for (size_t jl = 0; jl < v; ++jl) {
      if (dp[i][jl] == inf) continue;
      for (auto const& e: g[jl]) {
        size_t jr;
        int d;
        std::tie(jr, d) = e;
        if (i >> jr & 1) continue;
        size_t ni = i | 1_zu << jr;
        dp[ni][jr] = std::min(dp[ni][jr], dp[i][jl] + d);
      }
    }
  }

  int res = dp.back()[0];
  if (res == inf) return puts("-1"), 0;
  printf("%d\n", res);
}



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


using namespace std;

long long dp[123456];

int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for(int i = 0; i < n; i++) cin >> h[i];
	dp[0] = 0;
	dp[1] = abs(h[1] - h[0]);

	for(int i = 2; i < n; i++) dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]), dp[i-2]+abs(h[i] - h[i-2]));

	cout << dp[n-1] << endl;
}

Measured memory_bytes: 1408
import sys
#input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


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


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))

# rstrip().decode('utf-8')

#####segfunc#####
def segfunc(x, y):
    return x*y
#################

#####ide_ele#####
ide_ele = 1
#################

class SegTree:
    """
    init(init_val, ide_ele): 配列init_valで初期化 O(N)
    update(k, x): k番目の値をxに更新 O(logN)
    query(l, r): 区間[l, r)をsegfuncしたものを返す O(logN)
    """
    def __init__(self, init_val, segfunc, ide_ele):
        """
        init_val: 配列の初期値
        segfunc: 区間にしたい操作
        ide_ele: 単位元
        n: 要素数
        num: n以上の最小の2のべき乗
        tree: セグメント木(1-index)
        """
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num
        # 配列の値を葉にセット
        for i in range(n):
            self.tree[self.num + i] = init_val[i]
        # 構築していく
        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        """
        k番目の値をxに更新
        k: index(0-index)
        x: update value
        """
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        l: index(0-index)
        r: index(0-index)
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res

def main():
	n=II()
	s=input()
	S=[]
	for i in s:
		S.append(ord(i)-ord("a"))
	
	seg=[SegTree([1]*n,segfunc,ide_ele) for _ in range(26)]
	
	#print(S)
	#print(seg)
	for i in range(n):
		seg[S[i]].update(i,0)
	
	q=II()
	for _ in range(q):
		a,b,c=input().split()
		if int(a)==1:
			b=int(b)-1
			seg[S[b]].update(b,1)
			t=ord(c)-ord("a")
			seg[t].update(b,0)
			S[b]=t
		
		else:
			#print(S)
			b=int(b)-1
			c=int(c)
			cnt=0
			for se in seg:
				if se.query(b,c)==0:
					cnt+=1
			print(cnt)
			
	
	

if __name__=="__main__":
	main()


Measured memory_bytes: 324956
#include<iostream>
#include<algorithm>
#include<utility>
using namespace std;
typedef long long ll;
const ll one = 1ULL;
const ll zero = 0Ull;
int main(){
    ll a,b;
    while(cin>>a>>b){
        ll n = b - a + 1;
        ll ans = 0;
        for(int i = 0;i<62;i++){
            const ll base = one<<(i+1);
            if( (one<<i)> b )break;
            const ll r = n % base;
            const ll d = n / base;
            const ll ra = a % base;

            if(i == 0){
                ans ^= d%2;// 区分odd and even T
            }
            const ll zero2ra = max(zero, ra - base/2);
            ll zero2raPr;
            if(ra+r > base){
                zero2raPr = base/2 + max(zero, (ra+r-base) - base/2);
            }
            else {
                zero2raPr = max(zero, ra + r - base/2);
            }
            ll ones =zero2raPr - zero2ra;
            if(ones&1){
                ans ^= one<<(i);
            }
            //cout<<"r"<<" "<<r<<endl;
            //cout<<"d"<<" "<<d<<endl;
            //cout<<"ra"<<" "<<ra<<endl;
            //cout<<"zero2ra"<<" "<<zero2ra<<endl;
            //cout<<"zero2raPr"<<" "<<zero2raPr<<endl;
            //cout<<'i'<<':'<<i<<" ones:"<<ones<<" ans:"<<ans<<endl;
        }
        cout<<ans<<endl;
    }
    return 0;
}


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

const int mod=998244353;
const int MAX_N=300001;
ll fact[MAX_N+1];
ll inv[MAX_N+1],finv[MAX_N+1];
int inv_init(ll n,ll p){
    inv[1]=1;
    FOR(i,2,n+1) inv[i]=p-(p/i)*inv[p%i]%p;
    fact[0]=finv[0]=1;
    FOR(i,1,n+1){
        fact[i]=fact[i-1]*i%p;
        finv[i]=finv[i-1]*inv[i]%p;
    }
    return 0;
}
ll comb_mod(ll n,ll k,ll p){
    if(k<0||n<k) return 0;
    return finv[k]*finv[n-k]%p*fact[n]%p;
}
int main(){
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    inv_init(n,mod);
    ll sum=0;
    rep(i,n+1){
        if(k>=a*i&&(k-a*i)%b==0){
            ll j=(k-a*i)/b;
            if(j>n) continue;
            sum+=comb_mod(n,i,mod)*comb_mod(n,j,mod)%mod;
            sum%=mod;
        }
    }
    cout<<sum<<endl;
    return 0;
}

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

#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define UL unsigned long long


int main(void)
{
    IOS
    int n,k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> d;

    //if (s[0]== '0') d.push_back(0);
    d.push_back(1);
    for(auto i = 1; i < n; i++)
    {

        if (s[i-1] != s[i]) { 
            d.emplace_back(i+1);
        }
        // tail
        if (i == n-1) { 
            d.emplace_back(i+2);
        }
    }
    
    /*
    cerr << "zeroone: ";
    for(int i = 0; i < d.size() ; i++) {
        cerr << d[i] << " ";
    }
    cerr << endl;
    */
    
    int m = d.size();
    if (m < k*2+1) {
        cout << n << endl; 
        return 0;
    }
    
    int ans = 0;
    int tmp = 0;

    for( int i = 0; i < m - k*2; i++)
    {
        if ((s[d[i]-1]=='1') && (i+k*2+1 < m)) {
            tmp = d[i+k*2+1] - d[i];
        } else {
            tmp = d[i+k*2] - d[i];
        }

        //cerr << "i: " << i << " tmp: " << tmp << endl;
        //cerr <<" tmp: " << tmp << endl;
        ans = max(ans, tmp);

    }
    

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


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

int cur[8][3]={1,4,-1,0,2,5,1,3,6,2,7,-1,0,5,-1,4,6,1,5,2,7,3,6,-1};
struct A{
    int id,a[8];
    A(int i=0):id(i){}
    A(const A &m){
        id=m.id;
        memcpy(a,m.a,sizeof a);
    }
    bool operator < (const A &m)const{
        for(int i=0;i<8;i++){
            if(a[i] < m.a[i]) return 1;
            else if(a[i] > m.a[i]) return 0;
        }
        return 0;
    }
    bool operator == (const A &m)const{
        for(int i=0;i<8;i++)
            if(a[i]!=m.a[i]) return 0;
        return 1;
    }
};
map<A,int> m;
A a(0),ans(0);

int bfs()
{
    m.clear();
    m[ans]=0;
    queue<A> q;
    q.push(ans);
    while(!q.empty()){
        A t(q.front());
        q.pop();
        //if(t==ans) return m[t];
        for(int i=0;i<3;i++){
            A x(t);
            if(cur[x.id][i]!=-1) {swap(x.a[x.id],x.a[cur[x.id][i]]);x.id=cur[x.id][i]; }
            if(!m.count(x)){
                m[x] = m[t]+1;
                q.push(x);
            }
        }
    }
    return -1;
}
int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    for(int i=0;i<8;i++) ans.a[i]=i;
    bfs();
    while(cin>>a.a[0]){
        for(int i=1;i<8;i++)
            cin>>a.a[i];
        cout<<m[a]<<endl;
    }
    return 0;
}



Measured memory_bytes: 4716
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <deque>
#include <list>
#include <stack>
#include <queue>
#include <functional>
#include <set>
#include <tuple>
#include <map>
#include <numeric>

using namespace std;
#define PI 3.14159265359
#define ll long long int

int main(void)
{
    ll N, M;
    cin >> N >> M;
    pair<bool, ll> memo[N];

    for(ll i = 0; i < N; i++){
        memo[i].first = false;
        memo[i].second = 0;
    }

    for(ll i = 0; i < M; i++){
        ll p;
        string s;
        cin >> p >> s;
        if(s == "AC") memo[p - 1].first = true;
        else{
            if(memo[p - 1].first == false){
                memo[p - 1].second++;
            }
        }
    }

    ll ans1 = 0, ans2 = 0;
    for(ll i = 0; i < N; i++){
        if(memo[i].first == true){
            ans1++;
            ans2 += memo[i].second;
        }
    }


    printf("%lli %lli\n", ans1, ans2);
}

Measured memory_bytes: 1792
#include <iostream>
#include <set>
#include <vector>
#include <string>
#include <algorithm>
#include <iterator>
#include <map>
#include <utility>
#include <list>
#include <climits>
#include <bitset>
#include <numeric>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repi(i, n) for(auto i = (n).begin(); i != (n).end(); i++)
#define in_arr(type, a, n) copy_n(istream_iterator<type>(cin), n, (a).begin());
#define ll long long int

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    set<string> past;
    past.insert(s);
    char f = s[0], l = s[s.size() - 1];
    rep(i, n - 1){
        cin >> s;
        f = s[0];
        if(past.find(s) != past.end()){
            cout << "No" << endl;
            return 0;
        }
        past.insert(s);
        if(f != l){
            cout << "No" << endl;
            return 0;
        }
        l = s[s.size() - 1];
    }
    cout << "Yes" << endl;
    return 0;
}


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

def digitSum(n):
    # 数値を文字列に変換
    s = str(n)
    # １文字ずつ数値化し配列にする。
    array = list(map(int, s))
    # 合計値を返す
    return sum(array)


if digitSum(N) % 9 == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 11108
"use strict";
    
const main = arg => {
    const rectangles = arg.split("\n")[0].split(" ");
    const A = rectangles[0] * rectangles[1];
    const B = rectangles[2] * rectangles[3];
    console.log(Math.max(A, B));
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
using namespace std;
typedef long long ll;
inline ll min(ll x, ll y) { return x < y ? x : y; }
inline ll max(ll x, ll y) { return x > y ? x : y; }
const int Maxn = 3e3 + 5;
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	}while(isdigit(ch));
	return res * sign;
}
int n,cnt;
int val[Maxn],fir[Maxn];
bool win[Maxn],vis[Maxn];
struct {
	int to,last;
}e[2*Maxn];
void con(int u,int v)
{
	e[++cnt].to=v;
	e[cnt].last=fir[u];
	fir[u]=cnt;
}
void DFS(int x)
{
	vis[x]=true;
	for(int next=fir[x],nx;next;next=e[next].last)
	{
		nx=e[next].to;
		if(val[nx]>=val[x])
			continue;
		if(!vis[nx])
			DFS(nx);
		win[x]|=!win[nx];
	}
}
int main()
{
	rg int a,b;
	cin>>n;
	for(int i=1;i<=n;i++)
		val[i]=read();
	for(int i=1;i<n;i++)
	{
		a=read();
		b=read();
		con(a,b);
		con(b,a);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
			DFS(i);
	for(int i=1;i<=n;i++)
		if(win[i])
			printf("%d ",i);
	puts("");	
	return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<string.h>
#include<vector>
#include<list>
#include<stdio.h>
#include<math.h>
#include<iomanip>
#include<map>
#include<stack>
#include<queue>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug " << x << endl;
using namespace std;

int dp[15][15];

int main(){
    int n;
    while(cin >> n, n){
        rep(i,15){
            rep(j,15){
                dp[i][j] = 2 << 24;
            }
            dp[i][i] = 0;
        }
        int ma = 0;
        rep(i,n){
            int a, b, c;
            cin >> a >> b >> c;
            dp[a][b] = c;
            dp[b][a] = c;
            if(ma < a)
                ma = a;
            if(ma < b)
                ma = b;
        }
        rep(k,n + 1){
            rep(i,n + 1){
                rep(j,n + 1){
                    dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
                }
            }
        }
        int ans, time, mintime = 2 << 24;
        rep(i,ma + 1){
            time = 0;
            rep(j,ma + 1){
                time+= dp[i][j];
            }
            if(mintime > time){
                mintime = time;
                ans = i;
            }
        }
        cout << ans << ' ' << mintime << endl;
    }
}

Measured memory_bytes: 1160
class PriorityQueue():
    def __init__(self,arr,op=min):
        self.arr = arr
        self.op = op
        for i in range(len(arr)//2)[::-1]:
            self._siftup(i)

    def push(self,item):
        self.arr.append(item)
        self._siftdown(0,len(self.arr)-1)

    def pop(self):
        lastelt = self.arr.pop()
        if self.arr:
            returnitem = self.arr[0]
            self.arr[0] = lastelt
            self._siftup(0)
            return returnitem
        return lastelt

    def _siftdown(self,startpos,pos):
        newitem = self.arr[pos]
        while pos > startpos:
            parentpos = (pos - 1) >> 1
            parent = self.arr[parentpos]
            if self.op(newitem,parent) == newitem:
                self.arr[pos] = parent
                pos = parentpos
                continue
            break
        self.arr[pos] = newitem

    def _siftup(self,pos):
        endpos = len(self.arr)
        startpos = pos
        newitem = self.arr[pos]
        childpos = 2*pos + 1
        while childpos < endpos:
            rightpos = childpos + 1
            if rightpos < endpos and not self.op(self.arr[childpos],self.arr[rightpos])==self.arr[childpos]:
                childpos = rightpos
            self.arr[pos] = self.arr[childpos]
            pos = childpos
            childpos = 2*pos + 1
        self.arr[pos] = newitem
        self._siftdown(startpos,pos)

N,M = map(int,input().split())
A = list(map(int,input().split()))

P = PriorityQueue(A,max)

for i in range(M):
    x = P.pop()
    x //= 2
    P.push(x)

print(sum(P.arr))

Measured memory_bytes: 78232
#include<stdio.h>

int A[1000000], n;

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

int main(){
    int i, q, k, sum = 0;
    
    scanf("%d", &n);
    for(i = 0; i < n; i++){
        scanf("%d", &A[i]);
    }
    
    scanf("%d", &q);
    for(i = 0; i < q; i++){
        for(i = 0; i < q; i++){
            scanf("%d", &k);
            if(binarySearch(k)) sum++;
        }
        
        printf("%d\n", sum);
        
        return 0;
    }
}


Measured memory_bytes: 3080
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 

using namespace std;
using namespace __gnu_pbds; 

#define ff          first
#define ss          second
#define ll          int64_t
#define ld          long double
#define nl          cout<<"\n"
#define dbg(x)      cerr<<#x<<" = "<<x<<"\n"
#define dbg2(x,y)   cerr<<#x<<" = "<<x<<"   "<<#y<<" = "<<y<<"\n"
#define all(v)      v.begin(),v.end()
#define mset(a,v)   memset((a),(v),sizeof(a))
#define forn(i,a,b) for(int64_t i=int64_t(a);i<int64_t(b);++i)
#define forb(i,a,b) for(int64_t i=int64_t(a);i>=int64_t(b);--i)
#define fastio()    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ordered_set tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> 

#define mod         1000000007
#define mod2        998244353 
#define inf         1000000000000007
#define pi          3.14159265358979323846

template<typename T,typename U> static inline void amin(T &x,U y)                   {if(y<x)x=y;}
template<typename T,typename U> static inline void amax(T &x,U y)                   {if(x<y)x=y;}  
template<class L,class R> ostream& operator<<(ostream& out,pair<L,R> &p)            {return out<<"("<<p.ff<<", "<<p.ss<<")";}
template<class T> ostream& operator<<(ostream& out,vector<T> &v)                    {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,deque<T> &v)                     {out<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())out<<", ";out<<*it;}return out<<"]";}
template<class T> ostream& operator<<(ostream& out,set<T> &s)                       {out<<"{";for(auto it=s.begin();it!=s.end();++it){if(it!=s.begin())out<<", ";out<<*it;}return out<<"}";}
template<class L,class R> ostream& operator<<(ostream& out,map<L,R> &m)             {out<<"{";for(auto it=m.begin();it!=m.end();++it){if(it!=m.begin())out<<", ";out<<*it;}return out<<"}";}

ll count_digits(ll n)   {ll dig=floor(log10(n)+1);return dig;}
ll mpow(ll x,ll y,ll p) {ll r=1;x=x%p;while(y>0){if(y&1)r=(r*x)%p;y=y>>1;x=(x*x)%p;}return r;} 
string dec_bin_32(ll n) {string s;for(ll i=31;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
string dec_bin_64(ll n) {string s;for(ll i=63;i>=0;i--){ll k=n>>i;s+=(k&1)?'1':'0';}return s;} 
ll mod_inv(ll a,ll m)   {ll m0=m,y=0,x=1;if(m==1)return 0;while(a>1){ll q=a/m,t=m;m=a%m,a=t;t=y;y=x-q*y;x=t;}if(x<0)x+=m0;return x;} 
/* const ll MAXN=10000007;ll spf[MAXN+5];vector<ll> prime; */
/* void sieve(ll n)        {forn(i,2,MAXN+1)spf[i]=i;for(ll i=2;i*i<=n;i++)if(spf[i]==i)for(ll j=i*i;j<=n;j+=i)if(spf[j]==j)spf[j]=i;forn(i,2,MAXN+1)if(spf[i]==i)prime.push_back(i);} */

//-------------------------------L_I_Erq34-------------------------------

int main()
{
	fastio();
	ll z,n,m,t,k,i,j,l,d,h,r;
	cin>>n;
	string s;
	cin>>s;
	i=0,j=n-1;
	ll ans=0;
	while(i<j)
	{
		if(s[i]=='W')
		{
			while(j>i and s[j]=='W')
				j--;
			if(j>i)
				ans++;
			j--;
		}
		i++;
	}
	cout<<ans<<"\n";
	cerr<<"\nTime elapsed: "<<1000*clock()/CLOCKS_PER_SEC<<"ms\n";
	return 0;
}


Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
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 inf = 1001001001;

int main() {
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i,n) cin >> l[i];
    sort(all(l));
    int ans = 0;
    rep2(i,2,n) {
        for(int j = i-1; j > 0; j--) {
            int rem = l[i]-l[j];
            if(l[j-1] <= rem) break;
            int le = -1,ri = j;
            int ret;
            while(true) {
                if(ri-le <= 1) {
                    ret = ri;
                    break;
                }
                int mid = (le+ri)/2;
                if(l[mid] > rem) ri = mid;
                else le = mid;
            }
            ans += j-ret;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
// AOJ ALDS1_4_C Dictionary
// 2018.4.27 bal4u

#include <stdio.h>

// バッファを経ずstdinから数値を得る
#define gc() getchar_unlocked()
//#define gc() getchar()
int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

int  tr['T'+1];
char f[33554432];

int main()
{
	int n, k, c;

	tr['A'] = 0, tr['C'] = 1, tr['G'] = 2, tr['T'] = 3;
	n = in();
	while (n--) {
		if (gc() == 'i') {
			k = 6; while (k--) gc();
			k = 1; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
			f[k] = 1;
		} else {
			k = 4; while (k--) gc();
			k = 1; while ((c = gc()) >= ' ') k <<= 2, k |= tr[c];
			puts(f[k]? "yes": "no");
		}
	}
	return 0;
}



Measured memory_bytes: 2944
N = int(input())
V = list(map(int, input().split()))
C = list(map(int, input().split()))

D = [V[i]-C[i] for i in range(N)]

D.sort(reverse=True)

_sum=0

for d in D:
    if d <= 0:
        break
    _sum += d

print(_sum)


Measured memory_bytes: 38256
N = gets.to_i
S = gets.chomp
pivot = N.div(2)
pivot_west_cnt = S[0..pivot].count('W')
pivot_east_cnt = S[pivot..N-1].count('E')
cnt = N
cnt_west = pivot_west_cnt
cnt_east = pivot_east_cnt
pivot.downto(0) do |n|
    # 真ん中から西側への処理
    if S[n] == 'W'
        cnt_west -= 1
    else
        cnt_east += 1
    end
    cnt = [cnt, cnt_west + cnt_east].min
end
cnt_west = pivot_west_cnt
cnt_east = pivot_east_cnt
pivot.upto(N-1) do |n|
    # 真ん中から東側への処理
    if S[n] == 'W'
        cnt_west += 1
    else
        cnt_east -= 1
    end
    cnt = [cnt, cnt_west + cnt_east].min
end
puts cnt

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

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)
#define UNIQUE(v) do{ (v).erase( unique(begin(v), end(v)), end(v) ); } while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int main() {
	ios_base::sync_with_stdio(false);
	ll N, M; cin >> N >> M;
	if (N > M) swap(N, M);
	if (N == 1) {
		cout << (M == 1 ? 1 : M - 2) << endl;
		return 0;
	}
	cout << (N - 2) * (M - 2) << endl;
	return 0;
}


Measured memory_bytes: 256
// Standard I/O
#include <iostream>
#include <sstream>
#include <cstdio>
// Standard Library
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
// Template Class
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
// Container Control
#include <algorithm>

using namespace std;

#define rep( i, n ) for( int i = 0; i < n; ++i )
#define irep( i, n ) for( int i = n-1; i >= 0; --i )
#define reep( i, s, n ) for ( int i = s; i < n; ++i )
#define ireep( i, n, s ) for ( int i = n-1; i >= s; --i )
#define foreach(itr, x) for( typeof(x.begin()) itr = x.begin(); itr != x.end(); ++itr)

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all( v ) v.begin(), v.end()
#define fs first
#define sc second
#define vc vector

// for visualizer.html
double SCALE = 1.0;
double OFFSET_X = 0.0;
double OFFSET_Y = 0.0;
#define LINE(x,y,a,b) cerr << "line(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(a) + OFFSET_X << ","										\
	<< SCALE*(b) + OFFSET_Y << ")" << endl;
#define CIRCLE(x,y,r) cerr << "circle(" << SCALE*(x) + OFFSET_X << ","	\
	<< SCALE*(y) + OFFSET_Y << ","										\
	<< SCALE*(r) << ")" << endl;

typedef long long ll;
typedef complex<double> Point;

typedef pair<int, int> pii;
typedef pair<int, pii> ipii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector< vector<int> > vii;
typedef vector< vector<double> > vdd;

typedef vector<int>::iterator vi_itr;

const int IINF = 1 << 28;
const double INF = 1e30;
const double EPS = 1e-10;
const double PI = acos(-1.0);

// Direction : L U R D
const int dx[] = { -1, 0, 1, 0};
const int dy[] = { 0, -1, 0, 1 };

int W, H;
ll p[100000], q[100000];
vector<tuple<ll, int, int>> v;

ll solve ( int h, int w, int depth )
{
	if( depth == v.size() ){
		return 0;
	}

	ll cost;
	int row, column;
	tie(cost, row, column) = v[depth];

	if( row == -1 ){
		return (w+1)*cost + solve(h-1, w, depth+1);
	}
	else{
		return (h+1)*cost + solve(h, w-1, depth+1);
	}
}

int main()
{
	cin >> W >> H;
	rep(i, W){
		int p;
		cin >> p;
		v.eb(p, i, -1);
	}
	rep(i, H){
		int q;
		cin >> q;
		v.eb(q, -1, i);
	}

	sort(all(v));

	cout << solve(H, W, 0) << endl;
}


Measured memory_bytes: 4464
#include <iostream>
#include <cstdio>

using namespace std;

int n;
long long a,b,c,d,t1,t2;

int main(){
	cin>>n>>a>>b>>c>>d;
	a=b-a;
	for (int i=0;i<=n-1;i++){
		t1=c*i-d*(n-1-i);
		t2=d*i-c*(n-1-i);
		if (t1<=a&&a<=t2){
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
	return 0;
}

Measured memory_bytes: 256
/*
    STARK_BOY
*/
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repe(i,a,b) for(ll i=a;i<=b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
typedef pair<ll,ll> pii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define PI           3.14159265358979323846  /* pi */
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
#define N 1000005
//Variables Start
ll inf=1e18,MOD=1e9+7;
//Variables End

int main()
{
    ios
    int ti=1;
    //cin>>ti;
    while(ti--)
    {
		int n;cin>>n;
		vector<int> ans(n+1,0);
		for(int i=2;i<=n;i++){
			int x;cin>>x;
			ans[x]++;
		}
		
		for(int i=1;i<=n;i++)cout<<ans[i]<<"\n";
    }
    return 0;
        
}


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

int main(){
	string str;
	int k,u,p,c;
	k = u = p = c = 0;
	cin >> str;
	for(int i = 0; i < str.size();i++){
		switch(str[i]){
			case 'K': k++;break;
			case 'U': u++;break;
			case 'P': p++;break;
			case 'C': c++;break;
			default : break;
		}
	}
	cout << min(k,min(u,min(p,c))) << endl;
	return 0;
}



Measured memory_bytes: 3220
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int X = sc.nextInt();
		int ans = 0;
		
		for(int i = 0; i <= A; i++) {
			for(int j = 0; j <= B; j++) {
				for(int k = 0; k <= C; k++) {
					if(500 * i + 100 * j + 50 * k == X) {
						ans++;
					}
				}
			}
		}
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 23124
#include<cstdio>
#include<cstring>
const int N=100+10;
int n,ans;
char s[N];
int main()
{
	scanf("%s",s+1);
	n=strlen(s+1);
	for(int i=1;i<=n;i++)
		if(s[i]!=s[n-i+1])
		{
			s[n-i+1]=s[i];
			ans++;
		}
	printf("%d",ans);
	return 0;
}

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

int main(void){
  string s;
  int cnt = 0;
  while(cin >> s){
    int left = 0, right = s.length()-1;
    while(left <= right){
      if(s[left] != s[right]) break;
      left++;
      right--;
    }
    if(right < left) cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 1184
#include <iostream>
#include <string>

int main(void){
  int N, a, b;
  std::string s;

  std::cin >> N >> a >> b >> s;

  for(int n=0; n<N; n++){
    if(s[n]=='a'){
      if(a!=0){
	a--;
	std::cout << "Yes" << std::endl;
      }else if(b!=0){
	b--;
	std::cout << "Yes" << std::endl;
      }else{
	std::cout << "No" << std::endl;
      }
    }else if(s[n]=='b'){
      if(b!=0){
	b--;
	std::cout << "Yes" << std::endl;
      }else{
	std::cout << "No" << std::endl;
      }
    }else{
      std::cout << "No" << std::endl;
    }
  }
  
  return 0;
}

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

int main(){
  int n, a, b;
  cin >> n >> a >> b;
  int sum = 0;
  for(int idx = a; idx <= n; idx++){
    int cnt = 0;
    int i = idx;
    while(i){
      cnt += i % 10;
      i /= 10;
    }
    if(a <= cnt && cnt <= b) sum += idx;
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;cin>>N;
    vector<int>V(N);
    int x,sum,count,m;
    sum=0;
    m=100;
    count=0;
    for(int i=0;i<N;i++){
        cin>>x;
        sum+=x;
        if(x%10 !=0){
        m=min(m,x);
        count++;
    }
    }
    if(sum%10 != 0)cout<<sum<<endl;
    else if(count==0)cout<<'0'<<endl;
    else cout<<sum-m<<endl;

}

Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    k = int(input())
    ans = 1

    if k % 2 == 0 or k % 5 == 0:
        print(-1)
    else:
        a = 7
        while 1:
            if a % k == 0:
                print(ans)
                break
            else:
                a = (a % k) * 10 + 7
                ans += 1
if __name__ == '__main__':
    main()


Measured memory_bytes: 62800
#include<stdio.h>

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

int ask(int a,int b){
  char s[8];
  printf("? %d %d\n",a,b);
  fflush(stdout);
  scanf("%s",s);
  if(s[0]=='Y'){return 1;}
  return 0;
}

int main(){
  int a,b,n,i,p[4096],pl=0;
  char res[4096]={0};
  scanf("%d%d",&a,&b);
  n=a+b;
  if(a<=b){
    printf("Impossible\n");
    fflush(stdout);
    return 0;
  }
  for(i=0;i<n;i++){
    if(pl==0){p[0]=i;pl++;continue;}
    if(ask(p[pl-1],i)==0){pl--;}
    else{p[pl]=i;pl++;}
  }
  for(i=0;i<n;i++){
    res[i]='0'+ask(p[pl-1],i);
  }
  printf("! %s\n",res);
  fflush(stdout);
  return 0;
}


Measured memory_bytes: 716
N=int(input())
S=[input() for _ in range(N)]
import collections

C = collections.Counter(S)
max_c=C.most_common()[0][1]

values, counts = zip(*C.most_common())
min_i=len(counts)
for i in range(len(counts)):
    if counts[i]<max_c:
        min_i = i
        break
ans = sorted(list(values)[:min_i])

print("\n".join(ans))

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

auto keta(ll n) {
    ll res;
    for(ll i = 0; i < 100; i++) {
        n = n / 10;

        if(n == 0) {
            res = i + 1;
            break;
        }
    }
    return res;
}

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll w=(b-a)%2;
    if(w == 0) {
        ll ans = (b-a)/2;
        cout << ans << endl;
    } else {
        ll p = n - a, q = b - 1;
        if(p >= q) {
            ll ans=a+(b-1-a)/2;
            cout << ans << endl;
        } else{
            ll ans =n-b+1+(b-a-1)/2;
            cout << ans << endl;
        }

    }
}


Measured memory_bytes: 256
import sys
N=int(input())
ans=1
numbers=input().split()
zero="0" in numbers
if zero:
  print(0)
  sys.exit()
for j in range(N):
  num=int(numbers[j])
  ans=ans*num
  if ans>1000000000000000000:
    print(-1)
    sys.exit()
print(ans)

Measured memory_bytes: 19420
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int out = 0;
	int r1 = 0;
	int r2 = 0;
	int r3 = 0;
	int t = 0;
	string k;
	int a = 0;
	cin >> a;
	for (int i = 1; i <= a; i++)
	{
		out = 0;
		t = 0;
		r1 = 0;
		r2 = 0;
		r3 = 0;
		while (out != 3)
		{
			cin >> k;
			if (k == "OUT")
			{
				out++;
			}
			if (k == "HIT")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					r3 = 1;
					r2 = 0;
				}
				if (r1 == 1)
				{
					r2 = 1;
					r1 = 0;
				}
				r1 = 1;
			}
			if (k == "HOMERUN")
			{
				if (r3 == 1)
				{
					t++;
					r3 = 0;
				}
				if (r2 == 1)
				{
					t++;
					r2 = 0;
				}
				if (r1 == 1)
				{
					t++;
					r1 = 0;
				}
				t++;

			}
		}
		cout << t << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3132
import math
def isPrime(n):
    if n < 2:
        return False
    if n == 2:
        return True
    if n % 2 == 0:
    # ２ではない偶数は素数ではない
        return False
  
  # nの半分まで計算する範囲を絞る
    m = math.floor(n / 2) + 1
    for p in range(3, m, 2): # 奇数だけ計算する
        if n % p == 0:
            return False
    return True
# def isPrime(n):
#     if n < 2:
#     # 2未満は素数でない
#         return False
#     if n == 2:
#     # 2は素数
#         return True
#     for p in range(2, n):
#         if n % p == 0:
#         # nまでの数で割り切れたら素数ではない
#             return False
#   # nまでの数で割り切れなかったら素数
#     return True
X = int(input())
ans = 0
for i in range(X, 10 ** 10):
    if isPrime(i):
        ans = i
        break

print(ans)

Measured memory_bytes: 9192
edges=[[]for i in range(4)]
for i in range(3):
  a,b=map(int,input().split())
  edges[a-1].append(b-1)
  edges[b-1].append(a-1)

for i in range(4):
  if len(edges[i])>=3:
    print('NO')
    exit()
print('YES')


Measured memory_bytes: 2940
import sys
input=sys.stdin.readline
sys.setrecursionlimit(10 ** 8)
from itertools import accumulate
from itertools import permutations
from itertools import combinations
from collections import defaultdict
from collections import Counter
import fractions
import math
from collections import deque
from bisect import bisect_left
from bisect import insort_left
import itertools
from heapq import heapify
from heapq import heappop
from heapq import heappush
import heapq
from copy import deepcopy
from decimal import Decimal
alf = list("abcdefghijklmnopqrstuvwxyz")
ALF = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ")
#import numpy as np
INF = float("inf")
#d = defaultdict(int)
#d = defaultdict(list)
x,y = map(int,input().split())
if y % 2 == 0 and y >= 2*x and y <= 4*x:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 10520
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		int n  = Integer.parseInt(br.readLine());
		
		Node[] node = new Node[n];
		
		for(int i=0;i<n;i++)
		{
			//先 new n个节点 都为根节点
			node[i] = new Node(-1);
		}
		
		for(int i=0;i<n;i++)
		{
			String[] str = br.readLine().split(" ");
			int id = Integer.parseInt(str[0]); //
			int k = Integer.parseInt(str[1]); //k个节点
			
			for(int j=0;j<k;j++)
			{
				int c = Integer.parseInt(str[j+2]);
				//添加子节点
				node[id].add(c);
				//若是-1就是根节点，其他
				node[c].parent=id;
			}
						
		}
		
		
		
		//输出
		for(int i=0;i<n;i++)
		{
			System.out.println("node "+i+": parent = "+node[i].parent+", depth = "+node[i].getDepth(node)+", "+node[i].isType()+", "+node[i].child);
		}
 		
	}
}



// 节点类
class Node{

    int parent;
    //有字节点
    ArrayList<Integer> child=new ArrayList<>();
    
    //构造方法 有参
    public Node(int parent)
    {
    	this.parent=parent;
    }
    
    //添加子节点
    public void add(int id)
    {
    	child.add(id);
    }
    
    //判断是什么类型的节点
    //1 根节点 ， parent=-1
    //2 叶节点，没有子节点
    //3 ohter internal 节点
    public String isType()
    {
    	if(parent==-1)
    	{
    		return "root";
    	}
    	else if(child.size()==0)
    	{
    		return "leaf";
    	}
    	else
    	{
    		return "internal node";
    	}
    }
    
    //获取深度，就是根节点到节点的路径长度
    public int getDepth(Node node[])
    {
    	//构造的时候，输入的参数 parent
    	int pID=parent;
    	int count=0;
    	while(pID!=-1)
    	{
    		//只要不是根节点，就递归获取父节点，计数+1
    		pID=node[pID].parent;
    		count++;
    	}
    	//返回深度
    	return count;
    }
}


Measured memory_bytes: 119232
#include <cstdio>
#include <algorithm>

int main(){
    int N = 0;
    int a[101] = {};
    scanf("%d", &N);
    for(int i=0; i < N; i++){
        scanf("%d", &(a[i]));
    }
    auto mm = std::minmax_element(a, a + N);
    printf("%d\n", *mm.second - *mm.first);
}

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

class DayOfWeek {
	static const int m_startw = 4;

	int m_month;
	int m_day;

public:
	DayOfWeek( int mon, int day ):
		m_month( mon-1 ),
		m_day( day-1 )
	{}

	int days() const {
		static const int mdays[12] = { 31,29,31,30,31,30,31,31,30,31,30,31 };

		int d = m_day;
		for( int i = 0; i < m_month; ++i ) {
			d += mdays[i];
		}

		return d;
	}

	string name() const {
		static const string names[] = {
			"Sunday",
			"Monday",
			"Tuesday",
			"Wednesday",
			"Thursday",
			"Friday",
			"Saturday"
		};

		return names[(days() + m_startw) % 7];
	}
};

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

	int m, d;
	while( cin >> m >> d ) {
		if( m == 0 ) { break; }

		cout << DayOfWeek( m, d ).name() << '\n';
	}
}



Measured memory_bytes: 3004
#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>;

struct UnionFind{
    vector<int>p,r;
    UnionFind(int n){
        p.resize(n,-1);
        r.resize(n,1);
    }
    int find(int x){
        if(p[x]==-1)return x;
        else return p[x]=find(p[x]);
    }
    void unite(int x, int y){
        x=find(x);
        y=find(y);
        if(x==y)return;
        if(r[x]>r[y])swap(x,y);
        if(r[x]==r[y])r[y]++;
        p[x]=y;
    }
    bool same(int x, int y){
        return find(x)==find(y);
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    UnionFind uf(n+m);
    rep(i,n){
        int k; cin>>k;
        rep(j,k){
            int l; cin>>l; l--;
            uf.unite(i,l+n);
        }
    }
    bool ok=true;
    rep(i,n){
        if(!uf.same(0,i)){
            ok=false;
        }
    }
    if(ok)puts("YES");
    else puts("NO");
}

Measured memory_bytes: 4692