akhauriyash/Code-Regression huggingface dataset:
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<functional>
#include<iomanip>
#include<iostream>
#include<numeric>
#include<map>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>
// 追加１
#include <fstream>



using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()


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

	vector<ll> A(N);

	rep(i, N)
	{
		cin >> A[i];
	}

	ll maxD = 0;
	ll d = 0;
	rep(i, N - 1)
	{
		d = A[i + 1] - A[i];
		maxD = max(d, maxD);
	}

	d = A[0] + K - A[N - 1];
	maxD = max(d, maxD);

	cout << (K - maxD) << endl;

	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
  double N,T,A,a[1000],b[1000];
  int i,min=1;
  cin>>N;
  cin>>T>>A;
  for(i=1;i<=N;i=i+1)
  {
  cin>>a[i];
  a[i]=T-a[i]*0.006;
  if(a[i]-A>=0)b[i]=a[i]-A;
  else b[i]=A-a[i];
  }
  for(i=1;i<=N;i=i+1)
  {
  if(b[min]>b[i])min=i;
  }
  cout<<min;
  return 0;
}

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

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	const int N = 55;
	vector<vector<long long>> C(N, vector<long long>(N, 0));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= i; j++) {
			if (i == j || j == 0) C[i][j] = 1;
			else C[i][j] = C[i - 1][j - 1] + C[i - 1][j];
		}
	}
	int n, k, S, T; cin >> n >> k >> S >> T;
	vector<int> a;
	for (int i = 0; i < n; i++) {
		int b; cin >> b;
		if ((b & S) != S) continue;
		if ((b | T) != T) continue;
		a.push_back(b);
	}
	n = a.size();
	vector<int> bts;
	bool flag = true;
	for (int i = 0; i < 18; i++) {
		if ((S >> i & 1) && (~T >> i & 1)) flag = false;
		if ((~S >> i & 1) && (T >> i & 1)) {
			bts.push_back(i);
		}
	}
	int m = bts.size();
	vector<long long> nums(m, 0);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[i] >> bts[j] & 1) nums[j] |= 1ll << i;
		}
	}
	long long ans = 0;
	if (flag) {
		vector<int> cnt(n + 1, 0);
		vector<vector<long long>> st(1 << m);
		st[0].push_back((1ll << n) - 1);
		for (int i = 1; i < (1 << m); i++) {
			int sgn = __builtin_popcount(i) & 1 ? -1 : 1;
			for (int j = 0; j < m; j++) {
				if (i >> j & 1) {
					for (auto val : st[i ^ (1 << j)]) {
						if (val & nums[j]) st[i].push_back(val & nums[j]);
						if (val & (~nums[j])) st[i].push_back(val & (~nums[j]));
					}
					break;
				}
			}
			for (auto val : st[i]) {
				cnt[__builtin_popcountll(val)] += sgn;
			}
		}
		for (int c = 1; c <= min(n, k); c++) {
			ans += C[n][c];
			for (int i = 0; i <= n; i++) {
				ans += C[i][c] * cnt[i];
			}
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 139656
N = int(input())
P = list(map(int,input().split()))
A = 0
for i in range(1, N-1):
    if P[i-1] < P[i] < P[i+1]: 
      A += 1
    if P[i-1] > P[i] > P[i+1]: 
      A += 1
print(A)

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

int main(){
	int a, b, c;
	scanf("%d%d%d", &a, &b, &c);
	for(int i = a; i <= b * a; i += a) {
		if(i % b == c) {
			printf("YES\n");
			return 0;
		}
	}
	printf("NO\n");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll mod = 1e9+7;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    map<int,int> w;
    int tmp = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == 'W') tmp++; 
        w[i] = tmp;
    }    
    int ans = n-1-w[n-1]+w[0];
    for(int i = 1; i < n; i++){
        int can = w[i-1]+(n-i-1)-(w[n-1]-w[i]);
        if(ans > can) ans = can;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 14596
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int ex=0;
		int[] h=new int[8];
		for(int i=0;i<8;i++){h[i]=0;}
		for(int i=0;i<n;i++){
			int buf=sc.nextInt();
			for(int j=0;j<8;j++){
				if(buf<=399+j*400){
					h[j]++;
					break;
				}
				if(j==7){
					ex++;
				}
			}
		}
		int min=0;
		for(int i=0;i<8;i++){
			if(h[i]>=1){
				min++;
			}
		}
		int max=min+ex;
		if(min==0){
			min=1;
		}

		System.out.println(min+" "+max);
	}

}


Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <algorithm>


using namespace std;

int main(){
  int N , K;
  cin >> N >> K;
  vector<long long int> A(N);
  for(int  i = 0; i < N; i++) cin >> A[i];
  
  sort(A.begin(), A.end());
  
  long long int mind = 1000000001LL;
  for(int i = 0; i + K - 1 <N; i++){
    long long int maxh,minh,d;
    minh = A[i];
    maxh = A[i + K - 1];
    d = maxh - minh;
    mind = min(d, mind);
  }
  cout << mind;
}


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

int main(){
    int k,x;
    cin>>k>>x;
    int left=x-k+1,right=x+k-1;
    for(int i=left;i<=right;i++){
        cout<<i<<" ";
    }
    cout<<endl;
}


Measured memory_bytes: 256
import numpy as np
from bisect import bisect_right
N = int(input())
U = 10**6
pls = np.zeros(U,np.int32)
pls[2] = 1
pls[3::2] = 1
for i in range(3,U,2):
  if pls[i]==1:
    pls[i*i::2*i] = 0
