akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <queue>
#include <cmath>


using namespace std;

typedef long long ll;

struct TOWN{
    bool kaku;
    int kyo;
    vector<pair<int,int> > road;
    
    TOWN() :kaku(false){}
}town[3001];

int main(){
    int n,m,k,a,b,l,ina[100000],inb[100000],inl[100000],ans=0;
    priority_queue<pair<int,int> > pq;
    pair<int,int> p;
    
    scanf("%d%d%d",&n,&m,&k);
    
    for(int i=0;i<m;i++){
        scanf("%d%d%d",&a,&b,&l);
        town[a].road.push_back(make_pair(b,-l));
        town[b].road.push_back(make_pair(a,-l));
        ina[i]=a;
        inb[i]=b;
        inl[i]=l;
    }
    
    for(int i=0;i<k;i++){
        scanf("%d",&a);
        pq.push(make_pair(0,a));
    }
    
    while(!pq.empty()){
        p=pq.top();
        pq.pop();
        
        if(town[p.second].kaku) continue;
        town[p.second].kaku=true;
        town[p.second].kyo=-p.first;
        
        for(int i=0;i<town[p.second].road.size();i++)
            pq.push(make_pair(p.first+town[p.second].road[i].second,town[p.second].road[i].first));
    }
    
    for(int i=0;i<m;i++){
        int sa = abs(town[ina[i]].kyo-town[inb[i]].kyo);
        ans=max(ans,(max(inl[i]-sa,0)+1)/2+max(town[ina[i]].kyo,town[inb[i]].kyo));
    }
    
    
    
    printf("%d\n",ans);
    
    return 0;
}

Measured memory_bytes: 7024
#include<iostream>
#include<string>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	string s;
	int w;
	cin>>s>>w;
	string tmp="";
	for(int i=0;i<s.size();i+=w)tmp+=s[i];
	cout<<tmp<<endl;
	return 0;	
}

Measured memory_bytes: 256
import sys
N, T0 = map(int, sys.stdin.readline().split(" "))
L = sys.stdin.readlines()

isFound = False
ans = 0

for item in L:
  c, t = map(int, item.split(" "))
  if t <= T0:
    if isFound == False:
      ans = c
    else:
      ans = min(c, ans)
    isFound = True

if isFound == False:
  print("TLE")
else:
  print(str(ans))

Measured memory_bytes: 3060
N = int(input())
e = [0] * (N+1)
for i in range(2, N+1):
    cur = i
    for j in range(2, i+1):
        while cur % j == 0:
            e[j] += 1
            cur //= j
def num(m): # e の要素のうち m-1 以上のものの個数
    return len(list(filter(lambda x: x >= m-1, e)))

