akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <climits>
#include <cstring>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
using namespace std;

typedef long long LL;

int main()
{
    int N, T;
    cin >> N >> T;
    int pre;
    LL res = 0;
    cin >> pre;
    for (int i = 1; i < N; ++i)
    {
        int cur;
        cin >> cur;
        res += (cur - pre >= T) ? T : (cur - pre);
        pre = cur;
    }
    cout << (res + T) << endl;
    
    return 0;
};

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

#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = (n)-1; i >= 0; i--)
#define rep1(i,n) for(int i = 1; i <= (n); i++)
#define rrep1(i,n) for(int i = (n); i > 0; i--)

#define ll long long
#define pi pair<int, int>
#define pll pair<ll, ll>

#define MOD 1000000007
#define INF 1000000000000000LL

using namespace std;

int main(){
  ll n;cin>>n;
  vector<ll>a(n);
  rep(i, n)cin>>a[i];

  vector<ll>results;
  rep(i, n){
    auto it = lower_bound(results.begin(), results.end(), a[i]);
    if( it==results.end() ){
      if(results.size()>0 && a[i]>results[results.size()-1])*prev(it)=a[i];
      else results.insert(results.begin(), a[i]);
    }else{
      if(it==results.begin()){ results.insert(results.begin(), a[i]);
      }else{
        it--;
        *it = a[i];
      }
    }
  }
  cout<<results.size()<<endl;

  return 0;
}


Measured memory_bytes: 2168
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(x)-1; i >= (int)(n); i--)
#define INF 1e9
using ll = int64_t;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return true;
  }
  return false;
}
#define waru 1000000007

std::int64_t gcd(std::int64_t a, std::int64_t b) {
  // a >= b && b != 0
  std::int64_t c;
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
std::int64_t gcd_s(std::int64_t aa, std::int64_t bb) {
  std::int64_t a = max(aa, bb);
  std::int64_t b = min(aa, bb);
  std::int64_t c;
  if (b == 0) {
    return -1;
  }
  do {
    c = a % b;
    a = b;
    b = c;
  } while (c);

  return a;
}
void rle(std::vector<std::pair<char, std::int64_t>> &data, std::string str) {
  char now = str[0];
  std::int64_t count = 0;
  for (std::int64_t i = 0; i < str.size() + 1; i++) {
    if (i == str.size()) {
      data.push_back(make_pair(str[i - 1], count));
      break;
    } else if (now != str[i]) {
      data.push_back(make_pair(now, count));
      now = str[i];
      count = 0;
    }
    count++;
  }

  return;
}

#define MAX_NUM 1001

void Main() {
  //自動整形防止用コメント
  int n, a, b;
  cin >> n >> a >> b;
  std::cout << min(n * a, b) << std::endl;
  return;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}


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

using namespace std;
using ll = long long;
using ii = pair<ll, ll>;
using iii = tuple<ll, ll, ll>;

const int MAX { 310 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

ll dist[MAX][MAX], fuel[MAX];
vector<iii> es;

vector<ii> adj[MAX];
bitset<MAX> processed;

void dijkstra(int s, int N, ll L)
{
    for (int i = 1; i <= N; ++i)
        dist[s][i] = fuel[i] = oo;

    dist[s][s] = 0;
    fuel[s] = L;
    processed.reset();

    priority_queue<iii, vector<iii>, greater<iii>> pq;
    pq.push(iii(0, -L, s));

    while (not pq.empty())
    {
        auto [d, f, u] = pq.top();
        pq.pop();

        if (processed[u])
            continue;

        processed[u] = true;

        for (const auto& [v, c] : adj[u])
        {
            if (c <= fuel[u])
            {
                if (dist[s][v] > dist[s][u] or (dist[s][v] == dist[s][u] and fuel[u] - c > fuel[v]))
                {
                    dist[s][v] = dist[s][u];
                    fuel[v] = min(L, fuel[u] - c);
                    pq.push(iii(dist[s][v], -fuel[v], v));
                    continue;
                }
            }

            if (c <= L)
            {
                if (dist[s][v] > dist[s][u] + 1 or (dist[s][v] == dist[s][u] + 1 and L - c > fuel[v]))
                {
                    dist[s][v] = dist[s][u] + 1;
                    fuel[v] = min(L - c, L);
                    pq.push(iii(dist[s][v], -fuel[v], v));
                }
            }
        }
    }
}
    
vector<int> solve(ll N, ll L, const vector<ii>& qs)
{
    vector<int> ans(qs.size());

    for (int s = 1; s <= N; ++s)
        dijkstra(s, N, L);
 
    for (size_t i = 0; i < qs.size(); ++i)
    {
        auto [s, t] = qs[i];
        ans[i] = (dist[s][t] == oo ? -1 : dist[s][t]);
    }

    return ans;
}

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

    int N, M, L;
    cin >> N >> M >> L;

    for (int i = 0; i < M; ++i)
    {
        int a, b, c;
        cin >> a >> b >> c;

        adj[a].push_back(ii(b, c));
        adj[b].push_back(ii(a, c));

        es.push_back(iii(a, b, c));
        es.push_back(iii(b, a, c));
    }

    int Q;
    cin >> Q;

    vector<ii> qs(Q);

    for (int i = 0; i < Q; ++i)
        cin >> qs[i].first >> qs[i].second;

    auto ans = solve(N, L, qs);

    for (auto x : ans)
        cout << x << endl;

    return 0;
}



Measured memory_bytes: 11752
import java.util.*;
import java.lang.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int[] alp = new int[26];
		for (int i = 0; i < n; i++) {
			alp[s.charAt(i) - 'a']++;
		}
		long mod = 1000000007;
		long count = 1;
		for (int i = 0; i < 26; i++) {
			count = count * (alp[i] + 1) % mod;
		}
		System.out.println(count - 1);
	}
}

