akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
"""
Basic Data Structures - Splice
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ITP2_2_D&lang=jp

"""

class Node:
    def __init__(self, value=0):
        self.key = value
        self.prev, self.next = None, None

class Lst:
    def __init__(self):
        self.nil = Node('END')
        self.nil.next = self.nil
        self.nil.prev = self.nil
        self.cur = self.nil

    def insert(self, value):
        x = Node(value)
        x.prev = self.cur
        x.prev.next = x
        x.next = self.nil
        self.cur = x

    def dump(self):
        res = []
        cur = self.nil
        while cur.next.key != 'END':
            cur = cur.next
            res.append(cur.key)
        print(*res)

class Sp:
    def __init__(self, n):
        self.lst = [Lst() for _ in range(n)]

    def insert(self, t, x):
        self.lst[t].insert(x)

    def dump(self, t):
        self.lst[t].dump()

    def splice(self, s, t):
        self.lst[t].cur.next = self.lst[s].nil.next
        self.lst[s].nil.next.prev = self.lst[t].cur
        self.lst[t].cur = self.lst[s].cur
        self.lst[s] = Lst()


n, q = map(int, input().split())
lst = Sp(n)
for _ in range(int(q)):
    op, t, x = (input() + ' 1').split()[:3]
    if op == '0':
        lst.insert(int(t), int(x))
    elif op == '1':
        lst.dump(int(t))
    else:
        lst.splice(int(t), int(x))



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

int main(){

	char str[30] ={0};
	char tempstr[30] = {0};
	int a,i;

	scanf("%s",str);

	a = strlen(str);
	a=a-1;

	for(i=a;i>=0;i--)
		tempstr[a-i]=str[i];

	printf("%s\n",tempstr);


	
	return 0;
}

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

using namespace std;
int main()
{
	int N;

	cin >> N;

	string W[N];

	for(int i=0;i<N;i++){
		cin >> W[i];
	}

	//cout << W[0].front()<<endl;
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if((i!=j)&(W[i]==W[j])){
				cout << "No"<<endl;
				return 0;
			}
		}
	}

	for(int i=0;i<N;i++){



		if(i==0){
			continue;
		}
		if((W[i].front())!=(W[i-1].back())){
			cout<<"No"<<endl;
			return 0;
		}

	}

	cout <<"Yes"<<endl;



	return 0;
}




Measured memory_bytes: 256
#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,int> P;
const int MAX_N = 2005;
vector<P> A(MAX_N);
ll dp[MAX_N][MAX_N]; //dp[i][j] := 左にi人、右にj人

