akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define x first
#define y second

using namespace std;

const int MAXN=500500;

struct pii
{
	int x,y,id;
};

struct node
{
	pii d;
	int l,r;
	node(pii &dot)
	{
		//printf("%d\n",dot.id);
		d=dot;
	}
};

vector<node> T;
vector<int> Out;
pii In[MAXN];

bool cmpX(pii& X,pii& Y)
{
	return X.x<Y.x;
}

bool cmpY(pii& X,pii& Y)
{
	return X.y<Y.y;
}

int make(int l,int r,int dep)
{
	if(l+1>r) return -1;
	int id=T.size(),mid=(l+r)>>1;
	if(dep&1)
		sort(In+l,In+r,cmpX);
	else
		sort(In+l,In+r,cmpY);
	//printf("%d %d\n",l,r);
	T.push_back(node(In[mid]));
	//printf("|%d %d\n",l,r);
	T[id].l=make(l,mid,dep+1);
	T[id].r=make(mid+1,r,dep+1);
	//printf("|%d %d %d %d\n",id,T[id].d.id,T[id].l,T[id].r);
	return id;
}

bool inside(pii x,pii s,pii t)
{
	return x.x>=s.x&&x.y>=s.y&&x.x<=t.x&&x.y<=t.y;
}

void find(int id,pii s,pii t,int dep)
{
	if(id==-1) return ;
	if(inside(T[id].d,s,t)) Out.push_back(T[id].d.id);
	if(dep&1)
	{
		if(s.x<=T[id].d.x)
			find(T[id].l,s,t,dep+1);
		if(t.x>=T[id].d.x)
			find(T[id].r,s,t,dep+1);
	}
	else
	{
		if(s.y<=T[id].d.y)
			find(T[id].l,s,t,dep+1);
		if(t.y>=T[id].d.y)
			find(T[id].r,s,t,dep+1);
	}
}

int main()
{
	T.reserve(MAXN);
	int n;
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{
		scanf("%d%d",&In[i].x,&In[i].y);
		In[i].id=i;
	}
	make(0,n,0);
	//for(int i=0;i<n;i++) printf("%d %d %d\n",T[i].d.id,T[i].l,T[i].r);
	int q;
	scanf("%d",&q);
	for(int i=0;i<q;i++)
	{
		pii s,t;
		scanf("%d%d%d%d",&s.x,&t.x,&s.y,&t.y);
		Out.clear();
		find(0,s,t,0);
		sort(Out.begin(),Out.end());
		for(int i=0;i<Out.size();i++)
			printf("%d\n",Out[i]);
		printf("\n"); 
	}
	return 0;
}

Measured memory_bytes: 18208
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cmath>
#include<queue>
#include<stack>
#include<map>
#include<numeric>

using namespace std;

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

template<typename A, typename B> bool chmin(A &a, const B &b){ return b < a && (a = b, true); }
template<typename A, typename B> bool chmax(A &a, const B &b){ return a < b && (a = b, true); }