t = list(np.where(pls)[0])
dic = {}
ls = [i*(i-1)//2 for i in range(1,10**6)]
for p in t:
  cnt = 0
  while N%p==0:
    N //= p
    cnt += 1
  dic[p] = cnt
if N!=1:
  dic[N] = 1
ans = 0
for k in dic.keys():
  i = bisect_right(ls,dic[k])
  if i!=0:
    ans += i-1
print(ans)

Measured memory_bytes: 77300
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue> 
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,m;
	cin>>n>>m;
	int i,j,u,v;
	vector<vector<int> > adj;
	adj.resize(3*n+1);
	for(i=0;i<m;i++)
	{
		cin>>u>>v;
		adj[u].push_back(n+v);
		adj[n+u].push_back(2*n+v);
		adj[2*n+u].push_back(v);
	}
	int s,t;
	cin>>s>>t;
	vector<int> visit;
	visit.resize(3*n+1);
	for(i=1;i<=(3*n);i++)
		visit[i] = -1;
	queue<int> q;
	q.push(s);
	visit[s] = 0;
	while(!q.empty())
	{
		int cur = q.front();
		q.pop();
		int d = visit[cur];
		for(i=0;i<adj[cur].size();i++)
		{
			int x = adj[cur][i];
			if(visit[x]==-1)
			{
				visit[x] = d+1;
				q.push(x);
			}
		}
	}
	if(visit[t]==-1)
		cout<<"-1\n";
	else
		cout<<visit[t]/3<<'\n';
	return 0;
}

Measured memory_bytes: 17792
#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)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n; cin>>n;
    vector<ll> a(n);rep(i,n)cin>>a[i];
    sort(a.begin(),a.end());
    bool f = true;
    for(int i=1; i<n; i++){
        if(a[i]==a[i-1]){
            f=false;
            break;
        }
    }
    if(f)cout<<"YES";
    else cout<<"NO";
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
    long long int n, a[100010], ans = 0, cnt = 0;

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] < 0) {
            cnt++;
            a[i] *= -1;
        }
    }

    sort(a, a+n);

    if (cnt % 2) {
        a[0] *= -1;
    }

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

    cout << ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pi pair<int,int>
#define ff first
#define ss second
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr)

const int N = 55;
vector<int>g[N];
int path[N][N];
int cnt = 0;
bool dfs(int u,int p,int d){
    if(u==d)
        return true;
    for(int v:g[u]){
        if(v==p)
            continue;
        if(dfs(v,u,d)){
            cnt |= (1ll<<path[u][v]);
            return true;
        }
    }
    return false;
}
 
int32_t main() { 
    boost;
    int n;
    cin>>n;
    for(int i=0,u,v;i+1<n;i++){
        cin>>u>>v;
        g[u].push_back(v);
        g[v].push_back(u);
        path[u][v] = path[v][u] = i;
    }
    int m;
    cin>>m;
    int a[m];
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        cnt = 0;
        dfs(u,0,v);
        a[i] = cnt;
    }

    int ans = 0;
    for(int i=0;i<(1ll<<m);i++){
        cnt = 0;
        for(int j = 0;j<m;j++){
            if(i&(1ll<<j))
                cnt |= a[j];
        }
        cnt = __builtin_popcountll(cnt);
        int tt = (1ll<<(n-1-cnt));
        cnt = __builtin_popcount(i);
        if(cnt % 2 )
            ans-=tt;
        else
            ans+=tt;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b;
    int count =0;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%10==((i/10000)%10) && (i/10)%10==(i/1000)%10)
        {
            count++;
        }

    }
    cout<<count<<endl;





    return 0;
}


Measured memory_bytes: 3568
#include <iostream>

using namespace std;

int main()
{
	int n;
	
	cin >> n;
	
	if (n < 10) {
		cout << "ABC00" << n << endl;
	}
	else if (n < 100) {
		cout << "ABC0" << n << endl;
	}
	else {
		cout << "ABC" << n << endl;
	}
	
	return (0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int s[200005];
int main()
{
    int n;
    scanf("%d",&n);
    int mx=0;
    long long sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&s[i]);
        if(s[i]<mx) sum+=mx-s[i];
        mx=max(s[i],mx);
    }
    printf("%lld\n",sum);
}


Measured memory_bytes: 4500
n, c = map(int, input().split())
ss = [tuple(map(int, input().split())) for _ in range(n)]

max_e = 0

# clock
e = 0
for x, v in ss:
    e += v
    max_e = max(max_e, e - x)

# aclock
e = 0
for x, v in ss[::-1]:
    e += v
    max_e = max(max_e, e - (c - x))


# aclock -> clock
clocks = []
e = 0
for x, v in ss:
    e += v
    clocks.append(e - x)

max_clocks = clocks[:]
for i in range(1, len(clocks)):
    max_clocks[i] = max(clocks[i], max_clocks[i-1])

e = 0
for i in range(len(ss) - 1, 0, -1):
    x, v = ss[i]
    e += v
    max_e = max(max_e, e - 2 * (c - x) + max_clocks[i-1])

# clock -> aclock
aclocks = []
e = 0
for x, v in ss[::-1]:
    e += v
    aclocks.append(e - (c - x))

max_aclocks = aclocks[:]
for i in range(1, len(aclocks)):
    max_aclocks[i] = max(aclocks[i], max_aclocks[i-1])

aclocks.reverse()
max_aclocks.reverse()

e = 0
for i in range(len(ss) - 1):
    x, v = ss[i]
    e += v
    max_e = max(max_e, e - 2 * x + max_aclocks[i+1])

print(max_e)

Measured memory_bytes: 26600
#include"bits/stdc++.h"
//#include<bits/stdc++.h>
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
typedef long long ll;
const int mod = 100000003;