Measured memory_bytes: 24912
#define _GLIBCXX_DEBUG

#include "bits/stdc++.h"
using namespace std;
 
const int MOD = 1000000007;
const int abmax = 2020;
 
long long Inv(long long a) {
        long long res = 1;
        long long n = MOD - 2;
        while (n > 0) {
                if (n & 1) res = res * a % MOD;
                a = a * a % MOD;
                n >>= 1;
        }
        return res;
}
 
const int N = 8080;
long long fact[N];
long long invfact[N];
void init() {
        fact[0] = 1;
        for (int i = 1; i < N; i ++) fact[i] = (fact[i - 1] * i) % MOD;
        invfact[N - 1] = Inv(fact[N - 1]);
        for (int i = N - 2; i >= 0; i --) invfact[i] = (invfact[i + 1] * (i + 1)) % MOD;
}
long long C(long long n, long long r) {
        if (n < 0 || r < 0 || n < r) return 0;
        return fact[n] * invfact[n - r] % MOD * invfact[r] % MOD;
}
 
long long dp[4040][4040];
long long num[4040][4040];
 
int main() {
        init();
        int n;
        scanf("%d", &n);
        vector<int> a(n), b(n);
        for (int i = 0; i < n; i ++) scanf("%d%d", &a[i], &b[i]);
        for (int i = 0; i < n; i ++) { 
                dp[abmax - a[i]][abmax - b[i]] ++;
                num[abmax + a[i]][abmax + b[i]] ++;
        }
        long long ans = 0;
        for (int i = 0; i < abmax * 2 - 1; i ++) {
                for (int j = 0; j < abmax * 2 - 1; j ++) {
                        if (num[i][j] > 0) (ans += num[i][j] * dp[i][j]) %= MOD;
                        (dp[i + 1][j] += dp[i][j]) %= MOD;
                        (dp[i][j + 1] += dp[i][j]) %= MOD;
                }
        }
        for (int i = 0; i < n; i ++) ans = (((ans -  C(2 * (a[i] + b[i]), 2 * a[i])) % MOD) + MOD) % MOD;
        printf("%lld\n", (ans * Inv(2)) % MOD);
        return 0;
}

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

using namespace std;
using ll = long long;

#define int ll

#define rep(i, a) for (int i = 0; (i) < (int) (a); (i)++)
#define reps(i, a, b) for (int i = (int) (a); (i) < (int) (b); (i)++)
#define rrep(i, a) for (int i = (int) a-1; (i) >= 0; (i)--)
#define rreps(i, a, b) for (int i = (int) (a)-1; (i) >= (int) (b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
#define PERM(v) next_permutation(all(v))
#define UNIQUE(v) sort(all(v));(v).erase(unique(all(v)), v.end())
#define CIN(type, x) type x;cin >> x
#define TRUE__  "CONTINUE"
#define FALSE__ "GAMEOVER"
#define PRINT(f) if((f)){cout << (TRUE__) << endl;}else{cout << FALSE__ << endl;}
#define YES(f) if((f)){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(f) if((f)){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))

#define RS resize
#define CINV(v, N) do {\
	v.RS(N);\
	rep(i, N) cin >> v[i];\
} while (0);
#define RCINV(v, N) do {\
	v.RS(N);\
	rrep(i, N) cin >> v[i];\
} while (0);
#define fcout cout << fixed << setprecision(12)

#define MOD 1000000007

