akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define pi 3.1415926535897932384626
using namespace std;
  
struct P{
  int x,y;
  bool operator <(const P &a) const{
    return x>a.x;
  };
};
  
int a,b,c,d,i,k,n,m,e,dx[10]={1,0,-1,0,1,1,-1,-1},dy[10]={0,1,0,-1,1,-1,1,-1};
int o[555];
int l[1];
int j[1];

long long x,y,z,mod=1000000007;
string r[55],r1;
//char r[1],;
vector<int> v[31],v1;
queue<int> q;
//stack<int> s;
map<int,int> p;
P u[1];
  
bool as(P a,P b)
{
  if(a.x!=b.x)
  return a.x<b.x;
  return a.y<b.y;
}

int main()
{
  scanf("%d",&a);
  for(int t=1;t<=a;t++)
  {
    cin>>r[t];
    scanf("%d",&o[t]);
  }
  cin>>r1;
  for(int t=a;;t--)
  {
    if(r[t]==r1) break;
    k+=o[t];
  }
  printf("%d",k);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 2e5+7;

int n;
ll h[N],a[N];
ll dp[N];
ll bit[N];

ll mx(int k) {
    ll ret = 0;
    while (k >= 1) {
    ret = max(ret,bit[k]);
    k -= k&-k;
    }
    return ret;
}

void add(int k, ll x) {
    while (k <= n) {
    bit[k] = max(bit[k],x);
    k += k&-k;
    }
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    cin >> n;
    REP(i,1,n) cin >> h[i];
    REP(i,1,n) cin >> a[i];

    REP(i,1,n)
    {
        dp[i] = mx(h[i]);
        dp[i] += a[i];
        add(h[i],dp[i]);
    }
    ll ans = 0;
    REP(i,1,n) ans = max(ans,dp[i]);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
 
int N;
int x[10], y[10];
 
double dist(int i, int j) {
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx * dx + dy * dy, 0.5);
}
 
void solve() {
    cin >> N;
    for(int i = 1; i <= N; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(N);
    for(int i = 0; i < N; i++) v[i] = i + 1;
    do {
        for(int i = 0; i < N - 1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));
    int Factorial = 1;
    for(int i = 2; i <= N; i++) Factorial *= i;
    cout << fixed << setprecision(10) << sum / Factorial << endl;
    return;
}
 
int main() {
    solve();
    return 0;
}

Measured memory_bytes: 4248
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007L;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static ArrayList<int[]> list = new ArrayList<>();
	public static void main(String[] args) throws Exception {


		int N = nextInt();

		long[] a = new long['Z'-'A'+1];
		int[] p = {'Z'-'M','Z'-'A','Z'-'R','Z'-'C','Z'-'H'};
		Arrays.fill(a,0);
		for(int i=0;i<N;i++){
			a['Z'-nextString().charAt(0)]++;
		}

		long ans =0;
		for(int i=0;i<p.length;i++){
			for(int k=i+1;k<p.length;k++){
				for(int n=k+1;n<p.length;n++){
					ans+=a[p[i]]*a[p[k]]*a[p[n]];
				}
			}
		}

		System.out.println(ans);
	}



	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static String concatStringArray(String[] s){
		StringBuffer sb = new StringBuffer();
		for(String x:s){
			sb.append(x);
		}
		return sb.toString();
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 33376
#include "bits/stdc++.h"
#include "sstream"
#define quick ios_base::sync_with_stdio(false);cin.tie(NULL);
using namespace std;
const int N=1e5+1;
const double EulerConstant = exp(-1);
int arr[101];
int main() {
        quick
int n;  cin>>n;
long long sum=0;
for(int i=0;i<n-1;i++){cin>>arr[i];}
sum+=arr[0]+arr[n-2];
for(int i=1;i<n-1;i++){
    sum+=min(arr[i],arr[i-1]);
}
cout<<sum;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;

namespace AtCoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        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); }

        private static long Solve(int N, long[][] A)
        {
            if (N == 1) { return 0; }
            long sum = A.Sum(a => a.Sum()) / 2;
            if (N == 2) { return sum; }
            for (int i = 0; i < N; ++i)
            {
                for (int j = i + 1; j < N; ++j)
                {
                    long min = Enumerable.Range(0, N).Where(k => k != i && k != j).Min(k => A[i][k] + A[k][j]);
                    if (min < A[i][j]) { return -1; }
                    if (min == A[i][j]) { sum -= A[i][j]; }
                }
            }
            return sum;
        }
        static void Main(string[] args)
        {
            int N = ReadInt();
            long[][] A = new long[N][];
            for (int i = 0; i < N; ++i) { A[i] = ReadLongs(); }
            Console.WriteLine(Solve(N, A));
        }
    }
}


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

int main(){
  int a,b,c,d,e,f;
  cin >> a >> b >> c >> d >> e >> f;
  a = a + b*5 + c*10 + d*50 + e*100 + f*500;
  if(a >= 1000){
    cout << '1' << endl;
  } else { 
    cout << '0'  << endl;
  }
  return 0;
}

