akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline

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

def main():
    ################
    class UnionFind:
        def __init__(self, N: int):
            """
            N:要素数
            root:各要素の親要素の番号を格納するリスト.
                ただし, root[x] < 0 ならその頂点が根で-root[x]が木の要素数.
            rank:ランク
            """
            self.N = N
            self.root = [-1] * N
            self.rank = [0] * N
    
        def __repr__(self):
            return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
    
        def find(self, x: int) -> int:
            """頂点xの根を見つける"""
            if self.root[x] < 0:
                return x
            else:
                while self.root[x] >= 0:
                    x = self.root[x]
                return x
    
        def union(self, x: int, y: int) -> int:
            """x,yが属する木をunion"""
            # 根を比較する
            # すでに同じ木に属していた場合は何もしない.
            # 違う木に属していた場合はrankを見てくっつける方を決める.
            # rankが同じ時はrankを1増やす
            x = self.find(x)
            y = self.find(y)
            if x == y:
                return
            elif self.rank[x] > self.rank[y]:
                self.root[x] += self.root[y]
                self.root[y] = x
            else:
                self.root[y] += self.root[x]
                self.root[x] = y
                if self.rank[x] == self.rank[y]:
                    self.rank[y] += 1
    
        def same(self, x: int, y: int) -> bool:
            """xとyが同じグループに属するかどうか"""
            return self.find(x) == self.find(y)
    
        def count(self, x):
            """頂点xが属する木のサイズを返す"""
            return - self.root[self.find(x)]
    
        def members(self, x):
            """xが属する木の要素を列挙"""
            _root = self.find(x)
            return [i for i in range(self.N) if self.find == _root]
    
        def roots(self):
            """森の根を列挙"""
            return [i for i, x in enumerate(self.root) if x < 0]
    
        def group_count(self):
            """連結成分の数"""
            return len(self.roots())
    
        def all_group_members(self):
            """{ルート要素: [そのグループに含まれる要素のリスト], ...}の辞書を返す"""
            return {r: self.members(r) for r in self.roots()}
    ################
    
    N,Q=MI()
    uf=UnionFind(N)
    for _ in range(Q):
        t,u,v=MI()
        if t==0:
            uf.union(u,v)
        else:
            ans=0
            if uf.same(u,v):
                ans=1
            print(ans)



main()


Measured memory_bytes: 76108
<?php
$l=(int)trim(fgets(STDIN));
$s=$l%60;
$l-=$s;
$l/=60;
$m=$l%60;
$l-=$m;
$l/=60;
#echo $l.':'.$m.':'.$s."\n";
echo "{$l}:{$m}:{$s}\n";

Measured memory_bytes: 15388
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <queue>
#include <set>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)

using namespace std;
typedef long long int lli;
const int MAX=1e5;

