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

using ll = long long;
#define rep(i, j) for(int i=0; i < (int)(j); i++)
#define repeat(i, j, k) for(int i = (j); i < (int)(k); i++)
#define all(v) v.begin(),v.end()

class ModInt {
  public:
    static const ll MOD = 1000000007LL;
    ll x;
    ModInt():x(0){};
    ModInt(ll x){
        while(x < 0) x += MOD;
        x %= MOD;
        this->x = x;
    }
    ModInt& operator += (const ModInt &l){ x += l.x; if( x >= MOD) x -= MOD; return *this; }
    ModInt& operator -= (const ModInt &l){ x -= l.x; if( x < 0 ) x += MOD; return *this; }
    ModInt& operator *= (const ModInt &l){ x = (x * l.x) % MOD; return *this; }
    ModInt operator +(const ModInt &l) const { return ModInt( x + l.x); }
    ModInt operator -(const ModInt &l) const { return ModInt( x - l.x); }
    ModInt operator *(const ModInt &l) const { return ModInt( x * l.x); }
};

// @warning rの部分はmodとってはいけない
ModInt pow(const ModInt &n, ll r){
    if(r == 0) return ModInt(1);
    ModInt ret = pow(n, r / 2);
    ret *= ret;
    if(r % 2 != 0) ret = ret * n;
    return ret;
}

// @waring nはMODと互いに素
ModInt inverse(const ModInt &n){
    static map<ll, ll> cache;
    if(cache.count(n.x)) return cache[n.x];
    auto res = pow(n, ModInt::MOD - 2);
    cache[n.x] = res.x;
    return res;
}

ModInt factorial(const ModInt &n){
    static map<ll, ll> cache;
    if(cache.count(n.x)) return cache[n.x];
    ModInt ret = 1;
    for(ll i = n.x; i>1; i--){
        ret *= i;
    }
    cache[n.x] = ret.x;
    return ret;
}

vector<int> generate_primes(int N) {
    vector<int> primes;
    vector<int> is_prime(N, true);
    repeat(i, 2, N) {
        if(is_prime[i]) {
            primes.push_back(i);
            for(int j = i * 2; j < N; j += i) is_prime[j] = false;
        }
    }
    return primes;
}

map<int, int> prime_factorization(int N) {
    map<int, int> res;
    auto primes = generate_primes(sqrt(N) + 10);
    for(int p : primes) {
        while(N % p == 0) {
            res[p] += 1;
            N /= p;
        }
    }
    if(N > 1) res[N] = 1;
    return res;
}