template<class T>
inline T GET() {
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

int H, W;

vector<vector<int>> m;
vector<vector<bool>> h;
int dr[] = {-1, 0, 1, 0};
int dc[] = { 0, 1, 0, -1};

vector<int> dfs(int r, int c, int k = -1)
{
	auto v = vector<int>(2, 0);
	if (!RANGE2D(0, 0, r, c, H, W) || h[r][c] || (k != -1 && m[r][c] + k != 1)) {
		return v;
	}
	h[r][c] = true;
	v[m[r][c]]++;
	rep(i, 4) {
		auto t = dfs(r+dr[i], c+dc[i], m[r][c]);
		v[0] += t[0];
		v[1] += t[1];
	}
	return v;
}

void init()
{
	cin >> H >> W;
	m.RS(H, vector<int>(W));
	h.RS(H, vector<bool>(W, false));
	rep(i, H) {
		rep(j, W) {
			char c;
			cin >> c;
			m[i][j] = c == '#';
		}
	}
}

void solve()
{
	int res = 0;
	rep(i, H) {
		rep(j, W) {
			auto v = dfs(i, j);
			res += v[0] * v[1];
		}
	}
	cout << res << endl;
}




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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long
#define MOD 1e9+7
#define MAX_V
const double PI=3.14159265358979323846;

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
#define print_line(vec, n) {for(int i=0;i<(n-1);i++) cout << (vec)[i] << " "; cout << (vec)[(n)-1] << endl;}
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain; 

ll dp[100001];

int main(){
    int N, W;
    cin >> N >> W;
    vector<int> w(N), v(N);
    REP(i, N) cin >> w[i] >> v[i];

    REP(i, N) REP_REV(j, W+1) {
        if(j < w[i]) {
            dp[j] = dp[j];
        } else {
            dp[j] = max(dp[j], dp[j-w[i]] + v[i]);
        }
    } 

    cout << dp[W] << endl;

    return 0;
}

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

int main(){
	int n; cin >> n;
  	string s; cin >> s;
  	if (n % 2 != 0){
    	cout << "No"; return 0;
    }
  	cout << (s.substr(0, n / 2) == s.substr(n / 2, n / 2) ? "Yes" : "No");
}

Measured memory_bytes: 256
#include<stdio.h>
#define true 1
#define false -1

int A(int x,int y);

int a[2000],b[2000],c;

int main(){
    int d,e,i;
    char f[2][4]={"yes","no"};
    
    scanf("%d",&c);
    for(i=0;i<c;i++){
        scanf("%d",&a[i]);
    }
    
        scanf("%d",&d);
    for(i=0;i<d;i++){
        scanf("%d",&b[i]);
    if(A(0,b[i])==true){
        printf("%s\n",f[0]);
    }else{
        printf("%s\n",f[1]);
    }
    }
    return 0;
}

int A(int x,int y){
    int z;
    if(y==0){
        return true;
    }
    if(x>=c){
        return false;
    }
    if(A(x+1,y)==true){
        z=true;
    }else if(A(x+1,y-a[x])==true){
        z=true;
    }else{
        z=false;
    }
    return z;
}


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

using int64 = long long;
constexpr int64 kMod = 1000000007;

int main() {
  int64 n, k;
  cin >> n >> k;

  int64 ret = 0;
  for (int64 i = k; i <= n + 1; ++i) {
    int64 low = i * (i - 1) / 2;
    int64 up = n * (n + 1) / 2 - (n - i) * (n - i + 1) / 2;
    ret = (ret + up - low + 1) % kMod;
  }
  cout << ret << "\n";

  return 0;
}


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

using namespace std;

#define PI 3.1415926535897932

int main(){
    long long n,m,ans=0;
    scanf("%lld %lld",&n,&m);
    ans=(n*2<=m?n:m/2)+(n*2<=m?(m-n*2)/4:0);
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define DEBUG true
#ifdef ONLINE_JUDGE
#undef DEBUG
#define DEBUG false
#endif 

using namespace std;

#define MAXN ((int)2e5+5)
#define MOD ((int)1e9 + 7)
#define INF ((int)1e9 + 9)
#define ll long long
#define _ << " " <<
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define TRACE(x) if(DEBUG) cerr << #x << " = " << x << endl;
#define TRACE2(x,y) if(DEBUG) cerr << #x << " = " << x << " | " << #y << " = " << y << endl;
#define pb push_back
#define all(x) x.begin(), x.end()
#define endl "\n"
#define pii pair<int,int>
#define mid ((l+r)/2)

string s,t;

ll ct = 0;

map <char,vector<int>> mp;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(0);
	cin >> s >> t;

	for (int i = 0; i < s.size(); ++i)
		mp[s[i]].pb(i);

	for (int i = 0; i < t.size(); ++i)
		if(!mp.count(t[i]))
		{
			cout << -1 << endl;
			return 0;
		}

	int idx = 0;

	for (int i = 0; i < t.size(); ++i)
	{
		auto it = lower_bound(all(mp[t[i]]), idx);
		int index = it - mp[t[i]].begin();

		// TRACE2(i, index);
		// TRACE2(i, mp[t[i]][index]);

		if(index == mp[t[i]].size())
		{
			idx = 0;
			i--;
			ct++;
		}
		else
			idx = (mp[t[i]][index]+1);
	}

	// TRACE2(ct, s.size());

	ll ans = ct * s.size();
	ans += idx;

	cout << ans << endl;
}

Measured memory_bytes: 1228
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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

using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define EPS (1e-10)
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e16;
#define int long long

const int MAX_N = 1010;


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE s(n); int sum = 0;
	rep(i, n)cin >> s[i];
	rep(i, n)sum += s[i];
	sort(ALL(s));
	if (sum % 10 == 0) {
		rep(i, n) {
			if (s[i] % 10 != 0) {
				cout << sum - s[i] << endl; return 0;
			}
		}	
		cout << 0 << endl;
	}
	else {
		cout << sum << endl;
	}
	return 0;
}


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

#define pb push_back
#define fi first
#define se second
typedef long long ll;

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

	ll h, w;
	cin >> h >> w;
		
	ll first_row = w / 2 + w % 2;
	ll second_row = w / 2;

	if (h == 1 || w == 1)
		cout << "1\n";
	else
		cout << (h / 2 + h % 2) * first_row + (h / 2) * second_row << '\n';
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef pair<int, int> P;
//Pのfirstは最短距離 secondは頂点
const int INF = 10e8;

struct edge {int to, cost; };
int V, E;
vector<edge> G[100000];
int d[100000];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P>> que;
  fill(d, d + V, INF);
  d[s] = 0;
  que.push(P(0, s));

  while(que.size() != 0){
    P p = que.top(); que.pop();
    int v = p.second; // 取り出した頂点
    if(d[v] < p.first) continue;
    for(int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if(d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }

  }
}

int main(){
  int s;
  cin >> V >> E >> s;
  rep(i, E){
    int a, b, c;
    cin >> a >> b >> c;
    edge e = {b, c};
    G[a].push_back(e);
  }
  dijkstra(s);
  rep(i, V){
    if(d[i] == INF){
      cout << "INF";
    }else{
      cout  << d[i];
    }
    cout << endl;
  }
}