Measured memory_bytes: 3048
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] V = new int[N];
		int[] C = new int[N];
		for (int i = 0; i < N; i++) {
			V[i] = sc.nextInt();
		}
		for (int i = 0; i < N; i++) {
			C[i] = sc.nextInt();
		}
		sc.close();

		int ans = 0;
		for (int i = 0; i < N; i++) {
			int diff = V[i] - C[i];
			if (diff > 0) {
				ans += diff;
			}
		}
		System.out.println(ans);
	}
}


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


//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

    if(k < a){
        max += k;
    }else{
        max += a;
        k -= a;
        k -= b;
        if(k > 0){
            max += (-k);
        }
        
    }

    cout << max << endl;
    return 0;
}


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

const int L = 1000000000;

long long S;

int main() {
  scanf("%lld", &S);
  
  long long X = sqrt(S);
  long long Y = S / X;
  
  while (Y > L) --Y;
  while (X > L) --X;
  
  while (X * Y < S) {
    if (Y < L) ++Y;
    else ++X;
  }
  
  printf("0 0 %lld 1 %lld %lld\n", X, X*Y - S, Y);
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;

int main()
{
	long long s,rt,a,b,c,d,rtc;
	scanf("%lld",&s);
	rt=sqrt(s);
	for(a=max(1ll,rt-10);a<rt+10&&a<=1e9;a++)
		for(d=max(1ll,rt-10);d<rt+10&&d<=1e9;d++)
			if(a*d>=s){
				c=a*d-s;
				rtc=sqrt(c);
				b=1;
				for(int i=2;i<rtc&&c>1e9;i++)
					if(c%i==0)
						c/=i,b*=i;
				if(c<=1e9){
					printf("0 0 %lld %lld %lld %lld\n",a,b,c,d);
					return 0;
				}
			}
	while(1);
	return 0;
}

Measured memory_bytes: 128
N = int(input())
F = []
for i in range(N):
    F.append(list(map(int, input().split())))
P = []
for i in range(N):
    P.append(list(map(int, input().split())))

A = []
def dfs(arr):
    if len(arr) == 10:
        if arr != [0,0,0,0,0,0,0,0,0,0]:
            A.append(arr)
        return
    for i in [0,1]:
        dfs(arr + [i])
dfs([])

ans = -(10**18)
# 10^3 * 10^2 = O(10^5)
for i in range(len(A)):
    tmp = 0
    for j in range(N):
        fac = A[i][0]*F[j][0] + A[i][1]*F[j][1] + A[i][2]*F[j][2] + A[i][3]*F[j][3] + A[i][4]*F[j][4] + A[i][5]*F[j][5] + A[i][6]*F[j][6] + A[i][7]*F[j][7] + A[i][8]*F[j][8] + A[i][9]*F[j][9]
        tmp += P[j][fac]
    ans = max(tmp, ans)
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cstring>
#include <algorithm>
#include <functional>
#include <bits/stdc++.h>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <stdlib.h>
#include <deque>
#include <cstdint>
using namespace std;

int main () {
  long long int a, b, m;
  cin >> a >> b >> m;
  long long int sum = 0;
  long long int a_cost[a];
  long long int b_cost[b];
  int min_a = 100000;
  int min_b = 100000;
  for (int i = 0; i < a; i++){
    int tmp;
    cin >> tmp;
    a_cost[i] = tmp;
    if (tmp < min_a){
      min_a = tmp;
    }
  }
  for(int i = 0; i < b; i++){
    int tmp;
    cin >> tmp;
    b_cost[i] = tmp;
    if (tmp < min_b){
      min_b = tmp;
    }
  }
  sum = min_a + min_b;
  for (int i = 0; i < m; i++){
    int x, y, c;
    cin >> x >> y >> c;
    if (a_cost[x-1] + b_cost[y-1] - c < sum){
      sum = a_cost[x-1] + b_cost[y-1] - c;
    }
  }
  cout << sum;
  return 0;
}

Measured memory_bytes: 1792
s=input()
K=int(input())

sub_list=[]

for i in range(len(s)):
    for j in range(1,K+1):
        if(i+j<=len(s)):
            sub_list.append(s[i:i+j])

sub_set=set(sub_list)
sub_dict=sorted(sub_set,key=str)

print(sub_dict[K-1])

Measured memory_bytes: 5196
#include<stdio.h>
#include<string.h>
int MAX(int a,int b){return a<b?b:a;}
//int P[1010],L[1010],R[1010],H[1010],C=1;
int P[4][1010],C=1,H[1010];
//int hyouka(int i,int x){return N[i]<=x?N[i]<x?-1:0:1;}
char N[1010][110];
int hyouka(int i,char *s){return strcmp(N[i],s);}
int h(int a){return H[P[2][a]]-H[P[1][a]];}
void rot(int a,int t){
  int b=P[t][a],r=P[0][a];
  P[t][r]==a?(P[1][r]=b):(P[2][r]=b);
  if(P[3-t][b])P[0][P[3-t][b]]=a;
  P[t][a]=P[3-t][b];
  P[3-t][b]=P[0][b];
  P[0][b]=P[0][a];
  P[0][a]=b;
  H[a]=MAX(H[P[1][a]],H[P[2][a]])+1;
  H[b]=MAX(H[P[1][b]],H[P[2][b]])+1;
}
void make(int p,int t,char *s){
  P[t][p]=C;
  P[0][C++]=p;
  strcpy(N[C],s);
  H[p]=MAX(1,H[p]);
}
int mfind(char *x){
  int i,j,r,n,t;
  if(C==1){
    make(0,1,x);
    //P[1][0]=C;
    //N[C]=x;
    //strcpy(N[C],x);
    //P[0][C++]=0;
    return 1;
  }
  for(i=1;r=hyouka(i,x);i=n){
    if(r<0)t=1;
    else   t=2;
    if(P[t][i]==0){
      make(i,t,x);
      //P[t][i]=C;
      //P[0][C]=i;
      //H[i]=MAX(1,H[i]);
      //N[C]=x;
      //strcpy(N[C],x);
      //C++;
    }
    n=P[t][i];
  }//printf("%d\n",i);
  for(j=P[0][i];j;j=P[0][j]){
    if(h(j)<-1){
      if(h(P[1][j])>0)rot(P[1][j],1);
      rot(j,2);
      break;
    }
    if(h(j)>1){
      if(h(P[2][j])<0)rot(P[2][j],2);
      rot(j,1);
      break;
    }
    if(h(j)==0)break;
    //if(j==0)break;
  }//printf("%d\n",i);
  return i;
}      
int main(){
  int i,l,max=0,mj=1,r,a[1010]={};
  char *c,*mi,s[1020];
  fgets(s,1010,stdin);
  mi=strtok(s," \n");
  a[mj=mfind(mi)]++;
  max=strlen(mi);
  // printf("%s\n",mi);
  while(c=strtok(NULL," \n")){
    //printf("%s\n",c);
    a[r=mfind(c)]++;
    //printf("%d\n",r);
    l=strlen(c);//printf("%s %d\n",mi,l);
    if(max<l){
      max=l;
      strcpy(mi,c);
    }//printf("a\n");
    if(a[r]>a[mj])mj=r;//printf("a\n");
  }
  //printf("%s %d\n",mi,mj);
  printf("%s %s\n",N[mj],mi);
  return 0;
}

Measured memory_bytes: 568
import math

n = int(input())
p_list = list(map(int, input().split()))
q_list = list(map(int, input().split()))

num_list =[1,2,3,4,5,6,7,8][:n]

p_count = 0
for i in range(n):
    order = num_list.index(p_list[i])
    num_list.pop(order)
    num = (order)*math.factorial(n-i-1)
    p_count = p_count + num

num_list =[1,2,3,4,5,6,7,8][:n]

q_count = 0
for i in range(n):
    order = num_list.index(q_list[i])
    num_list.pop(order)
    num = (order)*math.factorial(n-i-1)
    q_count = q_count + num

print(abs(p_count-q_count))

Measured memory_bytes: 3064
#include <iostream>
#include <queue>
#include <map>

using namespace std;

typedef pair<int, int> P;

int n, q;
int fish[1000001];

int main() {
  cin >> n >> q;
  
  priority_queue<P> pq;
  
  for(int i = 0; i < q; i++) {
    int a, v;
    cin >> a >> v;
    fish[a] += v;
    pq.push(P(fish[a], a * (-1)));
    
    while(!pq.empty()) {
      P p = pq.top();
      p.second *= -1;
      if(p.first == fish[p.second]) {
        cout << p.second << ' ' << p.first << endl;
        break;
      }
      pq.pop();
    }
  }

  return 0;
}

Measured memory_bytes: 7800
num=list(map(int,list(input())))
op=[1,-1]
def ope(x):
    if x==1:
        return "+"
    else:
        return "-"

for k in op:
    for j in op:
        for i in op:
            if num[0]+num[1]*k+num[2]*j+num[3]*i==7:
                print("{0}{1}{2}{3}{4}{5}{6}=7".format(num[0],ope(k),num[1],ope(j),num[2],ope(i),num[3]))
                exit()

Measured memory_bytes: 3064
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline int my_getchar_unlocked(){
  static char buf[1048576];
  static int s = 1048576;
  static int e = 1048576;
  if(s == e && e == 1048576){
    e = fread_unlocked(buf, 1, 1048576, stdin);
    s = 0;
  }
  if(s == e){
    return EOF;
  }
  return buf[s++];
}
inline void rd(double &x){
  int k;
  int m=0;
  int p=0;
  double r = 1;
  x = 0;
  for(;;){
    k = my_getchar_unlocked();
    if(k=='-'){
      m = 1;
      break;
    }
    if(k=='.'){
      p = 1;
      break;
    }
    if('0'<=k&&k<='9'){
      x = k - '0';
      break;
    }
  }
  for(;;){
    k = my_getchar_unlocked();
    if(k=='.'){
      p = 1;
      continue;
    }
    if(k<'0'||k>'9'){
      break;
    }
    if(p){
      r *= 0.1;
      x += r * (k - '0');
    }
    else{
      x = x * 10 + k - '0';
    }
  }
  if(m){
    x = -x;
  }
}
template<class T> inline T pow3_L(T a){
  return a*a*a;
}
int main(){
  double L;
  double res;
  rd(L);
  res =pow3_L((L/3));
  printf("%.10f\n", res);
  return 0;
}
// cLay varsion 20200321-1

// --- original code ---
// {
//   double L, res;
//   rd(L);
//   res = (L/3) ** 3;
//   printf("%.10f\n", res);
// }


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int x = sc.nextInt();
        int y = sc.nextInt();
        int ans;
        if (k>n){
            ans = (n*x);
        }else {
            ans = (k * x) + (n - k) * y;
        }
        System.out.println(ans);
    }
}


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