int main() {
	string a, b, c;
	cin >> a;
	cin >> b;
	cin >> c;
	int counta = 0, countb = 0, countc = 0;
	char now= a[counta];
	counta += 1;
	while(true){
		if (now == 'a') { now = a[counta]; counta++; if (counta == a.size()+1) { print("A"); break; } }
		else if (now == 'b') { now = b[countb]; countb++; if (countb == b.size()+1) { print("B"); break; } }
		else if (now == 'c') { now = c[countc]; countc++; if (countc == c.size()+1) { print("C"); break; } }
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define mp make_pair
#define si(x) int(x.size())
const int mod=1000000007,MAX=3005,INF=1<<30;
int pos[MAX][2],cnt[MAX*2][2];
string ma[MAX];

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    string S;cin>>S;
    
    int a=0,b=0;
    for(int i=0;i<2*N;i++){
        if(S[i]=='a'){
            pos[a][0]=i;
            a++;
        }else{
            pos[b][1]=i;
            b++;
        }
        
        cnt[i][0]=a;
        cnt[i][1]=b;
    }
    
    pos[N][0]=INF;
    pos[N][1]=INF;
    
    if(S.back()=='b') ma[N-1]="ab";
    else ma[N-1]="ba";
    
    ma[N]="";
    
    for(int s=N-2;s>=0;s--){
        ma[s]="";
        if(pos[s][0]<pos[s][1]){
            string U=ma[s+1],U2="";
            if(U[0]=='B') ma[s]=U;
            else{
                U2="ab"+ma[cnt[pos[s][1]][0]];
                ma[s]=max(U,U2);
            }
        }else{
            int now=s;
            while(now<N){
                int bcnt=cnt[pos[now][0]][1];
                int apos=pos[bcnt-1][0];
                int bcnt2=cnt[apos][1];
                
                now=bcnt;
                if(bcnt==bcnt2) break;
            }
            
            int a=s,b=s;
            while(a<now||b<now){
                if(a==now){
                    ma[s]+='b';
                    b++;
                    continue;
                }
                if(b==now){
                    ma[s]+='a';
                    a++;
                    continue;
                }
                if(pos[a][0]<pos[b][1]){
                    ma[s]+='a';
                    a++;
                }else{
                    ma[s]+='b';
                    b++;
                }
            }
            
            ma[s]+=ma[now];
            
            chmax(ma[s],ma[s+1]);
        }
    }
    
    string ans="";
    for(int i=0;i<N;i++) chmax(ans,ma[i]);
    
    cout<<ans<<endl;
}


Measured memory_bytes: 16068
#include<iostream>
#include<list>

using namespace std;

int main(){
   int n, a;

   cin >> n;
   list<int> li;
   list<int>::iterator ite;

   for(int i = 0; i < n; i++){
      cin >> a;
      if(i % 2 == 0){
         li.push_front(a);
      }else{
         li.push_back(a);
      }
   }
   if(n % 2 == 0) li.reverse();

   ite = li.begin();
   while(ite != li.end()){
      cout << *ite << ' ';
      ite++;
   }
}

Measured memory_bytes: 9844
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
// template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m; cin >> n >> m;
    vector<int> a(m); rep (i, m) cin >> a[i];
    ll sum = 0; rep (i, m) sum += a[i];
    cout << (n - sum  >= 0 ? n - sum : -1) << "\n";
    return 0;
}

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

using namespace std;

#define REP1(i,n) for(int i=1, i##_len=(n); i<i##_len; ++i)
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const ll MAX = 1000000;
static const ll INFTY = 1e12;
static const ll MOD = 1000000007;

template < typename T > inline string toString( const T &a ) { ostringstream oss; oss << a; return oss.str(); };

struct edge {
    ll to, cost;
};

using Graph = vector<vector<int>>;
using _Graph = vector<vector<edge>>;


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

// 深さ優先探索
vector<bool> seen;
vector<int> colors;

int H, W, N;
int sx, sy, gx, gy; 
vector<vector<char>> field;
vector<vector<int>> dist;
//vector<pair<int, int>> gx, gy;
deque<pair<int, int>> que;

typedef vector<vector<int> > Matrix;

const int INF = 100000000;

int main() {

    ll N, M;
    cin >> N >> M;
    vector<ll> X(M);
    REP(i, M){
        cin >> X[i];
    }
    sort(X.begin(), X.end());

    vector<ll> diff(M-1);
    ll ans = 0;
    REP(i, M-1){
        diff[i] = X[i+1]-X[i];
        ans += X[i+1]-X[i];
    }
  
    sort(diff.begin(), diff.end(), greater<ll>());


    // long long res = X.back() - X[0];
    for (int i = 0; i < min((ll)diff.size(), N-1); ++i) ans -= diff[i];
    cout << ans << endl;



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


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b-1); i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

typedef long long ll;
typedef long double ld;

const int MAX_N = 7 + 100000;
const int INF = 1e9 + 7;
///----------------------------------------------
int dig[MAX_N];
int main() {

	///read
	int n,T; cin>>n>>T;
	rep(i,0,n) scanf("%d",&dig[i]);

	///work
	pii ans=mp(0,0);
	int mind=dig[0];
	rep(i,1,n) {
		if (dig[i]-mind>ans.fi) {
			ans=mp(dig[i]-mind,1);
		}
		else if (dig[i]-mind==ans.fi) {
			ans.se++;
		}
		mind=min(mind,dig[i]);
	}

	///print
	cout << ans.se;



}


Measured memory_bytes: 640
#include <iostream> 
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
const int inf = 1e9+123;


void solve()
{
	int n;
	cin >> n;
	int t = n%10;
	if(t==3)
		cout << "bon" << endl;
	else if(t==0 || t==1 || t==6 || t == 8)
		cout << "pon" << endl;
	else
		cout << "hon" << endl;
	
}

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

Measured memory_bytes: 3652
def solve(s):
    size = len(s)
    l = [0] * size
    c = 0
    turn = 'R'
    for i in range(size):
        if turn =='R' and s[i] == 'L':
            l[i - 1] += c // 2 + c % 2
            l[i] += c // 2
            turn = 'L'
            c = 0
        if turn =='L' and s[i] == 'R':
            l[i - c - 1] += c // 2
            l[i - c] += c // 2 + c % 2
            turn = 'R'
            c = 0
        c += 1
    l[size - c - 1] += c // 2
    l[size - c] += c // 2 + c % 2
    return l

_s = input()
print(*solve(_s))


Measured memory_bytes: 5608
#include<bits/stdc++.h>
using namespace std;
     
#define ll long long
#define loop(i,a,n) for(ll i=a;i<n;++i)
#define revloop(i,a,b) for(ll i=a;i>=b;--i)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 99999999999999
#define MOD 1000000007
 
