akhauriyash/Code-Regression huggingface dataset:
use proconio::input;
use std::collections::HashSet;

pub struct UnionFind {
    n: usize,
    par: Vec<usize>,
    rank: Vec<usize>
}

impl UnionFind {

    pub fn new(n:usize) -> UnionFind {
        UnionFind{
            n:n,
            par:(0..n).map(|i|i).collect(),
            rank:vec![0;n],
        }
    }

    pub fn size(&self) -> usize {self.n}

    pub fn find(&mut self,v:usize) -> usize {
        if self.par[v] == v {
            v
        }
        else {
            let p = self.find(self.par[v]);
            self.par[v] = p;
            p
        }
    }

    pub fn unite(&mut self,a:usize,b:usize){
        let a = self.find(a);
        let b = self.find(b);
        if a==b {
            return
        }
        else {
            if self.rank[a]<self.rank[b] {
                self.par[a] = b;
            }
            else {
                if self.rank[a]==self.rank[b] {
                    self.rank[a] += 1;
                }
                self.par[b] = a;
            }
        }
    }

    pub fn is_same(&mut self,a:usize,b:usize) -> bool {
        self.find(a)==self.find(b)
    }

}

const SZ:usize = 100001;
fn main() {
    input! {
        n:usize,
        xy:[(usize,usize);n]
    };

    let mut xid = vec![Vec::new();SZ];
    let mut yid = vec![Vec::new();SZ];
    for (i,&(x,y)) in xy.iter().enumerate() {
        xid[x].push(i);
        yid[y].push(i);
    }

    let mut uf = UnionFind::new(n);

    for i in 0..SZ {
        if xid[i].len()>0 {
            let p = xid[i][0];
            for &e in &xid[i] {
                uf.unite(p,e);
            }
        }
        if yid[i].len()>0 {
            let p = yid[i][0];
            for &e in &yid[i] {
                uf.unite(p,e);
            }
        }
    }

    let mut ids = vec![Vec::new();n];
    for i in 0..n {
        ids[uf.find(i)].push(i);
    }

    let mut ans = 0;
    for i in 0..n {
        let mut xs = HashSet::new();
        let mut ys = HashSet::new();
        for &id in &ids[i] {
            xs.insert(xy[id].0);
            ys.insert(xy[id].1);
        }
        ans+=(xs.len() as i64)*(ys.len() as i64);
    }

    println!("{}",ans-(n as i64));

}




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

using i32 = int_fast32_t;
using i64 = int_fast64_t;
using u32 = uint_fast32_t;
using u64 = uint_fast64_t;
using f64 = double;
using f80 = long double;

#define FOR(v, a, b) for(i64 v = (a); v < (b); ++v)
#define FORE(v, a, b) for(i64 v = (a); v <= (b); ++v)
#define REP(v, n) FOR(v, 0, n)
#define REPE(v, n) FORE(v, 0, n)
#define REV(v, a, b) for(i64 v = (a); v >= (b); --v)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define ITR(it, c) for(auto it = (c).begin(); it != (c).end(); ++it)
#define RITR(it, c) for(auto it = (c).rbegin(); it != (c).rend(); ++it)
#define EXIST(c,x) ((c).find(x) != (c).end())
#define fst first
#define snd second
#define UNIQ(v) (v).erase(unique(ALL(v)), (v).end())
#define bit(i) (1LL<<(i))

#ifdef DEBUG
#include <Mylib/Debug/debug.cpp>
#else
#define dump(...) ((void)0)
#endif

using namespace std;

template <typename I> void join(ostream &ost, I s, I t, string d=" "){for(auto i=s; i!=t; ++i){if(i!=s)ost<<d; ost<<*i;}ost<<endl;}
template <typename T> istream& operator>>(istream &is, vector<T> &v){for(auto &a : v) is >> a; return is;}
template <typename T> void pout(const T &value){std::cout << value << "\n";}
template <typename T, typename ...Args> void pout(const T &value, const Args&... args){std::cout << value << " ";pout(args...);}

template <typename T, typename U> bool chmin(T &a, const U &b){return (a>b ? a=b, true : false);}
template <typename T, typename U> bool chmax(T &a, const U &b){return (a<b ? a=b, true : false);}
template <typename T, size_t N, typename U> void fill_array(T (&a)[N], const U &v){fill((U*)a, (U*)(a+N), v);}
template <typename T> auto make_vector(int n, int m, const T &value){return vector<vector<T>>(n, vector<T>(m, value));}


struct Init{
  Init(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(12);
  }
}init;



int main(){
  double a, b, h, m;

  while(cin >> a >> b >> h >> m){
    double hang = h / 12 * 360 + m / 60 * 30;
    double mang = m / 60 * 360;

    double hx = cos(hang * M_PI / 180) * a;
    double hy = sin(hang * M_PI / 180) * a;

    double mx = cos(mang * M_PI / 180) * b;
    double my = sin(mang * M_PI / 180) * b;

    double dx = hx - mx;
    double dy = hy - my;

    double ans = sqrt(dx * dx + dy * dy);
    pout(ans);
  }

  return 0;
}


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

