akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
	int a,b,c; cin >>a>>b>>c;
	if(a<b){
		if(a<c && c<b){
			cout << "Yes";
		} else {
			cout << "No";
		}
	} else {
		if(a>c && c>b){
			cout << "Yes";
		} else {
			cout << "No";
		}
	}
	return 0;
}

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

int main() {
 string S;
  cin >> S ;
  for(int i=0;i<3;i++){
   if (S.at(i) == S.at(i+1)){
     cout <<"Bad";
     break;
   }
   if (i==2){
     cout << "Good";
   }
  }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int n,a,last=0,ans=0;
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        if(a>last)ans+=(a-last);
        last=a;
    }
    cout<<ans<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long int gcd(long long int a , long long int b)
{
    if(b==0)
    {

        return a;
    }
    return gcd(b,a%b);


}



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

if(s.size()<=k)
{

    cout<<s;
}
else{
int x=1;
for(int i=0;i<k;i++)
{
    cout<<s[i];

}

while(x<=3)
{

    cout<<'.';
    x++;
}

}


return 0;

}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
  int n;
  cin >> n;
  map<string, ll> cnt;
  ll ans = 0;
  for (int i = 0; i < n; i++){
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    ans += cnt[s];
    cnt[s]++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 11136
import java.util.*;

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

        if(old >= 13){
            System.out.println(fee);
        }else if(old <= 5){
            System.out.println(0);
        }else{
            System.out.println(fee/2);
        }
    }
}

Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[3] = { 0 };
	a[0] = 1;
	int x, y;
	char al[4] = {"ABC"};
	char s, s2, t;
	while ((cin>>s>>t>>s2)){

		if (s == 'A'){
			x = 0;
		}
		else if (s == 'B'){
			x = 1;
		}
		else if (s == 'C'){
			x = 2;
		}
		if (s2 == 'A'){
			y = 0;
		}
		else if (s2 == 'B'){
			y = 1;
		}
		else if (s2 == 'C'){
			y = 2;
		}
		swap(a[x], a[y]);
	}
	for (int i = 0; i < 3; i++){
		if (a[i]){
			cout << al[i] << endl;
			break;
		}
	}
}

Measured memory_bytes: 1132
import sys
import math

sys.setrecursionlimit(10**7)

a, b = input().split()
a = int(a)
b = "".join(b.split("."))
if b == "000":
    b = 0
else:
    i=0
    while b[i] == "0":
        i += 1
    b = int(b[i:])