long long gcd(long long a, long long b) {
	while (a != 0) {
		if (a < b)swap(a, b);
		a = a % b;
	}
	return b;
}
long long x(long long a, long long b) {
	if (a < b)swap(a, b);
	return a / gcd(a, b)*b;
}

int main() {
	int N; cin >> N;
	vector<long long> a(N);
	for (int i = 0; i < N; i++)cin >> a[i];
	long long ans;
	if (N == 1)cout << a[0] << endl;
	else {
		ans = x(a[0], a[1]);
		for (int i = 2; i < N; i++) {
			ans = x(a[i], ans);
		}
		cout << ans << endl;
	}
}



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


int main()
{
 int S;
 cin >> S;
 int h = S/3600;
 int m = (S/60)-60*h;
 int s = S-3600*h-60*m;
 cout << h << ":" << m << ":" << s << endl;
}

Measured memory_bytes: 1168
#include <stdio.h>
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
const int INF (1<<30);

int main() {
  int R;
  cin >> R;

  double pi = 3.14159265;

  printf("%.10f\n", 2.0*pi*R);
  return 0;
}


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

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

    for (int a = 0; a <= y / 10000; a++) {
        for (int b = 0; b <= y / 5000; b++) {
            int c = y / 1000 - 10 * a - 5 * b;
            if (a + b + c == n && c >= 0) {
                printf("%d %d %d\n", a, b, c);
                return 0;
            }
        }
    }

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