print(num(75) + num(25) * (num(3) - 1) + num(15) * (num(5) - 1)+ num(5) * (num(5) - 1) * (num(3) - 2) // 2)


Measured memory_bytes: 3064
/**
 * @param input string[][]
 */
function Main(input) {
  const line0 = input[0].split(' ').map(Number);
  const H = line0[0];
  const W = line0[1];
  const ss = input.slice(1);

  const checked = [];

  function getMax(y, x) {
    const stepMap = createStepMap(y, x);

    var max = 0, step;
    for (var i = 0; i < checked.length; i++) {
      step = stepMap[checked[i][0]][checked[i][1]];
      if (step > max) {
        max = step;
      }
    }

    return max;
  }

  function createStepMap(y, x) {
    const stepMap = ss.map((ssi) => ssi.split(''));

    fillRoute(y, x, stepMap);

    return stepMap;
  }

  function fillRoute(y, x, stepMap) {
    const ps = [[y, x, 0]];
    var p, py, px, pstep, current;

    while (p = ps.shift()) {
      py = p[0];
      px = p[1];
      current = stepMap[py][px];

      if (current !== '.') continue;

      pstep = p[2];
      stepMap[py][px] = pstep;

      // 左マス
      if (py > 0) {
        ps.push([py - 1, px, pstep + 1])
      }
      // 右マス
      if (py < H - 1) {
        ps.push([py + 1, px, pstep + 1])
      }
      // 上マス
      if (px > 0) {
        ps.push([py, px - 1, pstep + 1])
      }
      // 下マス
      if (px < W - 1) {
        ps.push([py, px + 1, pstep + 1])
      }
    }
  }

  var answer = 0;

  var y, x, max;
  for (y = 0; y < H; y++) {
    for (x = 0; x < W; x++) {
      if (ss[y][x] === '#') continue;

      if (checked.length > 0) {
        max = getMax(y, x);

        if (max > answer) {
          answer = max;
        }
      }

      checked.push([y, x]);
    }
  }

  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim()
  .split('\n')
  // .map((v) => v.split(' '))
);


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

int main(){
  int X,A,B;
  cin>>X>>A>>B;
  if(A-B>=0){
    cout<<"delicious"<<endl;
  }else{
    int d=B-A;
    if(d<=X){
      cout<<"safe"<<endl;
    }else{
      cout<<"dangerous"<<endl;
    }
  }
  return 0;
}


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

int main(){
    long long N;
    cin>>N;
    vector<long long> a(N,0);
    vector<long long> b(N,0);
    for(int i=0;i<N;i++){
        long long temp;
        cin>>temp;
        a[i]=temp;
        cin>>temp;
        b[i]=temp;
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    long long mid_a;
    long long mid_b;
    long long cnt;
    if(N%2==0){
        mid_a=(a[N/2-1]+a[N/2]);
        mid_b=(b[N/2-1]+b[N/2]);
        cnt=(mid_b-mid_a)+1;
    }else{
        mid_a=a[N/2];
        mid_b=b[N/2];
        cnt=mid_b-mid_a+1;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 6436
(*
ocamlfind ocamlopt -package batteries -linkpkg main.ml -o a.out
*)
open Batteries

let () = 
        Scanf.sscanf (read_line ()) "%d %d %d" (
                fun n m x -> 
                        let lst = Str.split (Str.regexp " ") (read_line ()) |> List.map int_of_string in
                        let ln = List.length (List.filter (fun elmnt -> elmnt < x) lst) in
                        let rn = List.length (List.filter (fun elmnt -> elmnt > x) lst) in
                                if ln < rn then ln else rn
        ) |> Printf.printf "%d\n"


Measured memory_bytes: 1152
#include <stdio.h>

int main()
{
        char str[1001], *strptr;
        scanf( "%[^\n]s", str );
        strptr = str;
        while ( *strptr != '\0' ) {
                if ( *strptr == 'a' ) {
                        if ( *(strptr+1) == 'p' && *(strptr+2) == 'p' && *(strptr+3) == 'l' && *(strptr+4) == 'e' ) {
                                *strptr     = 'p';
                                *(strptr+1) = 'e';
                                *(strptr+2) = 'a';
                                *(strptr+3) = 'c';
                                *(strptr+4) = 'h';
                        }
                } else if ( *strptr == 'p' ) {
                        if ( *(strptr+1) == 'e' && *(strptr+2) == 'a' && *(strptr+3) == 'c' && *(strptr+4) == 'h' ) {
                                *strptr     = 'a';
                                *(strptr+1) = 'p';
                                *(strptr+2) = 'p';
                                *(strptr+3) = 'l';
                                *(strptr+4) = 'e';
                        }
                }
                strptr++;
        }
        fprintf( stdout, "%s\n", str );
        return 0;
}



Measured memory_bytes: 2060
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();
        int count = 1;
        if(n == 1 || n == 2){
        	System.out.println("4");
            return;
        }
        while(n != 4){
        	if(n % 2 == 0){
            	n = n / 2;
            }else{
            	n = n * 3 + 1;
            }
            count++;
        }
        System.out.println(count + 3);
    }
}

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

using namespace std;

int main(){
    string s;
    cin >> s;
    bool flag = true;
    for(long long i = 0; i < s.length(); i += 2){
        if(s[i] != 'R' && s[i] != 'U' && s[i] != 'D'){
            flag = false;
            break;
        }
    }
    for(long long i = 1; i < s.length(); i += 2){
        if(s[i] != 'L' && s[i] != 'U' && s[i] != 'D'){
            flag = false;
            break;
        }
    }
    if(flag == false){
        cout << "No" << endl;
    }
    else{
        cout << "Yes" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# INPUT
h, w = map(int, input().split())
mapping = [list(input()) for i in range(h)]

# PROCESS

# 列をチェックして削除
def delete_row(mp):
  new_mp = []
  for row in mp:
    if ("#" in row):
      new_mp.append(row)
  return len(new_mp) < len(mp), new_mp

# 行をチェックして削除
def delete_column(mp):
  new_mp = []

  # 削除
  allow_columns = [0 for _ in range(len(mp[0]))]
  for row in mp:
    for cell_idx in range(len(row)):
      if (row[cell_idx] == "#"):
        allow_columns[cell_idx] = 1

  for row in mp:
    allow_row = []
    for cell_idx in range(len(row)):
      if (allow_columns[cell_idx] == 1):
        allow_row.append(row[cell_idx])
    new_mp.append(allow_row)

  return 0 in allow_columns, new_mp

deleted = True
while(deleted):
  deleted, mapping = delete_row(mapping)
  deleted, mapping = delete_column(mapping)

answer = mapping

# OUTPUT
for row in answer:
  print("".join(row))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define ll int64_t
int main(){
  ll N;
  cin >> N;
  vector<ll> A(N);
  rep(i,N)
    cin >> A.at(i);
  map<ll,ll> m;
  ll ans=0;
  rep(i,N){
    if(m.count(i-A.at(i)+1))
      ans += m.at(i-A.at(i)+1);
    if(!m.count(i+A.at(i)+1))
      m[i+A.at(i)+1]=0;
    ++m[i+A.at(i)+1];
  }
  cout << ans << endl;
}

Measured memory_bytes: 17156
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cmath>
using namespace std;

#define INF ((1LL << 31) - 1)
#define MOD int(1e9)
#define repi(i,j,n) for (int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)

inline void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int imos[105];

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    imos[a]++;
    imos[b]--;
    imos[c]++;
    imos[d]--;
    for (int i = 1; i < 101; ++i) {
        imos[i] += imos[i-1];
    }
    int ans = 0;
    repi(i,0,101) {
        if (imos[i] == 2) {
            ans++;
        }
    }
    //if (b == c || d == a) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <string>
#include <map>

using namespace std;

pair<int, int> simulate(int N, int M, const vector<vector<int>> &A, const vector<bool> &valid)
{
	map<int, int> h;
	int mx = 0;
	for (auto &p : A) {
		for (auto x : p) {
			if (valid[x]) {
				mx = max(mx, ++h[x]);
				break;
			}
		}
	}
	for (const auto &e : h) {
		if (e.second == mx) {
			return e;
		}
	}
	return make_pair(-1, -1);
}

int solve(int N, int M, const vector<vector<int>> &A)
{
	int ans = N;
	vector<bool> valid(M, true);
	for (int i = 0; i < M; ++i) {
		auto r = simulate(N, M, A, valid);
		ans = min(ans, r.second);
		valid[r.first] = false;
	}
	return ans;
}

int main()
{
	int N, M;
	cin >> N >> M;
	vector<vector<int>> A(N, vector<int>(M));
	for (int i = 0; i < N; ++i) {
		for (int j = 0; j < M; ++j) {
			cin >> A[i][j];
			--A[i][j];
		}
	}

	cout << solve(N, M, A) << endl;
}


Measured memory_bytes: 640
def argsort(seq):
    return sorted(range(len(seq)), key=seq.__getitem__)

def read():
    N = int(input().strip())
    A = list(map(int, input().strip().split()))
    return N, A

def solve(N, A):
    keys = argsort(A)
    keys = [k+1 for k in keys]
    return ' '.join(list(map(str, keys)))

if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 67308
package main

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

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	A := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		A[i] = nextInt(sc)
	}
	sort.Ints(A)
	var maxGCD int
	if A[len(A)-1] < K {
		fmt.Println("IMPOSSIBLE")
		return
	}
	maxGCD = A[0]
	for i := 1; i < N; i++ {
		maxGCD = gcd(maxGCD, A[i])
	}
	if maxGCD == 1 || (maxGCD > 1 && (K%maxGCD == 0)) {
		fmt.Println("POSSIBLE")
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define REPR(i, m, n) for (int i = (int)(m); i >= (int)(n); i--)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = 1001001001;

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

  vector<int> l;
  rep(i, n){
    int a; cin >> a;
    if(lower_bound(all(l), a) == l.end()){
      l.push_back(a);
    }
    else *lower_bound(all(l), a) = a;
  }

  cout << l.size() << endl;

  return 0;

}




Measured memory_bytes: 3456
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  ll x, y, z;
  cin >> x >> y >> z;
  x -= z;
  int ans = x / (y + z);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll  long long int
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
using namespace std;
ll dp[(1<<22)];

int main()
{
    fast; 
    ll n;
    cin>>n;

    ll a[n][n];
    for(ll i=0;i<n;i++)
      for(ll j=0;j<n;j++)
      cin>>a[i][j];

    memset(dp,0,sizeof(dp));

     dp[0]=1;
    for(ll mask=1;mask<(1<<n);mask++)
    {
      ll k=__builtin_popcount(mask);

        for(ll i=0;i<n;i++)
            if((mask&(1<<i)) and a[k-1][i]==1)
            dp[mask]=(dp[mask]+dp[(mask xor (1<<i))])%mod;
    }
    cout<<dp[(1<<n)-1]<<endl;
  }

Measured memory_bytes: 33024
#include<iostream>
using namespace std;
int D=365,c[26+1],last[26+1],M;
int main(){
    cin>>D;
    //input
    int s[D+1][26+1];
    for(int i=1;i<=26;i++)cin>>c[i];
    for(int i=1;i<=D;i++)for(int j=1;j<=26;j++)cin>>s[i][j];
    int t[D+1];
    for(int i=1;i<=D;i++)cin>>t[i];
    //score
    int v[D+1];v[0]=0;
    for(int day=1;day<=D;day++){
        v[day]=v[day-1]+s[day][t[day]];
        last[t[day]]=day;
        for(int i=1;i<=26;i++)v[day]-=c[i]*(day-last[i]);
    }
    //
    cin>>M;
    int v2[M+1];v2[0]=v[D];

    for(int n=1;n<=M;n++){
        int d,q;
        cin>>d>>q;
        t[d]=q;
        for(int i=0;i<=26;i++)last[i]=0;
        for(int day=1;day<=D;day++){
            v[day]=v[day-1]+s[day][t[day]];
            last[t[day]]=day;
            for(int i=1;i<=26;i++)v[day]-=c[i]*(day-last[i]);
        }
        v2[n]=v[D];
    }
    for(int i=1;i<=M;i++)cout<<v2[i]<<endl;
    return 0;
}

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

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

  int p[5000];
  for(int i=0; i<N; i++){
    cin >> p[i];
  }

  int min_sum = 20000;

  for(int I=0; I<=p[0]; I++){
    int q[5000];
    for(int i=0; i<N; i++){
      q[i] = p[i];
    }

    int sum = I;
    q[0] -= I;

    for(int i=0; i<=N-2; i++){
      if(q[i]<=0)
       continue;

      sum += q[i]*2;
      q[i+1] -= q[i];
    }

    if(q[N-1]>0){
      sum += q[N-1];
    }
    min_sum = min(min_sum, sum);
  }
  cout << min_sum << endl;
  return 0;
}



Measured memory_bytes: 3168
#include<stdio.h>
#include<string.h>
#include<list>

int main(){
  using namespace std;
  int i,n,m,ps;
  char opn[20],ans[20];
  bool ff,bf;
  list<int> player;
  list<int>::iterator it;
  do{
    scanf("%d %d",&m,&n);
    if(!m&&!n) break;
    for(i=0;i<m;i++) player.push_back(i+1);
    for(i=0,it=player.begin(),ps=m;i<n;i++){
      scanf("%s",opn);
      if(ps<2) continue;
      ff=(i+1)%3==0,bf=(i+1)%5==0;
      if(ff||bf){
	sprintf(ans,"%s%s",ff?"Fizz":"",bf?"Buzz":"");
      }else{
	sprintf(ans,"%d",i+1);
      }
      if(strcmp(ans,opn)){
	it=player.erase(it);
	ps--;
      }else{
	it++;
      }
      if(it==player.end()) it=player.begin();
    }
    it=player.begin();
    while(it!=player.end()){
      printf("%d",*it);
      it++;
      if(it!=player.end()) printf(" ");
    }
    printf("\n");
    player.clear();
  }while(1);
  return 0;
}

Measured memory_bytes: 0
using namespace std;
#include<bits/stdc++.h>
#define Debug(...) fprintf(stderr, __VA_ARGS__)
#define st first
#define nd second
#define FORE(i,a,b) for(int i=(a),b_=(b);i<=b_;++i)
#define FORD(i,a,b) for(int i=(a),b_=(b);i>=b_;--i)
#define TR(c, it) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); it++)
#define removeDuplicate(a) sort(a.begin(), a.end()); a.resize(distance(a.begin(), unique(a.begin(), a.end())))
 
const int N = 2e5 + 1;
const int MOD = 1e9 + 7;

int add (int a, int b) {
  return (a += b) >= MOD ? a - MOD : a;
}
 
int sub (int a, int b) {
  return (a -= b) < 0 ? a + MOD : a;
}
 
int mul (int a, int b) {
  return (long long) a * b % MOD;
}
 
int power(int a, long long n) {
  int res = 1;
  while(n) {
    if (n & 1LL) res = mul(res, a);
    a = mul(a, a);
    n >>= 1LL;
  }
  return res;
}
int inv(int a) {
  return power(a, MOD - 2);
}

int h, w, n; 

class Binomial {
  vector <int> fact, inv; 
  int n; 
  public:
    Binomial() {};
    Binomial(int sz) : n(sz), fact(sz + 1), inv(sz + 1) {
      fact[0] = fact[1] = inv[0] = inv[1] = 1;
        for (int i = 2; i <= n; ++i) {
            fact[i] = 1LL * fact[i - 1] * i % MOD;
            inv[i] = (MOD - 1LL * (MOD / i) * inv[MOD % i] % MOD) % MOD;
        }
        for (int i = 2; i <= n; ++i) inv[i] = 1LL * inv[i] * inv[i - 1] % MOD;
    };
    int operator() (int y, int x) { // x<=y; x>=0
        if (x > y) return 0;
        return 1LL * fact[y] * inv[x] % MOD * inv[y - x] % MOD;
    }
} nCr(N);

int solve (int n, int r) {
    return nCr(n + r, r); 
}

int calc (int a, int b, int c, int d) {
    int res = solve(c - a, d - b); 
    return res; 
}


 
int main() {
    #define TASK "TASK"	
	// freopen(TASK".inp","r",stdin);
	// freopen(TASK".out","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	cin >> h >> w >> n;
	h--, w--; 
	vector <int> ans(n + 2);
	vector < pair<int, int> > cells;   
	for (int i = 0; i < n; ++i) {
		int x, y;
		cin >> x >> y; 
		x--, y--; 
		cells.push_back(make_pair(x, y)); 
	}
	cells.push_back(make_pair(h, w)); 
	sort(cells.begin(), cells.end());
	for(int i = 0; i <= n; ++i) {
		// auto [x, y] = cells[i]; 
		int x = cells[i].st; 
		int y = cells[i].nd; 
		ans[i] = solve(x, y); 
	}
	for(int i = 0; i < n; ++i) {
		// auto [x, y] = cells[i];
		int x = cells[i].st; 
		int y = cells[i].nd;  
		for (int j = i + 1; j <= n; ++j) {
			// auto[u, v] = cells[j];
			int u = cells[j].st; 
			int v = cells[j].nd;  
			if (u < x || v < y || j == i) continue; 
			ans[j] = sub(ans[j], mul(ans[i], calc(x, y, u, v))); 
		}
	}
	cout << ans[n] << endl; 

     
  	return 0;
}

Measured memory_bytes: 1920
w=list(input())
n=len(w)
S=0
S_max=S
for i in range(n):
  if w[i]=='R':
    S+=1
    j=0
    while True:
      if i+j+1<=n-1:
        j+=1
        if w[i+j]=='R':
          S+=1
        else:
          i+=j
          break
      else:
        i=n-1
        break
  S_max=max([S_max,S])
  S=0
print(S_max)

Measured memory_bytes: 8960
from collections import deque
from enum import Enum
import sys
import math
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
class Process:
    def __init__(self,arg_name,arg_value):
        self.name = arg_name
        self.value = arg_value
        self.finish_time = BIG_NUM
 
Q = deque()
 
N,LIMIT = map(int,input().split())
 
#プロセスの取得
for loop in range(N):
    input_str = list(map(str,input().split()))
    tmp_Process = Process(input_str[0],int(input_str[1]))
    Q.append((tmp_Process))   #末尾に追加
 
num_finish = 0
current_time = 0
 
while  True:
    tmp_Process = Q.popleft() #先頭から取り出し、FIFOを実現
 
    if tmp_Process.value <= LIMIT: #終了
        current_time += tmp_Process.value
        print("%s %d"%(tmp_Process.name,current_time))
        num_finish += 1
    else:
        tmp_Process.value -= LIMIT
        current_time += LIMIT
        Q.append((tmp_Process))
 
    if num_finish == N:
        break


Measured memory_bytes: 18032
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back 
#define all(a) a.begin(),a.end()
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define ld long double
#define int long long int 
#define F first 
#define S second
signed main()
{
    fast;
    string s;
    cin>>s;
    int ans = 0;
    int i = 0;
    int j = s.size()-1;
    while(i<j)
    {
        if(s[i]!=s[j])
            ans++;
        i++,j--;
    }
    cout<<ans;

}


Measured memory_bytes: 256
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;

typedef long long ll;
//typedef pair<int,int> Pint;
typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
typedef vector<ll> vec;
typedef vector<vec> mat;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define revrep(i, n) for(ll i = n-1; i >= 0; i--)
ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1000000000;//10^9
ll MOD  = 1000000007;
//vector<int> dy = {0,0,1,-1};
//vector<int> dx = {1,-1,0,0};

ll bit[1 << 20];
ll bit_sum(ll i){
  ll s = 0;
  while(i > 0){
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void add(ll i, ll x){
  int a = 0;
  //cout << i << endl;
  while(i <= (1 << 18)){
    bit[i] += x;
    i += i & -i;
  }
}
ll N;
vector<ll> A(100010), S(100010);

//転倒数を求める
ll T(vector<ll> P){
  memset(bit, 0, sizeof(bit));
  rep(i, N+1) P[i] += N + 10;
  ll cnt = 0;
  rep(i, P.size()){
    cnt += i - bit_sum(P[i]);
    add(P[i], 1);
  }
  return cnt;
}

bool J(ll x){
  vec B(N);
  rep(i, N){
    if(A[i] >= x) B[i] = 1;
    else B[i] = -1;
  }
  rep(i, S.size()) S[i] = 0;
  rep(i, N) S[i+1] = S[i] + B[i];
  ll Tnt = T(S);
  ll notT = (N+1) * N / 2 - Tnt;
  return notT >= Tnt;
}

int main(){
  cin >> N;
  A.resize(N);
  S.resize(N+1);
  rep(i, N) cin >> A[i];

  ll ok = 0, ng = INFL;
  ll mid;
  while(ng - ok > 1){
    mid = (ng + ok) / 2;
    if(J(mid)){
      ok = mid;
    }else{
      ng = mid;
    }
  }
  cout << ok << endl;
}


Measured memory_bytes: 11624
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <deque>
#include <set>
#include <iomanip>
#include <utility>
typedef long long ll;
typedef long double ld;
using namespace std;

int main(void){
    int N, M;
    cin >> N >> M;
    if(N%2==1){
        for(int i=1; i<=M; ++i){
            cout << i << ' ' << N-i << endl;
        }
    }
    else{
        int g=N/2-1;
        for(int i=1; i<=min(M, (g+1)/2); ++i){
            cout << i << ' ' << g+g%2+1-i << endl;
        }
        for(int i=1; i+(g+1)/2<=M; ++i){
            cout << N+1-i << ' ' << N/2+1-(N/2)%2+i << endl;
        }
    }
    return 0;
}


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

using namespace std;

int main() {
    // 考え方メモ

    string S;
    cin >> S;

    string ACGT = "ACGT";

    int tmpLength = 0;
    int maxLength = 0;
    for (int i = 0; i < S.size(); i++) {
        bool found = false;
        for (int j = 0; j < 4; j++) {
            if (S.at(i) == ACGT.at(j)) {
                tmpLength++;
                found = true;
            }
        }
        maxLength = max(maxLength, tmpLength);
        if (!found) {
            tmpLength = 0;
        }
    }

    cout << maxLength << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int gcd(int a, int b) {
    if(b == 0) return a;
    return gcd(b, a % b);
}
int main(){
    ll a,b;
    cin>>a>>b;
    ll ans=a*b/gcd(a,b);
    cout<<ans<<endl;
}

Measured memory_bytes: 3608
import scala.io.StdIn.readInt

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toLong, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toLong,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<4000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> {
        val m = readInt; isPrime(m)
      }
    })
  }
}

Measured memory_bytes: 67544
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();
        }
        int ans = 0;
        for (int i = 0;i<n;i++) {
            int tmp = v[i] - c[i];
            if (tmp > 0) ans += tmp;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
//{
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double lf;
typedef pair<ll,ll> ii;
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define FILL(i,n) memset(i,n,sizeof i)
#define X first
#define Y second
#define SZ(_a) (int)_a.size()
#define ALL(_a) _a.begin(),_a.end()
#define pb push_back
#ifdef brian
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
#else
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0);
#endif // brian
//}