int main()
{
	char b, c[128];
	cin >> b;
	c['A'] = 'T';
	c['T'] = 'A';
	c['C'] = 'G';
	c['G'] = 'C';
	cout << c[(int)b] << endl;
	return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (n, a, b) = readLine()!!.split(" ").map(String::toInt)
    var num = 0
    for(i in 1..n) {
        val iStr = i.toString()
        var sum = 0
        for(j in 0..iStr.length -1) {
            val iInt = iStr[j].toString().toInt()
            sum = sum + iInt
        }
        if(sum >=a && sum <= b) {
            num += i
        }
    }
    println(num)
}

Measured memory_bytes: 38804
#include<bits/stdc++.h>
using namespace std;
typedef long double ld;
const long double pi = 3.1415926535497932384626433;
int main(){
  ld a,b,h,m;
  cin >> a >> b >> h >> m;
  ld h1 = h*30+m/2;
  ld m1 = m*6;
  ld jia = (max(h1,m1) - min(h1,m1));
  if(jia>180) jia = 360 - jia;
  ld ans = 0;
  ans = a*a+b*b-2*a*b*cos(jia*pi/180);
  ans = pow(ans,0.5);
  cout << fixed <<setprecision(20);
  cout << ans <<endl;;
  return 0;
}


Measured memory_bytes: 4048
a,b=map(int,input().split())
c,d=map(int,input().split())
e,f=map(int,input().split())
g,h=map(int,input().split())
i,j=map(int,input().split())
k,l=map(int,input().split())
m,n=map(int,input().split())

print(a-b)
print(c-d)
print(e-f)
print(g-h)
print(i-j)
print(k-l)
print(m-n)



Measured memory_bytes: 5588
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) //fprintf(stderr,f,##__VA_ARGS__),fflush(stderr)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

/*
const int N=;

int mul(int a,int b){ return 1ll*a*b%P; }
int add(int a,int b){ a+=b; return a>=P?a-P:a; }
int sub(int a,int b){ a-=b; return a<0?a+P:a; }
*/

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	//freopen("dat.in","r",stdin);
	//freopen("my.out","w",stdout);
#endif
	long long A,B,C,ans;
	cin>>A>>B>>C;
	ans=min(A%2*B*C,min(B%2*A*C,C%2*A*B)); 
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 10;

