akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

typedef long long ll;

int main() {
    int N;
    cin >> N;
    vector<int> A(N), B(N), C(N);
    rep(i, N) cin >> A[i];
    sort(A.begin(), A.end());
    int x = N / 2;
    ll ans = 0, ans2 = 0;
    if (N % 2) {
        B[0] = A[N / 2];
        C[N - 1] = A[N / 2];
        rep(i, N / 2) {
            B[i * 2 + 1] = A[N / 2 + i + 1];
            B[i * 2 + 2] = A[i];
            C[i * 2] = A[N / 2 + i + 1];
            C[i * 2 + 1] = A[i];
        }
        rep(i, N - 1) {
            ans += abs(B[i] - B[i + 1]);
            ans2 += abs(C[i] - C[i + 1]);
        }
        if (ans2 > ans) ans = ans2;
    } else {
        rep(i, N / 2) {
            B[i * 2] = A[N / 2 + i];
            B[i * 2 + 1] = A[i];
        }
        rep(i, N - 1) ans += abs(B[i] - B[i + 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
/*in the name of Allah the most beneficent the most merciful.*/
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define MAX 1e18
#define MIN -1e18
#define MOD 1000000007
//#define mod2 20071027
//#define MOD 998244353
#define base 139
// #define MOD 1000074259
#define base2 31
#define memz(a) memset(a, 0, sizeof(a))
#define memn(a) memset(a, -1, sizeof(a))
#define in1(a) scanf("%lld", &a)
#define in2(a, b) scanf("%lld%lld", &a, &b)
#define TC(c) printf("Case #%lld: ", ++c)
#define out(x) cout << #x << " -> " << x << endl;
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define FILE   freopen("input.txt", "r", stdin);  freopen("out.txt", "w", stdout);
using namespace std;
const ll B = 20, N = 300010, M = 2000000;
ll n;
string a,b;

int solve()
{
    cin>>n;
    cin>>a>>b;
    for(int i=0;i<n;i++)
        cout<<a[i]<<b[i];
    printf("\n");
    return 0;
}

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

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
MOD = 10**9+7

S = input().rstrip("\n")

# dp[i][j]: i文字目でjになる個数 (S[-i])
# 1-indexed
dp = [[0]*13 for _ in range(len(S)+1)]

# 初期条件(1桁目)
if S[-1] == "?":
    dp[1][:10] = [1]*10
else:
    dp[1][int(S[-1])] += 1

# mul = 10**(i-1)
mul = 10
# i: i桁目
for i in range(2,len(S)+1):
    if S[-i] == "?":
        # j: S[-i]がとる値 (?のとき0~9)
        for j in range(10):
            jmod = j*mul % 13
            # (i-1)桁目で余りがkとなる個数x
            for k,x in enumerate(dp[i-1]):
                dp[i][(k+jmod)%13] = (dp[i][(k+jmod)%13] + x) % MOD
    else:
        jmod = int(S[-i])*mul % 13
        for k,x in enumerate(dp[i-1]):
            dp[i][(k+jmod)%13] = (dp[i][(k+jmod)%13] + x) % MOD
    mul = (mul * 10) % 13

print(dp[-1][5])

Measured memory_bytes: 61916
#include <algorithm>
#include <iostream>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <set>
#include <map>

using namespace std;

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define ll long long
#define mod 1000000007
#define vi vector<int>
#define vll vector<ll>
#define pb push_back

ll power(int x, unsigned int y){
    ll res = 1;
    while(y > 0){
        if(y & 1) res = res * x;
        y >>= 1;
        x *= x;
    }
    return res;
}

// Check for number of Cases!!
void solve() {
    string s, t;
    cin >> s >> t;

    ll ans = INT_MAX;
    ll curr = 0;

    for(int i = 0; i < (int)(s.length() - t.length() + 1); i++) {
        curr = 0;
        int temp = i;
        for(int j = 0; j < (int)t.length(); j++) {
            // cout << s[temp];
            if(s[temp++] != t[j]) curr++;
        }
        // cout << '\n';
        ans = min(ans, curr);
    }

    cout << ans;
}

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int t = 1;
    // cin >> t;
    while(t--) {
      solve();
    }
}

Measured memory_bytes: 3632
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda:sys.stdin.readline().rstrip()
def resolve():
    n=int(input())
    A=list(map(int,input().split()))
    s=sum(A)

    dp=1
    for a in A:
        dp|=(dp<<a)

    for i in range((s+1)//2,s+1):
        if((dp>>i)&1):
            print(i)
            return
resolve()

Measured memory_bytes: 135944
W,H,N = map(int,input().split())
x_max = W
x_min = 0
y_max = H
y_min = 0
for i in range(N):
    x,y,a = map(int,input().split())
    if a == 1 and x>x_min:
        x_min = x
    elif a==2 and x<x_max:
        x_max = x
    elif a==3 and y>y_min:
        y_min = y
    elif a==4 and y<y_max:
        y_max = y
print((x_max-x_min)*(y_max-y_min) if x_max-x_min>=0 and y_max-y_min>=0 else 0)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS() std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
int main()
{
//	IOS();
//	double n;
//	cin>>n;
//	int ans=floor(n/1.08+0.5);
//	int p=ans*1.08;
//	if(n==p)
//	cout<<ans<<endl;
//	else cout<<":("<<endl;
	int n;
	cin>>n;
	int ans=0;
	for(int i=1; i<50000; i++)
	{
		if(i>n) break;
		if(int(i*1.08)==n)
		{
			ans=i;
			break;
		}
	}
	if(ans) cout<<ans<<endl;
	else cout<<":("<<endl;
	return 0;
}

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

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

Measured memory_bytes: 256
h, w = map(int, input().split())
C = [list(map(int, input().split())) for _ in range(10)]
A = [list(map(int, input().split())) for _ in range(h)]

DP = [[0] * 10 for _ in range(9)]
for i in range(9):
    for j in range(10):
        if i == 0:
            DP[i][j] = C[j][1]
        else:
            DP[i][j] = min(DP[i - 1][k] + C[j][k] for k in range(10))

answer = 0
for i in range(h):
    for j in range(w):
        if A[i][j] == -1:
            continue
        answer += DP[-1][A[i][j]]

print(answer)


Measured memory_bytes: 3444
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(const char c[]){
  int i=0;
  for(i=0;c[i]!='\0';i++){
    putchar_unlocked(c[i]);
  }
}
int H;
int N;
int A[100000];
int main(){
  int i;
  rd(H);
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=(0);Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  for(i=(0);i<(N);i++){
    H -= A[i];
  }
  if(H<=0){
    wt_L("Yes");
    wt_L('\n');
  }
  else{
    wt_L("No");
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20200119-1

// --- original code ---
// int H, N, A[1d5];
// {
//   rd(H,N,A(N));
//   rep(i,N) H -= A[i];
//   wt(if[H<=0,"Yes","No"]);
// }


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

int main(){
  int a, b ;
  cin >> a >> b ;
  int c = a + b;
  if(c % 2 == 0){
    cout << c / 2 << endl;
  }
  else{
    cout << c / 2 + 1 << endl;
  }
}
  


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


int main() {
    //配列の初期化
    vector<int> S(2);
    cin >> S.at(0) >> S.at(1);

    sort(S.begin(), S.end());

    if(S.at(0) != 1){
        cout << 1 << endl;
    }

    else if(S.at(1) != 2){
        cout << 2 << endl;
    }

    else{
        cout << 3 << endl;
    }


    return 0;
}

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

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

    vector<P> x_pos;
    vector<P> y_pos;

    vector<ll> x_map(N,0);
    vector<ll> y_map(N,0);

    rep(i,N){
        ll x,y;cin>>x>>y;
        x_pos.push_back(make_pair(x,i));
        y_pos.push_back(make_pair(y,i));
        x_map[i] = x;
        y_map[i] = y;
    }

    sort(x_pos.begin(),x_pos.end());
    sort(y_pos.begin(),y_pos.end());

    // x_sorted_pos[i]: i番目の都市のx位置のソートした際の順番
    vector<ll> x_sorted_pos(N,0);
    vector<ll> y_sorted_pos(N,0);
    rep(i,N){
        P temp_x = x_pos.at(i);
        x_sorted_pos.at(temp_x.second) =i;

        P temp_y = y_pos.at(i);
        y_sorted_pos.at(temp_y.second) =i;
    }


    //最小連結木を作る方針でやろう。
    //小さい部分グラフから初めて、最も近いノードの点を加えていく
    //この際に、追加するべき候補としてはx,yのそれぞれ両方向あることに注意しよう
    //そのノードが追加済ならばスキップする
    //一番目の町から探索を始めよう。

    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push(make_pair(0, 0));//

    vector<ll> cost_list(N,-1);

    while(!pq.empty()){
        P next_pos = pq.top(); pq.pop();
        if(cost_list.at(next_pos.second)!=-1){
            continue;
        }
        cost_list.at(next_pos.second) =  next_pos.first;

        ll x_position = x_map.at(next_pos.second);
        ll y_position = y_map.at(next_pos.second);

        ll x_index = x_sorted_pos.at(next_pos.second);
        ll y_index = y_sorted_pos.at(next_pos.second);
        for(int i=-1;i<2;i++){
            if(i==0)continue;
            if(x_index+i<0 || x_index+i>=N)continue;
            P next_candidate = x_pos.at(x_index+i);
            if(cost_list.at(next_candidate.second)!=-1){
                continue;
            }
            pq.push(make_pair(abs(x_position-next_candidate.first), next_candidate.second));
        }
        for(int i=-1;i<2;i++){
            if(i==0)continue;
            if(y_index+i<0 || y_index+i>=N)continue;
            P next_candidate = y_pos.at(y_index+i);
            if(cost_list.at(next_candidate.second)!=-1){
                continue;
            }
            pq.push(make_pair(abs(y_position-next_candidate.first), next_candidate.second));
        }
    }

    ll total = 0;
    for(int i=0;i<N;i++){
        total+=cost_list.at(i);
    }
    cout<<total<<endl;

    return 0;



}

Measured memory_bytes: 10340
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main()
{
  int n; cin >> n;
  string s,t; cin >> s >> t;
  rep(i,n){
    cout << s[i] << t[i];
  }
}

Measured memory_bytes: 256
n = int(input())
past_x = 0
past_y = 0
past_t = 0
for _ in range(n):
    t, x, y = tuple(map(int, input().split(" ")))
    diff = abs(past_x - x) + abs(past_y - y)
    if (t - past_t) >= diff and ((t - past_t) - diff) % 2 == 0:
        past_t, past_x, past_y = t, x, y
        continue
    else:
        print("No")
        exit(0)

print("Yes")

Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<cmath>
#include<algorithm>
#include<map>
#include<queue>
#include<deque>
#include<iomanip>
#include<tuple>
using namespace std;
typedef long long int LL;
typedef pair<int,int> P;
typedef pair<LL,int> LP;
const int INF=1<<30;
const LL MAX=1e9+7;

void array_show(int *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%d%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(LL *array,int array_n,char middle=' '){
	for(int i=0;i<array_n;i++)printf("%lld%c",array[i],(i!=array_n-1?middle:'\n'));
}
void array_show(vector<int> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%d%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}
void array_show(vector<LL> &vec_s,int vec_n=-1,char middle=' '){
	if(vec_n==-1)vec_n=vec_s.size();
	for(int i=0;i<vec_n;i++)printf("%lld%c",vec_s[i],(i!=vec_n-1?middle:'\n'));
}

int t1[220000],t2[440000];
int num[220000];
int numb[220000];

int main(){
	int n,m;
	int i,j,k,l;
	int a,b,c;
	cin>>n;
	for(i=0;i<n;i++){
		cin>>t1[i];
	}
	for(i=0;i<n;i++){
		cin>>t2[i];
	}
	a=0;
	for(i=1;i<n;){
		b=t1[i]^t1[0];
		for(;a<=n;a++){
			k=i+a;
			if(k>=n)k-=n;
			l=a;
			if(l>=n)l-=n;
			if((t1[k]^t1[l])!=b)break;
		}
		numb[i]=a;
		i++,a--;
		if(a<0)a=0;
		for(j=1;a>0;j++){
			if(numb[j]<a){
				numb[i]=numb[j],i++,a--;
			}else break;
			if(i>=n)break;
		}
	}
	a=0;
	for(i=0;i<n;){
		b=t1[i]^t2[0];
		for(;a<=n;a++){
			k=i+a;
			if(k>=n)k-=n;
			l=a;
			if(l>=n)l-=n;
			if((t1[k]^t2[l])!=b)break;
		}
		num[i]=a;
		i++,a--;
		for(j=1;a>0;j++){
			if(numb[j]<a){
				num[i]=numb[j],i++,a--;
			}else break;
			if(i>=n)break;
		}
	}
	a=0;
	for(i=0;i<n;i++){
		if(num[i]>=n){
			a=t1[i]^t2[0];
			cout<<i<<" "<<a<<endl;
		}
	}
}

Measured memory_bytes: 7552
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>

//#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;

#define INF   (1e9 + 7)
#define MAX_N (100000)

int N;
int A[MAX_N];

void solve() {
  int ans = 1;
  int x = A[0], y = A[0];
  for (int i = 1; i < N; i++) {
    if (A[i] == x) continue;
    int s = (A[i] - x) / abs(A[i] - x);
    if (s * (x - y) < 0) {
      ans++;
      y = x = A[i];
    } else {
      y = x; x = A[i];
    }
  }

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

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

  solve();

  return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;

struct UF{
    vector<int> p, rank;
    int n;
    UF(int siz){
        n = siz;
        p.resize(n);
        rank.resize(n, 1);
        for(int i = 0; i < n; i++)  p[i] = i;
    }
    int findSet(int x){
        if(p[x] != x)   p[x] = findSet(p[x]);
        return p[x];
    }
    bool same(int x, int y){
        return findSet(x) == findSet(y);
    }
    void unite(int x, int y){
        x = findSet(x), y = findSet(y);
        if(x == y)  return;
        if(rank[x] < rank[y]){
            p[x] = y;
            rank[y] += rank[x];
        }else{
            p[y] = x;
            rank[x] += rank[y];
        }
    }
};

int main(){
    int n, k, l;
    scanf("%d %d %d", &n, &k, &l);
    UF road(n), train(n);
    int s, t;
    while(k-- > 0){
        scanf("%d %d", &s, &t);
        road.unite(--s, --t);
    }
    while(l-- > 0){
        scanf("%d %d", &s, &t);
        train.unite(--s, --t);
    }
    map<pair<int,int>,int> cnt;
    for(int i = 0; i < n; i++)  cnt[{road.findSet(i), train.findSet(i)}]++;
    for(int i = 0; i < n; i++)  printf("%d%c", cnt[{road.findSet(i), train.findSet(i)}], " \n"[i==n-1]);
    return 0;
}

Measured memory_bytes: 15104
N = int(input())
A = list(map(int, input().split(' '))) 

A.sort()

ans = 1
for a in A:
    ans *= a
    if ans ==0 or ans > 1000000000000000000:
        break
    
if (ans > 1000000000000000000):
    ans = -1

print(ans)

Measured memory_bytes: 21652
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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;}
const ll INF = 1LL << 60;
const double pi = acos(-1.0);

int main() {
    int n; cin >> n;
    vector<int> v(n);
    rep(i, n) {
        char c; cin >> c;
        if(c == 'W') v[i] = 0;
        else v[i] = 1;
    }
    int l = 0, r = n-1;
    ll ans = 0;
    while(l < r) {
        while(v[l] == 1) l++;
        while(v[r] == 0) r--;
        if(l<r) ans++;
        l++;
        r--;
    }
    cout << ans << endl;
}


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

int main() {
  char OP;
  int a, b, result;
  cin >> a >> OP >> b;
  
  if (OP == '+'){
    result = a + b;
  }else{
    result = a - b;
  }

  cout << result << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	int x, a;
	cin >> x >> a ;
	if(x<a)
		cout << 0 << endl;
	else
		cout << 10 << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
 	// freopen("input.txt","r",stdin);
 	// freopen("output.txt","w",stdout);
 	// freopen("error.txt","w",stderr);
 	ll a,b,c;
 	cin>>a>>b>>c;
	long double A =sqrtl(a*b);
	long double B =sqrtl(b);
	long double C =sqrtl(c);
	long double res = a + b + 2.00 * A;		
	if(res<c)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
    return 0;
}

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

int main(){
    string S;
    cin >> S;
    int s=S.size();
    int ans=9*(s-1);
    int x=S[0]-'0';
    if (s==1){
        ans=x;
    }
    else {
        bool a=true;
        for (int i=1;i<s;i++){
            if (S[i]!='9'){
                a=false;
                break;
            }
        }
        if (a){
            ans+=x;
        }
        else {
            ans+=x-1;
        }
    }
    cout << ans << endl;
}

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

int N, M, cnt2;
LL a, LCM;

int count2(int num) {
    int result = 0;
    while (num % 2 == 0) {
        result += 1;
        num /= 2;
    }

    return result;
}

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

    cin >> a;
    a /= 2;

    LCM = a;

    cnt2 = count2(a);

    for (int i = 2; i <= N; i++) {
        cin >> a;
        a /= 2;

        LCM = (a * LCM)/__gcd(a, LCM);

        if (count2(a) != cnt2 || LCM > M) {
            cout << 0 << endl;
            return 0;
        }
    }

    int ans = M/LCM;
    cout << (ans + 1)/2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>
using namespace std;
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define rer(i, l, r) for (int (i) = (int)(l); (i) <= (int)(r); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define each(i, v) for (auto i : v)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second
#define setp(x) setprecision(x)
#define mset(m, v) memset(m, v, sizeof(m))
static const int INF = 0x3f3f3f3f;
static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

//static const int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#define int ll

signed main() { 
        int n, t;
        cin >> n >> t;
        vi tt(n);
        int ans = 0;
        rep(i, n) cin >> tt[i];
        rep(i, n - 1) {
                if (tt[i + 1] - tt[i] > t) ans += t;
                else ans += tt[i + 1] - tt[i];
        }
        ans += t;
        cout << ans << endl;
        return 0;
}



Measured memory_bytes: 1024
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
p=X()
e=[1 if i=="E" else 0 for i in p]
w=[1 if i=="W" else 0 for i in p]
e=list(itertools.accumulate(e))
w=list(itertools.accumulate(w))

for i in range(n):
    x = e[-1]-e[i]+w[i]
    if mod > x:
        mod = x
        cnt = i
if cnt == 0:
    mod-=1

print(mod)


Measured memory_bytes: 38764
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
char s[1105][1105];
bool vis[1105][1105],vis1[1005][1005];
int n,m,ans;

int X[10]={0,-1,1,0},Y[10]={1,0,0,-1};

queue<int> Q;

int bfs()
{
	while(!Q.empty())
	{
		int x = Q.front();
		Q.pop();
		int y = Q.front();
		Q.pop();
		int step = Q.front();
		Q.pop();
		ans++;
		if(ans==n*m)
		{
			return step;
		}
		for(int i=0;i<4;i++)
		{
			int xx = x+X[i];
			int yy = y+Y[i];
			if(xx<=n&&xx>=1&&yy<=m&&yy>=1)
			{
				if(!vis[xx][yy])
				{
					vis[xx][yy] =true;
					Q.push(xx);Q.push(yy);
					Q.push(step+1);
				}
			}
		}
	}
}

int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%s",s[i]+1);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(s[i][j]=='#'){
				Q.push(i);Q.push(j);vis[i][j]=true;
				Q.push(0);
			}
		}
	}
	cout<<bfs()<<endl;
	return 0;
}


Measured memory_bytes: 14208
// arc096_a
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif

template <typename A, typename B> bool cmin(A &a, const B &b) {
  return a > b ? (a = b, true) : false;
}
template <typename A, typename B> bool cmax(A &a, const B &b) {
  return a < b ? (a = b, true) : false;
}
const double PI = acos(-1);
const double EPS = 1e-9;
int inf = sizeof(int) == sizeof(long long) ? 2e18 : 1e9 + 10;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;

int main() {
  int a, b, c, x, y, z = 0;
  cin >> a >> b >> c >> x >> y;
  ll ans = a * x + b * y;
  while (x > 0 || y > 0) {
    if (x > 0 || y > 0)
      z += 2;

    if (x > 0)
      --x;

    if (y > 0)
      --y;

    ll now = a * x + b * y + c * z;
    ans = min(ans, now);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
    string S;
    cin >> S;
    long K;
    cin >> K;

    int place = 0;
    char num = '0';

    for(int i=0; i<S.size(); i++){
        if(S[i] != '1'){
            place = i;
            num = S[i];
            break;
        }
    }

    if(num == '0'){
        cout << 1 << endl;
    }
    else if(K >= place+1){
        cout << num << endl;
    }

    else{
        cout << 1 << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	string s;
	cin >> k >> s;
	if (s.size() <= k)
		cout << s << endl;
	else
	{
		s = s.substr(0, k);
		cout << s << "..." << endl;
	}
	return 0;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
#include <stdbool.h>

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

//qsort(str, n, sizeof(int), up_comp);
int up_comp(const void *a, const void *b){return *(int*)a - *(int*)b;}
int down_comp(const void *a, const void *b){return *(int*)b - *(int*)a;}
int int_sort( const void * a , const void * b ) {return strcmp(( char * )a , ( char * )b );}
int count_digit(int a){int i=0;while(a!=0){a=a/10;i++;}return i;}
int euclid( int a, int b ){int temp;if(a<b){temp=a;a=b;b=temp;}if(b<1)return -1;if(a%b==0) return b;return euclid(b,a%b);}

int main(void){
 
    int a, b, t;
    
    scanf("%d%d%d", &a, &b, &t);
    
    printf("%d", t/a*b);
    
    return 0;
}



Measured memory_bytes: 1700
#include <iostream>
#include <utility>

using namespace std;


int main(){
    
    int x, y;

    while(true){
        cin >> x >> y;
        if(x == 0 && y == 0){
            break;
        }
        if(y < x){
            swap(x, y);
        }
        cout << x << " " << y << endl;
    }

    return 0;
}






Measured memory_bytes: 3012
#include <stdio.h>		// standard input output
#include <iostream>		// input output stream, cin cout( console in console out)
#include <cmath>		// circle math ( sin, con, sinh
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>		// input output manipulation

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep3(i, a, n) for(int i = (int)(a); i < (int)(n); i++)
#define ll long long

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




int main() {
  string s; // 変数の宣言
  cin >> s; // 標準入力

  if("A"<=s && s<="Z"){
  cout << "A" << endl; // 標準出力
}
  else{
    cout << "a" << endl;
  }
}



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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greater<int>()

using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;

const int INF = 1001001001;
const int MOD = 1000000007;
const long long INFL = (1LL << 60);
const double EPS = 1e-9;

int main() {
  int N, K;
  cin >> N >> K;
  vi num(N);
  rep(i, N) {
    int a;
    cin >> a;
    num[a - 1]++;
  }

  sort(all(num));
  int sum = 0;
  rep(i, N) {
    if (num[i]) sum++;
  }
  int cnt = 0, kinds = 0;
  rep(i, N) {
    if (!num[i]) continue;
    if (sum - kinds <= K) break;
    cnt += num[i];
    kinds++;
  }

  cout << cnt << endl;
}

Measured memory_bytes: 1024
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;
 
#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define reps(i,x) for(ll i=1;i<=(int)(x);i++)
#define rrep(i,x) for(ll i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;
int x[50];
ll dp[51][51][2501];
int main() {
  int n, a;
  cin >> n >> a;
  reps(i,n)
    cin >> x[i];
  rep(i,n+1)
  dp[i][0][0] =1;
  reps(i,n)
     reps(j,n)
      rep(k,n*a+1){
        if(i > 0 && k < x[i]){
          dp[i][j][k] = dp[i-1][j][k];
	} else{
          dp[i][j][k] = dp[i-1][j][k]+dp[i-1][j-1][k - x[i]];
        }
      }
  ll ans = 0;
  reps(j,n)
	if(dp[n][j][j*a]) ans+=dp[n][j][j*a];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 50048
#include <bits/stdc++.h>
using namespace std;
int main(){
  double x;
  cin >> x;
  long long max_x = pow(x * 2, 0.20) + 1;
  long long i = max_x;
  while(true){
    long long a = (long long)pow(i,5);
    long long c = x-a;
    long long b = pow((double)c,0.2);
    int bi = (int) b;
    if(pow(b,5)+a == x){
      cout << i << " " << -bi << endl;
      break;
    }
    i--;
  }
}


Measured memory_bytes: 4188
#include <bits/stdc++.h>
using namespace std;
const int N = 100 * 1000 + 10;
vector<long long> v[3];
long long ans;
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++) {
		long long x, y;
		cin >> x >> y;
		ans -= y;
		v[0].push_back(x + y);
	}
	sort(v[0].begin(), v[0].end());
	reverse(v[0].begin(), v[0].end());
	for (int i = 0; i < v[0].size(); i += 2)
		ans += v[0][i];
	cout << ans;
}


Measured memory_bytes: 1400
#include<iostream>
#include<algorithm>
#include<utility>
#include<vector>
#include<cmath>
using namespace std;

typedef pair<int, int> P;
typedef long long ll;
const int INF = 100000000;

ll gcd( ll a, ll b ){
    ll tmp;
    if( a < b ) { tmp = a; a = b; b = tmp; }
    if( b < 1 ) return -1;

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

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


//入力

int main(){

    int a, p;
    cin >> a >> p;

    cout << (a*3 + p) / 2 << endl;

    return 0;
}

Measured memory_bytes: 256
/*
-----------------------------------------------------------------------------
Author :            ---------------------------------------------------------
    UTKARSH SAXENA  ---------------------------------------------------------
    GOOGLE          ---------------------------------------------------------
-----------------------------------------------------------------------------
*/
#include <algorithm>
#include <iostream>
#include <map>
#include <set>
#include <vector>
using namespace std;
#define fre freopen("0.in", "r", stdin), freopen("0.out", "w", stdout)
#define abs(x) ((x) > 0 ? (x) : -(x))
#define MOD 1000000007
#define LL signed long long int
#define ps(x) push_back(x)
#define scan(x) scanf("%d", &x)
#define print(x) printf("%d\n", x)
#define scanll(x) scanf("%lld", &x)
#define printll(x) printf("%lld\n", x)
#define boost ios_base::sync_with_stdio(0)
// vector<int> g[2*100000+5];int par[2*100000+5];
int main() {
  int N;
  cin >> N;
  std::vector<int> v;
  for (int i = 1; i <= N; ++i) {
    int x;
    cin >> x;
    v.push_back(x);
  }
  int ok = 1;
  std::vector<int> res;
  for (int i = N; i >= 1; --i) {
    int found = 0;
    for (int j = i; j >= 1; j--) {
      if (v[j - 1] == j) {
        found = j;
        break;
      }
    }
    if (found == 0) {
      ok = 0;
      break;
    }
    res.push_back(found);
    v.erase(v.begin() + found - 1);
  }
  if (!ok)
    cout << -1;
  else
    for (int i = N - 1; i >= 0; i--)
      cout << res[i] << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <complex>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair

vector<int> solve(ll x, int y)
{
    if (x == 1)
    {
        vector<int> res;
        res.clear();
        return res;
    }
    if (x % 2 == 0)
    {
        vector<int> res = solve(x / 2, y + 1);
        res.insert(res.begin() + (int)res.size() / 2, y);
        res.insert(res.begin(), y);
        return res;
    }
    else
    {
        vector<int> res = solve(x - 1, y + 1);
        res.insert(res.begin() + (int)res.size() / 2, y);
        res.insert(res.begin() + (int)res.size() / 2, y);
        return res;
    }
}

int main()
{
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);

    ll x;
    scanf("%lld", &x);
    x++;
    vector<int> res = solve(x, 1);
    printf("%d\n", (int)res.size());
    for (int p : res)
        printf("%d ", p);
    printf("\n");

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long[] cnt = new long[5];
		for (int i = 0; i < n; i++) {
			char ch = sc.next().charAt(0);
			if (ch == 'M') cnt[0]++;
			if (ch == 'A') cnt[1]++;
			if (ch == 'R') cnt[2]++;
			if (ch == 'C') cnt[3]++;
			if (ch == 'H') cnt[4]++;
		}
		sc.close();

		long ans = 0L;
		for (int i = 0; i < cnt.length; i++) {
			for (int j = i + 1; j < cnt.length; j++) {
				for (int k = j + 1; k < cnt.length; k++) {
					ans += cnt[i] * cnt[j] * cnt[k];
				}
			}
		}
		System.out.println(ans);
	}
}


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

int main() {
  int n;
  cin >> n;
  
  if(n / 100 == 7){
    cout << "Yes" << endl;
  }
  
  else{
    if( (n % 100) / 10 == 7){
    cout << "Yes" << endl;
  }
    else{
      if( (n % 10)  == 7){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
      
    }
  }
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define lli long long int
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF 9223372036854775807+1

int main() {
  char C;
  cin >> C ;
  string z= "abcdefghijklmnopqrstuvwxyza";
  rep(i, 100){
  if(z[i]== C){
  cout << z[i+1] << endl;
    return 0;
  }
  }
  
  
  
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

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

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

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n;
int x[101], y[101], h[101];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n;
  int ti = 0;
  REP(i, n) {
    cin >> x[i] >> y[i] >> h[i];
    if(h[i] > 0) ti = i;
  }

  REP(i, 101) {
    REP(j, 101) {
      int H = abs(i - x[ti]) + abs(j - y[ti]) + h[ti];
      bool f = true;
      REP(k, n) {
        int hi = H - abs(i - x[k]) - abs(j - y[k]);
        if(hi != h[k] && !(hi <= 0 && h[k] == 0)) {
            f = false;
            break;
        }
      }
      if(f) cout << i << " " << j << " " << H << endl;
    }
  }
}


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

int call(int n){
  int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
}

int call_alt(int n){
  for(int i=1; i<=n; i++){
    if (i%3==0) cout << " " << i;
    else{
    int x = i;
    while(x){
      if (x%10==3) {
        cout << " " << i ; 
        break;
      }
      x /= 10;
    }
    }
  }
  cout << endl;
}

int main(){
    int n;
    cin >> n;
//  for (int j=0;j<15;j++) call(j);
    call_alt(n);
}



Measured memory_bytes: 3100
const line = require('fs').readFileSync('/dev/stdin', 'utf-8').split('\n');

const newNode = (id, arr) => {
    return {
        id: id,
        children: [...arr],
        parentNode: -1,
        depth: null
    };
};

const nodeToString = node => {
    const type = node.parentNode === -1 ? 'root'
               : node.children.length > 0 ? 'internal node'
               : 'leaf';
    const arr = `[${node.children.join(', ')}]`;
    return `node ${node.id}: parent = ${node.parentNode}, depth = ${node.depth}, ${type}, ${arr}`;
};

const setDepth = tree => {
    const root = tree.filter(x => x.parentNode === -1)[0];
    const helper = (node, n) => {
        node.depth = n;
        node.children.forEach(x => {
            helper(tree[x], n+1);
        });
    };
    helper(root, 0);
};

const n = parseInt(line[0]);
const data = line.slice(1, n+1)
                 .map(x => x.split(' ').map(Number));

const tree = data.map(x => {
    const id = x[0];
    const children = x.slice(2);
    return newNode(id, children);
});

tree.sort((a, b) => a.id - b.id);
tree.forEach((x, _, arr) => {
    x.children.forEach(y => {
        arr[y].parentNode = x.id;
    });
});

setDepth(tree);

console.log(tree.map(x => nodeToString(x)).join('\n'));



Measured memory_bytes: 157684
N = int(input())
An = map(int, input().split(maxsplit=N))
Bn = map(int, input().split(maxsplit=N))

minus = []
plus = []

for Ai, Bi in zip(An, Bn):
    if Ai > Bi:
        plus.append(Ai - Bi)
    elif Ai < Bi:
        minus.append(Ai - Bi)

plus = sorted(plus)


if sum(plus) + sum(minus) < 0:
    print(-1)
    exit()


change_plus = 0
sum_minus = sum(minus)
while sum_minus < 0:
    sum_minus += plus.pop()
    change_plus += 1
print(str(change_plus + len(minus)))

Measured memory_bytes: 21748
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000



int main(){
	
	int N;
	cin>>N;
	
	vector<int> T(N);
	for(int i=0;i<N;i++){
		cin>>T[i];
	}
	
	int M;
	cin>>M;
	
	for(int i=0;i<M;i++){
		vector<int> TT = T;
		int P,X;
		cin>>P>>X;
		TT[P-1]=X;
		int ans = 0;
		for(int j=0;j<N;j++){
			ans += TT[j];
		}
		cout<<ans<<endl;
	}
	
    return 0;
}



Measured memory_bytes: 256
/**
 *  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_B
 */
#include <iostream>

using namespace std;

constexpr int
gcd(const int a, const int b)
{
    return a == b ? a : a > b ? gcd(a - b, b) : gcd(a, b - a);
}

int
main()
{
    int a, b;
    cin >> a >> b; cin.ignore();

    cout << gcd(a, b) << endl;

    return 0;
}

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

int main() {
   string s;
   cin >> s;
   int ans,a=1e9;
   rep(i,s.size()-2){
      string t=s.substr(i,3);
      if(abs(753-stoi(t))<abs(753-a))
      ans=abs(753-stoi(t)),a=stoi(t);
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
n = int(input())
w = [
    list(map(int, input().split())) for i in range(n)
]
works = sorted(w, key=lambda x: x[1])
time = 0
ans = "Yes"
for i in range(n):
    time += works[i][0]
    if time <= works[i][1]:
        continue
    else:
        ans = "No"
        break
print(ans)


Measured memory_bytes: 55264
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
struct Node{
  int key;
  struct Node *next,*prev;
};

struct Node *nil;

struct Node* listSearch(int key){
  struct Node *cur=nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil=(struct Node *)malloc(sizeof(struct Node));
  nil->next=nil;
  nil->prev=nil;
}

void printList(){
  struct Node *cur=nil->next;
  int isf=0;
  while(1){
    if(cur==nil) break;
    if(isf++ > 0) printf(" ");
    printf("%d",cur->key);
    cur=cur->next;
  }
  printf("\n");
}

void deleteNode(struct Node *t){
  if(t==nil) return;
  t->prev->next=t->next;
  t->next->prev=t->prev;
  free(t);
}

void deleteFirst(){
  deleteNode(nil->next);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void deleteKey(int key){
    deleteNode(listSearch(key));
}

void insert(int key){
  struct Node *x=(struct Node *)malloc(sizeof(struct Node));
  x->key=key;
  x->next=nil->next;
  nil->next->prev=x;
  nil->next=x;
  x->prev=nil;
}

int main(){
  int key,n,i;
  int size=0;
  char com[20];
  int np=0,nd=0;
  scanf("%d",&n);
  init();
  for(i=0 ; i<n ; i++){
    scanf("%s%d",com,&key);
    if(com[0]=='i'){
      insert(key);
      np++;
      size++;
    }
    else if(com[0]=='d'){
      if(strlen(com)>6){
          if(com[6]=='F') deleteFirst();
        else if(com[6]=='L')deleteLast();
      }
      else{
        deleteKey(key);
        nd++;
      }
      size--;
    }
  }
  printList();
  return 0;
}



Measured memory_bytes: 32948
#include<bits/stdc++.h>
#define Fi first
#define Se second
#define bug(x) cerr<<#x<<'='<<x<<' '
#define debug(x) cerr<<#x<<'='<<x<<endl
#define FOR(a,b,c) for(int a=(b),a##_end=(c);a<=a##_end;++a)
#define ROF(a,b,c) for(int a=(b),a##_end=(c);a>=a##_end;--a)
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int INF=0x3f3f3f3f,N=1e5+10;
template<class T>inline bool chkmin(T& A,T B){return B<A?A=B,1:0;}
template<class T>inline bool chkmax(T& A,T B){return A<B?A=B,1:0;}
int n,m,op[N],u[N],fa[N],vis[N];
int par[N];
int Find(int x){
	if(par[x]==x)return x;
	return par[x]=Find(par[x]);
}
int main(){
	char s[10];
	while(scanf("%d%d",&n,&m),n||m){
		ll ans=0;
		memset(vis,0,sizeof(vis));
		memset(par,0,sizeof(par));
		fa[1]=1;
		FOR(i,2,n)scanf("%d",&fa[i]);
		FOR(i,1,m){
			scanf("%s%d",s+1,&u[i]);
			if(s[1]=='M')op[i]=1,par[u[i]]=u[i],++vis[u[i]];
			else op[i]=2;
		}
		FOR(i,1,n)if(!par[i])par[i]=fa[i];
		ROF(i,m,1)
			if(op[i]==1){
				if(!(--vis[u[i]]))par[u[i]]=Find(fa[u[i]]);
			}
			else ans+=Find(u[i]);
		printf("%lld\n",ans);
	}
	return 0;
}


Measured memory_bytes: 5292
from sys import stdin
def main():
	readline=stdin.readline
	S=readline().strip()
	rflag=True
	rcount=0
	lcount=0
	li=[0]*len(S)
	for i in range(len(S)):
		if S[i]=="R" and rflag:
			rcount+=1
		elif S[i]=="L" and rflag:
			rflag=False
			lcount+=1
			co=[i-1,i]
			if i==len(S)-1:
				total=rcount+lcount
				if total%2==0:
					li[co[0]],li[co[1]]=total//2,total//2
				else:
					if rcount%2==0:
						li[co[0]]=total//2
						li[co[1]]=total//2+1
					else:
						li[co[0]]=total//2+1
						li[co[1]]=total//2
		elif S[i]=="L":
			lcount+=1
			if i==len(S)-1:
				total=rcount+lcount
				if total%2==0:
					li[co[0]],li[co[1]]=total//2,total//2
				else:
					if rcount%2==0:
						li[co[0]]=total//2
						li[co[1]]=total//2+1
					else:
						li[co[0]]=total//2+1
						li[co[1]]=total//2
		elif S[i]=="R" and rflag==False:
			total=rcount+lcount
			if total%2==0:
				li[co[0]],li[co[1]]=total//2,total//2
			else:
				if rcount%2==0:
					li[co[0]]=total//2
					li[co[1]]=total//2+1
				else:
					li[co[0]]=total//2+1
					li[co[1]]=total//2
			rflag=True
			rcount=1
			lcount=0

	print(*li)
if __name__=="__main__":
	main()

Measured memory_bytes: 6648
import java.util.Scanner

import scala.io.StdIn._
object Main extends App {

  def read(): (Int, Array[Int]) = {
    val sc: Scanner = new Scanner(System.in)
    val x, n = sc.nextInt()
    val arr = Array.fill(n)(sc.nextInt)
    sc.close()
    (x, arr)
  }

  def solve(): Int = {
    val (x, arr) = read()
    (0 to 101).diff(arr.toSeq).map { num =>
      (num, (x - num).abs)
    }.minBy { case (num, diff) => (diff, num) }._1
  }

  println(solve())

}


Measured memory_bytes: 55780
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
using namespace std;

int main() {
	long long int n=700,m,a,b,c,d,e;
	long double z,w;
	string str,str2,str3;
	char ch;
	long long int x[130]={};
	cout << fixed << setprecision(10);
	cin>>a>>b;
	a*=b;
	if(a%2==0){cout<<"Even";}
	else{cout<<"Odd";}






	cout<<endl;
} 


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

int main(){
    int n; cin>>n;
    vector<int> h(n+1); h.at(n) = 0;
    for(int i=0; i<n; i++) cin>>h.at(i);
    int ans=0;
    for(int i=1; i<=100; i++){
        for(int j=0; j<n; j++){
            if(h.at(j)>=i and h.at(j+1)<i)
                ans++;
        }
    }
    cout<<ans<<endl;
}


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

int main(){
    int N;
    cin >> N;
    int sup[N + 1] ={0};
    for(int i = 1; i < N; i++){
        int a;
        cin >> a;
        sup[a]++;
    }
    for(int i = 1; i <= N; i++){
        cout << sup[i] << endl;
    }
}

Measured memory_bytes: 4396
def print_ab(s, a, b):
    print(s[a:b+1])

def reverse_ab(s, a, b):
    s_f = s[:a]
    s_m = s[a:b+1]
    s_b = s[b+1:]

    return s_f + s_m[::-1] + s_b

def replace_ab(s, a, b, p):
    s_f = s[:a]
    s_b = s[b+1:]

    return s_f + p + s_b

if __name__ == "__main__":
    s = input()
    q = int(input())

    for i in range(q):
        ops = input().split()
        if ops[0] == "print":
            print_ab(s, int(ops[1]), int(ops[2]))
        elif ops[0] == "reverse":
            s = reverse_ab(s, int(ops[1]), int(ops[2]))
        elif ops[0] == "replace":
            s = replace_ab(s, int(ops[1]), int(ops[2]), ops[3])

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

using namespace std;
using ll = long long;

int main()
{
    int n, w;
    cin >> n >> w;
    vector<ll> dp(w+1);
    // dp[i] - the maximum total value of items with total weight exactly 
    for(int item=0; item<n; ++item) {
        vector<ll> new_dp(w+1);
        ll weight, value;
        cin >> weight >> value;
        new_dp = dp;
        for(ll i=weight; i < w+1; i++) {
            new_dp[i] = max(dp[i], value + dp[i-weight]);
        }
        // for(int i=0; i<=w; i++)
        //     cout << new_dp[i] << " ";
        // cout << endl;
        dp = new_dp;
    }
    cout << *dp.rbegin();
    return 0;
}


Measured memory_bytes: 1804
#include<iostream>
#include<cstring>
#include<string>
using namespace std;
const int N = 30010;
char c[N];
bool is1[10],is2[100],is3[1000];
struct node{
	int cnt[10];
}pre[N];
node g(int l,int r){
	node res=pre[r];
	for(int i=0;i<10;i++){
		res.cnt[i]-=pre[l-1].cnt[i];
	}
	return res;
}
int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	memset(is1,false,sizeof(is1));
	memset(is2,false,sizeof(is2));
	memset(is3,false,sizeof(is3));
	int n;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		pre[i].cnt[c[i]-'0']++;
	}
	for(int i=1;i<=n;i++){
		int t1=c[i]-'0';
		if(is1[t1]){
			continue;
		}
		for(int j=i+1;j<=n;j++){
			int t2=c[j]-'0';
			if(is2[10*t1+t2]){
				continue;
			}
			for(int k=j+1;k<=n;k++){
				int t3=c[k]-'0';
				is3[100*t1+10*t2+t3]=true;
			}
			is2[10*t1+t2]=true;
		}
		is1[t1]=true;
	}
	int ans=0;
	for(int i=0;i<=999;i++){
		ans+=is3[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1408