class Solver {
  public:
    bool solve() {
        int N, M; cin >> N >> M;

        auto factors = prime_factorization(M);

        ModInt ans = 1;
        vector<int> bs;
        for(auto p : factors) {
            int b = p.second;
            ans *= factorial(b + N - 1) * inverse(factorial(b) * factorial(N - 1));
        }
        cout << ans.x << endl;
        return 0;
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Solver s;
    s.solve();
    return 0;
}


Measured memory_bytes: 384
//@author :  |< U $ |-|
#include<cmath>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<deque>
#include<queue>
#include<algorithm>
#include<list>
#include<cstring>
#include<unordered_map>
#define ll long long
#define vi vector<long long>
#define pb push_back
#define pop pop_back
#define pi pair<long long ,long long>
#define vp vector<pair<long long,long long> >
#define mkp make_pair
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define jaldi ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define map map<long long,long long>
#define inm1(b)  memset(b,-1,sizeof(b))
#define in0(b) memset(b,0,sizeof(b))
#define ininf(b) memset(b,1000000001,sizeof(b))
#define MOD         1000000007
#define I 1000000000000000001
#define t(a) cout<<a<<" "<<endl
#define tt(a,b) cout<<a<<" "<<b<<endl
#define th(a,b,c) cout<<a<<" "<<b<<" "<<c<<endl
#define TakeInput freopen("input.txt", "r", stdin);freopen("output.txt", "w", stdout);
using namespace std;
ll gcd(ll a, ll b) {  if (a == 0)  return b; return gcd(b % a, a); }


int main(){
    jaldi
    #ifndef ONLINE_JUDGE
    TakeInput
    #endif
    
    ll i,j,k,n,m;
    cin>>n;

    ll a[n],maxi = 0 ;
    for(i=0;i<n;i++){
        cin>>a[i];
    }
    maxi = 0;
    ll count=0;

    for(i=0;i<n;i++){
        if(maxi>a[i]){
            count+=maxi-a[i];
        }
        else{
            maxi = a[i];
        }

    }
    cout<<count;



}


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

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

int main() {
  int n, m;
  cin >> n >> m;
  int ans = 0;
  if (n == 1) {
    ans += 300000;
  }
  if (n == 2) {
    ans += 200000;
  }
  if (n == 3) {
    ans += 100000;
  }
  if (m == 1) {
    ans += 300000;
  }
  if (m == 2) {
    ans += 200000;
  }
  if (m == 3) {
    ans += 100000;
  }
  if ((n==1) && (m==1)) {
    ans += 400000;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int n;
    static int k;
    static int[][] a;
    static int[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        a = new int[n+1][3];
        dp = new int[n+1][3];
        for (int i=0; i<n; i++) {
            for (int j=0; j<3; j++) {
                a[i][j] = sc.nextInt();
            }
        }

        for (int i=0; i<n; i++) {
            for (int j=0; j<3; j++) {
                for (int k=0; k<3; k++) {
                    if (j==k) continue;
                    //dp[i][j]は前回分 + a[i][k]　の最大値を今回分(dp[i+1][k])に格納する。
                    dp[i+1][k] = Math.max(dp[i+1][k], dp[i][j] + a[i][k]);
                }
            }
        }
        int ans = 0;
        for (int i=0; i<3; i++) {
            ans = Math.max(ans, dp[n][i]);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 99252
#include<iostream>
#include<cstdio>
#include<cstring>
typedef long long ll;
const int MAXN=100,P=1e9+7;

char s[2][MAXN];

int main()
{
	int i;
	scanf("%d",&i);
	scanf("%s%s",s[0],s[1]);
	int ans;
	for(i=0;i<strlen(s[0]);i++)
	{
		if(!i)
		{
			if(s[0][i]!=s[1][i]) ans=6,i++;
			else ans=3;
		}else
		{
			if(s[0][i]!=s[1][i]) 
			{
				if(s[0][i-1]!=s[1][i-1]) ans=((ll)ans*3)%P;
				else ans=((ll)ans*2)%P;
				i++;
			}
			else 
			{
				if(s[0][i-1]!=s[1][i-1]) ans*=1;
				else ans=((ll)ans*2)%P;
			}
		}
	}
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  int a,b,c,d,n;

  while(scanf("%d %d",&a,&b),a|b){
    n=b-a,c=n%1000,d=n%500;
    printf("%d %d %d\n",d/100,c/500,n/1000);
  }
  return 0;
}

Measured memory_bytes: 1028
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

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

		int ans = v[0];
		REP(i,1,v.size()) {
			v[i] += v[i-1];
			ans += v[i];
		}

		cout << ans << endl;
	}

	return 0;
}

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int a_d[100001];
int N;
vector<int> graph[100001];

void bfs1()
{
  queue<Pii> q;
  q.push(Pii(0, 0));

  while ( !q.empty() ) {
    Pii p = q.front(); q.pop();
    int n = p.fr, c = p.sc;
    
    if ( a_d[n] != INF ) continue;
    a_d[n] = c;

    Rep(i, graph[n].size()) {
      if ( graph[n][i] == N-1 ) continue;
      q.push(Pii(graph[n][i], c + 1));
    }
    
  }
  
}

bool bfs2()
{
  queue<Pii> q;
  bool used[100001] = {0};
  int cnt = 0;
  q.push(Pii(N-1, 0));

  while ( !q.empty() ) {
    Pii p = q.front(); q.pop();
    int n = p.fr, c = p.sc;

    if ( used[n] ) continue;
    used[n] = true;
    if ( c < a_d[n] ) cnt++;
    if ( cnt > (N - 2 + 1) / 2 ) return true;

    Rep(i, graph[n].size()) {
      if ( graph[n][i] == 0 ) continue;
      q.push(Pii(graph[n][i], c + 1));
    }
  }

  return false;
}

signed main()
{
  cin >> N;
  Rep(i, N-1) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    graph[a].pb(b);
    graph[b].pb(a);
  }

  fill_n(a_d, 100001, INF);
  bfs1();
  //cout << 'a' << endl;
  if ( bfs2() ) cout << "Snuke" << endl;
  else cout << "Fennec" << endl;
  
}


Measured memory_bytes: 7900
L,R=map(int,input().split())
M=2019
l,r,a=L%M,R%M,M
if l<r and R-L<672:
  for i in range(l,r):
    for j in range(i+1,r+1):
      a=min(a,i*j%M)
      if a<2: break
    if a<2: break
else: a=0
print(a)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) FOR(i, 0, (n))
#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define LAR(a, b) ((a)=max((a),(b)))
#define SML(a, b) ((a)=min((a),(b)))
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using pii = pair<int, int>;
using vpii = vector<pair<int, int>>;
template<typename T>
using pque = priority_queue<T, vector<T>, greater<T>>;
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define ALL(a) (a).begin(), (a).end()
#ifdef LOCAL_DEBUG
#define DEBUG(...) printf(__VA_ARGS__)
#else
#define DEBUG(...)
#endif

int main(){
	REP(i, 5){
		int a; scanf("%d", &a);
		if(a == 0) printf("%d\n", i+1);
	}
}


Measured memory_bytes: 3760
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
long long ans[1000010],h=0,i;
void dfs(long long s){
	if(s>3234566667){
		return ;
	}
	h++;
	ans[h]=s;
	long long t=s%10;
	if(t-1>=0){
		dfs(s*10+t-1);
	}
	if(t>=0){
		dfs(s*10+t);
	}
	if(t+1<=9){
		dfs(s*10+t+1);
	}
}
int main(){
	for(i=1;i<=9;i++){
		dfs(i);
	}
	sort(ans+1,ans+1+h);
	int k;
	scanf("%d",&k);
	printf("%lld\n",ans[k]);
	return 0;
} 

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

int x,y;

struct grid{
  char g[11][11];
  int count;
};

void DFS(grid& gr,char firstcell,char changecolor,int posx,int posy){

  //if(posx < 0 || posx >= x  || posy < 0 || posy >= y || gr.g[posx][posy] != firstcell){
  if(gr.g[posx][posy] != firstcell){
    return;
  }

  gr.g[posx][posy] = changecolor;

  DFS(gr,firstcell,changecolor,posx+1,posy);
  DFS(gr,firstcell,changecolor,posx-1,posy);
  DFS(gr,firstcell,changecolor,posx,posy+1);
  DFS(gr,firstcell,changecolor,posx,posy-1);
}

int main(){

  while(1){

    cin >> x >> y;

    if(x==0 && y==0){
      break;
    }

    grid start;

    for(int i=0; i<y; i++){
      for(int j=0; j<x; j++){
        cin >> start.g[j][i];
      }
    }

    char firstcell = start.g[0][0];

    bool flag = true;

    for(int i=0; i<y; i++){
      for(int j=0; j<x; j++){
        if(start.g[j][i]!=firstcell){
          flag = false;
          break;
        }
      }
      if(!flag){
        break;
      }
    }
    if(flag){
      cout << 0 << endl;
      continue;
    }

    start.count = 0;

    queue<grid> q;

    q.push(start);

    while(1){

      grid BeforeGrid = q.front();
      q.pop();

      BeforeGrid.count++;

      grid tmp = BeforeGrid;

      firstcell  = tmp.g[0][0];

      if(firstcell != 'R'){
          DFS(tmp,firstcell,'R',0,0);

          flag = true;
          for(int i=0; i<y; i++){
            for(int j=0; j<x; j++){
              if(tmp.g[j][i]!='R'){
                flag = false;
                break;
              }
            }
            if(!flag){
              break;
            }
          }
          if(flag){
            cout << tmp.count << endl;
            break;
          }

          q.push(tmp);
          tmp = BeforeGrid;
      }

      if(firstcell != 'G'){
          DFS(tmp,firstcell,'G',0,0);

          flag = true;
          for(int i=0; i<y; i++){
            for(int j=0; j<x; j++){
              if(tmp.g[j][i]!='G'){
                flag = false;
                break;
              }
            }
            if(!flag){
              break;
            }
          }
          if(flag){
            cout << tmp.count << endl;
            break;
          }

          q.push(tmp);
          tmp = BeforeGrid;
      }

      if(firstcell != 'B'){
          DFS(tmp,firstcell,'B',0,0);

          flag = true;
          for(int i=0; i<y; i++){
            for(int j=0; j<x; j++){
              if(tmp.g[j][i]!='B'){
                flag = false;
                break;
              }
            }
            if(!flag){
              break;
            }
          }
          if(flag){
            cout << tmp.count << endl;
            break;
          }

          q.push(tmp);
          tmp = BeforeGrid;
      }

    }






  }


    return 0;
}

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

int main(){
  while (true) {
    int H, W, n;
    char s;
    cin >> H >> W;
    if (H == 0 && W == 0) {
      break;
    }
    for (int i = 0; i < H; i++) {
      n = 0;
      for (int j = 0; j < W; j++) {
        if (i % 2 == 0) {
          if (n % 2 == 0) {
            s = '#';
          }
          else {
            s = '.';
          }
        }
        else {
          if (n % 2 == 1) {
            s = '#';
          }
          else {
            s = '.';
          }
        }
        if (j == W-1) {
          cout << s << endl;
        }
        else {
          cout << s;
        }
        n++;
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3088
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
#include<vector>
 
using namespace std;
 

int main(){
	int N,ans=0,a,count[11]={},b=0;
	cin >> N;
	for(int i=0; i<N; i++){
		cin >> a;
		if(a<3200)
		count[a/400]+=1;
		else
		b+=1;
	}
	for(int i=0; i<=7; i++){
		if(count[i]!=0)
		ans+=1;
	}
	if(ans==0)
	cout << '1' << ' ' << b << endl;
	else
	cout << ans << ' ' << ans+b << endl;

}



Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
using Graph = vector<vector<int>>;
typedef long long lint;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ldouble;
typedef vector<int> vec;
typedef vector<ll> lvec;
typedef vector<ull> ulvec;
typedef vector<double> dvec;
typedef vector<pair<int,int>> pvec;
typedef vector<pair<ll,ll>> plvec;
typedef vector<tuple<ll,ll,ll>> tvec;
typedef vector<string> svec;
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; }

int main(){
    int n;
    cin>>n;
    vec a(n);
    rep(i,n)cin>>a[i];
    set<int> st;
    int ans=1;
    st.insert(a[0]);
    for(int i=1;i<n;i++){
        if(*begin(st)>=a[i])ans++;
        st.insert(a[i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
string S;
vector<vector<int>> v(26);
int A[26] = {0},id[26] = {0};

ll merge_count(vector<ll> &a){
	int n = a.size();
	if(n<=1) return 0;
	ll cnt = 0;
	vector<ll> b(a.begin(),a.begin() + n/2);
	vector<ll> c(a.begin() + n/2, a.end());
	cnt += merge_count(b);
	cnt += merge_count(c);
	int ai = 0,bi = 0,ci = 0;
	while(ai<n){
		if(bi<b.size() && (ci == c.size() || b[bi] <= c[ci])){
			a[ai++] = b[bi++];
		}else{
			cnt += n/2 - bi;
			a[ai++] = c[ci++];
		}
	}
	return cnt;
}


int main(){
	cin >> S;
	string T = "";
	int N = S.size();
	for(int i=0;i<N;i++){
		int t = S[i]-'a';
		T = T + S[N-i-1];
		A[t]++;
		v[t].push_back(-1);
	}
	int count = 0;
	for(int i=0;i<26;i++){
		if(A[i]%2==1) count++;
	}
	if(count>=2){
		cout << -1 << endl;
		return 0;
	}
	vector<ll> L,R;
	int l = 0;
	for(int i=0;i<N;i++){
		int c = S[i]-'a';
		if(A[c]%2==1 && 2*id[c]+1==v[c].size()){
			L.push_back(N/2);
			id[c]++;
		}
		else{
			if(id[c]*2<v[c].size()){
				L.push_back(l);
				v[c][id[c]] = l;
				l++;
				id[c]++;
			}else{
				int t = v[c].size()-id[c]-1;
				L.push_back(N-v[c][t]-1);
				id[c]++;
			}
		}
	}
	l = 0;
	for(int i=0;i<26;i++) id[i] = 0;
	for(int i=0;i<N;i++){
		int c = T[i]-'a';
		if(A[c]%2==1&& 2*id[c]+1==v[c].size()){
			R.push_back(N/2);
			id[c]++;
		}
		else{
			if(id[c]*2<v[c].size()){
				R.push_back(l);
				v[c][id[c]] = l;
				l++;
				id[c]++;
			}else{
				int t = v[c].size()-id[c]-1;
				R.push_back(N-v[c][t]-1);
				id[c]++;
			}
		}
	}
/*	cout << S << " " << T << endl;
	for(int i=0;i<N;i++){
		cout << L[i] << (i!=N-1? " ":"\n");
	}
	for(int i=0;i<N;i++){
		cout << R[i] << (i!=N-1? " ":"\n");
	}
*/	cout << min(merge_count(L),merge_count(R)) << endl;
}

Measured memory_bytes: 7996
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <climits>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <complex>
#include <functional>
#include <utility>
#include <iterator>

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

#ifdef LOCAL
  #define dprintf(...) fprintf(stdout, __VA_ARGS__)
#else
  #define dprintf(...) 0
#endif

using namespace std;

typedef long long LL;
typedef unsigned long long ULL;
typedef unsigned int uint;

// join vector<int> to a string with delimiter
std::string join(const std::vector<int> &v, const std::string delim = "") {
  std::string result;
  for(unsigned int i = 0; i < v.size(); ++i) {
    result += std::to_string(v[i]);
    if(i != v.size() - 1) {
      result += delim;
    }
  }
  return result;
}

class Lamp {
  public:
    vector<int> *switches;
    int p;
};

vector<vector<int>> patterns;

void buildPatterns(vector<int> v, int count) {
  //string t = join(v, ", ");
  //cout << t << endl;
  if(count == 0) {
    patterns.push_back(v);
  }
  else {
    vector<int> v1 = v;
    vector<int> v2 = v;
    v1.push_back(1);
    buildPatterns(v1, count - 1);
    v2.push_back(0);
    buildPatterns(v2, count - 1);
  }
}

int main() {
  int n, m;
  cin >> n >> m;
  vector<Lamp*> lamps;
  REP(i, m) {
    int k;
    cin >> k;
    vector<int> *switches = new vector<int>;
    //vector<int> = switches(k);
    REP(j, k) {
      int s;
      cin >> s;
      switches->push_back(s);
    }
    Lamp *l = new Lamp();
    l->switches = switches;
    lamps.push_back(l);
  }

  REP(i, m) {
    int p;
    cin >> p;
    lamps[i]->p = p;
  }

  vector<int> v0;
  buildPatterns(v0, n);
  /*
  REP(i, patterns.size()) {
    string t = join(patterns[i], ", ");
    cout << t << '\n';
  }
  */

  int ans = 0;
  REP(i, patterns.size()) {
    bool ok = true;
    REP(j, lamps.size()) {
      int sum = 0;
      Lamp *lamp = lamps[j];
      REP(k, lamp->switches->size()) {
        int sno = lamp->switches->at(k);
        sum += patterns[i][sno - 1];
      }
      if(sum % 2 != lamps[j]->p) {
        ok = false;
      }
    }
    if(ok) {
      ans++;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

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

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		double distance1 = 0;
		double distance2 = 0;
		double distance3 = 0;
		double distance4 = 0;

		int n = Integer.parseInt(br.readLine());
		String[] x = null;
		String[] y = null;
		 x = br.readLine().split(" ");
		 y = br.readLine().split(" ");

		for (int i = 0; i < n; i++) {
			double xi = Double.parseDouble(x[i]);
			double yi = Double.parseDouble(y[i]);
			distance1 += Math.abs(xi - yi);
			distance2 += Math.pow(xi - yi, 2.0);
			distance3 += Math.pow(Math.abs(xi - yi), 3.0);
			double work = Math.abs(xi - yi);
			if (work > distance4) {
				distance4 = work;
			}
		}

		System.out.println(distance1);
		System.out.println(Math.sqrt(distance2));
		System.out.println(Math.cbrt(distance3));
		System.out.println(distance4);
	}
}

Measured memory_bytes: 24608
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <set>

using namespace std;

int main(){
    
    int n, d;
    set<int> se;
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        
        cin >> d;
        se.insert(d);
    }
    
    cout << se.size() << endl;
    
    return 0;
    
}

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

int main(){
	int n;
	while(cin>>n,n){
		int l=0,d=0,m=0,lo=0,du=0,mo=0;
		
		for(int i=0;i<n;i++){
			int a,b,c;
			scanf("%d:%d%d",&a,&b,&c);
			if(a>=0&&a<11)a+=24;
			if(a>=11&&a<15){
				l++;
				if(c<b)c+=60;
				if(c-b<=8)lo++;
				}
			else if(a>=18&&a<21){
				d++;
				if(c<b)c+=60;
				if(c-b<=8)du++;
				}
			else if(a>=21&&a<26){
				m++;
				if(c<b)c+=60;
				if(c-b<=8)mo++;
				}		
			}
			
			cout<<"lunch ";
			if(l==0)cout<<"no guest"<<endl;
			else cout<<lo*100/l<<endl;
			cout<<"dinner ";
			if(d==0)cout<<"no guest"<<endl;
			else cout<<du*100/d<<endl;
			cout<<"midnight ";
			if(m==0)cout<<"no guest"<<endl;
			else cout<<mo*100/m<<endl;
		}
		return 0;
	}

Measured memory_bytes: 3124
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int K = sc.nextInt();
		long[] H = new long[N];
		for(int i = 0;i < N;i++){
			H[i] = sc.nextLong();
		}
		sc.close();
		Arrays.sort(H);
		long cnt = 0;
		for(int i = 0;i < N-K;i++){
			cnt += H[i];
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 70572
#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
/*
    s.find_by_order(k) ---> returns iterator to the element at index(from 0) k
    s.order_of_key(val) ---> number of elements that are strictly smaller than the given value
*/
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long int> vl;
typedef vector<vector<int>> vvi;
typedef vector<vector<long long int>> vvl;
typedef pair<int, int> pii;
typedef pair<long long int, long long int> pll;
typedef vector<pair<int, int>> vii;
typedef vector<pair<long long int, long long int>> vll;
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define test() long long int tc; cin >> tc; cin.ignore(); while(tc--) 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define MOD 1000000007
#define SMOD 998244353
#define pq priority_queue
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sp " "
#define inp(a) ll a;cin>>a;cin.ignore()
#define inps(a,b) ll a,b;cin>>a>>b;cin.ignore()
#define out(a) cout<<SP(20)<<a<<'\n'
#define outs(a,b) cout<<SP(20)<<a<<" "<<b<<'\n'
#define ins insert
#define er erase
#define lb lower_bound
#define ub upper_bound
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define inpa(a,n) ll a[n]; for(int i=0; i<n; i++){cin>>a[i];}
#define inpv(a,n) vl a; for(int i=0; i<n; i++){inp(x);a.pb(x);}
#define outa(a,n) for(int i=0;i<n;i++){cout<<a[i]<<" ";}cout<<'\n';
#define outv(v) for(auto i:v){cout<<i<<" ";}cout<<'\n';
set<char> vow = {'a','e','i','o','u','A','E','I','O','U'};
ll xpow(ll n, ll m){if(m==0){return 1;}else{ll x = xpow(n, m/2);if(m&1){return x*x*n;}else{return x*x;}}}
ll xmod(ll a, ll m){return (((a%m)+m)%m);}
ll xmodpow(ll n, ll m, ll y){if(m==0){return 1;}else{ll x = xmodpow(n, m/2, y);if(m&1){return xmod((xmod((xmod(x,y)*xmod(x,y)),y)*xmod(n,y)),y);}else{return xmod((xmod(x,y)*xmod(x,y)),y);}}}

int main() {
	fast();
 
    /*NA – JEONG – MO – SA – JI – MI – DA – CHAE – TZU*/
    
    ld a, b, c;
    cin >> a >> b >> c;
    ll right = c-a-b;
    ll left = 2*sqrtl(1.0*a*b);
    if(left<right){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

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

using namespace std;

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                        \
	sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
	{
sim > struct rge
{
	c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug
{
#ifdef LOCAL
	~debug()
	{
		cerr << endl;
	}
	eni(!=) cerr << boolalpha << i;
	ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d)
{
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
#else
	sim dor(const c &)
	{
		ris;
	}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define forn(i, n) for (ll i = 0; i < int(n); i++)
#define rfor(n, i) for (ll i = (n - 1); i >= 0; --i)
#define all(V) V.begin(), V.end()
#define rall(V) V.rbegin(), V.rend()
#define len(V) (int)V.size()
#define ll long long
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define M_PI 3.14159265358979323846
#define EPS 1e-7

void solve()
{
	int n; cin >> n;
	set<ll> s;
	for (int i = 1; i <= n; ++i)
	{
		for(int j = 2; j <= 20; ++j)
		{
			if (pow(i, j) > n) break;
			s.insert(pow(i, j));
		}
	}
	ll res;
	for (auto x: s)
	{
		if (x <= n) res = x;
	}
	cout << res;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}

Measured memory_bytes: 4052
#include<bits/stdc++.h>
 
using namespace std;
using S = set<long long>;
using D = deque<long long>; //pop_back pop_front push_back push_front front back clear empty
using L = vector<long long>;
using M = map<int,long long>;  //erase  (でキーごと削除) 追加削除検索O(log(N))
using A = vector<vector<long long>>;
using Q = priority_queue<long long>; //erase  (でキーごと削除)
using U = unordered_map<int,long long>; //map  (との違いはkeyの順番を保持していない)

#define sorted(vector) sort(vector.begin(),vector.end()) //O(nlongn)
#define sortedreverce(vector) sort(vector.rbegin(),vector.rend()) //O(nlongn)
#define vmin(vector) *min_element(vector.begin(),vector.end()) //O(N)
#define vmax(vector) *max_element(vector.begin(),vector.end()) //O(N)
#define vsum(vector) accumulate(vector.begin(),vector.end(),0) //O(N)
#define vdel(vector,a) vector.erase(vector.begin()+a)
#define vcount(vector,a) count(vector.begin(), vector.end(),a) //O(N)
#define bisect_left(vector,a) (lower_bound(vector.begin(),vector.end(),a)-vector.begin())
#define bisect_right(vector,a) (upper_bound(vector.begin(),vector.end(),a)-vector.begin())
#define vfind(vector,a) find(vector.begin(), vector.end(), a) != vector.end() //遅いからあんまり使うな
#define inf 1000000000000000000+10

template <typename T>
void print(T a){for (auto b:a){cout<<b<<" ";};cout<<endl;}
template <>
void print(unsigned long a){cout<<a<<endl;}
template <>
void print(char a){cout<<a<<endl;}
template <>
void print(bool a){cout<<a<<endl;}
template <>
void print(long long a){cout<<a<<endl;}
template <>
void print(A a){for (auto b:a){for (auto c:b){cout<<c<<" ";}cout<<endl;};cout<<endl;}
template <>
void print(string a){cout<<a<<endl;}


//存在確認はmap!!!!!!!!!!!!!か配列に埋め込んでcontinueで回避
//__gcd(a,b)はコンパイラがGCC時のみ
//printf("%.16f", ans); 誤差落ち対応君

int main(){
    long long n,m;
    cin>>n;
    print(n*(n-1)/2);
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args){
    int Children;
    int Candies = 0;
    
    Scanner scanner = new Scanner(System.in);
    Children = scanner.nextInt();
    
    if(Children >= 1 && Children <= 100){
      for(int i = 1; i <= Children; i++){
        Candies = Candies + i;
      }
      System.out.println(Candies);
    }
  }
}

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

int main() {
	int n; scanf("%d", &n);
	rep(i, n) {
		string in = "000000000000000000000000000000";
		rep(j, 30) {
			char c; cin >> c;
			in[j] = c;
		}
		unordered_map<string, int>mp;
		queue<string>que;
		mp[in] = 1;
		que.push(in);
		while (!que.empty()) {
			string u = que.front(); que.pop();
			bool flag = true;
			rep(j, 9) {
				if (u[0] != u[j]) {
					flag = false;
					break;
				}
			}
			if (flag) {
				for (int j = 9; j < 19; j += 3)rep(k, 3) {
					if (u[j] != u[j + k]) {
						flag = false;
						break;
					}
				}
			}
			if (flag) {
				rep(j, 9) {
					if (u[21] != u[21 + j]) {
						flag = false;
						break;
					}
				}
			}
			if (flag) {
				printf("%d\n", mp[u] - 1);
				break;
			}
			if (mp[u] > 8)continue;
			string v;
			v = u;
			swap(v[0], v[23]); swap(v[3], v[26]); swap(v[6], v[29]); swap(v[9], v[20]); swap(v[15], v[17]);
			if (!mp[v]) {
				mp[v] = mp[u] + 1;
				que.push(v);
			}
			v = u;
			swap(v[2], v[21]); swap(v[5], v[24]); swap(v[8], v[27]); swap(v[11], v[18]); swap(v[12], v[14]);
			if (!mp[v]) {
				mp[v] = mp[u] + 1;
				que.push(v);
			}
			v = u;
			swap(v[0], v[27]); swap(v[1], v[28]); swap(v[2], v[29]); swap(v[14], v[15]); swap(v[18], v[20]);
			if (!mp[v]) {
				mp[v] = mp[u] + 1;
				que.push(v);
			}
			v = u;
			swap(v[6], v[21]); swap(v[7], v[22]); swap(v[8], v[23]); swap(v[12], v[17]); swap(v[9], v[11]);
			if (!mp[v]) {
				mp[v] = mp[u] + 1;
				que.push(v);
			}
		}
	}
}

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

int main()
{
  string table = "abcdefghijklmnopqrstuvwxyz";
  int a[20]={0};
  long long n;
  
  cin >> n;
  int i=0;
  n--;
  while (n >= 26) {
  		a[i]=n%26;
        n = n/26-1;
    	i++;
    }
  a[i]=n%26;
  i++;
  for(int j=i-1;j>=0;j--)
      cout << table[a[j]];
  cout << endl;
}

Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pii pair<int,int>
#define pll pair<lli, lli>
#define vi  vector<int>
#define vii vector<pair<int,int>>
#define vll vector<lli>
#define pb  push_back
#define mpr  make_pair
#define ss  second
#define ff  first
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define all(x) x.begin(),x.end()
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define testcase() int tc;cin>>tc;while(tc--)
#define clean(x) memset(x,0,sizeof(x))
const lli maxn = 1e5+9;
vector<lli> catlan(int n) {
    vector<lli> dp(n + 1, 0);
    dp[0] = 1;
    dp[1] = 1;
    for (int i = 2; i <= n; i ++) {
        for (int j = 0; j < i; ++ j) {
            dp[i] += dp[j] * dp[i - j - 1];
        }
    }
    return dp;
}
lli b_ex(lli n,lli a){lli res=1;while(n){if(n%2==1)res*=a;n>>=1;a=a*a;}return res;}
lli ncr(lli n,lli k){lli ans=1;if(k>n-k)k=n-k;for(lli i=1;i<=k;i++){ans*=(n-i+1),ans=ans/i;}return ans;}
lli power(lli a , lli n){lli ans = 1;while(n){if(n % 2)ans = (ans * a) % mod;n /= 2;a = (a * a) % mod;}return ans;}
lli set_bits(lli n)
{
    int c=0;
    if(n==0)return 0;
    while(n)
    {
        if((n&1)==1)
        {
           cout<<c<<" ";
        }
        c++;
        n=n>>1;
    }
    return c;
}
lli lcm(lli a,lli b)
{
    lli ans=(a*b)/(__gcd(a,b));
    return ans;
}
///------------------ALWAYS lli-----TEMP TSF99--------------------------------------------------------------------------------------///

void solve()
{
    string a;cin>>a;
    int n =a.size();
    int c=0,d=0;

    for(int i=0;i<n;i++)
    {
        if(a[i]=='A')
        {
            c=i;break;
        }

    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]=='Z')
        {
            d=i;break;
        }
    }
    cout<<d-c+1<<endl;

}
int main()
{
    FAST;
    //int tc=1;cin>>tc;while(tc--)solve();
    solve();
}



Measured memory_bytes: 3796
#include <bits/stdc++.h>
using namespace std;
const int IINF = INT_MAX;
const int MAX_N = int(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)

int main() {
    int n, h[MAX_N], dp[MAX_N];
    cin >> n;
    REP(i,n) cin >> h[i];
    fill(dp,dp+n+1,IINF);
    dp[0] = 0;
    REP(i,n-1){
        dp[i+1] = min(dp[i+1],dp[i]+abs(h[i+1]-h[i]));
        if(i<n-2)dp[i+2] = min(dp[i+2],dp[i]+abs(h[i+2]-h[i]));
    }
    cout << dp[n-1] << endl;
    return 0;
}


Measured memory_bytes: 1024
# gets.to_i
# gets.split.map(&:to_i)
# N.times.map{gets.to_i}
# N.times.map{gets.split.map(&:to_i)}
# 

N,M=gets.split.map(&:to_i)
ans=Array.new(N,-1)
M.times do 
    s,c=gets.split.map(&:to_i)
    s-=1
    if ans[s]!=-1 && ans[s]!=c
        puts -1
        exit
    end
    if N!=1 && s==0 && c==0
        puts -1
        exit
    end
    ans[s]=c
end
ans.each_with_index do |n,i|
    if i==0
        if n==-1
            if N==1
                print 0
            else
                print 1
            end
        else
            print n
        end
    elsif n==-1
        print 0
    else
        print n
    end
end
puts

Measured memory_bytes: 1788
N, K, Q = list(map(int, input().split()))

A = []
for i in range(Q):
    A.append(int(input()))

sc = [0] * N

for i in range(Q):
    sc[int(A[i]-1)] += 1

for i in range(N):
    if K - Q + sc[i] > 0:
        print('Yes')
    else:
        print('No')

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

int main(){

	string source,s;
	int counter = 0;

	cin >> source;
	transform(source.begin(),source.end(),source.begin(),::toupper);

	while(1){
		cin >> s;
		if(s == "END_OF_TEXT") break;
		transform(s.begin(),s.end(),s.begin(),::toupper);

		//cout << s + " " << source << endl;

		if(s == source){
			counter++;
			//cout << "Yes " << counter << endl;
		}
	}

	cout << counter << endl;

	return 0;
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n;
  cin >> n;
  ll ans = 0;
  for(int i = 1; i < n; i++){
    ll cnt = n/i;
    if(cnt * i == n) cnt --;
    ans += cnt;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3644
n, m = map(int, input().split())
ab = [map(int, input().split()) for _ in range(m)]

near = [set([]) for _ in range(n)]
for a, b in ab:
    near[a - 1].add(b - 1)
    near[b - 1].add(a - 1)

for i in near[0]:
    if i in near[n - 1]:
        print('POSSIBLE')
        break
else:
    print('IMPOSSIBLE')


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

int main()
{
    string s;
    int ans;
   cin>>s;
   if(s=="SUN")
    ans=7;
    else if(s=="MON")
        ans=6;
    else if(s=="TUE")
        ans=5;
    else if(s=="WED")
        ans=4;

    else if(s=="THU")
        ans=3;
    else if(s=="FRI")
        ans=2;
    else if(s=="SAT")
        ans=1;
    cout<<ans<<'\n';
}



Measured memory_bytes: 256
N = int(input())
list_an = input().split()
list_an_int = [int(s) for s in list_an]

list_an_int.sort()
list_an_int.reverse()

Alice_counter = 0
Bob_counter = 0

counter = 0
for i in range(N):
    if counter % 2 == 0:
        Alice_counter += list_an_int[i]
    else:
        Bob_counter += list_an_int[i]
    counter += 1
print(Alice_counter - Bob_counter)

Measured memory_bytes: 3064
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() {
            var t = ReadLine();
            if (t.Trim().Length == 0) return new List<int>();
            return new List<int>(t.Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var ND = Sarray();
            var N = ND[0];
            var D = ND[1]* ND[1];
            var ans = 0;
            for(var i=0;i<N;i++)
            {
                var XY = Sarray();
                if (XY[0] * XY[0] + XY[1] * XY[1] <= D) ans++;
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 22932
#include<stdio.h>
int main()
{
	int n,i,j,k,t;
	while(~scanf("%d",&n))
	{
	    int cnt=0;
		if(n>36)
		{
			printf("0\n");
			continue;
		}
		for(i=0;i<=9;i++)
			for(j=0;j<=9;j++)
				for(k=0;k<=9;k++)
					for(t=0;t<=9;t++)
						if(i+j+k+t==n)
							cnt++;
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 1036
coins = [500, 100, 50, 10, 5, 1]
if __name__ == '__main__':
    while True:
        p = int(input())
        if p == 0:
            break
        ch = 1000 - p

        count = 0
        for coin in coins:
            n = ch // coin
            ch -= coin * n
            count += n
        
        print(count)

Measured memory_bytes: 7648
#include<iostream>
#include<cstdio>
#include<queue>
#include<math.h>
#include<vector>
#include<algorithm>
#include<numeric>
#include<map>
using namespace std;

int main(){
    priority_queue<int> pque;
    
    int N,M,j=0,sum=0;
    pair<int,int> p[100010];
    cin>>N>>M;
    for(int i=0;i<N;++i){
        cin>>p[i].first>>p[i].second;
    }
    sort(p,p+N);

    for(int m=1;m<=M;m++){
        pque.push(0);
        while(p[j].first==m){
            pque.push(p[j].second);
            ++j;
        }
        sum+=pque.top();
        pque.pop();
    }
    cout<<sum<<endl;
    return 0;
}

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

int main() {
    int count = 0;
    string str;
    cin >> str;

    if (str[0] == 'o')
        count++;
    if (str[1] == 'o')
        count++;
    if (str[2] == 'o')
        count++;

    cout << 700 + (100 * count) << endl;

    return 0;
}

Measured memory_bytes: 256
import numpy as np

n, k = map(int, input().split())

d = [0] * k
A = [0] * k

for i in range(k):
    d[i] = int(input())
    A[i] = [0] * d[i]
    A[i] = list(map(int, input().split()))

list = []
for i in range(k):
    for j in range(d[i]):
        list.append(A[i][j])

count = 0
for i in range(1, n+1):
    if not i in list:
        count += 1

print(count)

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

int count[50];

int main() {
	int n, m;
	cin >> n >> m;
    
	for (int i = 0; i < n; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int a;
			cin >> a;
			count[a - 1]++;
		}
	}

	int ans = 0;
	for (int i = 0; i < m; i++) {
		if (count[i] == n) ans++;
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define SZ(x) ((int)(x.size()))
#define FOR(i,s,n) for (ll i = (s); (i) < (n); ++i)
#define FORD(i,s,l) for (ll i = (s); (i) >= l; --i)
#define F first
#define S second
#define TC int __tc; cin >> __tc; FOR(case_num,1,__tc+1)
#define TEST(x,i) ((x)&(1ll<<(i)))
#define SET(x,i) ((x)|(1ll<<(i)))
#define FLIP(x,i) ((x)^(1ll<<(i)))
#define CLEAR(x,i) ((x)&~(1ll<<(i)))

const double pi = 4 * atan(1);
using namespace std;
typedef long long ll;

const ll MOD = 1000000007;
const int MAXN = 200005;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	ll s = 0;
	int n;
	cin >> n;
	
	ll last = 0;
	FOR(i,0,n) {
		ll x;
		cin >> x;
		s+=max(last-x,0LL);
		last=max(last,x);
	}
	cout << s << "\n";

}


Measured memory_bytes: 3648
class Node

  attr_accessor :id, :left_child, :right_sibling, :parent

  def initialize(id)
    @id= id
    @parent = -1
    @children = []
  end

  def get_depth
    depth = 0
    u = id
    until $tree[u].parent == -1 do
      depth += 1
      u = $tree[u].parent
    end
    depth
  end

  def get_height
    leaves = self.get_leaves
    leaf_max_depth = leaves.map{|i|$tree[i].get_depth}.max
    leaf_max_depth - $tree[self.id].get_depth
  end

  def get_leaves
    return [self.id] if self.get_children.empty?
    children = get_children
    leaves = children.map do |child|
      $tree[child].get_leaves
    end
    leaves.flatten
  end

  def get_degree
    get_children.size
  end

  def get_children
    if left_child.nil?
      []
    else
      u = left_child
      children = [u]
      until $tree[u].right_sibling == nil do
        u = $tree[u].right_sibling
        children << u
      end
      children
    end
  end

  def get_sibling
    return -1 if parent == -1
    sibling = $tree[parent].get_children - [self.id]
    if sibling.empty?
      -1
    else
      sibling[0]
    end
  end

  def get_type
    if parent == -1
      'root'
    elsif get_children == []
      'leaf'
    else
      'internal node'
    end
  end
end

n = gets.to_i

$tree = {}

n.times do
  input = gets.split.map(&:to_i)
  id = input[0]
  left_child = input[1]
  right_child = input[2]

  children = [left_child, right_child].reject {|i| i == -1}
  children_count = children.size
  $tree[id] ||= Node.new(id)
  node = $tree[id]

  if children_count == 0
    node.left_child = nil
  else
    node.left_child = children[0]
    children.push(nil).each_cons(2) do |a, b|
      $tree[a] ||= Node.new(a)
      $tree[a].parent = id
      $tree[a].right_sibling = b if b
    end
  end
end

for i in 0..n - 1 do
  node = $tree[i]
  puts "node #{node.id}: parent = #{node.parent}, sibling = #{node.get_sibling}, degree = #{node.get_degree}, depth = #{node.get_depth}, height = #{node.get_height}, #{node.get_type}"
end




Measured memory_bytes: 6896
n,m=map(int,input().split())
s=[[]for i in range(n)]
for i in range(m):
    a,b=map(int,input().split())
    s[a-1].append(b-1)
    s[b-1].append(a-1)
c=0
k=[]
p=[[0]]
for i in range(m):
    k=[]
    for j in range(len(p[:])):
        for h in range(len(s[p[j][-1]])):
            t=s[p[j][-1]]
            if not t[h] in p[j]:
                k.append(p[j]+[t[h]])
                if len(k[-1])==n:
                    c+=1
                    k.pop(-1)
    else:
        p=k[:]
print(c)

Measured memory_bytes: 3956
#include<iostream>
#include<cstdlib>
#include<cstdio>
template<int BUFSIZE>
struct ans_buf {
  char buf[BUFSIZE];
  int i;
  ans_buf(): i(0) {}
  void putZ(unsigned int v, char delim='\n') {
    unsigned int k = 1;
    while(k <= v/10) k*=10;
    for(; k>0; v%=k, k/=10) buf[i++] = (v/k)+'0';
    buf[i++] = delim;
  }
  void out() { std::fwrite(buf, 1, i, stdout); }
};
char inbuf[1<<18];
unsigned int getZ() {
  unsigned int v = 0; int c;
  while((c = getchar_unlocked()) >= '0') v=v*10+c-'0';
  return v;
}

int const MAXN = 3e5;
int const MAXA = 6.4e5;
int N, m[MAXN], d[MAXN+1];

int main() {
  std::setbuf(stdin, inbuf);
  N = getZ();
 // std::fill_n(m, N, 0);
  for(int i = 0; i < N; ++i) ++m[getZ()-1];
  //std::fill_n(d, N+1, 0);
  for(int i = 0; i < N; ++i) ++d[m[i]];
 
  ans_buf<MAXA> buf;
  int sum_D = 0, sum_iD = N, k = 1;
  for(int ans = N; ans >= 1; --ans) {
    sum_D += d[ans];
    sum_iD -= d[ans]*ans;
    int next_k = sum_iD/ans + sum_D + 1;
    for(int i = k; i < next_k; ++i) buf.putZ(ans);
    k = next_k;
  }
  while(k <= N) { buf.putZ(0); ++k; }
  buf.out();
  return 0;
}


Measured memory_bytes: 2688
from collections import Counter
N = int(input())
D = list(map(int, input().split()))
M = int(input())
T = list(map(int, input().split()))

Dc = Counter(D)
Tc = Counter(T)

if (N < M):
    print('NO')
    exit()

for i, c in Tc.items():
    if (Dc[i] < c):
        print('NO')
        exit()
    else:
        continue

print('YES')


Measured memory_bytes: 169672
#include <stdio.h>

int main(void) {
	int a,b,c,tmp;
	scanf("%d %d %d",&a,&b,&c);
	if(a>b)tmp=a, a=b, b=tmp;
	if(b>c)tmp=b, b=c, c=tmp;
	if(a>b)tmp=a, a=b, b=tmp;
	printf("%d %d %d\n",a,b,c);
	return 0;
}



Measured memory_bytes: 2100
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
#include <algorithm>
#include <assert.h>
#include <bitset>
#include <cfloat>
#include <complex>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits.h>
#include <list>
#include <map>
#include <math.h>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<=n;i++)
#define int long long
#define ll long long
#define eps LDBL_EPSILON
#define mod (int)1000000007
#define DBLINF (DBL_MAX)/10
#define P pair<int,int>
#define prique(T) priority_queue<T,vector<T>,greater<T>>
#define all(V) V.begin(),V.end()
#ifdef int
constexpr int INF = LLONG_MAX / 10;
#else
constexpr int INF = INT_MAX / 10;
#endif
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
using namespace std;
inline int gcd(int a, int b) {
	while (b) {
		int c = a;
		a = b; b = c % b;
	}
	return a;
}
inline int lcm(int a, int b) {
	return a / gcd(a, b) * b;
}
bool isprime(int n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
int mypow(int a, int b) {
	if (!b)return 1;
	if (b & 1)return mypow(a, b - 1) * a;
	int memo = mypow(a, b >> 1);
	return memo * memo;
}
int modpow(int a, int b, int m = mod) {
	if (!b)return 1;
	if (b & 1)return modpow(a, b - 1, m) * a % m;
	int memo = modpow(a, b / 2, m);
	return memo * memo % m;
}
int n, a, b, cnt[100010], parent[100010];
vector<int> vec[100010];
bool used[100010];
queue<int> leaf;
void dfs(int node) {
	used[node] = true;
	bool isparent = false;
	for (int i : vec[node]) {
		if (!used[i]) {
			isparent = true;
			parent[i] = node;
			dfs(i);
		}
	}
	if (!isparent) {
		leaf.push(node);
	}
}
signed main() {
	cin >> n;
	if (n % 2) {
		puts("First");
		return 0;
	}
	rep(i, n - 1) {
		cin >> a >> b;
		vec[a].push_back(b);
		vec[b].push_back(a);
		cnt[a]++; cnt[b]++;
	}
	dfs(1);
	fill(used + 1, used + n + 1, false);
	while (!leaf.empty()) {
		int node = leaf.front();
		leaf.pop();
		if (node == 1 || used[parent[node]]) {
			puts("First");
			return 0;
		}
		used[node] = true;
		used[parent[node]] = true;
		if (parent[node] != 1 && !used[parent[parent[node]]]) {
			cnt[parent[parent[node]]]--;
			if (cnt[parent[parent[node]]] == 1) {
				leaf.push(parent[parent[node]]);
			}
		}
	}
	REP(i, n) {
		if (!used[i]) {
			puts("First");
			return 0;
		}
	}
	puts("Second");
	return 0;
}

Measured memory_bytes: 8448
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#define int long long
#define ll getchar();getchar();return 0;
using namespace std;
bool prime(int n) {
	int cnt = 0;
	for (int i = 1; i <= sqrt(n); i++) {
		if (n%i == 0)cnt++;
	}
	if (cnt != 1)return false;
	else return n != 1;
}
int gcd(int x, int y) {
	int ans;
	for (int i = (min(x, y)); i >= 1; i--) {
		if (x%i == 0 && y%i == 0) {
			ans = i;
			break;
		}
	}
	return ans;
}
int yakusuunowa(int n) {
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		if (n%i == 0)ans += i;
	}
	return ans;
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int ketanowa(int n) {
	int cnt = 0, sum = 0;
	for (int i = 10; i <= n * 10; i *= 10) {
		if (i == 10)cnt += n % i;
		else sum += (n%i - n % (i / 10)) / (i / 10);
	}
	return cnt + sum;
}
int a[114514];
signed main() {
	int n,cnta=0,cntb=0;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < n; i++) {
		if (a[i] % 4 == 0)cnta++;
		else if (a[i] % 2 == 0)cntb++;
	}
	if (cnta*2>=n-1||cntb - 1 + cnta * 2 >= n - 1)puts("Yes");
	else puts("No");
	ll
}

Measured memory_bytes: 1024