int main(){
	int N;
	cin>>N;
	int a[100];
	rep(i,N) cin>>a[i];
	
	sort(a,a+N);
	cout<<a[N-1]-a[0]<<endl;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <queue>
#include <string>
#define REP(i,n) for(int i = 0; i < (int)n; i++)
using namespace std;

int main(){
  int n;
  cin >> n;
  int p[n];
  REP(i,n){
    cin >> p[i];
  }
  int ans = 0;
  REP(i,n-1){
    if(p[i]==i+1){
      int tmp = p[i+1];
      p[i+1]=p[i];
      p[i]=tmp;
      ans++;
    }
  }
  if(p[n-1]==n) ans++;
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<stdio.h>
int main(void)
{
	int a,s,ss;
	while(1){
		scanf("%d",&a);
		if(a==0)break;
		s=1000-a;
		ss=s/500;
		s=s%500;
		ss+=s/100;
		s=s%100;
		ss+=s/50;
		s=s%50;
		ss+=s/10;
		s=s%10;
		ss+=s/5;
		s=s%5;
		ss+=s/1;
		printf("%d\n",ss);
	}
	return 0;
}

Measured memory_bytes: 1028
a,b,c = map(int, input().split())
k = int(input())

if (a>=b and a>=c) :
    for i in range(k):
        a *= 2
elif (b>a and b>=c):
    for i in range(k):
        b *= 2
else: 
    for i in range(k):
        c *= 2
print(a+b+c)

Measured memory_bytes: 9188
import itertools
inpl = lambda: list(map(int,input().split()))
N, A, B, C = inpl()
L = [int(input()) for _ in range(N)]
ABC = [A,B,C]

ans = 10000
for dist in itertools.product(range(4),repeat=N):
    n = [0]*3
    l = [0]*3
    for i in range(N):
        k = dist[i]
        if k < 3:
            n[k] += 1
            l[k] += L[i]
    for k in range(3):
        if n[k] == 0:
            break
    else:
        p = (sum(n)-3)*10 + sum(abs(ABC[k]-l[k]) for k in range(3))
        if p < ans:
            ans = p
print(ans)

Measured memory_bytes: 46172
#include <stdio.h>

int main(void){
    long long N,M;
    long long ans;
    
    scanf("%lld%lld",&N,&M);
    
    if(N < M/2){
        ans = N;
        M -= 2*N;
        ans += M/4;
    }
    else{
        ans = M/2;
    }
    
    printf("%lld\n",ans);
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output14.txt", "w", stdout);
#endif
	//ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	string s, t;
	cin >> s >> t;
	int n1, n2;
	n1 = s.length();
	n2 = t.length();
	vector<vector<int>> dp(n1 + 1, vector<int>(n2 + 1, 0));
	for (int i = 1; i <= n1; i++)
	{
		for (int j = 1; j <= n2; j++)
		{
			if (s[i - 1] == t[j - 1])
				dp[i][j] = dp[i - 1][j - 1] + 1;
			else
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
		}
	}
	// for (int i = 1; i <= n1; i++)
	// {
	// 	for (int j = 1; j <= n2; j++)
	// 	{
	// 		cout << dp[i][j] << "     ";
	// 	}
	// 	cout << "\n";
	// }
	string ans;
	int m = n1, n = n2;
	while (m > 0 && n > 0)
	{
		if (dp[m][n] == dp[m - 1][n])
			m--;
		else if ((dp[m][n] == dp[m][n - 1]))
			n--;
		else
		{

			ans = s[m - 1] + ans;
			n--;
			m--;
		}
	}
	cout << ans << "\n";
//cout << "\n";
}

Measured memory_bytes: 38940
#include <math.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <climits>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
const int N = 3e5+7 ;
const int INF = 1e18 ;
const int MOD = 1e9 + 7 ;
string s ;

void solve(){
	int n ;
	cin >> n ;
	vector<ii> a(n) ;
	for(int i = 0 ,x,y; i < n ; i++){
		cin >> x >> y ;
		a[i].ff = x-y ;
		a[i].ss = x+y ;
	}
	sort(all(a), [&](ii x,ii y){return x.ss < y.ss ;}) ;
	int cur = -INF ;
	int ans = 0 ;
	for(auto x : a){
		if(cur <= x.ff){
			ans++ ;
			cur = x.ss ;
		}
	}
	cout << ans << endl ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 1792
#include<iostream>

using namespace std;
int main(){
    int a,n,max=-1000001,min=1000001;
    long sum=0;
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> a;
        if (min > a){
            min=a;
        }
        if (max < a){
            max=a;
        }
        sum+=a;
    }
    cout << min << " " << max << " " << sum << endl;
    return 0;
}


Measured memory_bytes: 3108
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Anirudh Rayabharam
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        PalindromicNumber solver = new PalindromicNumber();
        solver.solve(1, in, out);
        out.close();
    }

    static class PalindromicNumber {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int first = n / 100;
            int last = n % 10;
            if (first == last) out.println("Yes");
            else out.println("No");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 21588
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int i = 1;
    vector<int> A;
    while(N - i >= 0) {
        A.push_back(i);
        N -= i;
        i++;
    }
    for(int i = A.size() - 1; N > 0; i--) {
        A[i]++; N--;
    }
    for(auto& e: A) {
        cout << e << endl;
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <queue>
#include <stack>
#include <deque>
#include <climits>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
//#include <tuple>

#define INF INT_MAX>>1 
#define SIZE 100010
#define MOD 1000000007
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rep2(i, from, to) for(int i=(from); i<(int)(to); i++)
#define repr(i, n) for(int i=(n-1); 0<=i; i--)
#define repr2(i, from, to) for(int i=(from-1); (int)(to)<=i; i--)
#define ALL(obj) (obj).begin(), (obj).end()
typedef long long ll;

using namespace std;

struct Point { int x, y; };
struct Edge { int to, cost; };
struct Node { int from, to, cost; };

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

int gcd(int a, int b){ return a % b == 0 ? b : gcd(b, a%b); }
int lcm(int a, int b){ return a * b/ gcd(a, b); }
int extgcd(int a, int b, int& x, int& y){
	int d = a;
	if(b != 0){
		d = extgcd(b, a%b, y, x);
		y -= (a/b) * x;
	} else{
		x = 1; y = 0;
	}
	return d;
}

class UnionFind {
public:
	vector <ll> par; // 親
	vector <ll> rank; // 木の深さ
	ll numComponent;
	void init(ll n) {
		par.resize(n);
		rank.assign(n, 1LL);  // resize だとなぜか初期化されなかった
		for(ll i = 0; i < n; ++i) par[i] = i; // 初期では親は自分自身
		numComponent = n;
	}

	ll findRoot(ll x) {
		if(par[x] == x) return x;
		else return par[x] = findRoot(par[x]);
	}

	void unite(ll x, ll y) {
		x = findRoot(x);
		y = findRoot(y);
		if(x == y) return;
		if(rank[x] < rank[y]) swap(x, y);
		rank[x] += rank[y];
		par[y] = x;
		numComponent--;
		return;
	}

	bool issame(ll x, ll y){
		return findRoot(x) == findRoot(y);
	}

	ll size(ll x) {
		return rank[findRoot(x)];
	}

	ll count(){
		rep(i, par.size()){

		}
	}
};


int main(void){
	int n, m; cin >> n >> m;
	UnionFind unionFind;
	unionFind.init(n);
	rep(i, m){
		int x, y, z; cin >> x >> y >> z;
		x--; y--;
		unionFind.unite(x, y);
	}
	cout << unionFind.numComponent << endl;

	return 0;
}

Measured memory_bytes: 1792
struct Rin{}
impl Rin{
    fn input(&self)->String{
        let mut x=String::new();
        std::io::stdin().read_line(&mut x).ok();
        x
    }
    fn inputs(&self)->String{
        let s=self.input().trim().to_string();
        s
    }
    fn inputn(&self)->i32{
        let n:i32=self.input().trim().parse().unwrap();
        n
    }
    fn inputvs(&self)->Vec<String>{
        let vs=self.input().trim().split(' ').map(|x|x.to_string()).collect();
        vs
    }
    fn inputvn(&self)->Vec<i32>{
        let vn=self.input().trim().split(' ').map(|x|x.to_string().parse().unwrap()).collect();
        vn
    }
}

fn main(){
    let rin=Rin{};
    let v=rin.inputvn();
    let s=v[0];
    let w=v[1];
    if s<=w{
        println!("unsafe");
    }else{
        println!("safe");
    }
}

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

int x[501],a[250001];
vector<int> l[501],r[501];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>x[i],a[x[i]]=i;
	set<int> st;
	for(int i=1;i<=n;i++)
		st.insert(x[i]);
	for(int i=1;i<=n*n;i++){
		if(st.count(i))	continue;
		int z=-1;
		for(int j=1;j<=n;j++)
			if((int)l[j].size()<=j-2&&i<x[j])
				if(z==-1||x[j]<x[z])
					z=j;
		if(z!=-1){
			l[z].emplace_back(i);
			continue;
		}
		for(int j=1;j<=n;j++)
			if((int)r[j].size()<=n-j-1&&i>x[j])
				z=j;
		if(z==-1){
			cout<<"No"<<endl;
			return 0;
		}
		r[z].emplace_back(i);
	}
	for(int i=1;i<=n;i++){
		for(int it:l[i])
			a[it]=i;
		for(int it:r[i])
			a[it]=i;
	}
	cout<<"Yes"<<endl;
	for(int i=1;i<=n*n;i++)
		cout<<a[i]<<' ';
	cout<<endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <algorithm>
#include <cmath>
#include <set>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;

#define for(i, a, b) for(ll (i)=a;(i)<(b);++(i))
#define rep(i, n)    for(i, 0, n)
#define sz(x)        ((ll)(x).size())
#define inf          1<<25

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; }

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

int main() {
    string n;
    cin >> n;
    
    int fx = 0;
    rep(i, sz(n)) fx += n[i] - '0';
    
    cout << (stoi(n) % fx == 0 ? "Yes" : "No") << endl;
    
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    import math

    A, B, H, M = map(int, input().split())

    h = H*30 + M*0.5
    ay = math.sin(math.radians(h)) * A
    ax = math.cos(math.radians(h)) * A

    bx = math.cos(math.radians(M*6)) * B
    by = math.sin(math.radians(M*6)) * B

    print(math.sqrt((ax-bx)**2 + (ay-by)**2))


if __name__ == "__main__":
    main()


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

// grid
//--------------------------------------------
VL dx = {0, 1, 0, -1};
VL dy = {1, 0, -1, 0};
VL dx2 = {-1, 0, 1, -1, 1, -1, 0, 1};
VL dy2 = {-1, -1, -1, 0, 0, 1, 1, 1};

//debug
//--------------------------------------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//IO accelerate
//--------------------------------------------
struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

//template
//--------------------------------------------
template<typename T>
istream& operator >>(istream& is, vector<T>& vec) {
  for(T& x: vec) is >> x;
  return is;
}
template<typename T>
ostream& operator <<(ostream& os, const vector<T>& vec) {
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : "\t" );
  }
  return os;
}
template<typename T>
ostream& operator <<(ostream& s, const vector<vector<T>>& vv) {
	for (int i = 0; i < vv.size(); ++i) {
		s << vv[i] << endl;
	}
	return s;
}

// 多重vector
// auto dp=make_v<int>(4,h,w) みたいに使える
template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// 多重vectorのためのfill
// fill_v(dp,0) みたいに使える
template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
  for(auto &e:t) fill_v(e,v);
}