Measured memory_bytes: 13032
def orderN(N,L,ices):
    upPeak = L - ices[0]
    downPeak = L - ices[0]
    peaks = []
    for i in xrange(len(ices)):
        if i < N-1:
            if ices[i] < ices[i+1]:
                peaks.append(downPeak)
                downPeak = L - ices[i+1]
                upPeak += L - ices[i+1]
            else:
                peaks.append(upPeak)
                upPeak = L - ices[i+1]
                downPeak += L - ices[i+1]
        else:
            peaks.append(upPeak)
            peaks.append(downPeak)
    print(max(peaks))

N,L = map(int,raw_input().strip().split())
ices = [int(raw_input().strip()) for _ in xrange(N)]

orderN(N,L,ices)

Measured memory_bytes: 12584
// D - Practical Skill Test
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rp(i,n) for(int i=0;i<(n);++i)

int main(){
	int H,W,D; cin>>H>>W>>D;

	int MAX = H * W;
	vi HH(MAX+1), WW(MAX+1), DD(MAX+1);

	rp(h, H){
		rp(w, W){
		int a; cin>>a;
		HH[a] = h+1; WW[a] = w+1;
		}
	}

	for(int pre=1; pre<MAX; ++pre){
		int now = pre + D;
		if(now > MAX) break;
		DD[now] = DD[pre]
			+ abs(HH[pre] - HH[now])
			+ abs(WW[pre] - WW[now]);
	}

	int Q; cin>>Q;
	while(Q--){
		int l,r; cin>>l>>r;
		cout<< DD[r] - DD[l] <<endl;
	}
}

Measured memory_bytes: 2176
s=input()

count=0
i=0
A=0
while count==0:
    if s[i]=='A':
        count+=1
        A=i
    i+=1

count2=0
j=len(s)-1
Z=0
while count2==0:
    if s[j]=='Z':
        count2+=1
        Z=j
    j-=1

print(Z-A+1)
        

Measured memory_bytes: 3516
import java.util.Scanner;

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

		for (int i =  1;;i++){
			int x = sc.nextInt();
			if(x == 0){
				break;
			}
			System.out.println("Case " + i + ": " + x);
		}
	}
}


Measured memory_bytes: 41908
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"
#include "set"
#include "stack"
#include "tuple"

#define rep(n) for (int i = 0; i < n; ++i)
#define REP(n,i) for (int i = 0; i < n; ++i)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nyan "(=^･ω･^=)"
#define mkp make_pair
#define mkt make_tuple
#define P pair<ll, ll>
#define iP pair<int,int>
typedef long long ll;
using namespace std;

int n,m,q,a,b,v,d,c;
vector<int>V[100000];
iP g[100000][11];

int main() {
	cin>>n>>m;
	rep(n){
		REP(11,j)
			g[i][j]=mkp(-1,0);
		V[i].push_back(i);
	}
	rep(m){
		cin>>a>>b;
		V[a-1].push_back(b-1);
		V[b-1].push_back(a-1);
	}
	cin>>q;
	rep(q){
		cin>>v>>d>>c;
		g[v-1][d]=mkp(i,c);
	}
	for(int i=9;i!=-1;--i){
		REP(n,j){
			REP(V[j].size(),k){
				if(g[V[j][k]][i].first<g[j][i+1].first)
					g[V[j][k]][i]=g[j][i+1];
			}
		}
	}
	rep(n)
		cout<<g[i][0].second<<endl;
	return 0;
}


Measured memory_bytes: 15232
n = int(input())
a = str(input())
b = str(input())
c = str(input())

p = 0
for i in range(n):
    t = 0
    if(a[i] != b[i]):
        t += 1
    if(b[i] != c[i]):
        t += 1
    if(a[i] != c[i]):
        t += 1

    if(t == 3):
        p += 2
    elif(t == 0):
        pass
    else:
        p += 1
print(p)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rrep(i,n) rrepi(i,n,0)
#define rrepi(i,a,b) for(int i=int(a);i>int(b);--i)


#define all(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define show(v) rep(i,v.size()){cout<<v[i]<<" ";}cout<<endl;
#define MOD 1000000007
using ll = long long;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }



void Main() {
	int n; cin >> n;
	vector<int > v;
	int a;
	rep(i, n) {
		cin >> a; v.push_back(a);
	}
	sort(all(v)); reverse(all(v));
	//show(v);
	int ans = 0;
	rep(i, n - 2) {
		repi(j, i + 1, n - 1) {
			repi(k, j + 1, n) {
				if (v[i] + v[j] > v[k] && v[j] + v[k] > v[i] && v[k] + v[i] > v[j]) {
					ans++;
					//cout << v[i] << v[j] << v[k] << endl;

				}
			}
		}
	}
	cout << ans;
	//rep(i, n)cout << v[i];
}


