akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {
	private static FastScanner sc = new FastScanner();

	public static void main(String[] args) {
		int q = sc.nextInt();
		
		for(int i=1; i<=q; i++) {
			char[] X = sc.next().toCharArray();
			char[] Y = sc.next().toCharArray();
			
			int[][] LCS = new int[X.length+1][Y.length+1];
			
			for(int j=1; j<=X.length; j++) {
				for(int k=1; k<=Y.length; k++) {
					if(X[j-1] == Y[k-1]) {
						LCS[j][k] = LCS[j-1][k-1] + 1;
					} else {
						LCS[j][k] = Math.max(LCS[j-1][k], LCS[j][k-1]);
					}
				}
			}
			
			System.out.println(LCS[X.length][Y.length]);
		}
	}

	static class FastScanner {
	    private final InputStream in = System.in;
	    private final byte[] buffer = new byte[1024];
	    private int ptr = 0;
	    private int buflen = 0;
	    private boolean hasNextByte() {
	        if (ptr < buflen) {
	            return true;
	        }else{
	            ptr = 0;
	            try {
	                buflen = in.read(buffer);
	            } catch (IOException e) {
	                e.printStackTrace();
	            }
	            if (buflen <= 0) {
	                return false;
	            }
	        }
	        return true;
	    }
	    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
	    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
	    private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
	    public boolean hasNext() { skipUnprintable(); return hasNextByte();}
	    public String next() {
	        if (!hasNext()) throw new NoSuchElementException();
	        StringBuilder sb = new StringBuilder();
	        int b = readByte();
	        while(isPrintableChar(b)) {
	            sb.appendCodePoint(b);
	            b = readByte();
	        }
	        return sb.toString();
	    }
	    public long nextLong() {
	        return Long.parseLong(next());
	    }
	    public int nextInt(){
	    	return Integer.parseInt(next());
	    }
	}
}

Measured memory_bytes: 63500
#include <iostream>
#include <cmath>
using namespace std;
int main(){
    long long n;
    int k;
    cin >> n >> k;
    long long th = 1;
    for(long long i = 1;; i++){
        if(n < th) {
            cout << i - 1;
            break;
        }
        else th *= k;
    }
    return 0;
}

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

#define     F       first
#define     S       second
typedef pair<int, int>  pi;
typedef long long       ll;

const int MAX=2e5+9;
const int MOD=1000000007;
int n, k;
vector<int> pos, choosedPos;
vector<int> neg, choosedNeg;

ll Calculate() {
    ll ans=1;
    for (int i=0; i<choosedNeg.size(); ++i) {
        ans*=-choosedNeg[i];
        ans%=MOD;
    }

    for (int i=0; i<choosedPos.size(); ++i) {
        ans*=choosedPos[i];
        ans%=MOD;
    }

    return ans;
}

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

    cin >> n >> k;
    while (n--) {
        int a;
        cin >> a;

        if (a>=0)       pos.push_back(a);
        else            neg.push_back(-a);
    }

    sort(pos.begin(), pos.end());
    sort(neg.begin(), neg.end());

    // max 2x negative
    while (choosedNeg.size()+1<k && neg.size()>=2) {
        choosedNeg.push_back(neg.back());
        neg.pop_back();

        choosedNeg.push_back(neg.back());
        neg.pop_back();
    }

    // fill by positive
    while (choosedNeg.size()+choosedPos.size()<k && !pos.empty()) {
        choosedPos.push_back(pos.back());
        pos.pop_back();
    }

    if (choosedPos.size()+choosedNeg.size()<k) { // must choose one neg
        vector<int> v;

        // undo
        while (!choosedNeg.empty()) {
            v.push_back(choosedNeg.back());
            choosedNeg.pop_back();
        }

        // undo
        while (!choosedPos.empty()) {
            v.push_back(choosedPos.back());
            choosedPos.pop_back();
        }

        while (!neg.empty()) {
            v.push_back(neg.back());
            neg.pop_back();
        }

        // choose min k elements by absolute value
        sort(v.begin(), v.end());
        for (int i=0; i<k; ++i) {
            choosedPos.push_back(v[i]);
        }

        choosedPos[0]*=-1;
    }
    else {
        // greedy
        while (choosedNeg.size()>=2 && pos.size()>=2) {
            ll have=1LL*choosedNeg.back()*choosedNeg[choosedNeg.size()-2];
            ll can=1LL*pos.back()*pos[pos.size()-2];

            if (can>have) {
                choosedNeg.pop_back();
                choosedNeg.pop_back();

                choosedPos.push_back(pos.back());
                pos.pop_back();

                choosedPos.push_back(pos.back());
                pos.pop_back();
            }
            else {
                break;
            }
        }
    }

    ll ans=Calculate();
    while (ans<0) {
        ans+=MOD;
    }

    cout << ans;

    return 0;
}


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

using namespace std;

const int N = (int) 1e5 + 2;

int dp[N][3];

int main()
{
  int n;
  cin >> n;
  vector<int>a, b, c;
  for (int i = 0; i < n; i++) {
    int x, y, z;
    cin >> x >> y >> z;
    a.push_back (x);
    b.push_back (y);
    c.push_back (z);
  }
  dp[0][0] = a[0];
  dp[0][1] = b[0];
  dp[0][2] = c[0];
  for (int i = 1; i < n; i++) {
    dp[i][0] = max (dp[i][0], max (dp[i - 1][2], dp[i - 1][1]) + a[i]);
    dp[i][1] = max (dp[i][1], max (dp[i - 1][2], dp[i - 1][0]) + b[i]);
    dp[i][2] = max (dp[i][2], max (dp[i - 1][0], dp[i - 1][1]) + c[i]);
  }
  cout << max (dp[n - 1][0], max (dp[n - 1][1], dp[n - 1][2]) );
  return 0;
}


Measured memory_bytes: 2796
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
 
