akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define mp make_pair
#define All(v) v.begin(),v.end()
#define mod  1000000007
#define write freopen("output.txt","w",stdout)
#define read freopen("street.in","r",stdin)
#define FIO std::ios_base::sync_with_stdio(false);
using namespace std;
typedef pair<int,double> ii;
vector<vector<ii> > v(1005);
int n;
struct circle
{
    int x,y,r;
};
typedef pair<double,int> di;
priority_queue<di,vector<di>,greater<di> > pq;
circle a[1005];
double dist[1005];
void dijkstra()
{
    while(!pq.empty())
    {
        di cur = pq.top();
        pq.pop();

        double d = cur.F;
        
        int u = cur.S;

        if(d > dist[u]) continue;
        for(int i=0; i<v[u].size(); i++)
        {
            ii k = v[u][i];
            if(dist[u] + k.S < dist[k.F])
            {
                dist[k.F] = dist[u] + k.S;
                pq.push(di(dist[k.F],k.F));
            }
        }
    }
}

double get(int i,int j)
{
    double dis = hypot(a[i].x-a[j].x,a[i].y-a[j].y);
    dis -= a[i].r;
    dis -= a[j].r;
    
    if(dis < 0) dis = 0.0;
    
    return dis;
}
int main()
{
    circle tmp;
    cin >> a[0].x >> a[0].y >> tmp.x >> tmp.y;
    a[0].r = tmp.r = 0;
    cin >> n;
    a[n+1] = tmp;
    for(int i=1; i<=n; i++)
    {
        scanf("%d%d%d",&a[i].x,&a[i].y,&a[i].r);
    }
    for(int i=0; i<=n+1; i++)
        for(int j=0; j<=n+1; j++)
            if(i != j)
                v[i].push_back(mp(j,get(i,j)));
                
    for(int i = 0; i<=n+1; i++)
        dist[i] = 1e18 ;
    dist[0] = 0.0;
    pq.push(mp(0.0,0));
    dijkstra();

    printf("%.10f\n",dist[n+1]);

return 0;
}


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

a = []
for i in range(H):
    a.append(input())

#print(a)

row_list = []
col_list = []
for i in range(H):
    for j in range(W):
        if a[i][j] == "#":
            row_list.append(i)
            col_list.append(j)

for i in range(H):
    ans = ""
    for j in range(W):
        if (i in row_list) and (j in col_list):
            ans += a[i][j]
    if(len(ans) > 0):
        print(ans)









Measured memory_bytes: 3316
import java.util.*;

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

int N=sc.nextInt();
int B=sc.nextInt();
int C=sc.nextInt();
  if(C<=B/N){
	System.out.println(C);  
  }else{
  System.out.println(B/N);
  }
}
}

