akhauriyash/Code-Regression huggingface dataset:
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, H, W, L, R;
vector<long long int>box;
vector<vector<int>>edge;
vector<long long int>up;
vector<bool>flag;
bool can = true;

long long int Search(int num) {
	if (up[num] != -1) {
		return up[num];
	}
	if (edge[num].size() == 1) {
		up[num] = box[num];
		return up[num];
	}
	flag[num] = false;
	long long int sum = 0;
	long long int ma = 0;
	for (auto i : edge[num]) {
		if (flag[i]) {
			long long int fig = Search(i);
			sum += fig;
			ma = max(ma, fig);
		}
	}
	R = sum;
	L = max((sum + 1) / 2, ma);
	if (L > box[num] || R < box[num]) {
		can = false;
	}
	up[num] = box[num] * 2 - sum;
	if (up[num] < 0) {
		can = false;
	}
	return up[num];
}

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

	cin >> N;
	box.resize(N + 1);
	edge.resize(N + 1);
	up.resize(N + 1,-1);
	flag.resize(N + 1, true);
	for (int i = 1; i <= N; i++) {
		cin >> box[i];
	}
	for (int i = 0; i < N - 1; i++) {
		cin >> L >> R;
		edge[L].push_back(R);
		edge[R].push_back(L);
	}
	if (N == 2) {
		if (box[1] == box[2]) {
			cout << "YES\n";
		}
		else {
			cout << "NO\n";
		}
		return 0;
	}
	for (int i = 1; i <= N; i++) {
		if (edge[i].size() != 1) {
			if (!Search(i) && can) {
				cout << "YES\n";
				return 0;
			}
			cout << "NO\n";
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 13952
N=int(input())
arr=[0]*4

ac=0
wa=0
tle=0
re=0

for i in range(N):
    a=input()
    if a=="AC":
        ac+=1
    elif a=="WA":
        wa+=1
    elif a=="TLE":
        tle+=1
    elif a=="RE":
        re+=1

print("AC x "+str(ac))
print("WA x "+str(wa))
print("TLE x "+str(tle))
print("RE x "+str(re))


Measured memory_bytes: 9152
#include<stdio.h>
int main()
{
    char s[10];
    scanf("%s",&s);
    if(s[0]=='A' && s[1]=='B' && s[2]=='C')
    {
        printf("ARC\n");
    }
    else
    {
        printf("ABC\n");
    }
    return 0;
}


Measured memory_bytes: 1628
# coding: utf-8
# Your code here!
O, E = list(input()), list(input())
mrg = []

for i in range(len(E)):
    mrg.append(O[i])
    mrg.append(E[i])
    
if len(O) > len(E):
    mrg.append(O[-1])
    
for j in range(len(mrg)):
    print(mrg[j], end = "")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0;}

int n;
int ans = 0;
void dfs(ll cur,int a,int b,int c) {
    if(cur > n) return;
    if(a && b && c) ans++;
    dfs(cur*10+7,1,b,c);
    dfs(cur*10+5,a,1,c);
    dfs(cur*10+3,a,b,1);
    return;
}

int main() {
    cin >> n;
    vector<int>a;
    int cur = 1;
    dfs(0,0,0,0);
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long ll;
ll mod=1e9+7;
ll inv(ll a){
    ll n=mod-2,ans=1;
    while(n>0){
        if(n%2) ans=ans*a%mod;
        n=n/2;
        a=a*a%mod;
    }
    return ans;
}
ll nCr(ll a,ll b){
    ll ans=1;
    rep(i,b) ans=ans*(a-i)%mod*inv(i+1)%mod;
    return ans;
}
int main(){
    long long n,m,ans=1,A[200000]={0},a=0;
    cin>>n>>m;
    rep(i,sqrt(m)-1){
        while(m%(i+2)==0) A[a]++,m=m/(i+2);
        a++;
    }
    if(m>1) A[a]++,a++;
    sort(A,A+a,greater<ll>());
    rep(i,n) ans=(ans*nCr(n+A[i]-1,A[i]))%mod;
    cout<<ans;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
	int a[10];
	for(int i=1;i<=5;i++){
		cin>>a[i];
	}
	for(int i=1;i<=5;i++){
		if(a[i]==0){
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 3632
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip.split())
def main():
    n = I()
    a = LI()
    bemax = a[0]
    ans = 0
    for i in a[1:]:
        if i > bemax:
            bemax = i
        elif i < bemax:
            ans += bemax - i
    print(ans)
main()

Measured memory_bytes: 96980
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, K;
	cin >> N >> K;

	cout << N % K << "\n";
	return 0;
}

Measured memory_bytes: 256
from heapq import heapify, heappop
from math import ceil
N, K = map(int, input().split())
H = list(map(int, input().split()))
# N=8
# K=9
# H=[7, 9, 3, 2, 3, 8, 4, 6]

Hminus = list(map(lambda x: x*(-1), H))
# print(type(Hminus))
heapify(Hminus)
# print(Hminus)
if K > len(H):
    print(0)
else:
    for _ in range(K):
        heappop(Hminus)
    print(sum(Hminus)*(-1))

Measured memory_bytes: 27404
import java.util.Scanner;

public class Main {
	static int[] subTreeSize;
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		long k = sc.nextLong();
		k--;
		int idx = 0;
		while (idx < s.length() && s.charAt(idx) == '1')
			idx++;
		char ans = k < idx ? '1' : s.charAt(idx);
		System.out.println(ans);
	}
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC exit(0);
using namespace std;
#define int long long
int dp[6006], n, m, x, y, res;
pair<int, int> p[3003];
int32_t main() {
    DAU
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
        cin >> p[i].first >> p[i].second;
    sort(p + 1, p + n + 1);
    dp[0] = 1;
    for (int i = 1; i <= n; ++i) {
        tie(x, y) = p[i];
        for (int j = m - 1; j >= 0; --j)
            if (dp[j])
                dp[j + x] = max(dp[j + x], dp[j] + y);
    }
    for (int i = 1; i <= m + 3000; ++i)
        res = max(res, dp[i]);
    cout << res - 1;
    PLEC
}


Measured memory_bytes: 3732
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>

size_t combination(size_t n, size_t r){
    if (r == 0 || r == n){
        return 1;
    }else if(r == 1){
        return n;
    }else{
        return (combination(n - 1, r - 1) + combination(n - 1, r));
    }
}

int main(){
    
    size_t n;

    std::cin >> n;

    std::map<std::string, size_t> s;

    for(size_t i = 0; i < n; i++){
        std::string tmp;
        std::cin >> tmp;
        std::sort(tmp.begin(), tmp.end());
        if(s.find(tmp) == s.end()){
            s.emplace(tmp, 1);
        }else{
            s[tmp]++;
        }
    }

    size_t ans = 0;

    for(const auto& e : s){
        if(e.second != 1) ans += combination(e.second, 2);
    }

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


Measured memory_bytes: 11136
def solve(n, r):
    if n <= 10:
        return r + 100 * (10 - n)
    else:
        return r


def main():
    n, r = map(int, input().split())
    res = solve(n, r)
    print(res)


def test():
    assert solve(2, 2919) == 3719
    assert solve(22, 3051) == 3051


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 2940
#include<iostream>

using namespace std;

int input[100];
int output[100];
int number=0;

void insertion_sort(int a[]);
void print(int a[]);

int main(){
    cin>>number;
    for (int i=0; i<number; i++) {
        cin>>input[i];
    }
    insertion_sort(input);
}

void insertion_sort(int a[]){
    print(a);
    for (int j=1; j<number; j++) {
        int key = a[j];
        int i = j-1;
        while (i>=0 && a[i]>key) {
            a[i+1] = a[i];
            i--;
        }
        a[i+1] = key;
        print(a);
    }
}

void print(int a[]){
    for (int i=0; i<number-1; i++) {
        cout<<a[i]<<" ";
    }
    cout<<a[number-1]<<endl;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
vector<long long> dsu(100005),cnt(100005,1);
long long parent(long long x){
	while(dsu[x]!=x){
		dsu[x] = dsu[dsu[x]] ; 
		x=dsu[x];
	}
	return x;
}
int main(){

	srand(42);
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	long long n,m,a1,r1,r2;
	cin>>n>>m;
	vector<pair<long long,long long> > edges;
	for(a1=1;a1<=m;++a1){
		dsu[a1]=a1;
		cin>>r1>>r2;
		edges.push_back(make_pair(r1,r2));
	}
	long long ans=(n*(n-1))/2;
	vector<long long> res;
	for(a1=m-1;a1>-1;--a1){
		res.push_back(ans);
		long long p1=parent(edges[a1].first),p2=parent(edges[a1].second);
		if(p1!=p2 && rand()&1){
			ans-=(cnt[p1]*cnt[p2]);
			dsu[p1]=p2;
			cnt[p2]+=cnt[p1];
		}
		else if(p1!=p2){
			ans-=(cnt[p1]*cnt[p2]);
			dsu[p2]=p1;
			cnt[p1]+=cnt[p2];
		}
		// cout<<ans<<"\n";
	}
	for(a1=m-1;a1>-1;--a1) cout<<res[a1]<<"\n";
	return 0;
}

Measured memory_bytes: 6256
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

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

ll modinv(ll a, ll mod){
  return modpow(a, mod-2, mod);
}

ll gcd(ll a, ll b){
  ll r = a%b;
  if(r==0) return b;
  else return gcd(b, a%b);
}

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}

struct UnionFind{
  ll N;
  llvec p;
  llvec cnt;
  UnionFind(ll n){
    N = n;
    p=llvec(N);
    cnt=llvec(N, 0);
    rep(i, N){
      p[i] = i;
      cnt[i] = 1;
    }
  }

  void con(ll a, ll b){
    P at = root(a);
    P bt = root(b);
    if(at.second!=bt.second){
      if(at.first>bt.first){
        swap(at, bt);
        swap(a, b);
      }
      p[at.second] = bt.second;
      cnt[bt.second]+=cnt[at.second];
      p[a]=bt.second;
    }
  }

  P root(ll a){
    ll atmp = a;
    ll c=0;
    while(atmp!=p[atmp]){
      atmp = p[atmp];
      c++;
    }
    p[a] = atmp;
    return {c, atmp};
  }

  bool is_con(ll a, ll b){
    P at=root(a);
    P bt=root(b);
    return at.second == bt.second;
  }
  
};

struct dijkstra{
  ll N;
  llvec d;
  vector<vector<edge>> e;
  dijkstra(ll n){
    N = n;
    //d = llvec(N, 1e18);
    e = vector<vector<edge>>(N);
  }

  void add_edge(ll from, ll to, ll cost){
    e[from].push_back({to, cost});
  }

  void run(ll start){
    priority_queue<P, vector<P>, greater<P>> que;
    que.push({0, start});
    d = llvec(N, 1e18);
    d[start]=0;
    while(!que.empty()){
      P q = que.top();que.pop();
      ll dc = q.first;
      ll x = q.second;
      if(dc>d[x]){
        continue;
      }else{
        for(auto ip: e[x]){
          if(d[ip.x]<=d[x]+ip.c){
            continue;
          }else{
            d[ip.x]= d[x]+ip.c;
            que.push({d[ip.x], ip.x});
          }
        }
      }
    }
  }  
};


/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  ll a = N%10;
  
  if(a==2 or a== 4 or a==5 or a==7 or a==9) cout << "hon";
  else if(a==0 or a==1 or a==6 or a==8) cout << "pon";
  else cout << "bon";
  cout << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <cstring>
#include <climits>
using namespace std;

int main() {
    int a[1000], b[1000], c[1000];
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }

    for (int i = 0; i < m; i++) {
        a[i]--;
        b[i]--;
    }
    int l[100][128] = {};
    for (int i = 0; i < m; i++) {
        l[a[i]][b[i]] = l[b[i]][a[i]] = c[i];
    }

    int k = 0;
    for (int i = 0; i < m; i++) {
        int d[100];
        for (int v = 0; v < n; v++) d[v] = INT_MAX;
        d[a[i]] = 0;
        priority_queue<pair<int, int>, vector<pair<int, int>>, greater<>> q;
        q.push({ 0, a[i] });
        
        for (; !q.empty();) {
            auto t = q.top();
            q.pop();
            if (t.second == b[i]) {
                if (d[b[i]] < c[i]) k++;
                break;
            }

            for (int v = 0; v < 100; v++) {
                int d4 = l[t.second][v];
                if (d4 == 0) continue;
                d4 += t.first;
                if (d[v] <= d4) continue;
                if (c[i] <= d4 && v != b[i]) continue;
                d[v] = d4;
                q.push({ d4, v });
            }
        }
    }

    cout << k << endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using I   = int;
using LL  = long long int;
using VI  = vector <I>;
using VLL = vector <LL>;
#define FOR( i, a, b ) for( int i=(a) ; i < (b) ; ++i )
#define REP( i, n )    for( int i= 0  ; i < (n) ; ++i )
#define ALL(a)         (a).begin(), (a).end()

int main( ) {
	I a,b,c,d,e,k;
	cin >> a >> b >> c >> d >> e >> k;

	if ( b - a > k || c - a > k || d - a > k || e - a > k ||
		 c - b > k || d - b > k || e - b > k || d - c > k ||
		 e - c > k || e - d > k ) {
		cout << ":(" << endl;
	} else {
		cout << "Yay!" << endl;
	}
}



Measured memory_bytes: 256
#include <iostream>

using namespace std;

int N, K;
int x[105];

int main(void)
{
	cin >> N >> K;
	for(int i = 0; i < N; i++) cin >> x[i];
	
	int ans = 0;
	for(int i = 0; i < N; i++){
		ans += min( x[i], K - x[i]);
	}
	
	cout << 2 * ans << endl;
	return 0;
}

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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 100500;



int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	ll a, b, c, ans = 0;
	cin >> a >> b >> c;

	if (a == b && b == c && c > 1) {
		cout << -1;
		return 0;
	}

	while (!(a & 1) && !(b & 1) && !(c & 1)) {
		ll x = (a >> 1);
		ll y = (b >> 1);
		ll z = (c >> 1);
		a = y + z;
		b = x + z;
		c = x + y;
		ans++;
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define pb push_back
#define mp make_pair
#define F .first
#define S .second 
#define pll pair<ll,ll>
using ll=long long;
using ld=long double;
const ll INF = 1LL<<60;
const ll mod=1e9+7;
using namespace std;
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }


int main(){
    ll x,y;
    cin>>x>>y;
    rep(i,0,51){
        rep(j,0,26){
            if(i+j==x&&i*2+j*4==y){
                cout<<"Yes";
                return 0;
            }
        }
    }
    cout<<"No";
}



Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define speedhack ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define fromfile freopen("input.txt", "r", stdin);  freopen("output.txt", "w", stdout); 
#define mod int (1e9+7)
#define MAXN int (1e9)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ull, ull> pull;
typedef pair<int, int> pii;
typedef pair<ld, ld> pld;
 


int k,t,n,m;
int a,b,c,d;
int coun;
vector<vector <int>> g;
vector<bool> vis(MAXN,false);
queue<int> q;




int main() {
    speedhack;
    //fromfile;
    cin >> n >> m;
    vis.resize(n);
    g.resize(n);
    coun = 0;
    while(m--){
        cin >> a >> b;
        g[a-1].pb(b-1);
        g[b-1].pb(a-1);
    }
    vector<int> d(n,0), p(n,-2);
    q.push(0);
    vis[0] = true;
    p[0] = -1;
    while(!q.empty()){
        int v = q.front();
        q.pop();
        for(int u:g[v]){
            if(!vis[u]){
                vis[u] = true;
                q.push(u);
                d[u] = d[v] + 1;
                p[u] = v;
            }
        }
    }
    for(int j = 1; j<n; j++){
        if (p[j] == -2){
            cout << "No";
            return 0;
        }
    }
    cout << "Yes\n";
    for(int j = 1; j<n; j++){
        cout << p[j] + 1 << "\n";
    }

}
 
 
    

Measured memory_bytes: 132796
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define REP(i,n) for (ll i = 0; i < (n); ++i)
#define RREP(i, n) for (ll i = (n) - 1; i >= 0; --i)
#define ALL(v) (v).begin(), (v).end()


int main(){
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i, n){
    cin >> a.at(i);
  }
  sort(ALL(a));

  ll ans = 1;
  REP(i, n){
    if(a.at(i) > 1000000000000000000LL / ans){
      cout << -1 << endl;
      return 0;
    }
    ans *= a.at(i);
    if(ans == 0){ break; }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4052
#include <stdio.h>
 
#define MAX 100000
#define nil -1
 
struct Node{
  int y; 
  int l; 
  int r; 
};
 
void preorder(int u);
void inorder(int u);
void postorder(int u);
 
struct Node T[MAX];
int n;
 
main(){
  int i,j,v,c,root;
 
  scanf("%d",&n); 
 
  for(i=0;i<n;i++){
    T[i].y=nil;
    T[i].l=nil;
    T[i].r=nil;
  }
 
  for(i=0;i<n;i++){
    scanf("%d",&v); 
 
    for(j=0;j<2;j++){
      scanf("%d",&c); 
 
      if(j==0){
    T[v].l=c;  
      } else {
    T[v].r=c;
      }
    T[c].y=v;       
    }
  }
 
  for(i=0;i<n;i++){
    if(T[i].y==nil){
      root=i;
      break;
    }
  }
 
  printf("Preorder\n");
  preorder(root);
  printf("\n");
  printf("Inorder\n");
  inorder(root);
  printf("\n");
  printf("Postorder\n");
  postorder(root);
  printf("\n");
  
  return 0;
}
 
 
void preorder(int u){
 
  printf(" %d",u);
  if(T[u].l!=nil) preorder(T[u].l);
  if(T[u].r!=nil) preorder(T[u].r);
 
}
 
void inorder(int u){
 
  if(T[u].l!=nil) inorder(T[u].l);
  printf(" %d",u);
  if(T[u].r!=nil) inorder(T[u].r);
}
 
void postorder(int u){ 
  
  if(T[u].l!=nil) postorder(T[u].l);
  if(T[u].r!=nil) postorder(T[u].r);
  printf(" %d",u);
 
}

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

int main(){
  string S;
  cin >> S;
  if(S=="Sunny"){
    cout << "Cloudy" << endl;
  }else if(S=="Cloudy"){
    cout << "Rainy" << endl;
  }else{
    cout << "Sunny" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>
#include <bitset>
#include <cmath>

#define MOD 1000000007

using namespace std;

typedef long long ll;

typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;

typedef pair<ll, ll> pll;
typedef pair<int, int> pi;

typedef vector<pll> vpl;
typedef vector<pi> vpi;

typedef queue<ll> ql;
typedef queue<int> qi;

template <class T>
void printv(vector<T> vc) {
    for (auto e: vc) cout << e << " ";
    cout << endl;
}

template <class T>
void printvv(vector<T> vvc) { 
    for (auto vc: vvc) {
        for (auto e: vc) cout << e << " ";
        cout << endl;
    }
}

template <class T>
void printvp(vector<pair<T, T> > vp) {
    for (auto pT: vp) cout << pT.first << " " << pT.second << endl;
}

int main() {
    int n; cin >> n;
    int map[100100] = {};
    for (int i = 0; i < n; ++i) {
        int a; cin >> a;
        ++map[a];
        if (a > 0) ++map[a + 1];
        if (a < 100100) ++map[a - 1];
    }
 
    int ans = 0;
    for (int i = 0; i < 100100; ++i) ans = max(ans, map[i]);
 
    cout << ans << endl;
 
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define pi pair<int,int> 
#define pb push_back
#define INF INT_MAX 
#define mod 1000000007ll
#define fi first
#define se second
#define f(i,p,q) for(int i=p;i<q;i++)
#define si(a) scanf("%d",&a)
#define sii(a,b) scanf("%d %d",&a,&b)
#define siii(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define pii(a) printf("%d\n",a)
#define psi(a) printf(" %d",a)
#define poi(a) printf("%d",a)
#define sl(a) scanf("%lld",&a)
#define pl(a) printf("%lld\n",a)
#define Nline() printf("\n")
#define sstr(str) scanf("%s",str)
#define pstr(str) printf("%s\n",str)
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define vi vector<int>
#define vvi vector<vi>
#define all(v) (v).begin(),(v).end()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())
#define VI(a,n) vi a(n); rep(i,n)cin>>a[i];
#define sq(n) (n)*(n)
#define ios ios::sync_with_stdio(false); cin.tie(0);cout.tie(NULL);
int dp[100005];
int main()
{   ios;
    int n,W;cin>>n>>W;
    f(i,0,100005)dp[i]=INF-1000000001;
    dp[0]=0;
    for(int i=0;i<n;i++)
    {
        int w,v;cin>>w>>v;
        for(int i=100005;i>=0;i--)
        {    if(i-v>=0)
             dp[i]=min(dp[i],dp[i-v]+w);
        }
    } 
     int ans=0;
     //f(i,0,100)cout<<i<<" "<<dp[i]<<"\n";
       for(int i=0;i<100005;i++)
         if(dp[i]<=W)
          ans=i;
        cout<<ans;
      //cout<<x;    
}
   

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, k;
    cin >> n >> k;
    vector<vector<int>> c(13, vector<int>(7));
    for (int i = 0; i < 13; ++i) {
        for (int j = 0; j < 7; ++j) {
            c[i][j] = (7 * i + j + 1) % 11;
        }
    }
    vector<vector<int>> s(11, vector<int>(5));
    for (int i = 0; i < 11; ++i) {
        for (int j = 0; j < 5; ++j) {
            for (int k = 0; k < 3; ++k) {
                for (int l = 0; l < 3; ++l) {
                    s[i][j] += c[i + k][j + l];
                }
            }
            s[i][j] %= 11;
        }
    }
    lint ret = 0;
    lint seq = 0;
    for (int i = 0; i < 11; ++i) {
        for (int j = 0; j < 5; ++j) {
            if (s[i][j] == k)
                seq++;
        }
    }
    n -= 2;
    ret = (n / 11) * seq;
    for (int i = 0; i < n % 11; ++i) {
        for (int j = 0; j < 5; ++j) {
            if (s[i][j] == k)
                ret++;
        }
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lo;
typedef pair<lo,lo> ll;//pair
typedef vector<lo> vl;  //vector of long
typedef vector<ll > vll;   //vector of pair
typedef priority_queue<lo>p_q;
#define mp(a,b) make_pair((a),(b))
#define REP(a,b) for(lo i=(a);i<(b);i++)//no need to declare variable i
 
#define REP2(a,b) for(lo j=(a);j<(b);j++)
#define REPE(a,b,c,d) REP(a,b)for(lo j=(c);j<(d);j++)//no need to declare vaiables i,j
#define REPV(a,b,c) for((a)=b;(a)<(c);(a)++)//a is the variable
#define IREP(a,b) for(lo i=(a);i>=(b);i--)
#define IREPV(a,b,c) for((a)=b;(a)>=(c);(a)--)
#define all(v) (v).begin(),(v).end()
#define TRvl(c) for (vl::iterator it = (c).begin(); it != (c).end(); it++)
#define TRvll(c) for (vll::iterator it = (c).begin(); it != (c).end(); it++
#define INF INT_MAX
#define gc getchar_unlocked
#define pc putchar_unlocked3
#define pb(a) push_back((a))
#define sz(x) x.size()
 
 
 
lo cel(lo x,lo y){
	if(x%y<=1)return x/y;
	else return x/y +1;
 }


lo power(lo n,lo ii,const lo mod){
	lo ans=1;
	REP(0,ii){
		ans= (ans*2)%mod;
	}
	return ans;
}
void solve(){
	lo n;
	const lo mod=1000000007;
	cin>>n;
	vl a (n,0);
	lo ans=0;
	REP(0,n){cin>>a[i];}
	lo z=0,o=0;
	REP(0,62){
		z=o=0;
		REP2(0,n){
			if(a[j]&1){
				o++;
			}
			else {
				z++;
			}
			a[j]=a[j]>>1;		
		}
		z=z%mod;o=o%mod;
		z=(z*o)%mod;
		lo x = power(2,i,mod)%mod;
		x=(x*z)%mod;
		ans= (ans%mod+(x)%mod)%mod;
	}

	cout<<ans;
}

 

 
 
int main(){

 
	// lo t;
	// cin>>t;
	// while(t--)
		solve();


	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int isPrime(int n)
{
    int i,count=0;

    if(n>1)

    {
        for(i=2; i<n; i++)
        {
            if(n % i == 0)
            {
                count++;
                break;
            }
        }
    }
    if(n==1)
        return 0;
    else
    {

        if(count==0)
        {
            return 1;
        }

        else
        {
            return 0;
        }
    }
}

int main()

{
    int number,ans;

    scanf("%d",&number);
    while(1)
    {
        ans = isPrime(number);
        if(ans == 1)
        {
            printf("%d",number );
            break ;
        }
        else
            number ++ ;



    }
    return 0;





}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<double,double> P;
const ll INF = 1e16;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



///////////////////////___modpow___////////////////////
ll modpow(ll a,  ll n, const ll &MOD = MOD){
  ll ret = n == 0 ? 1 : modpow(a, n/2, MOD);
  (ret *= ret) %= MOD;
  if(n%2)((ret *= a) %= MOD);
  return ret;
}
///////////////////////___modinv___////////////////////
ll modinv(ll d, const ll &MOD = MOD){
  return modpow(d, MOD-2, MOD);
}
////////////////////////////////////////////////////////////////////

int n,p;string s;
int d[11000];
signed main(){
  cin>>n>>p>>s;
  vector<int>v(n);
  rep(i,n)v[n-i-1] = ((int)(s[i] - '0'));
  if(p == 5){
    int ans = 0;
    rep(i,n){
      if(v[i] == 0 || v[i] == 5)ans += n-i;
    }
    cout << ans << endl;
    return 0;
  }else if(p == 2){
    int ans = 0;
    rep(i,n){
      if(v[i]%2 == 0)ans += n-i;
    }
    cout << ans << endl;
    return 0;
  }
  int pre = v[0]%p, ans = 0;
  if(pre == 0)ans++;
  d[pre]++;
  d[0]++;
  repd(i,1,n){
    pre = (pre + (v[i] * modpow(10, i, p))%p)%p;
    ans += d[pre];
    d[pre]++;
  }
  cout << ans << endl;
}




Measured memory_bytes: 2180
n, y = map(int, input().split())
b = 0
for i in range(n + 1):
    if b == 1:
        break
    for j in range(n - i + 1):
        if b == 1:
            break
        elif i * 10000 + j * 5000 + (n - i - j) * 1000 == y:
            print(i, j, n - i - j)
            b = 1
            break
if b == 0:
    print("-1 -1 -1")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    string S;
    cin >> S;
    
    bool flag = false;
    if(S == "KIHBR") flag = true;
    if(S == "AKIHBR") flag = true;
    if(S == "KIHABR") flag = true;
    if(S == "KIHBAR") flag = true;

    if(S == "KIHBRA") flag = true;
    if(S == "AKIHABR") flag = true;
    if(S == "AKIHBAR") flag = true;
    if(S == "AKIHBRA") flag = true;
    
    if(S == "AKIHABAR") flag = true;
    if(S == "AKIHABRA") flag = true;
    if(S == "AKIHABARA") flag = true;

    YES(flag);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 2001, C = N * N;
bitset <C> dp;
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif
    dp[0] = 1;
    int n; cin >> n;
    int sum = 0;
    while (n--) {
        int x; cin >> x;
        sum += x;
        dp |= dp << x;
    }   
    for (int i = (sum + 1) >> 1; ; ++i) {
        if (dp[i]) {
            cout << i << '\n';
            exit(0);
        }   
    }   
}   

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

int main(){
  string s;
  int query_num;
  cin >> s;
  cin >> query_num;

  vector<int> queries_q(query_num);
  vector<int> queries_f(query_num);
  vector<string> queries_c(query_num);

  for(int i=0; i<query_num; i++){
    int q, f;
    char c;
    cin >> q;
    if(q == 1){
      queries_q[i] = q;
      queries_f[i] = 0;
      queries_c[i] = "";
    }else{
      cin >> f >> c;
      queries_q[i] = q;
      queries_f[i] = f;
      queries_c[i] = c;
    }
  }

  string front;
  string back;
  long d = 0;

  for(int i=0; i<query_num; i++){
    if(queries_q[i] == 1){
      d++;
    }else{
      if(queries_f[i] == 1){
        if(d%2==0){
          front += queries_c[i];
        }else{
          back += queries_c[i];
        }
      }else{
        if(d%2==0){
          back += queries_c[i];
        }else{
          front += queries_c[i];
        }
      }
    }
  }
  reverse(front.begin(), front.end());
  s = front + s + back;
  if(d%2 != 0){
    reverse(s.begin(), s.end());
  }
  cout << s << endl;
}



Measured memory_bytes: 13852
#include <stdio.h>

int
main(int argc, char *argv[])
{
        int H, W;
        int i, j;

        while (scanf("%d %d", &H, &W), (H != 0) || (W != 0)) {
                for (i = 0; i < H; i++) {
                        for(j = 0; j < W; j++)
                                printf("#");
                        printf("\n");
                }
                printf("\n");
        }
        return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#include <iostream>
#include <cmath>
#include <limits>

using namespace std;

int main() {
  int N;
  int X;
  int T;
  
  cin >> N >> X >> T;
  
  int counter;
  if(N%X == 0)counter = N/X ;
  else counter = N/X + 1;
  
  int minute;
  minute = counter*T;
  
  cout << minute <<endl;
}

Measured memory_bytes: 3576
using System;
using System.IO;

class Program
{
    public static void Main()
    {
        int[] cnt = new int[26];
        while (true)
        {
            string str = Console.ReadLine();
            if (str == null) break;
            foreach (var c in str)
            {
                if (char.IsLetter(c))
                {
                    ++cnt[char.ToUpper(c) - 'A'];
                }
            }
        }
        for (int i = 0; i < 26; ++i)
        {
            Console.WriteLine("{0} : {1}", (char)('a' + i), cnt[i]);
        }
    }
}


Measured memory_bytes: 17832
/*
   Creator - Glitched
   Yeet!!
*/
#include "bits/stdc++.h"

using namespace std;

#define testcases ll T;cin>>T;while(T--)
#define ll long long
#define loop(i,x,n) for(ll i=x;i<n;i++)
#define loopr(i,x,n) for(ll i=n-1;i>=x;i--)
#define ff first
#define ss second
#define pb push_back
#define elif else if
#define flush cout<<"\n"
#define mod 1E9+7
#define L LONG_MAX
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
const string yes = "Yes", no = "No";
// vector<bad()ool> v(1E5, false);

int main()
{
    double a,b,ans=-1;
    cin>>a>>b;

    loop(i,1,1000000){

        double x = i;

        ll A,B;
        A = floor(x*(0.08));
        B = floor(x*0.1);

        if(A==a && B == b){
            ans = x;
            break;
        }

    }
    cout<<int(ans);



}

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

signed main(void)
{
	string s, t, u;
	cin >> s;

	int n;
	stack<char> sta;
	string tmp;

	n = s.size();
	rep(k, 3)
	{
		tmp = "";
		if (k == 0)
		{
			rep(i, n) sta.push(s[i]);
			while(!sta.empty())
			{
				tmp += sta.top();
				sta.pop();
			}
			if (tmp != s)
			{
				cout << "No" << endl;
				return 0;
			}
		}
		if (k == 1)
		{
			rep(i, (n - 1) / 2)
			{
				t += s[i];
				sta.push(s[i]);
			}
			while(!sta.empty())
			{
				tmp += sta.top();
				sta.pop();
			}
			if (tmp != t)
			{
				cout << "No" << endl;
				return 0;
			}
		}	
		if (k == 2)
		{
			For(i, (n + 3) / 2 - 1, n)
			{
				u += s[i];
				sta.push(s[i]);
			}
			while(!sta.empty())
			{
				tmp += sta.top();
				sta.pop();
			}
			if (tmp != u)
			{
				cout << "No" << endl;
				return 0;
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h> 
int main(void)
{   
  int x;   
  int i=0;    
  while(1)
  {     
    scanf("%d",&x);   
      if(x==0)break;     
    i++;      
   printf("Case %d: %d\n",i,x);    
  }    
   return 0; 
} 

Measured memory_bytes: 1028
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let N: usize = read();
    let mut min: usize = 100_100_100;
    let mut ans = 0;
    for _ in 0..N {
        let now: usize = read();
        if now <= min {
            ans += 1;
            min = now;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    ll n,k;
    cin>>n>>k;

    ll ans=0;
    for(ll i=k;i<=n+1;i++){
        ll l=(i-1)*i/2;
        ll r=n*(n+1)/2-(n-i)*(n-i+1)/2;
        ll tmp=r-l+1;

        //cout<<tmp<<endl;
        ans=(ans+tmp)%MOD;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 3548
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
#include <numeric>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
//#define mod 998244353
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<ull> vull;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//templete
int main() {
	cout<<setprecision(20)<<fixed;
	int N;
	cin>>N;
	vector<double> V;
	for(int i=0;i<N;i++){
		double v;
		cin>>v;
		V.pb(v);
	}
	sort(V.begin(),V.end());
	for(int i=0;i<N-1;i++){
		V[i+1]=(V[i]+V[i+1])/2.;
	}
	cout<<V.back()<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <list>

using namespace std;

int main() {
    size_t N;
    list<uint64_t> a;
    cin >> N;

    uint64_t input;
    for(size_t i = 0; i < N; i++) {
        cin >> input;
        if (0x0 == (input & 0x1)) {
            a.push_back(input >> 1);
        }
    }

    uint64_t sum = a.size();

    for (auto& ite : a) {
        size_t temp = 0;
        while ((ite != 0)) {
            if (0x1 == (ite & 0x1)) break;
            ite >>= 1; 
            temp++;
        }
        sum += temp;
    }

    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>
#include <cstring>
#include <algorithm>

using namespace std;

const int MAX = 100001;

int main() {

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

    sort(S, S + strlen(S));
    unique(S, S + strlen(S));

    int a = 97;
    for (int i = 0; i < strlen(S); ++i) {
        if (S[i] == a) {
            a++;
        } else {
            break;
        }
    }

    if (a == 123) printf("None\n");
    else printf("%c\n", (char)a);

    return 0;
}


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

class UnionFind:
    def __init__(self,N):
        self.parent = [i for i in range(N)]
        self._size = [1] * N
        self.count = 0
    def root(self,a):
        if self.parent[a] == a:
            return a
        else:
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    def is_same(self,a,b):
        return self.root(a) == self.root(b)
    def unite(self,a,b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb: return
        if self._size[ra] < self._size[rb]: ra,rb = rb,ra
        self._size[ra] += self._size[rb]
        self.parent[rb] = ra
        self.count += 1
    def size(self,a):
        return self._size[self.root(a)]

uf = UnionFind(N)
for a,b in AB:
    a,b = a-1,b-1
    if uf.is_same(a,b): continue
    uf.unite(a,b)
for i in range(N):
    uf.root(i)

st = set()
for i in range(N):
    st.add(uf.root(i))
print(len(st) - 1)

Measured memory_bytes: 27912
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);std::cout.precision(10);}} fast;

/* define */
#define FOR(I,X,Y) for(long long (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(long long (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define pb push_back
#define COUNT(V,X) upper_bound((V).begin(),(V).end(),X)-lower_bound((V).begin(),(V).end(),X)
#define debug(x) cerr<<#x<<':'<<x<<endl;
#define DEBUG(v) cerr<<#v<<':';for(auto xXx:v)cerr<<xXx<<' ';cerr<<endl;
#define Yes(X) if(X){cout<<"Yes"<<endl;}else{cout<<"No"<<endl;}
#define YES(X) if(X){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define ctoi(C) (C-'0')

/* alias */
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vl = vector<long long>;
using vll = vector<vector<long long>>;
using pi = pair<int,int>;
using pl = pair<long long,long long>;
template<typename T> using PQ = priority_queue<T>;
template<typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const long long dx[] = {1,0,-1,0};
const long long dy[] = {0,1,0,-1};
const long long dx8[] = {1,1,0,-1,-1,-1,0,1};
const long long dy8[] = {0,1,1,1,0,-1,-1,-1};
const long long dx9[] = {1,1,0,-1,-1,-1,0,1,0};
const int INF = 1000000007;
const long long LINF = 1000000000000000007;

/* func */
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
long long max(long long x,int y){return max(x,(long long)y);}
long long max(int x,long long y){return max((long long)x,y);}
long long min(long long x,int y){return min(x,(long long)y);}
long long min(int x,long long y){return min((long long)x,y);}

/* liblary */



/* main */

signed main(){
    ll N,M;
    cin >> N >> M;
    vector<ll> A(N),B(M);
    FOR(i,0,N)cin >> A[i];
    FOR(i,0,M)cin >> B[i];
    sort(ALL(A),greater<ll>());
    sort(ALL(B),greater<ll>());
    map<ll,ll> a,b;
    FOR(i,0,N)a[A[i]]++;
    FOR(i,0,M)b[B[i]]++;
    FOR(i,0,N){
        if(a[A[i]] >= 2){
            cout << 0 << endl;
            return 0;
        }
    }
    FOR(i,0,M){
        if(b[B[i]] >= 2){
            cout << 0 << endl;
            return 0;
        }
    }
    ll ans = 1;
    ll a_sum[1000010] = {0};
    ll b_sum[1000010] = {0};
    FOR(i,0,N)a_sum[A[i]]++;
    FOR(i,0,M)b_sum[B[i]]++;
    REP(i,0,1000009)a_sum[i] += a_sum[i+1];
    REP(i,0,1000009)b_sum[i] += b_sum[i+1];
    REP(i,1,N*M+1){
        if(a[i] && b[i]){
            ans *= 1;
        }
        else if(a[i]){
            ans *= b_sum[i];
        }
        else if(b[i]){
            ans *= a_sum[i];
        }
        else{
            ans *= (a_sum[i]*b_sum[i]-(N*M-i));
        }
        ans %= INF;
    }
    cout << ans << endl;
}

Measured memory_bytes: 140928
#include<iostream>
#include<algorithm>
#include<string>

using namespace std;
bool cat[1080][1080];
string s;
int main(){
	cin >> s;
	int len = s.size();
	for(int i = 0;i <= len;i++){
		for(int l = 0;l + i <= len;l++){
			int r = l + i;
			if(i == 0){
				cat[l][r] = true;
				continue;
			}
			if(s[l] != 'm' || s[r-1] != 'w')continue;
			for(int e = l+1;e < r-1;e++){
				if(s[e] != 'e')continue;
				if(cat[l+1][e] && cat[e+1][r-1]){
					cat[l][r] = true;
					break;
				}
			}
		}
	}
	if(cat[0][len])cout << "Cat" << endl;
	else cout << "Rabbit" << endl;
	return 0;
}


Measured memory_bytes: 3744
package main

import (
  "bufio"
  "fmt"
  "os"
)

var stack [100]int
var sp int = 0

func main() {
  sc := bufio.NewScanner(os.Stdin)

  var input string
  if sc.Scan() {
    input = sc.Text()
  }

  //  1文字ずつ操作しながらそれぞれの処理を行う
  var op bool = false
  var digits int8 = 0
  var buf int
  for _, r := range input {
    switch r {
      // 各演算子を受け取ったらスタックの値を用いて演算を実行
    case '+':
      op = true
      stack[sp-2] += stack[sp-1]
      sp--
    case '-':
      op = true
      stack[sp-2] -= stack[sp-1]
      sp--
    case '*':
      op = true
      stack[sp-2] *= stack[sp-1]
      sp--
    case ' ':
      //　空白を受け取ったら次へ行く
      if !op {
        stack[sp] = buf
        sp++
        buf = 0
      }
      op = false
      digits = 0
    default:
      buf = buf*10 + int(r - '0')
      digits++
    }
  }

  fmt.Printf("%d\n", stack[0])
}



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

int main() {
long long n,k;
cin >> n >> k;  
long long a;
long long c;
long long e;

for(int i = 1; i < n+1; i++){
  if(k%2 == 0){
if(i%k == k/2){
  c+=1;
}else if(i%k == 0){
  e += 1;
}

}else if(k%2 == 1){
  if(i%k == 0){
    e += 1;
  }
}
}
cout << c*c*c + e*e*e<< endl;
}

Measured memory_bytes: 256
import math
N, M = list(map(int, input().split()))
n_pairs = math.factorial(N) // (2*math.factorial(N-2)) if N > 1 else 0
m_pairs = math.factorial(M) // (2*math.factorial(M-2)) if M > 1 else 0
print(n_pairs + m_pairs)

Measured memory_bytes: 3316
#include<stdio.h>

#define N 100001

int Partition(int A[],int p,int r);

int main(){
  int A[N];
  int n,i,q;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++) scanf("%d",&A[i]);
  
  q = Partition(A,0,n-1);
  
  for(i=0;i<n;i++){
    if(i == q){
      printf("[%d] ",A[i]);
    } else if(i != n-1) {
      printf("%d ",A[i]);
    }
    else printf("%d",A[i]);
  }
  printf("\n");
  
  return 0;
}

int Partition(int A[],int p,int r){
  int i,j,x,y,z;
  
  x = A[r]; 
  i = p - 1;

  for(j = p ; j < r ; j++){
    if(A[j] <= x){
      i += 1;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
  }
  
  z = A[i+1];
  A[i+1] = A[r];
  A[r] = z;
  
  return i+1;
}

Measured memory_bytes: 996
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(in.hasNext()){
			double input = in.nextDouble();
			double sum=input,memo=input;
			for(int s=2;s<=10;s++){
				double m = s%2==0? memo*2:memo/3;
				memo=m;
				sum+=m;
			}
			System.out.println(sum);
		}
	}
}

Measured memory_bytes: 17416
#include<bits/stdc++.h>
#define N 209
using namespace std;

int n,a[N],b[2],pre[N]; bool mp[N][N],bo[N],tg[10000009];
bool isprm(int x){
	if (x==1) return 0;
	int i;
	for (i=2; i*i<=x; i++) if (!(x%i)) return 0;
	return 1;
}
bool dfs(int x){
	int i;
	for (i=1; i<=n; i++) if (bo[i] && mp[x][i]){
		bo[i]=0;
		if (!pre[i] || dfs(pre[i])){
			pre[i]=x; return 1;
		}
	}
	return 0;
}
int main(){
	scanf("%d",&n);
	int i,j,k;
	for (i=1; i<=n; i++){
		scanf("%d",&k); tg[k]=1;
	}
	for (i=1,n=0; i<=10000001; i++)
		if (tg[i]^tg[i-1]) a[++n]=i;
	for (i=1; i<=n; i++) if (a[i]&1)
		for (j=1; j<=n; j++) if (a[j]&1^1)
			mp[i][j]=isprm(abs(a[i]-a[j]));
	int sum=0;
	for (i=1; i<=n; i++) if (a[i]&1){
		memset(bo,1,sizeof(bo));
		sum+=dfs(i);
	}
	for (i=1; i<=n; i++) b[a[i]&1]++;
	b[0]-=sum; b[1]-=sum;
	printf("%d\n",sum+b[0]+b[1]+(b[0]&b[1]&1));
	return 0;
}


Measured memory_bytes: 6656
#!/usr/bin/env python
# -*- coding: utf-8 -*-

while True:
    N = int(input())
    if N == 0:
        break
    dates = [[] for i in range(31)]
    meets = [[] for i in range(N)]

    for i in range(N):
        D = list(map(int,input().split()))
        for d in D[1:]:
            dates[d].append(i)

    for i in range(31):
        hoge = []
        for p in dates[i]:
            hoge = set(hoge) | set(meets[p])
        for p in dates[i]:
            meets[p] = set(hoge) | set(dates[i])
            if len(meets[p]) == N:
                break
        else:
            continue
        break
    else:
        print(-1)
        continue
    print(i)

Measured memory_bytes: 6884