//main code

int main(int argc, char const* argv[])
{
	LL n;
	cin >> n;
	cout << n*(n+1)/2 - n << endl;
	return 0;
}


Measured memory_bytes: 256
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>

using namespace std;

int main(void) {
    int N;
    cin>>N;
    string S;
    int a=0;
    int b=0;
    int c=0;
    int d=0;
    for(int i=0;i<N;i++){
        cin>>S[i];
        if(S[i]=='P'){

            a++;
        }
        else if(S[i]=='W'){

            b++;
        }
        else if(S[i]=='G'){

            c++;
        }
        else if(S[i]=='Y'){
            d++;

        }
    }

    if(a==0||b==0||c==0||d==0){

        cout<<"Three"<<endl;

    }
    else{
        cout<<"Four"<<endl;
    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;
    return 0;
}




Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int main() {
  string A;
  cin >> A;
  int X = 0;
  for(int i = 0; i < 4; i++) { 
    if(A.at(i) == '2') {
      X++;
    }
  }
  cout << X << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;

#define modp(x, y) (((y) + (x) % (y)) % (y))
template<typename T> inline T gcd(T x, T y) { if(x < y) swap(x, y); T mod = x % y; if(mod == 0) return y; return gcd(y, mod); }
template<typename T> inline T lmc(T x, T y) { return x / gcd(x, y) * y; }

int N;
int num[13];

int rec(int i, int bit)
{
	if (i == 13) {
		int ret = iinf;
		int d = iinf;
		for (int j = 0; j < 48; j++) {
			if (bit & (1 << (j % 24))) {
				ret = min(ret, d);
				d = 0;
			}
			d++;
		}
		return ret;
	}

	switch(num[i]) {
		case 0:
			return rec(i + 1, bit);
		case 1:
			return max(rec(i + 1, bit | (1 << i)), rec(i + 1, bit | (1 << (24 - i))));
		case 2:
			return rec(i + 1, bit | (1 << i) | (1 << (24 - i)));
	}
	return 0;
}

int main(int argc, char* argv[])
{
	scanf("%d", &N);
	num[0]++;
	for (int i = 0; i < N; i++) {
		int m; scanf("%d", &m);
		num[m]++;
		if (num[m] >= 3 || m == 0) {
			printf("0\n");
			return 0;
		}
	}

	printf("%d\n", rec(1, 1));

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

ll lcm(ll c, ll d)
{
    ll a1, a2, r;
    a1 = max(c, d);
    a2 = min(c, d);

    r = a1 % a2;
    while(r != 0)
    {
        a1 = a2;
        a2 = r;
        r = a1 % a2;
    }
    return c * d / a2;
}
int main()
{
    ll a, b, c, d, ans;
    cin >> a >> b >> c >> d;

    ll a_cnt = ((a-1) / c) + ((a-1) / d) - ((a-1) / lcm(c, d));
    ll b_cnt = (b / c) + (b / d) - (b / lcm(c, d));
    // if(a % c == 0 || a % d == 0) a_cnt--;

    ans = (b - a) + 1 - (b_cnt - a_cnt);
    cout << ans << endl;
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
const ll INF=mod*mod;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define all(x) (x).begin(),(x).end()
ll min(ll a,ll b){
  if(a>b){
    return b;
    }
      else{
        return a;
      }
  }
  
  ll max(ll a,ll b){
    if(a>b){
      return a;
    }
    else{
      return b;
    }
  }

ll power(ll a,ll b){
 ll ans=1;
 for(ll i=1;i<=b;i++){
ans*=a;
  }
  return ans;
}

 ll gcd(ll m,ll n){
 	if(n==0){
       return m;
     }
   return gcd(n,m%n);
 }
ll lcm(ll a,ll b){
  ll g=gcd(a,b);
  return a/gcd(a,b)*b;
		

}

ll N;
vector<ll>S;

void dfs(ll a,ll b,ll c,ll d){
  if(d>N){
return;
  }


    dfs(a+1,b,c,d*10+3);
    dfs(a,b+1,c,d*10+5);
    dfs(a,b,c+1,d*10+7);  
   if(a>0&&b>0&&c>0){
S.push_back(d);
  }

}
int main(){
  
  cin>>N;
  
  dfs(0,0,0,0);
 
  
  cout<<S.size()<<endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

void solve() {
    string n;
    cin >> n;
    ll cnt = 0;
    REP(i, n.size()) {
        cnt += (n[i] - '0');
        cnt %= 9;
    }
    if (cnt == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}



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

int main(){
   
    map<int,int> A;
    bool ans=true;
    for(int i=0;i<6;i++){
        int a;cin>>a;
        A[a]++;
        if(A[a]==3) ans=false;
    }
    if(ans) cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

int w, d, h[2][10], m[10][10];
bool used[2][10];

void debug(){
	puts("[debug]");
	printf("  ");
	for(int x=0 ; x < w ; x++ ){
		printf("%2d", h[0][x]);
	}
	puts("");
	for(int y=0 ; y < d ; y++ ){
		for(int x=0 ; x < w ; x++ ){
			if( x == 0 ){
				printf("%2d", h[1][y]);
			}
			printf("%2d", m[y][x]);
		}
		puts("");
	}
	puts("");
}

// m[y][0..w-1] テ」ツ?ォ height テ、ツサツ・テ、ツクツ甘」ツ?ョテゥツォツ佚」ツ?陛」ツ?ョテ」ツδ姪」ツδュテ」ツδε」ツつッテ」ツ?古・ツュツ佚・ツ慊ィテ」ツ?凖」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ??
bool is_higher_y(int y, int height){
	for(int x=0 ; x < w ; x++ ){
		if( height <= m[y][x] ) return true;
	}
	return false;
}

// m[0..d-1][x] テ」ツ?ォ height テ、ツサツ・テ、ツクツ甘」ツ?ョテゥツォツ佚」ツ?陛」ツ?ョテ」ツδ姪」ツδュテ」ツδε」ツつッテ」ツ?古・ツュツ佚・ツ慊ィテ」ツ?凖」ツつ凝」ツ?凝」ツ?ゥテ」ツ??」ツ??
bool is_higher_x(int x, int height){
	for(int y=0 ; y < d ; y++ ){
		if( height <= m[y][x] ) return true;
	}
	return false;
}

int main(){
	while( cin >> w >> d, w || d ){
		// テ・ツ按敕ヲツ慊淌・ツ個?
		for(int i=0 ; i < 10 ; i++ ){
			used[0][i] = used[1][i] = false;
			for(int j=0 ; j < 10 ; j++ ){
				m[i][j] = 0;
			}
		}
		
		// テ・ツ?・テ・ツ環?
		for(int i=0 ; i < w ; i++ ){
			cin >> h[0][i];
		}
		for(int i=0 ; i < d ; i++ ){
			cin >> h[1][i];
		}
		sort(h[0], h[0] + w);
		sort(h[1], h[1] + d);
		reverse(h[0], h[0] + w);
		reverse(h[1], h[1] + d);
		
		int ans = 0;
		for(int y=0 ; y < d ; y++ ){
			// h[1][y] テ」ツ?ィテ・ツ青古」ツ?佚ゥツォツ佚」ツ?陛」ツ?ョテ」ツつづ」ツ?ョテ」ツつ?h[0][0..w-1] テ」ツ?凝」ツつ嘉ヲツ篠「テ」ツ??
			bool flag = false;
			for(int x=0 ; x < w ; x++ ){
				if( used[0][x] ) continue;
				
				if( h[1][y] == h[0][x] ){
					flag = true;
					m[y][x] = h[1][y];
					ans += h[1][y];
					used[1][y] = used[0][x] = true;
				}
				if( flag ) break;
			}
			if( !used[1][y] ){
				for(int x=0 ; x < w ; x++ ){
					if( h[1][y] == h[0][x] ){
						flag = true;
						m[y][x] = h[1][y];
						ans += h[1][y];
						used[1][y] = used[0][x] = true;
					}
					if( flag ) break;
				}
			}
		}
		// h[0][0..w-1] テ」ツ?ァテ」ツ?セテ」ツ??ァツ「ツコテ・ツョツ堙」ツ?療」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツδ姪」ツδュテ」ツδε」ツつッテ」ツつ津ヲツ篠「テ」ツ??
		for(int x=0 ; x < w ; x++ ){
			if( used[0][x] ) continue;
			
			bool flag = false;
			for(int y=0 ; y < d ; y++ ){
				if( is_higher_y(y, h[0][x]) ){
					flag = true;
					m[y][x] = h[0][x];
					ans += h[0][x];
					used[0][x] = true;
				}
				if( flag ) break;
			}
		}
		// h[1][0..d-1] テ」ツ?ァテ」ツ?セテ」ツ??ァツ「ツコテ・ツョツ堙」ツ?療」ツ?ヲテ」ツ??」ツ?ェテ」ツ??」ツδ姪」ツδュテ」ツδε」ツつッテ」ツつ津ヲツ篠「テ」ツ??
		for(int y=0 ; y < d ; y++ ){
			if( used[1][y] ) continue;
			
			bool flag = false;
			for(int x=0 ; x < w ; x++ ){
				if( is_higher_x(x, h[1][y]) ){
					flag = true;
					m[y][x] = h[1][y];
					ans += h[1][y];
					used[1][y] = true;
				}
				if( flag ) break;
			}
		}
		//debug();
		cout << ans << endl;
	}
}

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

#define ll long long
#define ld long double
#define db double
#define pb push_back
#define nl '\n'
#define X first
#define Y second
#define nimble ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v) (v).begin(),(v).end()
#define mod(x,m) ((((x)%(m))+(m))%(m))
#define _sz(x) (int)x.size()
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(v) for(int i=0;i<_sz(v);i++)
#define rep1(i,b,a) for(int i=b;i>=a;i--)
#define preci(x) fixed<<setprecision(x)
#define tc int tt=1;cin>>tt;while(tt--)

#define TRACE
#ifdef TRACE
#define see(...) __f(#__VA_ARGS__,__VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr<<name<<" : "<<arg1<<nl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma=strchr(names+1,',');cerr.write(names,comma-names)<<" : "<<arg1<<" | ";__f(comma+1, args...);
}
#else
#endif

int inf=0x3f3f3f3f;
ll infl=0x3f3f3f3f3f3f3f3fLL;
ld infd=1.0/0.0;
const ll MOD=1e9+7;// 998244353 // = (119<<23)+1
const ld pi=2*acos(0.0);

int main(){
    nimble;
    int n;
    cin>>n;
    vector<ll> a(n);
    rep(i,0,n)cin>>a[i];
    ll as=0;
    vector<ll> pre(n,0);
    pre[0]=a[0];
    rep(i,1,n){
        pre[i]=(pre[i-1]+a[i])%MOD;
    }
    rep(i,0,n-1){
        as+=(a[i]*(pre[n-1]-pre[i]))%MOD;
        as=(as+MOD)%MOD;
    }
    cout<<as;
    return 0;
}



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

static const int MOD=1000000007;
typedef long long ll;

ll solve(int n){
    if(n==1) return 1;
    else return n*solve(n-1)%MOD;
}

int main(){
    int N,M;
    cin >> N >> M;
    ll ans;
    if(N==M){
        ll ans=solve(N)*solve(M)*2;
        ans%=MOD;
        cout << ans << endl;
    }else if(N-1==M||M-1==N){
        ll ans=solve(N)*solve(M);
        ans%=MOD;
        cout << ans << endl;
    }else{
        cout << 0 << endl;
    }
}

Measured memory_bytes: 1792
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int main(void){
	int n,k;
	scanf("%d%d",&n,&k);
	if(k==1)puts("0");
	else printf("%d\n",n-k);
	return 0;
}






Measured memory_bytes: 256
#include <iostream>
using namespace std;
int gcd(int a, int b) {
    if(a == 1 || b == 1)return 1;
    if (b==0) return a;
    else return gcd(b, a%b);
}
int main(){
    int K = 0;
    cin >> K;
    int result = 0;
    for(int a = 1;a <= K;a++){
        for(int b = 1;b <= K; b++){
            for(int c = 1;c <= K; c++){
                result += gcd(a,gcd(b,c));
            }
        }
    }
    cout << result << '\n';
    return 0;
}

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

#define PI 4*atan(1)
#define INF 1e8

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

int main(){
  int A, B;
  cin >> A >> B;
  cout << (A + B) % 24 << endl;
}


Measured memory_bytes: 256
import math
import bisect


# 素数判定関数
def isPrime(num):
    # 2未満の数字は素数ではない
    if num < 2: return False
    # 2は素数
    elif num == 2: return True
    # 偶数は素数ではない
    elif num % 2 == 0: return False

    # 3 ~ numまでループし、途中で割り切れる数があるか検索
    # 途中で割り切れる場合は素数ではない
    for i in range(3, math.floor(math.sqrt(num))+1, 2):
        if num % i == 0:
            return False

    # 素数
    return True

# 素数判定
def callIsPrime(input_num=100000):
    numbers = []
    # ループしながら素数を検索する
    for i in range(1, input_num):
        if isPrime(i):
            numbers.append(i)

    # 素数配列を返す
    return numbers

# 関数の呼び出し
l = callIsPrime(100000)
#print(l)
#print(len(l))

ll = []
for i in range(len(l)):
    if (l[i]+1)//2 in l:
        ll.append(l[i])


Q = int(input())
l = [0] * Q
r = [0] * Q
for i in range(Q):
    l[i], r[i] = map(int, input().split())
for i in range(Q):
    a = bisect.bisect_left(ll,l[i])
    b = bisect.bisect_right(ll,r[i])
    print(b-a)


Measured memory_bytes: 11796
#include <bits/stdc++.h>
#define Inf 0x3f3f3f3f
#define rg register
#define pii pair<int, int>
#define mp(x, y) make_pair(x, y)
using namespace std;
typedef long long ll;
const int Maxn = 2e5 + 5;
typedef int arr[Maxn];
//ll Add(ll x, ll y) { return (x += y) >= Mod ? x - Mod : (x < 0 ? x + Mod : x); }
ll min(ll x, ll y) { return x < y ? x : y; }
ll max(ll x, ll y) { return x > y ? x : y; }
inline ll read()
{
	rg ll res = 0, sign = 1;
	rg char ch = getchar();
	while (!isdigit(ch))
	{
		if (ch == '-')
			sign = -1;
		ch = getchar();
	}
	do
	{
		res = (res << 3) + (res << 1) + (ch ^ 48);
		ch = getchar();
	} while (isdigit(ch));
	return res * sign;
}
int n, tot;
arr fa, deep;
int Max[Maxn][2], sum[Maxn];
ll ans;
char s[Maxn];
vector<int> to[Maxn];
void Add(int x, int p)
{
	if (deep[p] + 1 > deep[Max[x][1]])
	{
		if (deep[p] + 1 > deep[Max[x][0]])
		{
			Max[x][1] = Max[x][0];
			Max[x][0] = p;
			deep[x] = deep[Max[x][0]] + 1;
		}
		else
			Max[x][1] = p;
	}
}
void DFS(int x)
{
	for (rg int i = 0, nx; i < to[x].size(); i++)
	{
		nx = to[x][i];
		if (nx == fa[x])
			continue;
		fa[nx] = x;
		DFS(nx);
		sum[x] += sum[nx];
		Add(x, nx);
	}
}
void Solve(int x)
{
	if (to[x].size() == 1)
		ans += (s[x] == '1') * (1 + (n > 2));
	else
	{
		rg int Min;
		ans += Min = min(deep[x], deep[Max[x][1]] + 3);
		if (s[x] == '0')
		{
			for (rg int i = 0, nx; i < to[x].size(); i++)
			{
				nx = to[x][i];
				if (!sum[nx])
					continue;
				if (deep[nx] < Min)
					Min = deep[nx] + 1;
			}
			ans -= Min;
		}
	}
	rg int tmp;
	for (rg int i = 0, nx; i < to[x].size(); i++)
	{
		nx = to[x][i];
		if (nx == fa[x])
			continue;
		sum[x] = tot - sum[nx];
		tmp = deep[nx];
		deep[x] = deep[Max[x][Max[x][0] == nx]] + 1;
		Add(nx, x);
		Solve(nx);
		deep[nx] = tmp;
	}
}
int main()
{
	deep[0] = -1;
	rg int a, b, tmp;
	cin >> n;
	for (int i = 1; i < n; i++)
	{
		a = read();
		b = read();
		to[a].push_back(b);
		to[b].push_back(a);
	}
	cin >> s + 1;
	if (n == 1)
	{
		printf("%c\n", s[1]);
		return 0;
	}
	for (int i = 1; i <= n; i++)
		tot += sum[i] = s[i] == '1';
	if (!tot)
	{
		puts("0");
		return 0;
	}
	DFS(1);
	Solve(1);
	cout << ans + 1 << '\n';
	return 0;
}


Measured memory_bytes: 27136
n_s = input()
n = int(n_s)


def dfs(s):
    if int(s) > n:
        return 0
    ret = 1 if all(s.count(c) > 0 for c in '753') else 0
    for c in '753':
        ret += dfs(s + c)
    return ret


print(dfs("0"))


Measured memory_bytes: 2940
#include<iostream>
using namespace std;
int n,a;
int t[7],u[2];

bool v[7][7];
bool ud[7],vd[7];

void dfs(int pos){
  if(vd[pos]==true)return;
  vd[pos]=true;
  for(int i=0;i<7;i++){
    if(v[pos][i]==false)continue;
    dfs(i);
  }
}

bool check(){
  for(int i=0;i<7;i++)vd[i]=false;
  for(int i=0;i<7;i++)if(t[i]>0){dfs(i);break;}
  for(int i=0;i<7;i++){
    if(t[i]>0&&vd[i]==false)return false;
  }
  return true;
}

int main(){
  while(cin>>n){
    for(int i=0;i<7;i++)t[i]=0;
    for(int i=0;i<7;i++)for(int j=0;j<7;j++)v[i][j]=false;

    u[0]=u[1]=0;
    for(int i=0;i<n;i++){
      cin>>a;
      t[a/10]++;
      t[a%10]++;
      v[a/10][a%10]=v[a%10][a/10]=true;
    }

    for(int i=0;i<7;i++)if(t[i]>0)u[t[i]%2]++;    
    
    if((u[1]==2||u[1]==0)&&check())cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
  return 0;
}

Measured memory_bytes: 1152
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

a,b,c = inpl()
x = inpln(a)
y = inpln(b)
z = inpln(c)

def f(x,y,q):
    res = INF
    qq = []
    cs = bisect.bisect_left(x,q)
    if cs == 0:
        dist = abs(q - x[0])
        qq.append((x[0],dist))
    elif cs == len(x):
        dist = abs(q - x[-1])
        qq.append((x[-1],dist))
    else:
        qq.append((x[cs],abs(q - x[cs])))
        qq.append((x[cs-1],abs(q - x[cs-1])))
    # if q == 2000:
    #     print(qq,cs)
    while qq:
        now, dist = qq.pop()
        cs = bisect.bisect_left(y,now)
        # print(cs)
        if cs == 0:
            res = min(res,dist+abs(now - y[0]))
        elif cs == len(y):
            res = min(res,dist+abs(now - y[-1]))
        else:
            res = min(res,dist+abs(now - y[cs]))
            res = min(res,dist+abs(now - y[cs-1]))
    return res

for q in z:
    print(min(f(x,y,q),f(y,x,q)))



Measured memory_bytes: 123736
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////

int main() {
    int n; cin >> n;
    vector<vector<int>> a(n, vector<int>(n-1));
    rep(i,n) rep(j,n-1) {
        cin >> a[i][j];
        a[i][j]--;
    }
    rep(i,n) reverse(a[i].begin(), a[i].end());

    typedef pair<int, int> P;
    vector<P> que;
    auto make = [&](int me) -> void {
        if (a[me].size()==0) return;
        int you = a[me].back();
        if (a[you].back() == me) {
            que.emplace_back(me, you);
            if (que.back().first > que.back().second) {
                swap(que.back().first, que.back().second);
            }
        }
    };

    rep(i,n) {
        make(i);
    }

    int ans = 0;
    while (!que.empty()) {
        ans++;
        sort(que.begin(), que.end());
        que.erase(unique(que.begin(), que.end()), que.end());
        vector<P> cp;
        swap(que, cp);
        for (auto v : cp) {
            int i = v.first, j = v.second;
            a[i].pop_back();
            a[j].pop_back();
        }
        for (auto v : cp) {
            int i = v.first, j = v.second;
            make(i);
            make(j);
        }
    }
    rep(i,n) {
        if (a[i].size()) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
#define eprintf(...) 42
#endif

int main()
{

    lint n;
    cin >> n;

    string s;
    cin >> s;

    lint ans=0, tmp;
    lint u=0, d=0, r=0, l=0;

    REP(i, n) {
        if(s[i]<='M'){
            u += 1;
        }else if (s[i] <= 'Z'){
            d += 1;
        }
        else if (s[i] <= 'm')
        {
            r += 1;
        }
        else
        {
            l += 1;
        }
    }


    cout << abs(u-d)+abs(r-l) << "\n";
    string a, b;
    if(u>d)
        a = "A";else
        a = "Z";
    if(r>l)
        b = "a";
    else
        b = "z";

    REP(i, abs(u - d))
    cout << a;
    REP(i, abs(r - l))
    cout << b ;

    cout <<"\n";

    return 0;
}


Measured memory_bytes: 3304
#include <bits/stdc++.h>
using namespace std ;
 
#define lli long long int
#define pb push_back 
 
int main ()
{
    ios_base::sync_with_stdio(false) ; 
    cin.tie(NULL) ;

    string s ;
    cin >> s ;

    if (s[0] == 'A' && s[1] == 'A' && s[2] == 'A')
    {
        cout << "No\n" ;
    }
    else if (s[0] == 'B' && s[1] == 'B' && s[2] == 'B')
    {
        cout << "No\n" ;
    }
    else 
    {
        cout << "Yes\n" ;
    }
    return 0 ;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <climits>
#include <cmath>
#include <complex>
#include <cstring>
#include <deque>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <cstdint>
using namespace std;
typedef long long ll;
#define MP make_pair
#define PB push_back
#define inf 1000000007
#define mod 1000000007
#define rep(i,n) for(int i = 0; i < (int)(n); ++i)

int main(){
    int h,w,n;
    cin >> h >> w >> n;
    if(h<w)swap(h,w);
    for(int i=1;i<=n;i++){
        if(i*h>=n){
            cout << i << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 888
#include <stdio.h>
int main(){
    int sizu, v;
    int i, j, k;

    scanf("%d",&sizu);
    int A[sizu];

    for(j = 0; j < sizu; j++){
        scanf("%d",&A[j]);
    }

    for(j = 1; j < sizu; j++){
        v = A[j];
        i = j - 1;

        for(k = 0; k < sizu; k++ ){
            if(k+1 == sizu){
                printf("%d\n",A[k]);
            }else{
                printf("%d ",A[k]);
            }
        }
        
        while( i >= 0 && (A[i] > v)){
            A[i+1] = A[i];
            i = i - 1;
        }
	    A[i+1] = v;
    }

    for(k = 0; k < sizu; k++ ){
        if(k+1 == sizu){
            printf("%d\n",A[k]);
        }else{
            printf("%d ",A[k]);
        }
    }

    return 0;
}



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

n,m = map(int,input().split())
edges = [[] for _ in range(n)]
edges2 = [0] * n

dis = [0] * n

for _ in range(m):
    x,y = map(int,input().split())
    edges[y-1].append(x-1)
    edges2[x-1] += 1
    dis[x-1] = -1

q = []

for i in range(n):
    if dis[i] == 0:
        q.append(i)

while q:
    l = q.pop(0)
    for i in edges[l]:
        dis[i] = max(dis[i], dis[l] + 1)
        edges2[i] -= 1
        if edges2[i] == 0:
            q.append(i)

print(max(dis))


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

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

using namespace std;

using ll = long long;

using P = pair<int,int>;


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


cout << (n+1)/2<<endl ;
  return 0;

}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const long long INF = 1LL << 60;
const ll MOD = 1000000007;
using pint = pair<ll, ll>;

int main(){
    ll N;
    string S;
    cin >> N;
    cin >> S;
    ll left = 0, right = 0;
    for (int i = 0; i < N; i++){
      if (S[i] == 'W') left++;
      else
        right++;
    }

    ll tmpl = 0, tmpr = 0;
    ll cnt = INF;
    for (int i = 0; i < N; i++) {
      if (S[i] == 'W')
        tmpl++;
      else
        tmpr++;
      if(S[i]=='W'){
        cnt = min(cnt, right - tmpr + tmpl - 1);
      }
      else{
        cnt = min(cnt, tmpl + right - tmpr);
      }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3900
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)

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

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

    int n;
    cin>>n;
    vector<int> as(n);
    rep(i, n) cin>>as[i];

    int q;
    cin>>q;
    rep(i, q) {
        int b, m, e;
        cin>>b>>m>>e;

        rotate(as.begin() + b, as.begin() + m, as.begin() + e);
    }
    rep(i, n) cout<<as[i]<<((i != n - 1) ? ' ' : '\n');
}


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

int h,w,n;
int maps[1001][1001];
int home[1001][1001];
int main(void){
  scanf("%d%d%d",&h,&w,&n);
  while(h!=0){
    memset(maps,0,sizeof(maps));
    memset(home,0,sizeof(home));
    int i,j;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	scanf("%d",&(maps[i][j]));
      }
    }
    home[0][0]=n-1;
    int a;
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	if(home[i][j]%2==1){
	  a=(home[i][j]-1)/2;
	  home[i+1][j]+=a;
	  home[i][j+1]+=a;
	  if(maps[i][j]==1){
	    maps[i][j]=0;
	    home[i][j+1]++;
	  }
	  else{
	    maps[i][j]=1;
	    home[i+1][j]++;
	  }
	}
	else{
	  a=home[i][j]/2;
	  home[i+1][j]+=a;
	  home[i][j+1]+=a;
	}
      }
    }
    int ansi=0,ansj=0;
    while(ansi<h && ansj<w){
      if(maps[ansi][ansj]==1){
	ansj++;
      }
      else{
	ansi++;
      }
      //printf("%d\x0020%d\n",ansi+1,ansj+1);
    }
    printf("%d\x0020%d\n",ansi+1,ansj+1);
    scanf("%d%d%d",&h,&w,&n);
  }
  return 0;
}

Measured memory_bytes: 8864
/*
	Swamy Saranam

	Date	: 14/01/2018 12:41:19
	Author	: Krishna Mohan A M
	Problem	:
	Status	:
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int>	pii;
typedef pair<ld,ld>	pdd;
typedef vector<int> vi;
typedef vector<ld> vd;
typedef pair<ll,ll> pll;

#define FASTIO                ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FOR(i,a,b)            for(int i=(a);i<(b);i++)
#define REP(i,n)              FOR(i,0,n)
#define SORT(v)               sort((v).begin(),(v).end())
#define UN(v)                 SORT(v),(v).erase(unique((v).begin(),(v).end()),(v).end())
#define CL(a,b)               memset(a,b,sizeof a)
#define PB                    push_back
#define F                     first
#define S                     second

const int MOD = 1000000007;

ll n, k, tmp, mx;
set<ll> st;
bool pos;

int main()
{
      FASTIO
      cin>>n>>k;
      st.insert(0);
      REP(i, n){
            cin>>tmp;
            mx = max(tmp, mx);
            st.insert(tmp);
      }
      pos = false;
      // cout<<mx<<" : "<<k<<"\n";
      if(k <= mx){
            for(ll it : st){
                  if(it>=k)
                        break;
                  if(st.count(k-it)){
                        pos = true;
                        break;
                  }
            }
      }
      if(pos)
            cout<<"POSSIBLE\n";
      else
            cout<<"IMPOSSIBLE\n";
      return 0;
}


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

int main(){
 int N;
 cin >> N;
 
 vector <int> A(N-1);
 
 for(int i=0; i<N-1; i++){cin >> A.at(i);} //列Aの記入
 vector <int> B(N);
 for(int i=0; i<N; i++){B.at(i)=0;} //列Bの初期値を0に
 for(int i=0; i<N-1; i++){B.at(A.at(i)-1)++;}
 for(int i=0; i<N; i++){cout << B.at(i) << endl;}
}
 

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

//GCD
long gcd(long a, long b)
{
  if (b == 0)
    return a;
  return gcd(b, a % b);
}

int main() {
  int n;
  cin >> n;
  long t[n];
  for (int i=0; i<n; i++)
    cin >> t[i];
  long ans = t[0];
  for (int i=1; i<n; i++) {
    long g = gcd(ans, t[i]);
    ans = ans/g * t[i];
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    vi a(3);
    REP(i, 3) cin >> a[i];

    sort(ALL(a));

    if (a[0] != a[1]) print(a[0]);
    else print(a[2]);



}

Measured memory_bytes: 3648