ans = str(a*b//100)
i=0
while i < len(ans) and ans[i] != ".":
    i += 1
print(ans[:i])

Measured memory_bytes: 9208
"""
gcd(a,b,c) = gcd(a, gcd(b,c))
"""

import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline
K = int(readline())

from math import gcd

ans = 0

for i in range(1,K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            ans += gcd(i, gcd(j,k))
            
print(ans)

Measured memory_bytes: 9208
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>

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

int main()
{
	string a;
	cin>>a;
	ll r=0,t=stol(a);


	for(int i=0;i<a.length();i++)
	{
		r+=a[i]-'0';
	}
	puts(t%r==0?"Yes":"No");
}


Measured memory_bytes: 256
def c_fennec_vs_monster():
    N, K = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]
    H.sort()
    for _ in range(K):
        if not H:
            break
        H.pop()
    return sum(H)

print(c_fennec_vs_monster())

Measured memory_bytes: 26764
#include <stdio.h>
int main(void){
	int sx,sy,tx,ty,i;
	scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
	for(i=sx;i<tx;i++)printf("R");
	for(i=sy;i<ty;i++)printf("U");
	for(i=tx;i>sx;i--)printf("L");
	for(i=ty;i>sy-1;i--)printf("D");
	for(i=sx;i<tx+1;i++)printf("R");
	for(i=sy-1;i<ty;i++)printf("U");
	printf("LU");
	for(i=tx;i>sx-1;i--)printf("L");
	for(i=ty+1;i>sy;i--)printf("D");
	printf("R\n");
	return 0;
}

Measured memory_bytes: 128
N=input()
l=[]
f1=False
f2=False
f3=False
n=-1
for i in N:
    #print(i)
    if n==-1 or n!=int(i):
        #print('piu')
        f1=True
        f2=False
        f3=False
        n=int(i)
    elif n==int(i) and f1 and not f2:
        #print('poi')
        f2=True
    elif n==int(i) and f2:
        print('Yes')
        exit(0)
print('No')



Measured memory_bytes: 3060
h,w=map(int,input().split())
n=int(input())
*a,=map(int,input().split())
grid=[]
for i in range(n):
    for j in range(a[i]):
        grid.append(i+1)
for i in range(h):
    if i%2==0:
        print(*grid[i*w:i*w+w])
    else:
        print(*grid[i*w:i*w+w][::-1])

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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair

int main() {
  int n;
  cin >> n;
  vl a(n);
  rep (i, n) cin >> a[i];

  vl sum(n + 1);
  map<ll, ll> mp;
  mp[0]++;
  rep (i, n) {
    sum[i + 1] = sum[i] + a[i];
    mp[sum[i + 1]]++;
  }

  ll ans = 0;
  for (auto itr = mp.begin(); itr != mp.end(); itr++) {
    ans += itr->second * (itr->second - 1) / 2;
  }
  cout << ans << endl;
    
}


Measured memory_bytes: 15872
import math
n=int(input())

def gcd2(a,b,c):
    d=math.gcd(a,b)
    e=math.gcd(c,d)
    return e
    
s=0
s1=0
s2=0
s3=0

for i in range(1,n+1):
    s1+=i
    for i2 in range(i+1,n+1):
        s2+=math.gcd(i,i2)
        for i3 in range(i2+1,n+1):
            s3+=gcd2(i,i2,i3)

s=s1+6*s2+6*s3

print(s)



Measured memory_bytes: 9216
#include <iostream>
#include <cstring>
#include "stdio.h"

using namespace std;

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

int main(){
	int n;
	double prob[2][3][3];
	bool junk[3][3];
	while(cin >> n, n){
		char s, t, b; cin >> s >> t >> b;
		double ans = 0.0;
		for(int i=0;i<2;i++)
			for(int j=0;j<3;j++)
				for(int k=0;k<3;k++) prob[i][j][k] = 0.0;
		prob[0][(s-'A')/3][(s-'A')%3] = 1.0;
		int gx = (t-'A')/3, gy = (t-'A')%3;
		memset(junk, false, sizeof(junk));
		junk[(b-'A')/3][(b-'A')%3] = true;
		for(int i=0;i<n;i++){
			for(int x=0;x<3;x++)
				for(int y=0;y<3;y++) prob[1-(i%2)][x][y] = 0.0;
			for(int x=0;x<3;x++){
				for(int y=0;y<3;y++){
					for(int d=0;d<4;d++){
						int nx = x+dx[d], ny = y+dy[d];
						if(nx<0||3<=nx||ny<0||3<=ny||junk[nx][ny]) {
							nx = x, ny = y;
						}
						prob[1-(i%2)][nx][ny] += prob[i%2][x][y]*0.25;
					}
				}
			}
		}
		printf("%.8lf\n", prob[n%2][gx][gy]);
	}
}

Measured memory_bytes: 0
n, m = map(int, input().split())
a = [[i for i in input()] for _ in range(n)]
b = [[i for i in input()] for _ in range(m)]
com = True
for h in range(n-m+1):
    for w in range(n-m+1):
        for hi in range(m):
            for wi in range(m):
                if a[h+hi][w+wi] != b[hi][wi]:
                    com = False
        if com:
            print("Yes")
            exit()
        else:
            com = True
print("No")

Measured memory_bytes: 3064
#include <iostream>
#include <bitset>
#include <algorithm>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)

int n;
int m;
int k[15];
int s[15][15];
int p[15];

int main() {
	cin >> n >> m;
	rep(i, m) {
		cin >> k[i];
		rep(j, k[i]) cin >> s[i][j];
	}
	rep(i, m) cin >> p[i];
	int ans = 0;
	for (int bit = 0; bit < (1 << n); bit++) {
		bool G = true;
		rep(i, m) {
			int sum = 0;
			rep(j, k[i]) {
				if (bit & (1 << s[i][j] - 1)) {
					sum++;
				}
			}
			if (sum % 2 != p[i]) G = false;
		}
		if (G) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int w,n,a,b,num[30];
	char ch;
	cin >> w >> n;
	for(int i=0;i<w;i++){
		num[i] = i+1;
	}
	for(int i=0;i<n;i++){
		cin >> a >> ch >> b;
		swap(num[a-1],num[b-1]);
	}
	for(int i=0;i<w;i++){
		cout << num[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <complex>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int main() {
    char s[10];
    scanf("%s", s);
    if (s[2] == s[3] && s[4] == s[5]) {
        printf("Yes\n");
    } else {
        printf("No\n");
    }
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from fractions import Fraction
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations, accumulate
from operator import add, mul, sub, itemgetter, attrgetter


import sys
# sys.setrecursionlimit(10**6)
# readline = sys.stdin.buffer.readline
readline = sys.stdin.readline

INF = 1 << 60


def read_int():
    return int(readline())


def read_int_n():
    return list(map(int, readline().split()))


def read_float():
    return float(readline())


def read_float_n():
    return list(map(float, readline().split()))


def read_str():
    return readline().strip()


def read_str_n():
    return readline().strip().split()


def ep(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.perf_counter()
        ret = f(*args, **kwargs)
        e = time.perf_counter()

        ep(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, M, UV):
    g = defaultdict(list)
    fin = Counter()
    for u, v in UV:
        g[u].append(v)
        fin[v] += 1

    r = -1
    for v in range(1, N+1):
        n = fin[v]
        if n == 0:
            r = v
            break

    a = defaultdict(lambda: None)
    q = deque([r])
    a[r] = 0
    while q:
        u = q.popleft()
        for v in g[u]:
            fin[v] -= 1
            if fin[v] == 0:
                a[v] = u
                q.append(v)

    ans = [a[i] for i in range(1, N+1)]
    return ans


def main():
    N, M = read_int_n()
    UV = [read_int_n() for _ in range(N-1+M)]
    print(*slv(N, M, UV), sep='\n')


if __name__ == '__main__':
    main()


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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;


int main() {
    int n, k;
    cin >> n >> k;
    if ((n + 1) / 2 >= k) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
    long long n,a,b,c,d,e,sum=0,mi;
    cin >> n >> a >> b >> c >> d >> e;
    mi = min(a,min(b,min(c,min(d,e))));
    sum = 4 + n/mi;
    if(n%mi!=0) sum++;
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
w = list(map(int, input().split()))
ans = 10000000000
for t in range(1, n):
    left, right = 0, 0
    for i in range(t):
        left += w[i]
    for i in range(t, n):
        right += w[i]
    ans = min(ans, abs(left - right))
print(ans)


Measured memory_bytes: 2940
#include <cstdio>
#include <algorithm>
using namespace std;
int n, c, k, ans, x, y, a[100005];
int main() {
	int i;
	scanf("%d%d%d", &n, &c, &k);
	for(i=1; i<=n; i++) scanf("%d", &a[i]);
	sort(a, a+n+1);
	for(i=1; i<=n; i++) {
		if(x==0 || a[i]-y>k) ans++, x=c, y=a[i];
		x--;
	}
	printf("%d", ans);
	return 0;
}

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

int main() {
	int A, B, X;
	cin >> A >> B >> X;
	cout << (A <= X && X <= A + B ? "YES" : "NO");
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

やるだけ
*/

Measured memory_bytes: 256
using System;

namespace ABC102B
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            var target = Console.ReadLine().Split(' ');
            int[] a = new int[N];
            a[0] = int.Parse(target[0]);
            int max = a[0]; int min = a[0];
            for(int i = 1; i < N; i++){
                a[i] = int.Parse(target[i]);
                if(max < a[i]) max = a[i];
                if(min > a[i]) min = a[i];
            }
            Console.WriteLine("{0}", max-min);
//            Array.Sort(a);
//            Console.WriteLine("{0}", a[N-1]-a[0]);
        }
    }
}


Measured memory_bytes: 13268
n = int(input())
a = list(map(int, input().split()))

cumsum = [0] * (n + 1)
for i in range(n):
    cumsum[i + 1] = cumsum[i] + a[i]

ans = 10 ** 10
for i in range(1, n):
    x = cumsum[i]
    y = cumsum[n] - x
    ans = min(ans, abs(x - y))

print(ans)


Measured memory_bytes: 24824
import sys
import math
import heapq
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, m=DVSR): return pow(x, m - 2, m)
def DIV(x, y, m=DVSR): return (x * INV(y, m)) % m
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())
def FLIST(n):
    res = [1]
    for i in range(1, n+1): res.append(res[i-1]*i%DVSR)
    return res
def gcd(x, y):
    if x < y: x, y = y, x
    div = x % y
    while div != 0:
        x, y = y, div
        div = x % y
    return y

N=II()
INL=LI()
MM=10**15
cnt = 0
for i in range(N):
    if INL[i] <= MM: cnt += 1
    MM=min(MM,INL[i])
print(cnt)


Measured memory_bytes: 76752
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <unordered_map>
#include <set>
#include <map>
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(0), cout << fixed << setprecision(20);
#define rep(i,n) for (int i=0; i<n;++i)
#define ALL(a)  (a).begin(),(a).end()
#define PI 3.14159265358979
typedef long long ll;
using namespace std;
const ll MOD = 1e9+7LL;
const int INF = 2e9;
int N;
typedef pair<ll, int> P;
P A[2001];
ll DP[2001][2001]; // left人とright人の幸福度

int main() {
  INCANT;
  cin >> N;
  ll a;
  rep(i, N) {
    cin >> a;
    A[i] = P(a, i);
  }
  sort(A,A+N, greater<P>());
  
  rep(i, N) {
    P p = A[i];
    for (int j=0; j<=i; j++) { // i人並んでいる
      int left = j;
      int right = i-j;
      int right_idx = N-1-right;
      DP[left+1][right] = max(DP[left+1][right], DP[left][right]+p.first*abs(p.second-left)); // 左側に並ぶ
      DP[left][right+1] = max(DP[left][right+1], DP[left][right]+p.first*abs(right_idx-p.second)); // 右側に並ぶ
    }
  }
  ll MAX=0ll;
  rep(i, N+1) MAX = max(MAX, DP[i][N-i]);
  cout << MAX << endl;
  return 0;
}

Measured memory_bytes: 26248
N,M,C = list(map(int,input().split()))
B = list(map(int,input().split()))
A = [list(map(int,input().split())) for i in range(N)]

ans = 0
solve = 0

for i in range(N):
    for j in range(M):
        solve += A[i][j]*B[j]
        
    if solve > -C:
        ans+=1
    solve = 0
    
print(ans)

Measured memory_bytes: 3064
def count(words):
    for word in words:
        if word in count_dict:
            count_dict[word] += 1
        else:
            count_dict[word] = 1

def even_number(count_dict):
    for key in count_dict:
        if count_dict[key] % 2 != 0:
            return('No')
    return('Yes')

if __name__ == '__main__':
    words = input()
    count_dict = {}

    count(words)
    ans = even_number(count_dict)
    print(ans)

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

int main() {
  long n, ans = 0;
  cin >> n;
  if (n % 2 == 0) {
    long waru = 10;
    while (n >= waru) {
      ans += n / waru;
      waru *= 5;
    }
  }
  else {
  }
  cout << ans;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}

impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}
// use std::cmp::Reverse;
fn main(){
    input!{
        n:usize,
        mut spn:[(String,i64);n],
    }
    let sub = spn.clone();
    let mut ans:Vec<_> = spn.iter().enumerate().collect();
    // ans.sort_by(|a,b|(;
    ans.sort_by_key(|x|Rev((x.1).1));
    ans.sort_by_key(|&x| &(x.1).0);

    // ans.reverse();
    // println!("{:?}",ans);
    for &ref x in &ans {
        println!("{}",x.0 + 1);
    }
}

Measured memory_bytes: 4352
#include<iostream>
#include <algorithm>
#include<string>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
    int x,a,ans1,ans2;
    cin>>x>>a;
    if(x>=a){
        ans1 = x;
        x--;
    }
    else{
        ans1 = a;
        a--;
    }
    if(x>=a){
        ans2 = x;
        x--;
    }
    else{
        ans2 = a;
        a--;
    }
    cout<<ans1+ans2<<endl;
    return 0;
}


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

int div2cnt(int x)
{
    int cnt = 0;
    while(0 == x % 2)
    {
        cnt++;
        x /= 2;
    }

    return cnt;
}

int main(void){
int N;
scanf("%d",&N);
   int number[N];
    int ok,cal;
   for(int i=0;i<N;i++){
        scanf("%d",&number[i]);
}
     
  for(int i=0;i<N;i++){
      cal = div2cnt(number[i]);
          ok = ok + cal;
}
 printf("%d\n",ok);

return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rlcfpoj(x) scanf("%I64d",&x)
#define pi(x) printf("%d",x)
#define pl(x) printf("%lld",x)
#define plcfpoj(x) printf("%I64d",x)
#define lfd() printf("\n")
#define sp() printf(" ")
#define inrep(x) int x;scanf("%d",&x);while(x--)
int n,d;
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>d;
	cout<<(n+2*d)/(2*d+1)<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
using Graph=vector<vector<int>>;

int main()
{
  ull X;cin>>X;
  ull now=100;
  ull count =0;
  while (now<X)
  {
    now += now*0.01;
    count++;
  }
  cout<<count<<endl;
  
}

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

int main()
{
 int a ,b,c ;
 cin>>a>>b;
  c=(a*3)+b ;

  if(c%2==0)
{
     cout << c/2 ;

}
 else {cout << (c-(c%2))/2 ; }

return 0  ;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(x,y) (x=min(x,y))
#define chmax(x,y) (x=max(x,y))
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}
#define N 401
#define M 100010
#define N2 (N/64+1)
int n, m, x[M], y[M], k[N][N];
ull k2[N][N2];
int main(){
	scanf("%d%d", &n, &m);
	rep(i, m){
		scanf("%d%d", x+i, y+i); x[i]--; y[i]--;
	}
	reverse(x, x+m);
	reverse(y, y+m);
	rep(i, n){
		k[i][i] = 1;
		rep(j, m){
			if(k[i][x[j]]&&k[i][y[j]]) {k[i][i] = 2; break;}
			else if(k[i][x[j]]) k[i][y[j]] = 1;
			else if(k[i][y[j]]) k[i][x[j]] = 1;
		}
		if(k[i][i]==2){
			mset(k2[i], -1);
			continue;
		}
		rep(j, n) if(k[i][j]) k2[i][j/64] |= 1ull<<(j%64);
	}
	int res = 0;
	rep(i, n) rep(j, i){
		int r = 1;
		rep(l, n/64+1){
			if(k2[i][l]&k2[j][l]){
				r = 0;
				break;
			}
		}
		res += r;
	}
	printf("%d\n", res);
	return 0;
}


Measured memory_bytes: 1664
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#define MN 100000
using namespace std;
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9')x=x*10+ch-'0',ch=getchar();
    return x*f;
}
int n,m,c[MN+5];
int main()
{
    n=read();m=read();
    for(int i=1;i<=m;++i) c[read()]^=1,c[read()]^=1;
    for(int i=1;i<=n;++i) if(c[i]) return 0*puts("NO");
    puts("YES");
    return 0;
}


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

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

    int64_t answer = 0;
    int32_t h = 0;
    for (int32_t i = 0; i < n; i++) {
        int32_t d = a[i + 1] - a[i];
        if (d >= 2) {
            cout << -1 << endl;
            return 0;
        } else if (d <= 0) {
            answer += a[i];
        }
    }
    cout << answer << endl;
    return 0;
}


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

using namespace std;
using ll = long long;

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "YES"
#define FALSE__ "NO"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define RS(N) resize(N)
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);