Measured memory_bytes: 256
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	static FastScanner sc = new FastScanner();
	static PrintWriter out = new PrintWriter(System.out);

	static void solve() {
		int D = sc.nextInt();
		int N = sc.nextInt();
		int[] T = new int[D];
		for (int i = 0; i < D; i++) {
			T[i] = sc.nextInt();
		}
		int[] A = new int[N];
		int[] B = new int[N];
		int[] C = new int[N];
		int C_MAX = 0;
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			B[i] = sc.nextInt();
			C[i] = sc.nextInt();
			C_MAX = max(C_MAX, C[i]);
		}
		int[][] dp = new int[D][C_MAX + 1];
		for (int i = 0; i < D; i++) {
			for (int j = 0; j <= C_MAX; j++) {
				dp[i][j] = Integer.MIN_VALUE;
			}
		}
		for (int j = 0; j < N; j++) {
			if (A[j] <= T[0] && T[0] <= B[j]) {
				dp[0][C[j]] = 0;
			}
		}
		for (int i = 1; i < D; i++) {
			for (int j = 0; j < N; j++) {
				if (A[j] <= T[i] && T[i] <= B[j]) {
					for (int k = 0; k <= C_MAX; k++) {
						dp[i][C[j]] = max(dp[i][C[j]], dp[i - 1][k] + Math.abs(C[j] - k));
					}
				}
			}
		}
		int ans = 0;
		for (int i = 0; i <= C_MAX; i++) {
			ans = max(ans, dp[D - 1][i]);
		}
		out.println(ans);
		out.flush();
	}

	public static void main(String[] args) {
		solve();
	}

	static int max(int a, int b) {
		return a < b ? b : a;
	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}

	private static boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}

	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}

	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}

	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
}

Measured memory_bytes: 25648
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif
#include<bits/stdc++.h>
using namespace std;
#define rep(i,s,t) for(ll i = (ll)(s); i < (ll)(t); i++)
#define rrep(i,s,t) for(ll i = (ll)(s-1);(ll)(t) <= i; i--)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
constexpr ll INF = numeric_limits<ll>::max()/4;
constexpr ll n_max = 2e5+10;
#define int ll

