akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <deque>
#define ffor(_a,_f,_t) for(int _a=(_f),__t=(_t);_a<__t;_a++)
#define all(_v) (_v).begin() , (_v).end()
#define sz size()
#define pb push_back
#define SET(__set, val) memset(__set, val, sizeof(__set))
#define FOR(__i, __n) ffor (__i, 0, __n)
typedef long long LL;

using namespace std;

int f(int X, int K) {
	if (X < K)
		return 0;
	int val = X / K;
	int beg = val * K;
	int mul = (X - beg) / (val + 1);
	X -= mul * (val + 1);
	if (X % K == 0)
		return X / K;
	return f(X - val - 1, K);
}

int N;

int main() {
	cin >> N;
	int A, K;
	LL ret = 0LL;
	FOR (i, N) {
		cin >> A >> K;
		ret ^= f(A, K);
	}
	if (ret)
		cout << "Takahashi" << endl;
	else
		cout << "Aoki" << endl;
  return 0;
}

Measured memory_bytes: 384
import sys

N, K, S = map(int, input().split())

ans = ''
s1, s2 = 0, 0
if S % 2 == 0:
    s1 = s2 = S // 2
else:
    s1 = S // 2
    s2 = s1 + 1

ex = 10 ** 9
while ex == s1 or ex == s2 or ex == S or ex == 0:
    ex -= 1


if K == 0:
    for i in range(N): ans += str(ex) + ' '
elif K == N:
    for i in range(N): ans += str(S) + ' '
elif S == 1:
    for i in range(K): ans += str(S) + ' '
    for j in range(N-K): ans += str(ex) + ' '
else:
    for i in range(N):
        if i % 2 == 0 and i < K:
            ans += str(s1) + ' '
        elif i < K:
            ans += str(s2) + ' '
        elif i == K:
            ans += str(S) + ' '
        else:
            ans += str(ex) + ' '

print(ans.rstrip())


Measured memory_bytes: 7456
#include <iostream>
#include <string>
#include <vector>

using namespace std;
#define maxtime 100001

int min( int p, int q ) {
	if( p > q ) return q;
	return p;
}


int main(void){
	//FILE* fp_in = freopen("data.txt", "r", stdin);

	int t[16][17];
	
	while( 1 ) {
		int N;
		cin >> N;
		
		if( N == 0 ) break;

		vector<int> dp;
		for(int i = 0; i < (1 << N); i++)
			dp.push_back( 1 << 29 );

		for(int i = 0; i < N; i++)
			for(int j = 0; j <= N; j++)
				cin >> t[i][j];

		dp[0] = 0;
		for(int b = 0; b < ( 1 << N ) ; b++) {
			//これからどのステージを攻略するか？
			for(int i = 0; i < N; i++) {
				int mintime = t[i][0];
				if( ( b & ( 1 << i ) ) != 0 ) continue; 
				//いままでどのステージを攻略したか？
				for(int j = 0; j < N; j++) {
					if( ( b & ( 1 << j ) ) == 0 ) continue;
					mintime = min( mintime, t[i][j + 1] );
				}
				dp[ ( b | ( 1 << i ) ) ] = min( dp[ ( b | ( 1 << i ) ) ] , dp[ b ] + mintime ) ;
			
			}
		}
		
		cout << dp[ ( 1 << N ) - 1 ] << endl;

	}
	

//	while(1){}

    return 0;
}

Measured memory_bytes: 1596
fun main(args : Array<String>) {
    var N=readLine()!!.toInt()
    var A=(1..N).map{readLine()!!.toInt()}.map { it-1 }
    var visited=(1..N).map{false}.toMutableList()
    var current : Int=0
    var count=0
    while(true){
        if(current==1){
            println(count)
            break
        }
        if(visited[current]){
            println(-1)
            break
        }
        visited[current]=true
        count +=1
        current=A[current]
    }
   

}



fun ReadInts():MutableList<Int>{
    return readLine()!!.split(" ").map{it.toInt()}.toMutableList()
}

fun ReadLongs():MutableList<Long>{
    return readLine()!!.split(" ").map{it.toLong()}.toMutableList()
}
fun ReadDoubles():MutableList<Double>{
    return readLine()!!.split(" ").map{it.toDouble()}.toMutableList()
}

Measured memory_bytes: 45316
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e17;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

vl dijkstra(int s, const vector< vector<pll> > &g){
  ll n = g.size();
  vl d(n, INF); d[s] = 0;
  priority_queue< pll, vector<pll>, greater<pll> > q;
  q.em( pll(0,s) );

  while(not q.empty()){
    pll p = q.top(); q.pop();
    ll cost = p.first, v = p.second;
    if(d[v] < cost) continue;

    for(pll e : g[v]){
      ll ncost = cost + e.first, u = e.second;
      if(d[u] > ncost){
        d[u] = ncost;
        q.em( pll(ncost, u) );
      }
    }
  }
  return d;
}

int main(){
  ll n, m, r, q;
  cin >> n >> m >> r >> q;
  vector< vector<pll> > g(n+r);
  rep(i,m){
    ll a,b,c;
    cin >> a >> b >> c;
    a--; b--;
    g[b].eb( MP(c,a) );
  }
  rep(i,n) g[n+i%r].eb( MP(0,i) );

  vector<vl> d(r);
  rep(i,r) d[i] = dijkstra(n+i, g);

  ll ans = 0;
  rep(i,q){
    int x,y,z;
    cin >> x >> y >> z;
    x--; y--;

    ll cost = INF;
    rep(j,r) chmin(cost, d[j][x] + d[j][y]);
    ans += max(0LL, z - cost);
  }
  cout << ans << endl;
}

