akhauriyash/Code-Regression huggingface dataset:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    n,x = LI()
    a = LI()
    a.sort()
    ans = 0
    for i in a:
        if i <= x:
            ans += 1
            x -= i
        else:
            print(ans)
            return
    if x:
        print(ans-1)
    else:
        print(ans)
    return

#B
def B():
    n,X = LI()
    x = LI()
    for i in range(n-1):
        x[i+1] += x[i]
    x.insert(0,0)
    ans = float("inf")
    f = [5]*(n+1)
    for i in range(1,n):
        f[i+1] = f[i]+2
    for k in range(1,n+1):
        i = 0
        a = n
        d = (k+n)*X
        while a > 0:
            d += f[i]*(x[a]-x[max(0,a-k)])
            a -= k
            i += 1
        ans = min(ans,d)
    print(ans)
#C
def C():
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return


#Solve
if __name__ == "__main__":
    A()


Measured memory_bytes: 39024
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <string>
#include <map>
#include <queue>

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    string S;
    cin >> S;
    REP(i, S.size()) {
        if (S[i] == 'U' || S[i] == 'D') continue;
        if ((i % 2 == 0 && (S[i] != 'R')) ||
            (i % 2 == 1 && (S[i] != 'L'))) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Linq;
using System.Collections.Generic;

class Program {
    static void Main() {
        string x;
        while((x = Console.ReadLine()) != "0") {
            int ans = 0;
            for(int i = 0; i < x.Length; i++) ans += int.Parse(x.Substring(i, 1));
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 15964
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const double pi=acos(-1);
bool check(double a,double b,double x,double t)
{
    double v=a*a*b;
    t=t/180*pi;
    double c=sqrt(a*a+b*b);
    double tmp=asin(a/c);
    double limit=pi/2-tmp;
    if(t<=limit)
    {
        v-=0.5*a*a*tan(t)*a;
        return v>=x;
    }
    else
    {
        double q=pi/2-t;
        return 0.5*b*b*tan(q)*a>=x;
    }
}
int main()
{
    double a,b,x;
    scanf("%lf%lf%lf",&a,&b,&x);
    double ans=0;
    double l=0,r=90;
    for(int i=1;i<=10000;i++)
    {
        double mid=(l+r)/2;
        if(check(a,b,x,mid))
            ans=mid,l=mid;
        else
            r=mid;
    }
    printf("%.10f\n",ans);
    return 0;
}


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

int main(){
  int n;cin>>n;
  int x[n];
  int y[n];
  for(int i=0;i<n;i++){cin>>x[i];y[i]=x[i];}
  sort(x,x+n);

  for(int i=0;i<n;i++){
    if(y[i]<=x[n/2-1]){cout<<x[n/2]<<endl;}
    else{cout<<x[n/2-1]<<endl;}
  }
  
  return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
bool suf(ld a, ld b, ld c, ld d) {
	if (b <= c || d <= a) return 0;
	return 1;
}//[a,b),[c,d)
ll fact(ll i) {
	ll sum = 1;
	for (ll j = 2; j <= i; j++)
		sum = (sum* j) % Mod;
	return sum;
}//階乗(正）
#define int long long
const long long inf = 4523372036854775807;
const int iinf = 1500000000;
//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int m;
	cin >> m;
	cout << 24 + (24 - m) << endl;
	getchar(); getchar();
}

Measured memory_bytes: 256
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
a=b=c= 0
d = []

for i in range(n):
    t = abs(x[i]-y[i])
    a += t
    b += t**2
    c += t**3
    d.append(t)

print(a)
print(b**(1/2))
print(c**(1/3))
print(max(d))


Measured memory_bytes: 5640
let input = readLine()!.split(separator: " ").map { Int($0)! }

let N = input[0]
let M = input[1]

var intervals: [[Int]] = []

for _ in 0..<M {
  let inp = readLine()!.split(separator: " ").map { Int($0)! }
  intervals.append([inp[0], inp[1]])
}
let startMax = intervals.map { $0[0] }.max()!
let endMin = intervals.map { $0[1] }.min()!

print(max(0, endMin - startMax + 1))


Measured memory_bytes: 16040
#include <cstdio>
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
int a[100000];
int main()
{
	int n,q;
	long long int k;
	int a;
	int t[100000];
	cin >> n >> k >> q;
	for (int i=1;i<=n;i++)
	{
		t[i]=k;
	}
	for (int i=1;i<=q;i++)
	{
		cin >> a;
		t[a]++;
	}
	for (int i=1;i<=n;i++)
	{
		t[i]-=q;
	}
	for (int i=1;i<=n;i++)
	{
		if(t[i]<=0)
		cout << "No" << endl;
		else
		cout << "Yes" << endl;
	}
//	cout << t[8] << " " << t[10]; 
	
	return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int comp(const void *a, const void *b) {                                        
                                                                                
    if (*(int *)a == *(int *)b)                                                 
        return 0;                                                               
    else if (*(int *)a > *(int *)b)                                             
        return -1;                                                              
    else                                                                        
        return 1;                                                               
}

int main(void) {                                                                
    int x[5];                                                                   
    int i= 0;                                                                   
                                                                                
    while (i < 5)                                                               
        scanf("%d", &x[i++]);                                                   
    qsort(x,  5, sizeof(int), comp);                                            
    i = 0;                                                                      
    while (i < 5) {                                                             
        printf("%d", x[i++]);                                                   
        if (i != 5) printf(" ");                                                
    }                                                                           
    printf("\n");                                                               
    return 0;                                                                   
}

Measured memory_bytes: 604
#include <stdio.h>

int main()
{
    int H, W;
    int h, w;
    while(1) {
        scanf("%d %d", &H, &W);
        if(H == 0 && W == 0) {
            break;
        }
        for(h = 0; h < H; h++) {
            for(w = 0; w < W; w++) {
                putchar('#');
            }
            putchar('\n');
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 2056
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

ll add(ll x, ll y){
    return (x+y)%mod;
}

ll mul(ll x, ll y){
    return (x%mod)*(y%mod)%mod;
}

ll powll(ll x, ll y){
    x %= mod;
    ll res = 1LL;
    while(y){
        if (y & 1LL)
            res *= x;
        res %= mod;
        x = (x*x) % mod;
        y >>= 1LL;
    }
    return res;
}

ll divll(ll x, ll y){
    x %= mod;
    return (x * powll(y,mod-2)) % mod;
}

int main() {
    int n;
    cin >> n;
    VL a(n);
    map<ll, ll> mf;
    REP(i,n){
        a[i] = in();
        ll x = a[i];
        for (ll d = 2; d <= 1000; d++){
            if (x % d) continue;
            ll c = 0;
            while (x % d == 0){
                x /= d;
                c++;
            }
            if (c > mf[d]) mf[d] = c;
        }
        if (x != 1){
            if (1 > mf[x]) mf[x] = 1;
        }
    }
    ll lcm = 1;
    for (PL p : mf){
        ll d = p.first, c = p.second;
        REP(_,c) lcm = (lcm * d) % mod;
    }
    ll ans = 0;
    REP(i,n) ans = (ans + divll(lcm, a[i])) % mod;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 896
from functools import reduce
n,k = map(int,input().split())
n += 1
mod = 10 ** 9 + 7
ans = 0
lis = [i for i in range(n)]
left = [0]
right = [lis[-1]]
for i in range(1,n):
    left.append(left[-1]+i)
for i in range(n-2,-1,-1):
    right.append(right[-1]+i)
for i in range(k-1,n):
  #    print(right[i],left[i])
    ans += max(0,right[i]-left[i]+1)%mod
    ans %= mod
  #print(left,right)
print(ans)

Measured memory_bytes: 38688
/*

Our shadows stretch out on the pavement
As I walk in the twilight with you
If we could be together like this forever
Holding hands
It's almost enough to make me cry

The wind grows colder
I can smell winter
Soon the season will come to this town
When I can get close to you

This moment
When the two of us cuddle up
To gaze at the first snow flower of the year
Is overflowing with happiness

It's not dependence or weakness
I just love you
I thought so with all my heart

I feel like when I'm with you
I can overcome anything
I pray that these days
Will continue forever

The wind rattled the window
The night shakes you awake
I will change any sorrow
Into a smile

The snow flowers fell
Outside the window
Unceasing
And colored our town
I realized that love means
Wanting to do something
For someone else

If I should lose you
I'll become a star and shine on you
I'll be with you even on nights
When your smile is wet with tears

This moment
When the two of us cuddle up
To gaze at the first snow flower of the year
Is overflowing with happiness

It's not dependence or weakness
I just want to be like this
With you forever
I can honestly think that now

The pure white snow flowers
Bury this town
Softly drawing memories in our hearts
Together forever with you...

*/

#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 5;

int a[N];

int main() {
  int n, A, B;
  scanf("%d %d %d", &n, &A, &B);
  for (int i = 0; i < n; i++) a[i] = i;
  int sisa_n = n - B;
  int cluster = A - 1;
  int k = sisa_n / B + (sisa_n % B? 1 : 0);
  if (k <= cluster && cluster <= sisa_n) {
    reverse(a + n - B, a + n);
    int now = n - B;
    int makan = sisa_n - cluster;
    while (makan > 0) {
      int del = min(B - 1, makan);
      //printf("makan %d del %d\n", makan, del);
      //printf("rev %d %d\n", now - del - 1, now - 1);
      reverse(a + now - del - 1, a + now);
      makan -= del;
      now -= del + 1;
    }
    for (int i = 0; i < n; i++) printf("%d ", a[i] + 1);
  } else {
    puts("-1");
  }

  return 0;
}


Measured memory_bytes: 3328
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main{
  public static void main(String[] args) {
    try {
      BufferedReader stdReader =
        new BufferedReader(new InputStreamReader(System.in));
      String line;
      while ((line = stdReader.readLine()) != null) { 
    	  int x = Integer.parseInt(line);
        System.out.println(x*x*x);
      }
      stdReader.close();
    } catch (Exception e) {
      e.getStackTrace();
      /*?????´??????0??????*/
      System.exit(0); 
    }
  }
}

Measured memory_bytes: 16928
#include <iostream>
#include <cstdio>
#include<list>
#include<iomanip>
#include<cmath>
#include<queue>
#include <functional>
#include<stdio.h>
#include<assert.h>
#include<stack>
#include<sstream>
#include <cstdlib>
#include<map>
#include<algorithm>
#include<iostream>
#include<set>
#include<utility>
#include<memory.h>
#include<complex>
#include<string>
#include<vector>
#include<numeric>
using namespace std;
#define ll  long long
#define pb push_back
#define sz(v)               ((int)((v).size()))
#define all(x)          (x).begin(),(x).end()
#define REP(i, v)       for(int i=0;i<sz(v);i++)
using namespace std;
typedef pair<int,int> pii;
ll n,m;
vector<ll> v;
bool ok()
{
	//REP(i,v) cerr << v[i] << " ";
//	cerr << "\n";
	REP(i,v) if(v[i] >= n) return 0;
	return 1;
}
int main()
{
	scanf("%lld",&n);
	ll x;
	for(int i = 0 ; i < n ; ++i)
	{

		scanf("%lld",&x);
		v.pb(x);
	}
	sort(v.rbegin(),v.rend());
	ll ops = 0;
	while(!ok())
	{

		REP(i,v)
	    {
			REP(j,v) if(i != j) v[j] += 1LL*(v[i]/n);
			ops += (1LL*v[i]/n),v[i] = v[i] % n;
		}
		sort(v.rbegin(),v.rend());
	}
	printf("%lld\n",ops);
}


Measured memory_bytes: 256
s = [0,['.',',','!','?',' '],['a','b','c'],['d','e','f'],['g','h','i'],['j','k','l'],['m','n','o'],['p','q','r','s'],['t','u','v'],['w','x','y','z']]
for _ in range(int(input())):
    l = list(filter(lambda x: x!='', input().split('0')))
    r = ''
    for d in l:
        i,j = int(d[0]),len(d)-1
        r += s[i][j%len(s[i])]
    print(r)

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

int main(){
  int N,K;
  cin >> N >> K;
  int x,d;
  for(int i=0; N > i;i++){
    cin >> x;
    if( K-x > x){
    d = d+x;
    }
    else{
    d = d+(K-x);
    }
  }
  cout << 2*d << endl;
  
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define mod 1000000007


int main() {
    ll H, W; cin >> H >> W;
    ll ans = INF;
    if((H-H/3)%2 == 0){
        ans = min(ans, W * abs((H-H/3)/2 - H/3));
    }else{
        ans = min(ans, W * abs(H-2*H/3 - H/3));
    }

    if((W-W/3)%2 == 0){
        ans = min(ans, H * abs((W-W/3)/2 - W/3));
    }else{
        ans = min(ans, H * abs(W-2*W/3 - W/3));
    }
    
    for(int i=1; i<=H; i++){
        ll a = i * W;
        ll b = (H-i) * (W/2);
        ll c = (H-i) * W - b;
        ll mxr = max(max(a,b),c);
        ll mnr = min(min(a,b),c);
        
        ans = min(ans, mxr-mnr);
    }
    
    for(int i=1; i<=W; i++){
        ll a = i * H;
        ll b = (W-i) * (H/2);
        ll c = (W-i) * H - b;
        ll mxr = max(max(a,b),c);
        ll mnr = min(min(a,b),c);
        ans = min(ans, mxr-mnr);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#!C:\Users\daichi\Anaconda3/python.exe
# -*- coding: utf-8 -*-

C = input().split()
a = C[0]
b = C[1]
c = C[2]

k=3
if(a == b and b == c):
    k = 1
elif(a == b and b != c):
    k = 2
elif(a == c and b != c):
    k = 2
elif(b == c and a != c):
    k = 2
else:
    k=3
print(k)

Measured memory_bytes: 3060
N = int(input())
S1 = str(input())
S2 = str(input())

if S1[0] == S2[0]:
  ans = 3
  cnt = 1
  tmp = 0
else:
  ans = 6
  cnt = 2
  tmp = 1
  
while cnt < N:
  if tmp == 0:
    if S1[cnt] == S2[cnt]:
      ans *= 2
      cnt += 1
    else:
      ans *= 2
      cnt += 2
      tmp = 1
  else:
    if S1[cnt] == S2[cnt]:
      cnt += 1
      tmp = 0
    else:
      ans *= 3
      cnt += 2
print(ans%1000000007)

Measured memory_bytes: 9212
h, w, k = map(int, input().split())
c = [[] for _ in range(h)]
for i in range(h):
    c[i] = input()

res = 0
from itertools import product
for v1 in product([0,1], repeat=h):
    for v2 in product([0,1], repeat=w):
        cnt = 0
        for i in range(h):
            if v1[i] == 0: continue
            for j in range(w):
                if v2[j] == 1 and c[i][j] == '#':
                    cnt += 1
        if cnt == k:
            res += 1
print(res)

Measured memory_bytes: 72852
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

const int CN = 4;
const int RN = 13;
const char scs[] = {'S','H','C','D'};

bool cs[CN][RN];

int main(){
	int n;
	cin >> n;
	
	for(int i = 0; i < n; i++){
		char sc;
		int c,r;
		cin >> sc >> r;
		
		switch(sc){
			case 'S': c = 0; break;
			case 'H': c = 1; break;
			case 'C': c = 2; break;
			case 'D': c = 3; break;
		}
		
		cs[c][r-1] = true;
	}
	
	for(int c = 0; c < CN; c++)
		for(int r = 0; r < RN; r++)
			if(! cs[c][r]) printf("%c %d\n", scs[c], r + 1);
		return 0;
}
	

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

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

    long long res = 0;
    int right = 0;
    int sum = 0;
    for (int left = 0; left < N; left++) {
        while (right < N && (sum ^ a[right]) == (sum + a[right])) {
            sum += a[right];
            right++;
        }
        res += right - left;
        if (left == right) {
            right++;
        } else {
            sum -= a[left];
        }
    }
    cout << res << endl;
}

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

int main() {
  int x, n;
  cin >> x >> n;

  vector<int> Ps(n);
  for (int i = 0; i < n; i++) {
    cin >> Ps.at(i);
  }

  vector<int> line(102, 0);
  for (int p : Ps) {
    line.at(p) = 1;
  }

  int L, R;
  for (int i = 0; i < 102; i++) {
    L = x - i;
    R = x + i;
    if (line.at(L) == 0) {
      cout << L << endl;
      break;
    }
    if (line.at(R) == 0) {
      cout << R << endl;
      break;
    }
  }
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,a[100],ans=1;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i]; 
	}
	sort(a,a+n);
	int c=a[0];
	for(int i=0;i<n;i++){
		if(a[i]>c){
			c=a[i];
			ans++;
		}
	}
	cout<<ans;
}

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

using namespace std;
typedef long long ll ;
const int N = 1e5 + 2 , OO = 0x3f3f3f3f ;
ll arr1[N]  , arr2[N] , arr3[N], mem[101][N];
int n , w ;
ll solve(int idx , int weight){
    if(idx == n)
        return 0;
    ll &ret = mem[idx][weight];
    if(~ret)
        return ret;
    ret = max(ret , solve(idx + 1 , weight));
    if(weight >= arr1[idx])
        ret = max(ret , arr2[idx] + solve(idx + 1 , weight - arr1[idx]));
    return ret;
}
int main()
{
    cin >> n >> w ;
    for(int i = 0 ; i < n ; ++i) cin >> arr1[i] >> arr2[i];
    memset(mem , -1 , sizeof mem);
    cout << solve(0 , w);
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SREP(i, s) for(int i = 0; i < (s.length()); i++)
#define SORT(v, n) sort(v, v+n);
#define GSORT(v, n) sort(v, v+n, greater<int>())
#define REV(a) reverse(begin(a),end(a));

int main(){
	ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////
	string a,b,c;
	cin >> a >> b >> c;
	cout << (a[a.size()-1]==b[0] && b[b.size()-1]==c[0] ? "YES" : "NO") << endl;

	
//////////////////////////////////////////////
}


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

int ans[600010],A,B,n,f[600010],g[600010],len,nw,lenn,nww;
char s[200010],ss[200010];

int main()
{
	scanf("%d%s",&n,s),len=strlen(s),A=B=1;
	for (int i=1; i<=(n+1)/2; i++) A*=3;
	for (int i=(n+1)/2; i<n; i++) B*=3;
	for (int i=0; i<A*B; i++) f[i]=f[i/3]*3+(i*2%3),g[i]=(i+1)%(A*B);
	for (int i=0; i<A; i++)
	{
		nw=i,lenn=0,ss[0]='P';
		for (int j=0; j<len; j++)
			if (s[j]=='R') 
			{
				nw=g[nw]; 
				if (nw%A==0) ss[++lenn]='R';
			} else 
			{
				nw=f[nw];
				if (ss[lenn]=='S') lenn--; else ss[++lenn]='S';
			}
		ans[i]=nw,nw%=A;
		for (int j=1; j<B; j++)
		{
			nww=j;
			for (int k=1; k<=lenn; k++)
				if (ss[k]=='R') nww=g[nww]; else nww=f[nww];
			ans[j*A+i]=nww%B*A+nw;
		}
	}
	for (int i=0; i<A*B; i++) printf("%d ",ans[i]);
	return 0;
}

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

using namespace std;

int main(){
    vector<int> dis(5);
    int distant=0,k,cnt=0;
    for(auto &e:dis) cin >>e;
    cin >> k;
    for(int h=0;h<4;h++){
        for(int j=h+1;j<5;j++){
            if(dis[j]-dis[h]>k){
                cout <<":("<<endl;
                return 0;
            }
        }
        distant=0;
    }
    cout << "Yay!" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define co(n) cout<<n<<endl
#define all(n) (n).begin(),(n).end()
#define pb(n,m) n.push_back(m)
#define fix(n) cout<<fixed<<setprecision(n);
using namespace std;
//using bint=boost::multiprecision::cpp_int;
typedef long long ll;
typedef unsigned long long ull;

int main(){
  while(1){
    int a,b;
    char c;
    cin>>a>>c>>b;
    if(c=='+') co(a+b);
    else if(c=='-') co(a-b);
    else if(c=='*') co(a*b);
    else if(c=='/') co(a/b);
    else break;
  }
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vi X(n);
  vi Y(n);
  rep(i,n){
    int x;
    cin >> x;
    X.at(i) = x;
    Y.at(i) = x;
  }
  sort(Y.begin(),Y.end());
  rep(i,n){
    if (X.at(i) < Y.at(n/2)) cout << Y.at(n/2) << endl;
    else cout << Y.at(n/2-1) << endl;
  }
  return 0;
}


Measured memory_bytes: 4852
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include<unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X <<":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;
struct edge {int to,cost;};
#define VMAX 100000
bool cmp(P a,P b){ return a.second < b.second;}
ll N,M,ans=0;
vector<P> S;
int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>M;
    //S.reserve(M);
    REP(i,M){
        int a,b;
        cin>>a>>b;
        S.push_back({a,b});
        //cin>>S[i].first>>S[i].second;
    }
    sort(ALL(S),cmp);
    int t=0;
    REP(i,M){
        DEB(S[i].first)DEB(S[i].second)END
        if(S[i].first>=t){
            t=S[i].second;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
}


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

int main(){
	int n;
	string s[101];
	cin>>n;
	for(int i=1,j;i<=n;++i){
		cin>>s[i];
		if(i==1)	continue;
		if(s[i][0]!=s[i-1][s[i-1].length()-1]){
			cout<<"No";
			return 0;
		}
		else{
			for(j=1;j<=i-1;++j){
				if(s[i]==s[j]){
					cout<<"No";
					return 0;					
				}
			}
		}
	}
	cout<<"Yes";
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static List<int[]>[] to;
    static long[] dist;
    static int n;
    
    public static void main(String[] args) throws Exception {
        // Your code here! 
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        
        // to: 隣接リスト(無向)
        to = new List[n];
        for (int i = 0; i < n; i++) {
            to[i] = new ArrayList<int[]>();
        }
        for (int i = 0; i < n - 1; i++) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            int dis = sc.nextInt();
            to[p].add(new int[]{q, dis});
            to[q].add(new int[]{p, dis});
        }
        
        // 点kから各点までの距離を計算 
        int query = sc.nextInt();
        int k = sc.nextInt() - 1;
        long[] distK = calcDist(k);
        
        // p→k→qの最短距離を出力
        while (query-- > 0) {
            int p = sc.nextInt() - 1;
            int q = sc.nextInt() - 1;
            
            System.out.println(distK[p] + distK[q]);
        }
    }
    
    public static long[] calcDist(int p) {
        dist = new long[n];
        dfs(p, 0, -1);
        return dist;
    }
    
    // 頂点pと隣接する点に自分の値+距離を配る
    public static void dfs(int p, long d, int par) {
        dist[p] = d;
        
        for (int[] q : to[p]) {
            if (q[0] == par) continue;
            dfs(q[0], d + q[1], p);
        }
    }
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const int MAX_N = 60;
const int MAX_X = 60;
const int MAX_V = MAX_N * MAX_X;
ll dp[MAX_N][MAX_X][MAX_V];

int main() {
    int N, A;
    cin >> N >> A;
    vector<int> x(N);
    rep(i, N) cin >> x[i];

    dp[0][0][0] = 1;
    rep(i, N) {
        rep(j, N) {
            rep(k, 2550) {
                if (dp[i][j][k] == 0) continue;

                dp[i + 1][j][k] += dp[i][j][k];
                dp[i + 1][j + 1][k + x[i]] += dp[i][j][k];
            }
        }
    }

    ll ans = 0;
    for (int j = 1; j <= N; j++) ans += dp[N][j][j * A];
    cout << ans << endl;
}


Measured memory_bytes: 84224
n = int(input())
v = list(map(int, input().split()))

even_map = {}
for i in range(0, n)[::2]:
    if v[i] not in even_map:
        even_map[v[i]] = 1
    else:
        even_map[v[i]] += 1

odd_map = {}
for i in range(1, n)[::2]:
    if v[i] not in odd_map:
        odd_map[v[i]] = 1
    else:
        odd_map[v[i]] += 1

odd_map[-1] = 0
even_map[-2] = 0
odd_list = list(odd_map.items())
odd_list.sort(key=lambda x: x[1], reverse=True)
even_list = list(even_map.items())
even_list.sort(key=lambda x: x[1], reverse=True)

odds = [odd_list[i][0] for i in range(2)]
evens = [even_list[i][0] for i in range(2)]

ans_list = []
for odd in odds:
    for even in evens:
        if odd == even:
            continue
        ans = 0
        for k, v in odd_map.items():
            if k != odd:
                ans += v
        for k, v in even_map.items():
            if k != even:
                ans += v
        ans_list.append(ans)

print(min(ans_list))

Measured memory_bytes: 22752
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
)

type contest struct {
	in  io.Reader
	out io.Writer
}

func (con *contest) Scan(a ...interface{}) (int, error) {
	return fmt.Fscan(con.in, a...)
}
func (con *contest) Scanln(a ...interface{}) (int, error) {
	return fmt.Fscanln(con.in, a...)
}
func (con *contest) Scanf(f string, a ...interface{}) (int, error) {
	return fmt.Fscanf(con.in, f, a...)
}
func (con *contest) Print(a ...interface{}) (int, error) {
	return fmt.Fprint(con.out, a...)
}
func (con *contest) Println(a ...interface{}) (int, error) {
	return fmt.Fprintln(con.out, a...)
}
func (con *contest) Printf(f string, a ...interface{}) (int, error) {
	return fmt.Fprintf(con.out, f, a...)
}
func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	con := &contest{in: in, out: out}
	con.main()
}

const mod = 1e9 + 7

func (con *contest) main() error {
	var n, m int
	con.Scan(&n, &m)
	s := make([]int, 500001)
	k := m - n
	s[1] = k
	s[2] = k + 1 + k*k
	s[2] %= mod
	for i := 3; i <= n; i++ {
		x := s[i-2] * (i - 1)
		x %= mod
		y := s[i-1] * (i - 1 + k)
		y %= mod
		s[i] = x + y
		s[i] %= mod
	}
	p := 1
	for i := m; i > m-n; i-- {
		p *= i
		p %= mod
	}
	p *= s[n]
	p %= mod
	con.Println(p)
	return nil
}


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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  cerr << setprecision(10);
  int N; 
  ll K;
  cin >> N >> K;

  vector<double> A(N,0);

  long double max_len = 0;
  for(int i = 0; i < N; i++){
    cin >> A[i];
    max_len = (max_len > A[i] ? max_len : A[i]);
  }

  // cerr << "max_len" << max_len << endl;

  long double right = max_len;
  long double mid;
  long double eps = 0.00001;
  long double left = eps;

  while(right - left > eps){
    // cerr << left << " " << right << endl;
    mid = (right + left)/2;

    ll tmp = 0;
    for(int i= 0; i < N; i++){
      tmp += floor(A[i]/mid);
    }
    if(tmp > K){
      left = mid;
    } else {
      right = mid;
    }
  }
  // cerr << "right " << right << endl;
  cout << ceil(left) << endl;

}


Measured memory_bytes: 4692
def get_divisors(N):
  divisors = []
  for i in range(1,int(N**0.5)+1):
    if N%i == 0:
      divisors.append(i)
      divisors.append(N//i)
      
  divisors.sort()
  return divisors

divisors = get_divisors(int(input()))
n1,n2 = divisors[len(divisors)//2-1:len(divisors)//2+1]
print(n1+n2-2)

Measured memory_bytes: 3272
#include<iostream>
#include<string>
#include<bits/stdc++.h>
using namespace std;
int main() 
{ 
/*
// 1 3 5 7 8 10 12
// 4 6 9 11
//2
int x,y;
cin>>x>>y;
if(x==1||y==1||x==3||y==3||x==5||y==5||x==7||y==7||x==8||y==8||x==10||y==10||x==12||y==12)
cout<<"Yes";
else if(x==4||y==4||x==6||y==6||x==9||y==9||x==11||y==11)
cout<<"Yes";
else if(x==2||y==2)
cout<<"Yes";
else
cout<<"No";
*/
int A,B;
cin>>A>>B;
int a1;
a1=A+B;
if(a1>=10)
cout<<"error";
else
cout<<a1;
   return 0; 
} 

Measured memory_bytes: 3612
#include<iostream>
using namespace std;
int main(){
    int n , k , cn=0, i;
    cin >> n >> k;
    int a[n];
    for(i=0; i<n; i++)
        cin >> a[i];
    for(i=0; i<n; i++){
        if(a[i]>=k)
            cn++;
    }
    cout << cn << endl;
}

Measured memory_bytes: 640
import sys
input = sys.stdin.readline
n=int(input())
x=list(map(int,input().split()))
power=[]
x.sort()
for i in range(x[0],x[n-1]+1):
  sum=0
  for j in range(n):
    sum+=(x[j]-i)**2
  power.append(sum)
power.sort()
print(power[0])

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

int main(void) {
	long s[10001], t[501];
	int n,q,count = 0;

	cin >> n;

	for (int i = 0; i < n; i++) {
		cin >> s[i];
	}
	sort(s,s + n);

	cin >> q;
	for (int i = 0; i < q; i++) {
		cin >> t[i];
	}
	sort(t, t + q);
	for (int i = 0; i < q; i++) {
		for (int j = 0; j < n; j++) {
			if (s[j] == t[i]) {
				count++;
				break;
			}
		}
	}
	cout << count << endl;
	return 0;
}

Measured memory_bytes: 1256
#include <iostream>
#include <cstring>

using namespace std;

const int mod=1e9+7;
char polje[100003];
long long br[27];

int main (){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>polje[i];
		br[int(polje[i])-97]++;
	}
	long long sol=1LL;
	for(int i=0;i<27;i++){
		sol*=(br[i]+1)%mod;
		sol%=mod;
	}
	cout<<sol-1;
	





return 0;
}



Measured memory_bytes: 384
#ABC154C

n, k = list(map(int,input().split()))
p = [((int(x)+1)/2) for x in input().split()]

ave = sum(p[0:k])
max = ave
for i in range(n-k):
    ave = ave-p[i]+p[k+i]
    if ave > max:
        max = ave
print(max)

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

int main(){


	int n;
	string str;
	int x = 0;
	int sum = 0;

	cin >> n;
	cin >> str;

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

		if(str[i] == 'I'){
			sum++;
		}
		else{
			sum--;
		}

		if(sum > x){
			x = sum;
		}
	}

	cout << x << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        ArrayList<Integer> hl = new ArrayList<>();
        int prev = Integer.MAX_VALUE;
        for(int i = 0; i < n; i++){
            hl.add(sc.nextInt());
        }
        Collections.reverse(hl);
        for(int i = 0; i < n; i++){
            int now = hl.get(i);
            if(prev >= now){
                prev = now;
            }else if(prev+1 == now){
                continue;
            }else{
                System.out.println("No");
                return;
            }
        }
        System.out.println("Yes");
    }
}


Measured memory_bytes: 60896
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline

n,k = map(int,readline().split())
MOD = 10**9+7

def divisor_list(N): #約数のリスト
    if N == 1: return [1]
    res = []
    for i in range(1,N):
        if i*i >= N: break
        if N%i == 0:
            res.append(i)
            res.append(N//i)
    if i*i == N: res.append(i)
    return sorted(res)



if n&1:
    p = [i for i in divisor_list(n)]
    r = {pi:pow(k,(pi+1)//2,MOD) for pi in p}
    #print(r)
    for pi in p:
        for pj in p:
            if pj >= pi: break
            if pi%pj==0:
                r[pi] -= r[pj]
    #print(r)
    ans = 0
    for pi,v in r.items():
        ans += v*(pi)
    ans %= MOD
    print(ans)
    
    

else:
    p = [1] + [i for i in divisor_list(n) if i%2==0 and i!=2]
    
    r = {pi:pow(k,(pi+1)//2,MOD) for pi in p}
    for pi in p:
        for pj in p:
            if pj >= pi: break
            if pi%pj==0:
                r[pi] -= r[pj]

    #print(r)
    ans = 0
    for pi,v in r.items():
        if pi==1:
            ans += v
        else:
            ans += v*(pi//2)
    ans %= MOD
        
        
    print(ans)        
        
        
    
    
    
    


    
    
    
    
    
    

Measured memory_bytes: 9272
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

// Definitions
#define MAXN 
#define elif else if
typedef long long int64;
typedef long double num128;
typedef unsigned long long uint64;

#define PUTLINE printf("[%d] current line.\n", __LINE__)
#define STARTFUNC printf("[%s] function start.\n", __FUNCTION__)
#define File(s) freopen(#s".in", "r", stdin), freopen(#s".out","w", stdout)

// Improve the speed of read-in.
inline bool IsNum(char x) { return ('0' <= x) && (x <= '9'); }
inline int64 ReadNum() {
  int64 sign = 1, val = 0; char tmp = getchar();
  while (!IsNum(tmp)) { if (tmp == '-') {sign = -sign;} tmp = getchar(); }
  while (IsNum(tmp)) { val = val * 10 + tmp - 48; tmp = getchar(); }
  return val * sign;
}

// Variables
string s, p;
int ans = 0x3f3f3f3f;

// Functions
inline void Initialize(bool prgmsta) {
  if (!prgmsta) {
    
  } else {
    
  }
}
inline void Process() {
  for (int i = 0, slen = s.size(), plen = p.size(), tmp = 0; i < slen - plen + 1; i++) {
    tmp = 0;
    for (int j = 0; j < plen; j++)
      if (s[i + j] != p[j])
        tmp++;
    ans = min(ans, tmp);
  }
}
inline void ReadIn() {
  cin >> s;
  cin >> p;
}
inline void PrintAns() {
  cout << ans << endl;
}

int main() {
  #ifndef ONLINE_JUDGE
    File(data);
  #endif
  Initialize(0);
  ReadIn();
  Initialize(1);
  Process();
  PrintAns();
  return 0;
}
/*

*/


Measured memory_bytes: 3624
/** 
 * Dont raise your voice, improve your argument.
 * --Desmond Tutu
 */

#include <bits/stdc++.h>
using namespace std;

/* see https://github.com/pllk/cphb/ */
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,
    tree_order_statistics_node_update> indexed_set;

typedef unsigned int uint;
typedef long long ll;
//typedef __int128 lll;

#define fori(n) for(ll i=0; i<(n); i++)
#define forn(i, n) for(ll i=0; i<(n); i++)
#define forn3(i, x, n) for(ll i=(x); i<(n); i++)

int main() {
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
    int x, a;
    cin>>x>>a;

    if(x<a)
        cout<<0<<endl;
    else
        cout<<10<<endl;
    
}



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

string a, b, c;

int main(){
  cin >> a >> b >> c;
  if(a[a.size() - 1] == b[0] && b[b.size() - 1] == c[0]){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Split(bufio.ScanWords)
}

func nextInt() int {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return int(i)
}

func nextInt64() int64 {
	sc.Scan()
	i, e := strconv.ParseInt(sc.Text(), 10, 64)
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	n := nextInt()
	cs := make([]int64, 0, n+1)
	hs := make([]int64, 0, n)

	for i := 0; i <= n; i++ {
		cs = append(cs, nextInt64())
	}

	for i := 0; i < n; i++ {
		hs = append(hs, nextInt64())
	}

	var c int64
	for i, item := range hs {
		m := cs[i]
		if item-m <= 0 {
			c += item
		} else {
			c += m
			item = item - m
			mm := cs[i+1]
			if item-mm <= 0 {
				c += item
				cs[i+1] = mm - item
			} else {
				c += mm
				cs[i+1] = 0
			}
		}
	}

	fmt.Println(c)
}


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


#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }

using pll = pair<long long, long long>;
int N;
long long D, A;
vector<long long> X, H;

long long solve() {
    // モンスターを X が小さい順に
    vector<int> ids(N);
    for (int i = 0; i < N; ++i) ids[i] = i;
    sort(ids.begin(), ids.end(), [&](int i, int j) {
            return X[i] < X[j]; });
    vector<long long> nX(N), nH(N);
    for (int i = 0; i < N; ++i) nX[i] = X[ids[i]], nH[i] = H[ids[i]];
    X = nX, H = nH;

    // imos 法で処理していく
    vector<long long> S(N+1, 0);
    long long res = 0;
    for (int i = 0; i < N; ++i) {
        // モンスター i を倒すのに必要な回数
        long long need = (H[i] - S[i] + A - 1) / A;

        if (need > 0) {
            // X[i] を左端とした爆発が届く範囲を求める
            long long right = X[i] + D * 2;
            int id = upper_bound(X.begin(), X.end(), right) - X.begin();
            
            // imos しながら爆発させる
            S[i] += need * A;
            S[id] -= need * A;
            res += need;
        }

        // imos の累積和をとる操作
        S[i+1] += S[i];
    }
    return res;
}

int main() {
    cin >> N >> D >> A;
    X.resize(N); H.resize(N);
    for (int i = 0; i < N; ++i) cin >> X[i] >> H[i];
    cout << solve() << endl;
}


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

int main(){
  int n; cin>> n;
  int q; cin >> q;
  fenwick_tree<ll> fw(n);
  for(int i=0;i<n;i++){
    ll tmp; cin >> tmp;
    fw.add(i,tmp);
  }
  
  for(int i=0;i<q;i++){
    int a; cin >> a;
    if(a == 0){
      int p; cin >> p;
      ll x; cin >> x;
      fw.add(p,x);
    }else{
      int l,r; cin >> l >> r;
      cout << fw.sum(l,r) << endl;
    }
  }
}


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

using namespace std;

#define LL long long
#define DD double
#define Pb push_back
#define Bp pop_back
#define Pf push_front
#define Fp pop_front
#define Ub upper_bound
#define Lb lower_bound
#define In insert
#define All(x) x.begin(), x.end()
#define mem(a, b) memset(a, b, sizeof(a))
#define fast ios_base::sync_with_stdio(0);cin.tie(0)
#define X first
#define Y second
#define mx1 10
#define mx2 110
#define mx3 1010
#define mx4 10010
#define mx5 100010
#define mx6 1000010

typedef vector<LL> Vl;
typedef vector<DD> Vd;
typedef vector<bool> Vb;
typedef vector<Vl> VVl;
typedef pair<LL, LL> Pll;
typedef pair<DD, DD> Pdd;
typedef vector<Pll> Vpl;
typedef vector<Pdd> Vpd;
typedef queue<LL> Ql;
typedef stack<LL> Sl;
typedef deque<LL> Dl;

LL _set(LL N, LL pos) {return N = N | (1 << pos);}
LL _reset(LL N, LL pos) {return N = N & ~(1 << pos);}
bool _check(LL N, LL pos) {return (bool)(N & (1 << pos));}
bool _upper(char a) {return a >= 'A' && a <= 'Z';}
bool _lower(char a) {return a >= 'a' && a <= 'z';}
bool _digit(char a) {return a >= '0' && a <= '9';}

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

///**************************DONE****************************///

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int ans = 0;
    if(k)
        ans += min(k, a), k -= min(k, a);
    if(k)
        k -= min(k, b);
    if(k)
        ans -= min(k, c), k -= min(k, c);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

using namespace std;

int N,M;
vector<pair<int, int> > v;

int main(){
    long long a;
    int b;
    cin >> N >> M;
    for(int i=0;i<N;i++){
        cin >> a >> b;
        v.push_back(make_pair(a,b));
    }
    sort(v.begin(),v.end());
    int count = 0;
    long long y = 0;
    for(int i=0;i<N;i++){
        if(count + v[i].second < M){
            y += (long long)v[i].first * v[i].second;
            count += v[i].second;
            continue;
        }
        y += (long long)v[i].first * (M-count);
        break;
    }
    cout << y << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define endl '\n'
int main()
{ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
    int n,K;cin>>n>>K;vector<int>h(n+1);for(int i=1;i<=n;i++)cin>>h[i];
    vector<int>dp(n+1,inf);dp[1]=0;
    for(int i=2;i<=n;i++)
    {int sum=inf;
        if(i==2)dp[i]=dp[i-1]+abs(h[i]-h[i-1]);
        else 
       {
           for(int k=1;k<=min(K,i);k++)
           {
               sum=min(sum,dp[i-k]+abs(h[i]-h[i-k]));
           }
          dp[i]=sum; 
       }
        
    }
    cout<<dp[n];
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
#ifdef DEBUG
#define line() cerr << "[" << __LINE__ << "] ";
#define dump(i) cerr << #i ": " << i << " ";
#define dumpl(i) cerr << #i ": " << i << endl;
#else
#define line(i)
#define dump(i)
#define dumpl(i)
#endif
using namespace std;
int main(int argc, char const *argv[])
{
    int used[26] = {0};
    string s;
    cin >> s;
    rep(i, s.size())
    {
        used[s[i] - 'a'] = 1;
    }
    rep(i, 26)
    {
        if (used[i] == 0)
        {
            cout << (char)('a' + i) << endl;
            return 0;
        }
    }
    cout << "None" << endl;
    return 0;
}


Measured memory_bytes: 512
let hand a =
    let t = (a.(0),a.(1),a.(2),a.(3),a.(4)) in
    match t with
    (i,j,k,l,m) when (j,k,l) = (i,i,i) || (k,l,m) = (j,j,j) -> "four card"
    | (i,j,k,l,m) when (j,l,m) = (i,k,k) || (j,k,m) = (i,i,l) -> "full house"
    | (i,j,k,l,m) when (j,k) = (i,i) || (k,l) = (j,j) || (l,m) = (k,k) -> "three card"
    | (i,j,k,l,m) when (j,l) = (i,k) || (j,m) = (i,l) || (k,m) = (j,l) -> "two pair"
    | (i,j,k,l,m) when j = i || k = j || l = k || m = l -> "one pair"
    | (i,j,k,l,m) when (i,j,k,l,m) = (i,(i+1),(i+2),(i+3),(i+4))
                     || (i,j,k,l,m) = (1,10,11,12,13) -> "straight"
    | _ -> "null"
;;

let () =
    let rec read () =
        try let line = Scanf.scanf " %d,%d,%d,%d,%d\n" (fun v w x y z -> [|v;w;x;y;z|]) in
        Array.sort compare line;
        hand line |> print_endline;
        read ()
        with End_of_file -> ()
    in read ()
;;

Measured memory_bytes: 2168
#include <iostream>
#include <bitset>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <cmath>
#include <regex>
#include <iomanip>
#include <climits>
#include <utility>
#include <queue>
using namespace std;
using ll = long long int;
using dd = long double;
const ll MOD = 1e9 + 7;

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

struct Fish
{
    ll beauty;
    ll taste;
};

ll fact(ll n)
{
    if (n == 0)
    {
        return 1;
    }
    if (n == 1)
    {
        return 1;
    }
    return n * fact(n - 1) % MOD;
}

int main()
{
    ll N;
    cin >> N;
    map<string, ll> mp;
    vector<string> words(N);

    bool ok = true;

    for (ll i = 0; i < N; i++)
    {
        string w;
        cin >> w;
        
        words[i] = w;
        mp[w] += 1;

        if (i > 0) {
            ok &= words[i - 1].back() == words[i].front();
        }
        if (mp[w] > 1) {
            ok = false;
        }
    }

    cout << (ok ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256