#define MOD 1000000007

void init();
void solve();

signed main()
{
	init();
	solve();
}

vector<int> memo;
vector<int> pos;
vector<int> v;
int N;

void init()
{
	cin >> N;
	CINV(v, N);
	memo.resize(N+1, 0);
	pos.resize(N+1);
	rep(i, N) {
		pos[v[i]] = i;
	}
	memo[N] = 1;
}

int culc(int x)
{
	int& m = memo[x];
	if (m) return m;
	if (pos[x] < pos[x+1]) return m = 1 + culc(x+1);
	else return m = 1;
}

void solve()
{
	int ma = 0;
	reps(i, 1, N+1) {
		ma = max(ma, culc(i));
	}
	cout << N - ma << endl;
}





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

int main() {
	int h, w;
	while (true) {
		cin >> h >> w;
		if (h == 0 && w == 0)break;
		for (int i = 0; i < h/2; i++) {
			for (int j = 0; j < w / 2; j++)cout << "#.";
			if (w % 2 == 1)cout << '#';
			cout << endl;
			for (int j = 0; j < w / 2; j++)cout << ".#";
			if (w % 2 == 1)cout << '.';
			cout << endl;
		}
		if (h % 2 == 1) {
			for (int j = 0; j < w / 2; j++)cout << "#.";
			if (w % 2 == 1)cout << '#';
			cout << endl;
		}
		cout << endl;
	}
}