Measured memory_bytes: 18104
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		List <Integer> arraylistA = new ArrayList <Integer> ();
		List <String> arraylistOP = new ArrayList <String> ();
		List <Integer> arraylistB = new ArrayList <Integer> ();
		String OP;
		
		do {
			arraylistA.add(stdIn.nextInt());
			OP = stdIn.next();
			arraylistOP.add(OP);
			arraylistB.add(stdIn.nextInt());
		} while(!OP.equals("?"));
		
		for(int i = 0; i < arraylistA.size() - 1; i++) {
			if(arraylistOP.get(i).equals("+")) {
				System.out.println(arraylistA.get(i) + arraylistB.get(i));
			}
			else if(arraylistOP.get(i).equals("-")) {
				System.out.println(arraylistA.get(i) - arraylistB.get(i));
			}
			else if(arraylistOP.get(i).equals("*")) {
				System.out.println(arraylistA.get(i) * arraylistB.get(i));
			}
			else if(arraylistOP.get(i).equals("/")) {
				System.out.println(arraylistA.get(i) / arraylistB.get(i));
			}
		}
	}
}

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

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif

	long long int x, k, d;
	cin >> x >> k >> d;
	if(d >= abs(x)) {
		if(k % 2 == 0) cout << abs(x);
		else if(k % 2 != 0) cout << min(abs(x - d), abs(x + d));
	}
	else {
		long long int div = abs(x) / d;
		div = min(div, k);
		k -= div;
		if(x < 0) {
			x += div * d;
		}
		else {
			x -= div * d;
		}
		if(k > 0) {
			if(k % 2 == 0) cout << abs(x);
			else cout << min(abs(x + d), abs(x - d));
		}
		else {
			cout << abs(x);
		}
	}
	return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

int n, m, x;
ll c[100], a[100][100], cnt[100];

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

    cin >> n >> m >> x;
    for (int i = 0; i < n; ++i) {
        cin >> c[i];
        for (int j = 0; j < m; ++j)
            cin >> a[i][j];
    }
    
    ll ans = 1e18;
    
    for (int i = 1; i < (1 << n); ++i) {
        for (int j = 0; j < m; ++j)
            cnt[j] = 0;
        
        ll cur = 0;
            
        for (int j = 0; j < n; ++j)
            if ((1 << j) & i) {
                cur += c[j];
                for (int p = 0; p < m; ++p)
                    cnt[p] += a[j][p];
            }
            
        bool f = 1;
        
        for (int j = 0; j < m; ++j)
            if (cnt[j] < x)
                f = 0;
                
        if (f)
            ans = min(ans, cur);
    }
    
    cout << (ans == 1e18 ? -1 : ans) << "\n";
}


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

int n,m,l,q;
vector<pair<int,int> >way[302];
vector<int>wayway[302];

priority_queue<pair<int,int> >que1;
queue<int>que2;

int flag[302];
int ff[302];
int ans[302][302];

int slv_1(int);
int slv_2(int);

int main(){

	// Input
	cin>>n>>m>>l;
	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			ans[i][j] = -1;
		}
	}
	for(int i=0;i<m;i++){
		int a,b,c;
		cin>>a>>b>>c;
		if(c<=l){
			way[a].push_back(make_pair(b,c));
			way[b].push_back(make_pair(a,c));
		}
	}

	// Solve
	for(int i=1;i<=n;i++){
		slv_1(i);
	}
	for(int i=1;i<=n;i++){
		slv_2(i);
	}

	// Output
	cin>>q;
	for(int i=0;i<q;i++){
		int a,b;
		cin>>a>>b;
		cout<<ans[a][b]<<endl;
	}

	return(0);
}

int slv_1(int nnow){
	int mn[302];

	for(int i=0;i<=n;i++){
		flag[i]=ff[i]=0;
		mn[i] = 1000000001;
	}

	flag[nnow]=1;
	mn[nnow]=0;
	que1.push(make_pair(0,nnow));

	while(!que1.empty()){
		pair<int,int>f = que1.top();que1.pop();
		int now = f.second;
		if(ff[now]==1)continue;
		ff[now]=1;
		for(int i=0;i<way[now].size();i++){
			int next = way[now][i].first , cos = way[now][i].second;
			if(mn[now]+cos<=l && mn[now]+cos<mn[next]){
				mn[next] = mn[now]+cos;
				que1.push(make_pair(mn[next]*-1,next));
				if(flag[next]!=1){
					flag[next]=1;
					wayway[nnow].push_back(next);
				}
			}
		}
	}

	return(0);
}

int slv_2(int bas){
	que2.push(bas);
	for(int i=0;i<=n;i++){
		flag[i]=0;
	}

	int cnt = 0;
	while(!que2.empty()){
		int zis = que2.size();
		for(int siz=0;siz<zis;siz++){
			int now = que2.front();que2.pop();
			for(int i=0;i<wayway[now].size();i++){
				int next = wayway[now][i];
				if(ans[bas][next]==-1){
					ans[bas][next] = cnt;
				}
				if(flag[next]==0){
					flag[next] = 1;
					que2.push(next);
				}
			}
		}
		cnt++;
	}
}

Measured memory_bytes: 2824
//Volume5-0502
import java.util.*;

class Main {
	
	private static int[][][] t = {{{1,2,3},{2,3,4}},
		                          {{2,2,0},{5,4,2}},
		                          {{0,0,3},{1,3,5}}};
	