int main() {
	Main();

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    string s;
    cin>>s;
    string t="CODEFESTIVAL2016";
    int ans=0;
    rep(i,s.size()){
        if(s[i]!=t[i])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    
    //*
    int a;
    cin >> a ;
    //*/

    /*
    vector<int> vec(3);
    cin >> vec.at(0) >> vec.at(1) >> vec.at(2) ;
    
    sort(vec.begin(), vec.end());
    */
    
    //*
    if( a < 1200 ){
        cout << "ABC" << endl;
    } else if (a < 2800) {
        cout << "ARC" << endl;
    } else {
        cout << "AGC" << endl;
    }
    //*/
    
    //cout << vec.at(2) - vec.at(0) << endl;

    return 0; 
}


Measured memory_bytes: 3540
N = int(input().strip())

keta = len(str(N))

count = 0

if N >= 10:
  
  count += 9
  
  for i in range(3, keta, 2):
    count += (10 ** (i) - 10 ** (i - 1))

  if (keta  % 2) != 0:
    count += (N - 10 ** (keta - 1) + 1)
  
else:
  count = N
  
print(count)

Measured memory_bytes: 3060
// Author:Eleus Ahammad, CSE, KUET
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define vii vector<pii>
#define vi vector<int>
#define F first
#define S second
#define endl "\n"
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ifile freopen("input.txt", "r", stdin)
#define ofile freopen("output.txt", "w", stdout)
#define MOD 1000000007
using namespace std;
ll gcd(ll a, ll b)
{
    if (b == 0) return a;
    return gcd(b, a%b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b);}
ll modpow(ll a, ll b, ll m)
{
    if (b == 0) return 1%m;
    ll u = modpow(a, b / 2, m);
    u = (u * u)%m;
    if (b%2) u = (a * u)%m;
    return u;
}
ll egcd(ll a, ll b, ll &x, ll &y)
{
    if (b == 0) {
        x = 1, y = 0;
        return a;
    }
    ll x1, y1;
    ll d = egcd(b, a%b, x1, y1);
    x = y1;
    y = x1 - y1 * (a / b);
    return d;
}
// Code begins here

void solve()
{
    int k;
    cin >> k;
    if (k <= 9) cout << k << endl;
    else {
        int cnt = 9;
        queue<ll> q;
        for (int i = 1; i <= 9; i++) q.push(i);
        bool ok = false;
        while (!ok) {
            ll d = q.front();
            for (int i = -1; i <= 1; i++) {
                ll m = d%10 + i;
                if (m < 0 || m > 9) continue;
                m = d * 10 + m;
                q.push(m);
                if (++cnt == k) {
                    ok = true;
                    break;
                }
            }
            q.pop();
        }
        cnt = q.size();
        for (int i = 1; i < cnt; i++) q.pop();
        cout << q.front() << endl;
    }
}


int main()
{
    fastio;
    int t = 1;
    //cin >> t;

    while (t--) {
        solve();
    }
}



Measured memory_bytes: 768
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;

int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a==c)cout<<b<<endl;
	if(b==c)cout<<a<<endl;
	if(a==b)cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_A main
#include "bits/stdc++.h" 
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
// functions

#endif

int main_A() {
    cin.tie(0);
    ios::sync_with_stdio(false);
     
    int M, D; cin >> M >> D;
    
    int ans = M - 1;
    if (D >= M) ans++;

    cout << ans << endl;

    return 0;
}

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


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

    ll n,m;
    cin >> n>> m;
    vector<vector<int>> gra(n);
    int a,b;
    for (int i = 0; i < m; i++) {
        cin >> a >> b;
        a--;b--;
        gra[a].push_back(b);
        gra[b].push_back(a);

    }
    vector<int> ans(n,-1);
    queue<int> que;
    int tmp=0;
    que.push(tmp);
    while (que.size()) {
        tmp = que.front();que.pop();
        for (int i = 0; i<gra[tmp].size(); i++) {
            int k = gra[tmp].at(i);
            if (ans.at(k)==-1) {
                que.push(k);
                ans.at(k) = tmp+1;
            }
        }
    }
    if (*min_element(ans.begin()+1, ans.end()) != -1) {
        cout<< "Yes"<<endl;
        for(int i=1;i<n;i++){
            cout<< ans.at(i) << endl;
        }
    }else{
        cout<<"No"<<endl;
    }


    return 0;
}


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

using namespace std;

int main()
{
    //C-step
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++){
        int val;
        cin>>val;
        a[i]=val;
    }
    long long height=0;
    for(int i=0;i<n-1;i++){
        if(a[i+1]>=a[i]){
            continue;
        }
        int stool=a[i]-a[i+1];
        a[i+1]+=stool;

        height+=stool;
    }

    cout<<height;

    }

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=1;i<(int)s.size();i++){
		if(s[i] == s[i-1]){cout<<"Bad"<<endl;;
		return 0;
		}
	}
	cout<<"Good"<<endl;
	return 0;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B

main :: IO ()
main = do
  s <- B.getLine
  B.putStrLn . toString . none' $ s

none'
  :: B.ByteString -> Maybe Char
none' x 
  = if B.null fx then Nothing
                 else Just $ B.head fx
  where
    fx = B.dropWhile (`B.elem` x) $ B.pack ['a' .. 'z']

toString
  :: Maybe Char -> B.ByteString
toString (Just c) = B.singleton c
toString Nothing  = B.pack "None"

Measured memory_bytes: 636
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll; typedef vector<int> vi; typedef vector<ll> vll;
template<class T>using vv = vector<vector<T>>; template<class T>auto vvec(int n, int m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 29, MOD = int(1e9) + 7; constexpr ll LINF = 1LL << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10); }; }aaaa;

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

    int all = 0;
    rep(i, N) {
        all += L + i;
    }

    int ans = -1;
    int diff = INF;
    rep(i, N) {
        int taste = all - (L + i);
        if (chmin(diff, abs(all - taste))) {
            ans = taste;
        }
    }
    write(ans);
}

Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <vector>


using namespace std;
const long long DIV = 1e9 + 7;


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

    long long max_item = -1001001001;
    for (auto item: a) max_item = max(max_item, item);
    if (max_item == 0) {
        cout << 0 << endl;
        return 0;
    }

    long long k = log2(max_item) + 1;
    vector<long long> ct(k, 0);

    for (long long t=0; t<n; t++) {
        for (long long i=k; i>0; i--) {
            if (1 & a[t]>>(i-1)) {
                ct[i-1]++;
            }
        }
    }


    long long ans = 0;
    long long coe = 1;

    for (int i=0; i<k; i++) {
        long long _ans = (ct[i] * (n - ct[i])) % DIV;
        ans += (coe * _ans) % DIV;
        ans %= DIV;
        coe *= 2;
        coe %= DIV;
    }

    ans %= DIV;
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 2560
#include<stdio.h>

