akhauriyash/Code-Regression huggingface dataset:
N = int(input())
S = []
judge = 0
for i in range(N):
    S += [input().split()]
for i in range(N):
    if i <= N-3:
        if S[i][0] == S[i][1]:
            if S[i+1][0] == S[i+1][1]:
                if S[i+2][0] == S[i+2][1]:
                    print("Yes")
                    judge = 1
                    break
if judge == 0:
    print("No")


Measured memory_bytes: 9116
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c,d,i,j;
	cin>>a>>b;
	if(a>0&&b>0){
		cout<<"Positive"<<endl;
	}
	else if(a<0&&b<0){
		if(abs(a-b-1)%2==0){
			cout<<"Positive"<<endl;
		}
		else{
			cout<<"Negative"<<endl;
		}
	}
	else{
		cout<<"Zero"<<endl;
	}
	return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define ll long long
static const int MAX = 10000;
static const ll INFTY = 1e12;

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 ll MRINF = 5000000000000000;

int main() {

    int H, W, K;
    cin >> H >> W >> K;
    string c[10] = {""};
    REP(i, H)REP(j, W)cin >> c[i][j];
    ll ans = 0;

    // {0, 1, ..., n-1} の部分集合の全探索
    for (int bit = 0; bit < (1<<H); ++bit) {
        vector<int> S(H, 0);
        for (int i = 0; i < H; ++i) {
            if (bit & (1<<i)) { // 列挙に i が含まれるか
                S[i] = 1;
            }
        }
        

        for (int bit = 0; bit < (1<<W); ++bit) {
            vector<int> S2(W, 0);
            for (int i = 0; i < W; ++i) {
                if (bit & (1<<i)) { // 列挙に i が含まれるか
                    S2[i] = 1;
                }
            }
            ll count = 0;

            REP(j, H){
                REP(k, W){
                    if(S[j] == 1 && S2[k] == 1){
                        if(c[j][k] == '#')count++;
                    }
                }
            }
            // cout << count << endl;
            if(count == K)ans++;
        }

    }

    cout << ans << endl;


}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using P = pair<ll,ll>;

int main() {
    ll N;
    cin >> N;
    vector<vector<P>> tree(N);
    for(int i=0;i<N-1;i++){
        int a,b,c;
        cin >> a >> b >> c;
        --a;--b;
        tree[a].push_back(P(b,c));
        tree[b].push_back(P(a,c));
    }
    vector<ll> d(N,-1);
    ll Q,K;
    cin >> Q >> K;
    d[K-1]=0;
    queue<int> q;
    q.push(K-1);
    while(!q.empty()){
        int t = q.front();q.pop();
        for(P p:tree[t]){
            if(d[p.first] ==-1){
                d[p.first] = d[t] + p.second;
                q.push(p.first);
            }
        }
    }

    for(int q=0;q<Q;q++){
        int x,y;
        cin >> x>>y;
        --x;--y;
        cout <<d[x] +d[y] <<"\n";
    }

    return 0;
}

Measured memory_bytes: 11636
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb  push_back
int32_t main()
{
    int N,X,T;
    cin>>N>>X>>T;
    int times = (N + X - 1) / X;
    int ans = times * T;
    cout << ans << endl;
    
    

}


Measured memory_bytes: 3584
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 28 19:26:54 2020