	private static int[] dice;
	private static int   sum;
	
	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
		int n;
		String s;
		while((n=sc.nextInt())!=0){
			init();
			while(n-- > 0){
				s=sc.next();
				if     (s.equals("North")){change(0,0);}
				else if(s.equals("South")){change(0,1);}
				else if(s.equals("East")) {change(1,0);}
				else if(s.equals("West")) {change(1,1);}
				else if(s.equals("Right")){change(2,0);}
				else if(s.equals("Left")) {change(2,1);}
				sum+=dice[2];
			}
			System.out.println(sum);
		}
	}

	private static void init(){
		sum  = 1;
		dice = new int[6];
		int[] init = {4,5,1,2,6,3}; 
		for(int i=0;i<6;i++){
			dice[i] = init[i];
		}
	}

	private static void change(int a,int b){
		int init,limit,incr;
		if   (b==0){init=0; limit=3 ; incr= 1;}
		else       {init=2; limit=-1; incr=-1;}
		for(int i=init;i!=limit;i+=incr){
			swap(t[a][0][i],t[a][1][i]);
		}
	}
	
	private static void swap(int i,int j){
		dice[j]  = dice[i] - dice[j];
		dice[i] -= dice[j];
		dice[j] += dice[i];
	}
}

Measured memory_bytes: 25328
#include <bits/stdc++.h>
using namespace std;
set<int> decompose(int n) {
        set<int> ret;
        while (n > 0) {
                ret.insert(n % 10);
                n /= 10;
        }
        return ret;
}
int main () {
        int n, k;
        set<int> dig;
        cin >> n >> k;
        for (int i = 0; i < k; i++) {
                int d; cin >> d; dig.insert(d);
        }
        for (int m = n; ; m++) {
                set<int> cur_dig = decompose(m);
                int yes = 1;
                for (auto d: cur_dig) {
                        if (dig.count(d)) {
                                yes = 0; break;
                        }
                }
                if (yes) {
                        cout << m << '\n'; break;
                }
        }
        return 0;
}


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

int main() {
  int n;
  cin >> n;
  int sum = 0;
  rep(i,n){
    int l,r;
    cin >> l >> r;
    sum += r-l+1;
  }
  cout << sum << endl;
}
  


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using PLL = pair<ll, ll>;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repn(i,n) for(int i = 0; i <= (int)(n); i++)
#define srep(i,l,n) for(int i = l; i < (int)(n); i++)
#define srepn(i,l,n) for(int i = l; i <= (int)(n); i++)
#define drep(i,n) for(int i = (int)(n-1); i >= 0; i--)
#define drepn(i,n) for(int i = (int)(n); i >= 0; i--)
#define size(s) (int)s.size()
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }
template<class T = int> using V = vector<T>;
template<class T = int> using VV = vector<V<T>>;
bool isIn(int i, int j, int h, int w) {return i >= 0 && i < h && j >= 0 && j < w;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void err() {cout << -1 << endl;}
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define ep emplace_back

const int MOD = 1000000007;
const int INF = 1e9;

#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    VV<ll> c(26);
    rep(i, size(s)) {
        int now = s[i] - 'a';
        c[now].push_back(i);
    }
    ll ans = 0;
    int pos = -1;
    rep(i, size(t)) {
        int now = t[i] - 'a';
        if(c[now].empty()) {
            cout << -1 << endl;
            return 0;
        }
        auto it = upper_bound(all(c[now]), pos);
        if(it == c[now].end()) {
            ans = (ans+(ll)size(s)-1)/(ll)size(s)*(ll)size(s)+c[now][0]+1;
            pos = c[now][0];
        }else {
            ans = ans/(ll)size(s)*(ll)size(s)+*it+1;
            pos = *it;
        }
    }
    cout << ans << endl;
}

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

const int MAX_N=3e5+10;

int n;
vector<int> ans;
vector<int> is_prime(MAX_N,1);