const ll MAXn=3e7+5,MAXlg=__lg(MAXn)+2;
const ll MOD=1000000007;
const ll INF=ll(1e15);

ll dp[MAXn];

ll a[3], b[3];

int main()
{
    IOS();
    ll N;
    cin>>N;
    REP(i, 3)cin>>a[i];
    REP(i, 3)cin>>b[i];
    REP1(i, N)dp[i] = i;
    REP(j, 3)
    {
        for(int i = a[j];i <= N;i ++)dp[i] = max(dp[i], dp[i - a[j]] + b[j]);
    }
    N = dp[N];
    assert(N < MAXn);
    REP(i, N + 1)dp[i] = i;
    REP(j, 3)
    {
        for(int i = b[j];i <= N;i ++)dp[i] = max(dp[i], dp[i - b[j]] + a[j]);
    }
    cout<<dp[N]<<endl;
}


Measured memory_bytes: 196864
#include"bits/stdc++.h"


#define PB push_back
#define PF push_front
#define LB lower_bound
#define UB upper_bound
#define fr(x) freopen(x,"r",stdin)
#define fw(x) freopen(x,"w",stdout)
#define iout(x) printf("%d\n",x)
#define lout(x) printf("%lld\n",x)
#define REP(x,l,u) for(int x = (l);x<=(u);x++)
#define RREP(x,l,u) for(int x = (l);x>=(u);x--)
#define mst(x,a) memset(x,a,sizeof(x))
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define MP make_pair
#define se second
#define fi first
#define dbg(x) cout<<#x<<" = "<<(x)<<endl;
#define sz(x) ((int)x.size())
#define cl(x) x.clear()