int main()
{
	int N;
	cin >> N;
	rep(i,N)
	{
		ll a;
		cin >> a;
		A[i] = P(a,i+1);
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	dp[0][0] = 0;
	for (int i = 0; i <= N; ++i)
	{
		for (int j = 0; j <= i; ++j)
		{
			int l = i-j, r = j;
			if (l != 0) dp[l][r] = max(dp[l][r], dp[l-1][r] + A[l+r-1].first * abs(l-A[l+r-1].second));
			if (r != 0) dp[l][r] = max(dp[l][r], dp[l][r-1] + A[l+r-1].first * abs(N-r+1-A[l+r-1].second));
		}
	}
	ll ans = 0;
	/*
	for (int i = 0; i <= N; ++i)
	{
		for (int j = 0; j <= N-i; ++j)
		{
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
	*/
	for (int i = 0; i <= N; ++i)
	{
		ans = max(ans, dp[i][N-i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26276
#define _GLIBCXX_DEBUG
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;
priority_queue<int> pq;
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;

int P[10010];
void init(int n){
    for(int i=0;i<n;++i)P[i]=i;
}
int root(int a) {
    if(P[a]==a)return a;
    return (P[a]=root(P[a]));
}
bool is_same_set(int a,int b){
    return root(a) == root(b);
}
void unite(int a,int b){
    P[root(a)]=root(b);
}//対グラフ

double dot_product(xy_t a, xy_t b) { return (conj(a)*b).real(); }//内積
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }//外積
xy_t projection(xy_t p, xy_t b) { return b*dot_product(p,b)/norm(b); }//投影
//対図形

int main(){
    int s;
    cin >>s;
    int a[1000000];
    a[0]=s;
    int n=a[0];
    int p=0;
    int t=0;
    while(1){
        if(n%2==0){
            n=n/2;
        }else{
            n=3*n+1;
        }
        p=p+1;
        a[p]=n;
        rep(i,p){
            if(n==a[i]){
                t=1;
            }
        }
        if(t==1){
            break;
        }
    }
    cout<<p+1<<endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		boolean[] canmake = new boolean[10101]; // kawaii!
		Arrays.fill(canmake, false);
		for(int i = 0; i < N; i++) {
			int s = sc.nextInt();
			for(int j = 10100; j >= 0; j--) {
				if(canmake[j] && j + s < 10101) canmake[j + s] = true;
			}
			canmake[s] = true;
		}
		int ans;
		for(ans = 10000; ans > 0; ans--) if(canmake[ans] && (ans % 10 != 0)) break;
		System.out.println(ans);
	}
}

Measured memory_bytes: 22228
#include <stdio.h>
#include <cmath>
#include <bits/stdc++.h>



using namespace std;

typedef vector<int> VI;
typedef vector<string> VS;


//container util
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)



int main(void){

	vector<string> C(2);
	REP(i,2) cin >> C[i];

	if(C[0][0] == C[1][2] and C[0][1] == C[1][1] and C[0][2] == C[1][0]) cout << "YES" << endl;
	else cout << "NO" << endl;
	
		


	return 0;

}


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

int main () {
  string a , b ;
  cin >> a >> b ;
  int c = stoi(a+b) ;
  int i = floor(sqrt(c));
  if ( pow(i,2) == c){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;

int main()
{
	int32_t N;
	cin >> N;

	vector<int32_t> x(N), y(N), h(N);
	for (int32_t i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
	}

	for (int32_t cx = 0; cx <= 100; cx++) {
		for (int32_t cy = 0; cy <= 100; cy++) {
			int32_t fixed_H = -1;
			int32_t min_H = numeric_limits<int32_t>::max();
			bool found = true;
			for (int32_t i = 0; i < N; i++) {
				if (h[i] == 0)
					min_H = min(min_H, abs(x[i] - cx) + abs(y[i] - cy));
			}
			for (int32_t i = 0; i < N; i++) {
				if (h[i] > 0) {
					int32_t local_H = h[i] + abs(x[i] - cx) + abs(y[i] - cy);
					if (fixed_H == -1)
						fixed_H = local_H;
					if (fixed_H != local_H || fixed_H > min_H) {
						found = false;
						break;
					}
				}
			}
			if (found) {
				cout << cx << " " << cy << " " << fixed_H << endl;
				return 0;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count etc.
#include <cstdlib>	// require abs
#include <cstdio>	// require printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>	// require tolower, toupper
#include <fstream>	// require freopen

using namespace std;

map <string, int> minC;
map <string, vector <string> > rela;

bool last_item (string item )
{
	return (rela.find(item) == rela.end() );
}

void dfs (string item )
{
	if (last_item (item ) ){
		return;
	} // end if

	map <string, vector <string> >::iterator it = rela.find(item);
	vector <string> r = (*it).second;
	vector <string>::iterator jt = r.begin();

	int sum = 0;
	int prev = minC[item];

	for (; jt != r.end(); ++jt ){
		dfs ((*jt) );
		sum += minC[(*jt)];
	} // end for
	if (prev > sum )
		minC[item] = sum;

}

int main()
{
//	cut here before submit 
//	freopen ("testcase.wgm", "r", stdin );
	int n, m;

	while (cin >> n && n ){
		minC.clear();
		rela.clear();
		for (int i = 0; i < n; ++i ){
			string ite = "";
			int cost;
			cin >> ite >> cost;
			minC[ite] = cost;
		} // end for
		cin >> m;
		for (int i = 0; i < m; ++i ){
			string s = "";
			cin >> s;
			int num;
			cin >> num;
			vector <string> t (num );
			for (int j = 0; j < num; ++j ){
				cin >> t[j];
			} // end for
			rela[s] = t;
		} // end for
		string qns;
		cin >> qns;
		
		dfs (qns );

		cout << minC[qns] << endl;
	} // end loop
		
	return 0;
}

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

using namespace std;

int main() {
	int MAX = 55555;
	int N;
	vector<bool> prime(MAX + 1,true);

	cin >> N;

	for (int i = 2; i*i <= MAX; i++) {
		for (int j = 2 ;prime[i] &&  i*j <= MAX;j++) {
			prime[i*j] = false;
		}
	}
	int ans = 0;
	for (int i = 2; i <= MAX && ans < N; i++) {
		if (prime[i] && (i - 1) % 5 == 0) {
			cout << i << " ";
			ans++;
		}
	}

	cout<< endl;

	return 0;
}

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

if (b-a+1)/2 < k:
    for i in range(a, b+1):
        print(i)
else:
    for j in range(a, a+k):
        print(j)
    for k in range(b-k+1, b+1):
        print(k)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define all(x) (x).begin(),(x).end()
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll a[n]={};
ll ans=0;
ll ans1=0;
ll b[n]={};
ll ca;
for(ll i=0; i<n; i++){
cin>>a[i];
b[i]=a[i];}
sort(a,a+n);
sort(b,b+n);
reverse(b,b+n);
if(n%2==1){
ca=a[(n-1)/2];
for(ll i=0; i<n/2; i++){
ans+=abs(a[i]-ca);
ca=a[i];
ans+=abs(b[i]-ca);
ca=b[i];}
ca=a[(n-1)/2];
for(ll i=0; i<n/2; i++){
ans1+=abs(b[i]-ca);
ca=b[i];
ans1+=abs(a[i]-ca);
ca=a[i];}
ans = max(ans , ans1);
cout << ans << endl;}
else{
ll ca = a[n/2];
for(ll i=0; i<n/2-1; i++){
ans+=abs(a[i]-ca);
ca=a[i];
ans+=abs(b[i]-ca);
ca=b[i];}
ans+=abs(ca-a[n/2-1]);
cout << ans << endl;}}


Measured memory_bytes: 5208
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
 
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
int dx[2] = {0,1};
int dy[2] = {1,0};

int main(){
    string S;
    getline(cin,S);
    int ans = 1000;

    int N = S.length();



    REP(i,N){
        char target = S[i];
        string nowS = S;
        bool term = false;

        term = true;
        REP(k,nowS.length()){
            if (nowS[k] != target) term = false; 
        }

        if (term){
            PRINTD(0);
            return 0;
        }



        while(!term){
            string next = "";
            REP(j,nowS.length()-1){
                if (nowS[j] == target || nowS[j+1] == target){
                    next.push_back(target);
                }else{
                    next.push_back('*');
                }
            }

            term = true;
            REP(k,next.length()){
               if (next[k] != target) term = false; 
            }

            nowS = next;
        }

        if (ans >= N - nowS.length()) ans = N - nowS.length();
        //printf("target = %c, %s \n",target,)

    }

    cout << ans << endl;

}


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

const int INF = 1e5+2;

int main() {
    std::cout<<std::fixed<<std::setprecision(10);
    
    int N; cin >> N;
    vector<int> B(N+1);
    B[0] = INF;
    B[N] = INF;
    rep(i, N-1) cin >> B[i+1];

    int ans = 0;

    rep(i, N) {
        // cout << "i: " << i << endl;
        // cout << B[i] << " " << B[i+1] << endl;
        ans += min(B[i], B[i+1]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int N, A;
    cin >> N >> A;
    cout << N * N - A << endl;
    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
adjacent = []
score = ['None' for i in range(N)]
score[0] = 0
for i in range(M):
    a, b, c = map(int, input().split())
    adjacent.append([a-1, b-1, c])
for i in range(N):
    for j in adjacent:
      if score[j[1]] == 'None' and score[j[0]] != 'None':
        score[j[1]] = score[j[0]] + j[2]
      if score[j[1]] != 'None' and score[j[0]] != 'None':
        if score[j[1]] < score[j[0]] + j[2]:
          score[j[1]] = score[j[0]] + j[2]
    if i == N-2:
      t = score[N-1]
    if i == N-1:
      if t != score[N-1]:
        score[N-1] = 1e+15
if score[N-1] < 1e+15:
    print(t)
else:
    print('inf')

Measured memory_bytes: 3420
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        for (int i = 0; i < n; i++) {
            String k1 = sc.next();
            String k2 = sc.next();
            int r = toDec(k1) + toDec(k2);
            // System.out.println(toDec(k1));
            // System.out.println(toDec(k2));
            // System.out.println(r);
            System.out.println(toMc(r));
        }
    }

    public static int toDec(String s) {
        int t = 1;
        int sum = 0;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c == 'm') {
                sum += t * 1000;
                t = 1;
            } else if (c == 'c') {
                sum += t * 100;
                t = 1;
            } else if (c == 'x') {
                sum += t * 10;
                t = 1;
            } else if (c == 'i') {
                sum += t;
                t = 1;
            } else {
                t = Integer.valueOf(c + "");
            }
        }
        return sum;
    }

    public static String toMc(int n) {
        int mn = n / 1000 % 10;
        int cn = n / 100 % 10;
        int xn = n / 10 % 10;
        int in = n % 10;
        String k = "";
        if (mn > 1) {
            k += String.valueOf(mn) + "m";
        } else if (mn == 1) {
            k += "m";
        }
        if (cn > 1) {
            k += String.valueOf(cn) + "c";
        } else if (cn == 1) {
            k += "c";
        }
        if (xn > 1) {
            k += String.valueOf(xn) + "x";
        } else if (xn == 1) {
            k += "x";
        }
        if (in > 1) {
            k += String.valueOf(in) + "i";
        } else if (in == 1) {
            k += "i";
        }
        return k;
    }
}

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

#define FOR(i,a,b)  for(ll (i)=a;(i)<(b);++(i))
#define RFOR(i,a,b) for(ll (i)=a;(i)>=(b);--(i))
#define REP(i,n)    FOR(i,0,n)
#define RREP(i,n)   RFOR(i,n,0)
#define ALL(v)      (v).begin(),(v).end()
#define BIT(n)      (1LL<<(n))
#define IN(x,l,r)   ((l)<=(x)&&(x)<=(r))
#define SHOW(x)     cout<<#x<<" = "<<x<<endl
#define SORT(v)     sort(ALL(v))
#define SZ(v)       (ll)(v).size()
#define UNIQ(v)     SORT(v);(v).erase(unique(ALL(v)),(v).end())
#define PERM(c)     for(bool p=1;p;p=next_permutation(ALL(c)))
#define PQ(T)       priority_queue<T,vector<T>,greater<T>>

template<typename T>string join(const vector<T>& v, string d=" ")
{stringstream s;REP(i,SZ(v))s<<d<<v[i];return s.str().substr(d.length());}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v)
{if(SZ(v))s<<join(v,", ");return s;}

const ll inf = 1e15;
const ll mod = 1e9+7;
const double eps = 1e-10;

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

int main() {
    ll A, B, C; cin >> A >> B >> C;
    
    if (A % 2 == 0 or B % 2 == 0 or C % 2 == 0) {
        cout << 0 << endl;
        return 0;
    }
    
    cout << min({A * B, B * C, C* A}) << endl;
    
    return 0;
}


Measured memory_bytes: 256
def check(n):
    """
    if n <= P-1:
        return True
    """
    
    if A[n]+M < A[P-1]:
        return False
    
    votes = (P+N-1-n)*M + sum([A[n]+M-A[i] for i in range(P-1,n)])

    if votes < M*V:
        return False
    else:
        return True

N,M,V,P = map(int,input().split())
A = list(map(int,input().split()))

A.sort(reverse=True)

right = N-1
left = P-1

if check(right):
    print(N)
    exit()

while abs(right-left) > 1:

    mid = (right+left)//2

    if check(mid):
        left = mid
    else:
        right = mid

print(left+1)

Measured memory_bytes: 14964
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int NMAX=110;
const ll VMAX=100100;
int N;
ll W;
vector<ll> v(NMAX);
vector<ll> w(NMAX);

int main()
{
    cin >> N>>W;
    REP(i, N) cin >> w[i]>>v[i];

    vector<vector<ll>> dp(NMAX, vector<ll>(VMAX, LLONG_MAX/10));
    
    dp[0][0] = 0;
    for (int i = 0; i < N; i++){
        for (int vsum = 0; vsum < VMAX; vsum++){
            if(vsum-v[i]>=0){
                chmin(dp[i+1][vsum], dp[i][vsum-v[i]]+w[i]);
            }
            chmin(dp[i+1][vsum], dp[i][vsum]);
        }
    }

    ll res=0;
    for(int vsum=0; vsum<VMAX; vsum++){
        if(dp[N][vsum] <=W) res = vsum;
    }
    cout << res << endl;

    return 0;
}

Measured memory_bytes: 87296
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    int n, m;
    cin >> n >> m;
    vector<vector<P>> table(n + 1);
    for(int i = 0; i < m; ++i){
        int p, y;
        cin >> p >> y;
        table[p].emplace_back(y, i);
    }
    for(int i = 1; i <= n; ++i){
        sort(table[i].begin(), table[i].end());
    }
    vector<P> ans(m);
    for(int i = 1; i <= n; ++i){
        for(int j = 0; j < (int)table[i].size(); ++j){
            P p = table[i][j];
            ans[p.second] = P(i, j + 1);
        }
    }
    for(P p : ans){
        cout << setfill('0') << right << setw(6) << p.first;
        cout << setfill('0') << right << setw(6) << p.second << '\n';
    }
}

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

int n;
int a[1 << 18];
pair<int,int> opt[1 << 18];
int res[1 << 18];

bool cmp(int x,int y) { return a[x] > a[y]; }

int main() {
	ios_base::sync_with_stdio(false);
	cin >> n;
	for (int i = 0; i < (1 << n); ++i) cin >> a[i];
	for (int i = 0; i < (1 << n); ++i) {
		vector<int> imp;
		imp.push_back(i);
		for (int j = 0; j < n; ++j) if ((i >> j) & 1) {
			int x = i ^ (1 << j);
			imp.push_back(opt[x].first);
			if (~opt[x].second) imp.push_back(opt[x].second);
		} 
		sort(imp.begin(), imp.end(), cmp);
		imp.resize(unique(imp.begin(), imp.end()) - imp.begin());
		if (!i) opt[i] = {imp[0], -1};
		else {
			opt[i] = {imp[0], imp[1]};
			res[i] = a[imp[0]] + a[imp[1]];
			res[i] = max(res[i], res[i - 1]);
		}
	} 
	for (int i = 1; i < (1 << n); ++i) cout << res[i] << '\n';
}

Measured memory_bytes: 7168
# 最小が最上位の親になる 優先度付きキュー PQ
# 最大が最上位の親にする時は、コメントアウト箇所を変更
# 更新機能
class PriorityQueue
  attr_accessor :data, :size

  def initialize(array = [])
    @data = []
    array.each { |a| push(a) }
  end

  def push(element)
    current = @data.size
    @data[up_heap(current, element)] = element
  end

  def pop
    ret = @data.first
    x = @data.last
    @data[down_heap(0, x)] = x
    @data.pop
    ret
  end

  def update(current, element)
    index = up_heap(current, element)
    index = down_heap(current, element) if index == current
    @data[index] = element
  end

  def size
    @data.size
  end

  def front
    @data.first
  end

  def empty?
    @data.empty?
  end

  def parent(num)
    (num - 1) / 2
  end

  def left_child_index(num)
    2 * num + 1
  end

  def right_child_index(num)
    2 * num + 2
  end

  def have_parent?(index)
    index > 0
  end

  def have_child?(index)
    left_child_index(index) < @data.size
  end

  private

    def up_heap(current, element)
      while have_parent?(current)
        p_index = parent(current)
        # break if @data[p_index] >= element
        break if @data[p_index] <= element
        @data[current] = @data[p_index]
        current = p_index
      end
      current
    end

    def down_heap(current, element)
      while have_child?(current)
        a_index = left_child_index(current)
        b_index = right_child_index(current)
        # a_index = b_index if @data[b_index] && @data[b_index] > @data[a_index]
        # break if @data[a_index] <= element
        a_index = b_index if @data[b_index] && @data[b_index] < @data[a_index]
        break if @data[a_index] >= element
        @data[current] = @data[a_index]
        current = a_index
      end
      current
    end
end

n, m = gets.split.map(&:to_i)
nums = gets.split.map(&:to_i)
pq = PriorityQueue.new(nums.map { |i| -i } )
m.times { pq.push((pq.pop / 2.0).ceil) }
puts -pq.data.inject(:+)


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

int main(){
  int N;
  int64_t K;
  cin >> N >> K;
  vector<int> A(N);  
  for(int i = 0; i < N ; i++){
    cin >> A[i];
  }
  vector<bool> check1(N, false);
  int now = 0, cnt1 = 0, cnt2 = 0;
  
  while(true){
    if(check1[now]  == false){
      check1[now] = true;
      now = A[now]-1;
      cnt1++;
    }
    else
      break;
  }
  
  vector<bool> check2(N, false);
  
  while(true){
    if(check2[now]  == false){
      check2[now] = true;
      now = A[now]-1;
      cnt2++;
    }
    else
      break;
  }
  
  if(K >=cnt1){
  int ans = (K-cnt1)%cnt2;
    
    for(int i = 0; i < ans; i++){
      now = A[now]-1;
    }
  }
  
  else{
    now = 0;
    for(int i = 0; i < K; i++){
      now = A[now]-1;
    }
  }
  
  cout << now+1 << endl;
  
  return 0;
  
}


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

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

using namespace std;
using lint=long long;

template<class T>
class segment_tree{
	int n;
	vector<T> dat;
	T query(int l,int r,int a,int b,int u){
		if(l<=a && b<=r) return dat[u];
		T res=0;
		int c=(a+b)/2;
		if(l<c && a<r) res=max(res,query(l,r,a,c,2*u+1));
		if(l<b && c<r) res=max(res,query(l,r,c,b,2*u+2));
		return res;
	}
public:
	segment_tree(int N){
		for(n=1;n<N;n*=2);
		dat.assign(2*n-1,0);
	}
	void update(int u,T v){
		u+=n-1;
		dat[u]=max(dat[u],v);
		while(u>0) u=(u-1)/2, dat[u]=max(dat[2*u+1],dat[2*u+2]);
	}
	T query(int l,int r){ return query(l,r,0,n,0); }
};

int main(){
	int n; scanf("%d",&n);
	vector<int> h(n),a(n);
	rep(i,n) scanf("%d",&h[i]);
	rep(i,n) scanf("%d",&a[i]);

	vector<pair<int,int>> p(n);
	rep(i,n) p[i]={h[i],i};
	sort(p.begin(),p.end());

	segment_tree<lint> ST(n);
	for(auto q:p){
		int i=q.second;
		ST.update(i,ST.query(0,i)+a[i]);
	}
	printf("%lld\n",ST.query(0,n));

	return 0;
}


Measured memory_bytes: 7424
#include <bits/stdc++.h>
using namespace std;
string s;
int main() {
	cin >> s;
	for(int i = 0; i < s.size(); i++) s[i] = (s[i] - 65 + 23) % 26 + 65;
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3236
#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;}

int main(){
	ll n, a, b;
	cin>>n>>a>>b;
	string s;
	cin>>s;
	rep(i, s.size()){
		bool ok = true;
		if(s[i]=='a'){
			if(a) a--;
			else if(b) b--;
			else ok = false;
		} else if(s[i]=='b'){
			if(b) b--;
			else ok = false;
		} else ok = false;
		cout<<(ok?"Yes":"No")<<endl;
	}
	return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<list>

using namespace std;
static const int MAX = 100000;

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;

void dfs(int u) {
	V[u] = true;
	for (int i = 0; i < G[u].size(); i++) {
		int v = G[u][i];
		if (!V[v]) dfs(v);
	}
	out.push_front(u);
}

int main() {
	int s, t, M;
	cin >> N >> M;

	for (int i = 0; i < N; i++) {
		V[i] = false;
	}

	for (int i = 0; i < M; i++) {
		cin >> s >> t;
		G[s].push_back(t);
	}

	for (int i = 0; i < N; i++) {
		if (!V[i]) dfs(i);
	}

	for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
		cout << *it << endl;
	}

	return 0;
}



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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}
int main() {
	int n = ri();
	int m = ri();
	int a[m];
	int b[m];
	std::vector<int> hens[n];
	for (int i = 0; i < m; i++) a[i] = ri() - 1, b[i] = ri() - 1, hens[a[i]].push_back(b[i]), hens[b[i]].push_back(a[i]);
	int q = ri();
	int start[q];
	int dist[q];
	int color[q];
	for (int i = 0; i < q; i++) start[i] = ri() - 1, dist[i] = ri(), color[i] = ri();
	std::vector<int> res(n, -1);
	std::vector<int> cur(n, -1);
	for (int i = 10; i; i--) {
		for (int j = 0; j < q; j++) if (dist[j] == i) cur[start[j]] = std::max(cur[start[j]], j);
		std::vector<int> next(n, -1);
		for (int j = 0; j < n; j++) {
			for (auto k : hens[j]) next[k] = std::max(next[k], cur[j]);
		}
		std::swap(cur, next);
		for (int j = 0; j < n; j++) res[j] = std::max(res[j], cur[j]);
	}
	for (int i = 0; i < q; i++) res[start[i]] = std::max(res[start[i]], i);
	for (int i = 0; i < n; i++) {
		if (res[i] == -1) std::cout << 0 << std::endl;
		else std::cout << color[res[i]] << std::endl;
	}
	return 0;
}


Measured memory_bytes: 9576
/*
これを入れて実行
g++ code.cpp
./a.out
*/

#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef long double ld;

int dy4[4] = { -1, 0, +1, 0 };
int dx4[4] = { 0, +1, 0, -1 };
int dy8[8] = { -1, -1, 0, 1, 1, 1, 0, -1 };
int dx8[8] = { 0, 1, 1, 1, 0, -1, -1, -1 };

const long long INF = 1LL << 60;
const ll MOD = 1e9 + 7;

bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
	return f.second > s.second;
}

ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}

ll lcm(ll a, ll b){
	return a / gcd(a, b) * b;
}

ll nCr(ll n, ll r){
	if (r == 0 || r == n){
		return 1;
	}
	else if (r == 1){
		return n;
	}
	return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}

ll nPr(ll n, ll r){
	r = n - r;
	ll ret = 1;
	for (ll i = n; i >= r + 1; i--) ret *= i;
	return ret;
}

//-----------------------ここから-----------

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

	int w = 0;

	int rest = 15 - s.size();

	for (int i = 0; i < s.size(); i++){
		if (s[i] == 'o'){
			w++;
		}
	}

	if (rest + w >= 8){
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
} 


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

using namespace std;

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

    int count = 0;
    for (int i = 0; i < N; ++i) {
        int a;
        cin >> a;
        while (a % 2 == 0) {
            a /= 2;
            count++;
        }
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <stdio.h>
#include <math.h>


using namespace std;

typedef long long ll;

typedef vector<vector<int>> vvi;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<ll> vll;

typedef pair<int, int> P;
#define mp(x, y) make_pair(x, y)

typedef queue<int> qi;
typedef queue<string> qs;


#define rep(i, n) for(int i=0; i<(n); ++i)
#define repp(i, a, b) for(int i = (a); i <= (b); i++)
#define repm(i, n) for(int i=n; i >= 0; i--)

#define all(v) v.begin(), v.end()
//sort( all(v) )　などと使える


int main(void) {
	int AC = 0, WA = 0, TLE = 0, RE = 0;

	int n; cin >> n;
	rep(i, n) {
		string s; cin >> s;
		if (s == "AC") AC++;
		else if (s == "WA") WA++;
		else if (s == "TLE") TLE++;
		else RE++;
	}

	cout << "AC x " << AC << endl;
	cout << "WA x " << WA << endl;
	cout << "TLE x " << TLE<< endl;
	cout << "RE x " << RE << endl;
	return 0;
}



Measured memory_bytes: 3628
import java.util.Scanner;

public class Main{
    public static void main(String[]args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int i=0;
            int n = sc.nextInt();
            int r = sc.nextInt();
            int[] card = new int[n];
            if(n==0 && r==0) break;
            for(i=0;i<n;i++){
                card[i]=i+1;
            }
            for(i=0;i<r;i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                for(int j=0;j<(p+c-1)/2;j++){
                    int alt1=card[(n-1)-j];
                    card[(n-1)-j]=card[(n-(p+c-1))+j];
                    card[(n-(p+c-1))+j]=alt1;
                }
                for(int k=0;k<c/2;k++){
                    int alt2=card[(n-1)-k];
                    card[(n-1)-k]=card[(n-c)+k];
                    card[(n-c)+k]=alt2;
                }
                for(int l=0;l<(p-1)/2;l++){
                    int alt3=card[(n-c-1)-l];
                    card[(n-c-1)-l]=card[(n-(p+c-1))+l];
                    card[(n-(p+c-1))+l]=alt3;
                }
            }
             System.out.println(card[n-1]);
        }
    }
}


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

int main()
{
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, x;
  cin >> n >> x;
  if (x == 1 || x == 2 * n - 1) {
    cout << "No" << endl;
    return 0;
  }
  vector<int> ans(2 * n - 1);
  for (int i = n - 1; i < n - 1 + 2 * n; ++i) {
    ans[i % (2 * n - 1)] = (i - (n - 1) + (x - 1)) % (2 * n - 1) + 1;
  }
  cout << "Yes" << endl;
  for (int i : ans) {
    cout << i << '\n';
  }
  return 0;
}


Measured memory_bytes: 2304
#include<stdio.h>
long long dp[5][4001];
int main(){
	dp[0][0]=1;
	for(int i=0;i<4;i++)
		for(int j=0;j<=4000;j++){
			if(dp[i][j]){
				for(int k=0;k<=1000;k++)dp[i+1][j+k]+=dp[i][j];
			}
		}
	int b;
	while(~scanf("%d",&b)){
			printf("%lld\n",dp[4][b]);
	}
}

Measured memory_bytes: 1116
#アルゴリズム実装
def binarySearch(list, find_number):
    left = 0
    right = len(list)
    while left < right:
        mid = (left + right) // 2
        if list[mid] == find_number:
            return 1
        elif list[mid] > find_number:
            right = mid
        else:
            left = mid + 1
    return 0

#インプットdata
n_number = int(input())
n_list = list(map(int, input().split()))
q_number = int(input())
q_list = list(map(int, input().split()))
result = 0

#処理の実行
for i in range(q_number):
        result += binarySearch(n_list, q_list[i])

#結果の表示
print(result)


Measured memory_bytes: 16708
/*  
   |\_/|
   |* *|
   \_+_/
          */
#include<bits/stdc++.h>

#define endl '\n'

using namespace std;

int main(){

  cin.tie(0);     // cout と cin の同期を切る
  ios::sync_with_stdio(false);  /* cの stdioストリーム (printfとか)と*/

  int a,b;

  cin>>a>>b;

  cout<<a*b<<" "<<(a+b)*2<<endl;
  
  return 0;

}



Measured memory_bytes: 3128
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<string>
#include<set>
#include<unordered_map>
#include<iterator>
using namespace std;

int main()
{   
    vector<long long int> data;
    long long int N, i, ans, a, temp;
    cin>>N;
    for(i=0;i<N;i+=1)
    {
        cin>>a;
        data.push_back(a);
    }
    sort(data.begin(), data.end(), greater<long long int>());
    ans = data[0];
    temp = 0;
    for(i=2;i<N;i+=1)
    {
        if(i%2==0)
        {
            temp+=1;
        }
        ans+=data[temp];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5300
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <deque>
#include <algorithm>
#include <random>
#include <ctime>
using namespace std;
using ld = long double;
using ll = long long;
using pii = pair<int, int>;

#define int int64_t
#define pb push_back
#define pbb pop_back
#define pf pop_front
#define pff push_front
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()

const int INF = 1e6, MOD = 1e9 + 7, MAXN = 1e5 + 7;
const ld EPS = 1e-9, PI = acos(-1);

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

    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i = 0; i < n; ++i)
        cin >> nums[i];

    sort(all(nums));
    int first = nums.back(), second = nums.front();
    for (int i = 0; i < n; ++i)
        if (abs((first + 1) / 2 - second) > abs((first + 1) / 2 - nums[i]))
            second = nums[i];

    cout << first << " " << second << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main() {
	int A, B, C, X;

	cin >> A >> B >> C >> X;

	int ans = 0;
	for (int i = 0; i <= A; i++)
	{
		for (int j = 0; j <= B; j++) {
			if (X - 500 * i - 100 * j <= 50 * C && X - 500 * i - 100 * j >= 0) {
				ans++;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
m,n = map(int,input().split())
M =[]
N = []

for i in range(m):
    row = str(input())
    M.append(row)
for i in range(n):
    row = str(input())
    N.append(row)

for i in range(m-n+1):
    for j in range(m-n+1):
        M_ = []
        for k in range(n):
            M_.append(M[i+k][j:j+n])
            if M_ == N:
                print("Yes")
                exit()
print("No")


Measured memory_bytes: 3064
from statistics import median
N = int(input())
X = [int(i) for i in input().split()]
sort_X = sorted(X)
sort_X = sort_X[N//2-1:N//2+1]
for x in X:
    if sort_X[0] >= x:
        print(sort_X[1])
    else:
        print(sort_X[0])

Measured memory_bytes: 27240
from math import ceil
n,k=map(int,input().split())
a=[int(i) for i in input().split()]
def is_ok(x):
  c=0
  for i in a:
    c+=ceil(i/x)-1
    if c>k:
      return False
  return True
def binary_search(m): 
  left=0
  right=m+1
  while left<=right:
    center=(left+right)//2
    if right-left==1:
      return right
    elif is_ok(center):
      right=center
    else:
      left=center
if k==0:
  print(max(a))
else:
  print(binary_search(max(a)))

Measured memory_bytes: 30928
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>
#include <unordered_map>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N, M;
  cin >> N >> M;

  ll diff = 0;
  if (N == M) diff = 2;
  else if (abs(N-M) == 1) diff = 1;

  ull nN = 1;
  ull nM = 1;
  for (auto i = 2; i <= N; i++) nN = (nN * i) % mod;
  for (auto i = 2; i <= M; i++) nM = (nM * i) % mod;

  ull res = (nN * nM * diff) % mod;

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 888
#include <algorithm>
#include <iostream>
using namespace std;
int main() {
	int x, w[10], k[10];
	for(int i = 0; i < 20; i++) {
		cin >> x;
		if(i < 10) {
			w[i] = x;
		}
		else {
			k[i - 10] = x;
		}
	}
	sort(w, w + 10);
	sort(k, k + 10);
	cout << w[9] + w[8] + w[7] << " " << k[9] + k[8] + k[7] << endl;
}

Measured memory_bytes: 0
#include <cstdio>
#include <vector>
using namespace std;

bool isprime[50010];
int ans[50010];

int main(){
	for(int i = 2; i <= 50000; ++i){
		isprime[i] = true;
	}
	for(int i = 2; i < 300; ++i){
		if(isprime[i]){
			for(int j = i * i; j <= 50000; j += i){
				isprime[j] = false;
			}
		}
	}

	vector<int> primes;
	for(int i = 2; i <= 50000; ++i){
		if(isprime[i]) primes.push_back(i);
	}

	for(int i = 0; primes[i] <= 25000; ++i){
		for(int j = i; primes[i] + primes[j] <= 50000; ++j){
			++ans[primes[i] + primes[j]];
		}
	}

	int n;
	while(scanf("%d", &n), n){
		printf("%d\n", ans[n]);
	}
}

Measured memory_bytes: 1352
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()
int main(){
    int H,N;cin>>H>>N;
    int sum=0;
    rep(i,N){
        int a;
        cin>>a;
        sum+=a;
    }
    if(H<=sum)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 3612
///
/**
 * @Samaritan
 */
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;

#define pb emplace_back
#define fi first
#define se second
#define PII pair<int, int>

LL quick_pow (LL a, LL b, LL mod) {
    LL ans = 1, base = a;
    while (b) {
        if (b & 1) (ans *= base) %= mod;
        b >>= 1;
        (base *= base) %= mod;
    }
    return ans;
}

//struct node {
//    int pos, len;
//    bool operator < (const node& k) const {
//        return pos < k.pos;
//    }
//};

const int mod = 1e9 + 7;
const int N = 2e5 + 5;
/// n个区间覆盖[1, n]的方案数
int dp[N], pre[N];
int work_dp(vector<PII>& intervals) {
    intervals.emplace_back(-100, -100);
    sort(intervals.begin(), intervals.end(), [](PII a, PII b) {
         return a.second == b.second ? a.first < b.first : a.second < b.second;
    });
//    for (auto a : intervals) {
//        cout << a.fi << " " << a.se << endl;
//    }
    LL ans = 0;
    pre[0] = 0;
    int n = intervals.size() - 1;
    /// dp[i] [1, i]区间覆盖到i.r的方案数，且使用了i的区间
    for (int i = 1, j = 1; i <= n; ++i) {
        /// 区间都是闭区间且离散的，所以不覆盖是[j.r, i.l-1), i.l-1, [i.l, i.r]
//        cout << intervals[i].first << " " << intervals[i].second << endl;
        while (intervals[j].second < intervals[i].first - 1)
            ++j;
        dp[i] = (pre[i - 1] - pre[j - 1] + mod) % mod;
        /// 自己可以覆盖
        if (intervals[i].first == 1)
            dp[i]++;
        if (intervals[i].second == n)
            ans = (ans + dp[i]) % mod;
        pre[i] = (pre[i - 1] + dp[i]) % mod;
    }
//    for (int i = 0; i <= n; ++i) cout << dp[i] << " "; cout << endl;
    return ans;
}

struct node {
    int pos, v, id;
    int l, r;
    bool operator < (const node& k) const {
        return v > k.v;
    }
};
node arr[N];
int temp[N];
int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d %d", &arr[i].pos, &arr[i].v);
        temp[i] = arr[i].v;
        arr[i].id = i;
    }
    sort(temp, temp + n);
    int temp_len = unique(temp, temp + n) - temp;
    for (int i = 0; i < n; ++i) {
        arr[i].v = lower_bound(temp, temp + temp_len, arr[i].v) - temp;
    }
    sort(arr, arr + n);
    /// get L
    vector<PII> L(n);
    for(int i = 0; i < n; ++i)
        L[i] = {arr[i].pos, arr[i].id};
    sort(L.begin(), L.end());
    int cur = n - 1;
    for(int i = 0; i < n; ++i) {
        while (cur >= 0) {
            if (arr[i].pos <= L[cur].first)
                arr[L[cur].second].r = n - i, cur--;
            else
                break;
        }
    }

    cur = 0;
    for (int i = n - 1; i >= 0; --i) {
        while (cur < n) {
            if (arr[i].pos >= L[cur].first)
                arr[L[cur].second].l = n - i, cur++;
            else
                break;
        }
    }
    vector<PII> intervals(n);

    for (int i = 0; i < n; ++i)
        intervals[i] = {arr[i].l, arr[i].r};

    int ans = work_dp(intervals);
    printf("%d\n", ans);
    return 0;
}


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

#define ll long long int 
int main()
{
	ll n;
	cin>>n;
	map<ll,ll>m;
	m[1]=0;
	for(ll i=2;i<n+1;i++)
	{
		ll x;
		cin>>x;
		m[x]++;
	}
	for(ll i=1;i<=n;i++)
	{
		cout<<m[i]<<endl;
	}
	
}


Measured memory_bytes: 16128
/*
1 insertionSort(A, N) // N個の要素を含む0-オリジンの配列A
2   for i が 1 から N-1 まで
3     v = A[i]
4     j = i - 1
5     while j >= 0 かつ A[j] > v
6       A[j+1] = A[j]
7       j--
8     A[j+1] = v
*/
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

void print_vec(vector<int> &A){
    for(int i=0;i<A.size();i++){
        cout << A.at(i);
        if(i == A.size()-1){
            cout << endl;
        }else{
            cout << ' ';
        }
    }
}

void insertionSort(vector<int> &A){
    print_vec(A);
    for(int i=1;i<A.size();i++){
        int v = A.at(i);
        int j = i-1;
        while(j >= 0 && A.at(j) > v){
            A.at(j+1) = A.at(j);
            j--;
        }
        A.at(j+1) = v;
        print_vec(A);
    }
}

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i,N) cin >> A.at(i);
    insertionSort(A);
}   


Measured memory_bytes: 3104
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>

using namespace std;

typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    int N,R;
    cin >> N>>R;
    if(N<10){
        cout<<R+100*(10-N);
    }else{
        cout<<R;
    }

    return 0;
}

Measured memory_bytes: 256
n,m = gets.split.map &:to_i

arr = Array.new(n + 1).map{ Array.new }

m.times{
	a,b = gets.split.map &:to_i
	arr[a] << b
	arr[b] << a
}

count = 0

(1..n).each{ |x|
	if arr[x] == nil then
		next
	end

	temp = arr[x]
	
	arr[x] = nil

	while temp.size > 0
		n_temp = {}
		
		temp.each{ |t|
			if arr[t] != nil then
				arr[t].each{ |i|
					n_temp[i] = true
				}
				arr[t] = nil
			end
		}
		
		temp = n_temp.keys
	end
	
	count += 1
}

puts count - 1

Measured memory_bytes: 31580
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

int main() {
    string S; cin >> S;
    ll ans=S.size();
    for(ll i=0;i<S.size()-1;i++){
        if(S[i]!=S[i+1]){
            ans=min(ans,max(i+1,(ll)S.size()-i-1));
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import sys
sys.setrecursionlimit(10**6)
def dfs_rec(start,prev,c):
    cost[start] = cost[prev] + c
    for node,c in tr[start]:
        if node!=prev:
            dfs_rec(node,start,c)
    return


n  = int(input())
tr = [[] for i in range(n)]
cost = [0]*n
for i in range(n-1):
    a,b,c = map(int,input().split())
    tr[a-1].append([b-1,c])
    tr[b-1].append([a-1,c])

q,k = map(int,input().split())
dfs_rec(k-1,k-1,0)
for i in range(q):
    x,y = map(int,input().split())
    print(cost[x-1] + cost[y-1])


Measured memory_bytes: 137932
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<string>
#include<bitset>
#include<cfloat>
#include<iomanip>
#include<numeric>

//#define int long long
#define repi(i,start,end) for(int (i)=(start),TemPNuM=(int)(end);(i)<TemPNuM;++(i))
#define rep(i,end) repi((i),0,(end))
#define rfor(x,v) for(auto& (x) : (v))
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fsort(v,lambda) sort(all((v)),(lambda))
#define vin(v) rep(i,(v).size())cin >> (v)[i];
#define vpin(v) rep(i,(v).size())cin>>v[i].first>>v[i].second

using namespace std;
using ll =  long long;
using pint =  pair<int,int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vpint = vector<pint>;

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>void put_double(T a){if(cout.precision()!=12)cout<<setprecision(12);cout<<a<<endl;}
template<class T>void print(T a){cout << a << endl;}
//lambda: [](int x, int y){return x<y;}

signed main(void) {
    int n, d, x; cin >> n >> d >> x;
    vint a(n); vin(a);
    int ans = x;
    rfor(x, a) {
        int day = 0;
        while(day < d) {
            ans++;
            day += x;
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 256