void init(){
	is_prime[1]=0;
	for (int i=0;;++i){
		int a=7*i+1;
		if (a>=MAX_N) return;
		if (is_prime[a]){
			for (int j=2*a;j<MAX_N;j+=a) is_prime[j]=0;
		}
		int b=7*i+6;
		if (b>=MAX_N) break;
		if (is_prime[b]){
			for (int j=2*b;j<MAX_N;j+=b) is_prime[j]=0;
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	init();
	while(cin >> n,n!=1){
		ans.clear();
		for (int i=2;i<=n;++i){
			if (is_prime[i]&&(i%7==1||i%7==6)){
				if (n%i==0) ans.emplace_back(i);
			}
		}
		cout << n << ':';
		for (int x:ans) cout << ' ' << x;
		cout << '\n';
	}
}


Measured memory_bytes: 4180
import itertools
N,M = map(int,input().split())
src = [tuple(map(int,input().split())) for i in range(M)]
es = [[] for i in range(N)]
for a,b in src:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

ans = 0
for ptn in itertools.permutations(range(1,N)):
    a = 0
    for b in ptn:
        if a not in es[b]:
            break
        a = b
    else:
        ans += 1
print(ans)

Measured memory_bytes: 3188
n = int(input())

count = 0
max_count = 0
pre_height = -1

for height in list(map(int, input().split())):
    if (pre_height < height):
        if (max_count < count):
            max_count = count
        count = 0
        pre_height = height
        
        continue
    
    count += 1
    pre_height = height

if (max_count < count):
    max_count = count

print(max_count)

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

using namespace std;

typedef long long ll;
typedef vector<int> vi; 
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;

#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define ini(a, i) memset(a, i, sizeof(a))
#define contains(c, i) ((c).find(i) != (c).end())
#define present(i, c) (find(all(c), i) != (c).end())

#define rep(i, n) for(int i = 0; i < n; i++)
#define repa(i, b, e) for(int i = (b)-((b)>(e)); i != (e)-((b)>(e)); i += 1-2*((b)>(e)))

#define dbg(x) cerr << #x << " = " << x << endl;
#define dbgall(x) cerr << #x << " = "; for(auto i_ : x) cerr << i_ << " "; cerr << endl;
#define debug(args...) { string s_(#args); replace(all(s_), ',', ' '); stringstream ss_(s_); istream_iterator<string> it_(ss_); cerr_(it_, args); }
void cerr_(istream_iterator<string> it) { (void) it; }
template<class T, class... Args> void cerr_(istream_iterator<string> it, T a, Args... args) { cerr << *it << " = " << a << endl; cerr_(++it, args...); }

template<class T, class S>  ostream& operator<<(ostream& os, const pair<T, S>& p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &v) { os << '{'; string sep; for (const auto &x : v) os << sep << x, sep = ", "; return os << '}'; }
template<class T> ostream& operator<<(ostream &os, const set<T> &s) { os << '{'; string sep; for (const auto &x : s) os << sep << x, sep = ", "; return os << '}'; }
template<class T, class S> ostream& operator<<(ostream &os, const map<T, S> &m) { os << '{'; string sep; for (const auto &x : m) os << sep << x, sep = ", "; return os << '}'; }
template<class T, size_t size> ostream& operator<<(ostream &os, const array<T, size> &arr) { os << '{'; string sep; for (const auto &x : arr) os << sep << x, sep = ", "; return os << '}'; }

//=========================

void run_test() {
	int a; cin >> a;
	cout << a + a * a + a * a * a << endl;
}

//=========================

int main() {
	ios::sync_with_stdio(false); cin.tie(nullptr);
	//int t_ = 1, t__; cin >> t__; while(t_ <= t__) { cout << "Case #" << t_++ << ": "; run_test(); }
	// int t_; cin >> t_; while(t_--) run_test();
	run_test();
	return 0;	
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} 
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

const int mod = 1000000007;
const int inf = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


struct edge{
    ll from, to, cost;
};

bool comp(const edge& a, const edge& b){
    return a.cost < b.cost;
}

class UnionFind{
public:
    vector<ll> par;
    vector<ll> siz;

    UnionFind(ll k):par(k), siz(k, 1LL){
        rep(i,k) par[i] = i;
    }

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

    void unite(ll x, ll y){
        x = root(x);
        y = root(y);
        if(x==y) return;

        if(siz[x]<siz[y]) swap(x, y);
        par[y] = x;
        siz[x] += siz[y];
        return;
    }

    bool same(ll x, ll y){
        return root(x) == root(y);
    }

    ll size(ll x){
        return siz[root(x)];
    }
};

vector<pair<ll, ll>> s, t;
vector<edge> ed;

int main(){
    ll n;
    cin >> n;
    UnionFind uf(100005LL);
    rep(i,n){
        ll x, y;
        cin >> x >> y;
        pair<ll, ll> a = make_pair(x,i);
        pair<ll, ll> b = make_pair(y,i);
        s.push_back(a);
        t.push_back(b);
    }
    sort(s.begin(), s.end());
    sort(t.begin(), t.end());
    rep(i,n-1){
        ll dis = s[i+1].first-s[i].first;
        edge e = {s[i+1].second, s[i].second, dis};
        ed.push_back(e);
    }
    rep(i,n-1){
        ll dis = t[i+1].first-t[i].first;
        edge e = {t[i+1].second, t[i].second, dis};
        ed.push_back(e);
    }
    sort(ed.begin(), ed.end(), comp);
    ll ans = 0;
    for(int i = 0; i < ed.size(); i++){
        edge e = ed[i];
        if(!uf.same(e.from, e.to)){
            uf.unite(e.from, e.to);
            ans += e.cost;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 14560
/*--------------------------*/
// p.114
// 4.6 データ構造の応用：面積計算
//
// ALDS1_3_D: Areas on the Cross-Section Diagram
//
// 入力例:
//    \\///\_/\/\\\\/_/\\///__\\\_\\/_\/_/\
// 出力例
//    35
//    5 4 2 1 19 9
/*--------------------------*/

#include<iostream>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;

int main(){
    stack<int> S1;             // S1 全体の地形の総合面積 
    stack<pair<int, int> > S2; // S2 1番目:水たまりの左座標, 2番目:水たまりの横幅   
    char ch;
    int sum = 0;

    for (int i = 0 ; cin >> ch ; i++) {
        if(ch == '\\') {
            S1.push(i);
        }else if(ch == '/' && S1.size() > 0){
            int j = S1.top(); S1.pop();
            int a = i - j; // a 新しくできる水たまりの増加分の面積
            sum += a;
            while(S2.size() > 0 && S2.top().first > j){
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;        // ans
    while(S2.size() > 0){
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());

    cout << sum << endl;
    cout << ans.size();
    for(int i = 0 ; i < ans.size() ; i++){
        cout << " ";
        cout << ans[i];
    }
    cout << endl;

    
    return 0;
}


Measured memory_bytes: 3236
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) 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()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

n,q = map(int,input().split())
uf = UnionFind(n)
for i in range(q):
    t,u,v = map(int,input().split())
    if t == 0:
        uf.union(u,v)
    else:
        print(uf.same(u,v)*1)

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

int main(){
  string S;
  cin >> S;
  int count = 0;
  for(int i = 0;i < 3;i++){
    if(S[i] == 'o'){
    count++;
    }
  }
  cout << 700 + 100 * count << endl;
}


Measured memory_bytes: 3612
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;

string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
	bool operator>(Edge e) {
		return cost > e.cost;
	}
};

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

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

	int N;
	string s;
	cin >> N >> s;
	int L = s.size();

	vvll dp(N + 1, vll(N + 2, 0));	// dp[i][j]=キーi回押下、現在j文字表示
	dp[0][0] = 1;

	repr(i, 1, N + 1)rep(j, N + 1) {
		if (j == 0) dp[i][0] = (dp[i - 1][0] + dp[i - 1][1]) % MOD;
		else dp[i][j] = (dp[i - 1][j - 1] * 2 + dp[i - 1][j + 1]) % MOD;
	}
	ll inv = powMod(2, MOD - 2, MOD);
	ll ans = dp[N][L];

	rep(i, L) {
		ans *= inv;
		ans %= MOD;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 195968
class UF:
    def __init__(self, n):
        # 負  : 根であることを示す。絶対値はランクを示す
        # 非負: 根でないことを示す。値は親を示す
        self.table = [-1] * n
    def _root(self, x):
        if self.table[x] < 0:
            return x
        else:
            # 経路の圧縮
            self.table[x] = self._root(self.table[x])
            return self.table[x]
    def find(self, x, y):
        return self._root(x) == self._root(y)
    def union(self, x, y):
        r1 = self._root(x)
        r2 = self._root(y)
        if r1 == r2:
            return
        # ランクの取得
        d1 = self.table[r1]
        d2 = self.table[r2]
        if d1 <= d2:
            self.table[r2] = r1
            if d1 == d2:
                self.table[r1] -= 1
        else:
            self.table[r1] = r2
    def show(self):
        print(self.table)
    def data(self):
        res={}
        n=len(self.table)
        for i in range(n):
            res.update({i:[i] if self.table[i]<0 else [self.table[i]]})
        for i in range(n):
            res[res[i][0]]+=[i]
        for i in range(n):
            if len(res[i])==1:
                del res[i]
            else:
                del res[i][0]
        return list(res.values())
###############################################################
n,m=map(int,input().split())
p=list(map(int,input().split()))
xy=[list(map(int,input().split())) for _ in range(m)]
x=[t[0] for t in xy]
y=[t[1] for t in xy]

uf=UF(n)
for i in range(m):
    uf.union(x[i]-1,y[i]-1)
ans=0
for i in range(n):
    if p[i]==i+1:
        ans+=1
    elif uf.find(p[i]-1,i):
        ans+=1
print(ans)

Measured memory_bytes: 105964
#include <bits/stdc++.h>
#define source 200
#define sink 201
#define pii pair<long long, long long>
using namespace std;
 
const long long INF = 2e16;
 
int N;
long long A[205];
vector<int> adj[205];
long long cap[205][205];
int par[205];
 
void edge(int u, int v, long long c) {
  adj[u].push_back(v);
  adj[v].push_back(u);
//  cout << u << " -> " << v << " " << c << "\n";
  cap[u][v] = c;
}
 
long long BFS() {
  memset(par, -1, sizeof(par));
  queue<pii> q;
  q.emplace(source, INF);
  while(!q.empty()) {
    int u = q.front().first;
    long long flow = q.front().second;
//    cout << u << " " << flow << "\n";
    q.pop();
 
    for(int v : adj[u]) {
      if(par[v] == -1 && cap[u][v] > 0) {
        par[v] = u;
        long long new_flow = min(flow, cap[u][v]);
        if(v == sink) return new_flow;
        q.emplace(v, new_flow);
      }
    }
  }
//  cout << "NO\n" << "\n";
  return 0;
}
 
long long macflow() {
  long long flow = 0, new_flow;
  while(1) {
    new_flow = BFS();
    if(new_flow == 0) break;
    flow += new_flow;
    int u = sink;
    while(u != source) {
      cap[par[u]][u] -= new_flow;
      cap[u][par[u]] += new_flow;
      u = par[u];
    }
  }
//  cout << flow << "\n";
  return flow;
}
 
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin >> N;
  long long sum = 0;
  for(int i = 1; i <= N; i++) {
    cin >> A[i];
    if(A[i] < 0) {
      edge(source, i, -A[i]);
    }else {
      edge(i, sink, A[i]);
      sum += A[i];
    }
    for(int j = i * 2; j <= N; j += i) {
      edge(i, j, INF);
    }
  }
  long long ans = macflow();
//  cout << ans << "\n";
  cout << sum - ans << "\n";
  cin >> N;
}

Measured memory_bytes: 3848
import collections

n = int(input())
a = list(map(int,input().split()))

ac = collections.Counter(a)

ac_c={}
sum=0
for i,j in ac.items():
    ac_c[i]=(j*(j-1))//2
    sum+=ac_c[i]

for i in a:
    tmp=ac_c[i]-ac_c[i]*(ac[i]-2)//(ac[i])
    print(sum-tmp)


Measured memory_bytes: 32156
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;
const int maxn = 1e5 + 10;
int a[maxn] , n;

int abs(int x){
	return x > 0 ? x : -x;
}

int main(){
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> a[i];
	sort(a + 1 , a + n + 1);
	int c = 1;
	for(int i = 1 ; i < n ; ++ i)
		if(abs(2 * a[i] - a[n]) < abs(2 * a[c] - a[n]))
			c = i;
	cout << a[n] << " " << a[c] << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  string S;
  cin>>S;
  int a=0,b=0,c=0;
  for(int i=0;i<3;i++){
    if(S.at(i)=='a')a++;
    else if(S.at(i)=='b')b++;
    else c++;
  }
  if(a==b&&b==c)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cassert>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>

int N, M;
int h[2048];
int w[2048];

void load() {
  scanf("%d %d", &N, &M);
  for(int i = 0; i < (int)N; ++i) {
    scanf("%d", &h[i]);
  }
  for(int i = 0; i < (int)M; ++i) {
    scanf("%d", &w[i]);
  }  
}

class Solve_ {
public:
  long operator() () {
    init();
    sub_h();
    sub_w();
    for(int i = 0; i <= N; ++i) {
      for(int j = i + 1; j <= N; ++j) {
        counth[ sumh[j] - sumh[i] ] += 1;
      }
    }    
    for(int i = 0; i <= M; ++i) {
      for(int j = i + 1; j <= M; ++j) {
        countw[ sumw[j] - sumw[i] ] += 1;
      }
    }
    long res = 0;
    for(int i = 1; i < 2048 * 1024; ++i) {
      res += counth[i] * countw[i];
    }
    return res;
  }
  void init() {
    for(long& I : countw) I = 0;
    for(long& I : counth) I = 0;
  }
  void sub_h() {
    sumh[0] = 0;
    for(int i = 0; i < N; ++i) {
      sumh[i + 1] = h[i];
    }
    long t = 0;
    for(int i = 0; i <= N; ++i) {
      t += sumh[i];
      sumh[i] = t;
    }
  }
  void sub_w() {
    sumw[0] = 0;
    for(int i = 0; i < M; ++i) {
      sumw[i + 1] = w[i];
    }
    long t = 0;
    for(int i = 0; i <= M; ++i) {
      t += sumw[i];
      sumw[i] = t;
    }
  }
    
      
private:
  long countw[2048 * 1024];
  long counth[2048 * 1024];
  long sumw[2048];
  long sumh[2048];
};
Solve_ Solve;

int main() {
  for(;;) {
    load();
    if( N == 0 and M == 0 ) break;
    long res = Solve();
    printf("%ld\n", res);
  }
  
  return 0;
}

Measured memory_bytes: 36024
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;
//typedef vector<unsigned int>vec;
typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef vector<vector<int>> Graph;

const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
//const ll MOD = 998244353;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};



int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    if((B - A - 1) % 2 == 1){
        cout << (B - A) / 2 << endl;
    }
    else{
        cout << min({B - 1, N - A, (N-B+1) + (N - (A + N - B + 1) + 1) / 2, A + (B - A) / 2}) << endl;
        //cout << (N-B+1) + (N - (A + N - B + 1) + 1) << " " <<  A + (B - 1 - 1) / 2 << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
const ll MAX = 1001001;
const ll MOD = 1000000007;
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    cout << max(0LL, c - a + b) << endl;
}

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

int main() {
	int n;
	cin>>n;
	int h[n];
	for(int i=0;i<n;i++){
	    cin>>h[i];
	}
	int ans[n]={0};
	for(int i=1;i<n;i++){
	    ans[i]=1000000000;
	}
	
	for(int i=1;i<n;i++){
	    if(i==1){
	        ans[i]=abs(h[0]-h[1]);
	    }else{
	        ans[i]=min(ans[i],min(ans[i-1]+abs(h[i]-h[i-1]),ans[i-2]+abs(h[i]-h[i-2])));
	    }
	}
	cout<<ans[n-1]<<"\n";
	return 0;
}


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

#define int long long int
#define double long double
#define pb push_back
#define fi first
#define se second
#define vii vector<int>
#define pii pair<int,int>
#define vpii vector<pii>
#define pq priority_queue<int>
#define test int tcase; cin>>tcase; for(int tc = 1; tc <= tcase; tc++)
#define inp(a,n,f) int a[n+f];for(int hh=f;hh<n+f;hh++)cin>>a[hh];
#define prdec(k) cout<<fixed<<setprecision(k);
#define mem(a,k) memset(a,k,sizeof(a))
#define ub upper_bound
#define lb lower_bound
#define mii map<int,int>
#define all(v) v.begin(),v.end()
#define inf LLONG_MAX

void clear(queue<pii> &q)
{
   queue<pii> empt;
   swap(q,empt);
}


signed main()
{
	#ifndef ONLINE_JUDGE
   		freopen("input.txt","r",stdin);
   		freopen("output.txt","w",stdout);
	#endif

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

   	int n,m,i,j,ans=0;
   	cin>>n>>m;
   	char s[n+1][m+1];
   	pii st,end;
   	vpii v;
   	cin>>st.fi>>st.se>>end.fi>>end.se;
   	int vis[n+1][m+1];
   	for(i=1;i<=n;i++)
   		for(j=1;j<=m;j++)
   			cin>>s[i][j],vis[i][j]=0;
   	queue<pii> q;
   	q.push(st);
   	vis[st.fi][st.se]=1;
   	while(!q.empty())
   	{
	   	while(!q.empty())
	   	{
	   		pii temp=q.front();
	   		q.pop();
	   		v.pb(temp);
	   		i=temp.fi,j=temp.se;
	   		if(i-1>=1)
	   		{
	   			if(s[i-1][j]=='.'&&vis[i-1][j]==0)
	   				q.push({i-1,j}),vis[i-1][j]=1;
	   		}
	   		if(i+1<=n)
	   		{
	   			if(s[i+1][j]=='.'&&vis[i+1][j]==0)
	   				q.push({i+1,j}),vis[i+1][j]=1;
	   		}
	   		if(j-1>=1)
	   		{
	   			if(s[i][j-1]=='.'&&vis[i][j-1]==0)
	   				q.push({i,j-1}),vis[i][j-1]=1;
	   		}
	   		if(j+1<=m)
	   		{
	   			if(s[i][j+1]=='.'&&vis[i][j+1]==0)
	   				q.push({i,j+1}),vis[i][j+1]=1;
	   		}
	   }
	   if(vis[end.fi][end.se])
	   		break;
	   queue<pii> qu;
	   for(pii node:v)
	   {
	   		i=node.fi,j=node.se;
	   		for(int x=max(i-2,1LL);x<=min(n,i+2);x++)
	   			for(int y=max(j-2,1LL);y<=min(m,j+2);y++)
	   				if(vis[x][y]==0&&s[x][y]=='.')
	   					qu.push({x,y}),vis[x][y]=1;
	   }
	   clear(q);
	   v.clear();
	   while(!qu.empty())
	   {
	   		q.push(qu.front());
	   		qu.pop();
	   }
	   ans++;
	}
	if(vis[end.fi][end.se])
		cout<<ans;
	else
		cout<<-1;
	return 0;
}


Measured memory_bytes: 12508
import java.util.Scanner;

public class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);

        final int N = sc.nextInt();
        final int R = sc.nextInt();

        if (N >= 10) {
            System.out.println(R);
        } else {
            System.out.println(R + 100 * (10 - N));
        }
    }
}


Measured memory_bytes: 23124
import sys
readline = sys.stdin.readline

H,W = map(int,readline().split())
G = [None] * 10

for i in range(10):
  G[i] = list(map(int,readline().split()))

for k in range(10):
  for i in range(10):
    for j in range(10):
      if G[i][j] > G[i][k] + G[k][j]:
        G[i][j] = G[i][k] + G[k][j]

ans = 0
for i in range(H):
  line = list(map(int,readline().split()))
  for j in range(W):
    if line[j] == -1:
      continue
    if line[j] == 1:
      continue
    ans += G[line[j]][1]

print(ans)

Measured memory_bytes: 9240
from scipy.sparse.csgraph import floyd_warshall
import numpy as np
 
N, M, L = map(int, input().split())
graph = np.full((N, N), 10**10)
for _ in range(M):
    s, t, w = map(int, input().split())
    if w <= L:
        graph[s-1][t-1] = graph[t-1][s-1] = w
graph = floyd_warshall(graph, directed=False)
graph = floyd_warshall(graph <= L, directed=False)
graph[np.isinf(graph)] = 0
 
Q = int(input())
ans = []
for _ in range(Q):
    s, t = map(int, input().split())
    ans.append(int(graph[s-1][t-1]) - 1)
print(*ans, sep='\n')

Measured memory_bytes: 17632
#include<bits/stdc++.h>
#define xx first
#define yy second
#define ll long long
using namespace std;
 
const int N = 200000 + 5;
int a[N], n, cnt;
int ans[N];
 
int main () {
    scanf ("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf ("%d", &a[i]);
    }
    for (int i = n; i >= 1; --i) {
        int tmp = 0;
        for (int j = n / i; j >= 1; --j) {
            tmp ^= ans[j * i];
        }
        ans[i] = tmp ^ a[i];
        cnt += ans[i];
    }
    printf ("%d\n", cnt);
    for (int i = 1; i <= n; ++i) {
        if (!ans[i]) {continue;}
        printf ("%d ", i);
    }
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF INT_MAX/3

map<ll,ll> prime_factor(ll n){
  map<ll,ll> res;
  for(ll i=2;i*i<=n;i++){
    while(n%i==0){
      res[i]++;
      n/=i;
    }
  }
  if(n!=1)res[n]=1;
  return res;
}

int main(){
	cin.sync_with_stdio(false);
  ll p,q;
  cin>>p>>q;
  ll np,nq;
  np=p/__gcd(p,q); nq=q/__gcd(p,q);
  map<ll,ll> d=prime_factor(nq);
  ll res=1;
  each(it,d){
    res*=it.fi;
  }
  cout<<res<<endl;
	return 0;
}

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

int main(){
	int n;
	scanf("%d", &n);
	vector<int> a(n);
	for(int i = 0; i < n; i++)
		scanf("%d", &a[i]);
	int q;
	scanf("%d", &q);
	int k;
	for(int i = 0; i < q; i++) {
		scanf("%d", &k);
		long x = lower_bound(a.begin(), a.end(), k) - a.begin();
		long y = upper_bound(a.begin(), a.end(), k) - a.begin();
		printf("%ld %ld\n", x, y);
	}
}



Measured memory_bytes: 3384
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ii = pair<ll, ll>;
const int maxn = 212345;
ll v[maxn];
vector<ii> p;
int main() {
    int n, m;
    scanf("%d %d", &n, &m);
    for (int i = 0; i<n; ++i) {
        scanf("%lld", v+i);
    }
    sort(v, v+n);

    for (int i = 0, u, w; i<m; ++i) {
        scanf("%d %d", &u, &w);
        p.emplace_back(-w, u);
    }
    sort(p.begin(), p.end());

    int i = 0, j = 0, u, w;
    ll ans = 0;
    while (i < n && j < m) {
        tie(w, u) = p[j];
        while (u && i < n && v[i] < -w) {
             ans -= w;
             ++i;
             --u;
        }
        if (i < n) {
            if (u > 0) {
                ans += v[i];
                ++i;
            } else {
                ++j;
            }
        }
    }
    while (i < n) ans += v[i++];

    printf("%lld\n", ans);
}


Measured memory_bytes: 3188
#include<stdio.h>
#include<string.h>

int main(){
  int N,n=0,t;
  char S[99];

  scanf("%d\n", &N);
  scanf("%[^\n]", &S);
  for( int i=0;S[i]!='\0';i++) {
    n=i+1;
  }
  t=n%2;
  if(N>1&&N==n&&t==0){
    for( int i=0;i<n/2;i++){
      if(S[i]!=S[i+n/2]){
        printf("No");
        return 0;
      }
      if(i+1==n/2){
        printf("Yes");
        return 0;
      }
      
    }
  }else{
    printf("No");
    return 0;
  }
  return 0;
}

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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> g[n+1];
  vector<bool> u(n+1,false);
  int a, b;
  rep(i,m){
    cin >> a >> b;
    g[a].push_back(b); g[b].push_back(a);
  }
  vector<int> t; vector<int> s;
  t.push_back(a); s.push_back(b);
  u[a] = true; u[b] = true;
  int na = a, nb = b;
  while(true){
    int p = -1;
    rep(i,g[na].size()){
      if(!u[g[na][i]]) {
        p = g[na][i];
        u[p] = true;
        t.push_back(p);
        na = p;
      }
    }
    if(p != -1) continue;
    rep(i,g[nb].size()){
      if(!u[g[nb][i]]) {
        p = g[nb][i];
        u[p] = true;
        s.push_back(p);
        nb = p;
      }
    }
    if(p == -1) break;
  }
  reverse(t.begin(),t.end());
  cout << t.size() + s.size() << endl;
  rep(i,t.size()) cout << t[i] << " ";
  rep(i,s.size()) cout << s[i] << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 6648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const int nmax = 8;
bool graph[nmax][nmax];
 
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}
 
ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}
int dfs(int v, ll N, bool visited[nmax])
{
    bool all_visited = true;
 
    for (int i = 0; i < N; i++)
    {
        if (!visited[i])
        {
            all_visited = false;
        }
    }
 
    if (all_visited)
    {
        return 1;
    }
    int ret = 0;
    for (size_t i = 0; i < N; i++)
    {
        if (!graph[v][i])
        {
            continue;
        }
        if (visited[i])
        {
            continue;
        }
 
        visited[i] = true;
        ret += dfs(i, N, visited);
        visited[i] = false;
    }
 
    return ret;
}

void solve(std::string S){
    if(S <= "2019/04/30"){
        cout << "Heisei" << endl;
    }else{
        cout << "TBD" << endl;
    }
}

int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

long long combi(long long n, long long k) {
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}

int main(){    
  string S;
  cin >> S;
  if(S[2]==S[3] && S[4]== S[5]){
    cout <<  "Yes" << endl;
    return 0;
  }
  cout <<  "No" << endl;

}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
using namespace std;

/*int par[100000];

void init(int n){
    for(int i=0; i<n; i++) par[i] = i;
}

int find(int x){
    if(par[x] == x) return x;
    else{
        par[x] = find(par[x]);
        return par[x];
    }
}

int min(int a, int b){
    if(a > b) return b;
    else return a;
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;

    par[x] = y;
}*/

int main(){

	int h1,h2,k1,k2,a,b,c,d;
	cin >> h1 >> h2 >> k1 >> k2 >> a >> b >> c >> d;

	int H,K;
	H = a*h1 + b*h2 +c*(h1/10)+d*(h2/20);
	K = a*k1 + b*k2 +c*(k1/10)+d*(k2/20);

	if(H>K){
		cout << "hiroshi" << endl;
	}
	else if(H == K){
		cout << "even" << endl;
	}
	else{
		cout << "kenjiro" << endl;
	}
	/*int p,m,c;
	cin >> p >> m >> c;
	cout << p+m+c << endl;*/
/*int W;
cin>>W;
cout<<W*32<<endl;*/
    return 0;
}


Measured memory_bytes: 3108
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long n = sc.nextLong();

        if (n < 10) {
            System.out.println(n);
            return;
        }
        
        long ans = 0;
        long ans2 = 0;
        while (n > 0) {
            if (n < 10) {
                ans += n -1;
                ans2 += n;
                break;
            }
            ans += 9;
            ans2 += n % 10;
            n /= 10;
        }
        System.out.println(Math.max(ans, ans2));
    }
}

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

int main(){
  int a,n,t1,t2;
  while(1){
    cin >> n;
    if(n == 0) break;
    cin >> a;
    for(int i=0;i<a;i++){
      cin >> t1 >> t2;
      n -= t2 - t1;
    }
    if(n <= 0) cout << "OK" << endl;
    else cout << n << endl;
  }
}

Measured memory_bytes: 1160
n = int(input())
dic = {}
from collections import Counter
for i in range(n):
  s = input()
  s = sorted(s)
  s = ''.join(s)
  if s not in dic: dic[s] = 1
  else: dic[s] += 1
a = dic.values()
a = list(a)
ans = 0
for i in range(len(a)):
  ans += a[i]*(a[i]-1)/2
print(int(ans))

Measured memory_bytes: 18244
#include <cstdio>

int N, A, B, nnsame, nndiff;
int N_same[26];
int N_diff[26];
int visited[100008];
void put_res(int value, int first) {
	if(first==0) printf(" ");
	int ret=0;
	int dig = 0;
	for(int i=0;i<nndiff;i++) {
		if(value&(1<<dig)) ret+=(1<<N_diff[i]);
		dig++;
	}
	for(int i=0;i<nnsame;i++) {
		if(value&(1<<dig)) ret+=(1<<N_same[i]);
		dig++;
	}
	printf("%d", A ^ ret);
}
int run[100008];
int main() {
	scanf("%d%d%d", &N, &A, &B);
	for(int i=0;i<N;i++) {
		if((A^B)&(1<<i)) {
			N_diff[nndiff++] = i;
		} else {
			N_same[nnsame++] = i;
		}
	}
	if((nndiff % 2) == 0) {
		printf("NO\n");
		return 0;
	}
	printf("YES\n");
	int cur = 0;
	for(int i=0;i<(1<<(N-1));i++) {
		visited[cur] = 1;
		run[i] = cur;
		int dig = 0;
		while(visited[cur ^ (1<<dig)]) dig++;
		cur ^= (1<<dig);
	}
	int ng = (1<<(nndiff-1)) - 1;
	put_res(0, 1);
	if(ng == 0) {
		int cnt = (1<<(N-1)) - 1;
		cur = run[cnt] * 2;
		int flg = 0;
		while(cnt) {
			put_res(cur + flg, 0);
			flg = 1 - flg;
			put_res(cur + flg, 0);
			cnt--;
			cur = run[cnt] * 2;
		}
		put_res(1, 0);
	} else {
		int cnt = 0;
		int next = run[cnt + 1];
		while(next != ng) {
			put_res(next * 2, 0);
			cnt++;
			next = run[cnt + 1];
		}
		for(int j=cnt;j>=0;j--) put_res(run[j] * 2 + 1, 0);
		int cnt2 = (1<<(N-1)) - 1;
		int flg = 1;
		while(cnt < cnt2) {
			put_res(run[cnt2] * 2 + flg, 0);
			flg = 1 - flg;
			put_res(run[cnt2] * 2 + flg, 0);
			cnt2--;
		}
	}
	printf("\n");
	return 0;
}

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

int main() {
    int N;
    cin >> N;
    map<string, int> mp;
    for (int n = 0; n < N; n++) {
        string S;
        cin >> S;
        mp[S]++;
    }
    int mx = 0;
    for (auto p : mp) {
        mx = max(mx, p.second);
    }
    for (auto p : mp) {
        if (p.second == mx) {
            cout << p.first << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 25216