typedef  long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ld;
using namespace std;

const int maxn = 1000010;
const int mod = 1e9+7;
const int MAX = 1000000010;
const double eps = 1e-6;
const double PI = acos(-1);

template<typename T> inline void read(T &x){
x=0;T f=1;char ch;do{ch=getchar();if(ch=='-')f=-1;}while(ch<'0'||ch>'9');do x=x*10+ch-'0',ch=getchar();while(ch<='9'&&ch>='0');x*=f;
}

template<typename A,typename B> inline void read(A&x,B&y){read(x);read(y);}
template<typename A,typename B,typename C> inline void read(A&x,B&y,C&z){read(x);read(y);read(z);}
template<typename A,typename B,typename C,typename D> inline void read(A&x,B&y,C&z,D&w){read(x);read(y);read(z);read(w);}
template<typename A,typename B> inline A fexp(A x,B p){A ans=1;for(;p;p>>=1,x=1LL*x*x%mod)if(p&1)ans=1LL*ans*x%mod;return ans;}
template<typename A,typename B> inline A fexp(A x,B p,A mo){A ans=1;for(;p;p>>=1,x=1LL*x*x%mo)if(p&1)ans=1LL*ans*x%mo;return ans;}

int n,ans;

char s[maxn],t[maxn];

queue<int> Q;