void func()
{
    ll x;
    cin>>x;
    if(x>=30){
        cout<<"Yes"<<"\n";
    }
    else{
        cout<<"No"<<"\n";
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r" , stdin);
    freopen("output.txt", "w" , stdout);
    #endif
 
    ll t=1;
    //cin>>t;
    while(t--)
    {
        func();
    }

}

Measured memory_bytes: 3688
#include <iostream>
#include <algorithm>
#include <vector>
#include <functional>
#include <sstream>
#include <cstdio>
#include <stack>
using namespace std;

// Ball(0033)
int main()
{
	int N;
	while (cin >> N) {
		for (int i = 0; i < N; ++i) {
			vector<int> ball(10);
			for (int j = 0; j < 10; ++j)
				cin >> ball[j];

			int prev = ball.front();
			ball[0] = -1;
			for (int j = 1; j < ball.size(); ++j) {
				if (prev < ball[j]) {
					prev = ball[j];
					ball[j] = -1;
				}
			}

			prev = -1;
			for (int j = 0; j < ball.size(); ++j) {
				if (prev == -1 && ball[j] != -1) {
					prev = ball[j];
					ball[j] = -1;
				} else {
					if (prev < ball[j]) {
						prev = ball[j];
						ball[j] = -1;
					}
				}
			}

			if (count(ball.begin(), ball.end(), -1) == 10)
				cout << "YES" << endl;
			else
				cout << "NO" << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};
	
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);

	int n,a,b;
	cin >> n;
	if(n==2){
		cin >> a >> b;
		cout << a+b << "\n";
	}else{
		cout << "Hello World\n";
	}
	return 0;
}

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

#define INF 1e9
#define llINF 1e18
#define MOD 1e9+7
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
using namespace std;
int main(){
  ll a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  if(c>(a+b)/2){
    cout<<a*d+b*e<<endl;
  }else{
    ll aa=d-min(d,e),bb=e-min(d,e);
    cout<<min(c*min(d,e)*2+aa*a+bb*b,c*max(d,e)*2)<<endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int arr[4][4];
	
	for (int i=1;i<=3;i++)
	{
		for(int j=1;j<=3;j++)
		{
			cin>>arr[i][j];
		}
	}
	
	int a1=1000,a2,a3,b1,b2,b3;
	//kita misalkan i1 dulu;
	for(int i=1;i<=3;i++)
	{
		a1= min(a1,arr[1][i]);
	}
	
	for(int i=0;i<=a1;i++)
	{
		b1= arr[1][1] - a1;
		b2= arr[1][2] - a1;
		b3= arr[1][3] - a1;
		
		//tinjau a2
		a2= arr[2][1]-b1;
		if(a2+b2!=arr[2][2] or a2+b3!=arr[2][3])
		{
			continue;
		}
		
		//tinjau a3
		a3= arr[3][1]-b1;
		if(a3+b2!=arr[3][2] or a3+b3!=arr[3][3])
		{
			continue;
		}
		
		cout<<"Yes\n";
		return 0;
	}
	
	cout<<"No\n";
	return 0;
}


Measured memory_bytes: 256
N, = map(int, input().split())

def s(x):
    x = x & 0xFFFF0000 if x & 0xFFFF0000 else x
    x = x & 0xFF00FF00 if x & 0xFF00FF00 else x
    x = x & 0xF0F0F0F0 if x & 0xF0F0F0F0 else x
    x = x & 0xCCCCCCCC if x & 0xCCCCCCCC else x
    x = x & 0xAAAAAAAA if x & 0xAAAAAAAA else x
    return x


xs = []
for _ in range(N):
    xs.append(list(map(int, input().split())))
d = [0]*(2**N)
# d[i] = iに含まれるウサギが全部同じgroupに入るスコアで初期化
for i in range(1, 2**N):
    x = bin(i)[2:][::-1]
    l = len(x)-1
    d[i] = d[i-s(i)]
    # 最上位bitに対応するウサギを入れる。
    for j, b in enumerate(x):
        if b == '1':
            d[i] += xs[l][j]
# d[i] = iに含まれるウサギを分割してもいいとしてスコアの最大値. iを２つのグループk, nkに分けて足す
for i in range(1, 2**N):
    k = i
    while k:
        k = (k-1)&i
        nk = i^k
        d[i] = max(d[i], d[k]+d[nk])
print(d[2**N-1])


Measured memory_bytes: 45956
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

int main(void){
int H;
int W;
int a;
int i;
int j;
int c=0;

scanf("%d %d",&H,&W);

for(a=1;a>0;a++){
  for(i=1;i<=H;i++){
    for(j=1;j<=W;j++){
    c++;
      if(c%2==1){
      printf("#");}
      else{
      printf(".");}}
    printf("\n");
  if(W%2==0){
    c=c+1;}}
  scanf("%d %d",&H,&W);
  printf("\n");
  c=0;
  if(H==0 && W==0){
  break;}
}
return 0;
}


Measured memory_bytes: 2108
N = int(input())
a = list(map(int,input().split(" ")))

MAX = max(a)
MIN = min(a)

count = 0
ans = []

def showans():
	global count
	global ans
	print(count)
	for i,j in ans:
		print(str(i) + " " + str(j))


def allplus():
	global count
	global ans
	for i in range(N-1):
		if a[i] > a[i+1]:
			a[i+1] += a[i]
			count += 1
			ans.append((i+1,i+2))

			

def allminas():
	global count
	global ans
	for i in range(N-1,0,-1):
		if a[i] < a[i-1]:
			a[i-1] += a[i]
			count += 1
			ans.append((i+1,i))


if abs(MAX) >= abs(MIN) and MAX > 0:
	ind = a.index(MAX)
	for i in range(N):
		if a[i] < 0:
			while a[i] < 0:
				a[i] += MAX
				count += 1
				ans.append((ind+1,i+1))

	allplus()
	showans()
	exit(0)

elif abs(MIN) > abs(MAX) and MIN < 0:
	ind = a.index(MIN)
	for i in range(N):
		if a[i] > 0:
			while a[i] > 0:
				a[i] += MIN
				count += 1
				ans.append((ind+1,i+1))

	allminas()
	showans()
	exit(0)

elif MAX <= 0:
	allminas()
	showans()

elif MIN >=  0:
	allplus()
	showans()

Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
long long int gcd(long long int x, long long int y){
  return y!=0 ? gcd(y, x%y) : x;
}
long long int lcm(long long int x, long long int y){
  return x*y/gcd(x, y);
}
int main(){
  int i, j, n, ans=0;
  char s[100002];
  cin >> s;
  n=strlen(s);
  for(i=0; i<n-1; i++)
    if(s[i]!=s[i+1]) ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 384
#include<iostream>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if((a<=0&&b>=0)||(a>=0&&b<=0)){
		cout<<"Zero";
	}
	if(a>0&&b>0){
		cout<<"Positive";
	}
	if(a<0&&b<0){
		if((b-a)%2==1)cout<<"Positive";
		else cout<<"Negative";
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String args[])throws Exception
  {
    try {
    Scanner sc=new Scanner(System.in);
    int x,y,t,c;
      x=sc.nextInt();
      y=sc.nextInt();
      if(y%2!=0)
        System.out.println("No");
      else
      {
        t=y/2-x;
        c=x-t;
        if(t>=0 && c>=0)
          System.out.println("Yes");
        else
          System.out.println("No");
      }
    } catch(Exception e) { return;
                         } finally {
    }
  }
}
    


Measured memory_bytes: 35860
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
using namespace std;
int main() {
	int n;
	string s;
	cin >> n;
	int a[100];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for (int i = n - 1; i >= 0; i--) {
		if (i == n - 1) cout << a[i];
		else cout << " " << a[i];
	}
	cout << endl;
}

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

const int max_n = 1e5 + 10;

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

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

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }


int main()
{
    int n, h[max_n];
    cin >> n;
    for (int i = 0; i < n; ++i)
    {
        cin >> h[i];
    }
    for (int i = n - 2; i >= 0; --i)
    {
        if(h[i] - 1 > h[i+1])
        {
            cout << "No" << endl;
            return 0;
        } else if(h[i] - 1 == h[i+1])
        {
            --h[i];
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m, x, y;
  cin >> n >> m >> x >> y;
  vector<int> X(n);
  vector<int> Y(m);
  for (int i = 0; i < n; i++)
    cin >> X[i];
  for (int j = 0; j < m; j++)
    cin >> Y[j];
  int xj = *max_element(X.begin(), X.end());
  int yj = *min_element(Y.begin(), Y.end());
  if (yj-xj > 0 && x < yj && yj <= y)
    cout << "No War" << endl;
  else
    cout << "War" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 1e5 + 10;
ll a[N], b[N];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    ll n, m;
    cin >> n >> m;
    for (int i=1; i<=n; i++) {
        cin >> a[i];
        ll A = a[i];
        while (A%2 == 0) {
            b[i]++;
            A /= 2;
        }
    }
    set<int> kek;
    for (int i=1; i<=n; i++) {
        kek.insert(b[i]);
    }
    if (kek.size() > 1) {
        cout << "0\n";
        return 0;
    }
    ll lcm = a[1];
    for (int i=2; i<=n; i++) {
        ll prod = lcm * a[i];
        lcm = prod / __gcd(lcm, a[i]);
    }
    ll ans = 2 * m / lcm;
    cout << (ans + 1) / 2 << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
using namespace std;
 
#define x first
#define y second
 
int solve(vector<pair<int,int> >& p,
      set<pair<int,int> >& sp,
      int i, 
      int j){
  int dx = p[j].x - p[i].x;
  int dy = p[j].y - p[i].y;
  pair<int,int> n1 = make_pair( p[j].x-dy, p[j].y+dx );
  pair<int,int> n2 = make_pair( p[i].x-dy, p[i].y+dx );
  if(sp.find(n1) != sp.end() && sp.find(n2) != sp.end() )
    return dx*dx + dy*dy;
  else
    return 0;
}
 
 
int main(){
  while(1){
    int n; cin >> n;
    if(n==0)break;
     
    vector<pair<int,int> > point(n);
    set<pair<int,int> > sp;
    for(int i=0; i<n; i++){
      cin >> point[i].x >> point[i].y;
      sp.insert(point[i]);
    }
 
    sort(point.begin(),point.end());
    int ans=0;
    for(int i=0; i<n-1; i++){
      for(int j=i+1; j<n; j++){
    int tmp = solve(point,sp,i,j);
    ans = max(ans,tmp);
    //  cout << tmp << endl;
      }
    }
    cout << ans << endl;
  }
}

Measured memory_bytes: 3228
#import numpy as np
import sys, math
from itertools import permutations, combinations
from collections import defaultdict, Counter, deque
from math import factorial#, gcd
from bisect import bisect_left #bisect_left(list, value)
sys.setrecursionlimit(10**7)
enu = enumerate
MOD = 10**9+7
def input(): return sys.stdin.readline()[:-1]
pl = lambda x: print(*x, sep='\n')

N, X = map(int, input().split())
m = [list(map(int, input().split())) for _ in range(N)]

minm = MOD
for mi in m:
    minm = min(minm, mi[0])
    X -= mi[0]
print(N + X//minm)

Measured memory_bytes: 3316
def main():
    N, M, K=map(int, input().split())
    friend_or_block = [0] * N
    friends_chain = UnionFindTree(N)

    for _ in range(M):
        a, b = map(int, input().split())
        a, b = a-1, b-1
        friends_chain.unite(a, b)
        friend_or_block[a] += 1
        friend_or_block[b] += 1

    for _ in range(K):
        c, d = map(int, input().split())
        c, d = c-1, d-1
        if friends_chain.same(c, d):
            friend_or_block[c] += 1
            friend_or_block[d] += 1

    print(*[friends_chain.count(i) - friend_or_block[i] - 1 for i in range(N)])

class UnionFindTree:
    def __init__(self, n):
        self.parent = [-1] * n

    def root(self, x):
        p, s = self.parent[x], list()
        while p >= 0:
            s.append(x)
            x, p = p, self.parent[p]
        for c in s: self.parent[c] = x
        return x

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

    def count(self, x): return -self.parent[self.root(x)]

    def unite(self, x, y):
        xr, yr = self.root(x), self.root(y)
        if xr == yr: return
        if self.parent[xr] > self.parent[yr]: xr, yr = yr, xr
        self.parent[xr] += self.parent[yr]
        self.parent[yr] = xr

if __name__ == '__main__':
    main()



Measured memory_bytes: 74712
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let ans: String;

    if a < b {
        ans = "a < b".to_string();
    } else if a > b {
        ans = "a > b".to_string();
    } else {
        ans = "a == b".to_string();
    }

    println!("{}", ans);
}



Measured memory_bytes: 5024
import sys
import numpy as np
sys.setrecursionlimit(10 ** 9)

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N = ri()
x = N // 1.08
bool = True
if int(x * 1.08) != N or x < 1:
    x += 1
    if int(x * 1.08) != N:
        bool = False
print(int(x) if bool else ':(')


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

#define ll long long int
#define pb push_back
#define mp make_pair
#define endl "\n"

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	double d, t, s;
	cin >> d >> t >> s;
	if(d/s <= t) cout << "Yes";
	else cout << "No";
	return 0;
}

Measured memory_bytes: 3728
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int H, W, K, A[310][310], num;
int cnt[310];
char c[310][310];

void solve(int cl, int cr) {
  vector<int> P;
  for(int i = cl; i <= cr; i++) {
    for(int j = 1; j <= W; j++) {
      if(c[i][j] == '#') P.push_back(j);
    }
  }
  sort(P.begin(), P.end());

  for(int i = 0; i < P.size(); i++) {
    int v1 = 1, v2 = W;
    if(i >= 1) v1 = P[i-1] + 1;
    if(i < (int)P.size() - 1) v2 = P[i];

    num++;

    for(int j = cl; j <= cr; j++) {
      for(int k = v1; k <= v2; k++) A[j][k] = num;
    }
  }
}

int main() {
  cin >> H >> W >> K;
  for(int i = 1; i <= H; i++) {
    for(int j = 1; j <= W; j++) {
      cin >> c[i][j];
      if(c[i][j] == '#') cnt[i]++;
    }
  }

  vector<int> vec;
  for(int i = 1; i <= H; i++) { if(cnt[i] >= 1) vec.push_back(i); }

  for(int i = 0; i < vec.size(); i++) {
    int v1 = 1, v2 = H;
    if(i >= 1) v1 = vec[i-1]+1;
    if(i < (int)vec.size() - 1) v2 = vec[i];

    solve(v1, v2);
  }

  for(int i = 1; i <= H; i++) {
    for(int j = 1; j <= W; j++) {
      if(j >= 2)  cout << " "; cout << A[i][j];
    }
    cout << endl;
  }
  return 0;
}


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

using namespace std;
using ll = long long;

//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)

const int INF = 1e9;

int main(void){

	int N, M; cin >> N >> M;
	vector<int> X(M);

	REP(i,M) cin >> X[i];
	SORT(X);

	vector<int> Y(M-1);
	FOR(i,1,M){
		Y[i-1] = X[i] - X[i-1];
	}

	SORT(Y);

	int ans = 0;
	REP(i,M-(N-1)-1){
		ans += Y[i];
	}

	cout << ans << endl;


	return 0;

}


Measured memory_bytes: 1024
N = int(input())
def dfs(scgs):
    # 終了の処理 dfs(scgs)=0
    if int(scgs) > N:
        return 0
    # scgsが753数かどうか
    if all(scgs.count(c)>0 for c in '753'):
        ret = 1
    else:
        ret = 0
    # 分岐処理
    for c in '753':
        ret = ret + dfs(scgs + c)
    return ret
print(dfs('0'))

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string a;
  cin>>a;
  ll b=a.size();
  char c=a.at(b-1);
  if(c=='3'){
    cout<<"bon"<<endl;
  }
  else if(c=='0'||c=='1'||c=='6'||c=='8'){
    cout<<"pon"<<endl;
  }
  else{
    cout<<"hon"<<endl;
  }
}


Measured memory_bytes: 3636
# import sys
# sys.setrecursionlimit(10**5)
# from collections import defaultdict
geta = lambda fn: list(map(fn, input().split()))
gete = lambda fn: fn(input())

def main():
    N, K = geta(int)
    h = geta(int)

    INF = 1 << 60
    dp = [INF]*N
    dp[0], dp[1] = 0, abs(h[0] - h[1])

    for i in range(2, N):
        lb = i - K if i > K else 0
        for j in range(lb, i):
            tmp = dp[j] + abs(h[j] - h[i])
            if tmp < dp[i]:
                dp[i] = tmp

    print(dp[N - 1])

if __name__ == "__main__":
    main()

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

int main(){
    int N;
    vector<int> poloc;
    vector<int> odd_poloc;
    int t = 1;
    while (1)
    {
        if (t * (t + 1) * (t + 2) / 6>1000000)
            break;
        poloc.push_back(t * (t + 1) * (t + 2) / 6);
        if ((t * (t + 1) * (t + 2) / 6)%2 == 1)
            odd_poloc.push_back(t * (t + 1) * (t + 2) / 6);
        t++;
    }
    vector<int> dp(1000001, 10000000), dp2(1000001, 10000000);
    dp[0] = 0;
    for (int i = 0; i < 1000000; i++)
    {
        for (int j = 0; j < poloc.size(); j++)
        {
            if (i + poloc[j] > N)
                break;
            dp[i + poloc[j]] = min(dp[i + poloc[j]], dp[i] + 1);
        }
    }
    dp2[0] = 0;
    for (int i = 0; i < 1000000; i++)
    {
        for (int j = 0; j < odd_poloc.size(); j++)
        {
            if (i + odd_poloc[j] > N)
                break;
            dp2[i + odd_poloc[j]] = min(dp2[i + odd_poloc[j]], dp2[i] + 1);
        }
    }
    while (cin >> N, N)
    {
        cout << dp[N] << " " << dp2[N] << endl;
    }
}


Measured memory_bytes: 10616
#include<stdio.h>
int main(){
	const int max=1000000;
	int sum[max+2];
	int i, k, n;
	int sosu[max+1];
	for(i=2;i<=max;i++){
		sosu[i]=1;
	}
	for(i=2;i*i<=max;i++){
		if(sosu[i]){
			for(k=2*i;k<=max;k+=i){
				sosu[k]=0;	
			}
		}
	}	

	for(i=2;i<=max;i++){
		if(sosu[i]){//i????´???°??????
			sum[i+1]=sum[i]+1;
		}else{
			sum[i+1]=sum[i];
		}
	}	
	while(scanf("%d",&n) != EOF){
		printf("%d\n",sum[n+1]);
	}
	return 0;
}

Measured memory_bytes: 8408
import java.util.Scanner; 
public class Main{ 
    public static void main(String[] args){ 
        Scanner scan = new Scanner(System.in); 
        int a =scan.nextInt(); 
        int b =scan.nextInt(); 
        int c =scan.nextInt(); 
        if(a>b && a>c){ 
            if(b>c){ 
                System.out.printf("%d %d %d\n",c,b,a); 
            }else{ 
                System.out.printf("%d %d %d\n",b,c,a); 
            }
        }else if(b>a && b>c){ 
            if(a>c){ 
                System.out.printf("%d %d %d\n",c,a,b); 
            }else{ 
                System.out.printf("%d %d %d\n",a,c,b); 
            } 
        }else if(c>a && c>b){ 
            if(a>b){ 
                System.out.printf("%d %d %d\n",b,a,c); 
            }else{ 
                System.out.printf("%d %d %d\n",a,b,c); 
            } 
        } 
    } 
} 



Measured memory_bytes: 26332
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = Integer.parseInt(sc.next());
		int M = Integer.parseInt(sc.next());

		Map<Long, Long> m = new TreeMap<>();
		for (int i = 0; i < N; i++) {
			long cost = Long.parseLong(sc.next());
			Long remain = Long.parseLong(sc.next());
			if(m.containsKey(cost)) {
				// 同値はマージしていく
				m.put(cost, (long)m.get(cost) + remain);
			}else {
				m.put(cost, remain);
			}
		}
		
		long ans = solve(N,M,m);
		System.out.println(ans);
	}

	public static long solve(int N, int M, Map<Long, Long> m) {

		long ans = 0;
		int remain = M;
		for (Entry<Long, Long> entry : m.entrySet()) {

			long tmp = remain - entry.getValue();
			if (tmp >= 0) {

				// 1店舗分全部買い取れる
				ans += (long) entry.getKey() * entry.getValue();
			} else {

				// 全部は買い取れない。
				ans += (long) entry.getKey() * remain;
			}
			remain -= entry.getValue();
			if (remain <= 0) {
				// もう買い取る必要がないので抜ける
				break;
			}
		}
		return ans;
	}
}


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