template <typename A, typename B>
string to_string(pair<A, B> p);
string to_string(const string &s) {return '"' + s + '"';}
string to_string(const char *c) {return to_string((string) c);}
string to_string(bool b) {return (b ? "true" : "false");}
template <size_t N>
string to_string(bitset<N> v){
    string res = "";
    for(size_t i = 0; i < N; i++) res += static_cast<char>('0' + v[i]);
    return res;
}
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for(const auto &x : v) {
        if(!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}
template <typename A, typename B>
string to_string(pair<A, B> p){return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}

void debug_out() {cerr << endl;}
template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

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

struct item{
    double x, y;
    char c;
    item(){}
    item(double x, double y, char c):x(x), y(y), c(c){}
};

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    ll n; cin >> n;
    vector<item> v(n);
    rep(i,0,n){
        double x,y; cin >> x >> y;
        char c; cin >> c;
        v[i] = {x, y, c};
    }
    auto calc = [&](double k){
        double xmin = INF, xmax = -INF, ymin = INF, ymax = -INF;
        rep(i,0,n){
            double x = v[i].x, y = v[i].y;
            if(v[i].c == 'R')x += k;
            if(v[i].c == 'L')x -= k;
            if(v[i].c == 'U')y += k;
            if(v[i].c == 'D')y -= k;
            chmin(xmin, x), chmax(xmax, x);
            chmin(ymin, y), chmax(ymax, y);
        }
        return (xmax - xmin) * (ymax - ymin);
    };
    
    double ma = 1e9, mi = 0;
    rep(_,0,300){
        double le = mi + (ma - mi) / 3.0;
        double ri = ma - (ma - mi) / 3.0;

        if(calc(le) > calc(ri))mi = le;
        else ma = ri;
    }

    cout << fixed << setprecision(15);
    cout << calc(ma) << "\n";
}

Measured memory_bytes: 5652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int a=in(),b=in(),c=in(),f[100]={},i=1,x;
	x=a*i%b;
	while(!f[x]){
		f[x]=1;
		i++;
		x=a*i%b;
	}
	puts(f[c]?"YES":"NO");
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int N_MAX=200000;
typedef long long ll;
int main()
{
  int n,i,j,x=0,s=0;
  int a[N_MAX];
  ll res=0;
  cin >> n;
  for(i=0;i<n;i++)
    cin >> a[i];
  for(i=0,j=0;i<n;i++){
    for(;j<n;j++){
      if(x!=s)
        break;
      x^=a[j];
      s+=a[j];
    }
    if(x==s)
      j=n+1;
    res+=j-i-1;
    x^=a[i];
    s-=a[i];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 4372
using System;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var N = int.Parse(Console.ReadLine());
            var p = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            var result = 0;
            for (int i = 0; i < N; i++)
            {
                if (p[i] != i + 1)
                {
                    result++;
                }
            }
            Console.WriteLine(result <= 2 ? "YES" : "NO");
        }
    }
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main() {
int x,n;
cin>>x>>n;
int p[n];
map<int,bool> m;
rep(i,n){
  cin>>p[i];
  m[p[i]]=true;
}
int count=INF,ans=INF;
for(int i=-1000;i<1000;i++){
if(!m[i]){
  if(count>abs(x-i)){
  count=min(count,abs(x-i));
  ans=i;
  }
}
}
cout<<ans<<endl;
    return 0;
}


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

int main(){
  int N;
  int j = 1;
  cin>>N;
  vector<int> a(N);
  for(int i = 0;i < N;i++){
    cin>>a.at(i);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  for(int i = 0;i < N;i++){
    if(i == N - 1){
      break;
    }
    if(a.at(i) > a.at(i + 1)){
      j++;
    }
  }
  cout<<j<<endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
const int MAX=1000000000;
int main(){
  
  long long s;
  cin>>s;
  
  long long xa=0,xb=MAX,xc,ya=0,yb=1,yc;
  long long aa,mod;
  yc=s/MAX+1;
  mod=s%MAX;
  xc=MAX-mod;
  if(s==1000000000000000000){
  	xb=MAX;
    xc=0;
    yb=0;
    yc=MAX;
  } 
  cout<<xa<<" "<<ya<<" "<<xb<<" "<<yb<<" "<<xc<<" "<<yc<<" "<<endl;

}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
const int mod= 1e+9+7;

int main(){
    ll n,m; cin>>n>>m;
    vector<ll>a(m); 
    vector<ll>f(n+1,0);
    rep(i,m){
        cin>>a[i];
        f[a[i]]=-1;
    }
    vector<ll>ans(n+1,0);
    if(f[1]==-1)ans[1]=0;
    else ans[1]=1;
    if(f[2]==-1)ans[2]=0;
    else ans[2]=1+ans[1];
    if(n<=2){
        cout<<ans[n]<<endl;
        return 0;
    }
    for(int i=3;i<=n;i++){
        if(f[i]==-1)ans[i]=0;
        else {
            ans[i]=ans[i-2]+ans[i-1];
            ans[i]%=mod;
        }
    }
    cout<<ans[n]<<endl;

}



















































Measured memory_bytes: 2560
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("O3")
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<cstdlib>
#include<set>
#include<vector>
#include<sstream>
#include<queue>
#include <iomanip>
#include<unordered_set>
#include <stack>
#include <unordered_map>
#include <map>
constexpr auto INF = 9223372036854775807;
typedef long long int ll;
typedef unsigned long long int ull;
typedef unsigned long int ul;
#define f(i,a,b) for(ll i=(ll)a;i<(ll)b;i+=1)
#define rf(i,a,b) for(ll i=(ll)a;i>=(ll)b;i-=1)
#define endl '\n'
#define N 1000000007 // prime modulo value 
#define M 998244353
#define all(x) x.begin(),x.end()
using namespace std;
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		// http://xorshift.di.unimi.it/splitmix64.c
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}
};
#define safe_map unordered_map<ll, ll, custom_hash>