Measured memory_bytes: 23764
#include<iostream>
using namespace std;
int main(){
  int n,m;
  while(cin >>n>>m,n||m){
    int ans=0,time=9999,diff=9999;
    bool flag = false;
    for(int i=0,a; i<n; i++){
      cin >>a;
      if(time>(m/a)*a){
	time = (m/a)*a;
	diff = a;
	flag = false;
	ans = i+1;
      }
      else if(time == (m/a)*a){
	if(diff>a){
	  diff = a;
	  flag = false;
	  ans = i+1;
	}
	else if(diff == a) flag = true;
      }
    }
    if(flag) cout <<n<<endl;
    else cout <<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1156
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
using namespace std;
typedef long long ll;
const double PI = acos(-1.0);

int main()
{
    int k, s;
    cin >> k >> s;

    int res = 0;
    for (int i = 0; i <= k; i++) {
        for (int j = i; j <= k; j++) {
            for (int l = j; l <= k; l++) {
                if (i + j + l == s) {
                    if (i == j && j == l) {
                        res++;
                    }
                    else if (i == j || j == l || l == i) {
                        res += 3;
                    }
                    else {
                        res += 6;
                    }
                }
            }
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c;
  cin>>a>>b>>c;
  vector<int> mods(0);
  for(int i=1;i>0;i++){
    int mod=(a*i)%b;
    if(mod==c){
      cout<<"YES"<<endl;
      return 0;
    }else{
      for(int j=0;j<mods.size();j++){
        if(mods.at(j)==mod){
          cout<<"NO"<<endl;
          return 0;
        }
      }
      mods.push_back(mod);
    }
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
	Scanner scan = new Scanner(System.in);
	int n = scan.nextInt();
	double money = 100;
	for (int i = 0; i < n; i++) {
	    money *= 1.05;
	    money = Math.ceil(money);
	}
	System.out.println((int)money * 1000);
    }
}

Measured memory_bytes: 26284
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
// ============ template finished ============

int main()
{
    ll A;
    string Bd;
    cin >> A >> Bd;
    ll B = (Bd[0] - '0') * 100 + (Bd[2] - '0') * 10 + (Bd[3] - '0');
    ll res = A * B / 100;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define rep3(i, s, n, a) for (int i = (s); i < (int)(n); i += a)
#define rep2(i, s, n) rep3(i, s, n, 1)
#define rep(i, n) rep2(i, 0, n)

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

int main(){
    string s;
    cin >> s;
    int len = s.size();
    int cnt=0;
    rep(i, len/2){
        if(s[i]!=s[len-i-1]){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 3628
#include  <iostream>

using namespace std;

int main()
{
	int a, b;
	double k;
	cin >> a >> b;
	k = double(a + b) / 2;
	int k2;
	k2 = static_cast <int> (k);
	if (k2 - k == 0)  cout << k2 << endl;
	else  cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8')
inf = float('inf') ;mod = 10**9+7
mans = inf ;ans = 0 ;count = 0 ;pro = 1

s = input()
if s == "ABC":
  print("ARC")
else:
  print("ABC")

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

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


int main() {
  int n, k;
  cin >> n >> k;
  vector<int> p(n);
  rep (i, n) {
    cin >> p[i];
  }
  sort(p.begin(), p.end());

  int count = 0;
  rep (i, k) {
    count += p[i];
  }
  cout << count << endl;
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i ++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i ++)
#define MP make_pair

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;

const int MOD = 1000003;

int fac[1000003];
int power(int x, int t)
{
	int ret = 1;
	while(t > 0) {
		if(t & 1) ret = 1LL * ret * x % MOD;
		x = 1LL * x * x % MOD;
		t >>= 1;
	}
	return ret;
}

void gen_fac()
{
	fac[0] = 1;
	rep1(i, MOD - 1) fac[i] = 1LL * fac[i - 1] * i % MOD;
}

int itv_prod(int l, int r)
{
	if(l / MOD != r / MOD) return 0;
	
	return 1LL * fac[r] * power(fac[l], MOD - 2) % MOD;
}

int main()
{
	gen_fac();
	
	int q;
	scanf("%d", &q);
	
	while(q --) {
		int x, d, n;
		scanf("%d%d%d", &x, &d, &n);
		if(d == 0) printf("%d\n", power(x, n));
		else {
			int nl = (1LL * x * power(d, MOD - 2) + MOD - 1) % MOD;
			int nr = nl + n;
			
			printf("%d\n", 1LL * power(d, n) * itv_prod(nl, nr) % MOD);
		}
	}
	return 0;
}

Measured memory_bytes: 4736
# -*- coding: utf-8 -*-

import sys
import copy

input = sys.stdin.readline

# ---------------------------------------------------------

from itertools import permutations

A = [int(input().rstrip()) for _ in range(5)]

ans = 1000000000000000000

for B in list(permutations(A)):
    sum = 0
    for i in range(5):
        sum += B[i]
        if (i < 4):
            sum += (10 - sum % 10) % 10
    ans = min(ans, sum)

print(ans)


Measured memory_bytes: 3444
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop;

immutable long INF = 1L << 59;

void main() {
    auto N = readln.chomp.to!int;
    auto A = readln.split.map!(to!long).array;
    
    auto source = N;
    auto sink = N+1;
    auto ff = new FordFulkerson(N+2, source, sink);

    foreach (i; 0..N) {
        if (A[i] >= 0) {
            ff.add_edge(source, i, 0);
            ff.add_edge(i, sink, A[i]);
        } else {
            ff.add_edge(source, i, -A[i]);
            ff.add_edge(i, sink, 0);
        }

        for (int j = (i+1)*2; j <= N; j += i+1) {
            ff.add_edge(i, j-1, INF);
        }
    }

    writeln(A.map!(a => max(a, 0)).sum - ff.run);
}



class FordFulkerson {
    int N, source, sink;
    int[][] adj;
    long[][] flow;
    bool[] used;

    this(int n, int s, int t) {
        N = n;
        source = s;
        sink = t;
        assert (s >= 0 && s < N && t >= 0 && t < N);
        adj = new int[][](N);
        flow = new long[][](N, N);
        used = new bool[](N);
    }

    void add_edge(int from, int to, long cap) {
        adj[from] ~= to;
        adj[to] ~= from;
        flow[from][to] = cap;
    }

    long dfs(int v, long min_cap) {
        if (v == sink)
            return min_cap;
        if (used[v])
            return 0;
        used[v] = true;
        foreach (to; adj[v]) {
            if (!used[to] && flow[v][to] > 0) {
                auto bottleneck = dfs(to, min(min_cap, flow[v][to]));
                if (bottleneck == 0) continue;
                flow[v][to] -= bottleneck;
                flow[to][v] += bottleneck;
                return bottleneck;
            }
        }
        return 0;
    }

    long run() {
        long ret = 0;
        while (true) {
            foreach (i; 0..N) used[i] = false;
            long f = dfs(source, long.max);
            if (f > 0)
                ret += f;
            else
                return ret;
        }
    }
}

Measured memory_bytes: 380
#include <cstdio>
#include <vector>
#include <utility>
#include <algorithm>

using namespace std;

vector<int> Heap;

void insert(int node)
{
	Heap.push_back(node);
}

void Max_Heapify(int node)
{
	int l = node * 2;
	int r = node * 2 + 1;

	int largest;

	if (l < Heap.size())
	{
		if (Heap[node] < Heap[l])
		{
			largest = l;
		}
		else
		{
			largest = node;
		}
	}
	else
	{
		largest = node;
	}

	if (r < Heap.size())
	{
		if (Heap[largest] < Heap[r])
		{
			largest = r;
		}
	}

	if (largest != node)
	{
		swap(Heap[largest], Heap[node]);

		Max_Heapify(largest);
	}
}

int main()
{
	int N; scanf("%d", &N); Heap.push_back(0);

	int tmp;

	for (int i = 1; i <= N; i++)
	{
		scanf("%d", &tmp);

		insert(tmp);
	}

	for (int i = N / 2; i >= 1; i--)
	{
		Max_Heapify(i);
	}

	for (int i = 1; i <= N; i++)
	{
		printf(" %d", Heap[i]);
	}

	printf("\n");
	
	return 0;
}

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

using namespace std;


int main() {
  
     int n,m,c,sum=0;
     scanf("%d%d%d",&n,&m,&c);
    
     int b[m],a[n][m];
     int i,j,cnt=0;
  
    for(i=0;i<m;++i)
         scanf("%d",&b[i]);
         
      
   
  
   for(i=0;i<n;++i)
   {
     sum=c;
     for(j=0;j<m;++j)
     {
         scanf("%d",&a[i][j]);
       sum+=(a[i][j]*b[j]);
     }
     if(sum>0)
         cnt++;
   }
  
  printf("%d",cnt);
    
   
    	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<set>
#include<algorithm>

using namespace std;

int main(){
    int num_query,command,val,val2;
    scanf("%d",&num_query);
    multiset<int> int_set;
    multiset<int>::iterator itr;
    
    for(int i = 0;i < num_query;i++){
        scanf("%d %d",&command,&val);
        if(command == 0){
            int_set.insert(val);
            printf("%d\n",(int)int_set.size());
        }else if(command == 1){
            int counter = int_set.count(val);
            printf("%d\n",counter);
        }else if(command == 2){
            int_set.erase(val);
        }else if(command == 3){
            scanf("%d",&val2);
            itr = int_set.lower_bound(val);
            while(int_set.end() != itr && *itr <= val2){
                printf("%d\n",*itr);
                itr++;
            }
        }
    }
    
    return 0;
}


Measured memory_bytes: 11940
import sys
sys.setrecursionlimit(10**6)

def MI(): return map(int, input().split())

N,Q=MI()
Edge=[[] for _ in range(N)]
Point=[0]*N

for i in range(N-1):
  a,b=MI()
  Edge[a-1].append(b-1)
  Edge[b-1].append(a-1)

for i in range(Q):
  p,x=MI()
  Point[p-1]+=x

def dfs(now,pre=-1):
  for nxt in Edge[now]:
    if nxt==pre:
      continue
    Point[nxt]+=Point[now]
    dfs(nxt,now)
dfs(0)
print(*Point)

Measured memory_bytes: 283160
import java.io.PrintStream;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    public static void main(String[] args) {
        char BLACK = '#';
        char WHITE = '.';
        int N = ni();
        char[] c = ns().toCharArray();
        
        int[] count = new int[N+1];
        
        // all while
        for (int i = 0; i < N; i++) {
            if (c[i] == BLACK)
                count[N]++;
        }
        
        for (int i = N-1; i >= 0; i--) {
            if (c[i] == BLACK) {
                count[i] = count[i+1] - 1;
            } else {
                count[i] = count[i+1] + 1;
            }
        }
        
        so.println(IntStream.of(count).min().getAsInt());
    }

    static int ni() {
        return sc.nextInt();
    }

    static long nl() {
        return sc.nextLong();
    }

    static String ns() {
        return sc.next();
    }

    static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    static int[] nints(int n) {
        return nints(n, 0, 0);
    }

    static int[] nints(int n, int padHead, int padTail) {
        int[] a = new int[padHead + n + padTail];
        for (int i = 0; i < n; i++)
            a[padHead + i] = ni();
        return a;
    }
}


Measured memory_bytes: 30420
#include <cstdio>  
#include <algorithm>  
#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
using namespace std;
int main()
{
	int  x, y;
	while (~scanf("%d%d", &x, &y))
	{
		if (x%y==0)
			cout << -1 << endl;
		else
			cout << x << endl;
	}
	return 0;
}

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

ll f(ll a, ll b) {
  if (a == b)
    return a;
  return abs(a - b);
}

int main() {
  int n;
  cin >> n;
  int m = 1 << n;
  vector<ll> a(m);
  for (int i = 0; i < m; i++)
    cin >> a[i];
  while (a.size() > 1) {
    vector<ll> b;
    for (int i = 0; i < m; i += 2) {
      b.push_back(f(a[i], a[i + 1]));
    }
    a = b;
    m >>= 1;
  }
  cout << a[0] << endl;
  return 0;
}

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

using namespace std;

// #define int long long

bool codejam = 0;

typedef long long li;
typedef long double ld;

void solve();

int32_t main () {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(20);
	#ifdef LOCAL
		freopen("input.txt", "r", stdin);
	#endif
	int t = 1;
	// int t; 
	// cin >> t;
	int tt = t;
	while (t--) { 
		if (codejam) cout << "Case #" << tt - t << ": ";
		solve();
	}
	return 0;
}

void solve() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	cout << a[0] + a[1];
}	
 	

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int i = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int i = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define MP make_pair
#define pb push_back
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1 << 30;
const ll LINF = 1LL << 61;
const int MOD = 1e9 + 7;

int main() {
    int A, B, C;
    cin >> A >> B >> C;
    if(A + B >= C) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, a, b) for(int i=a; i<b; i++)
#define repi(i, a, b) for(int i=a; i>b; i--)
#define db(x) (cerr << #x << ": " << x << '\n')
#define sync ios_base::sync_with_stdio(false), cin.tie(NULL)
#define ll long long
#define mp make_pair
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define sz size()
#define all(v) (v).begin(), (v).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll, ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define vvi vector<vi>
#define fi first
#define se second
#define umap unordered_map
#define umapi umap<int, int>
#define mapi map<int, int>
#define uset unordered_set
#define useti uset<int>
#define seti set<int>
#define pqueue priority_queue
#define si(a) scanf("%d", &a)
#define sll(a) scanf("%lld", &a)
#define bitcount(x) __builtin_popcount(x)
#define cps CLOCKS_PER_SEC
#define PI acos(-1.0)
#define EPS 1e-9
#define mod 1000000007
#define MOD 1000000007
#define N 
using namespace std;

template<typename T>
using maxpq = priority_queue<T, vector<T>, greater<T>>;

template<typename T>
using minpq = priority_queue<T>;

main()
{	
	#ifndef ONLINE_JUDGE
//		freopen("C:\\Users\\HP\\Desktop\\input.txt", "r", stdin);
//		freopen("C:\\Users\\HP\\Desktop\\output.txt", "w", stdout);
	#endif
	
	clock_t clk = clock();
	
	string s;
	cin >> s;
	int i = 0;
	for(char c : s) {
		i += c == '+';
		i -= c == '-';
	}
	cout << i << '\n';
	
	cerr << double(clock() - clk) * 1000.0 / cps << '\n';
}








Measured memory_bytes: 256
def main():
    n, h, w = [int(i) for i in input().split()]
    # print(n, h, w)
    # alloys = []
    count = 0
    for i in range(n):
        a, b = [int(i) for i in input().split()]
        if a >= h and b >= w:
            count += 1
    print(count)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
s=[2]
a=[int(i) for i in range(2,10000) if pow(2 ,int(i)-1, int(i)) ==1]

while a!=[]:
    t=a[0]
    a=[i for i in a if i % t !=0]
    s.append(t)

n=int(input())
x=0
for i  in range(n):
    y=0
    t = int(input())
    for j in s:
        if t % j ==0 and t !=j:
           break
    else:
        x+=1
print(x)

Measured memory_bytes: 7788
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
using namespace std;

int InsertionSort(vector<int>& Array, int N, int g)
{
  	int count = 0;
  	for(int i = g; i< N;i++)
    {
    	int tmp = Array[i];
	  	int j = i -g;
      	while(j>=0 && Array[j] > tmp)
        {
          	Array[j+g] = Array[j];
          	j = j-g;
          	count++;
        }
    	Array[j+g] = tmp;
    }
  	return count;
}

void ShellSort(vector<int> Array, int N)
{
  	int count=0;
  	vector<int> G;
  	G.push_back(1);
  	int g=G[0];
  	while(N > g*3+1)
    {
      g=g*3+1;
      G.push_back(g);
    }
  	int m = G.size();
  	for(int i=m-1;i>=0;i--)
    {
      count+=InsertionSort(Array, N, G[i]);
    }
  	cout << m << endl;
  	for(int i=m-1;i>0;i--) cout << G[i] << " ";
  	cout << G[0] << endl;
  	cout << count << endl;
  	for(int i=0;i<N;i++) cout << Array[i] << endl;
}

vector<string> split(const string &s, char delim) {
    vector<string> elems;
    string item;
    for (char ch: s) {
        if (ch == delim) {
            if (!item.empty())
                elems.push_back(item);
            item.clear();
        }
        else {
            item += ch;
        }
    }
    if (!item.empty())
        elems.push_back(item);
    return elems;
}

bool compare_by_b(pair<int, int> a, pair<int, int> b) {
    if(a.second != b.second){
        return a.second > b.second;
    }else{
        return a.first > b.first;
    }
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n,q;
  	cin >> n >> q;
  	queue< pair<string, long> > p;
	//vector<long> A(N);
  	int idx = 0;
  	//while(cin >> A[idx]) idx++;
  	string name;
  	long time;
  	while(cin >> name >> time)
    {
      p.push(make_pair(name, time));
      idx++;
    }
  	time = 0;
  	while(!p.empty())
    {
      if(p.front().second <= q)
      {
        cout << p.front().first << " " << time + p.front().second << endl;
        time+=p.front().second;
        p.pop();
      }else
      {
        pair<string, long> tmp = p.front();
        tmp.second -= q;
        p.pop();
        p.push(tmp);
        time+=q;
      }
    }
  	return 0;
}



Measured memory_bytes: 6312
n = input()
A = [raw_input() for i in xrange(n)]

R = [sum(e[j] == '#' for j in xrange(n)) for e in A]
C = [sum(A[j][i] == '#' for j in xrange(n)) for i in xrange(n)]

c_need = sum(e < n for e in C)

INF = 10**9+7
ans = INF
for i in xrange(n):
    if R[i] == C[i] == 0:
        continue
    if C[i] == 0:
        ans = min(ans, n-R[i] + c_need + 1)
    else:
        ans = min(ans, n-R[i] + c_need)
print -1 if ans == INF else ans


Measured memory_bytes: 2948
#include <stdio.h>

using namespace std;

int main(){
	int m,f,r;
	char grade;
	while(true){
		scanf("%d %d %d",&m,&f,&r);
		if(m == -1 && f == -1 && r == -1) break;
		if(m == -1 || f == -1){
			grade = 'F';
		}else if(m+f >= 80){
			grade = 'A';
		}else if(m+f >= 65){
			grade = 'B';
		}else if(m+f >= 50){
			grade = 'C';
		}else if(m+f >= 30){
			grade = (r >= 50)? 'C':'D';
		}else{
			grade = 'F';
		}
		printf("%c\n",grade);
	}
}



Measured memory_bytes: 2688
import java.io.*;
import java.io.BufferedReader; 
import java.io.IOException; 
import java.io.InputStreamReader; 
import java.util.StringTokenizer; 
import java.util.*;


public  class Main 
{

	   
	   static class FastReader 
	    { 
	        BufferedReader br; 
	        StringTokenizer st; 
	       
	  
	        public FastReader() 
	        { 
	            br = new BufferedReader(new
	                     InputStreamReader(System.in)); 
	        } 
	  
	        String next() 
	        { 
	            while (st == null || !st.hasMoreTokens()) 
	            { 
	                try
	                { 
	                    st = new StringTokenizer(br.readLine()); 
	                } 
	                catch (IOException  e) 
	                { 
	                    e.printStackTrace(); 
	                } 
	            } 
	            return st.nextToken();
	            
	        } 
	  
	        int nextInt() 
	        { 
	            return Integer.parseInt(next()); 
	        } 
	  
	        long nextLong() 
	        { 
	            return Long.parseLong(next()); 
	        } 
	  
	        double nextDouble() 
	        { 
	            return Double.parseDouble(next()); 
	        } 
	  
	        String nextLine() 
	        { 
	            String str = ""; 
	            try
	            { 
	                str = br.readLine(); 
	            } 
	            catch (IOException e) 
	            { 
	                e.printStackTrace(); 
	            } 
	            return str; 
	        }

			public Character charAt(int i) {
				// TODO Auto-generated method stub
				return null;
			} 
	    } 

  

	  // Complete the hurdleRace function below.
//    public static void solve() {
//    	FastReader s=new FastReader();

   
    public static void main(String[] args) throws IOException {
    	FastReader s=new FastReader();
    	long t = s.nextLong();
    	long c=0;
    	if(t<5)System.out.println(0);
    	
    	else {
    		if(t>=500)c=1000*(t/500);
    		t=t%500;
    		if(t>0)c+=(t/5)*5;
    			
       		
    		System.out.println(c);
    		
    	}
    	
    }	
}





        
    

      
 

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

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

	int count = 0;
	int ans = 0;
	rep(i,3){
		if(s[i] == 'R'){
			count++;
			ans = max(ans, count);
		}
		else{
			count = 0;
		} 
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3624
import sys
input = sys.stdin.readline

N, W = map(int, input().split())
w = [0] * N
v = [0] * N
for i in range(N):
    w[i], v[i] = map(int, input().split())
w0 = w[0]
for i in range(N):
    w[i] -= w0
s = sum(w)
dp = [[-1] * (s+1) for _ in range(N+1)]
dp[0] = [0] * (s+1)
for n in range(N):
    for i in range(N)[::-1]:
        for j in range(s-w[n]+1)[::-1]:
            if dp[i][j] == -1:
                continue
            dp[i+1][j+w[n]] = max(dp[i+1][j+w[n]], dp[i][j] + v[n])
ans = 0
for i in range(N+1):
    if W - w0 * i >= 0:
        ans = max(ans, dp[i][min(s, W-w0*i)])
print(ans)


Measured memory_bytes: 42096
n = int(input())
b = list(map(int, input().split()))

a = [0]*(n)

for i in range(len(a)):
  if (i == 0):
    a[i] = b[i]
  elif i == len(a)-1:
    a[i] = b[i-1]
  else:
    a[i] = min(b[i-1], b[i])
    
print(sum(a))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define pii pair <int, int>
#define fi first
#define sc second
#define ALL(x) x.begin(), x.end()
#define RALL(X) x.begin(), x.end()
#define FOR(i, n, k) for(i=0; i<n; i+=k)
#define FO(i, n, k) for(i=1; i<=n; i+=k)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define N 10000007
#define mid ((l+r)/2)
#define dbg(x) (cerr << #x << " : " << x << endl)
#define endl "\n"

using namespace std;

typedef long long int lli;
static const lli  MOD = 1e9 + 7;

lli fact[N];
lli inv_fact[N];
lli inv[N];

lli c(lli a, lli b){
	return (((fact[a] * inv_fact[b]) % MOD) * inv_fact[a-b]) % MOD;
}

int main(){
	ios_base::sync_with_stdio(false);

	inv[0] = inv[1] = 1;
	for(lli i = 2; i < N; ++i)
    	inv[i] = (MOD - (MOD/i) * inv[MOD%i] % MOD) % MOD;

    fact[0] = inv_fact[0] = fact[1] = inv_fact[1] = 1;

    for(lli i=1; i<N; i++){
    	fact[i] = (i * fact[i-1]) % MOD;
    	inv_fact[i] = (inv[i] * inv_fact[i-1]) % MOD;
	}

	lli n, k;
	cin >> n >> k;
	lli r = n-k;
	lli b = k;

	for(lli i=1; i<=k; i++){
		if(i > r+1) cout << 0 << endl;
		else cout << ((c(r+1, i) * c(b-1, i-1)) % MOD) << endl;
	}

	return 0;
    
}

Measured memory_bytes: 234624
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

int main(){
    ll n; string s;
    cin >> n >> s;
    vector<vector<ll>> cnt(11, vector<ll>(n, 0));
    for(ll i = s.length()-1; i >= 0; --i){
        rep(j, cnt.size()-1){
            if(i == s.length()-1) break;
            cnt[j][i] = cnt[j][i+1];
        }
        cnt[s[i]-'0'][i]++;
        for(ll j = 0; j < cnt.size()-1; ++j) if(cnt[j][i] > 0) cnt[10][i]++;
    }

    ll total = 0;
    for(ll i = 0; i < 10; ++i){
        size_t index1 = s.find('0'+i);
        if(index1 == string::npos) continue;
        for(ll j = 0; j < 10; ++j){
            size_t index2 = s.find('0'+j, index1+1);
            
            if(index2 != string::npos && index2+1 != s.length()){
                total += cnt[10][index2+1];
            }
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 6176
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = 2000000000;
// const ll MOD = 1000000007;

int A, B, C;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> A >> B >> C;

  if (A == B && B == C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
	int a =  sc.nextInt();
	int b =  sc.nextInt();
	int c =  sc.nextInt();
	int sum = a+b+c;

	System.out.println(sum>=22?"bust":"win");
  }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,k;cin>>n>>k;
    cout<<(n+k-3)/(k-1)<<endl;
    return 0;
}

Measured memory_bytes: 3620
n, a, b =map(int, input().split())

if (a - b) % 2 == 0:
  print(abs(a - b) // 2)
else:
  if a > b:
    a, b = b, a
  if n - b > a - 1:
    print((a + b - 1) // 2)
  else:
    print((2 * n - b - a + 1) // 2)


Measured memory_bytes: 2940
(let [a (read) b (read) c (read) d (read)
      ca (Math/abs (- a c))
      ab (Math/abs (- a b))
      bc (Math/abs (- b c))]
  (println (if (or (<= ca d)
                   (and (<= bc d) (<= ab d)))
             "Yes" "No"))
  	)

Measured memory_bytes: 60796
#include <iostream>
using namespace std;
int main(void){
    int N,A[3][10],B[3][10],C[3][10],D[3][10],b,f,r,v;
    cin>>N;
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            A[i][j]=0,B[i][j]=0,C[i][j]=0,D[i][j]=0;
        }
    }
    for(int i=0;i<N;i++){
        cin>>b>>f>>r>>v;
        b==1 ? A[f-1][r-1]+=v : 
        b==2 ? B[f-1][r-1]+=v : 
        b==3 ? C[f-1][r-1]+=v : 
        b==4 ? D[f-1][r-1]+=v : 0 ;
    }
    
    for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<A[i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
        for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<B[i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
        for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<C[i][j];
        }
        cout<<endl;
    }
    cout<<"####################"<<endl;
        for(int i=0;i<3;i++){
        for(int j=0;j<10;j++){
            cout<<" "<<D[i][j];
        }
        cout<<endl;
    }
    return 0;
}


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

int main() {
  uint64_t n, m;
  std::cin >> n >> m;

  uint64_t root = std::floor(std::sqrt(m));

  if (n <= root) {
    for (uint64_t i = n; i <= root; i++) {
      if (m % i == 0) {
        std::cout << m / i << std::endl;
        return 0;
      }
    }

    for (uint64_t i = n - 1; 0 < i; i--) {
      if (m % i == 0) {
        std::cout << i << std::endl;
        return 0;
      }
    }
  } else {
    for (uint64_t i = m / n; 0 < i; i--) {
      if (m % i == 0) {
        std::cout << i << std::endl;
        return 0;
      }
    }
  }
}


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

int main(void)
{
	int n, k;
	cin >> n >> k;
	cout << n - k + 1 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	S := nextString()
	c1 := 0
	c2 := 0
	found := false
	var second byte

	for i := 0; i < 4; i++ {
		if S[i] == S[0] {
			c1++
		} else {
			if !found {
				second = S[i]
				found = true
			}
			if S[i] == second {
				c2++
			}
		}
	}

	if c1 == 2 && c2 == 2 {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}

var stdin = initStdin()

func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024 // 1 MB
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func nextString() string {
	stdin.Scan()
	return stdin.Text()
}

func nextBytes() []byte {
	stdin.Scan()
	return stdin.Bytes()
}

func nextInt() int {
	i, _ := strconv.Atoi(nextString())
	return i
}

func nextInt64() int64 {
	i, _ := strconv.ParseInt(nextString(), 10, 64)

	return i
}


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

#define bitGet(a, i) a & (1 << i)
#define bitOn(a, i) a != (1 << i)
#define bitOff(a, i) a &= ~(1 << i)
#define bitMake(a, i) a = (1 << N)
#define fto(i, a, b) for(int i = a; i <= b; ++i)
#define fdto(i, a, b) for(int i = a; i >= b; --i)
#define ull unsigned long long
#define ll long long
#define ld long double
#define pri(a) cout << a << " "
#define pril(a) cout << a << " "
#define pb push_back
#define mp make_pair
#define vi vector<int> 
#define pi pair<int, int>
#define oo INT_MAX
#define maxN

using namespace std;


int main() {
    #ifndef ONLINE_JUDGE
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    #endif // !ONLINE_JUDGE

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << max((ll)b*d, max((ll)a*c, max((ll)a*d, (ll)b*c)));
    
    return 0;
}


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

typedef struct point{
    double x, y;
}point;

double segment(point p1, point p2);
double inclination(point p1, point p2);
point reflection(point p1, point p2, point p3);

int main(void)
{
    point p1, p2, p;
    int n, i;

    scanf("%lf%lf%lf%lf", &p1.x, &p1.y, &p2.x, &p2.y);
    //ax+by+c=0
    scanf("%d",&n);
    for (i = 0; i < n; i++) {
        scanf("%lf %lf", &p.x, &p.y);
        p = reflection(p1, p2, p);
        printf("%.10lf %.10lf\n", p.x, p.y);
    }
    return 0;
}

point reflection(point p1, point p2, point p3) 
{
    double a, b, c;
    point ans;
    a = inclination(p1, p2);
    b = -1.0;
    c = segment(p1, p2);
    //ax+by+c=0
    if (a > 2000000000) {
        if (p3.x < p1.x) {
            ans.x = p3.x+2.0*(p1.x-p3.x); 
            ans.y = p3.y;
        } else {
            ans.x = p3.x-2.0*(p3.x-p1.x);
            ans.y = p3.y;
        }
    } else {
        ans.x = p3.x-2.0*a*(a*p3.x+b*p3.y+c)/(a*a+b*b);
        ans.y = p3.y-2.0*b*(a*p3.x+b*p3.y+c)/(a*a+b*b);
    }
    return ans;
}

double segment(point p1, point p2)
{
    //*切片
    double a, b1, b2;
    a = inclination(p1, p2);
    if (a > 2000000000.0) {
        return 2100000000.0;
    }
    b1 = -a * p1.x + p1.y;
    b2 = -a * p2.x + p2.y;
    return (b1 + b2) / 2;
}

double inclination(point p1, point p2)
{
    //*傾き
    if (-0.00000000002 < p2.x - p1.x && p2.x - p1.x < 0.00000000002) {
        return 2100000000.0;
    } else {
        return (p2.y - p1.y) / (p2.x - p1.x);
    }
}

Measured memory_bytes: 668
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
vector<int64_t> aib;
vector<int> h, a;
int n;
int64_t res, curr;
inline void Update(int pos, int64_t val) {
    for (int i = pos; i <= n; i += i & -i)
        aib[i] = max(val, aib[i]);
}
inline int64_t Query(int pos) {
    int64_t maxi(0);
    for (int i = pos; i > 0; i -= i & -i)
        maxi = max(maxi, aib[i]);
    return maxi;
}
int main(){
    DAU
    cin >> n;
    aib = vector<int64_t>(n + 1);
    h = a = vector<int>(n + 1);
    for (int i = 1; i <= n; ++i)
        cin >> h[i];
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        curr = Query(h[i] - 1) + a[i];
        Update(h[i], curr);
        res = max(res, curr);
    }
    cout << res;
    PLEC
}


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

int main() {
  string str;
  string A;
  cin >> str;

    if (str == "a" || str == "i" || str == "u" || str == "e" || str == "o") {
      A = "vowel";
    }
      else {
      A = "consonant";
    }

  
  cout << A << endl;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n0,n) for(int i=n0;i<n;i++)
#define Com(i,j,n) for(int i=0;i<n-1;i++)for(int j=i+1;j<n;j++)
const long long INF = 1e10;
const int MOD = (int)1e9+7;
const double EPS = 1e-9;
typedef long long ll;
typedef long li;
#define pb push_back
#define mp make_pair

signed main (){
  ll n;
  cin >> n;
  vector<ll> l(n);
  for(ll & x : l){
    cin >> x;
  }
  sort(l.begin(), l.end());
  // rep (i,n)
  // {
  //   cout << l[i] << endl;
  // }
  ll ans = 0;
  ll c = 0;
  rep(i,n) {
    Rep(j,i+1,n) {
      // cout << *(l.begin() + j) << " " << *l.end() << endl;
      auto it = lower_bound(l.begin() + j + 1, l.end(), l[i] + l[j]);
      if(it != l.end()) {
        // cout << "if   " << i << " " << j << " " << l.end() - it << endl;
        ans += it - (l.begin() + j + 1);
      } else {
        // cout << "else " << i << " " << j << " " << n - 1 << endl;
        ans += n - j - 1;
      }
      c ++;
    }
  }
  // cout << ans << " " << c << endl;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
N,x = map(int,input().split())
a = list(map(int,input().split()))
a.sort()
ans = 0
for i in range(len(a)):
    if i == len(a)-1:
        if x == a[i]:
            ans += 1
            break
    else:
        x -= a[i]
        if x < 0:
            break
        ans+=1
print(ans)

Measured memory_bytes: 9084
#include<bits/stdc++.h>
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define vi vector<int>
#define v(i) vector<i>
#define FOR(i,a,b) for(i=a;i<b;i++)
#define FORE(i,a,b) for(i=a;i<=b;i++)
#define FORV(i,a,b) for(i=a;i>b;i--)
#define FOREV(i,a,b) for(i=a;i>=b;i--)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define look(v) for(auto c:v) cout<<c<<" "; cout<<"\n";
#define dfdc int i,j,k,m,n,ct=0;string s;
#define ppl(a,st,end) for(i=st;i<=end;i++)cin>>a[i];
#define fz(a) memset(a,0,sizeof a);
#define dp_1(n) int dp[n];fz(dp);
#define dp_2(m,n) int dp[m][n];fz(dp);
#define arpt(a,s,e) for(i=s;i<=e;i++) cout<<a[i]<<" ";cout<<"\n";
#define tk int t;cin>>t;while(t--)
 
using namespace std;
 
typedef long long int ll;
 
 
int main(){
    fastio
    dfdc
    cin>>n;
    vi v1(n);
    ppl(v1,0,n-1);
    int ans = 0;
    for(int i=0;i<n;i++){
    	for(int j=i+1;j<n;j++){
    		for(int k=j+1;k<n;k++){
    			if(v1[i]!=v1[j] && v1[i]!=v1[k] && v1[k]!=v1[j]){
	    			int sum = v1[i] + v1[j] + v1[k];
	    			int mx = max(v1[i],max(v1[j],v1[k]));
	    			if(mx<sum-mx){
	    				ans++;
	    			}
    			}
    		}
    	}
    }
    cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const string YES = "Yes";
const string NO = "No";

int main()
{
  ll A;
  scanf("%lld",&A);
  ll B;
  scanf("%lld",&B);
  ll C;
  scanf("%lld",&C);
  if (A==B&&B==C) cout << YES << endl;
  else cout << NO << endl;

  return 0;
}


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

#0.10%を基準にする
k_min = B * 10
k_max = (B+1) * 10

ans = -1
for k in range(k_min, k_max):
    if k * 8 // 100 == A:
        ans = k
        break
print(ans)

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

template<typename T>
void fin (T a){
    cout<<a<<endl;
    exit(0);
}

template<typename S>
void print(S a){
    cout<<a<<endl;
}

template<typename U>
void pprint(U a){
    cout<<a;
}

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

    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll ans;
    ans = b*d;
    ans = max(ans,b*c);
    ans = max(ans,a*c);
    ans = max(ans,a*d);
    fin(ans);




    return 0;
}




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


signed main() {
	int n;
	cin>>n;
	vector<int>t(n+1),xy(n+1);
	t[0]=0;
	xy[0]=0;
	for(int i=1;i<=n;i++){
		int x,y;
		cin>>t[i]>>x>>y;
		xy[i]=x+y;
	}
	for(int i=1;i<=n;i++){
		if(t[i]-t[i-1]<abs(xy[i]-xy[i-1])||(t[i]-t[i-1])%2!=abs(xy[i]-xy[i-1])%2){
			cout<<"No"<<endl;
			return 0;
		}
	}
	cout<<"Yes"<<endl;
}

Measured memory_bytes: 1792
import collections
n = int(input())
s = []
for i in range(n):
  s.append(input())
c = collections.Counter(s)
print('AC x {}'.format(c['AC']))
print('WA x {}'.format(c['WA']))
print('TLE x {}'.format(c['TLE']))
print('RE x {}'.format(c['RE']))

Measured memory_bytes: 16476
n,m=map(int,input().split())

s=[0]*n

for _ in range(m):
  s[int(input())-1]=""
  
#print(s)

if n==1:
  print(1)
  exit()
elif n==2:
  if s[0]=="":
    print(1)
  else:
    print(2)
  exit()
  
if s[0]=="":
  s[0]=0
else:
  s[0]=1
  
if s[1]=="":
  s[1]=0
else:
  s[1]=1+s[0]

i=2
while i<n:
  if s[i]=="":
    s[i]=0
  else:
    s[i]=s[i-1]+s[i-2]
  i+=1
print(s[-1]%1000000007)

Measured memory_bytes: 460020
import sys
readline=sys.stdin.readline

N,D,A=map(int,readline().split())
D*=2 # 爆発の長さ
X=[None]*N
for i in range(N):
  X[i]=list(map(int,readline().split()))

X=sorted(X,key=lambda x:x[0])
# lastX=X[-1][0] # 最後のモンスターの場所
damage=0 # 現在の爆発が与えられるダメージ
from collections import deque
bombs=deque() # 爆弾が切れるタイミング
# [位置、効力]
ans=0
for i in range(len(X)):
  x=X[i][0]
  h=X[i][1] # モンスターの体力
  # 爆発が途切れていないかを確認
  while bombs:
    b=bombs.popleft()
    if b[0]<x:
      damage-=b[1]
    else:
      bombs.appendleft(b)
      break
  h-=damage
  if h>0:
    turn=((h+A-1)//A)
    damage+=turn*A
    ans+=turn
    bombs.append([x+D,turn*A])
print(ans)


Measured memory_bytes: 66456
// id: ALDS1_2_C
#include <iostream>
#include <vector>

using std::cin;
using std::cout;
using std::endl;
using std::swap;
using std::vector;

static const int MAX_N = 36;
static const int rank_num = 9;

vector<char> seq[rank_num];
bool to_check[rank_num];

struct Card {
	char suit;
	int rank;
};

void bubble_sort(Card c[], int n);
void selection_sort(Card c[], int n);
void print_cards(Card c[], int n);
//bool operator==(const Card &lhs, const Card &rhs);
//bool operator!=(const Card &lhs, const Card &rhs);
bool check_stable(Card c[], int n);

int main()
{
	Card cards1[MAX_N], cards2[MAX_N];
	int n;
	bool stable = true;

	cin >> n;
	for ( int i = 0; i < n; ++i ) {
		cin >> cards1[i].suit >> cards1[i].rank;
		cards2[i] = cards1[i];

		seq[cards1[i].rank - 1].push_back(cards1[i].suit);
	}

	for ( int i = 0; i < rank_num; ++i )
		to_check[i] = seq[i].size() > 1;

	bubble_sort(cards1, n);
	selection_sort(cards2, n);

	print_cards(cards1, n);
	//cout << "Stable" << endl;

	if ( check_stable(cards1, n) )
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	print_cards(cards2, n);

	/*for ( int i = 0; i < n; ++i )
		if ( cards2[i] != cards1[i] ) {
			stable = false;
			break;
		}

	if ( stable )
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;*/

	if ( check_stable(cards2, n) )
		cout << "Stable" << endl;
	else
		cout << "Not stable" << endl;

	return 0;
}

void bubble_sort(Card c[], int n)
{
	bool flag = true;
	int i = 0;

	while ( flag ) {
		flag = false;

		for ( int j = n - 1; j > i; --j )
			if ( c[j].rank < c[j - 1].rank ) {
				swap(c[j - 1], c[j]);
				flag = true;
			}

		++i;
	}
}

void selection_sort(Card c[], int n)
{
	Card minv;
	int minj;

	for ( int i = 0; i < n - 1; ++i ) {
		minj = i;
		minv = c[i];

		for ( int j = i + 1; j < n; ++j )
			if ( c[j].rank < minv.rank ) {
				minj = j;
				minv = c[j];
			}

		if ( minj != i ) {
			c[minj] = c[i];
			c[i] = minv;
		}
	}
}

void print_cards(Card c[], int n)
{
	cout << c[0].suit << c[0].rank;

	for ( int i = 1; i < n; ++i )
		cout << " " << c[i].suit << c[i].rank;
	cout << endl;
}
/*
bool operator==(const Card &lhs, const Card &rhs)
{
	return lhs.suit == rhs.suit && lhs.rank == rhs.rank;
}

bool operator!=(const Card &lhs, const Card &rhs)
{
	return !(lhs == rhs);
}*/

bool check_stable(Card c[], int n)
{
	vector<char>::size_type pos[rank_num] = {0};
	bool stable = true;

	for ( int i = 0; i < n; ++i ) {
		int num = c[i].rank;

		if ( to_check[num - 1] )
			if ( c[i].suit == seq[num - 1][pos[num - 1]] )
				++pos[num - 1];
			else {
				stable = false;
				break;
			}
	}

	return stable;
}


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

// in-short-use macros

#define all(c) (c).begin(),(c).end()
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define PI 3.14159265
#define sizes 1000010



//main function here

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    int n;
    cin>>n;
    int a[n],cnt[n+10]={0};
    memset(cnt,0,sizeof(cnt));
    for(int i=0;i<n-1;i++)
    {
        cin>>a[i];
    }
    for(int i=0;i<n-1;i++)
        cnt[a[i]]++;
    for(int i=1;i<=n;i++)
        cout<<cnt[i]<<"\n";
    return 0;
}

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


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


Measured memory_bytes: 3120
a, b, c = sorted([int(v) for v in input().split()])

ans = 0
if a % 2 == b % 2 == c % 2:
    ans = (c - b + c - a) // 2
elif a % 2 == b % 2 != c % 2:
    ans = (b - a) // 2 + c - b
elif a % 2 != b % 2 == c % 2:
    ans = (c - b) // 2 + (c - a + 1) // 2 + 1
else:
    ans = (c - a) // 2 + (c - b + 1) // 2 + 1

print(ans)

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

using namespace std;
int main() {

	int N ,result;

	cin >> N;

	vector<int> B(N);

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

	for (int i = 0; i < N - 1; i++)
	{
		if (i == 0)
		{
			result = B[0];
		}
		else {
			result += min(B[i-1], B[i]);
		}
	}
	result += B[N - 2];

	cout << result;

}



Measured memory_bytes: 256
n = int(input())
s = str(input())
a = str("ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ")
k = len(s)
ans = str("")
for i in range(k):
    for j in range(26):
        if s[i] == a[j]:
            ans += a[j+n]
print(ans)

Measured memory_bytes: 3060
use std::cmp::*;
use std::io::*;
const MOD: usize = 1_000_000_007;

fn main() {
    let mut s: String = String::new();
    stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let k: usize = itr.next().unwrap().parse().unwrap();

    let mut ans = 0;
    for i in k..=n + 1 {
        let high = (n + n - i + 1) * i / 2;
        let low = (i - 1) * i / 2;
        ans = (ans + high - low + 1) % MOD;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2104
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int map[101][101]={{}};
    int r,c;
    cin>>r>>c;
    //まずは右に合計を出力する
    for(int t=0;t<r;t++)
    {
        int S={};
        for(int i=0;i<c;i++)
        {
            cin>>map[t][i];
            cout<<map[t][i]<<" ";
            S+=map[t][i];
        }
        cout<<S<<endl;
    }//全て配列に格納してSを出力した
    int All={};
    for(int s=0;s<c;s++)
    {
        int T={};
        for(int t=0;t<r;t++)
        {
            T+=map[t][s];
            All+=map[t][s];
        }
        cout<<T<<" ";
    }
    cout<<All<<endl;
    
    
    return 0;
}



Measured memory_bytes: 3116
from math import log
N = int(input())
li = [[0]* 10 for i in range(10)]
for i in range(1,N+1):
    u = i//10**int(log(i,10))
    l = i%10
    if l != 0:
        li[u][l] += 1
ans = 0
for i in range(1,10):
    for j in range(1,10):
        ans += li[i][j] * li[j][i]
print(ans)

Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    int x, y;
    cin >> x >> y;
    int odp = 0;
    int w[] = {300000, 200000, 100000};
    if (x <= 3)
        odp += w[x - 1];
    if (y <= 3)
        odp += w[y - 1];
    if (x == 1 && y == 1)
        odp += 400000;
    cout << odp;
    return 0;
}


Measured memory_bytes: 256