int main()
{
	int N;
	string s;
	while (cin >> N, N) {
		vector<int> a(N);
		for (int i = 0; i < N; i++) {
			cin >> s;
			if (s == "x") {
				a[i] = INF;
			}
			else {
				a[i] = stoi(s);
			}
		}
		int ma = INF, mi = -INF;
		for (int i = 1; i < N; i++) {
			if (a[i] == INF) {
				if (a[i - 1] == INF) {
					ma = -INF;
					mi = INF;
					break;
				}
				else if (i & 1) {
					mi = max(mi, a[i - 1] + 1);
				}
				else {
					ma = min(ma, a[i - 1] - 1);
				}
			}
			else if (a[i - 1] == INF) {
				if (i & 1) {
					ma = min(ma, a[i] - 1);
				}
				else {
					mi = max(mi, a[i] + 1);
				}
			}
			else if (i & 1) {
				if (a[i - 1] >= a[i]) {
					ma = -INF;
					mi = INF;
					break;
				}
			}
			else {
				if (a[i - 1] <= a[i]) {
					ma = -INF;
					mi = INF;
					break;
				}
			}
		}
		if (ma == mi) {
			cout << ma << endl;
		}
		else {
			cout << (ma > mi ? "ambiguous" : "none") << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
int a[500],b[500],c[500],D,N,t[500],dp[500][500];
int main(){
    cin>>D>>N;
    for(int i=1;i<D+1;i++){ cin>>t[i]; }
    for(int i=1;i<N+1;i++){ cin>>a[i]>>b[i]>>c[i]; }
    for(int i=1;i<D+1;i++){ fill(dp[i]+1,dp[i]+N+1,-1); }
    for(int i=1;i<N+1;i++){ if(a[i]<=t[1]&&t[1]<=b[i]){ dp[1][i]=0; } }
    for(int i=2;i<D+1;i++){
        for(int j=1;j<N+1;j++){
            if(dp[i-1][j]!=-1){
                for(int u=1;u<N+1;u++){
                    if(a[u]<=t[i]&&t[i]<=b[u]){
                        int cu=c[j]-c[u];
                        if(cu<0)cu=cu*-1;
                        dp[i][u]=max(dp[i][u],dp[i-1][j]+cu);
                    }
                }
            }
        }
    }
    int kotae=0;
    for(int i=1;i<N+1;i++){ kotae=max(kotae,dp[D][i]); }
    cout<<kotae<<endl;
}

Measured memory_bytes: 3456
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

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

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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

const double pi = 3.141592653589793;
// -------------------------------------------------------
ll N;

ll f(ll a, ll b) {
  ll ma = max(a, b);
  ll res = 0;
  while (ma) {
    ++res;
    ma /= 10;
  }
  return res;
}

int main() {
  cin >> N;
  ll ans = INF;
  repe(i, 1, min(100000LL, N)) {
    if (N % i == 0) {
      chmin(ans, f(i, N / i));
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    vector<ll> a(n);
    rep(i,n){
        cin>>a[i];
    }
    ll ans=1000,ind=0;
    rep(i,n-1){
        if(a[i]<a[i+1]){
            ll pre=ans;
            ans%=a[i];
            ans+=pre/a[i]*a[i+1];
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>

int main() {
  int n, k; std::cin >> n >> k;
  std::vector<bool> hasTreat(n, false);
  
  while (k--) {
    int c; std::cin >> c;
	while (c--) {
      int s; std::cin >> s;
      --s;
      hasTreat[s] = true;
    }
  }
  int sum = 0;
  for (int i = 0; i < n; ++i) {
    sum += (hasTreat[i] == false); 
  }
  std::cout << sum << std::endl;
  return 0;
}

Measured memory_bytes: 3572
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define SORT(a) sort(a.begin(),a.end())
using namespace std;
int main(){
    //Seiranchan!
     int N,K;
     cin >> N >> K;
    if(N==1||K==1){
        cout << 0 << endl;
    }else{
     cout << (N-1)*(K-1) <<endl;
    }
}


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


int main() 
{
    int A, B, C;
    cin >> A >> B >> C;

    bool answer = false;

    for (int i = 1; i <= B; i++)
    {
        if (A * i % B == C)
            answer = true;
    }

    if (answer)
        cout << "YES";
    else
        cout << "NO";

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=998244353;
ll mul(ll a, ll b)
{
	return ((a%mod)*(b%mod))%mod;
}
ll add(ll a, ll b)
{
	return ((a%mod)+(b%mod))%mod;
}
ll sub(ll a, ll b)
{
	return ((a%mod)-(b%mod)+mod)%mod;
}
int main() 
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	string s,t;
	cin>>s>>t;
	ll tr=1;
	for(ll i=0;i<s.size();i++)
	{
		if(s[i]!=t[i])
		{
			tr=0;
		}
	}
	if(tr)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
}

Measured memory_bytes: 3636
#template
def inputlist(): return [int(j) for j in input().split()]
#template
X,Y = inputlist()
x = (4*X-Y)/2
y = (Y-2*X)/2
if x >= 0 and y >= 0 and x.is_integer() and y.is_integer():
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9152
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;

void no() {
    cout << "No" << endl;
}
void yes() {
    cout << "Yes" << endl;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string s;
    cin >> s;

    queue<int> q;
    q.push(a-1);
    vector<bool> used(n, false);
    used[a-1] = true;
    while(!q.empty()) {
        int now = q.front();
        q.pop();
        for(int j = 1; j < 2; j += 2) for(int k = 1; k < 3; k++) {
            int ni = now+j*k;
            if(ni >= 0 and ni < n and s[ni] != '#' and !used[ni]) {
                used[ni] = true;
                q.push(ni);
            }
        }
    }

    vector<bool> uused(n, false);
    uused[b-1] = true;
    q.push(b-1);
    while(!q.empty()) {
        int now = q.front();
        q.pop();
        for(int j = 1; j < 2; j += 2) for(int k = 1; k < 3; k++) {
            int ni = now+j*k;
            if(ni >= 0 and ni < n and s[ni] != '#' and !uused[ni]) {
                uused[ni] = true;
                q.push(ni);
            }
        }
    }

    if(d < c) {
        bool x = false;
        for(int i = b-1;i < d; ++i) {
            if(s[i] == '.' and s[i-1] == '.' and s[i+1] == '.') {
                x = true;
            }
        }
        if(!x) {
            no();
            return 0;
        }
    }

    if(used[c-1] and uused[d-1]) {
        yes();
        return 0;
    }
    no();
}


Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long q,h,s,d,n;
    cin>>q>>h>>s>>d;
    cin>>n;
    s=min(s,4*q);
    s=min(s,2*h);
    d=min(2*s,d);
    unsigned long long ans=0;
    ans=(n/2)*d+(n%2)*s;
    cout<<ans;
    return 0;
}

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

int main ()
{
	int n, k;
	cin >> n >> k;
	if (k==10){
		int ans=0;
		while (n){
			ans++;
			n/=10;
		}
		cout<<ans;
	}
	else {
		string ans="";
		while (n){
			ans+=n%k+'0';
			n=n/k;
		}
		reverse(ans.begin(),ans.end());
		cout<<ans.size();
	}
}



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

int main() {
    int N;  cin >> N;
    vector<int> P(N), Q(N), R(N);
    for (int i = 0; i < N; ++i) {
        cin >> P[i];
        --P[i];
    }
    for (int i = 0; i < N; ++i) {
        cin >> Q[i];
        --Q[i];
    }
    for (int i = 0; i < N; ++i) R[i] = i;

    int cnt = 0, idx_p, idx_q;
    do {
        bool match_p = true, match_q = true;
        for (int i = 0; i < N; ++i) {
            if (P[i] != R[i]) match_p = false;
            if (Q[i] != R[i]) match_q = false;
        }
        if (match_p) idx_p = cnt;
        if (match_q) idx_q = cnt;
        ++cnt;
    } while (next_permutation(R.begin(), R.end()));

    cout << abs(idx_p - idx_q) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if (a < b)
			System.out.println("a < b");
		else if (a > b)
			System.out.println("a > b");
		else if (a == b)
			System.out.println("a == b");
	}
}


Measured memory_bytes: 26388
// B - Strings woth the Same Length
#include <stdio.h>

int main(void){
    int n;
    char s[101], t[101];
    scanf("%d", &n);
    scanf("%s%s", s, t);
    for(int i=0; i<n; i++)printf("%c%c", s[i], t[i]);
    puts("");
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define REP(i, a, b) for (long long i = a; i <= b; ++i)
#define ll long long
#define N 110
using namespace std;

ll n, t, ans = 1001;

inline ll read(){											//¿ì¶Á 
	ll s = 0, w = 1;
	char ch = getchar();
	while (ch < '0' || ch > '9'){
		if (ch == '-') w *= -1;
		ch = getchar();
	}
	while (ch >= '0' && ch <= '9'){
		s = s * 10 + ch - '0';
		ch = getchar();
	}
	return s * w;
}

inline void work(){
	n = read(), t = read();									//ÓÐnÌõÏßÂ·ºÍt¸öÊ±¼ä 
	REP(i, 1, n){
		ll x = read(), y = read();							//ÊäÈë·ÑÓÃºÍÊ±¼ä 
		if (y <= t) ans = min(ans, x);						//È¡×îÐ¡Öµ 
	}
	if (ans == 1001) puts("TLE");							//ÌØÅÐ,Êä³öTLE 
	else printf("%lld\n", ans);								//Êä³ö´ð°¸ 
}

int main(){
	work();
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
#include "string.h"
#include "algorithm"
 
using namespace std;
typedef int64_t ll;
typedef vector<int64_t> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SIZE(a) int((a).size())


int main(){
  ll n;
  cin>>n;
  ll m=1e12+7;
  
  for(ll i=0;i<pow(n,0.5)+2;i++){
    if(n%(i+1)!=0){continue;}
	else{
      ll x=n/(i+1);
      m=min(m,i+x-1);
    }
  }
  cout<<m<<endl;
}



Measured memory_bytes: 256
#include <string>
#include <vector>
#include <iostream>
using namespace std;
string s, t[] = { "',.!?", "abcABC", "defDEF", "ghiGHI", "jklJKL", "mnoMNO", "pqrsPQRS", "tuvTUV", "wxyzWXYZ" };
int main() {
	while (cin >> s) {
		int p = 0; s += "-";
		vector<pair<int, int> > v;
		for (int i = 1; i < s.size(); i++) {
			if (s[i - 1] != s[i]) {
				v.push_back(make_pair(s[i - 1] - 48, i - p - 1));
				p = i;
			}
		}
		for (int i = 0; i < v.size(); i++) {
			if (v[i].first == 0) {
				for (int j = 0; j < v[i].second; j++) {
					cout << ' ';
				}
			}
			else {
				v[i].second %= t[v[i].first - 1].size();
				cout << t[v[i].first - 1][v[i].second];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3108
while True:
    m, t, p, r = map(int, input().split())
    if m == t == p == r == 0:
        break

    score = [[-1 for i in range(p + 1)] for j in range(t + 1)]
    for i in range(r):
        mi, ti, pi, j = map(int, input().split())
        if not j:
            score[ti][pi] = mi - (score[ti][pi] + 1) * 20
        else:
            score[ti][pi] -= 1

    data = list()
    for ti in range(1, t + 1):
        ans = 0
        pen = 0
        for pi in range(1, p + 1):
            if score[ti][pi] >= 0:
                ans += 1
                pen += score[ti][pi]
        data.append((ans, -pen, ti))

    data.sort(reverse = True)
    for i in range(t - 1):
        ans, pen, ti = data[i]
        pen = -pen
        print(ti, end = "")
        if ans > data[i + 1][0] or pen < - data[i + 1][1]:
            print(",", end = "")
        else:
            print("=", end = "")
    print(data[t - 1][2])


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

int main(){
    int n,k,c = 0;
    cin>>n;
    cin>>k;
    int sintyo[n];
    for(int i=0;i<n;i++){
        cin>>sintyo[i]; 
        if(sintyo[i]>=k){
            c += 1;
        }  
    }
    cout<<c<<endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
using namespace std;
// type alias
typedef long long LL;
typedef vector < int > VI;
typedef unordered_map < int, int > MAPII;
typedef unordered_set < int > SETI;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// minmax
#define SMAX(a,b) a = max(a,b)
#define SMIN(a,b) a = min(a,b)
// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }

/*
 
 8/7/2018
 
 13:10-14:00 pause
 14:55-
 
 */

// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG x.cpp && ./a.out
//const int MAX_N=1e5+1;
//int N;
string S;
const string p1="First",p2="Second";
bool solve() {
  int N=SZ(S);
  if(N%2==0) return S.front()==S.back();
  if(S.front()==S.back()) return false;
  set<char> X(S.begin(),S.end());
  return SZ(X)!=2;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  
  cin>>S;
  cout<<(solve()?p1:p2)<<endl;
  return 0;
}


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

int main(){
    string s; cin >> s;
    int tmp1 = 0, tmp2 = 0;
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 1 && s.at(i) == '0') tmp1++;
        if(i % 2 == 0 && s.at(i) == '1') tmp1++;
    }
    for(int i = 0; i < s.size(); i++){
        if(i % 2 == 1 && s.at(i) == '1') tmp2++;
        if(i % 2 == 0 && s.at(i) == '0') tmp2++;
    }
    cout << min(tmp1, tmp2) << endl;


}

Measured memory_bytes: 512
// -*- coding:utf-8-unix -*-

use proconio::input;

fn main() {
    input! {
        w: usize,
        h: usize,
        n: usize,
    }

    let mut is_white = vec![vec![true; w]; h];
    for _ in 0..n {
        input! {
            x: usize,
            y: usize,
            a: u8,
        }

        match a {
            1 => {
                for i in 0..h {
                    for j in 0..x {
                        is_white[i][j] = false;
                    }
                }
            },
            2 => {
                for i in 0..h {
                    for j in x..w {
                        is_white[i][j] = false;
                    }
                }
            },
            3 => {
                for i in 0..y {
                    for j in 0..w {
                        is_white[i][j] = false;
                    }
                }
            },
            4 => {
                for i in y..h {
                    for j in 0..w {
                        is_white[i][j] = false;
                    }
                }
            },
            _ => unreachable!(),
        }
    }

    let ans = is_white.iter().fold(0, |acc, row| {
        acc + row.iter().filter(|&p| *p).count()
    });
    println!("{}", ans);
}


Measured memory_bytes: 2208
if __name__=="__main__":
    n = int(input())
    A = [0 for i in range(n)]
    B = [0 for i in range(n)]
    C = [0 for i in range(n)]
    for i in range(n):
        A[i], B[i], C[i] = [int(i) for i in input().split(' ')]
    f = [0, 0, 0]
    for i in range(n):
        g = [0, 0, 0]
        g[0] = max(f[0], max(f[1], f[2]) + A[i])
        g[1] = max(f[1], max(f[0], f[2]) + B[i])
        g[2] = max(f[2], max(f[0], f[1]) + C[i])
        f = g
    print(max(f[0], max(f[1], f[2])))


Measured memory_bytes: 16800
from collections import deque

n,m=map(int,input().split())
graph=[[] for _ in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    graph[a-1].append(b-1)#aにはbがつながってる
    graph[b-1].append(a-1)#bにはaがつながってる
#print(graph)

res=[-1]*n
que=deque()
que.append(0)

while len(que)>0:
    i=que.popleft();
    for j in graph[i]:
        if res[j]==-1:
            res[j]=i
            que.append(j)
    #print(que)

print("Yes")
for l in res[1:]:
    print(l+1)

Measured memory_bytes: 34900
n,tmax=map(int,input().split())
c=[0]*n
t=[0]*n
result=9999
for i in range(0,n):
  c[i],t[i]=map(int,input().split())
  if t[i]<=tmax and c[i]<result:
    result=c[i]
if result==9999:
  print("TLE")
else:
  print(result)


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

int main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> H(N);
  rep(i, N) cin >> H[i];
  vector<vector<ll>> G(N, vector<ll>(0));
  rep(i, M) {
    ll a, b;
    cin >> a >> b;
    --a; --b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  ll ans = 0;
  for (int i = 0; i < N; i++) {
    bool h = true;
    for (auto g : G[i]) {
      if (H[g] >= H[i]) {
        h = false;
        break;
      }
    }
    if (h) ans++;
  }
  cout << ans << endl;
}

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

int main()
{
	int N;
	cin >> N;
	vector<int> C(N), S(N), M(N);

	for (int i = 0; i < N-1; ++i)
	{
		cin >> C[i] >> S[i] >> M[i];
	}

	vector<int> T(N, 0);
	for (int i = 0; i < N-1; ++i)
	{
		for (int j = i; j < N-1; ++j)
		{
			if (T[i] < S[j])
			{
				T[i] = S[j];
			}
			else
			{
				if ((T[i] - S[j]) % M[j] != 0)
				{
					T[i] += M[j] - (T[i] - S[j]) % M[j];
				}
			}

			T[i] += C[j];
		}
	}

	for (int i = 0; i < N; ++i)
	{
		cout << T[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
 
int partition(int A[], int p, int r) {
    int i = p;
    for (int j = p; j < r; j++) {
        if (A[j] <= A[r]) {
            swap(A[i++], A[j]);
        }
    }
    swap(A[i], A[r]);
    return i;
}
 
int main(){
    int n;
    cin >> n;
    int A[n];
    for (int i = 0; i < n; i++) {
        int tmp;
        cin >> tmp;
        A[i] = tmp;
    }
    int q = partition(A, 0, n - 1);
 
    for (int i = 0; i < n; i++) {
        if (i > 0) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0index
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1index
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからb - 1まで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //逆
#define all(x) (x).begin(),(x).end()
const int INF = 1000000007;  //最大値兼MOD
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }  //GCD
int main(){
    int a,b;
    cin >> a >> b;
    cout << max(a -(2*b),0) << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
	int n,sum=0,t=0,m;
	char a[1000];
	scanf("%s",a);
	n=strlen(a);
	for(int i=0;i<n;i++)
	{
		m=a[i]-'0';
		sum+=m;
		t+=m*pow(10,n-i-1);
	}
	if(t%sum==0)printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<cstdlib>
using namespace std;

#define re return
#define in inline
#define inc(l, i, r) for(i=l; i<r; ++i)

const short mxn=101;

short h, w, xe, ye, a[mxn][mxn], s[mxn][mxn], f[mxn][mxn][mxn][mxn]; char str[mxn];

in void upd(short& a, short b){a<b? a=b: 0;}

in short sum(short x1, short x2, short y1, short y2)
{re s[x2][y2]+s[x1-1][y1-1]-s[x2][y1-1]-s[x1-1][y2];}

int main()
{
    short i, j, k, l, ans=0;
    cin>>h>>w; scanf("\n");
    inc(1, i, h+1)
    {
        scanf("%s", str);
//        gets(str);
        inc(1, j, w+1)
            switch(str[j-1])
            {
            case 'o': a[i][j]=1; break;
            case 'E': xe=i, ye=j;
            }
    }
    inc(1, i, h+1)
        inc(1, j, w+1)
        s[i][j]=a[i][j]-s[i-1][j-1]+s[i][j-1]+s[i-1][j];

    inc(0, i, xe+1)
        inc(0, j, ye+1)
        inc(0, k, h-xe+1)
        inc(0, l, w-ye+1)
    {
//        printf("%d %d %d %d : %d\n", i, j, k, l, f[i][j][k][l]);
        upd(ans, f[i][j][k][l]);
        if(i+k+1<xe)
            upd(
                f[i+1][j][k][l],
                f[i][j][k][l]+
                sum(
                    xe-i-1, xe-i-1,
                    max(ye-j, l+1), min(ye+l, w-j)
                    )
                );
        if(xe+i+k<h)
            upd(
                f[i][j][k+1][l],
                f[i][j][k][l]+
                sum(
                    xe+k+1, xe+k+1,
                    max(ye-j, l+1), min(ye+l, w-j)
                    )
                );
        if(j+l+1<ye)
            upd(
                f[i][j+1][k][l],
                f[i][j][k][l]+
                sum(
                    max(xe-i, k+1), min(xe+k, h-i),
                    ye-j-1, ye-j-1
                    )
                );
        if(ye+j+l<w)
            upd(
                f[i][j][k][l+1],
                f[i][j][k][l]+
                sum(
                    max(xe-i, k+1), min(xe+k, h-i),
                    ye+l+1, ye+l+1
                    )
                );
    }
    cout<<ans<<"\n";
    re 0;
}


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

using namespace std;

pair<int, int> q[100001];

int main(){
  int n, m;
  cin >> n >> m;
  for(int i = 0; i < m; ++i){
    cin >> q[i].first >> q[i].second;
  }
  sort(q, q + m);
  int next = -1, ans = 0;
  for(int i = 0; i < m; ++i){
    if(q[i].first < next){
      next = min(next, q[i].second);
    }else{
      next = q[i].second;
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <stack>
#include <iomanip>
#include <numeric>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <vector>
#include <utility>
#include <queue>
#include <cmath>

#define BEGIN(x) x.begin()
#define END(x) x.end()
#define ALL(x) BEGIN(x), END(x)
#define PAIR make_pair
#define VEC(type) vector<type >
#define endl '\n'

#define FOR(i, A, B) for(auto i = (A);i != (B); i++)
#define FORD(i, A, B) for(auto i = (A);i != (B); i--)

#define READRANGE(begin, end) FOR(it, begin, end) cin >> *it
#define READVEC(V) READRANGE(BEGIN(V), END(V))

using namespace std;

typedef long long lint;
typedef pair<int, int> Pii;
typedef pair<int, lint> Pil;
typedef pair<lint, lint> Pll;
typedef pair<lint, int> Pli;

// ---- BEGIN LIBRARY CODE ----
// ---- END LIBRARY CODE ----
void io_init()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
};

int main(int argc, char **argv)
{
    io_init();

    // Actual program code starts here.
    int N;
    cin >> N;
    VEC(char) Directions(N);
    VEC(int) X(N), Y(N);
    FOR(i, 0, N) {
        cin >> X[i] >> Y[i] >> Directions[i];
    }

    auto area = [&N, &X, &Y, &Directions](double t) {
        double xlo = 1e10, xhi = -(1e10);
        double ylo = 1e10, yhi = -(1e10);
        FOR(i, 0, N) {
            double x = X[i], y = Y[i];
            if (Directions[i] == 'U')
                y += t;
            else if (Directions[i] == 'D')
                y -= t;
            else if (Directions[i] == 'R')
                x += t;
            else
                x -= t;

            xlo = min(xlo, x);
            ylo = min(ylo, y);
            xhi = max(xhi, x);
            yhi = max(yhi, y);
        }

        return (xhi - xlo) * (yhi - ylo);
    };

    double lo = 0, hi = 1e10;

    int iters = 150;
    while (iters-- && hi - lo > 1e-10) {
        double md1 = (2 * lo + hi) / 3, md2 = (lo + 2 * hi) / 3;
        if (area(md1) < area(md2))
            hi = md2;
        else
            lo = md1;
    }

    cout << fixed << setprecision(10) << area((lo + hi) / 2) << endl;
    return 0;
};


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    string S;
    cin>>N>>S;
    int point=0;
    for(int i=0;i<S.size();i++){
        if(S[i]=='W'){point++;}
    }
    int M=1-N;
    for(int i=0;i<S.size();i++){
        if(S[i]=='W'){point--;}
        M=max(M,point);
        if(S[i]=='E'){point++;}
    }
    cout<<N-M-1<<endl;
}

Measured memory_bytes: 720
# include<bits/stdc++.h>
using namespace std;
# define lowbit(x) ((x)&(-x))
# define pi acos(-1.0)
# define eps 1e-8
# define MOD 1000000007
# define INF 100000000
# define mem(a,b) memset(a,b,sizeof(a))
# define FOR(i,a,n) for(register int i=a; i<=n; ++i)
# define FDR(i,a,n) for(register int i=a; i>=n; --i)
# define bug puts("H");
# define lch p<<1,l,mid
# define rch p<<1|1,mid+1,r
# define mp make_pair
# define pb push_back
typedef pair<int,int> PII;
typedef vector<int> VI;
# pragma comment(linker, "/STACK:1024000000,1024000000")
typedef long long LL;
inline char nc(){
    static char buf[1000000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int Scan(){
    char ch=nc();int sum=0, f=1;
    if (ch=='-') f=-1, ch=nc();
    while(!(ch>='0'&&ch<='9'))ch=nc();
    while(ch>='0'&&ch<='9')sum=sum*10+ch-48,ch=nc();
    return sum*f;
}
const int N=1005;

int main ()
{
    LL A, B;
    scanf("%lld%lld",&A,&B);
    int ans=0;
    while (1) {
        if (A>B) break;
        ++ans; A<<=1;
    }
    printf("%d\n",ans);
    return 0;
}


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

const int inf = 0x3f3f3f3f;

string s;

int dp[200002][4];

int f(int idx, int prv, string sx) {
        if(idx >= s.size()) return 0;
        if(~dp[idx][prv]) return dp[idx][prv];
        int res = -inf;
        string t;
        t += s[idx];
        if(t != sx) res = max(res, 1 + f(idx + 1, 1, t));
        if(idx + 1 < s.size()) {
            t += s[idx + 1];
            if(t != s) res = max(res, 1 + f(idx + 2, 2, t));
        }
        return dp[idx][prv] = res;
}

int main() {
        cin >> s;
        memset(dp, -1, sizeof dp);
        cout << f(0, 0, "") << endl;

}


Measured memory_bytes: 36740
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;cin>>s;
	int l=s.size()-1;
	if(l%2&&s[0]==s[l])puts("First");
	else if(l%2)puts("Second");
	else if(s[0]!=s[l])puts("First");
	else puts("Second");
	return 0;
}

Measured memory_bytes: 512
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const S = arg[0].split("");
    const list = [];
    
    let last;
    
    for(let i in S) {
        if(S[i] !== last) {
            list.push(S[i]);
        }
        
        last = S[i];
    }

    console.log(list.join("").length - 1);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 32840
h, w = map(int, input().split())

# 共に奇
if h == 1 or w == 1:
    print(1)
    exit(0)
if h % 2 == 1 and w % 2 ==1:
    print(int((h // 2 + 1) * (w // 2 + 1) + (h // 2) * (w // 2)))
    exit(0)
# 片方偶数
if h % 2 == 0 and w % 2 ==1:
    print(int((h // 2) * (w // 2 + 1) + (h // 2) * (w // 2)))
    exit(0)
if h % 2 == 1 and w % 2 ==0:
    print(int((h // 2 + 1) * (w // 2) + (h // 2) * (w // 2)))
    exit(0)
else:
    print(int(h * w / 2))
    exit(0)



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

#define int long long
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i < b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<bool> > vvb;
typedef vector<vector<double> > vvd;
typedef vector<vector<string> > vvs;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

signed main()
{   
    gearup;
    int n; cin >> n;
    vector<vector<pair<int,int> > > g(n);
    rep(i,n-1){
        int u,v,w; cin >> u >> v >> w;
        u--;v--;
        g[u].push_back({v,w});
        g[v].push_back({u,w});
    }
    vl dists(n,L_INF);
    queue<pair<int,int> > que; //ノード, 総距離
    que.push({0, 0});
    dists[0] = 0;
    while(!que.empty()){
        int node = que.front().first;
        int dist = que.front().second;
        que.pop();
        for(auto nv:g[node]){
            int n_node = nv.first;
            if(dists[n_node] == L_INF){
                dists[n_node] = dist + nv.second;
                que.push({n_node, dist + nv.second});
            }
        }
    }
    rep(i,n){
        out(dists[i] % 2);
    }
}

Measured memory_bytes: 11308
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node {int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d){
    if(u==NIL) return;
    D[u] = d;
    setDepth(T[u].left, d+1);
    setDepth(T[u].right, d+1);
}

int setHeight(int u){
    int h1 = 0, h2 = 0;
    if(T[u].left != NIL)
        h1 = setHeight(T[u].left) + 1;
    if(T[u].right != NIL)
        h2 = setHeight(T[u].right) + 1;
    return H[u] = (h1 > h2 ? h1 : h2);
}

int getSibling(int u){
    if(T[u].parent == NIL) return NIL;
    if(T[T[u].parent].left != u && T[T[u].parent].left != NIL)
        return T[T[u].parent].left;
    if(T[T[u].parent].right != u && T[T[u].parent].right != NIL)
        return T[T[u].parent].right;
    return NIL;
}

void print(int u){
    printf("node %d: ", u);
    printf("parent = %d, ", T[u].parent);
    printf("sibling = %d, ", getSibling(u));
    int deg = 0;
    if(T[u].left != NIL) deg++;
    if(T[u].right != NIL) deg++;
    printf("degree = %d, ", deg);
    printf("depth = %d, ", D[u]);
    printf("height = %d, ", H[u]);
    
    if(T[u].parent == NIL){
        printf("root\n");
    } else if (T[u].left == NIL && T[u].right == NIL){
        printf("leaf\n");
    } else {
        printf("internal node\n");
    }
}

int main(){
    int v, l, r, root = 0;
    scanf("%d", &n);
    
    for(int i=0; i<n; i++) T[i].parent = NIL;
    
    for(int i=0; i<n; i++){
        scanf("%d %d %d", &v, &l, &r);
        T[v].left = l;
        T[v].right = r;
        if(l != NIL) T[l].parent = v;
        if(r != NIL) T[r].parent = v;
    }
    
    for(int i=0; i<n; i++) if (T[i].parent == NIL) root = i;
    
    setDepth(root, 0);
    setHeight(root);
    
    for(int i=0; i<n; i++) print(i);
    
    return 0;
}


Measured memory_bytes: 2768
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;
const ll INF=1e9+7;

int main(void) {
	int n;
	cin >> n;
	vector<int> d(n);
	REP(i, n)cin >> d[i];
	sort(d.begin(),d.end());
	//REP(i, n)cout << d[i] << endl;
	int mid = d.size() / 2;
	int ans = d[mid] - d[mid - 1];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long int;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const ll INF = 1e11;
const ll MOD = 1000000007;
typedef pair<ll,ll> P;
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main(){
    ll n;
    ll a[100005];
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    ll c = a[0];
    rep(i,n-1){
        c = gcd(c,a[i+1]);
    }
    PRINT(c);
}

Measured memory_bytes: 1024
#include<iostream>
#include<utility>
#include<cmath>
#include<vector>
#define FOR(i,a,n) for(int i=a;i<n;i++)
using namespace std;
typedef long long ll;
int Ax[900001],Ay[900001];
int H,W,D;
int Q;
int L[100000],R[100000];
vector<ll> s[900001];
int extmod(int a,int b){
  int res=a%b;
  if(res!=0) return res;
  else return b;
}
int main(){
  cin >> H >> W >> D;
  FOR(i,0,H){
    FOR(j,0,W){
      int a;
      cin >> a;
      Ax[a]=i;Ay[a]=j;
    }
  }
  FOR(i,1,D+1){
    s[i].push_back(0);
    ll n=i,sum=0;
    while(n<=H*W){
      n+=D;
      ll cost=abs(Ax[n]-Ax[n-D])+abs(Ay[n]-Ay[n-D]);
      s[i].push_back(sum+=cost);
    }
  }
  cin >> Q;
  FOR(i,0,Q) cin >> L[i] >> R[i];
  FOR(i,0,Q){
    int j=extmod(L[i],D),k=(L[i]-1)/D,l=(R[i]-1)/D;
    ll res=s[j][l]-s[j][k];
    cout << res << "\n";
  }
  return 0;
}


Measured memory_bytes: 27776
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;

int main() {
    int n;
    cin >> n;
    
    int M = n*(n-1)/2 - n/2;

    cout << M << "\n";

    int x = n;
    if(n%2 == 0) {
        x++;
    }
    
    for(int i = 1; i < n; i++) {
        for(int j = i+1; j <= n; j++) {
            if(i+j == x) {
                continue;
            }
            cout << i << " " << j << "\n";
        }
    }

    return 0;
}

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


int main(){
	ll n;cin>>n;
	vector<ll> a(n);
	vector<int> b(1000005,0);
	for(int i = 0; i < n; i++) {
		cin>>a[i];
		b[a[i]] ++;
	}
	bool pairwise = true;
	for(int i = 2; i < b.size(); i++) {
		int cnt = 0;
		for(int j = i; j < b.size(); j+= i) {
			cnt += b[j];
		}
		if(cnt > 1){
			pairwise = false;
		}
	}
	if (pairwise){
		cout << "pairwise coprime" << endl;
	}
	else {
		ll setwise = a[0];
		for(int i = 1; i < n; i++) {
			setwise = __gcd(setwise,a[i]);
		}
		if (setwise == 1){
			cout << "setwise coprime" << endl;
		}
		else{
			cout << "not coprime" << endl;
		}
	}

	
	return 0;
}

Measured memory_bytes: 14876
#include <stdio.h>
#include <iostream>
#include <queue>
#include <string>
#include <algorithm>
#include <cstdio>
#include <stack>
#include <vector>
#include <map>
#include <ctime>
#include <cmath>
#include <string.h>
#define inf 0x7fffffff
using namespace std;
struct P
{
    int x,y,z;
};
vector<P> v[456];
int a,b,c,n,m,i,k,o[400][400],d,e[400],dy[5]={0,0,-1,1,0},dx[5]={0,1,1,1,2};
int l[400];
long long x[100],y,z;
//double u[20000],p[20000];
int j[200100];
//long long x=0,y=0,z[99];
//char r[10003000];
//deque<int> d;
//'1'==49;
string r,r1;



int main()
{
    scanf("%d %d",&a,&b);
    for(int t=1;t<=a;t++)
        for(int w=1;w<=b;w++)
        scanf("%d",&o[t][w]);
    k=987654;
    for(int t=1;t<=a;l[t]=1,t++);
    for(int u=1;u<=b;u++)
    {
        memset(j,0,sizeof(j));
        for(int t=1;t<=a;t++)
            j[o[t][l[t]]]++;
        int n=0,m;
        for(int t=1;t<=b;t++)
            if(j[t]>n) n=j[t],m=t;
        e[m]=1;
        for(int t=1;t<=a;t++)
        {
            for(;e[o[t][l[t]]];l[t]++);
           // printf("%d ",o[t][l[t]]);
        }
        k=min(k,n);
        //printf("%d\n",n);
    }
    printf("%d",k);
}


Measured memory_bytes: 1536