Measured memory_bytes: 3092
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 999999999

using namespace std;


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


ll cake[1010][3];
ll cake2[1010][3];
ll a[8][1010];
ll x[3];
int main() {
	int N, M;
	cin >> N >> M;
	REP(i, N)REP(j, 3)cin >> cake[i][j];
	int cnt = 0;
	REP(pat, 8) {
		REP(i, N) {
			REP(j, 3) {
				if (pat&(1 << j)) {
					x[j] = -cake[i][j];
				}
				else x[j] = cake[i][j];
			}
			a[pat][i] = x[0] + x[1] + x[2];
		}
	}
	ll ans = 0;

	REP(i, 8) {
		ll c = 0;
		SORT(a[i], N);
		REVERSE(a[i], N);
		REP(j, M) {
			c += a[i][j];
		}
		if(c > ans)ans = c;
	}
	cout << ans << endl;
}


Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#define rep(i,n) for(int i = 0; i<n;++i)
using namespace std;

int main(void){
	int d,e;
	while(cin >> d >> e,d){
		double ans = 1e100;

		for(int x = 0; x <= d;++x){
			int y = d - x;
			ans = min(ans, abs(sqrt(1.0*x*x+1.0*y*y)-e));
		}

		cout.precision(20);
		cout << fixed << ans << endl;

	}
	return 0;
}