void Work(){
	if(!strcmp(s+1,t+1)){
		puts("0");
		return;
	}
	int now=n;
	RREP(i,n,1)if(t[i]!=t[i-1]){
		now=min(now,i);
		while(now&&s[now]!=t[i])now--;
		if(!now){
			puts("-1");
			return;
		}
		while(!Q.empty()&&Q.front()>=Q.size()+i)Q.pop();
		if(now!=i)Q.push(now);
		ans=max(ans,(int)Q.size());
	}
	iout(ans+1);
}

void Init(){
	read(n);
	scanf("%s%s",s+1,t+1);
}

int main(){
	Init();
	Work();
	return 0;
}


Measured memory_bytes: 6272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e6+30;
char s[maxn];
int main(){
    cin >> s;
    int n=strlen(s);
    for (int i=0;i<n;i++) if(s[i]=='?') s[i]='D';
    cout << s << endl;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  
  cin >> N;
  
  int A = N / 1000;
  
  int B = (N % 1000) / 100;
  
  int C = (N % 100) / 10;
  
  int D = N % 10;
  
  if ((A == B && B == C) || (B == C && C == D)){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

using namespace std;

#define pb push_back
#define F first
#define S second
#define ALL(v) v.begin(),v.end()
#define fast_cin() ios_base::sync_with_stdio(0);
#define smid ((i + j) >> 1)
#define lc (sidx * 2)
#define rc (lc + 1)

typedef long long ll;
typedef long double ld;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

bool bit(int n, int i) { return (n >> i) & 1; }
int ceil(int a, int b) { return ceil(((ld)a) / b); }

int faltu;

const int mod = 1e9+7;
const ll inf = 4e18;
const ll ninf = -inf;
const int imax = 2e9 + 100;


int main()
{
	time_t t1, t2;
	t1 = clock();
	srand(time(0));

	fast_cin();
	int t;
	cin >> t;
	while(t--) {
		ll a, b, c, d;
		cin >> a >> b >> c >> d;
		if(b > d or a < b) {
			cout << "No\n";
		} else if(b < c) {
			cout << "Yes\n";
		} else {
			ll g = __gcd(b, d);
			ll x = a % b;
			ll lrg = b - x - 1, sml = c - x;
			// trace(sml, lrg, g);
			if((lrg / g) * g > sml) {
				cout << "No\n";
			} else {
				cout << "Yes\n";
			}
			// bool flag = false;
			// for(int it = 0; it < 10000; it++) {
			// 	// trace(x);
			// 	if(x > c) {
			// 		flag = true;
			// 		break;
			// 	} else {
			// 		x = (x + d) % b;
			// 	}
			// }
			// cout << (flag ? "No\n": "Yes\n");
		}
	}	
	

	t2 = clock();
	cerr << "time taken: " << t2 - t1 << 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);
        String s = sc.next();
        int k = sc.nextInt();
        int len = s.length();
        int rotate[] = new int[len];
        for (int i = 0; i < len; i++) {
            rotate[i] = count(s.charAt(i));
        }
        StringBuilder sb = new StringBuilder();
        for (int i = 0; i < len; i++) {

            if (k >= rotate[i]) {
                // 回転させる
                k -= rotate[i];
                // s = s.substring(0, i) + 'a' + s.substring(i + 1);
                sb.append("a");
            } else {
                // 回転出来ない
                sb.append(s.charAt(i));
            }
        }
        k %= 'z' - 'a' + 1;
        char c = sb.charAt(len - 1);
        sb.deleteCharAt(len - 1);
        sb.append((char) (c + k));
        // s = s.substring(0, len - 1) + (char) (s.charAt(len - 1) + k);
        System.out.println(new String(sb));

        sc.close();
    }

    static int count(char c) {
        if (c == 'a') {
            return 0;
        }
        return ((int) ('z' - c)) + 1;
    }
}