int main(void) {
   int A, B;
   int add, sub, mul;
   int max;

   scanf("%d%d", &A, &B);
   add = A + B;
   sub = A - B;
   mul = A * B;

   max = add;
   if(sub > max) {
      max = sub;
   }
   if(mul > max) {
      max = mul;
   }
   printf("%d\n", max);
   return 0;
}

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

int main(){
  int N,K;
  int num[100];
  int bootstrap[100][100];
  bool bs[100][100];
  cin >> N>> K;
  for(int i=0;i<100;i++)for(int j=0;j<100;j++)bs[i][j] = false;

  for(int i=0;i<K;i++){
    cin >> num[i]; 
    for(int j=0;j<num[i];j++){
      cin >> bootstrap[i][j];
    }
  }
  int how,p,q;
  bool pt,qt;
  int pp,qp;
  pt = qt =false;
  cin >>how;
  for(int i=0;i<how;i++){
    cin >> p >> q;
    
    for(int j=0;j<K;j++){
      for(int k=0;k<num[j];k++){
	
	if(p == bootstrap[j][k]){
	  pt = true;
	  pp = k;
	}
	if(q == bootstrap[j][k]){
	  qt = true;
	  qp = k;
	}
      }
      if(pt && qt){
	bs[j][pp] = bs[j][qp] = true;
      }
      pt = qt = false;
    
    }
       

  }

  
  int Ans = 0;
  for(int j=0;j<K;j++){
    for(int k=0;k<num[j];k++){
	if(bs[j][k])Ans++;
    }
  }
  cout << Ans << endl;
  

  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
        
        int a = stdIn.nextInt();
        int b = stdIn.nextInt();
        //int c = stdIn.nextInt();
        //int w = stdIn.nextInt();
        //int n = stdIn.nextInt();
        //int k = stdIn.nextInt();
        //String s = stdIn.next();
        //char c[] = s.toCharArray();
        //boolean heisei = true;
        
        if(b % a == 0){
            System.out.println(a + b);
        }else{
            System.out.println(b - a);
        }
        
        //System.out.println();
        //System.out.print();
    }
}


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

#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <math.h>

int main() {

    long long int x, n;
    cin >> x >> n;

    vector< long long int > p( n );
    for ( long long int i = 0; i < n; i++ ) {
        cin >> p[i];
    }
    for ( long long int i = 0;; i++ ) {
        long long int k = x - i;
        bool f = true;
        for ( long long int j = 0; j < n; j++ ) {
            if ( p[j] != k ) continue;
            f = false;
            break;
        }
        if ( f ) {
            cout << k << endl;
            return 0;
        }
        k = x + i;
        f = true;
        for ( long long int j = 0; j < n; j++ ) {
            if ( p[j] != k ) continue;
            f = false;
            break;
        }
        if ( f ) {
            cout << k << endl;
            return 0;
        }
    }

    return 0;

}


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

using namespace std;

int main() {
  string S;
  cin >> S;
  int answer = 1000;
  for (int i = 0; i + 2 < S.length(); i++) {
    istringstream iss(S.substr(i, 3));
    int num;
    iss >> num;
    answer = min(answer, abs(753 - num));
  }
  cout << answer;
  return 0;
}


Measured memory_bytes: 256
n=int(input())

num_list = []
for i in range(n):
    num_list.append(list(map(int,input().split())))

flag_a=0
flag_b=0
for i in range(n):
  if num_list[i][0]==num_list[i][1] :
    flag_a+=1
  else:
    flag_a=0
  
  if flag_a==3:
    flag_b=1
    
if flag_b==1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9112
#include <iostream>