inline int mex(unordered_set<int> st)
{
	int m = 0;
	while (st.find(m) != st.end())
	{
		m += 1;
	}
	return m;
}
inline int calculateGrundy(int n)
{
	if (n == 1)
		return 0;
	unordered_set<int> mexi;
	for (int i = 1; i <= sqrt(n); i += 1)
	{
		if (n % i == 0)
		{
			if (n / i != n)
				mexi.insert(calculateGrundy(n / i));
			mexi.insert(calculateGrundy(i));
		}
	}
	return mex(mexi);
}
inline ll gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}
ll power(ll x, ll y)
{
	ll res = 1;

	x = x % N;
	if (x == 0) return 0;
	while (y > 0)
	{
		if (y & 1)
			res = (res * x) % N;
		y = y >> 1;
		x = (x * x) % N;
	}
	return res;
}
int main()
{
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n;
	cin >> n;
	set<string> st;
	f(i, 0, n)
	{
		string temp;
		cin >> temp;
		st.insert(temp);
	}
	cout << st.size();
	return 0;
}

Measured memory_bytes: 19200
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    string s;
    cin >> s;
    s += '$';
    long l = 0, r = 0, ans = 0;
    bool left = true;
    char prev = '<';
    for (auto &c:s) {
        if (c == prev) {
            if (left) l++;
            else r++;
        } else {
            if (left) {
                r++;
                ans += l * (l+1) / 2;
            } else {
                long amari = min(l, r);
                ans += r * (r+1) / 2;
                ans -= amari;
                l = 1;
                r = 0;
            }
            left = !left;
        }
        prev = c;
        //cerr << c << ' ' << l << ' ' << r << ' ' << ans << '\n';
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 900
from collections import Counter

N = int(input())
S = [input() for i in range(N)]
M = int(input())
T = [input() for i in range(M)]

cou_S = Counter(S)
cou_T = Counter(T)

ans = [0]
for key in cou_S:
    ans.append(cou_S[key] - cou_T.get(key, 0))
print(max(ans))

Measured memory_bytes: 3316
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
char s[100005];
int main()
{
   // freopen("in.txt","r",stdin);freopen("out.txt","w",stdout);
    int i,n;
    scanf("%s",s+1);n=strlen(s+1);
    if (s[1]==s[n]) {if (n%2==0) puts("First"); else puts("Second");}
     else {if (n%2==1) puts("First"); else puts("Second");}
    
    return 0;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

string n;
int len;
ll calc(int a, int b){
  ll dp[10][2][2];
  memset(dp,0,sizeof(dp));
  dp[0][0][0] = 1;
  for(int i = 0; i < len; i++){
    for(int j = 0; j < 2; j++){
      rep(k,2){

        int lim = n[i] - '0';
        if(j == 1)  lim = 9;
        // 桁の最後
        if(len == i+1){
          if(k > 0){ // a が入っている
            if(j == 1) (dp[i+1][j][k] += dp[i][j][k]);
            else if(j==0 && lim >= b) (dp[i+1][j || b < lim][1] += dp[i][j][k]);
          }
          else if(k == 0 && a == b && lim >= a){
            (dp[i+1][j || a < lim][1] += dp[i][j][k]);
          } 
        }else if(k==0){
          if(j==0){
            (dp[i+1][j || a < lim][1] += dp[i][j][k]); // a をおく
            (dp[i+1][0][0] += dp[i][j][k]); // a を置かない
          }
        }
        else if(k == 1){
          for(int d = 0; d <= lim; d++){
            (dp[i+1][j || d < lim][1] += dp[i][j][1]);
          }
        }
      }
    }
  }
  rep(k,2){
    cout << dp[1][0][k] << endl;
  }
  ll ans = 0;
  rep(j,2) {
    ans = ans + dp[len][j][1];
  }
  return ans;
}
  ll t[10][10];
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);

  cin >> n;
  len = n.length();


  ll N = toInt(n);
  rep(i,N+1){
    ll ii = i%10;
    ll tmp = i;
    while(tmp > 9) tmp /= 10;
    ll jj = tmp;
    t[ii][jj]++;
  }

  ll ans = 0;
  FOR(i,1,10) FOR(j,1,10){
    ans += t[i][j] * t[j][i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  LL N;
  string a, b, c;
  cin >> N >> a >> b >> c;
  LL cnt = 0;
  REP(i, N)
  {
    if(a[i]==b[i]&&b[i]==c[i]){

    }else
    if(a[i]!=b[i]&&b[i]!=c[i]&&c[i]!=a[i]){
      cnt += 2;
    }else{
      cnt += 1;
    }
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define MOD 1000000007
#define rep(i,n) for(i=0;i<(n);i++)
#define loop(i,a,n) for(i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main(void) {
    int i,j,k;
    int n;
    cin >> n;
    int ans = 0;
    loop(i,1,n+1)if(i%2){
        int t = 0;
        loop(j,1,i+1)if(i%j == 0) t++;
        if(t == 8) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
#include <map>
#include <set>

using namespace std;

#define FOR(i,n,m) for(int i=n;i<m;++i)
#define ROF(i,n,m) for(int i=n;i>m;--i)
#define pb push_back
#define ll long long

const int INF = 0x3f3f3f3f;

set <int> mochi;
int n;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;
    int x;
    FOR(i,0,n){
        cin >> x;
        mochi.insert(x);
    }
    cout << mochi.size() <<'\n';

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    string S; cin >> S;
    OUT(S.substr(0,S.size()-8))

    return 0;
}

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

int main() {
    int n, m; cin >> n >> m;
    map<int, int> cityroads;
    for (int i = 1; i <= n; ++i) cityroads[i] = 0;
    for (int i = 0; i < m; ++i) {
        int a, b; cin >> a >> b;
        cityroads[a]++; cityroads[b]++;
    }
    for (auto cityroad : cityroads)
        cout << cityroad.second << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
using ll = long long;
using graph = std::vector<std::vector<ll>>;

using namespace std;

int main() {
    ll N,D,A;
    cin >> N >> D >> A;
    vector<pair<ll,ll>> Enemy(N);
    for(ll i = 0; i < N; i++){
        ll x,h;
        cin >> x >> h;
        Enemy[i] = make_pair(x,h);
    }
    sort(Enemy.begin(),Enemy.end());
    ll totalCount = 0;
    queue<pair<ll,ll>> bomb = queue<pair<ll,ll>>();
    ll bombCount = 0;
    for(int i = 0; i < N; i++){
        while(bomb.size() > 0){
            pair<ll,ll> currentB = bomb.front();
            if(currentB.first + 2 * D < Enemy[i].first){
                bombCount -= currentB.second;
                bomb.pop();
            }else{
                break;
            }
        }
        Enemy[i].second -= A * bombCount;
        if(Enemy[i].second > 0){
            ll bc = Enemy[i].second / A;
            if(Enemy[i].second % A != 0){
                bc++;
            }
            totalCount += bc;
            bomb.push(make_pair(Enemy[i].first,bc));
            bombCount += bc;

        }
    }
    cout << totalCount << endl;

}

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

using namespace std;

inline void Boost() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
}
typedef long long int ll;
typedef long double ld;

int main() {
	Boost();

	int n, k; cin >> n >> k;

	vector < pair < ll, ll > > v(n);
	for (int i = 0; i < n; ++i) {
		cin >> v[i].first >> v[i].second;
	}

	ll area = LLONG_MAX;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < n; ++j) {
			for (int m = 0; m < n; ++m) {
				for (int p = 0; p < n; ++p) {
					ll mnx = min(v[i].first, v[j].first);
					ll mxx = max(v[i].first, v[j].first);
					ll mny = min(v[m].second, v[p].second);
					ll mxy = max(v[m].second, v[p].second);
					int cnt = 0;
					for (int l = 0; l < n; ++l) {
						if (mnx <= v[l].first && v[l].first <= mxx && mny <= v[l].second && v[l].second <= mxy) {
							++cnt;
						}
					}
					if (cnt >= k) {
						area = min(area, (mxx - mnx) * (mxy - mny));
					}
				}
			}
		}
	}
	cout << area;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<stdlib.h>
#include<time.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#include<queue>
using namespace std;

int main(void){
 vector<string> A;
 int k;
 string x;
 string y;

 cin>>x;
 cin>>k;
 for(int i=0; i<x.length(); i++){
  for(int j=i;j<x.length() &&j<i+5;j++){
    y+=x[j];
    A.push_back(y);
  }
  y.clear(); 
 }
 sort(A.begin(),A.end());
 A.resize(unique(A.begin(),A.end()) - A.begin());
 
 std::cout<<A[k-1]<<std::endl;

}
     
     





Measured memory_bytes: 1660
main :: IO()
main = do
  [a,b] <- map read . words <$> getLine
  putStrLn $ show $ judge $ calc a b

judge :: Maybe Int -> Int
judge Nothing = -1
judge (Just n) = n

calc :: Int -> Int -> Maybe Int
calc a b
  | (a `div` 10) > 0 || (b `div` 10) > 0 = Nothing
  | otherwise = Just (a * b)


Measured memory_bytes: 508
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

#define LEN 50001
#define min(x,y) x < y ? x:y

typedef struct{
  char name[100];
  int t;
}P;

void Initialize(int *,int *,int);
int IsEmpty(int,int);
int IsFull(int,int);
void Enqueue(P [],int *,int *,P);
P Dequeue(P [],int *,int *);
  
int main(){
  P Q[LEN];
  int head,tail,n;
  int elaps = 0,c;
  int i,q;
  P u;

  scanf("%d %d",&n,&q);

  for (i = 0;i < n;i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].t);
  }

  Initialize(&head,&tail,i);

  while (head != tail){
    u = Dequeue(Q,&head,&tail);
    c = min(q,u.t);
    u.t -= c;
    elaps += c;
    
    if (u.t > 0)
      Enqueue(Q,&head,&tail,u);

    else
      printf("%s %d\n",u.name,elaps);
    
  }
  
  return 0;
}

void Initialize(int *head,int *tail,int i){
  *head = 0;
  *tail = i;
}

int IsEmpty(int head,int tail){
  if (head == tail)
    return 1;

  return 0;
}

int IsFull(int head,int tail){
  if (head == (tail + 1) % LEN)
    return 1;

  return 0;
}

void Enqueue(P Q[],int *head,int *tail,P x){
  if (IsFull(*head,*tail)){
    fprintf(stderr,"Over flow\n");
    exit(1);
  }

  Q[*tail] = x;

  if (*tail + 1 == LEN)
    *tail = 0;

  else
    (*tail)++;
}

P Dequeue(P Q[],int *head,int *tail){
  P x;
  
  if (IsEmpty(*head,*tail)){
    fprintf(stderr,"Under flow\n");
    exit(2);
  }

  x = Q[*head];

  if (*head + 1 == LEN)
    *head = 0;

  else
    (*head)++;

  return x;
}



Measured memory_bytes: 6788
#include <stdio.h>
#include <string.h>

int h_max,k_max;
double memo[101][100];
char memo_written[101][100];
double seicho_table[101][101];

double tansaku(int prev,int pos) {
	int i;
	double result=0,now;
	if(pos>=k_max)return 1.0;
	if(memo_written[prev][pos])return memo[prev][pos];
	for(i=1;i<=h_max;i++) {
		now=seicho_table[prev][i]*tansaku(i,pos+1);
		if(now>result)result=now;
	}
	memo[prev][pos]=result;
	memo_written[prev][pos]=1;
	return result;
}

int main(void) {
	int i,j;
	long long result;
	while(1) {
		scanf("%d%d",&h_max,&k_max);
		if(h_max==0 && k_max==0)break;
		for(i=1;i<=h_max;i++) {
			for(j=1;j<=h_max;j++) {
				scanf("%lf",&seicho_table[i][j]);
			}
		}
		for(i=0;i<=h_max;i++) {
			seicho_table[i][0]=seicho_table[0][i]=1.0;
		}
		memset(memo_written,0,sizeof(memo_written));
		result=(long long)((tansaku(0,0)+1e-10)*1000);
		if(result%10>=5)result+=10;
		printf("%lld.%02lld\n",result/1000,(result/10)%100);
	}
	return 0;
}

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

int main() {
	// your code goes here
	int n;
	cin>>n;
	int a[110];
	for(int i=0;i<n;i++){
		int u;
		cin>>u;
		a[i]=u;
	}
	long long dp[110][21]={0};
	dp[0][a[0]]=1;
	for(int i=0;i<n-1;i++){
	for(int j=0;j<21;j++){
	if(j+a[i+1]>-1 && 21>j+a[i+1]) dp[i+1][j+a[i+1]]=dp[i+1][j+a[i+1]]+dp[i][j];
	if(j-a[i+1]>-1 && 21>j-a[i+1]) dp[i+1][j-a[i+1]]=dp[i+1][j-a[i+1]]+dp[i][j];
	
	
	}
	}
	cout<<dp[n-2][a[n-1]]<<endl;
	return 0;
}

Measured memory_bytes: 1180
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
const int INF = 2e9;
const int MOD = 1e9 + 7;

int main() {
   int n, x;
   cin >> n >> x;
   vector<int> m(n);
   rep(i, 0, n) cin >> m[i];
   rep(i, 0, n) x -= m[i];
   sort(m.begin(), m.end());
   int ans = n + x / m[0];
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define repk(i,k,n) for (ll i = k; i <= (ll)(n); ++i)
#define MAX 500010
#define MOD 1000000007
typedef long long  ll;

using namespace std;

ll ans;


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

	ll INF = 1e10;
	
	ll N,K;
	cin >> N >> K;

	vector<ll> A(N);
	ll min_index,minn = INF;
	rep(i,N){
		cin >> A[i];
	}

	if(N==1){
		ans = 0;
	}
	else if(N - K <= 0){
		ans = 1;
	}
	else{
		N -= K;
		ans++;
		ans += (N + K - 2) /(K - 1);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

vector<vector<int>> G(600, vector<int>());

bool isOK(int st_num, int index, int key){
	if(G[st_num][index] <= key) return true;
	else return false;
}

int binary_search(int st_num, int nax, int key){
	int ng = nax;
	int ok = -1;
	while(abs(ok-ng) > 1){
		int mid = (ok + ng)/2;
		if(isOK(st_num,mid,key))ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
	int N, M, Q, l, r, p, q;
	cin >> N >> M >> Q;
	G.resize(N);
	rep(i,M){
		cin >> l >> r;
		--l; --r;
		G[l].push_back(r);
	}
	rep(i,N)sort(all(G[i]));
	rep(_,Q){
		cin >> p >> q;
		--p; --q;
		int res = 0;
		int key = q;
		for(int i = p; i <= q; ++i){
			int siz = G[i].size();
			res += binary_search(i, siz, key) + 1;
		}
		cout << res << endl;
	}
	return 0;
}


Measured memory_bytes: 4960