Measured memory_bytes: 27036
#include <stdio.h>
int main(){
	int S,h,m,s;
	scanf("%d",&S);//7261/2:1:1/
	h=S/3600;
	m=(S-3600*h)/60;
	s=(S-3600*h-60*m);
	printf("%d:%d:%d\n",h,m,s);
	return 0;
}

Measured memory_bytes: 1020
X=list(map(int,input().split()))
X.sort()
ans=X[2]-X[1]
if (X[2]-(X[0]+ans))%2==0:
  print(ans+(X[2]-(X[0]+ans))//2)
else:
  print(ans+(X[2]-(X[0]+ans)+1)//2+1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;

int main(){
  int N, M;cin>>N>>M;
  vii v;
  for (int i=0;i<M;++i){
    int a_, b_;cin>>a_>>b_;
    ii p=make_pair(b_, a_);
    v.push_back(p);
  }

  sort(v.begin(), v.end());

  int ans=1;
  int standard=v[0].first;

  for (int i=1;i<M;++i){
    if(v[i].second>=standard){
      ans++;
      standard=v[i].first;
    }
  }

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

Measured memory_bytes: 1400
#include <algorithm>
#include <iostream>
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <string.h>
#include <stack>
#include <map>
#define maxn 100000 + 5
#define INF 0x3f3f3f3f
#define xin(a) scanf("%d", &a)
#define ffr(i,m, n) for (i = m; i < n; i++)
#define clr(a, b) memset(a, b, sizeof(a));
#define pi acos(-1,0)
typedef double db;
typedef long long ll;
using namespace std;
void t(void)
{
    int t, n;
    xin(t);
    while (t--)
    {

    }
}
void n(void)
{
    int n, i,d;
    xin(n);
    cout<<(n%1000?1000-n%1000:0)<<endl;
}
int main(void)
{
    #ifndef ONLINE_JUDGE
    long _begin_time = clock();
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    n();
    #ifndef ONLINE_JUDGE
    long _end_time = clock();
    printf("time = %ld ms\n", _end_time - _begin_time);
    fclose(stdin);
    fclose(stdout);
    #endif
    return 0;
}

Measured memory_bytes: 3736
def gcd(x, y):
    if x < y:
        x = x ^ y
        y = x ^ y
        x = x ^ y
    div = x % y
    while div != 0:
        x = y
        y = div
        div = x % y
    return y

N=int(input())
As = list(map(int,input().split()))
As.sort()

res = As[0]
for i in range(1, N):
    res = gcd(res, As[i])

print(res)


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

using namespace std;
/**
********************************************************************
******************* Author:Bisnu sarkar ****************************
********************************************************************
**/

#define ull            unsigned long long
#define ll             long long
#define vi             vector<int>
#define pb             push_back
#define mp             make_pair
#define pii            pair<int,int>
#define vit            vector<int> :: iterator
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second

#define what_is(x)     cerr << #x << " is " << x << endl;

///*....Debugger....*/

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it)
{
    cout << endl ;
}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a << ' ' ;
    err(++it, args...);
}

int dx[8]= {1,0,-1,0,-1,-1,1,1};
int dy[8]= {0,1,0,-1,-1,1,-1,1};
int ini()
{
    int x;
    scanf("%d",&x);
    return x;
}
long long inl()
{
    long long x;
    scanf("%lld",&x);
    return x;
}

int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);