int main() {
  int n,cnt = 0;
  cin >> n;
  for (int i = 1; i <= n; i++){
    if ((i >= 1 && i <= 9) || (i >= 100 && i <= 999) || (i >= 10000 && i<= 99999)){
      cnt++;
    }
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ld double
#define mp make_pair
#define pb push_back
#define mod 1000000007
#define ff first
#define ss second
#define pll pair <ll,ll>
#define nl "\n"
ll cum[402][402];
ll dp[402][402];
ll n;
ll fx(ll i, ll j)
{
	if(i>=n || j>=n)
		return dp[i][j] = 1e18;
	if(dp[i][j] != 1e18)
		return dp[i][j];
	for(int k=i;k<j;k++)
	{
		ll su = cum[i][k] + cum[k+1][j];
		if(i!=k)
			su += fx(i, k);
		if(k+1!=j)
			su += fx(k+1, j);
		dp[i][j] = min(dp[i][j], su);
	}
	return dp[i][j];
}
int main()
{
	ios_base::sync_with_stdio(false);
	ll i,j,k;
	cin>>n;
	ll a[n+2];
	for(i=0;i<n;i++)
		cin>>a[i];
	for(i=0;i<n;i++)
		for(j=i;j<n;j++)
			for(k=i;k<=j;k++)
				cum[i][j] += a[k];
	for(i=0;i<402;i++)
		for(j=0;j<402;j++)
			dp[i][j] = 1e18;
	cout<<fx(0, n-1)<<nl;
	return 0;
}

Measured memory_bytes: 6188
T = int(input())

for _ in range(T):
    N = int(input())
    As = list(map(int, input().split()))
    S = list(input())
    mine = [0] * 61
    for a, s in reversed(list(zip(As, S))):
        bl = a.bit_length()
        if s == '0':
            while bl > 0:
                if (a >> (bl-1)) & 1:
                    if mine[bl] == 0:
                        mine[bl] = a
                        break
                    a ^= mine[bl]
                bl -= 1

        else:
            while bl > 0:
                if (a >> (bl-1)) & 1:
                    if mine[bl] == 0:
                        print(1)
                        break
                    a ^= mine[bl]
                bl -= 1
            else:
                continue
            break
    else:
        print(0)



Measured memory_bytes: 8976
#include <bits/stdc++.h>
#define ll long long
#define PB push_back
#define MP make_pair
#define pri 1000000007
#define ff first
#define ss second
#define all(x) x.begin(),x.end()
using namespace std;
void run(){
ll n;cin>>n;
ll c=0;
ll a[n+1],b[n];
ll s=0;
for(ll i=0;i<=n;i++){
	cin>>a[i];
	s+=a[i];
}

for(ll i=0;i<n;i++)
{   cin>>b[i];
	if(a[i]>b[i])a[i]-=b[i];
	else{
		b[i]-=a[i];
		a[i]=0;
		if(a[i+1]>b[i])a[i+1]-=b[i];
		else a[i+1]=0;
	}
}
for(ll i=0;i<=n;i++)s-=a[i];
cout<<s<<endl;
	
}
int main() {
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++)run();
	// your code goes here
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <math.h>
#include <iomanip>
#include <map>
using namespace std;

int main() {
    int a, b;
    double t;
    cin >> a >> b >> t;
    t += 0.5;
    cout << (int)(t / a) * b << endl;
}


Measured memory_bytes: 256
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_cumulative(A):
    C = [0] * (len(A) + 1)
    for i, a in enumerate(A):
        i += 1
        C[i] = C[i - 1] + a
    return C


def main():
    N, K = NMI()
    P = NLI()
    P = [p-1 for p in P]
    C = NLI()

    seen = [0] * N
    loops = []
    for i in range(N):
        if seen[i] == 1:
            continue
        now = i
        now_loop = [now]
        now_cost = C[now]
        while True:
            seen[now] = 1
            goto = P[now]
            if seen[goto] == 1:
                break
            now_loop.append(goto)
            now_cost += C[goto]
            now = goto
        loops.append([now_loop, now_cost])

    ans = -float("inf")
    for loop, cost in loops:
        C_cum = make_cumulative([C[p] for p in loop])

        for i, start in enumerate(loop):
            for j, end in enumerate(loop):
                if i == j:
                    base = cost
                    moved = len(loop)
                elif i < j:
                    base = C_cum[j] - C_cum[i]
                    moved = j - i
                else:
                    base = cost - (C_cum[i] - C_cum[j])
                    moved = len(loop) + j - i

                if moved > K:
                    continue

                if cost > 0:
                    tmp_K = K - moved
                    num_loop = tmp_K // len(loop)
                    tmp_ans = num_loop * cost + base
                else:
                    tmp_ans = base

                ans = max(ans, tmp_ans)

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 69636
#include <bits/stdc++.h>
using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;
long long INF2 = 1e16;

long long f(int l, int r, vector <long long>& v, vector <vector <long long>>& dp, vector <vector <long long>>& range_sum) {
  if (dp[l][r] != -1) return dp[l][r];
  if (l == r) {
    range_sum[l][r] = v[l];
    dp[l][r] = 0;
    return dp[l][r];
  }
  if (l + 1 == r) {
    range_sum[l][r] = v[l] + v[r];
    dp[l][r] = range_sum[l][r];
    return dp[l][r];
  }
  if (l > r) {
    return 0;
  }
  long long ans = INF2;
  for(int i = l; i < r; i++) {
    ans = min(ans, 
              f(l, i, v, dp, range_sum) + f(i + 1, r, v, dp, range_sum) + range_sum[l][i] + range_sum[i + 1][r]);
  }
  dp[l][r] = ans;
  range_sum[l][r] = range_sum[l][l + 1] + range_sum[l + 2][r];
  return ans;
}

int main(void) {
  int n;
  cin >> n;
  vector <long long> v(n);
  ffor(n) cin >> v[i];
  
  vector <vector <long long>> dp(n, vector <long long>(n, -1));
  vector <vector <long long>> range_sum(n, vector <long long>(n, -1));
  
  cout << f(0, n - 1, v, dp, range_sum) << '\n';
}

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

for i in range(N+1):
  for j in range(N-i+1):
    if 10000 * i + 5000 * j + 1000 * (N - i - j) == Y:
      print(str(i) + ' ' + str(j) + ' ' + str(N - i - j))
      exit()
print('-1 -1 -1')
      

Measured memory_bytes: 2940
n=list(map(int,input().split()))
answer=1001
for i in range(n[0]):
    a=list(map(int,input().split()))
    if a[0]<answer and a[1]<=n[1]:
        answer=a[0]
if answer==1001:
    print('TLE')
else:
    print(answer)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define dbg(a) cout << #a << " := " << (a) << endl
#define all(a) (a).begin(), (a).end()

using namespace std;
void solve();
signed main(){
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    solve();

    return 0;
}


const int INF = (int) 1e9 + 7;
void solve(){
    vector<int> nums(3); cin >> nums[0] >> nums[1] >> nums[2];
    int res = INF;
    for (int i = -2000; i <= 2000; ++i){
        int cur = 0;
        for (int j = 0; j < 3; ++j){
            int a = nums[j], b = i;
            if (a == b){
                cur += 0;
            } else if (b < a){
                cur += a - b;
            } else {
                if ((b - a) % 2 == 0)
                    cur += (b - a) / 2;
                else
                    cur += (b - (a - 1)) / 2 + 1;
            }
        }
        res = min(res, cur);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<bitset>
using std::bitset;
bitset <2005*2005> f(1);
int n,a[2005],sum;
bool flag;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){scanf("%d",&a[i]);f=f|(f<<(a[i]));sum+=a[i];}
	for(int i=(sum+1)/2;!f[i];i++) 
		if(f[i+1]){printf("%d\n",i+1);flag=true;break;}
	if(!flag) printf("%d\n",(sum+1)/2);
	return 0;
}

Measured memory_bytes: 2176
#include<stdio.h>
int main()
{
    int a, b;

    scanf("%d %d", &a, &b);

    if(a==b)
    {
        int ar[10];

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

        for(int i=0; i<b; i++)
        {
            printf("%d", ar[i]);
        }

        printf("\n");
    }

    else
    {
        if(a>b)
        {
            for(int i=0; i<a; i++)
            {
                printf("%d", b);
            }
        }

        else if(b>a)
        {
            for(int i=0; i<b; i++)
            {
                printf("%d", a);
            }
        }

        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 1672
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, K, sum = 0;
  cin >> N >> K;
  for(int i = 0; i < N; i++) {
    int x;
    cin >> x;
    if(x < K - x) {
      sum += x * 2;
    }
    else if(x >= K - x) {
      sum += (K - x) * 2;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<ll, ll>;
#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
struct FastIO {FastIO() { cin.tie(0); ios::sync_with_stdio(0); }}fastiofastio;
#ifdef DEBUG
#include "../program_contest_library/memo/dump.hpp"
#else
#define dump(...)
#endif
const ll INF = 1LL<<60;

template<class T, class F, ll LOG=60>
struct doubling {
    vector<vector<T>> nxt;
    doubling(vector<T> xs, F f) : nxt(LOG, vector<T>(xs.size())) {
        REP(i, xs.size()) nxt[0][i] = f(xs[i]);
        FOR(k, 1, LOG) REP(j, xs.size()) nxt[k][j] = nxt[k-1][nxt[k-1][j]];
    }
    // xs[x]にk回適用
    T query(ll x, ll k) {
        for(ll i=LOG-1; i>=0; --i) if(k&1LL<<i) x = nxt[i][x];
        return x;
    }
};

int main() {
    ll n;
    cin >> n;
    vector<ll> x(n);
    REP(i, n) cin >> x[i];
    ll l;
    cin >> l;

    // x[j] <= x[idx] + l であるような最大のj に移動できる
    vector<ll> xs(n);
    iota(ALL(xs), 0);
    auto f = [&](ll idx) { 
        return upper_bound(ALL(x), x[idx]+l) - x.begin() - 1;
    };
    doubling<ll, decltype(f)> dbl(xs, f);

    ll q;
    cin >> q;
    while(q--) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        if(a > b) swap(a, b);

        ll ret = 0;
        for(ll i=59; i>=0; --i) {
            if(dbl.nxt[i][a] < b) {
                ret += 1LL<<i;
                a = dbl.nxt[i][a];
            }
            if(dbl.nxt[0][a] >= b) {
                ret++;
                break;
            } 
        }
        cout << ret << endl;
    }

    return 0;
}

Measured memory_bytes: 50432
import sys
input = sys.stdin.readline
import bisect
from collections import deque

def main():
    N = int(input())
    use = deque([10**9+1])
    for _ in range(N):
        num = int(input())
        index = bisect.bisect_left(use,num)
        if index == 0:
            use.appendleft(num)
        else:
            use[index-1] = num
    
    print(len(use)-1)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 7284
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        int x;
        cin >> x;
        a[i] = x - 1;
    }

    vector<bool> c(n, false);
    int x = 0;
    int cnt = 0;
    c[0] = true;
    while(true){
        cnt++;
        int y = a[x];
        if(c[y]){
            cout << -1 << endl;
            return 0;
        }else if(y == 1){
            cout << cnt << endl;
            return 0;
        }
        c[y] = true;
        x = y;
    }
    
}

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

using namespace std;

#define int long long

const int DIM = 200007;

int v[DIM];

map <int, int> H;
 
main() 
{
	int n, k;
	cin >> n >> k;
 
	for(int i = 1; i <= n; i++) 
	{
		cin >> v[i];
		
		v[i] += v[i - 1];
		v[i] %= k;
	}
 
	H[0] = 1;
	int ans = 0;
	
	for(int i = 1; i <= n; i++) 
	{
		if(i >= k) 
		{
			int aux = (v[i - k] - (i - k)) % k;
			if(aux < 0) 
				aux += k;
			
			H[aux]--;
		}
		
		int cur = (v[i] - i) % k;
		
		if(cur < 0) 
			cur += k;
		
		ans += H[cur];
		H[cur]++;
	}
 
	cout << ans;
}

Measured memory_bytes: 14336
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=5000;
const int MAXK=5000;

int n,k;
int a[MAXN];

bool can[MAXK];

bool isneeded(int x) {
	if(x>=k) return true;
	memset(can,false,sizeof(can)); can[0]=true;
	int skip=-1; REP(i,n) if(a[i]==x&&skip==-1) skip=i;
	REP(i,n) if(i!=skip) for(int j=k-1;j>=0;--j) if(can[j]&&j+a[i]<k) can[j+a[i]]=true;
	//printf("test=%d skip=%d ",x,skip); REP(i,k) printf("%c",can[i]?'V':'x'); puts("");
	REP(i,k) if(can[i]&&i+x>=k) return true;
	return false;
}

void run() {
	scanf("%d%d",&n,&k); REP(i,n) scanf("%d",&a[i]); sort(a,a+n);
	int l=-1,h=n; // (l,h]
	while(l+1<h) {
		int m=l+(h-l)/2;
		if(isneeded(a[m])) h=m; else l=m;
	}
	int nneeded=n-h;
	printf("%d\n",n-nneeded);
}

int main() {
	run();
	return 0;
}


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

arr=[]
for i in range(n+1):
  if i==0:
    arr.append(0)
  else:
    arr.append(arr[i-1]+L[i-1])

ans=0
for i in range(n+1):
  if arr[i]<=x:
    ans+=1
  else:
    break
print(ans)

  
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define bit(n) (1<<(n))
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template < typename T > string tost( const T& n ) { ostringstream stm; stm << n; return stm.str();}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
int const INF = 1001001001;


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

int N,M; cin >> N >> M;
vl A(N);
rep(i,N) cin >> A[i];

ll ans = 0;
rep(i,N) ans += A[i];

priority_queue<ll> pq;
rep(i,N) pq.push(A[i]);
rep(i,M) {
    ll cur = pq.top();
    pq.pop();
    ans -= cur;
    pq.push(cur/2);
    ans += cur/2;
}

cout << ans << endl;
return 0;
}

Measured memory_bytes: 2168
import math
def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
N,M=map(int,input().split())
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
if N==1:
  print(M)
else:
  ans=0
  a=M//N
  v=make_divisors(M)
  for i in range(a,0,-1):
    if M%i==0:
      print(i)
      break

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

#include <fstream>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  /*
  ifstream in("input.txt");
  cin.rdbuf(in.rdbuf());
  //*/
  long long N, K;
  cin >> N >> K;
  vector<long long> tele(N);
  vector<bool> itta(N);
  for(int i = 0; i < N; i++){
    cin >> tele[i];
    tele[i]--;
  } 
  vector<long long> junban;
  int k = 0;
  int cnt = 0;
  for(cnt; cnt < K; cnt++){
    if(cnt == K - 1){
      cout << tele[k] + 1 <<endl;
      return 0;
    }
    if(itta[k]){
      break;
    }
    itta[k] = true;
    junban.emplace_back(k);
    k = tele[k];
  }
  int start;
  for(int i = 0; i < junban.size(); i++){
    if(junban[i] == k){
      start = i;
      break;
    }
  }
  K -= cnt;
  int roop = junban.size() - start;
  int nokori = K % roop;
  //cout << start <<  " " << junban.size() << " " << roop << " " << nokori <<endl;
  /*
  for(auto x: junban){
    cout << x << " ";
  }
  cout <<endl;
  //*/
  cout << junban[start + nokori] + 1 <<endl;
}


Measured memory_bytes: 6904
#include<bits/stdc++.h>
#define int long long
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bug1( x ) {cerr << (#x) <<"="<< x << endl;}
#define bug2( x , y ) {cerr << (#x) <<"="<< (x) << "    " << (#y) << "="<< (y) << endl;}
#define bug3( x , y , z ) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << endl;}
#define bug4( x , y , z , w) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << endl;}
#define bug5( x , y , z , w ,p) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << endl;}
#define bug6( x , y , z , w ,p , q) {cerr << (#x) <<"="<<(x) << "    " << (#y) <<"="<< (y) << "    " << (#z) <<"="<< (z) << "    " << (#w) <<"="<< w << "    " << (#p) <<"="<< p << "    " << (#q) <<"="<< q << endl;}
#define bugn( x , n ) {cerr << (#x) <<":";for(int i=0;i<n;i++)cerr << x[i] <<"  "; cerr << endl;}
#define bugnm( x , n , m ) {cerr << (#x)<<endl;for(int i=0;i<n;i++){cerr << "Row #" << i<< ":";for(int j=0;j<m;j++)cerr << x[i][j] << "   ";cerr << endl;}}
typedef long long ll;
typedef long double ld;
using namespace std;



const int maxn = 2000+5;
int dp[maxn][maxn];
vector<pair<int,int>>a;
int n;
int solve(int l,int r){
	if( l + r == n )return 0;
	int &ans = dp[l][r];
	if( ans != -1 )return ans;
	ans = 0;
	int i = n - (l + r) - 1;
	ans = max( ans , a[i].first * abs( a[i].second - l ) + solve(l+1,r) );
	ans = max( ans , a[i].first * abs( a[i].second - (n - r -1) ) + solve(l,r+1) );
	return ans;
}
int32_t main(){
	IOS
	cin>>n;
	a = vector<pair<int,int>>(n);
	for(int i = 0 ; i < n ; i++ ){
		cin >> a[i].first; a[i].second = i;
	}
	sort(a.begin(),a.end());
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0);
}
/*
 * long long or int?
 * index out of bound? 
 * Tested on own test case?corner?
 * Make more general solution.
 * Read Read Read Read ....
 */


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

using i64 = int64_t;

constexpr i64 INF = (1ll<<31) - 1;

template <typename T, typename E>
class SegmentTree {
  private:
    int n;
    vector<T> node;
    const function<T (T, T)> query_func;
    const function<T (T, E)> update_func;
    const T identity;

  public:

    SegmentTree() = default;

    SegmentTree(int size, function<T(T, T)> query_func,
                function<T(T, E)> update_func, T identity,
                vector<T> v = vector<T>())
            : query_func(query_func), update_func(update_func), identity(identity) {
        n = 1;
        while(n < size) n *= 2;
        node.resize(2*n-1, identity);
        if(size == v.size()) build(size, v);
    }

    void build(int size, vector<T> v) {
        for(int i=0;i<size;++i) node[i+n-1] = v[i];
        for(int i=n-2;i>=0;--i) node[i] = query_func(node[2*i+1], node[2*i+2]);
    }

    void update(int x, E val) {
        x += n - 1;

        node[x] = update_func(node[x], val);
        while(x > 0) {
            x = (x - 1) / 2;
            node[x] = query_func(node[2*x+1], node[2*x+2]);
        }
    }

    T query(int a, int b, int k=0, int l=0, int r=-1) {
        if(r < 0) r = n;

        if(r <= a || b <= l) return identity;

        if(a <= l && r <= b) return node[k];

        int vl = query(a, b, 2*k+1, l, (l+r)/2);
        int vr = query(a, b, 2*k+2, (l+r)/2, r);
        return query_func(vl, vr);
    }
};

int main(){
    int n, q;
    cin >> n >> q;
    SegmentTree<i64, i64> st(n+1,
        [](i64 a, i64 b){return a+b;},
        [](i64 a, i64 b){return a+b;},
        0
    );
    for(int i=0;i<q;++i){
        int com, x, y;
        cin >> com >> x >> y;
        if(com == 0){
            st.update(x, y);
        }else{
            cout << st.query(x, y+1) << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 4940
#include <bits/stdc++.h>
using namespace std;
#define rep(i,c) for(int i=0;i<c;++i)
int  main(){
  int a,b;
  cin >> a>> b;
  vector<int> d(a);
  int count =0;
  int yon = 0;
  rep(i,a){
    cin >> d[i];
    count +=d[i];
  }
  for(int i= 0;i<d.size();i++){
    if(d[i]*4*b>=count){
      yon++;
    }
  }
    if(yon>=b){
     cout << "Yes" << endl;
  }else{
  cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){int b,r,g,c,s,t;while(cin>>b>>r>>g>>c>>s>>t&&b+r+g+c+s!=0)cout<<100+b*80+r*54+7*g+c*2-(t-s-(b*5)-(r*3))*3<<endl;}

Measured memory_bytes: 1160
import java.util.Scanner;

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

		String s = sc.next();
		int sumWin = 0;
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(i) == 'o')
				sumWin++;
		}

		String ans = sumWin + (15 - s.length()) >= 8 ? "YES" : "NO";
		System.out.println(ans);
		sc.close();
	}

}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

//popcount:count number of bits which are 1
template<typename T>
int popcount(T n)
{
	int res = 0;
	while (n > 0)
	{
		if (n & 1)res++;
		n = n >> 1;
	}
	return res;
}

int h, w, k;
vector<string> s;
vector<vector<int>> sum;

void build_sum()
{
	rep(i, h)rep(j, w)
	{
		sum[i+1][j+1] = int(s[i][j]-'0') + sum[i+1][j]+sum[i][j+1]-sum[i][j];
	}
}

int get_sum(int y_b, int y_e, int x_b, int x_e)
{
	int res = sum[y_e][x_e]-sum[y_e][x_b-1]-sum[y_b-1][x_e]+sum[y_b-1][x_b-1];
	return res;
}

void solve()
{
	cin >> h >> w >> k;
	s.resize(h);
	rep(i, h) cin >> s[i];
	sum = vector<vector<int>>(h+1,vector<int>(w+1,0));
	build_sum();

	int ans = h*w;
	rep(mask, 1 << (h-1))
	{
		vector<int> bord(1, 0);
		rep(j, h-1)if(mask >> j & 1)bord.push_back(j+1);
		bord.push_back(h);
		int cnt = popcount(mask);
		int last_x = 0;
		reps(x, w)
		{
			bool less_than_k = true;
			rep(y, sz(bord)-1)
			{
				int b_b = bord[y];
				int b_e = bord[y+1];
				int white = get_sum(b_b+1,b_e,last_x+1,x);
				if(white > k)less_than_k = false;
			}
			if(!less_than_k && last_x + 1 == x)
			{
				cnt = h*w;
				break;
			}
			else if(!less_than_k)
			{
				cnt++;
				x--;
				last_x = x;
			}
		}
		chmin(ans, cnt);
	}
	cout << ans << endl;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>

struct Point {
    int x, y;
};

std::vector<Point> points;

struct Node {
    int id;
    Node *l, *r;
    Node(int id) : id(id), l(nullptr), r(nullptr){};
};

Node* buildkD(std::vector<int>& ids, int l, int r, int depth) {
    if (l == r) return nullptr;

    if (depth & 1) {
        std::sort(ids.begin() + l, ids.begin() + r,
                  [&](int i, int j) { return (points[i].x != points[j].x ? points[i].x < points[j].x : points[i].y < points[j].y); });
    } else {
        std::sort(ids.begin() + l, ids.begin() + r,
                  [&](int i, int j) { return (points[i].y != points[j].y ? points[i].y < points[j].y : points[i].x < points[j].x); });
    }

    int mid = (l + r) / 2;
    Node* node = new Node(ids[mid]);
    node->l = buildkD(ids, l, mid, depth + 1);
    node->r = buildkD(ids, mid + 1, r, depth + 1);
    return node;
}

std::vector<int> find(int lx, int rx, int ly, int ry, int depth, Node* node) {
    std::vector<int> ret;
    if (node == nullptr || lx > rx || ly > ry) return ret;

    int x = points[node->id].x, y = points[node->id].y;
    if (lx <= x && x <= rx && ly <= y && y <= ry) ret.push_back(node->id);

    if (depth & 1) {  // xでソートされている
        std::vector<int> res = find(lx, std::min(rx, x), ly, ry, depth + 1, node->l);
        std::copy(res.begin(), res.end(), back_inserter(ret));

        res = find(std::max(lx, x), rx, ly, ry, depth + 1, node->r);
        std::copy(res.begin(), res.end(), back_inserter(ret));

    } else {  // yでソートされている
        std::vector<int> res = find(lx, rx, ly, std::min(ry, y), depth + 1, node->l);
        std::copy(res.begin(), res.end(), back_inserter(ret));

        res = find(lx, rx, std::max(ly, y), ry, depth + 1, node->r);
        std::copy(res.begin(), res.end(), back_inserter(ret));
    }
    return ret;
}

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

    int N;
    std::cin >> N;

    points.resize(N);
    for (auto& p : points) std::cin >> p.x >> p.y;

    std::vector<int> ids(N);
    std::iota(ids.begin(), ids.end(), 0);
    Node* root = buildkD(ids, 0, N, 0);

    int Q;
    std::cin >> Q;
    for (int q = 0; q < Q; ++q) {
        int lx, rx, ly, ry;
        std::cin >> lx >> rx >> ly >> ry;

        auto ret = find(lx, rx, ly, ry, 0, root);
        std::sort(ret.begin(), ret.end());

        for (auto i : ret) std::cout << i << '\n';
        std::cout << '\n';
    }
    return 0;
}



Measured memory_bytes: 23564
import math

n=int(input())
x=list(map(int,input().split()))
a=(sum(x)/n)
b1=math.ceil(a)
b2=math.floor(a)

s1=0
s2=0
for i in range(n):
    k1=(x[i]-b1)**2
    k2=(x[i]-b2)**2
    s1+=k1
    s2+=k2
    
if s1<s2:
    print(s1)
else:
    print(s2)

Measured memory_bytes: 9156
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static private int sample = 0;
	static private InputStream in;
	static private PrintStream out;
	static private Scanner sc;
	static {
		if(sample == 0) {
			in = System.in;
			out = System.out;
		}else {
			try {
				in = new FileInputStream(new File("sample"+sample));
				out = new PrintStream("result"+sample);
			} catch (Exception e) {
				e.printStackTrace();
				System.exit(1);
			}
		}
		sc = new Scanner(in);
	}
	static public boolean fileCompare2(String fileA, String fileB) {
		boolean bRet = false;
		try {
			bRet = Arrays.equals(Files.readAllBytes(Paths.get(fileA)), Files.readAllBytes(Paths.get(fileB)));
		} catch (IOException e) {
		}
		return bRet;
	}
	static public void exit() {
		if(sample!=0) {
			out.close();
			String sam = "sample"+sample;
			String ans = "answer"+sample;
			String res = "result"+sample;
			if(fileCompare2(ans, res)) {
				System.out.println("AC");
			}else {
				System.out.println("WA");
				try {
					System.out.println(new String(Files.readAllBytes(Paths.get(ans))));
					System.out.println(new String(Files.readAllBytes(Paths.get(res))));
					System.out.println(new String(Files.readAllBytes(Paths.get(sam))));
				} catch (IOException e) {
				}
			}
		}
		sc.close();
	}
	static public void main(String ...strings ) {
		try {
			final int N = sc.nextInt();
			final int A[] = new int[N];
			final int C[] = new int[N];
			for(int i=0;i<N;i++) {
				A[i] = sc.nextInt();
			}
			int color = 1;
			C[0] = A[0];
			for(int i=1;i<N;i++) {
				boolean ok = false;
				if(C[color-1] < A[i]) {
					for(int c=0;c<color;c++) {
						if(C[c] < A[i]) {
							C[c] = A[i];
							ok=true;
							break;
						}
					}
				}
				if(!ok) {
					C[color] = A[i];
					color++;
				}
			}
			out.println(color);
		} finally {
			exit();
		}
	}
}


Measured memory_bytes: 59712
package main

import (
	"fmt"
	"bufio"
	"os"
	"strings"
	"strconv"
	"reflect"
	"sort"
)

func showType(obj interface{}){
	v:=reflect.ValueOf(obj)
	fmt.Println(v.Type())
}

func main(){
	//stdinから読み込み
	sc:=bufio.NewScanner(os.Stdin)
	//1行読み込む(Splitの設定が1行になっているため)
	//scanner.Split(bufio.ScanWords) // 1単語ごと
	//scanner.Split(bufio.ScanLines) // 1行ごと（デフォルト）と変更可能
	sc.Scan()

	//読み込み
	line:=sc.Text()

	//エラー処理
	if err:=sc.Err();err!=nil{
		fmt.Println("fail to read stdio")
	}

	//"1 23 4" -> ["1","23","4"]
	var str_num_slice []string =strings.Split(line," ")

	num_slice:=make([]int,0)

	//rangeで回すと暗黙にintになっている
	for _,s:=range(str_num_slice){
		temp,err:=strconv.Atoi(s)
		if err!=nil{
			fmt.Println("there are not int string.")
			os.Exit(1)
		}
		num_slice=append(num_slice,temp)
	}

	sort.Ints(num_slice)

	for idx,num :=range num_slice{
		fmt.Print(num)
		if idx!=len(num_slice)-1{
			fmt.Print(" ")
		}else{
			fmt.Print("\n")
		}
	}

}


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


main() {
  int n;cin>>n;
  int L[n];rep(i,n) cin>>L[i];
  sort(L,L+n);
  int ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<i;j++){
      for(int k=0;k<j;k++){
        if(L[i]!=L[j] && L[j]!=L[k] && L[k]+L[j]>L[i]){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxN = 2e5+7;
const int maxV = 90010;
//const int INF = 1e9+9;
const ll INF = (1ll)<<60;
const int MOD = 1e9+7;

int m,k;
int main()
{
	scanf("%d%d",&m,&k);
	int ans = k;
	if(m<=12 && m>=6)
		ans = k/2;
	else if(m<6)
		ans = 0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repr(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define reprrev(i,a,b) for(int i=b-1;i>=a;i--) // [a, b)
#define reprev(i,n) reprrev(i,0,n)
typedef long long ll;
typedef unsigned long long ull;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    cin.tie(0);
    ios::sync_with_stdio(false);<- これら、printfとかと併用しない方が良さそう

*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n==0) return 1;
    ll res=modpow(x, n/2);

    if(n%2==0) return res*res%mod;
    else return res*res%mod*x%mod;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };


// 線分 ab の偏角 返り値は[-π, π]
double argument(const pair<double, double> &a, const pair<double, double> &b){
    double ax=a.first, ay=a.second, bx=b.first, by=b.second;
    return atan2(by-ay, bx-ax);
}

/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */
/* <-----------------------------------------------------------------------------------> */

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
 
  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

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

    ll n; cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());
    vector<mint> two(n+1);
    two[0] = 1;
    rep(i, n) two[i+1] = two[i]*2;
    mint ans = 0;
    rep(i, n) {
        int l = i, r = n - 1 - i;
        mint now = two[r];
        if(r != 0) now += two[r-1]*r;
        now *= two[l];
        now *= a[i];
        ans += now;
    }
    ans *= two[n];
    cout << ans.x << endl;

    return 0;
}


Measured memory_bytes: 2560
MOD = 1000000007

def solve(n,k):
	ans = (n*k - k*k + 1)%MOD
	return ans

n, k = list(map(int,input().strip().split()))

n +=1 

output = 0

for i in range(k,n+1):
	output = (output + solve(n,i))%MOD
print(output)



Measured memory_bytes: 9180
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	for(int n;cin>>n,~n;){
		int mv[8][9]={},mh[9][8]={};
		rep(_,n){
			char c; int x,y; cin>>c>>x>>y;
			if(c=='x') mh[y][x]=1;
			if(c=='y') mv[y][x]=1;
		}
		int cx=3,cy=1,dx=1,dy=1;
		for(;;){
			if(cx%4==0){
				if(mv[cy/4][cx/4])
					dx*=-1;
				else if(cx==0 || cx==32)
					break;
			}
			else if(cy%4==0){
				if(mh[cy/4][cx/4])
					dy*=-1;
				else if(cy==0 || cy==32)
					break;
			}
			cx+=dx,cy+=dy;
			if(cx==3 && cy==1)
				break;
		}
		cout<<cx*25<<' '<<cy*25<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
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 r: i32 = read();
    let d: i32 = read();
    let mut x: i32 = read();
    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define debugg(x) cout<<#x <<":"<< x << endl;
typedef  long long ull;
using namespace std;
#define  INF 1e9
int main()
{
    int N;
    cin >> N ;
    int T[N+5][3];
    for(int i=0 ; i<N ; i++)
    {
        for(int j=0 ; j<3 ; j++)
        {
            cin >>T[i][j];
        }
    }
    int dp[N+5][3];
    dp[0][0]= T[0][0];
    dp[0][1]= T[0][1];
    dp[0][2]= T[0][2];
    for(int i=1 ; i<N ; i++)
    {

        for(int j=0 ; j<3 ; j++)
        {
            int maxi = -INF;
            for(int k=0 ; k<3 ; k++)
            {
                if(k != j)
                {
                   int res1 = T[i][j]+dp[i-1][k];
                   if(maxi < res1)
                   {
                       maxi = res1;
                   }
                }
            }
            dp[i][j]=maxi ;

        }
    }
    cout << max((max(dp[N-1][0] , dp[N-1][1] )) , dp[N-1][2]) << endl ;


    return 0;
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  vector<int> b(m);
  for(int i = 0; i < m; i++){
    cin >> a.at(i) >> b.at(i);
  }
  vector<int> c(n);
  for(int i = 0; i < m; i++){
    if(a.at(i) == 1){
      c.at(b.at(i))++;
    }
    if(b.at(i) == n){
      c.at(a.at(i))++;
    }
  }
  bool flag = false;
  for(int i = 0; i < n; i++){
    if(c.at(i) >= 2){
      flag = true;
    }
  }

  if(flag){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
}


Measured memory_bytes: 2560
package main

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

// Monster .
type Monster struct {
	x int
	h int
}

// Monsters .
type Monsters []Monster

func (m Monsters) Len() int {
	return len(m)
}

func (m Monsters) Less(i, j int) bool {
	return m[i].x < m[j].x
}

func (m Monsters) Swap(i, j int) {
	m[i], m[j] = m[j], m[i]
}

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return a
}

func main() {
	sc.Split(bufio.ScanWords)
	var n, d, a int
	fmt.Scan(&n, &d, &a)

	monsters := make([]Monster, n)
	for i := 0; i < n; i++ {
		x, h := nextInt(), nextInt()
		monsters[i] = Monster{x, h}
	}
	sort.Sort(Monsters(monsters))

	im := make([]int, n+1)
	ans := 0
	for i := 0; i < n; i++ {
		m := monsters[i]
		if im[i] < m.h {
			tmp := monsters[i:]
			id := sort.Search(len(tmp), func(i int) bool {
				return m.x+d*2 < tmp[i].x
			}) + i
			c := (m.h - im[i] + a - 1) / a
			im[i] += c * a
			im[id] -= c * a
			ans += c
		}
		im[i+1] += im[i]
	}

	fmt.Println(ans)
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, ans = 0;
  cin >> A >> B >> C;
  if(A + B + C >= 22){
  cout << "bust" << endl;
  }
  if(A + B + C <=21){
  cout << "win" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=200010;
const ll mod=1e9+7;

int main(){
  string s;
  cin >> s;
  s[3] = '8';

  cout << s << endl; 
  return 0;
}  


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = ReadInt();
            var p = ReadInts();

            var other = 0;
            for (int i = 0; i < n; i++)
            {
                if (p[i]!=i+1)
                {
                    other++;
                }
            }

            if (other == 2 || other == 0)
            {
                WriteLine("YES");
            }
            else
            {
                WriteLine("NO");
            }
        }
    

    private static string Read() { return ReadLine(); }
    private static string[] Reads() { return (Read().Split()); }
    private static int ReadInt() { return int.Parse(Read()); }
    private static long ReadLong() { return long.Parse(Read()); }
    private static double ReadDouble() { return double.Parse(Read()); }
    private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
    private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
    private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }


    public static bool IsPrime(int num)
    {
        if (num < 2) return false;
        else if (num == 2) return true;
        else if (num % 2 == 0) return false;

        double sqrtNum = Sqrt(num);
        for (int i = 3; i <= sqrtNum; i += 2)
        {
            if (num % i == 0)
            {
                return false;
            }
        }
        return true;
    }

    //最大公約数
    public static int Gcd(int a, int b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            var reminder = a % b;
            a = b;
            b = reminder;
        }
        return a;
    }

    //最小公倍数
    public static int Lcm(int a, int b)
    {
        return a * b / Gcd(a, b);
    }

    //文字数を数える
    public static int CountChar(string s, char c)
    {
        return s.Length - s.Replace(c.ToString(), "").Length;
    }
    public static void debuglist(List<int> x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
    public static void debuglist(List<string> x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
    public static void debugarray(int[] x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
    public static void debugarray(string[] x)
    {
        foreach (var item in x)
        {
            WriteLine(item);
        }
    }
}
}


Measured memory_bytes: 11092
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <functional>
#include <math.h>
#include <stdlib.h>
#include <map>
#include <deque>
#include <list>
#include <sys/timeb.h>
#include <fstream>
#include <set>

using namespace std;

#define repr(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repr(i,0,n)
#define reprrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) reprrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define mp make_pair
#define mt make_tuple
#define INF 1050000000
#define INFL 1100000000000000000LL
#define EPS (1e-10)
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> Pi;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<Pi> vPi;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<Pi> > vvPi;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<Pi, vector<Pi>, greater<Pi> > pqlP;
struct Edge {
	int from, to, cost;
	bool operator<(Edge e) {
		return cost < e.cost;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
template <class T>
using vec = vector<T>;
template<class T>
using pql = priority_queue<T, vector<T>, greater<T>>;
string debug_show(Pi a) {
	return "(" + to_string(a.first) + "," + to_string(a.second) + ")";
}

template<class T>
struct augEdge {
	T from, to;
	int cost;
	bool operator<(augEdge e) { return cost < e.cost; }
	bool operator>(augEdge e) { return cost > e.cost; }
};
template<class T>
using augGraph = vector<augEdge<T>>;


bool pairCompare(const Pi& firstElof, const Pi& secondElof)
{
	return firstElof.second > secondElof.second;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	int tmp = 0;
	int ans = 0;
	rep(i, n) {
		int t;
		cin >> t;
		if (t >= tmp) {
			ans++;
			tmp = t;
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        List<Integer> nums = Arrays.asList(sc.nextInt(), sc.nextInt(), sc.nextInt());
        String print = nums.stream().sorted().map(x -> String.valueOf(x)).collect(Collectors.joining(" "));
        System.out.println(print);
        sc.close();
    }
}



Measured memory_bytes: 32208
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
#define ll long long
ll n,a,b;
int main(){
    scanf("%lld%lld%lld",&n,&a,&b);
    if (n>1&&b>=a||n==1&&a==b) printf("%lld\n",(n-2)*(b-a)+1);
        else puts("0");
}

Measured memory_bytes: 3160