int main(){
  int n;
  cin>>n;
  vector<int>v(n);
  rep(i,n)cin>>v[i];
  sort(v.begin(),v.end());
  double ans=v[0];
  for(int i=1;i<n;i++){
    ans=(ans+v[i])/2;
  }
  printf("%.5f",ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>N;
    vec a(N*3), left_sum(N+1,0), right_sum(N+1,0);
    multiset<ll> left,right;
    rep(i,N*3) cin>>a[i];
    rep(i,N) {
        left.insert(a[i]);
        left_sum[0] += a[i];
    }
    reps(i,N*2, N*3) {
        right.insert(a[i]);
        right_sum[N] += a[i];
    }
    reps(i,N,N*2){
        left.insert(a[i]);
        left_sum[i - (N - 1)] = left_sum[i - N] + a[i] - *left.begin();
        left.erase(left.begin());
    }
    for(ll i = N*2 - 1; i >= N; --i){
        right.insert(a[i]);
        right_sum[i - N] = right_sum[i - N + 1] + a[i] - *right.rbegin();
        right.erase(--right.end());
    }
    ll ans = -(1e+15);
    rep(i,N+1) ans = max(ans, left_sum[i] - right_sum[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 13568
package main

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

func main() {
	a, b, c := getInt(), getInt(), getInt()
	x, y := getInt(), getInt()

	ans1 := a*x + b*y
	ans2 := c * max(x, y) * 2
	ans3 := func() int {
		if x > y {
			return c*y*2 + a*(x-y)
		}
		return c*x*2 + b*(y-x)
	}()

	ans := min(ans1, ans2, ans3)
	fmt.Println(ans)
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

// -----------------------------------------

var sc = bufio.NewScanner(os.Stdin)

func init() {
	// buf := 200001
	// sc.Buffer(make([]byte, buf), buf)
	sc.Split(bufio.ScanWords)
}

func getInt() int {
	i, err := strconv.Atoi(getString())
	if err != nil {
		panic(err)
	}
	return i
}

func getString() string {
	sc.Scan()
	s := sc.Text()
	return s
}


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

using namespace std;
using ll = long long;

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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << max(a*b,c*d) << endl;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

    int n,max,min,i,a;
    long long int sum=0;

    scanf("%d",&n);

    for(i=0;i<n;i++){

      scanf("%d",&a);

      if(i==0){ max = a; min = a; }

      if(max < a) max = a;
      if(min > a) min = a;

      sum += a;

    }

    printf("%d %d %lld\n",min,max,sum);

    return 0;

}


Measured memory_bytes: 2108
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)
using namespace std;
const ll MAX_N=2000,MOD=1e9+7;
ll K,N,A[MAX_N*2],cnt[MAX_N*2];
ll mpw(ll n,ll m){
	ll r=1;
	while(m){
		if(m&1){
			r*=n;
			r%=MOD;
		}
		n*=n;
		m>>=1;
		n%=MOD;
	}
	return r;
}
ll minv(ll n){
	return mpw(n,MOD-2);
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>N>>K;
	REP(i,N){
		cin>>A[i];
		A[i+N]=A[i];
	}
	REP(i,N*2){
		REP(j,i){
			if(A[j]>A[i]){
				cnt[i]++;
			}
		}
	}
	ll ans=0;
	REP(i,N){
		ll d=cnt[i+N]-cnt[i];
		ans+=(2*cnt[i]+(K-1)*d)%MOD*K%MOD*minv(2)%MOD;
		ans%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n,k;
  cin>>n>>k;
  if(n<=k)
  {
    cout<<"0";
    return 0;
  }
  vector<long long int > H(n);
  long long int  sum=0;
  for(int i=0 ; i<n ; i++)
  {
    cin>>H[i];
  }
  sort(H.rbegin() , H.rend());
  for(int i=k ; i<n ; i++)
  {
    sum = sum + H[i];
  }
  cout<<sum;

return 0;
}

Measured memory_bytes: 1792
n = int(input())
dp=[0]*(n+1)
dp[1]=1
j,k=1,1
for i in range(2,n+1):
    if i==6*j:
        j*=6
    if i==9*k:
        k*=9
    dp[i]=min(dp[i-k],dp[i-j],dp[i-1])+1
print(dp[n])

Measured memory_bytes: 39792
import java.util.*;
 
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		long[] a = new long[n];
		long sum = 0;
		int minusCount = 0;
		
		for(int i=0; i<n; i++) {
		    a[i] = Long.parseLong(sc.next());
		    if(a[i] < 0) {sum += -a[i]; minusCount++; a[i] = -a[i];} 
		    else sum += a[i];
		}
    	
		Arrays.sort(a);
		if(minusCount % 2 == 0) minusCount = 0;
		else minusCount = 1;
		for(int i=0; i<minusCount; i++) {
		    sum -= a[i]*2;
		}
        
        System.out.println(sum);
	}
}

Measured memory_bytes: 46928
#include <iostream>
#include <cstdio>


using namespace std;

const long int INF = 5000000000;
const int MAX_E = 500000;
const int MAX_V = 100000;

struct edge   //??????????????????cost???(from,to)??¨??????(?????????)???
{
	int from;
	int to;
	int cost;

	edge()
	{
		from = 0;
		to = 0;
		cost = 0;
	}
};

//edge es[MAX_E];

int V,E,r;    //??°?????????????????°,?????°,?§????
long int d[MAX_V];
edge es[MAX_E];



void shortest_path(int r)
{
	for(int i = 0; i < V; i++)
	{
		d[i] = INF;
	}

	d[r] = 0;

	while(true)
	{
		bool update = false;

		for(int i = 0; i < E; i++)
		{
			edge e = es[i];

			if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost)
			{
				d[e.to] = d[e.from] + e.cost;
				update = true;
			}
		}

		if (!update) break;
	}
}


int main()
{
	int a[10];
	//edge es[MAX_E];

	scanf(" %d %d %d", &V,&E,&r);

	//cout << endl;
	//cout << V << E << r << endl;


	for(int i = 0; i < E; i++)
	{
		scanf(" %d %d %d", &es[i].from, &es[i].to, &es[i].cost);
	}

	/*for(int i = 0; i < E; i++)
	{
		//scanf("%d %d %d", &es[i].from, &es[i].to, &es[i].cost);
		printf("%d %d", i,es[i].from);
		printf(" %d", es[i].to);
		printf(" %d", es[i].cost);
		cout << endl;
	}


	cout << "okok";*/

	shortest_path(r);

	for(int i = 0; i < V; i++)
	{
		if (d[i] == INF)
		{
			printf("INF\n");
		}else
		{
			printf("%ld\n", d[i]);
		}
	}

	return 0;
}

Measured memory_bytes: 9792
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <numeric>
#include <climits>
#include <math.h>
#include <memory.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, M;
int cnt = 0;
ll ans = 0LL;
int i_index;
int dh[4] = {1, 0, -1, 0};
int dw[4] = {0, 1, 0, -1};
string board[64];
int main(){
    string s, t;
    cin >> s >> t;
    if(s == t){
        cout << "Yes" << endl;
        return 0;
    }
    for(int i = 0; i < s.size(); i++){
        s = s.back() + s.substr(0, s.size() - 1);
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
import Text.Printf

add :: [Int] -> [Int] -> [Int]
add [] _ = []
add _ [] = []
add (x:xs) (y:ys) = (x+y):(add xs ys)

acm :: [[Int]] -> [Int]
acm (x1:[]) = x1
acm (x1:xs) =
  add x1 $ acm xs
  
ans :: [[Int]] -> [[Int]]
ans lst =
  let s1 = map (\r -> r ++ [sum r]) lst
      s2 = acm s1
  in
    s1 ++ [s2]

play :: [[Int]] -> [[Int]]
play ([0]:_) = []
play (n:xs) =
  let n' = n!!0
      a = ans  $ take n' xs
      b = play $ drop n' xs
  in
    a ++ b

to_str :: [[Int]] -> String
to_str [] = ""
to_str (line:lines) =
  let sl = concat $ map (printf "%5d") line
      ss = to_str lines
  in
    (sl++"\n"++ss)

main = do
  c <- getContents
  let l = map (map read) $ map words $ lines c :: [[Int]]
      o = play l
  putStr $ to_str o

Measured memory_bytes: 4396
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n, a, b, p1;
  cin >> n >> a >> b;
  p1 = n * a;
  
  if (p1 > b) {
    cout << b << endl;
  }
  else {
    cout << p1 << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h> //全てのヘッダファイルをインクルード
 
//ループ
#define rep(i, n) for(int i = 0; i < (n); i++) //普通のループ
#define repr(i, n) for(int i = n; i >= 0; i--) //逆ループ
 
//型名省略
typedef long long ll;
//値
static const ll MX = 100005;
static const ll MX_ll = 1e18;
const double PI = acos(-1); //π
 
using namespace std;
 
//ソート
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))
 
//#include "./lib/generic/search.h"

//文字列入力した小数値を小数点なくして返す
int changeDoubleToInt(string decimal){ 
    decimal.erase(1, 1); //小数点削除
    int n_decimal = atoi(decimal.c_str()); //c_strでchar*に変換後、atoiでintに変換
    return n_decimal;
}

//最大公約数
int gcd(int a, int b){
    if(b == 0) return a;
    return gcd(b, a%b);
}

int main(){
    int k, ans=0;
    cin >> k;
    for(int i=1; i<=k; i++){
        for(int j=1; j<=k; j++){
            for(int l=1; l<=k; l++){
                if(i==j && j==l) ans+=i;
                else if(i==j && j!=l) ans+=gcd(i,l);
                else if(i!=j && j==l) ans+=gcd(i,j);
                else if(i==l && j!=l) ans+=gcd(i,j);
                else{
                    ans+=gcd(gcd(i,j),l);
                }
                //cout << i << " " << j << " " << l << " " << ans << endl; 
            }
        }
    }

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

Measured memory_bytes: 3616
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<numeric>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

const int CM = 130000, CL = 12;
char cn[CM + CL], * ci = cn + CM + CL, * owa = cn + CM, ct;
const ll ma0 = 1157442765409226768;
const ll ma1 = 1085102592571150095;
const ll ma2 = 71777214294589695;
const ll ma3 = 281470681808895;
const ll ma4 = 4294967295;
inline int getint() {
	if (ci - owa > 0) {
		memcpy(cn, owa, CL);
		ci -= CM;
		fread(cn + CL, 1, CM, stdin);
	}
	ll tmp = *(ll*)ci;
	int dig = 68 - __builtin_ctzll((tmp & ma0) ^ ma0);
	if (dig == 68) dig = 0;
	tmp = tmp << dig & ma1;
	tmp = tmp * 10 + (tmp >> 8) & ma2;
	tmp = tmp * 100 + (tmp >> 16) & ma3;
	tmp = tmp * 10000 + (tmp >> 32) & ma4;
	ci += (64 - dig >> 3);
	while ((ct = *ci++) >= '0') tmp = tmp * 10 + ct - '0';
	return tmp;
}

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


	int X = getint(), Y = getint(), A = getint(), B = getint(), C = getint();

	int abc[400000];
	auto a = abc;
	auto b = abc + A;
	auto c = abc + A + B;

	rep(i, A + B + C) a[i] = getint();

	nth_element(a, b - X, b);
	nth_element(b, c - Y, c);
	if (X + Y > B) memcpy(b, b - X, (B - Y) * sizeof(int));
	else memcpy(c - X - Y, b - X, X * sizeof(int));
	nth_element(c - X - Y, c + C - X - Y, c + C);

	ll kotae = accumulate(c + C - X - Y, c + C, 0ll);
	//for (auto kari = c + C - X - Y; kari < c + C; kari++) kotae += *kari;
	printf("%lld", kotae);

	Would you please return 0;
}

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

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

int main(){
  int n,a;
  cin >> n;
  ll ans=0;
  rep(i,n){
    cin>>a;
    while(a%2==0){
      ans++;
      a/=2;
    }
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
#define nrep(i,a,b) for(int i=a;i<b;i++)
using namespace std;

int main() {
	ll n; cin >> n;
	vector<string> s(n);
	rep(i, n) cin >> s[i];
	string my_name; cin >> my_name;
	ll l = 0, r = 0;
	sort(s.begin(), s.end());
	rep(i, n) {
		string temp = s[i];
		//cout << "temp=" << temp << endl;
		rep(j, temp.size()) if (temp[j] == '?') temp[j] = 'a';
		if (temp <= my_name) {
			l++;
			//cout << "l++" << endl;
		}
		temp = s[i];
		rep(j, temp.size()) if (temp[j] == '?') temp[j] = 'z';
		if (my_name <= temp) {
			r++;
			//cout << "r++" << endl;
		}
	}//cout << l << " " << r << endl;
	nrep(i, n - r,l+1) {
		if (i != n-r) cout << " ";
		cout << (i + 1);
	}cout << endl;
}

Measured memory_bytes: 896
import math

n, d = map(int, input().split())
x = [tuple(map(int, input().split())) for i in range(n)]
count = 0
for i in range(n):
  for j in range(i+1, n):
    distance = 0
    for k in range(d):
      distance += (x[i][k] - x[j][k]) ** 2
    if math.sqrt(distance).is_integer():
      count += 1

print(count)


Measured memory_bytes: 38624
h,w=map(int,input().split())
s=[list("."+input()+".") for _ in range(h)]
s= [["."]*(w+2)] + s + [["."]*(w+2)] 
for i in range(1,h+1):
    l=[]
    for k in range(1,w+1):
        if s[i][k]=="#":
            p="#"
        else:
            p=0
            p+=s[i-1][k-1:k+2].count("#")
            p+=s[i][k-1:k+2].count("#")
            p+=s[i+1][k-1:k+2].count("#")
        l.append(str(p))
    print("".join(l))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define dump(x) cerr<<#x<<": "<<(x)<<endl
#define INF 100000000
#define IINF 9999999999999;
using vint = std::vector<int>;
using ll = long long;
using vll = std::vector<ll>;
template <class T> void chmin(T& a, const T& b) { a = std::min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = std::max(a, b); }

int main() {
    int N;
    cin >> N;
    bool check = false;
    for(int i = 0; i <= N; i += 4) {
        for(int j = 0; j <= N; j+= 7) {
            if((i + j) == N) check = true;
        }
    }

    if(check) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>

using namespace std;

int main() {
  string s;
  cin >> s;
  sort(s.begin(), s.end());

  if( s[0]==s[1] && s[2]==s[3] && s[1]!=s[2] ) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
    int N,i,j,k,v;
	scanf("%d",&N);
	int A[N];
	for(i=0;i<N;i++){
		scanf("%d",&A[i]);
	}
	/*print*/
	for(i=0;i<N;i++){
		printf("%d",A[i]);
		if(i<N-1){
			printf(" ");
		}
	}
	printf("\n");
	/*insertion sort*/
	for(i=1;i<=N-1;i++){
		v = A[i];
		j = i - 1;
		while(j>=0 && A[j] > v){
			A[j+1] = A[j];
			j--;
		}
		A[j+1] = v;
		/*print*/
		for(k=0;k<N;k++){
			printf("%d",A[k]);
			if(k<N-1){
				printf(" ");
			}
		}
		printf("\n");
	}
    return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define ff first
#define ss second
#define p pair<int,int>
#define pb push_back
#define endl '\n'
#define w(t) ll test;cin>>test;while(test--)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(0);
#define pi acos(-1)

int main()
{
    fast;
    int x;
    cin>>x;
   if(x>=400&&x<=599)cout<<"8"<<endl;
   else if(x>=600&&x<=799)cout<<"7"<<endl;
    else if(x>=800&&x<=999)cout<<"6"<<endl;
     else if(x>=1000&&x<=1199)cout<<"5"<<endl;
      else if(x>=1200&&x<=1399)cout<<"4"<<endl;
       else if(x>=1400&&x<=1599)cout<<"3"<<endl;
        else if(x>=1600&&x<=1799)cout<<"2"<<endl;
         else if(x>=1800&&x<=1999)cout<<"1"<<endl;
}


Measured memory_bytes: 3648
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>

#define MAX_SIZE 100000000
typedef unsigned long long ull;
using namespace std;

int main() {
  int N, X; cin >> N >> X;
  int min_elm = MAX_SIZE;
  for(int i = 0; i < N; i++) {
    int a; cin >> a;
    min_elm = min(min_elm, a);
    X -= a;
  }

  int remain = 0;
  while(X - min_elm >= 0) {
    X -= min_elm;
    remain++;
  }
  const int ans = N + remain;
  cout << ans << endl;
}


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

string f(string x, string y) {
	int pos = 0;
	while (pos = x.find(y,pos),pos != string::npos) {
		x.replace(pos, y.length(), "0");
		pos = x.find(y, pos + 1);
	}
	return x;
}

int main() {
	string s;
	string ans = "YES";
	cin >> s;
	s = f(s, "eraser");
	s = f(s, "erase");
	s = f(s, "dreamer");
	s = f(s, "dream");

	for (int i = 0; i < s.length(); i++) {
		if (s[i] != '0') {
			ans = "NO";
			break;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>

int main() {
	char letters[20];
	scanf ("%[^\n]", letters);
	for (int i = 0; i < 19; i++) {
		if (i == 5 || i == 13) {
			printf(" ");
			continue;
		}
	printf("%c", letters[i]);
	}
	return 0;
}

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

int main(){

  int n,m;
  scanf("%d %d",&n,&m);

  while(n!=0 || m!=0){
    int p[1111];
    for(int i=0;i<n;i++){
      scanf("%d",&p[i]);
    }
    
    
    for(int i=0;i<n-1;i++){
      for(int j=n-1;j>i;j--){
	if(p[j]>p[j-1]){
	  int tmp=p[j];
	  p[j]=p[j-1];
	  p[j-1]=tmp;
	}
      }
    }
    
    int sum=0;
    
    for(int i=0;i<n;i++){
      if(i%m == m-1);
      else{
	sum+=p[i];
      }
    }
    printf("%d\n",sum);
    scanf("%d %d",&n,&m);
  }
      
    
  return 0;
}

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


int main(){
  ll N,A,B;
  cin >> N >> A >> B;
  
  if(A>B){
    cout << 0 << endl;
    return 0;
  }
  
  if(N==1){
    if(A==B)
      cout << 1 << endl;
    else
    	cout << 0 << endl;
    return 0;
  }
  
  cout << (B-A)*(N-2)+1 << endl;
  
}

Measured memory_bytes: 3580
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

    void solve() {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();  // コマ数
        int M = sc.nextInt();  // 座標数

        int[] X = new int[M]; // 座標
        for (int i = 0; i < M; i++) {
            X[i] = sc.nextInt();
        }
        Arrays.sort(X);

        Integer[] distances = new Integer[M - 1];
        for (int i = 0; i <= M - 2; i++) {
            distances[i] = X[i + 1] - X[i];
        }
        Arrays.sort(distances, Comparator.reverseOrder());

        if (N >= M) {
            System.out.print(0);
            return;
        }

        int distanceToMove = X[M - 1] - X[0];
        for (int i = 0; i < N - 1; i++) {
            distanceToMove -= distances[i];
        }
        System.out.print(distanceToMove);
    }

    // Main
    public static void main(String[] args) {
        new Main().solve();
    }
}

Measured memory_bytes: 52048
<?php
list($a, $b, $c, $k)=fscanf(STDIN, '%d %d %d %d');

$sum = 0;
$n=min($a, $k);
$sum += $n;
$k -= $n;
$n=min($b, $k);
$k -= $n;
$sum -= $k;

echo $sum;

Measured memory_bytes: 16180
#define _USE_MATH_DEFINES  // M_PI等のフラグ

#include <iostream>
#include <bitset>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>
#include <list>

#define MOD 1000000007
#define COUNTOF(array) (sizeof(array)/sizeof(array[0]))

using namespace std;


void solve(){
    int N;
    cin >> N;
    int ans = 0;
    int now = 1;
    for (int i=0; i<N; i++) {
        int a;
        cin >> a;
        if (now != a) {
            ans++;
        }
        else {
            now++;
        }
    }

    if (now == 1) {
        cout << "-1" << endl;
    }
    else {
        cout << ans << endl;
    }

}

int main(int argc, char const *argv[]){
    solve();
    return 0;
}

Measured memory_bytes: 3600
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (lint)(1LL<<56)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
#define fi first
#define se second
typedef long long lint;
int dx[8]={1,1,0,-1,-1,-1,0,1};
int dy[8]={0,1,1,1,0,-1,-1,-1};


int main(void){
    int N;
    cin >> N;
    string S[N];
    rep(i,N) cin >> S[i];
    sort(S,S+N);
    int maxi=1;
    int count=1;
    string comp=S[0];
    map<string,int> ans;
    ans[S[0]]=1;
    for(int i=1;i<N;i++){
        if(S[i]==comp){
            count++;
            ans[S[i]]=count;
        }
        else{
            comp=S[i];
            count=1;
        }
        maxi=max(count,maxi);
        ans[S[i]]=count;
    }
    set<string> done;
    rep(i,N){
        if(ans[S[i]]==maxi && !done.count(S[i])){
            cout << S[i] << endl;
            done.insert(S[i]);
        }
    }
}

Measured memory_bytes: 34816
#include <bits/stdc++.h>
   
using namespace std;
     
#define PB(x) push_back(x)
#define ALL(x) (x).begin(), (x).end()
#define ALLR(x) (x).rbegin(), (x).rend()
#define MP(x) make_pair(x);
    
#define debug(x) cerr << #x << '=' << x << endl;
#define debug2(x, y) cerr << #x << '=' << x << ' ' << #y << '=' << y << endl;
#define debugn(a) for (int x: a) cerr << x << ' '; cerr << endl;
     
#define int long long
     
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vii;
typedef vector<string> vs;
typedef unsigned long long ull;

const int INF = 1e13;
const int mmod = 1000000007;

int32_t main()
{
	int n;
	cin >> n;
	int ans = 1;
	cout << n*n*n<< endl;
}


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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  int h,w;cin>>h>>w;
  int n;cin>>n;

  cout<<((n%max(h,w)==0)?n/max(h,w):n/max(h,w)+1)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 
int flag[100010];
int mistake[100010];
 
int main(void){
    int n,m;
    cin>>n>>m;
    int ans1 = 0;
    int ans2 = 0;
    for(int i=0;i<m;i++){
        int p;
        string s;
        cin>>p>>s;
        if(s == "AC"){
            if(flag[p]==0){
                flag[p] = 1;
            }
        }
        if(s == "WA"){
            if(flag[p]==0){
                mistake[p]++;
            }
        }
    }
    for(int i=1;i<=n;i++){
        if(flag[i]==1){
            ans1++;
            ans2+=mistake[i];
        }
    }
    cout<<ans1<<" "<<ans2<<endl;
    return 0;
}

Measured memory_bytes: 1024
e=enumerate
n,*a=map(int,open(0).read().split())
d=[0]
for j,(a,i)in e(sorted((a,i)for i,a in e(a))[::-1]):d=[d[0]+a*(~i-j+n)]+[max(d[k+1]+a*(n+k-i-j),t+a*abs(i-k))for k,t in e(d[:j])]+[d[j]+a*abs(i-j)]
print(max(d))

Measured memory_bytes: 9592
//write：Sakura
//id：
//problem：
//note：

#include <cstdio>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;

typedef long long ll;

int main(){
int N; 
scanf("%d",&N);
int A[2*100005]; 
for(int i = 0; i < N; i++){
	scanf("%d",&A[i]);
}
long long int B[2*100005];
B[0] = A[0]; 
for(int i = 0; i < N; i++){
B[i+1] = B[i] + A[i+1]; 
}

long long int S = B[N-1]; 

for(int i = 1; i < N-1; i++){
long long int L = upper_bound(B, B+N, B[i]/2) - B; 
long long int M = upper_bound(B, B+N, (B[i] + B[N-1])/2) - B; 

long long int P1 = max(max(B[L], B[i]-B[L]), max(B[M]-B[i], B[N-1]-B[M])); 
long long int P2 = max(max(B[L], B[i]-B[L]), max(B[M-1]-B[i], B[N-1]-B[M-1])); 
long long int P3 = max(max(B[L-1], B[i]-B[L-1]), max(B[M]-B[i], B[N-1]-B[M])); 
long long int P4 = max(max(B[L-1], B[i]-B[L-1]), max(B[M-1]-B[i], B[N-1]-B[M-1])); 
long long int Q1 = min(min(B[L], B[i]-B[L]), min(B[M]-B[i], B[N-1]-B[M])); 
long long int Q2 = min(min(B[L], B[i]-B[L]), min(B[M-1]-B[i], B[N-1]-B[M-1])); 
long long int Q3 = min(min(B[L-1], B[i]-B[L-1]), min(B[M]-B[i], B[N-1]-B[M])); 
long long int Q4 = min(min(B[L-1], B[i]-B[L-1]), min(B[M-1]-B[i], B[N-1]-B[M-1]));
long long int R1 = P1 - Q1; 
long long int R2 = P2 - Q2;
long long int R3 = P3 - Q3;
long long int R4 = P4 - Q4;
long long int R = min(min(R1, R2), min(R3, R4)); 
 S = min(S, R);
}
cout<<S<<endl;
return 0;
}


Measured memory_bytes: 2560
// ref. https://atcoder.jp/contests/abc162/submissions/11878644

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << 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; }

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e15;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

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

  int buf = (n%2 == 1) ? 3 : 2;
  // dp[i][j] .. max value using [0, i), buf is j. j = 0 if there is no buffer (compact to left).
  vector<vector<ll>> dp(n+1, vector<ll>(buf, -INF));
  dp[0][0] = 0;
  rep(i, n) rep(j, buf) {
    // If j = 0 (no buffer), even i is used.
    chmax(dp[i+1][j], dp[i][j] + ((j+i)%2 == 0 ? a[i] : 0));
    if (j < buf-1) { // add buf here
      chmax(dp[i+1][j+1], dp[i][j]);
    }
  }
  cout << dp[n][buf-1] << endl;
}



Measured memory_bytes: 15880
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j,l;
		Scanner sc = new Scanner(in);
		int n = parseInt(sc.next());
		String s = "";
		HashMap<String, Integer> map = new HashMap<>();
		for (i = 0; i < n; i++) {
			s = sc.next();
			if(map.get(s)==null) {
				map.put(s, 1);
			} else {
				map.put(s, map.get(s)+1);
			}
		}
		out.println(map.size());
	}
}


Measured memory_bytes: 71720
#include <iostream>
#include <algorithm>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<iomanip>
#include<ctime>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<bitset>
#define sqr(x) ((x)*(x))
#define fz1(i,n) for ((i)=1;(i)<=(n);(i)++)
#define fd1(i,n) for ((i)=(n);(i)>=1;(i)--)
#define fz0g(i,n) for ((i)=0;(i)<=(n);(i)++)
#define fd0g(i,n) for ((i)=(n);(i)>=0;(i)--)
#define fz0k(i,n) for ((i)=0;(i)<(n);(i)++)
#define fd0k(i,n) for ((i)=(long long)((n)-1);(i)>=0;(i)--)
#define fz(i,x,y) for ((i)=(x);(i)<=(y);(i)++)
#define fd(i,y,x) for ((i)=(y);(i)>=(x);(i)--)
#define fzin fz1(i,n)
#define fzim fz1(i,m)
#define fzjn fz1(j,n)
#define fzjm fz1(j,m)
#define ff(c,itr) for (__typeof((c).begin()) itr=(c).begin();itr!=(c).end();++itr)
#define rdst(st,len){static char ss[len];scanf(" %s",ss);(st)=ss;}
#define inc(x,y) {x+=(y);if(x>=mod)x-=mod;}
#define dec(x,y) {x-=(y);if(x<0)x+=mod;}
#define incm(x,y) {x=((x)+(y))%mod;}
#define spln(i,n) (i==n?'\n':' ')
#define fac_init(n){fac[0]=fac[1]=inv[1]=fi[0]=fi[1]=1;fz(i,2,n){fac[i]=1ll*fac[i-1]*i%mod;inv[i]=1ll*(mod-mod/i)*inv[mod%i]%mod;fi[i]=1ll*fi[i-1]*inv[i]%mod;}}
using namespace std;
inline void read(int &x)
{
	char c;int f=1;
	while(!isdigit(c=getchar()))if(c=='-')f=-1;
	x=(c&15);while(isdigit(c=getchar()))x=(x<<1)+(x<<3)+(c&15);
	x*=f;
}
int n,i,j;
long long ans,dp[45][45][45];
string st[45];
long long dfs(int l,int r,int k)
{
	if(dp[l][r][k]!=-1) return dp[l][r][k];
	if(l==r) return 1;
	if(l==k||r==k) return 0;
	dp[l][r][k]=0;
	int i,j,p,q;
	fz(i,l,k-1)fz(j,k+1,r){
		if(st[i][j]=='0')continue;
		fz(p,i,k-1)fz(q,k+1,j){
			dp[l][r][k]+=dfs(l,p,i)*dfs(p+1,q-1,k)*dfs(q,r,j);
		}
	}
	return dp[l][r][k];
}
int main()
{
	cin>>n;
	fz1(i,n+n){
		cin>>st[i];st[i]=" "+st[i];
	}
	memset(dp,-1,sizeof(dp));
	fz(i,2,n*2){
		if(st[1][i]&1){
			ans+=dfs(2,n+n,i);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4320
#include<bits/stdc++.h>
using namespace std;
int a,b;

int main(){
    scanf("%d %d",&a,&b);
    int maxx,maxn;
    if (a>b) maxx=a,maxn=b;
    else maxx=b,maxn=a;
    printf("%d",maxx+max(maxx-1,maxn));
    return 0;
} 

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main() {
    int i, j, H, W;
    while (cin >> H >> W)
    {
        if (H==0&&W==0) break;
        
    for ( j = 0; j < W; j++)
        {
            cout << "#";
        }
        cout << "\n";    
    
    for ( i = 0; i < H-2; i++)
    {
    
        

        cout << "#";
        for ( j = 0; j < W-2; j++)
        {
            cout << ".";
        }
        cout << "#";
        cout << "\n";
        
        
    
    }
    for ( j = 0; j < W; j++)
        {
            cout << "#";
        }
        cout << "\n";
        cout << "\n";
        
    }

    

    
	return 0;
}


Measured memory_bytes: 3068
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<int>v1, v2;
    for(int i = 0; i < n; i++){
        int a, b;
        cin >> a >> b;
        v1.push_back(a);
        v2.push_back(b);
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    if(n % 2 == 1){
        cout << v2[n/2] - v1[n/2] + 1;
    }
    else{
        cout << v2[n/2 - 1] + v2[n/2] - v1[n/2 - 1] - v1[n/2] + 1;
    }
    return 0;
}

Measured memory_bytes: 5036
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
#define MAXN 100+5

typedef long long ll;

const int INF=0x7fffffff;

using namespace std;

struct C{
	int a,b,tv;
};

vector<C> c;//30个频道 
vector<C> reco;

bool cmp(C h,C k){//按结束时间从小到大进行排序 
	if(h.a==k.a){
		return h.b<k.b;//开始得早的节目放在前面 
	}
	return h.a<k.a;//结束得早的节目放在前面 
}
int main() {
	int n,cn;
	scanf("%d %d",&n,&cn);
	for(int i=1;i<=n;i++){
		int s,t,c1;
		scanf("%d %d %d",&s,&t,&c1);
		C v;
		v.a=s;
		v.b=t;
		v.tv=c1;
		c.push_back(v);
	}
	sort(c.begin(),c.end(),cmp);//开始得早的放在前面 
	reco.push_back(c[0]);//第一个录音机 
	
	int num=1;
	for(int i=1;i<n;i++){
		C v;
		v.a=c[i].a;//第i个节目 
		v.b=c[i].b;
		v.tv=c[i].tv;
		bool f=1;
		for(int j=0;j<num;j++){//寻找可以录制节目i的录音机j 
			if(v.a>reco[j].b||(v.tv==reco[j].tv&&v.a==reco[j].b)){//节目开始的时间大于等于录音机结束的时间，可以用这个录音机 录制 
				//同一个节目可以连续录制 
				reco[j].a=v.a;
				reco[j].b=v.b;
				reco[j].tv=v.tv;
				f=0; 
				break; 
			}
		}
		if(f){//没有找到可以的录音机，就只能增加录音机 
			num++;
			reco.push_back(v); 
		}
		
	}
	printf("%d",num);
	return 0;
}

Measured memory_bytes: 1912
import collections
calc_time = 0
hoge = collections.deque()
num, q = [int(x) for x in input().split()]
for _ in range(num):
    name, t = input().split()
    hoge.append([name, int(t)])
while hoge:
    name, t = hoge.popleft()
    if t - q > 0:
        hoge.append([name, t-q])
        calc_time += q
    elif t == q:
        calc_time += q
        print ('{} {}'.format(name, calc_time))
    elif t - q < 0:
        calc_time += t
        print ('{} {}'.format(name, calc_time))


Measured memory_bytes: 13276
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 110

int lenmemo[SIZE];
int endmemo[SIZE];

int len(char *s, int *pos);

bool isNum(char c){
  return '0' <= c && c <= '9';
}

bool isAlp(char c){
  return 'A' <= c && c <= 'Z';
}

int len_factor(char *s, int *pos){
  int res, start = *pos;
  
  if (s[*pos] == '(') {
    (*pos)++;
    res = len(s, pos);
    (*pos)++;
  } else {
    res = len(s, pos);
  }

  lenmemo[start] = res;
  endmemo[start] = (*pos);
  
  return res;
}

int len_num(char *s, int *pos){
  int res = 0, start = *pos;
  int num = 0;
  
  while(isNum(s[*pos])){
    num = num * 10 + s[*pos] - '0';
    (*pos)++;
  }
  
  if (s[*pos] == '('){
    //(*pos)++;
    res = min((ll)num * len_factor(s, pos), 100000000LL);
  } else {
    (*pos)++;
    res = min(num, 100000000);
  }

  lenmemo[start] = res;
  endmemo[start] = *pos;
  
  return res;
}

int len_str(char *s, int *pos){
  int res = 0;
  while(1){
    if (isNum(s[*pos])) {
      res += len_num(s, pos);
    } else if(isAlp(s[*pos])){
      res++;
      (*pos)++;
    } else {
      return min(res, 100000000);
    }
  }
}

int len(char *s, int *pos){
  int res = 0;
  
  while(1){
    if (isNum(s[*pos])) {
      res += len_num(s,pos);
    }else if (isAlp(s[*pos])){
      res += len_str(s,pos);
    }else{
      // (*pos)++;
      return min(res, 100000000);
    }
  }
}



bool solve(){
  char s[SIZE];
  int X;

  scanf("%s%d", s, &X);

  if(s[0] == '0') return false;
  
  int pos = 0;
  int slen = len(s, &pos);

  if (slen <= X) {
    puts("0");
    return true;
  }

  for(int i=0;i<slen;i++){
    if(isNum(s[i])){
      if(lenmemo[i] <= X){
        X -= lenmemo[i];
        i = endmemo[i] - 1;
      } else {
        while(!(isAlp(s[i]) || s[i] == '(')) i++;

        if(s[i] == '('){
          X %= lenmemo[i];
        }else{
          printf("%c\n",s[i]);
          return true;
        }
      }
    }else if(isAlp(s[i])){
      if(X == 0){
        printf("%c\n",s[i]);
        return true;
      }
      X--;
    }
  }

  return true;
}

int main(){
  while(solve());
  
  return 0;
}



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

// 数学的考察の問題。組み合わせ論だが、自力で思いつけなかった。。
const ll MOD = 1000000007;


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

  ll digit = 0, sum = 0;
  rep(i, m) {
    ll d, c;
    cin >> d >> c;
    digit += c;
    sum += d * c;
  }
  ll ans = ((9 * digit + sum) - (9 * 1 + sum % 9)) / 9;
  ans = digit - 1 + (sum - 1) / 9;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3564
#include<iostream>
#include<vector>

using namespace std;

int N,M;
vector<vector<int>> adj;
vector<vector<int>> orders;
vector<int> nt;

int next(int u){
    for(int v=nt[u]+1; v<N; v++){
        if(adj[u][v]==1){
            nt[u]=v;
            return v;
        }
    }
    return -1;
}

int dfs(int u,vector<bool> visited){
    bool all_visited=true;

    visited[u]=true;
    
    for(int i=0; i<N; i++){
       if(visited[i]==false){
           all_visited=false;
           break;
       }
    }

    if(all_visited){
        //cout<<1<<endl;
        return 1;
    }

    int ret=0;
    for(int v=1; v<N; v++){
        if(visited[v]==true){
            //cout<<v+1<<"は探索済み"<<endl;
            continue;
        }
        if(adj[u][v]==0){
            //cout<<u+1<<" → "<<v+1<<"は存在しない"<<endl;
            continue;
        }
        visited[v]=true;
        ret+=dfs(v,visited);
        visited[v]=false;
    }
    //cout<<ret<<endl;
    return ret;
}

int main(){
    vector<bool> visited;
    cin>>N>>M;

    adj.resize(N);
    nt.resize(N,(-1));
    visited.resize(N);

    for(int i=0; i<N; i++){
        adj[i].resize(N,(0));
    }
/*
    for(int i=0; i<N; i++){
        for(int j=0; j<N; j++){
            cout<<adj[i][j];
        }cout<<endl;
    }
*/
    for(int i=0; i<M; i++){
        int u,v;
        cin>>u>>v;
        adj[u-1][v-1]=1;
        adj[v-1][u-1]=1;
    }

    cout<<dfs(0,visited)<<endl;
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    abc068c()
}

fun abc068c() {
    val (n, m) = readLine()!!.split(' ').map { it.toInt() }
    val abList = (1..m).map { readLine()!!.split(' ').map { it.toInt() - 1 } }
        .map { Pair(it[0], it[1]) }
    val paths = Array(n) { mutableSetOf<Int>() }

    abList.forEach {
        paths[it.first].add(it.second)
        paths[it.second].add(it.first)
    }

    var list = mutableListOf(0)
    repeat(2) {
        val curr = list.map { paths[it] }.flatten()
        if (curr.contains(n - 1)) return println("POSSIBLE")
        list = curr.toMutableList()
    }

    return println("IMPOSSIBLE")
}


Measured memory_bytes: 121724
#include <bits/stdc++.h>
using namespace std;
int main(){
  map<string, int> M;
  int q;
  cin >> q;
  for (int i = 0; i < q; i++){
    int t;
    cin >> t;
    if (t == 0){
      string key;
      cin >> key;
      int x;
      cin >> x;
      M[key] = x;
    }
    if (t == 1){
      string key;
      cin >> key;
      cout << M[key] << endl;
    }
  }
}


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

using namespace std;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) (a).begin(),(a).end()

int main(){
    int n, q;
    cin >>  n;
    vector<int> a(n), pat(pow(2, n));
    rep(i,n)cin >> a[i];
    sort(all(a));
    rep(i, pow(2, n)){
        stringstream ss;
        ss << bitset<20>(i);
        string s = ss.str();
        reverse(all(s));
    
        int tmp = 0;
        rep(j,n)if(s[j] == '1')tmp += a[j];
        pat[i] = tmp;
    }

    sort(all(pat));
    
    cin >> q;
    rep(i,q){
       int m;
       cin >> m;
       cout << ((binary_search(all(pat), m))? "yes" : "no") << endl;
    }

    return 0;
}


Measured memory_bytes: 7160
S=input()
count=0
def sigma(i):
    a=[b for b in range(0,i+1)]
    return sum(a)
place=0
flag=0
start=0
for i in range(len(S)):
    if S[i]=="B":
        flag=1
    elif S[i]=="W":
        if flag == 1:
            count += 1
            place += i - start
        else:
            start+=1
ans=place-sigma(count-1)
print(ans)

Measured memory_bytes: 7528
//  Created by conan1024hao in 2020.
//  Copyright © 2020 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao Twitter/QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define Endl endl
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef long long int LL;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}

//---------------------------------------------------------------------------
bool cmp(const Pll &l,const Pll &r){
    return l.fi<r.fi;
}
//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????统一类型        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;cin>>n;
    ll d,a;cin>>d>>a;
    vector<Pll>xh(n);
    for(ll i=0;i<n;i++){
        cin>>xh[i].fi>>xh[i].se;
    }
    sort(all(xh));
    ll ans=0;
    vector<ll>s(n+1,0);
    for(ll i=0;i<n;i++){
            if(xh[i].se>s[i]){
            ll k=upper_bound(xh.begin(),xh.end(),mp(xh[i].fi+2*d,0),cmp)-xh.begin();
            ll cnt=(xh[i].se-s[i])/a;if((xh[i].se-s[i])%a!=0)cnt++;
            s[i]+=cnt*a;
            s[k]-=cnt*a;//imos しながら爆発させる
            ans+=cnt;
        }
        s[i+1]+=s[i];//imos の累積和をとる操作
    }
    
    cout<<ans<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------







Measured memory_bytes: 4992