std::vector<int> adj[N];
int a[N];
bool vis[N];
int res[N];
void dfs(int u){
    vis[u]=true;
    res[u]+=a[u];
    for(auto x:adj[u]){
        if(!vis[x]){
            res[x]+=res[u];
            dfs(x);
        }
    }
}
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int n=ini(),q=ini();

    for(int i=1;i<n;i++){
        int u=ini(),v=ini();
        adj[u].push_back(v);
        adj[v].push_back(u);
    }

    while(q--){
        int in=ini(),x=ini();
        a[in]+=x;
    }
    dfs(1);
    for(int i=1;i<=n;i++){
        printf("%d", res[i]);
        if(i!=n)printf(" ");
    }
    printf("\n");

    return 0;
}


Measured memory_bytes: 43776
# include <iostream>
# include <algorithm>
# include <vector>
# include <functional>
# include <string>
using namespace std;

int main() {
	int num[4], val;
	bool flag=0;

	cin >> val;
	num[0] = val / 1000;
	val %= 1000;
	num[1] = val / 100;
	val %= 100;
	num[2] = val / 10;
	val %= 10;
	num[3] = val;

	if (num[0] + num[1] + num[2] + num[3] == 7 && flag == 0) cout << num[0] << '+' << num[1] << '+' << num[2] << '+' << num[3] << "=7" << endl, flag=1;
	if (num[0] + num[1] + num[2] - num[3] == 7 && flag==0) cout << num[0] << '+' << num[1] << '+' << num[2] << '-' << num[3] << "=7" << endl, flag = 1;
	if (num[0] + num[1] - num[2] - num[3] == 7 && flag == 0) cout << num[0] << '+' << num[1] << '-' << num[2] << '-' << num[3] << "=7" << endl, flag = 1;
	if (num[0] - num[1] - num[2] - num[3] == 7 && flag == 0) cout << num[0] << '-' << num[1] << '-' << num[2] << '-' << num[3] << "=7" << endl, flag = 1;
	if (num[0] - num[1] + num[2] + num[3] == 7 && flag == 0) cout << num[0] << '-' << num[1] << '+' << num[2] << '+' << num[3] << "=7" << endl, flag = 1;
	if (num[0] - num[1] - num[2] + num[3] == 7 && flag == 0) cout << num[0] << '-' << num[1] << '-' << num[2] << '+' << num[3] << "=7" << endl, flag = 1;
	if (num[0] + num[1] - num[2] + num[3] == 7 && flag == 0) cout << num[0] << '+' << num[1] << '-' << num[2] << '+' << num[3] << "=7" << endl, flag = 1;
	if (num[0] - num[1] + num[2] - num[3] == 7 && flag == 0) cout << num[0] << '-' << num[1] << '+' << num[2] << '-' << num[3] << "=7" << endl, flag = 1;



	
	return 0;
}

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