int main() {
    int n,s,sm=0,mn=100;
    cin>>n;
    for (int i=0;i<n;i++) {
        cin>>s;
        sm+=s;
        if (s%10)
            mn=min(mn,s);
    }
    if (sm%10)
        cout<<sm<<endl;
    else if (mn!=100)
        cout<<sm-mn<<endl;
    else
        cout<<0<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<set>
using namespace std;
char in[3];
set<int> S[5];
set<int> U;
int cur;
char str[110000];
set<int>expr();
set<int>term(){
	if(str[cur]=='('){
		cur++;
		set<int>ret=expr();
		cur++;
		return ret;
	}
	if(str[cur]=='c'){
		cur++;
		set<int>tmp=term();
		set<int>ret;
		for(set<int>::iterator it=U.begin();it!=U.end();it++){
			if(!tmp.count(*it))ret.insert(*it);
		}
		return ret;
	}
	if(str[cur]=='U'){
		cur++;
		return U;
	}
	return S[str[cur++]-'A'];
}
set<int>expr(){
	set<int>ret=term();
	while(str[cur]=='u'||str[cur]=='i'||str[cur]=='d'||str[cur]=='s'){
		char c=str[cur];
		cur++;
		set<int>tmp=term();
		set<int>to;
		if(c=='i'){
			for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
				if(tmp.count(*it))to.insert(*it);
			}
		}
		if(c=='u'){
			for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
				to.insert(*it);
			}
			for(set<int>::iterator it=tmp.begin();it!=tmp.end();it++){
				to.insert(*it);
			}
		}
		if(c=='d'){
			for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
				if(!tmp.count(*it))to.insert(*it);
			}
		}
		if(c=='s'){
			for(set<int>::iterator it=ret.begin();it!=ret.end();it++){
				if(!tmp.count(*it))to.insert(*it);
			}
			for(set<int>::iterator it=tmp.begin();it!=tmp.end();it++){
				if(!ret.count(*it))to.insert(*it);
			}
		}
		ret=to;
	}
	return ret;
}
int main(){
	int n;
	while(~scanf("%s%d",in,&n)){
		for(int i=0;i<5;i++)S[i].clear();
		U.clear();
		cur=0;
		for(int i=0;i<n;i++){
			int p;scanf("%d",&p);
			S[in[0]-'A'].insert(p);
			U.insert(p);
		}
		while(1){
			scanf("%s%d",in,&n);
			if(in[0]=='R')break;
			for(int i=0;i<n;i++){
				int p;scanf("%d",&p);
				S[in[0]-'A'].insert(p);
				U.insert(p);
			}
		}
		scanf("%s",str);
		set<int>res=expr();
		bool f=true;
		
		for(set<int>::iterator it=res.begin();it!=res.end();it++){
			if(!f)printf(" ");
			printf("%d",(*it));
			f=false;
		}
		if(f)printf("NULL");
		printf("\n");
	}
}