int main(){
    
    int m, f, r;
    while(std::cin >>  m >> f >> r){
        if( m+f+r == -3 ){
            std::cout << std::flush;
        }else if( m==-1 || f==-1 ){
            std::cout << "F" << "\n";
        }else if( m + f >= 80){
            std::cout << "A" << "\n";
        }else if( m + f >= 65){
            std::cout << "B" << "\n";
        }else if( m + f >= 50){
            std::cout << "C" << "\n";
        }else if( m + f >= 30){
            if(r >= 50){
                std::cout << "C" << "\n";
            }else{
                std::cout << "D" << "\n";
            }
        }else{
            std::cout << "F" << "\n";
        }
    }
    
    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = 10e10;
const ll MINF = -10e10;
//const int INF = INT_MAX;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

typedef priority_queue<P, vector<P>, greater<P> > PQ_ASK;
const int mod = 1000000007;
//ifstream myfile("C:\\Users\\riku\\Downloads\\01.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;

int gcd(ll x, ll y) {
    if (x < y) swap(x, y);
    if (y == 0) {
        return x;
    }
    return gcd(y, x % y);
}

int main() {
    int h, w;
    cin >> h >> w;

    vector<vector<int>> board(w, vector<int>(h, -1));

    rep(y, h) rep(x, w) cin >> board[x][y];

    vector<vector<int>> ans;

    int x = 0, y = 0;
    for (int i = 0; i < (h * w) - 1; i++) {

        int next_x;
        int next_y;

        if (i % w == (w - 1)) {
            // 下
            next_x = x;
            next_y = y + 1;
        } else if (i / w % 2 == 0) {
            // 右
            next_x = x + 1;
            next_y = y;
        } else {
            // 左
            next_x = x - 1;
            next_y = y;
        }
//        printf("(%d, %d) (%d, %d)\n", x, y, next_x, next_y);

        if (board[x][y] % 2 == 1) {
            board[next_x][next_y]++;
            vector<int> now = {x + 1, y + 1, next_x + 1, next_y + 1};
            ans.push_back(now);
        }

        x = next_x;
        y = next_y;

    }
    cout << ans.size() << endl;
    for (auto a : ans) {
        printf("%d %d %d %d\n", a[1], a[0], a[3], a[2]);
    }

}


Measured memory_bytes: 10032
#include <iostream>
using namespace std;
typedef long long ll;
ll n, z, a[3000];
int main(void){
    // Your code here!
    cin >> n >> z;
    for (ll i = 0; i <= n; i++) cin >> a[i];
    cout << max(abs(a[0] - a[n]), abs(a[n - 1] - a[n])) << endl;
}


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

int main()
{
    int N;
    int res = 32;
    cin >> N;
    for(int i = 0; i < N; ++i){
        int a, tmp = 0; 
        cin >> a;
        while(a%2 == 0) { a /= 2; ++tmp; }
        res = min(res, tmp);
    }
    cout << res << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
#define REP(i,n) for(ll i = 0;i < (ll)n;i++)
#define REPD(i,n) for(ll i = (ll)n - 1;i >= 0;i--)
#define ALL(x) (x).begin(),(x).end()
#define FILLl(n,first_dimension_size,value) fill((ll*)n,(ll*)(n+first_dimension_size),value)
#define FILL(n,first_dimension_size,value) fill((int*)n,(int*)(n+first_dimension_size),value)
#define INF (1 << 29)
#define MOD 1000000007
//int dx[4] = {1,0,0,-1};
//int dy[4] = {0,1,-1,0};


int main(){
  
  int a,b,c;
  cin >> a >> b >> c;
  cout << min(b/a,c) << endl;



  return 0;
}


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

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int N, M, X; cin >> N >> M >> X;

    vector<int> A(M);
    for(int i = 0; i < M; i++) cin >> A[i];

    int sum0 = 0;
    int sum1 = 0;
    for(int i = 0; i < M; i++){
        if(A[i] < X) sum0++;
        else sum1++;
    }

    cout << min(sum0, sum1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

typedef struct{
	char name[13];
	int time;
}data;
int head,tail;

void Enqueue(data* q, data d){
	int pos=tail%100000;
	q[pos]=d;
	tail++;
}
void Dequeue(data* q){
	head++;

}
data Front(data* q){
	int pos=head%100000;
	return q[pos];
}

int main(){
	int totalTime=0,n,q,i;	scanf("%d%d",&n,&q);
	data Q[100000];
	head=tail=0;

	data tmp;
	for(i=0;i<n;i++){
		scanf("%s%d",&(tmp.name),&(tmp.time));
		Enqueue(Q,tmp);
	}

	while(head!=tail){
		tmp=Front(Q);	Dequeue(Q);
		if(tmp.time<=q){
			totalTime+=tmp.time;
			printf("%s %d\n",tmp.name, totalTime);
		}else{
			totalTime+=q;
			tmp.time-=q;
			Enqueue(Q,tmp);
		}
	}

	return 0;
}



Measured memory_bytes: 4664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1e18;
const ll mod = 1e9+7;
#define rep(i,n) for(int i = 0;i<n;i++)

int main(){
	int A,B,C,k;
	cin >> A >> B >> C >> k;
	bool flag = false;

	vector<int>a_bi(k+1);
	vector<int> b_bi(k+1);
	vector<int> c_bi(k+1);
	a_bi[0] = A;
	b_bi[0] = B;
	c_bi[0] = C;

	for(int i = 1; i<= k; i++){
		a_bi[i] = a_bi[i-1]*2;
		b_bi[i] = b_bi[i-1]*2;
		c_bi[i] = c_bi[i-1]*2;
	}

	for(int a=0; a<=k; a++){
		for(int b = 0; b <= k-a; b++){
			for(int c = 0; c <= k-b-a;c++){
				A = a_bi[a];
				B = b_bi[b];
				C = c_bi[c];
				//cout << a << "," << b << "," << c << ":";
				//cout << A << "," << B << "," << C << endl;
				if(C > B && B > A){
					cout << "Yes" << endl;
					return 0;
				}
			}
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3624
#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 fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

void _main() {
  int A, B, C, K;
  cin >> A >> B >> C >> K;
  int a[3] = {A, B, C};
  sort(a, a + 3);
  int ans = a[0] + a[1] + (a[2] << K);
  cout << ans << "\n";
}

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

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector <int> bad(10, false);
    for (int i = 0; i < k; i++) {
        int x;
        cin >> x;
        bad[x] = true;
    }
    auto ok = [&] (int x) {
        while (x > 0) {
            if (bad[x % 10]) {
                return false;
            }
            x /= 10;
        }
        return true;
    };
    while (true) {
        if (ok(n)) {
            cout << n << '\n';
            break;
        }
        n++;
    }
    return 0;
}

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

int main() {
   int n;
   cin >> n;
   vector<int> p(n);
   rep(i, n) cin >> p[i];
   int m = p[0];
   int ans = 1;
   for (int i = 1; i < n; i++) {
      m = min(p[i], m);
      if (p[i] <= m) {
         ans++;
      }
   }
   cout << ans << endl;
   return 0;
}

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

int main(){
	int n, m, k; cin >> n >> m >> k;
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= m; ++j){
			if(i * m + j * n - 2 * i * j == k){
				cout << "Yes\n";
				return 0;
			}
		}
	}
	cout << "No\n";
	return 0;
}

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

int main(){
  int N, X, i, sum = 0, kosuu = 0;
  int a[N];
  cin >> N >> X;
  for(i = 0 ; i <= N; i++){
    cin >> a[i];
    sum += a[i];
  }
  sort(a, a+N);
  for (int j = 1 ; j * a[0] <= X-sum ;j++){
    kosuu ++;
  }
  cout << N + kosuu << endl;
}


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

int main(){
    int n;
    long long ans,m;
    cin >> n;
    for (int i=0;i<n;i++){
        long long cur;
        cin >> cur;
        if (i==0){
            ans = -1000000000;
            m = cur;
        }else{
            ans = max(ans,cur-m);
            m = min(cur,m);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3092
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut s = Vec::new();
    for _ in 0..n {
        s.push(read::<String>().chars().collect::<Vec<_>>());
    }

    let mut ans = 0;
    for i in 0..n {
        for j in 0..s[i].len() - 1 {
            if s[i][j] == 'A' && s[i][j + 1] == 'B' {
                ans += 1;
            }
        }
    }
    let mut end_with_a_count = 0;
    let mut start_with_b_count = 0;
    let mut both = 0;

    for i in 0..n {
        if s[i][0] == 'B' && s[i][s[i].len() - 1] == 'A' {
            both += 1;
        } else if s[i][0] == 'B' {
            start_with_b_count += 1;
        } else if s[i][s[i].len() - 1] == 'A' {
            end_with_a_count += 1;
        }
    }

    ans += min(end_with_a_count, start_with_b_count);
    if end_with_a_count == start_with_b_count {
        if end_with_a_count == 0 {
            ans += max(both - 1, 0);
        } else {
            ans += both;
        }
    } else if end_with_a_count > start_with_b_count {
        end_with_a_count -= start_with_b_count;
        if both <= end_with_a_count {
            ans += both;
        } else {
            ans += end_with_a_count;
            both -= end_with_a_count;
            ans += both;
        }
    } else {
        start_with_b_count -= end_with_a_count;
        if both < start_with_b_count {
            ans += both;
        } else {
            ans += start_with_b_count;
            both -= start_with_b_count;
            ans += both;
        }
    }
    println!("{:?}", ans);
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}


Measured memory_bytes: 4352
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
typedef long long ll;
typedef double dd;
#define For(i,j,k) for (int i=(int)j;i<=(int)k;++i)
#define Forr(i,j,k) for (int i=(int)j;i>=(int)k;--i)
#define Set(a,p) memset(a,p,sizeof(a))
using namespace std;

template<typename T>bool chkmax(T &a,T b) { return a<b?a=b,1:0; }
template<typename T>bool chkmin(T &a,T b) { return a>b?a=b,1:0; }

int cnt;

inline void file() {
	freopen("ARC099D.in","r",stdin);
	freopen("ARC099D.out","w",stdout);
}

inline int Divide(ll n) {
	int sum=0; cnt=0;
	while (n) {
		sum+=n%10; ++cnt; n/=10;
	}
	return sum;
}

inline ll calc(ll n) {
	ll k=1,m,Ans=n;
	dd ans=1.0*n/Divide(n);
	For (i,1,cnt) {
		k*=10; m=(n/k)*k+k-1;
		if (chkmin(ans,1.0*m/Divide(m))) Ans=m;
	}
	return Ans;
}

int main() {
//	file();
	ll n; scanf("%lld",&n);
	for (ll i=1;n--;i=calc(i+1)) printf("%lld\n",i);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_N 1000000
typedef unsigned long long ull;
using namespace std;

int n, k;
int Rank[MAX_N + 1];
int tmp[MAX_N + 1];

bool Compare_SA(int i, int j) {
	if (Rank[i] != Rank[j]) return Rank[i] < Rank[j];
	else {
		int ri = i + k <= n ? Rank[i + k] : -1;
		int rj = j + k <= n ? Rank[j + k] : -1;
		return ri < rj;
	}
}

void Construct_SA(const string &S, vector<int> &SA) {
	n = S.length();
	SA = vector<int>(n + 1);

	for (int i = 0; i <= n;i++) {
		SA[i] = i;
		Rank[i] = i < n ? S[i] : -1;
	}

	for (k = 1; k <= n; k *= 2) {
		sort(SA.begin(), SA.end(), Compare_SA);

		tmp[SA[0]] = 0;
		for (int i = 1; i <= n; i++) {
			tmp[SA[i]] = tmp[SA[i - 1]] + (Compare_SA(SA[i - 1], SA[i]) ? 1 : 0);
		}
		for (int i = 0; i <= n; i++) {
			Rank[i] = tmp[i];
		}
	}
}

bool Contain(const string &S, const vector<int> &SA, const string &T) {
	int a = 0, b = S.length();
	while (b - a > 1) {
		int c = (a + b) / 2;
		if (S.compare(SA[c], T.length(), T) < 0) a = c;
		else b = c;
	}
	return S.compare(SA[b], T.length(), T) == 0;
}

int main()
{
	int Q;
	string T, P;
	vector<int> SA;
	cin >> T;
	Construct_SA(T, SA);
	cin >> Q;
	while (Q--) {
		cin >> P;
		cout << Contain(T, SA, P) << endl;
	}
	return 0;
}

Measured memory_bytes: 15728