Measured memory_bytes: 3160
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 1000010
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
char s[N]; 
int n,dp[N][2];
int main(){
	scanf("%s",s+1);
	n=strlen(s+1);
	dp[n][0]=s[n]-'0',dp[n][1]=10-dp[n][0];
	for(int i=n-1;i>=1;i--){
		int c=s[i]-'0';
		dp[i][0]=min(dp[i+1][0]+c,dp[i+1][1]+c+1);
		dp[i][1]=min(dp[i+1][0]+10-c,dp[i+1][1]+9-c);	
	}
	cout<<min(dp[1][0],dp[1][1]+1)<<endl;
	return 0;
}


Measured memory_bytes: 9088
#include <stdio.h>

int main(){
  int i, n, a, b, suma, sumb;

  scanf("%d", &n);

  while(n!=0){
    suma = sumb = 0;
    for(i=0;i<n;i++){
      scanf("%d" ,&a);
      scanf("%d" ,&b);
      if(a>b){
        suma += (a+b);
      }else if(a==b){
        suma += a;
        sumb += b;
      }else{
        sumb += (a+b);
      }
    }

    printf("%d %d\n", suma, sumb);

    scanf("%d", &n);
  }
  return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <cstring>
#include <cstdio>
int val[100005], app[25], seq[25];
int dp[100005], pop[100005], sum[100005];
int main()
{
	// freopen("E.in", "r", stdin);
	int n, m = 0, ans = 0;
	scanf("%d", &n);
	for (int i = 1; i < n; i++)
	{
		int u, v, w;
		scanf("%d%d%d", &u, &v, &w);
		val[u] ^= w;
		val[v] ^= w;
	}
	for (int i = 0; i < n; i++)
		app[val[i]]++;
	for (int i = 1; i < 16; i++)
	{
		ans += app[i] >> 1;
		if (app[i] & 1)
			seq[m++] = i;
	}
	for (int i = 1; i < 1 << m; i++)
	{
		pop[i] = pop[i ^ (i & -i)] + 1;
		for (int j = 0; j < m; j++)
		{
			if (i & (1 << j))
				sum[i] ^= seq[j];
		}
	}
	memset(dp, 0x3f, sizeof(dp));
	dp[0] = 0;
	for (int i = 0; i + 1 < 1 << m; i++)
	{
		int rem = (1 << m) - 1 ^ i, low = rem & -rem;
		for (int j = rem ^ low; ; j = j - 1 & (rem ^ low))
		{
			int add = j | low;
			if (!sum[add])
				dp[i | add] = std::min(dp[i | add], dp[i] + pop[j]);
			if (!j)
				break;
		}
	}
	printf("%d\n", ans + dp[(1 << m) - 1]);
	return 0;
}


Measured memory_bytes: 1152
import sys
sys.setrecursionlimit(10**9)
N, M = map(int, input().split())
edge = [[] for _ in range(N)]
for i in range(M):
    a, b = map(int, input().split())
    a, b = a-1,b-1
    edge[a].append(b)
    edge[b].append(a)

visited = [0] * N
cnt = 0
def dfs(n):
    global cnt
    if visited[n]: return
    cnt += 1
    visited[n] = True
    for nv in edge[n]:
        dfs(nv)

ans = 0
for i in range(N):
    cnt = 0
    dfs(i)
    ans = max(ans, cnt)
print(ans)


Measured memory_bytes: 680544
#include<bits/stdc++.h>
#define LL long long
using namespace std;

LL k,n,t;

int main(){
	cin>>k;
	if(!(k%7))k/=7;
	n=1,t=1;
	while(t<=k+1){
		n%=k;
		if(!n){
			cout<<t<<endl;
			return 0;
		}
		t++;
		n=n*10+1;
	}
	cout<<"-1"<<endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	int N; cin >> N;
	string S; cin >> S;

	int p = 0; // 括弧のペア数
	string pre = ""; // 前に加える文字列
	string post = ""; // 後ろに加える文字列
	for (int i = N - 1; i >= 0; --i){
		if (S[i] == '('){
			if (p > 0){
				--p;
			}else{
				post += ')';
			} // end if
		}else{ // if (S[i] == ')')
				p += 1;
		} // end if
	} // end rep

	pre = string(p, '(');
	string res = pre + S + post;
	cout << res << endl;
		
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_083_B
{
    class Program
    {
        static void Main(string[] args)
        {
			var input = Console.ReadLine().Split(' ');
			int N = int.Parse(input[0]);
			int A = int.Parse(input[1]);
			int B = int.Parse(input[2]);
			int ans = 0;
			for (int i = 1; i <= N; i++)
			{
				int sum = 0;
				int tmp_num = i;
				while (tmp_num > 0)
				{
					sum += tmp_num % 10;
					tmp_num /= 10;
				}
				if (sum >= A && sum <= B) ans += i;
			}
			Console.WriteLine(ans);
		}
    }
}


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

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

int n;
vector<int> e[100000];
int g[100000];
bool saw[100000];

int dfs(int v) {
    saw[v] = true;
    int ret = 0;
    rep(i,e[v].size()) {
        if(saw[e[v][i]]) continue;
        ret ^= (dfs(e[v][i])+1);
    }
    return ret;
}

int main(){
    cin >> n;
    rep(i,n-1) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        e[x].push_back(y);
        e[y].push_back(x);
    }
    int ans = dfs(0);
    if(ans == 0) {
        cout << "Bob" << endl;
    } else {
        cout << "Alice" << endl;
    }
}
































Measured memory_bytes: 10496
#include <iostream>
using namespace std;
int main(void){
  int i, n, max, min;
  cin >> n;
  int a[n];
  for(i=0;i<n;i++) cin >> a[i];

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

  min = a[0];
  for (i = 1; i < n; i++) {
    if (min > a[i]) {
      min = a[i];
    }
  }
  cout << max-min << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
const long long MOD = 1000000007;
const int INF = INT_MAX / 2;
const long double PI = 3.1415926;
using namespace std;
#define FOR(i, r, n) for(int i=(ll)(r); i<(ll)(n); i++) 
#define REP(i, n) FOR(i, (0), n)
#define ALL(r) r.begin(), r.end()
#define ll long long int
#define lld long double
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> vp;
typedef vector<tuple<ll, ll, ll>> vt;
//vector<vector<ll>> vv(n, vector<ll>(n));

int main()
{
	string s;
	cin >> s;
	if (s.size() < 4) cout << "No" << endl;
	else if (s.substr(0, 4) == "YAKI") cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 768
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()

m = 0
ans = 1

for i in range(1,n+1):
    if i % 2 == 1:
        continue
    cnt = 0
    t = i
    while t % 2 == 0:
        t //= 2
        cnt += 1
    if cnt > m:
        ans = i
        m = cnt

print(ans)


Measured memory_bytes: 62008
#include<bits/stdc++.h>
using namespace std;
int main()
{
int num[50500],n,ma,anslow=0,anshigh=0;
ma=sqrt(50500);
for(int i=1;i<50500;i++)num[i]=0;
for(int i=2;i<ma;i++){
if(num[i]==0){
for(int j=2;j*i<50500;j++)num[j*i]=1;
}
}
while(cin>>n){
for(int i=1;anslow==0||anshigh==0;i++){
if(num[n-i]==0&&anslow==0)anslow=n-i;
if(num[n+i]==0&&anshigh==0)anshigh=n+i;
}
cout<<anslow<<" "<<anshigh<<endl;
anshigh=0;anslow=0;
}
}

Measured memory_bytes: 1356
def examA():
    N = I()
    L = LI()
    L.sort()
    if sum(L)<=L[-1]*2:
        print("No")
    else:
        print("Yes")
    return

def examB():
    N, M = LI()
    A = [LI()for _ in range(N)]
    A.sort(key=lambda x:x[0])
    ans = 0
    for a,b in A:
        if M<=b:
            ans += a*M
            break
        ans += a*b
        M -= b
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(readline())
def LI(): return list(map(int,readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examB()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 29860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,s,n) for(int i = (s); i < (n); i++)
#define all(v) v.begin(), v.end()

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  if(abs(a-c) <= d or (abs(a-b)<= d and abs(b-c) <= d))
    cout << "Yes" << "\n";
  else
    cout << "No" << "\n";
  
  //cout << fixed << setprecision(10) << n << "\n";

}


Measured memory_bytes: 256
n,m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
bc = m.times.map{gets.split.map(&:to_i)}.sort_by{|b,c|-c}
idx = 0
bc.each{|b, c|
  while idx <  n && a[idx] < c && b > 0
    a[idx] = c
    idx += 1
    b -= 1
  end
}
puts a.inject(:+)

Measured memory_bytes: 21024
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int inf = 1001001001;
//2020/7/27 23:47-

int main(){
  int n;
  cin >> n;
  map<string,ll> m;
  rep(i,n) {
    string s;
    cin >> s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  ll ans = 0;
  for(auto p : m) {
    ll n = p.second;
    ans += n*(n-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 11324
#include <iostream>
#include <algorithm>
#include <tuple>
#include <vector>
#include <string>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;
using ll = long long;

struct UnionFind{

    vector<int> par;

    UnionFind(int N) : par(N){
        for(int i = 0; i < N; i++) par[i] = i;
    }

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

    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry) return ;
        par[rx] = ry;
    }

    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

};

int main()
{
    int n, k, l;
    cin >> n >> k >> l;
    vector<int> p(k), q(k), r(l), s(l);
    map<int, int> ans, path, train;
    UnionFind tree1(n), tree2(n);
    
    for(int i = 0; i < k; i++){
        cin >> p[i] >> q[i];
        tree1.unite(p[i]-1, q[i]-1);
    }

    for(int i = 0; i < l; i++){
        cin >> r[i] >> s[i];
        tree2.unite(r[i]-1, s[i]-1);
    }

    map<pair<int, int>, int> pa;
    for(int i = 0; i < n; i++){
        pa[{tree1.root(i), tree2.root(i)}]++;
    }
    for(int i = 0; i < n; i++){
        cout << pa[{tree1.root(i), tree2.root(i)}] << endl;
    }
    return 0;
}

Measured memory_bytes: 17696
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e17 // 4倍しても(4回足しても)long longを溢れない
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  ll n; cin >> n;
  vector<ll> a(n), b(n), diff(n);
  ll suma = 0, sumb = 0;
  rep(i,n) {
    cin >> a[i];
    suma += a[i];
  }
  rep(i,n) {
    cin >> b[i];
    sumb += b[i];
  }

  if (suma < sumb) {
    cout << -1 << endl;
    return 0;
  }

  ll remain = suma - sumb;

  for (int i = 0; i < n; ++i) {
    diff[i] = a[i] - b[i];
  }

  ll ans = 0;
  sorti(diff);
  for (int i = 0; i < n; ++i) {
  
    if (diff[i] < 0) {
      ans++;
      continue;
    }

    if (remain - diff[i] < 0) {
      ans += n - i;
      break;
    } else {
      remain -= diff[i];
    }
  }

  cout << ans << endl;
}


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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

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

int main( void )
{
	ll x, y;
	cin >> x >> y;

	ll tmp = y - x * 2;

	if ( ((tmp % 2) != 0) || (tmp > (x * 2)) || (tmp < 0) ) {
		cout << "No" << endl;
	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
#define repi(i,a,b) for(ll i = (ll)(a); i < (ll)(b); 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; }
const ll INF = 1LL << 60;

ll n;
int main(){
    cin >> n;
    vector<ll> av;
    ll tmp;
    rep(i,n){cin>>tmp; av.push_back(tmp);}

    sort(av.begin(), av.end());
    ll last = -1;
    int flag = 0;
    rep(i,n){
        if (last == av[i]){
            flag = 1;
            break;
        }
        last = av[i];
    }
    

    if (flag==0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

Measured memory_bytes: 2420
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=2e5+5; 

ll n,a[maxn];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	ll sum=a[n-1],t=n-2,tmp=t/2;
	int i=n-2;
	for(;i>n-2-tmp;i--){
		sum+=2*a[i];
	}
	if(t%2)sum+=a[i];
	cout<<sum;
	return 0;
}

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

struct BinaryIndexedTree {
    vector<int> data;
    int n;
    BinaryIndexedTree(int n) : data(n+1), n(n+1) {}

    void update(int i,long x){
        for(; i <= n; i += i & -i) data[i] += x;
    }

    long query(int i){
        long ret = 0;
        for(; i > 0; i -= i & -i) ret += data[i];
        return ret;
    }
};

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    long n; cin >> n;
    long a[100010]; for(int i = 0; i < n; ++i) cin >> a[i];

    long l = 0, r = 2e9;
    while(r - l > 1) {
        long mid = (l + r) / 2;
        BinaryIndexedTree bit(n * 2);
        long sum = n + 1, num = 0;
        bit.update(sum, 1);

        for(int i = 0; i < n; ++i) {
            sum += (a[i] <= mid ? 1 : -1);
            num += bit.query(sum - 1);
            bit.update(sum, 1);
        }

        if(num > n * (n + 1) / 2 - num) r = mid;
        else l = mid;
    }

    cout << r << endl;
    return 0;
}

Measured memory_bytes: 1804
//AUTHOR:BlackBox Inc.//
#include<bits/stdc++.h>
#include<unordered_map>
#include<tr1/unordered_map>
#define ll long long
#define ull unsigned long long
#define vi vector<int>
#define vlli vector<long long int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int>>
#define vs vector<string>
#define lin1(x) ll int x; x = scan();
#define lin2(x,y) ll int x, y; x = scan(), y = scan();
#define lin3(x,y,z) ll int x, y, z; x = scan(), y = scan(), z = scan();
#define pb(x) push_back(x)
#define makep(x,y) make_pair(x,y)
#define mx(a,b) (a)>(b)?(a):(b)
#define mn(a,b) (a)<(b)?(a):(b)
#define fori(s,e) for(i=s;i<=e;i++)
#define forj(s,e) for(j=s;j<=e;j++)
#define fork(s,e) for(k=s;k<=e;k++)
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x));
#define bits1(x) __builtin_popcount(x)
#define pi 3.14159265358979323846264338327950
#define MOD7 1000000007
#define MOD9 1000000009
#define fast std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
using namespace std;
using namespace std::tr1;

int main()
{
#ifdef RAHUL
    freopen("input.txt","r",stdin);
#endif

int a,b;
cin>>a>>b;

if (a>=10)
{
    cout<<b<<endl;
    /* code */
}
else{
    int x=100*(10-a);
    cout<<b+x<<endl;
}

return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

num = 0
for i in range(0, n, 2):
    num += a[i]
for i in range(1, n - 1, 2):
    num -= a[i]
ans = [num]
for i in range(n - 1):
    ans.append(2 * a[i] - ans[-1])
print(*ans)

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

int main()
{
    int N,L; cin>>N>>L;
    int taste = N*L+(N*N+N)/2-N;
    int bite;

    if(L >= 0) taste -= L;
    else
    {
        if(!(L+N-1 >= 0)) taste -= L+N-1;
    }
    cout << taste << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>


int main(void){
    unsigned long int x = -1;
    scanf("%lu\n", &x);

    if (x == -1){
        printf("Error in scan");
        return 1;
    }
    
  	unsigned long int money = 100;
    for(int year = 0; year < 3763; year++){
        if (money >= x){
            printf("%d\n", year);
            break;
        }
        money *= 1.01;
    }

    return 0;
}

Measured memory_bytes: 2152
/******
author :- Mahmoud Tarek.
*******/

#include<bits/stdc++.h>

using namespace std ;

#define rg register
#define dbg(v) cerr << #v << " " << v ;
typedef long long ll ;

const int N = 1e5 + 5 ;
vector<int> adj[N] ;
int n, m, a, b ;
int dp[N] ;

int solve(int i){

   if(i != 0 && !adj[i].size()){
     return 0 ;
   }

   int & ret = dp[i] ;
   if(~ret) return ret ;
   ret = 0 ;
   if(i == 0){
      for(int j = 1 ; j <= n ; j++)
        ret = max(ret, solve(j)) ;
   }

   for(auto j: adj[i]){
      ret = max(ret, 1 + solve(j)) ;
   }

   return ret ;
}

int main() {
//  freopen("in.txt", "r", stdin) ;

    cin >> n >> m ;
    for(int i = 0 ; i < m ; i++){
        cin >> a >> b ;
        adj[a].push_back(b) ;
    }

    memset(dp, -1, sizeof dp) ;
    cout << solve(0) ;

}


/*
  Empty set of troubles.
*/



Measured memory_bytes: 7424
import bisect
A, B, Q = map(int, input().split())
INF = 10**18
shrine = [-INF] + [int(input()) for i in range(A)] + [INF]
temple = [-INF] + [int(input()) for i in range(B)] + [INF]

for i in range(Q):
    pos = int(input())
    b,d = bisect.bisect_right(shrine, pos), bisect.bisect_right(temple, pos)
    res = INF
    for S in [shrine[b-1], shrine[b]]:
        for T in [temple[d-1], temple[d]]:
            d1, d2 = abs(S-pos)+abs(T-S), abs(T-pos)+abs(S-T)
            res = min(res, d1, d2)
    print(res)

Measured memory_bytes: 14720
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;

ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

int main(){
	string s;
	cin >> s;
	//-----------------------------------
	ll total = 0;
	int n = s.length()-1;
	if(n>=1){
		for(int bit = 0; bit < (1<<n); bit++){
			ll tmp = s[0]-'0';
			ll res = 0;
			int pos = 1;
			for(int i = 0; i < n; i++){
				if(bit & (1<<i)){
					res += tmp;
					tmp = s[pos++]-'0';
					//cout << "tmp:" << tmp << endl;
					//cout << "res:" << res << endl; 
				}else{
					tmp = tmp*10 + (s[pos++]-'0');
					//cout << "tmp!:" << tmp << endl;
					//cout << "res!:" << res << endl; 
				}
				if(pos>n) res += tmp;
			}
			total += res;
		}
	}else{
		total = s[0]-'0';
	}
	
	//----------------------------------- 
	cout << total << endl;
}

Measured memory_bytes: 256