@author: matha
"""


x, y, a, b, c = map(int, input().split())

p = sorted(map(int, input().split()), reverse = 1)
q = sorted(map(int, input().split()), reverse = 1)
r = sorted(map(int, input().split()), reverse = 1)


nl = sorted(p[0:x] + q[0: y] + r, reverse = 1)

print(sum(nl[0:x+y]))




Measured memory_bytes: 108652
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		double sx=sc.nextDouble();
		double sy=sc.nextDouble();
		double gx=sc.nextDouble();
		double gy=sc.nextDouble();
		int n=sc.nextInt();
		double[][] dis=new double[n+2][n+2];
		double[] x=new double[n+2];
		double[] y=new double[n+2];
		double[] r=new double[n+2];
		x[0]=sx;
		y[0]=sy;
		x[1]=gx;
		y[1]=gy;
		for(int i=2;i<n+2; i++){
			x[i]=sc.nextDouble();
			y[i]=sc.nextDouble();
			r[i]=sc.nextDouble();
		}
		for(int i=0; i<n+2; i++){
			for(int j=i+1; j<n+2; j++){
				dis[i][j]=dis[j][i]=Math.max(0,dist(x[i],y[i],x[j],y[j])-r[i]-r[j]);
			}
		}
		
		PriorityQueue<State> q=new PriorityQueue<>();
		boolean[] ch=new boolean[n+2];
		q.add(new State(0,0));
		while(!q.isEmpty()){
			State s=q.poll();
			ch[s.idx]=true;
			if(s.idx==1){
				break;
			}
			for(int i=0; i<n+2; i++){
				if(!ch[i] && dis[0][i]>=s.d+dis[s.idx][i]){
					dis[0][i]=s.d+dis[s.idx][i];
					q.add(new State(i,dis[0][i]));
				}
			}
		}
		System.out.println(dis[0][1]);
	}
	static double dist(double sx,double sy,double gx,double gy){
		return Math.sqrt((sx-gx)*(sx-gx)+(sy-gy)*(sy-gy));
	}
	static class State implements Comparable<State>{
		public int idx;
		public double d;
		public State(int idx,double d){
			this.idx=idx;
			this.d=d;
		}
		@Override
		public int compareTo(State o) {
      		return Double.compare(this.d, o.d);
   		}
	}
}


Measured memory_bytes: 61996
def getN():
    return int(input())


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


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

n = getN()
nums = getList()

c1 = max(nums)
nums.sort()
nums = nums[:-1]

c2 = 0
dif = float(c1)/2

for num in nums:
     diff = abs(float(c1)/2 - float(num))
     if diff < dif:
         dif = diff
         c2 = num

print(c1, c2)



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

typedef long long ll;

const int inf = 100000;

int main() {
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    string t = "";
    int left = 0;
    int right = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] == '(') {
            left++;
            t += S[i]; 
        } else {
            if (left > 0) {
                t += S[i];
                left--;
                continue;
            } else {
                t = '(' + t;
                t += S[i];
            }
        }
    }
    for (int i = 0; i < left; i++) {
        t += ')';
    }
    cout << t << endl;
}


Measured memory_bytes: 256
// UTPC2010 A. ツ甘コツ鳴鳴篠篠個ア!

#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		vector<int> vi;
		for(int i=0;i<n;i++){
			int sum = 0, t;
			for(int j=0;j<5;j++) { cin >> t; sum += t; }
			vi.push_back(sum);
		}
		int m = vi[0], M = vi[0];
		for(int i=1;i<n;i++){
			m = min(vi[i], m);
			M = max(vi[i], M);
		}
		cout << M << " " << m << endl;
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define rep(i, n) for(ll i = 0;i < n;i++)
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }

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

  int n, m;
  cin >> n >> m;

  vector<int> l(m, 0);
  rep(i, n) {
    int k;
    cin >> k;
    rep(j, k) {
      int a;
      cin >> a;
      l[a-1]++;
    }
  }

  int ans = 0;
  rep(i, m) {
    if (l[i] == n) ans++;
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)

vector< pair<int,int> > leaf_to_root(const vector<int> &u,const vector<int> &v,const int root){
	// return <parent,child>
	int yet = 1000000000;
	vector<int> d(u.size()+1,yet);
	vector< pair<int,int> > res;
	queue<int> Q;
	Q.push(root);
	d[root] = 0;
	vector< vector<int> > G(u.size()+1);
	for(int i=0;i<u.size();i++){
		G[u[i]].push_back(v[i]);
		G[v[i]].push_back(u[i]);
	}
	while( Q.size() ){
		int now = Q.front();
		Q.pop();
		for(auto nex:G[now]){
			if(d[nex]!=yet)continue;
			d[nex] = d[now] + 1;
			Q.push(nex);
			res.push_back( make_pair(now,nex) );
		}
	}
	reverse(res.begin(), res.end());
	return res;
}
int main(){
	ll N,M,ans = 0;
	cin >> N;
	vector<int> a(N-1),b(N-1);
	
	FOR(i,0,N-1) cin >> a[i] >> b[i];
	FOR(i,0,N-1) a[i]--,b[i]--;

	cin >> M;
	vector<int> u(M),v(M);
	FOR(i,0,M) cin >> u[i] >> v[i];
	FOR(i,0,M) v[i]--,u[i]--;
	map<pair<int,int>,int> ma;
	FOR(i,0,N-1){
		ma[{a[i],b[i]}] = i;
		ma[{b[i],a[i]}] = i;
	}
	
	auto x = leaf_to_root(a,b,0);
	vector<ll> pass(M,0);
	FOR(i,0,M){
		vector<int> cnb(N,0);
		cnb[v[i]]=1;
		cnb[u[i]]=1;
		for(auto to:x){
			int p = to.first;
			int c = to.second;
			if(cnb[c]==1){
				pass[i] += (1LL << ma[{p,c}]);
				cnb[p]+=cnb[c];
			}
		}
	}
	FOR(s,1,1LL<<M){
		ll pass_or = 0;
		FOR(i,0,M){
			if(s&(1<<i)){
				pass_or |= pass[i];
			}
		}
		ll num = 1LL<<(N-1-bitset<64>(pass_or).count());
		if(bitset<64>(s).count() & 1){
			ans += num;
		}else{
			ans -= num;
		}
	}
	cout << (1LL<<(N-1))-ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	ll n; cin >> n;
	ll a[n];
	forn(i,0,n) cin >> a[i];
	// the number, its sum
	map<ll,ll> m;
	
	ll total_sum = 0;
	forn(i,0,n){
		++m[a[i]];
		total_sum += a[i];
	}
	 
	ll q; cin >> q;
	forn(i,0,q){
		ll b,c; cin >> b >> c;
		ll count = m[b];
		total_sum -= count*b;
		total_sum += count*c;
		m.erase(b);
		m[c] += count;
		cout << total_sum << '\n';
	}
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 8384
import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int x = scanner.nextInt();
        int y = scanner.nextInt();
        int z = scanner.nextInt();
        System.out.println(z + " " + x + " " + y);
        return;
    }
}

Measured memory_bytes: 20948
i,j,k;main(n){
	scanf("%d",&n);
	double x[n*2],s,t,u,m;s=t=u=m=0;
	for(;i<n*2;scanf("%lf",&x[i++]));
	for(;j<n;x[j]=fabs(x[j]-x[n+j++]));
	for(m=x[0];k<n;s+=x[k],t+=x[k]*x[k],u+=x[k]*x[k]*x[k],m<x[k]?m=x[k]:0,k++);
	printf("%lf\n%lf\n%lf\n%lf\n",s,sqrt(t),cbrt(u),m);
	exit(0);
	}

Measured memory_bytes: 672
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define ll long long int
#define sci(x) sca nf("%d",&x);
#define scd(x) scanf("%lf",&x);
#define pb(x) push_back(x)
#define FasterIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define mkp(x,y) make_pair(x,y)
#define pii pair<int , int>
#define SEIVE seive(){ prime[1]=1; for(ll i=2; i*i<=1000000; i++) { if(prime[i]) continue; for(ll j=i*i; j<=1000000; j+=i) prime[j]=1; } }
bool prime[1000006];
vector<int>vec[20000],root;
int vis[20002];

int main()
{
    char c;
    cin>>c;
    if(c>='a'&&c<='z')
        cout<<'a'<<endl;
    else
        cout<<'A'<<endl;

}


Measured memory_bytes: 4088
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define COUT(x) cout<<(x)<<"\n"

int main(){
    char s;cin >> s;
    if(65<=s&&s<=90){
        COUT("A");
    }
    else COUT("a");
    return 0;
}


Measured memory_bytes: 3620
S = input()
atgc = ['A','T','G','C']
flag = True
count = 0
max = 0

for c in S:
  if (c in atgc):
    flag = True
    if not flag:
      count = 0
    count += 1
    if max < count:
      max = count
  else:
    flag = False
    count = 0
    
print(max)

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <functional>
#include <cmath>
#include <complex>
#include <cctype>
#include <cassert>
#include <sstream>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <deque>

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;

const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main() {
	int b[3];
	REP(i, 3) cin >> b[i];
	
	if (b[2] || (b[0] && b[1])) puts("Open");
	else puts("Close");
	return 0;
}

Measured memory_bytes: 3008
def slove():
    import sys
    input = sys.stdin.readline
    n, k = list(map(int, input().rstrip('\n').split()))
    t = 0
    for i in range(1, n + 1):
        cnt = 0
        ti = i
        while True:
            if ti >= k:
                t += (((1 / 2) ** cnt) * 1 / n)
                break
            else:
                ti *= 2
                cnt += 1
    print(t)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39536
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<bitset>
#include<queue>
#define rep(i,n) for (int i=0; i<n; i++)
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using ll = long long;

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

  vi vec(n);
  rep(i,n) cin >> vec.at(i);

  sort(vec.begin(), vec.end());
  int sum = 0;
  rep(i,k) sum += vec.at(i);

  cout << sum << endl;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<vector<int> > mat(n,vector<int>(n,0));
    for(int i=0;i<n;i++){
        int u,k;
        cin >> u >> k;
        for(int j=0;j<k;j++){
            int v;
            cin >> v;
            mat.at(u-1).at(v-1)=1;
        }
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            cout << mat.at(i).at(j);
            if(j==n-1) cout << endl;
            else cout << " ";
        }
    }
}


Measured memory_bytes: 3112
use std::io::stdin;
use std::str::FromStr;

use std::collections::HashMap;

fn read_line<T>() -> Vec<T>
where
    T: FromStr,
    <T as std::str::FromStr>::Err: std::fmt::Debug,
{
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect()
}

fn main() {
    let in_vec: Vec<i32> = read_line();
    let n = in_vec[0];
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let s: Vec<char> = s.trim().to_string().chars().collect();

    // $BA4It0c$&$7Ey4V3V$G$J$$AH$N?t$r5a$a$k(B
    let mut abc_map_1: HashMap<char, i64> = HashMap::new();
    abc_map_1.insert('R', 0);
    abc_map_1.insert('G', 0);
    abc_map_1.insert('B', 0);
    let mut abc_map_2: HashMap<char, i64> = HashMap::new();
    abc_map_2.insert('R', 0);
    abc_map_2.insert('G', 0);
    abc_map_2.insert('B', 0);
    let mut abc_map_3: HashMap<char, i64> = HashMap::new();
    abc_map_3.insert('R', 0);
    abc_map_3.insert('G', 0);
    abc_map_3.insert('B', 0);

    for i in 0..n {
        *(abc_map_3.get_mut(&s[i as usize]).unwrap()) += 1;
    }

    let mut res: i64 = 0;
    // 2 $BHVL\(B
    for i in 0..n {
        // $B0lHV:8(B
        // $B99?7(B
        *abc_map_2.get_mut(&s[i as usize]).unwrap() += 1;
        *abc_map_3.get_mut(&s[i as usize]).unwrap() -= 1;
        if s[i as usize] == 'R' {
            res += abc_map_1[&'G'] * abc_map_3[&'B'];
            res += abc_map_1[&'B'] * abc_map_3[&'G'];
        } else if s[i as usize] == 'G' {
            res += abc_map_1[&'R'] * abc_map_3[&'B'];
            res += abc_map_1[&'B'] * abc_map_3[&'R'];
        } else {
            res += abc_map_1[&'R'] * abc_map_3[&'G'];
            res += abc_map_1[&'G'] * abc_map_3[&'R'];
        }

        let mut start = i - 1;
        if start < 0 {
            start = 0;
        }
        for j in start..i {
            *abc_map_1.get_mut(&s[j as usize]).unwrap() += 1;
            *abc_map_2.get_mut(&s[j as usize]).unwrap() -= 1;
            if s[j as usize] == 'R' {
                res += abc_map_2[&'G'] * abc_map_3[&'B'];
                res += abc_map_2[&'B'] * abc_map_3[&'G'];
            } else if s[j as usize] == 'G' {
                res += abc_map_2[&'R'] * abc_map_3[&'B'];
                res += abc_map_2[&'B'] * abc_map_3[&'R'];
            } else {
                res += abc_map_2[&'R'] * abc_map_3[&'G'];
                res += abc_map_2[&'G'] * abc_map_3[&'R'];
            }
        }
    }

    let mut dup = 0;

    for win_size in 0..(n - 3) / 2 + 1 {
        let mut i = 0;
        while i + win_size * 2 + 2 < n {
            if (&s[i as usize] != &s[(i + win_size + 1) as usize])
                && (&s[(i + win_size + 1) as usize] != &s[(i + win_size * 2 + 2) as usize])
                && (&s[i as usize] != &s[(i + win_size * 2 + 2) as usize])
            {
                dup += 1;
            }
            i += 1;
        }
    }

    println!("{}", res - dup);
}


Measured memory_bytes: 2188
// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef vector<vector<P>> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<ll> vec;
const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
const int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30);
const int INF = (1LL << 60);
const double EPS = (1 >> 30);
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int n; cin>>n;
    vector<string> s(n);
    REP(i,n) cin >> s[i];

    map<string,int> mp;
    rep(i,n){
        mp[s[i]]++;
    }

    ll MAX=0;
    for(auto &x : mp){
        chmax(MAX,x.sc);
    }
    for(auto &x : mp){
        if(MAX==x.sc){
            cout<<x.fs<<endl;
        }
    }
    
}


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

int main()
{

  // input data
  long k,n;
  cin>>k>>n;

  vector<long> A(n);
  for(int i=0;i<n;i++){
    cin>>A.at(i);
  }

  // search max distance index
  int index=0,wk,wkmax=0;
  for(int i=1;i<n;i++){
    wk=A.at(i)-A.at(i-1);
    if(wk>wkmax){
        index=i;
        wkmax=wk;
    }
  }
  wk= A.at(0)-A.at(n-1)+k;
  if(wk>wkmax)
    index=0;

  // output minimum moving istance
  if(index==0)
    cout<<A.at(n-1)-A.at(0);
  else{
    cout<<A.at(index-1)+k-A.at(index);
  }

  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread_unlocked(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint();
	int A[200000];
	ll S = 0;
	rep(i, N) S += (A[i] = getint());

	ll AB[200000];
	ll saA = A[0];
	int p = 0;

	for (int i = 1; i < N - 2; i++) {
		saA -= A[i];
		while (p + 1 < i && saA < 0) {
			p++;
			saA += A[p] + A[p];
		}
		AB[i] = min(abs(saA - A[p] - A[p]), abs(saA));
	}

	ll kotae = 1e18;
	ll keiCD = A[N - 1], saD = A[N - 1];
	p = N - 1;
	for (int i = N - 2; i >= 2; i--) {
		keiCD += A[i];
		saD -= A[i];
		while (p - 1 > i && saD < 0) {
			p--;
			saD += A[p] + A[p];
		}
		ll kari = min(abs(saD - A[p] - A[p]), abs(saD));

		kotae = min(kotae, max(S - keiCD + AB[i - 1], keiCD + kari) - min(S - keiCD - AB[i - 1], keiCD - kari));
	}
	co(kotae / 2);

	Would you please return 0;
}

Measured memory_bytes: 2816
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  if(a>0){
    cout << "Positive"<<endl;
    return 0;
  }
  if(a<=0 && b>=0){
    cout << "Zero"<<endl;
    return 0;
  }
  
  if((b-a)%2==0){
    cout <<"Negative"<<endl;
  }
  else{
    cout <<"Positive"<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sat Dec  1 02:30:33 2018
//
package main

import (
	"fmt"
	"sort"
)

type city struct {
	p int
	y int
}

var n, m int
var cityYears [100001][]int
var cities []city

func main() {
	fmt.Scan(&n, &m)

	cities = make([]city, m)
	for i := range cityYears {
		cityYears[i] = make([]int, 0)
	}

	for i := range cities {
		fmt.Scan(&cities[i].p, &cities[i].y)
		cityYears[cities[i].p] = append(cityYears[cities[i].p], cities[i].y)
	}

	for i := range cityYears {
		sort.Ints(cityYears[i])
	}

	for i := range cities {
		p, y := cities[i].p, cities[i].y
		index := sort.Search(len(cityYears[p]), func(i int) bool { return cityYears[p][i] >= y })
		fmt.Printf("%06d%06d\n", p, index+1)
	}
}


Measured memory_bytes: 10368
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    ll a[N];
    map<ll, int> mp;
    for(int i = 0; i < N; i++){
        cin >> a[i];
        mp[a[i]] ++;
    }

    sort(a, a + N);

    int ans = 0;

    for(int i = N - 1; i >= 0; i--){
        if(mp[a[i]] == 0) continue;

        mp[a[i]]--;
        ll x = 1;
        while(x <= a[i]) x *= 2;

        ll y = x - a[i];
        if(mp[y] > 0){
            //cout << a[i] << y << endl;
            ans++;
            mp[y] --;
        }
        else {
            mp[a[i]]++;
        }
    }

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

Measured memory_bytes: 26752
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>

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

const int INF = 100000000;
int H,W;
char maze[22][22];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int d[22][22];

int bfs(int sx, int sy, int gx, int gy){
    queue<P> que;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            d[i][j] = INF;
        }
    }
    que.push(P(sx,sy));
    d[sx][sy] = 0;
    while(que.size()){
        P p = que.front();
        que.pop();
        if(p.first == gx && p.second == gy) break;

        for(int i = 0; i < 4; i++){
            int nx = p.first+dx[i], ny = p.second+dy[i];

            if(0 <= nx && nx < H && 0 <= ny && ny < W && maze[nx][ny] != '#' && d[nx][ny] == INF){
                que.push(P(nx,ny));
                d[nx][ny] = d[p.first][p.second]+1;
            }
        }
    }
    return d[gx][gy];

}
int main(){
    cin >> H >>W;
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> maze[i][j];
        }
    }
    int ans = 0;
    for(int sx = 0; sx < H; sx++){
        for(int sy = 0; sy < W; sy++){
            for(int gx = 0; gx < H; gx++){
                for(int gy = 0; gy < W; gy++){
                    if(maze[sx][sy] != '#' && maze[gx][gy] != '#')
                    ans = max(ans, bfs(sx, sy, gx, gy));
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define inf 1000000000
#define maxs(x,y) (x = max(x , y))
#define mins(x,y) (x = min(x , y))
using namespace std;
typedef long long int ll;

int main(){
  int a,b,k,i,j,ans;
  cin >> a >> b >> k;

  j=min(a,b);
  for(i=0 ; i<k ;j--){
    if((a%j == 0)&&(b%j == 0)){
      i++;
      ans=j;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
// g++ -std=c++11 -Wall ファイル名
//-std=c++11はc+11規格を有効にする -Wallは警告を表示するためのオプション

#include <iostream>
using namespace std;

int n,a[10010];
int min(){
  int min=a[0];
  for(int i=1;i<n;i++){
    if(min>a[i]){
      min=a[i];
    }
  }
  return min;
}

int max(){
  int max=a[0];
  for(int i=1;i<n;i++){
    if(max<a[i]){
      max=a[i];
    }
  }
  return max;
}

long long int sum(){
  long long int sum=0;
  for(int i=0;i<n;i++){
    sum+=a[i];
  }
  return sum;
}

int main(){
  cin >> n;
  for(int i=0;i<n;i++){
    cin >>a[i];
  }
  cout << min() << " " << max() << " " << sum() << endl;
}



Measured memory_bytes: 3120
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <deque>

using namespace std;

int main(int argc, char* argv[]){
	int n,i;
	long long a;
	cin >> n;
	deque<long long> b;

	cin >> a;
	b.push_back(a);
	for (i=1; i<n; i++){
		cin >> a;
		if((i-n)%2 == 0){
			//nとiの偶奇が異なる
			b.push_back(a);
		}else{
			//nとiの偶奇が一致
			b.push_front(a);
		}
	}

	for (i=0; i<n; i++){
		cout << b[i] << " ";
	}
	cout << endl; 

	return 0;
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
        using namespace std;
   #define int long long
const int MAX = 510000;
const int MOD =  998244353;

     signed main(){
        int n,m;
        cin>>n>>m;
        pair<int,int> k[m];
        int p,y;
        for(int i=0;i<m;i++){
           cin>>p>>y;
           k[i]=make_pair(p*10000000000+y,i);
        }
        sort(k,k+m);
        int a=0,b=0;
        for(int i=0;i<m;i++){
           if(a/1000000!=k[i].first/10000000000)a=k[i].first/10000000000*1000000+1;
           k[i]=make_pair(k[i].second,a);
           a++;
        }
        sort(k,k+m);for(int i=0;i<m;i++)cout<<std::setw(12) << std::setfill('0') <<k[i].second<<endl;


      }

        


Measured memory_bytes: 3072
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int[] R = new int[n];
		
		for(int i = 0; i < n; i++) {
			R[i] = sc.nextInt();
		}
		
		int max = Integer.MIN_VALUE;
		int min = R[0];
		
		for(int j = 1; j < n; j++) {
				max = Math.max(max, R[j] - min);
				min = Math.min(min, R[j]);
		}
		
		System.out.println(max);
	}
}

Measured memory_bytes: 101440
# -*- coding: utf-8 -*-

N = int(input())
dict_number = {}
S = 0

for a in map(int, input().split()):
  S += a
  if a in dict_number.keys():
    dict_number[a] += 1
  else:
    dict_number[a] = 1

Q = int(input())
for _ in range(Q):
  B,C = map(int, input().split())
  if B in dict_number.keys():
    b = dict_number.pop(B)
    S += b*(C-B)
    if C in dict_number.keys():
      dict_number[C] += b
    else:
      dict_number[C] = b
  print(S)

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

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

    while (true) {
        int H, W;
        cin >> H >> W;
        if (H == 0 && W == 0)
            break;

        rep(i, H) {
            rep(j, W) {
                if ((i + j) % 2 == 0)
                    cout << "#";
                else
                    cout << ".";
            }
            cout << endl;
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#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 ALL(v) v.begin(), v.end()
#define CMAX(m, x)  m = max(m,x);
#define CMIN(m, x)  m = min(m,x);
#define itn int
typedef long long lint;
const int INF = 1e9;
const lint LINF = 1e18;
int main(){
    int n;
    cin >> n;
    int cnt = 0;
    int count = 0;
    FOR(i,1,n + 1){
        if(i % 2 == 1){
            cnt = 0;
            FOR(j,1,i + 1){
                if(i % j == 0){
                    cnt++;
                }
            }
            if(cnt == 8){
                count++;
            }
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
/*input
10
5 9 5 9 8 9 3 5 4 3
*/
#include <bits/stdc++.h>
using namespace std;
int64_t a[100005],n,bit[200005];
void update(int idx, int x){
	for(++idx;idx<200005;idx+=idx&-idx) bit[idx] += x;
}
int query(int idx){
	int res = 0;
	for(++idx;idx;idx-=idx&-idx) res += bit[idx];
	return res;
}
bool check(int m){
	memset(bit,0,sizeof(bit));
	update(n,1);
	int64_t CNT = 0;
	for(int i=0,sum=0;i++<n;update(sum+n,1))
		CNT += query((sum+=a[i]<m?-1:1)+n);
	return 2*CNT >= n*(n+1)/2;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;cin>>a[i++]);
	int low = 1, high = 1e9, mid;
	while(low<high)
		if(check(mid=low+high+1>>1)) low = mid;
		else high = mid - 1;
	cout<<low;
}

Measured memory_bytes: 2560
N, M = map(int,input().split())
root = [[] for i in range(N)]
for i in range(M):
    a, b = map(int,input().split())
    root[a-1].append(b-1)
    root[b-1].append(a-1)
ans = [-1 for _ in range(N)]
check = [(-1,0)]#(from , now)
count = 1
while True:
    for _ in range(len(check)):
        From, now = check.pop(0)
        for next in root[now]:
            if next == From:
                continue
            else:
                if ans[next] == -1:
                    ans[next] = now + 1
                    check.append((now,next))
                    count += 1
    if count == N:
        break
print('Yes')
ans.pop(0)
print('\n'.join(list(map(str,ans))))

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

#define vi vector<int>
#define pii pair<int, int>
#define LL long long int 
#define x first
#define y second
#define f first
#define s second

using namespace std;

int main () {
    
    int n;
    cin >> n;
    
    for(int i=1; i<=9; i++)
        for(int j=1; j<=9; j++)
            if(i*j==n){
                cout << "Yes" << endl;
                return 0;
            }
    
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

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

    string curr, prev;
    prev = s[0];
    ll count = 1;
    rep(i, 1, s.size()){
        if(s[i] == prev[0] && prev.size() == 1){
            if(i < s.size() - 1){
                curr = s[i] + s[i + 1];
                i++;
                count++;
            }
        }else{
            curr = s[i];
            count++;
        }
        prev = curr;
    }

    cout << count << endl;
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<cmath>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ull, ull> UP;
typedef tuple<int, int, int> T;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int gcd(int a, int b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
int digisum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}


int main() {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	if (a + b == c + d)cout << "Balanced" << endl;
	else if(a + b > c + d)cout << "Left" << endl;
	else cout << "Right" << endl;
}



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

using namespace std;

int main ()
{
  int a, b, i;
  cin >> a >> b;
  i = 0;
  
  while(i < b || i < a)
  {
    if(abs(a - i) == abs(b - i))
    {
      cout << i << endl;
      return 0;
    }
    i++; 
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;
 
int main()
{
  string s;
  cin >> s;
  rep(i,s.size()){
    if(s[i] == ',') cout << " ";
    else cout << s[i];
  }
  return 0;
}


Measured memory_bytes: 3624
import Data.Ratio

main = do
    n <- readLn
    print $ eulerPhi n

eulerPhi :: Integer -> Integer
eulerPhi n = floor.fromRational $ (fromInteger n) * (product.map (\x -> 1-1%x) $ factors)
    where factors = map fst.grouping (-1,0).primeFactorize $ n

grouping acc [] = [acc]
grouping acc (x:xs)
  | fst acc == -1 = grouping (x,1) xs
  | fst acc /= x  = acc : grouping (x,1) xs
  | fst acc == x  = grouping (fmap (+1) acc) xs

primeFactorize :: Integer -> [Integer]
primeFactorize n = pf n primes

pf :: Integer -> [Integer] -> [Integer]
pf n (x:xs)
  | x > n = []
  | isPrime n = [n]
  | modnx == 0 = x : pf divnx (x:xs)
  | otherwise = pf n xs
  where (divnx, modnx) = divMod n x

primes :: [Integer]
primes = 2 : filter isPrime [3,5..]

isPrime :: Integer -> Bool
isPrime n = all (/= 0).map (mod n).takeWhile (<= sqrtn) $ primes
    where sqrtn = floor.sqrt.fromIntegral $ n

Measured memory_bytes: 4248
import sys
sys.setrecursionlimit(10**7)
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return sys.stdin.readline().strip()
INF = 10 ** 18
MOD = 10 ** 9 + 7

def main(): 
    H, W, D = LI()
    mod_array = [[(0,0) for _ in range(H*W//D+1)] for _ in range(D)]
    for row_number in range(H):
        row = LI()
        for column_number, item in enumerate(row):
            mod_array[item%D][item//D] = (row_number, column_number)

    # print(mod_array)

    mod_array_cumsum = [[0 for _ in range(H*W//D+1)] for _ in range(D)]
    for row_number in range(D):
        cumsum = 0
        prev_position = mod_array[row_number][0]
        for column_number in range(1, H*W//D+1):
            position = mod_array[row_number][column_number]
            cumsum += abs(prev_position[0] - position[0]) + abs(prev_position[1] - position[1])
            mod_array_cumsum[row_number][column_number] = cumsum
            prev_position = position

    # print(mod_array_cumsum)

    Q = II()
    for _ in range(Q):
        L, R = LI()
        ans = mod_array_cumsum[L%D][R//D] - mod_array_cumsum[L%D][L//D]
        print(ans)
        

main()

Measured memory_bytes: 33168
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin >> a >> b;
	if(a<b)cout << "a < b" << endl;
	if(a>b)cout << "a > b" << endl;
	if(a==b)cout << "a == b" << endl;
	return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
#define mod 1e9+7
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    ll n; cin >> n;
    //nが奇数なら0個
    if (n%2==1) {
        cout << 0 << endl;
        return 0;
    }

    //要するに約数に5が何個あるかゲー
    ll ans = 0;
    ll five = 5;
    while (five <= n) {
        ans += n/five/2;
        five *= 5;
    }
    cout << ans << endl;

}

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

int main(void){
  int w,q;
  while(cin>>w>>q){
    if((w|q) == 0) break;
    char c;
    int s,t;
    int state[w],width,index;
    bool sleepable;
    memset(state,-1,sizeof(state));
    for(int i=0;i<q;i++){
      cin >> c;
      if(c == 's'){
	cin >> s >> t;
	sleepable = false;
	width = 0;
	index = 0;
	for(int j=0;j<w;j++){
	  if(state[j] == -1){
	    if(width == 0) index = j;
	    width++;
	  }else{
	    width = 0;
	  }
	  if(width >= t){
	    sleepable = true;
	    break;
	  }
	}
	if(sleepable){
	  cout << index << endl;
	  for(int j=0;j<t;j++) state[index+j] = s;
	}else{
	  cout << "impossible" << endl;
	}
      }else{
	cin >> s;
	for(int i=0;i<w;i++){
	  if(state[i] == s){
	    state[i] = -1;
	  }
	}
      }
    }
    cout << "END" << endl;
  }
}

Measured memory_bytes: 0
n = gets.to_i

edges = []
g = Array.new(n+1){ [] }
(n-1).times do |i|
  a, b = gets.split.map(&:to_i)
  a, b = b, a if a > b # 辺は頂点 i < j の形で入れる。
  g[a] << b # 隣接リストに
  g[b] << a # 反対向きにも隣接リストに.無向グラフなので
  edges << [a,b] # 辺リストにいれる。辺が識別されてて、最後に辺リストから辺を回して色をとりだす。
end

colors = Hash.new() # Esge => color # 辺についてO(1)で使った色を見れる。O(1)はホントに?
colors_used = Array.new(n+1){Hash.new} # 頂点と色についてO(1)で使ったか確かめられる。
used = Array.new(n){false} # 頂点について探索済みかどうかO(1)でわかる。
que = [1] # 頂点1から見ていくので0が入っている # 探索待ちの未探索の頂点リスト

k = 0 # 答えとなる色の数
while v = que.shift # queにある頂点を取り出す. 破壊的メソッドなので先頭は削除される。なければnilを返す
  cur = 1 # 使ってない色がわからないので、とりあず色1から見ていく。
  g[v].each do |w| # vの隣接頂点wを見ていく。
    next if used[w] #trueで、探索済みの頂点なら見ない。
    k = g[v].size if k < g[v].size  # 隣接する頂点数より色数が小さければ色数を更新
    v<w ? (i,j = v,w) : (i,j = w,v) # i < jの並びで頂点を捉える。
    cur += 1 while colors_used[v][cur] == true # v周りの頂点で色をつかっていれば次の色に更新していく。塗る前に使ってない色にする。
    colors_used[v][cur] = true # vに色を使ったので記録する。
    colors_used[w][cur] = true # wに色を使ったので記録する。
    colors[[i,j]] = cur # 辺に使った色をいれる。
    que.push(w) #探索待ちの未探索頂点リストに頂点wを入れる。
  end
  used[v] = true # 頂点vを探索済みにする。
end

puts k
edges.each{ |e| puts colors[e] }

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

const int cnMaxArray = 1000033;

long long fnStrToInt(string sKey)
{
  int iElement;
  int iBase = 1;
  int llKey  = 0;
  for (int i = sKey.size() - 1; i >= 0; i--)
  {
    switch (sKey[i])
    {
      case  'A': iElement = 1;
                 break;
      case  'C': iElement = 2;
                 break;
      case  'G': iElement = 3;
                 break;
      case  'T': iElement = 4;
                 break;
      default:   iElement = 0;
    }
    llKey += iBase * iElement;
    iBase *= 5;
  }
  return llKey;
}

int fnHash1(long long a_llKey) { return (a_llKey % cnMaxArray); }
int fnHash2(long long a_llKey) { return (1 + (a_llKey % (cnMaxArray - 1))); }

void fnDictionary(string a_rsDictionary[], vector<string> &a_rvsFind)
{
  int iCommandCnt;
  cin >> iCommandCnt;

  for (int i = 0; i < iCommandCnt; i++)
  {
    string sCommand;
    string sKey;
    cin >> sCommand >> sKey;

    long long llKey = fnStrToInt(sKey);
    int iCnt = 0;
    for (iCnt = 0; ;iCnt++)
    {
      int ix = (fnHash1(llKey) + iCnt * fnHash2(llKey)) % cnMaxArray;
      if (a_rsDictionary[ix] == sKey)
      {
        if (sCommand[0] == 'f')
        {
          a_rvsFind.push_back("yes");
          break;
        }
      }
      else if (a_rsDictionary[ix].size() == 0)
      {
        if (sCommand[0] == 'i')
        {
          a_rsDictionary[ix] = sKey;
          break;
        }
        else if (sCommand[0] == 'f')
        {
          a_rvsFind.push_back("no");
          break;
        }
      }
    }
  }
}

void fnResult(const vector<string> &a_cnrvsFind)
{
  for (int i = 0; i < a_cnrvsFind.size(); i++)
    cout << a_cnrvsFind[i] << endl;
}

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

  static string sDictionary[cnMaxArray];
  vector<string> vsFind;

  fnDictionary(sDictionary, vsFind);
  fnResult(vsFind);
  
  return 0;
}

Measured memory_bytes: 59676
#include <cstdio>
#include <cstdint>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <utility>
#include <numeric>

int main() {
  intmax_t n, k;
  scanf("%jd %jd", &n, &k);

  intmax_t x = n % k;
  x = std::min(x, std::abs(x - k));
  
  printf("%jd\n", x);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(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;}
#define y0 y3487465 //j0
#define y1 y1347829 //j1
#define INF 1000000007 //4000000000000000037
#define PI (acos(-1))
#define MOD 1000000007
using namespace std;
typedef long long ll;



void Main(){

  string s,t;
  cin>>s>>t;

  SORT(s);

  sort(ALL(t),greater<char>());

  cout<< ( s<t ? "Yes" : "No" )<<"\n";

}

//-----------------------------------
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
}
//-----------------------------------


Measured memory_bytes: 256
import heapq
import math

mnum, gnum = map(int, input().split())
array = list(map(lambda a: -int(a), input().split()))

array.sort()
heapq.heapify(array)

for i in range(gnum):
	temp = heapq.heappop(array)
	temp /= 2.0
	heapq.heappush(array, temp)
    
amount = 0
for a in array:
  amount += math.floor(-a)
print(amount)

Measured memory_bytes: 14532
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
using namespace std;
typedef long double ld;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------
typedef pair<int,int> P;
vi w(1e6 + 10, 0);
 int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// gcdも呼ぶ！！！
int ngcd(vector<int>& a) {
    int d = a[0];
    for (int i = 1; i < a.size() && d != 1; i++) d = gcd(a[i], d);
    return d;
}
void enum_div(int n) {
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            // ret.push_back(i);
            w[i]++;
            // if (w[i] > 1) return 0;
            if (w[i] > 1) return;
            if (i != 1 && i * i != n) {
                // ret.push_back(n/i);
                w[n / i]++;
                if (n / i > 1 && w[n / i] > 1) return;
            }
        }
    }
    w[n]++;
    // if (w[n] > 1) return 0;
    // return 1;
}

int main(void){
    // Your code here!
    int n;cin >> n;
    vi v(n);
    string ans = "";
    rep(i,n) cin >> v[i];
    if (ngcd(v)!=1) {
        ans = "not coprime";
    } else {
        bool ch = 1;
        rep(i,n) {enum_div(v[i]);}
        for (int i = 2; i < w.size(); i++) {
            if (w[i] > 1) {
                ch = 0;
                break;
            }
        }
        if (ch) ans = "pairwise coprime";
        else ans = "setwise coprime";
    }
    cout << ans << endl;
}


Measured memory_bytes: 11180