Measured memory_bytes: 1052
#include <stdio.h>
#include <math.h>

int main()
{
  int kk, ss;
  scanf("%d %d", &kk, &ss);
  int count = 0;
  for(int xx = 0;xx <= kk;xx++)
  {
    for(int yy = 0;yy <= kk;yy++)
    {
      int zz = ss - xx - yy;
      if(zz >= 0 && zz <= kk)
        count++;
    }
  }
  printf("%d\n", count);
  return 0;
}

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

using namespace std;

#define int long long

int MAX = 2e5 + 100;

int N,M,V,P,ans;
vector<int> A(MAX), sum(MAX);

main() {

    
    cin >> N >> M >> V >> P;
    for (int i = 1; i <= N; i++) cin >> A[i];

    sort(A.begin()+1,A.begin()+N+1);
    reverse(A.begin()+1,A.begin()+N+1);

    for (int i = 1; i <= N; i++) sum[i] = sum[i-1] + A[i];

    int i;

    for (i = P+1; i <= N; i++) {
        int k = max(0LL, V-P);
        int contrib = M*(N-i);
        contrib += (A[i] + M)*(i-P) - (sum[i-1]-sum[P-1]);//(sum from p to i-1);
        if (contrib < k*M || A[i]+M < A[P]) {
            break;
        }
    }

    cout << i-1 << "\n";

    return 0;
}