int main()
{
	ll N, sum = 0;
	cin >> N;
	vector<ll> a(N);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
		sum += a[i];
	}
	ll res = 1e17, tmp = 0;
	for (int i = 0; i < N - 1; i++) {
		tmp += a[i];
		res = min(res, abs(sum - tmp * 2));
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	int a = 0;
	int c[6] = { 1,5,10,50,100,500 };
	for (int i = 0; i < 6; i++) {
		int b; cin >> b;
		a += b*c[i];
	}
	if (a >= 1000)
		cout << 1 << endl;
	else
		cout << 0 << endl;
	return 0;
}

Measured memory_bytes: 3132
#include<bits/stdc++.h>
#define ll long long
#define ld long double

using namespace std;

void slove() {
	int h1, h2, m1, m2, k;
	cin >> h1 >> m1 >> h2 >> m2 >> k;
	int t = (h2 - h1) * 60;
	t = t + m2 - m1;
	if (t >= k) {
		cout << t-k << endl;
	}
	else {
		cout << 0 << endl;
	}

}

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


Measured memory_bytes: 3672
#pragma GCC optimize("Ofast")
  
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstring>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <unordered_set>
#include <list>
#include <tuple>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <cassert>
#include <numeric>
#include <math.h>
#include <bitset>
#include <random>
#include <regex>

using namespace std;

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,f,n) for(int i=f;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(10)
#define int int_fast64_t
using pii = pair<int,int>;
using Graph = vector<vector<pii> >;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;
constexpr int dy[] = {0,1,0,-1,1,-1,-1,1};
constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
 
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class A, class B> inline A updiv(const A a,const B b){ return (a + b - 1) / b; }
template <class A, class B> inline A gcd(const A a,const B b){ return b ? gcd(b,a % b) : a; }
template <class A, class B> inline A lcm(const A a,const B b){ return a / gcd(a,b) * b; }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A,class B> using umap = unordered_map<A,B>;

int n, k;
vector<int> h, dp;

int rec(int p){
    if(~dp[p]) return (dp[p]);
    int ret = INF;
    for(int i = 1; p - i >= 1 && i <= k; ++i){
        chmin(ret, abs(h[p] - h[p-i]) + rec(p - i));
    }
    return (dp[p] = ret);
}

signed main(void){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);

    cin >> n >> k;

    h.resize(n+1);
    dp.resize(n+1, -1);

    reps(i,1,n){
        cin >> h[i];
    } 

    dp[1] = 0;

    cout << rec(n) << '\n';

    return 0;
}  

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

typedef vector<int> vi;
#define FOR(i,a,b) for (int i=(a); i<(b); ++i)
#define all(a) (a).begin(), (a).end()
inline int in() {int x; cin >> x; return x;}

void solve(){
  int n = in(), m = in();
  vi A(n); for (auto &a:A) a = in();
  sort(all(A));

  int lo = 0, hi = 2e5+5;
  while (hi-lo>1) {
    int mid = (lo+hi)/2;
    int cnt = 0;
    for (int a:A) cnt += A.end() - lower_bound(all(A), mid-a);
    (cnt >= m ? lo : hi) = mid;
  }
  vi S(n+1); FOR (i,0,n) S[i+1] = S[i] + A[i];
  int ans = 0;
  int cnt = 0;
  FOR (i,0,n) {
    int pt = lower_bound(all(A), hi - A[i]) - A.begin();
    cnt += n - pt;
    ans += S[n] - S[pt] + (n - pt) * A[i];
  }
  ans += lo * (m - cnt);
  cout << ans << endl;
}

#undef int
int main(){
    solve();
    return 0;
}

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

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();}

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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;

#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())
#define REVERSE(c) reverse((c).begin(),(c).end())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;

#define CLR(a) memset((a), 0 ,sizeof(a))

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

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

int main(void){
    int H,A; cin >> H >> A;
    if(H%A) cout << H/A + 1 << endl;
    else cout << H/A << endl;
    return 0;
}

Measured memory_bytes: 256