Measured memory_bytes: 3328
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String n = sc.next();

//		int[] arrayA = new int[n];
//		for(int i=0;i<n;i++) {
//			arrayA[i] = sc.nextInt();
//		}
		sc.close();


		int l = n.length();

		if(!n.substring(l-1).equals("s")) {
			System.out.println(n+"s");
		}else {
			System.out.println(n+"es");
		}

	}
}


Measured memory_bytes: 38548
import sys
import math
#a,b= map(int,input().split())
N=int(input())
#a, b, c = [list(map(int, input().split())) for _ in range(3)]
li0= [int(x) for x in input().split()]
sum=i=0
for i in range(len(li0)):
  sum+=1/li0[i]
print(1/sum)

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(i64 (i) = (s);(i) < (e);(i)++)
#define all(x) x.begin(),x.end()
#define STRINGIFY(n) #n
#define TOSTRING(n) STRINGIFY(n)
#define PREFIX "#" TOSTRING(__LINE__) "| "
#define debug(x) \
{ \
  std::cout << PREFIX << #x << " = " << x << std::endl; \
}

std::ostream& output_indent(std::ostream& os, int ind) {
  for(int i = 0; i < ind; i++) os << " ";
  return os;
}

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p);
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v);

template<class S, class T> std::ostream& operator<<(std::ostream& os, const std::pair<S, T>& p) {
  return (os << "(" << p.first << ", " << p.second << ")");
}
template<class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
  os << "[";
  for(int i = 0;i < v.size();i++) os << v[i] << ", ";
  return (os << "]");
}

template<class T>
static inline std::vector<T> ndvec(size_t&& n, T val) { return std::vector<T>(n, std::forward<T>(val)); }
template<class... Tail>
static inline auto ndvec(size_t&& n, Tail&&... tail) {
  return std::vector<decltype(ndvec(std::forward<Tail>(tail)...))>(n, ndvec(std::forward<Tail>(tail)...));
}
template<class Cond> struct chain {
  Cond cond; chain(Cond cond) : cond(cond) {}
  template<class T> bool operator()(T& a, const T& b) const { if(cond(a, b)) { a = b; return true; } return false; }
};
template<class Cond> chain<Cond> make_chain(Cond cond) { return chain<Cond>(cond); }

int main() {
  int N;
  cin >> N;
  int cnt = 0;
  int MAX = 0;
  rep(i,0,N) {
    int a, b;
    cin >> a >> b;
    if(a == b) {
      cnt++;
    }
    else {
      cnt = 0;
    }
    MAX = std::max(MAX, cnt);
  }
  if(MAX >= 3) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

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

    int n;
    cin >> n;
    unordered_map<int, int> mp;
    REP(i, n){
        int a;
        cin >> a;
        mp[a]++;
    }

    int cnt = 0;
    for(auto x : mp){
        if(x.first > x.second) cnt += x.second;
        if(x.first < x.second) cnt += x.second - x.first;
    }

    cout << cnt << endl; 

    return 0;
}

Measured memory_bytes: 4260
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>

#define ll long long
#define Int ll
#define loop(x, start, end) for(Int x   = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (*(x.end()-1)) 

using namespace std;
#define M 1000000007

Int X, Y;

Int faster_pow(Int x, Int y) {
  if (y == 0) return 1;
  Int res = faster_pow((x * x) % M, y / 2);
  if (y % 2 == 1) {
    res = (res * x) % M;
  }
  return res;
}

void input() {
  cin >> X >> Y;
}

void solve() {
  cout << faster_pow(X, Y) << endl;
}

int main() {
  input();
  solve();
  return 0;
}


Measured memory_bytes: 3080
H, W = map(int, input().split())

L_input = [["." for i in range(W)] for j in range(H)]
L_width = [["x" for i in range(W)] for j in range(H)]
L_height = [["x" for i in range(W)] for j in range(H)]

flag = 0



for i in range(H) : 
    tmp = list(input())
    for j in range(W) : 
        L_input[i][j] = tmp[j]

for i in range(H) : 
    for j in range(W-1) : 
        if L_input[i][j] == "#" and L_input[i][j+1] == "#" : 
            L_width[i][j] = "o"
            L_width[i][j+1] = "o"

for j in range(W) : 
    for i in range(H-1) : 
        if L_input[i][j] == "#" and L_input[i+1][j] == "#" : 
            L_height[i][j] = "o"
            L_height[i+1][j] = "o"
            
for i in range(H) : 
    for j in range(W) : 
        if L_input[i][j] == "#" : 
            if L_width[i][j] != "o" and L_height[i][j] != "o" : 
                flag = 1
                
if flag == 0 : 
    print("Yes")
else : 
    print("No")

Measured memory_bytes: 3188