akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 * @throws NumberFormatException 
	 */
	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int a = Integer.parseInt(tmpArray[0]);
		int b = Integer.parseInt(tmpArray[1]);
//		int c = Integer.parseInt(tmpArray[2]);
//		int y = Integer.parseInt(tmpArray[3]);
//		int r = Integer.parseInt(tmpArray[4]);
		
		
		System.out.printf("%d %d %f", a/b, a%b, ((double)a)/b);
		/*
		int i = 1;
		while(true){
			String[] tmpArray = br.readLine().split(" ");
			int a = Integer.parseInt(tmpArray[0]);
			int b = Integer.parseInt(tmpArray[1]);
			if(a == 0 && b == 0){
				break;
			}
			if(a > b){
				int tmp = a; 
				a = b;
				b = tmp;
			}
			System.out.println(a + " "+b);
			
		}*/

		//		int[] array = new int[3];
//		array[0] = a; array[1] = b; array[2] = c;
//
//		Arrays.sort(array);
//		System.out.printf("%d %d %d\n", array[0], array[1], array[2]);
		/*
		if(a < b && b < c){
			System.out.println("Yes");
		}
		else{
			System.out.println("No");
		}*/
	}

}

Measured memory_bytes: 24820
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
#define dump(val) cerr << __LINE__ << ":\t" << #val << " = " << (val) << endl

using namespace std;

typedef long long int lli;

template<typename T>
vector<T> make_v(size_t a, T b) {
    return vector<T>(a, b);
}

template<typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v(ts...))>(a, make_v(ts...));
}

int main() {
    int arr[3] = {0};
    REP(i, 0, 3) {
        cin >> arr[i];
    }
    int ans = 1 << 30;
    sort(begin(arr), end(arr));
    do {
        ans = min(ans, abs(arr[0] - arr[1]) + abs(arr[1] - arr[2]));

    } while (next_permutation(begin(arr), end(arr)));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string a, b;
  cin >> a >> b;
  
  if((a == "H" && b == "H") || (a == "D" && b == "D")) cout << "H" << endl;
  else cout << "D" << endl;
  return 0;
}

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

#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define PI acos(-1.0)
#define sq(n) ((n)*(n))

using namespace std;
typedef long long ll;

ll calc(ll n, ll a, ll b) {
    ll l = a/__gcd(a,b) * b;
    return (n - n/a - n/b + n/l);
}

int main() {
    ll a, b, c, d, n, r;
    cin >> a >> b >> c >> d;
    if (b < a) swap(a, b);

    r = calc(b,c,d) - calc(a-1,c,d);
    cout << r << endl;

    return 0;
}



Measured memory_bytes: 256
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 19
MOD = 10 ** 9 + 7
EPS = 10 ** -10

D = INT()
C = LIST()
S = [[]] * D
for i in range(D):
    S[i]  = LIST()
T = [t-1 for t in LIST(D)]
M = 26

last = list2d(M, D+2, 0)
def check(T):
    score = 0
    for i, t in enumerate(T):
        score += S[i][t]
        for j in range(M):
            last[j][i+1] = last[j][i] + 1
        last[t][i+1] = 0
        for j in range(M):
            score -= C[j] * last[j][i+1]
    return score

def change(day, a, b):
    nxtday = last[a].index(0, day+2)
    w = nxtday - day - 1
    h = last[a][day] + 1
    a_change = C[a] * h * w
    for d in range(day, nxtday-1):
        last[a][d+1] = last[a][d] + 1

    nxtday = last[b].index(0, day+2)
    w = nxtday - day - 1
    h = last[b][day] + 1
    b_change = C[b] * h * w
    last[b][day+1] = 0
    for d in range(day+1, nxtday-1):
        last[b][d+1] = last[b][d] + 1

    res = -a_change + b_change - S[day][a] + S[day][b]
    return res

score = check(T)
Q = INT()
for i in range(Q):
    d, q = MAP()
    d -= 1; q -= 1

    prev = T[d]
    nxt = q
    score += change(d, prev, nxt)
    print(score)
    T[d] = q


Measured memory_bytes: 77240
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]
diff = 0
for i in range(N):
    x = A[i] - B[i]
    if x > 0:
        diff += 2 * x
    else:
        diff -= 2 * (-x // 2)
if diff <= 0:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 4600
#ifdef LOCAL111
	#define _GLIBCXX_DEBUG
#else
	#define NDEBUG
#endif
#define _USE_MATH_DEFINES
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

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

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

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <type_traits>
#include <typeindex>
#include <unordered_map>
#include <unordered_set>
#endif
const int INF = 1e9;
using namespace std;
template<typename T, typename U> ostream& operator<< (ostream& os, const pair<T,U>& p) { os << '(' << p.first << ' ' << p.second << ')'; return os; }

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#ifdef LOCAL111
	#define DEBUG(x) cout<<#x<<": "<<(x)<<endl
	template<typename T> void dpite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
#else
	#define DEBUG(x) true
	template<typename T> void dpite(T a, T b){ return; }
#endif
#define F first
#define S second
#define SNP string::npos
#define WRC(hoge) cout << "Case #" << (hoge)+1 << ": "
template<typename T> void pite(T a, T b){ for(T ite = a; ite != b; ite++) cout << (ite == a ? "" : " ") << *ite; cout << endl;}
template<typename T> bool chmax(T& a, T b){if(a < b){a = b; return true;} return false;}
template<typename T> bool chmin(T& a, T b){if(a > b){a = b; return true;} return false;}

typedef long long int LL;
typedef unsigned long long ULL;
typedef pair<int,int> P;

void ios_init(){
	//cout.setf(ios::fixed);
	//cout.precision(12);
#ifdef LOCAL111
	return;
#endif
	ios::sync_with_stdio(false); cin.tie(0);
}

int main()
{
	ios_init();
	int n, a, b;
	while(cin >> n >> a >> b) {
		cout << min(a, b) << ' ' << max(a+b-n, 0) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, y,i,j;
    cin>>n>>y;
    bool t=false;
    
    for(i=0;i<=n;i++){
      for(j=0;j<=n-i;j++){
        if(10000*i+5000*j+1000*(n-i-j)==y&&n>=i+j){
          t=true;
          break;
          }
        }
        if(t)break;
      }
      
if(t)cout<<i<<' '<<j<<' '<<n-i-j<<endl;
else{cout<<"-1 -1 -1"<<endl;}
    return 0;
}


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

int main(){
	int n, r;
	int X[41], L[41], R[41];//X[i] = i - 20
	int x_l, x_r, h;
	double t;
	
	while(true){
		scanf("%d%d", &r, &n);
		if(r == 0 && n == 0) break;
		for(int i = -20; i < 20; i++){
			L[i + 20] = 0; R[i + 20] = 0;
		}
		for(int i = 0; i < n; i++){
			scanf("%d%d%d", &x_l, &x_r, &h);
			for(int i = x_l + 1; i <= x_r; i++){
				L[i + 20] = max(L[i + 20], h);
			}
			for(int i = x_l; i < x_r; i++){
				R[i + 20] = max(R[i + 20], h);
			}
		}
		
		X[-r + 20] = R[-r + 20]; X[r + 20] = L[r + 20];
		for(int i = -r + 1; i < r; i++){
			X[i + 20] = min(L[i + 20], R[i + 20]);
		}
		t = 100;
		for(int i = -r; i <= r; i++){
			t = min(t, X[i + 20] + r - sqrt((r + i) * (r - i)));
		}
		printf("%lf\n", t);
	}
	
	return 0;
}

Measured memory_bytes: 1064
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
	int b = sc.nextInt();
	
	System.out.println(a * (a - 1) / 2 + b * (b - 1) / 2);
	}
}

Measured memory_bytes: 21972
X, Y = [int(x) for x in input().split(' ')]
prize = {
    1:300000,
    2:200000,
    3:100000,
}

if (X == 1) and (Y == 1):
    print(1000000)
else:
    s = 0
    if X < 4:
        s += prize[X]
    if Y < 4:
        s += prize[Y]
    print(s)

Measured memory_bytes: 3060
/*ex5_3
  kt125 */

#include<stdio.h>

int main(void){
    int height, width, //縦、横
        count, //'.'をカウントする変数
        k=0, //カウンタ変数
        row_del_num, //消去する行の数
        col_del_num, //消去する列の数
        height_ans, //答えとなる配列の縦の長さ
        width_ans; //答えをなる配列の横の長さ
    
    scanf("%d %d", &height, &width);

    int col_del[height], //消去する列の番号を記憶する配列
        row_del[width];  //消去する行の番号を記憶する配列
    char board[height][width], //与えられたマス目の配列
         ans_row[height * width]; //答えとなるマス目の文字を一列に並べた配列

    for(int i=0; i < height;i++){
        for (int j=0; j < width; j++){
            scanf(" %c", &board[i][j]);
        }  
    }

    for(int i=0; i < height; i++){
        for(int j=0; j < width; j++){
            if(board[i][j]== '.'){
                count++;
            }
        }
        if (count == width){ //i行が全て'.'だった場合
            row_del[k] = i; //配列の最初から順に用いるためにkを使う
            k++;
        }
        count = 0; //各行ごとにリセット
    }  
    row_del_num = k; //消去する行の数

    k = 0; //リセット

    for(int i=0; i < width; i++){
        for(int j=0; j < height; j++){
            if(board[j][i]== '.'){
                count++;
            }
        }
        if (count == height){ //i列が全て'.'だった場合
            col_del[k] = i;
            k++;
        }
      	count = 0; //各列ごとにリセット
    } 

  	col_del_num = k; //消去する列の数
    
    for(int i=0; i < row_del_num; i++){
        for (int j=0; j < width; j++){
            board[row_del[i]][j] = 'o'; //消去する行の文字を'o'に置き換える
        }
    }
    for(int i=0; i < col_del_num; i++){
        for (int j=0; j < height; j++){
            board[j][col_del[i]] = 'o'; //消去する列の文字を'o'に置き換える
        }
    }
  	k = 0; // リセット
  	
    for(int i=0; i < height; i++){
        for(int j=0; j < width; j++){
            if (board[i][j] != 'o'){ //'o'を飛ばす
                ans_row[k] = board[i][j];
              	k++;
            }
        }
    }

  	height_ans = height - row_del_num; //答えとなる配列の縦の長さ
  	width_ans = width - col_del_num; //答えとなる配列の横の長さ

  	char ans[height_ans][width_ans];  //答えとなる配列

    for(int i=0; i < height_ans; i++){
        for(int j=0; j < width_ans;j++){
            ans[i][j] = ans_row[j + i * (width_ans)]; //一次元の配列をマス目に合うように二次元に直す
        }
    }
  
	for(int i=0; i < height_ans;i++){
        for (int j=0; j < width_ans; j++){
            printf("%c", ans[i][j]); //マス目をprint
        }
        printf("\n");
    }
    return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int n, m;
  cin >> n >> m;
  
  int ac = 0;
  vector<string> ans(n);
  vector<int> p(n);
  rep(i, m) {
    int j;
    cin >> j; --j;
    string temp;
    cin >> temp;
    if (ans[j] == "AC") {
      continue;
    }
    if (temp == "AC") {
      ac++;
      ans[j] = "AC";
    } else {
      p[j]++;
    }
  }
  int pena = 0;
  rep(i, n) {
    if (ans[i] == "AC") pena += p[i]; 
  }
  cout << ac << " " << pena << endl;
  return 0;
}


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

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

void solve(void) {
  int s, w; cin >> s >> w;

  if(w >= s) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

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

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

int main(){
    string s;
    int y, m, d;
    while(cin >> s >> y >> m >> d){
        if(y < 31){
            cout << s << " " << y << " " << m << " " << d << endl;
        }else if(y > 31){
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        }else if(m <= 4){
            cout << s << " " << y << " " << m << " " << d << endl;
        }else{
            cout << "? " << y - 30 << " " << m << " " << d << endl;
        }
    }
}


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

n, m = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]
g = [[] for _ in range(n)]
for _ in range(m):
    a, b = [int(x) for x in input().split()]
    g[a - 1].append(b - 1)
    g[b - 1].append(a - 1)
ans = 0
for i in range(n):
    if len(g[i]) == 0:
        ans += 1
    else:
        flag = 0
        for j in g[i]:
            if h[i] <= h[j]:
                flag = 1
                break
        if not flag:
            ans += 1
print(ans)




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

ll n;

//curnum現在の数字,use3,5,7を使ったかどうか,nownumカウント
ll func(ll curnum, int use,ll &cnt) {
    if(curnum > n) return cnt;
    if(use == 0b111)++cnt;

    func(curnum*10+3, use | 0b001, cnt);
    func(curnum*10+5, use | 0b010, cnt);
    func(curnum*10+7, use | 0b100, cnt);

}

int main() {
 cin >> n;
 ll res=0;
 cout << func(0,0,res) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int maxn=2e5+5;

int main()
{
    ios::sync_with_stdio(false);
    ll n,k;cin>>n>>k;
    if(n>=10)
        cout<<k<<endl;
    else
        cout<<(10-n)*100+k<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

struct st{int a,b,c,d;};
int a[1000][1000];
int dx[]{1,-1,0,0},dy[]{0,0,1,-1};
int main(){
	int h,w;cin>>h>>w;
	rep(i,h)rep(j,w)scanf("%d",&a[i][j]);
	vector<st>v;
	rep(i,h)rep(j,w){
		if(a[i][j]%2){
			rep(k,4){
				int nx=i+dx[k],ny=j+dy[k];
				if(0<=nx&&nx<h&&0<=ny&&ny<w&&a[nx][ny]%2){
					v.push_back({i,j,nx,ny});a[i][j]--;a[nx][ny]++;goto G;
				}
			}
			rep(k,4){
				int nx=i+dx[k],ny=j+dy[k];
				if(0<=nx&&nx<h&&0<=ny&&ny<w&&nx*w+ny>i*w+j){
					v.push_back({i,j,nx,ny});a[i][j]--;a[nx][ny]++;goto G;
				}
			}
			G:;
		}
	}
	cout<<v.size()<<endl;
	for(auto s:v){
		cout<<s.a+1<<' '<<s.b+1<<' '<<s.c+1<<' '<<s.d+1<<endl;
	}
	//~ cout<<"-----------"<<endl;
	//~ rep(i,h){
		//~ rep(j,w){
			//~ cout<<a[i][j]%2<<' ';
		//~ }
		//~ cout<<endl;
	//~ }
}

Measured memory_bytes: 6128
S = input()
s1 = int(S[:2])
s2 = int(S[2:])

# 00<= YY <= 99
# 01<= MM <= 12

if (s1 > 12):
    if (s2 > 12 or s2==0):
        print("NA")
    else:
        print("YYMM")
elif (s1 <= 12 and s1 > 0):
    if s2 > 12 or s2 == 0:
        print("MMYY")
    else:
        print("AMBIGUOUS")
elif s1 == 0:
    if s2 > 12 or s2 == 0:
        print("NA")
    else:
        print("YYMM")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    private static Scanner sc;

    public Main() {
    }

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

    }

    private void solve() {
        int x = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        if (Math.abs(x - a) < Math.abs(x - b)) {
            System.out.println("A");
        } else {
            System.out.println("B");
        }
    }
}


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

int main() {

  char str[1050] = {0};
  char ch[1050] = {0};
  char mei[30] = {0};
  char pl[1050]={0};
  int i,j,k,l,m,n,o,p;

 
  scanf("%s",str);
  scanf("%d",&n);
   
  for(i=0; i<7 ;i++) {
    ch[i] = str[i];
  }

  j=0;
  o=0;
  k=l=0;

  for ( i = 0; i < n; i++ ){
    scanf("%s", mei);
    scanf("%d %d", &k, &l);
    // printf("mei= %s",mei);
  
    
    if(mei[2] =='p') {
     
      scanf("%s", pl);

      for(m=0;m<l-k+1;m++) {

	//	printf("str[%d]%c = pl[%d]%c\n",m+k,str[m+k] ,m,pl[m]);
	str[m+k] = pl[m];	
      }
    }

    else if(mei[2] == 'v') {
      
      for(m=0; m<strlen(str);m++) {
	ch[m] = str[m];
      }
      
      for(m=0;m<l-k+1;m++) {
	//	printf("str[%d]%c = ch[%d]%c\n",k+m,str[k+m],l-m,ch[l-m]);
	str[k+m] = ch[l-m];
      }
    
    }

    else if(mei[0] = 'p') {   
      
      for(m=k; m<=l;m++) {
	printf("%c" ,str[m]);
      }
      printf("\n");
    }
    
  }

   
  return 0;

}

Measured memory_bytes: 576
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, m, a, b;
    ll z = 0;
    priority_queue<pii, vector<pii>, greater<pii>> q;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a >> b, q.push({a, b});
    while (m--) {
        pii x = q.top();
        q.pop();
        z += x.first;
        x.second--;
        if (x.second) q.push(x);
    }
    cout << z;
}


Measured memory_bytes: 1400
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{
    char A[10],B[10],C[10];
    scanf("%s %s %s", &A, &B, &C);
    int la=strlen(A);
    int lb=strlen(B);
    if(A[la-1] == B[0] && B[lb-1] == C[0]){
      printf("YES\n");
    }
    else{

    printf("NO\n");
    }

    return 0;
}


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

using namespace std;

int main() {
    int N, K;
    cin >> N >> K;
    vector<long long int> H(N);
    for(int i = 0; i < N; i++) {
        cin >> H.at(i);
    }
    sort(H.begin(), H.end());
    reverse(H.begin(), H.end());
    long long int sum = 0;
    for(int i = K; i < N; i++) {
        sum += H.at(i);
    }
    cout << sum << endl;
}

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

struct LOGIN{
	int start;
	int end;
};

struct USER {
	int count;
	int start;
	USER(){
		count=0;
		start=0;
	}
	vector<LOGIN> login;
};

int g(int s1,int e1,int s2,int e2)
{
	int s=max(s1,s2);
	int e=min(e1,e2);
	return max(0,e-s);
}

int main() {
	while(true){
		int n,m;
		cin >> n >> m;
		if(n==0)break;
		
		vector<USER> users(m);

		int l;
		cin >> l;
		for(int i=0;i<l;i++){
			int t,p,u,s;
			cin >> t >> p >> u >> s;
			u--;
			if(s==1){
				if( users[u].count==0){
					users[u].start = t;
				}
				users[u].count++;
			}else{
				users[u].count--;
				if(users[u].count==0){
					LOGIN lo={users[u].start,t};
					users[u].login.push_back(lo);
				}
			}
		}
		
		int q;
		cin >> q;
		for(int i=0;i<q;i++){
			int s,e,u;
			cin >> s >> e >> u;
			u--;
			int t = 0;
			for(LOGIN log : users[u].login){
				t += g(s,e,log.start,log.end);
			}
			cout << t << endl; 
		}
	}


	return 0;
}

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

using namespace std;

int main(int argc, char *argv[]) {
    string s;
    cin >> s;

    int A = s[0] - '0';
    bool found(false);
    for (int i = 0; i < 2; i++) {
        char op1 = (i == 0) ? '+' : '-';
        int B = s[1] - '0';
        for (int j = 0; j < 2; j++) {
            char op2 = (j == 0) ? '+' : '-';
            int C = s[2] - '0';
            for (int k = 0; k < 2; k++) {
                char op3 = (k == 0) ? '+' : '-';
                int D = s[3] - '0';
                int ans = A;
                ans = (op1 == '+') ? ans + B : ans - B;
                ans = (op2 == '+') ? ans + C : ans - C;
                ans = (op3 == '+') ? ans + D : ans - D;
                if (ans == 7) {
                    cout << s[0] << op1 << s[1] << op2 << s[2] << op3 << s[3] << "=7" << endl;
                    found = true;
                    break;
                }
            }
            if (found) break;
        }
        if (found) break;
    }
    return 0;
}


Measured memory_bytes: 256
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
 
BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001
 
 
N = int(input())
S = list(map(int,input().split()))
 
DICT = {}
 
for i in range(len(S)):
    DICT[S[i]] = True
 
Q = int(input())
T = list(map(int,input().split()))
 
ans = 0
 
for i in range(len(T)):
    if DICT.__contains__(T[i]):
        ans += 1
 
print("%d"%(ans))


Measured memory_bytes: 7268
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<vector>
#include<fstream>
#include<string>
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
#include<queue>
#include<map>
#include<set>
#include<bitset>
#include<cmath>
#include<typeinfo>

using namespace std;
#define rep(i,m,n) for(int i=m;i<n;++i)
#define llrep(i,m,n) for(ll i=m;i<n;++i)
#define inf 1000000000
#define llinf 1000000000000000000
#define MOD 1000000007
#define ll long long
#define mp make_pair
#define all(v) v.begin(),v.end()

ll dp[60][60];
vector<ll>v;

int main() {
	int n, a, b;
	cin >> n >> a >> b;
	rep(i, 0, n) {
		ll hoge;
		cin >> hoge;
		v.push_back(hoge);
	}
	sort(all(v), greater<ll>());
	int m = 0, big = 0;
	double ave = 0;
	rep(i, 0, a) {
		ave += double(v[i]);
	}
	ave /= a;
	rep(i, 0, n) {
		if (v[a - 1] == v[i]) {
			m++;
		}
		else if (v[a - 1] < v[i]) {
			big++;
		}
		
	}
	rep(i, 0, 60) {
		rep(j, 0, 60) {
			dp[i][j] = 0;
		}
	}
	dp[0][0] = 1;
	rep(i, 0, m) {
		rep(j, 0, i + 1) {
			if (dp[i][j] != 0) {
				dp[i + 1][j] += dp[i][j];
				dp[i + 1][j + 1] += dp[i][j];
			}
		}
	}
	ll ans = 0;
	if (v[a - 1] != v[0]) {
		ans = dp[m][a - big];
	}
	else {
		rep(i, a, min(b, m) + 1) {
			ans += dp[m][i];
		}
	}
	cout.precision(20);
	cout << fixed << ave << endl;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
import numpy as np
from itertools import combinations


def input():
    return sys.stdin.readline()[:-1]


if __name__ == "__main__":
    N = int(input())
    al = [chr(ord('a') + i) for i in range(26)]

    def dfs(s, mx):
        if (len(s) == N):
            print(s)
        else:
            for c in al:
                if c == chr(ord(mx) + 1):
                    break
                tmp = chr(ord(mx) + 1) if (c == mx) else mx
                dfs(s+c, tmp)

    dfs('', 'a')


Measured memory_bytes: 13780
n = gets.to_i
net_values = []

values = gets.split.map(&:to_i)
costs = gets.split.map(&:to_i)

(0...values.length).each do |i|
  if values[i] - costs[i] >= 0
  	net_values.push(values[i] - costs[i])
  end
end

if net_values.length != 0
  puts net_values.inject(:+)
else
  puts 0
end


Measured memory_bytes: 1788
Scanf.scanf "%d" @@ fun n ->
  let a = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  Array.sort (fun x y -> y-x) a;
  let sa = Array.init n (fun i -> a.(i)) in
  for i = n-2 downto 0 do sa.(i) <- sa.(i) + sa.(i+1) done;
  Array.fold_left (fun (c, (ok, x)) y ->
    if ok && x-y <= 2*y then (c+1, (true, y)) else (c, (false, y))) (0, (true, 0)) sa
  |> fst |> Printf.printf "%d\n"

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

int main() {
  int a,b,c,d,e;
  cin >> a>>b>>c>>d>>e;
  int k;
  cin>>k;

  if (e-a >k) {
    cout << ":(" << endl;
  }
  else
    cout<<"Yay!"<<endl;
}


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

typedef long long ll;

ll n, k;

bool need(int*, int);
int main(){
  cin >> n >> k;
  int a[n+1];
  for(int i=1; i<=n; i++) cin >> a[i];
  sort(a+1, a+n+1);

  int l=1, r=n, m;
  if(need(a, 1)){
    cout << 0 << endl;
    return 0;
  }
  if(!need(a, n)){
    cout << n << endl;
    return 0;
  }

  while(l+1<r){
    m = (l+r)/2;
    if(need(a, m)){
      r = m;
    }
    else{
      l = m;
    }
  }

  cout << r-1 << endl;

  return 0;
}

//カードindexが要るならtrue, いらないのならfalse
bool need(int* a, int index){
  int tmp[n];
  for(int i=1, j=1; i<=n; i++){
    tmp[j] = a[i];
    if(i!=index) j++;
  }

  bool dp[n][k];
  for(int i=0; i<n; i++){
    for(int j=0; j<k; j++) dp[i][j] = false;
  }
  dp[0][0] = true;

  for(int i=1; i<n; i++){
    for(int j=0; j<k; j++){
      if(j<tmp[i]) dp[i][j] = dp[i-1][j];
      else dp[i][j] = dp[i-1][j] || dp[i-1][j-tmp[i]];
    }
  }

  for(int j=max(1LL*0, k-a[index]); j<k; j++){
    if(dp[n-1][j]) return true;
  }

  return false;
}


Measured memory_bytes: 24704
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let n:u32 = r.readl();
    let s = n.to_string();
    let splitted_s:Vec<&str> = s.split("").collect();
    let mut res = "No";
    for i in splitted_s {
        if(i == "7"){
            res = "Yes";
            break;
        }
    }

    println!("{}", res);
}


Measured memory_bytes: 2140
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    map<int, int> D;
    int M;
    int d, t;
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> d;
        if(D.count(d)){
            D[d]++;
        }
        else{
            D[d] = 1;
        }
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        cin >> t;
        if(!D.count(t)){
            NO();
            return 0;
        }
        else{
            D[t]--;
            if(D[t] < 0){
                NO();
                return 0;
            }
        }
    }
    YES();

}

Measured memory_bytes: 13004
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MOD = 1e9 + 7;

void solve()
{
    ll n;
    cin>>n;
    ll h[n];
    for(ll i=0;i<n;i++)
    {
        cin>>h[i];
    }
    ll dp[n];
    for(ll i=0;i<n;i++)
    {
        dp[i] = INT_MAX;
    }
    dp[0] = 0;
    for(ll i=0;i< n;i++)
    {
        //cout << "i = "<<i<<"\n";
        for(ll j=i+1;j<i+3;j++)
        {
            //cout<<"j = "<<j<<"\n";
            dp[j] = min(dp[j] , dp[i]+abs(h[i] - h[j]));
           /* for(ll i=0;i<n;i++)
            {
                cout<<dp[i]<<" ";
            }
            cout<<'\n';
            */
        }
    }
    
    //cout<<"\n";
    cout<<dp[n-1]<<"\n";
}

//MAIN 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll t=1;
    while(t--)
    {
        solve();
    }
    return 0;
}


Measured memory_bytes: 5100
using System;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = long.Parse(Console.ReadLine());
            var bigger = 0L;
            //大きいほうの数字を求める
            for(long i = (long)Math.Floor(Math.Sqrt(N));i > 0 ; i--){
              if(N%i == 0){
                bigger = N/i;
                break;
              }
            }

           //大きい数字の10進数の桁数を求め答えを出す
          　var ans = bigger.ToString().Length;
          Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <list>
#include <cstring>
#include <map>
#include <queue>
#include <ctime>
#include <set>
#include <sstream>
#include <unordered_set>
#include <unordered_map>
#include <cmath>

#define pb push_back
#define mp make_pair
#define ll long long
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ull unsigned long long
#define iloop(a,b) for(ll i = a; i < b; ++i)
#define jloop(a,b) for(ll j = a; j < b; ++j)
#define sz(a) int((a).size()) 
#define pb push_back 
#define all(c) (c).begin(),(c).end() 
#define tr(c,i) for(typeofa((c).begin() i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end()) 
#define p(a) cout << a << "\n";
#define p1(a) cout << a << " ";

#define PI 3.141592653589793
#define MOD (ll)(1e9 + 7)

using namespace std;
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef pair<int,int> ii; 

void solve()
{
	string s;
	cin >> s;
	int si = s.length();
	int arr[26];
	memset(arr,0,sizeof(arr));
	iloop(0,si)
	{
		arr[s[i]-'a']++;
	}
	int flag = 0;
	iloop(0,26)
	{
		if(arr[i] == 0) 
		{
			++flag;
			p(char(i+(int)'a'))
			break;
		}
	}
	if(!flag)
		p("None")
}
int main()
{
	bool testing = false;
	IOS
	if(testing)
	{
		freopen("test.txt","rt",stdin);
		int start = clock();
		solve();
		int end = clock();
		cout << "time: " << (end - start)/(double)(CLOCKS_PER_SEC)*1000 << " milliseconds\n";
	}
	else
	{
		solve();
	}
} 

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

int main() {
  string a;
  int r=0;
  cin >> a;
  
  if (a[0] == '+') r += 1;
  else r -= 1;
  if (a[1] == '+') r += 1;
  else r -= 1;
  if (a[2] == '+') r += 1;
  else r -= 1;
  if (a[3] == '+') r += 1;
  else r -= 1;
  
  cout << r << endl;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
l = [[0,0] for _ in range(n)]
for i in range(n):
    l[i][0],l[i][1] = map(int,input().split())
l.sort(key = lambda x:x[0])
ans = 0
for i in range(n):
    ans += l[i][0]*min(m,l[i][1])
    m -= min(m,l[i][1])
    if m == 0:
        break
print(ans)

Measured memory_bytes: 21156
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define F0R(i, a) FOR(i,0,a)
#define ROF(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i, a) ROF(i,0,a)
#define trav(a, x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9 + 7; // 998244353; // = (119<<23)+1
const int MX = 2e5 + 5;

template<class T>
bool ckmin(T &a, const T &b) {
    return a > b ? a = b, 1 : 0;
}

template<class T>
bool ckmax(T &a, const T &b) {
    return a < b ? a = b, 1 : 0;
}

mt19937 rng((uint32_t) chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template<typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template<typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

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

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template<class X, class Y>
std::ostream &operator<<(std::ostream &os, std::pair<X, Y> const &p) {
    return os << p.first << " " << p.second;
}

template<class Ch, class Tr, class Container>
std::basic_ostream<Ch, Tr> &operator<<(std::basic_ostream<Ch, Tr> &os, Container const &x) {
    bool first = true;
    for (auto &y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class BRuinedSquare {
public:
    void solve(std::istream &in, std::ostream &out) {
        int x1, y1, x2, y2;
        in >> x1 >> y1 >> x2 >> y2;
        int dx = x2 - x1, dy = y2 - y1;
        int x3 = x2 - dy, y3 = y2 + dx;
        int x4 = x3 - dx, y4 = y3 - dy;
        assert(x1 == x4 + dy and y1 == y4 - dx);
        out << x3 << ' ' << y3 << ' ' << x4 << ' ' << y4 << '\n';
    }

    void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
    BRuinedSquare solver;
    solver.setup();
    std::istream &in(std::cin);
    std::ostream &out(std::cout);
    in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
    solver.solve(in, out);
    return 0;
}


Measured memory_bytes: 3640
/**
DufauX-XuafuD
**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define reset(x) memset(x,-1,sizeof(x))
#define CheckBit(a,b) (a&(1ll<<b))
#define SetBit(a,b) a=(a|(1ll<<b))
#define UnSetBit(a,b) a=(a&(~(1ll<<b)))
#define maxx 10000006
#define PI 2*acos(0.0)
const long long INF = 2000000000000000000LL;	// 2e18
const int inf = 0x3f3f3f3f;	// 1061109567
const long double EPS = 1e-9;
//bitset<maxx/2>vis;
//bitset<maxx>pr;
//int mobi[maxx+10];
//vector<ll>prime;
//void sieve(){
//    ll x=maxx/2, y=sqrt(maxx)/2;
//    for(ll i=1;i<=y;i++){
//        if(vis[i]==0){
//            for(ll j=(i*(i+1)*2);j<x;j+=(2*i)+1)
//                vis[j]=1;
//        }
//    }
//    prime.push_back(2);
//    for(ll i=3;i<maxx;i+=2)
//        if(vis[i/2]==0)
//        prime.push_back(i);
//}
//void generate_mobius()
//{
//    for(int i=0;i<maxx;i++)mobi[i]=1;
//    for(int i=2;i<maxx;i++){
//        if(!pr[i]){
//            mobi[i]*=-1;
//            for(int j=i+i;j<maxx;j+=i){
//                pr[j]=1;
//                mobi[j]*=(j%(i*i)?-1:0);
//            }
//        }
//    }
//}
//bool isprime(ll a)
//{
//    if(a==1)return false;
//    if(a==2)return true;
//    if(a%2==0)return false;
//    for(ll i=0;i<prime.size() && prime[i]*prime[i]<=a;i++)
//        if(a%prime[i]==0)return false;
//    return true;
//}
/* Calculate ( a*b ) %c */
inline ll mulmod(ll a, ll b, ll c) {
    ll ret = 0 , cur = a % c ;
    while(b) { if(b%2) ret=(ret+cur)%c; cur=(cur<<1)%c; b=b>>1; }
    return ret%c;
}
//Calculate (b^p)%m || modular inverse: b^-1 = bigmod(b, m-2, m)
inline ll bigmod(ll b, ll p, ll m){
    ll ret = 1, cur = b % m;
    while(p) { if(p&1) ret=(ret*cur)%m; cur=(cur*cur)%m; p=p>>1; }
    return ret;
}
inline ll modulo(ll a,ll b,ll c) { //Same as big mod, use for numbers over 1e10
    ll ret = 1 , cur = a%c ;
    while(b) { if(b%2) ret=mulmod(ret,cur,c); cur=mulmod(cur,cur,c); b=b>>1; }
    return ret%c ;
}
inline ll power(ll b, ll p){
    ll ret = 1, cur = b;
    while(p) { if(p&1) ret=(ret*cur); cur=(cur*cur); p=p>>1; }
    return ret;
}
ll lcm(ll a,ll b)
{
    return (a/__gcd(a,b))*b;
}
ll gcd(ll a,ll b)
{
    return __gcd(a,b);
}
void Dufaux()
{
    string a,b;
    cin>>a>>b;
    if(a.size()>b.size()){
        cout<<"GREATER"<<endl;
    }
    else if(a.size()<b.size()){
        cout<<"LESS"<<endl;
    }
    else{
        for(int i=0;i<a.size();i++){
            if(a[i]!=b[i]){
                if(a[i]>b[i]){
                    cout<<"GREATER"<<endl;
                    return;
                }
                else{
                    cout<<"LESS"<<endl;
                    return;
                }
            }
        }
        cout<<"EQUAL"<<endl;
    }
}
int main()
{
    FastIO;
	///sieve();
	///generate_mobius();
	int test=1;
	while(test--){
        Dufaux();
	}
	return 0;
}






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

#define int long long

using namespace std;

signed main(){
    int N;
    cin>>N;
    int arr[N]={0};
    int sum=0;
    int boss[N]={0};
    boss[0] = 1;
    for(int i=0;i<N;i++){
        cin>>arr[i];
    }
    for(int i=1;i<N;i++){
        boss[arr[i]-1]++;
    }
    for(int i=0;i<N;i++){
        cout<<boss[i]<<"\n";
    }

}

Measured memory_bytes: 6760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    ll n,ans=0;cin>>n;
    map< ll , ll , greater<ll> > mp;
    for(ll i=0,x;i<n;i++)cin>>x,mp[x]++;
    vector<ll> a;
    for(auto &ele:mp){
        while(ele.second>=2 && a.size()<2)a.push_back(ele.first),ele.second-=2;
    }
    if(a.size()==2)ans=a[0]*a[1];
    cout<<ans;
}

Measured memory_bytes: 6528
n = int(input())
li = [0] + list(map(int, input().split())) + [0]
ans = 0
for i in range(1, n+2):
    ans += abs(li[i-1] - li[i])
for i in range(1, n+1):
    center = li[i]
    nx = abs(center - li[i+1])
    pr = abs(li[i-1] - center)
    sk = abs(li[i-1] - li[i+1])
    print(ans + sk - nx - pr)

Measured memory_bytes: 14048
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		ArrayDeque<Task> q = new ArrayDeque<Task>();
		ArrayDeque<Task> ans = new ArrayDeque<Task>();
		
		try {
			String[] param = in.readLine().split(" ");
			int lim = Integer.parseInt(param[0]);
			int time = Integer.parseInt(param[1]);
			
			for (int i = 0; i < lim; i++) {
				param = in.readLine().split(" ");
				
				Task t = new Task(Integer.parseInt(param[1]), param[0]);
				q.add(t);
			}
			
			int past = 0;
			while (q.isEmpty() == false) {
				Task tmp = q.remove();
				boolean flag = tmp.minusTime(time);
				
				if (flag == true) {
					past = past + tmp.getTIme() + time;
					ans.add(new Task(past, tmp.getName()));
				} else {
					past = past + time;
					q.add(tmp);
				}
			}
			
			while (ans.isEmpty() == false) {
				Task tmp = ans.remove();
				System.out.println(tmp.getName() + " " + tmp.getTIme());
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

class Task {
	private int time;
	private String name;
	
	public Task(int t, String n) {
		time = t;
		name = n;
	}
	
	public int getTIme() {
		return time;
	}
	
	public String getName() {
		return name;
	}
	
	public boolean minusTime(int t) {
		time = time - t;
		if (time <= 0) return true;
		return false;
	}
}

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

int main() {
	string s,t;
	cin>>s>>t;
	int i,j,ind=-1;
	for(i=0;i<s.size();i++)
	   {
	   		for(j=0;j<t.size();j++)
	   		   {
	   		   		if(s[i+j]==t[j] || s[i+j]=='?')
	   		   		   continue;
	   		   		 break;  
	   		   }
	   		if(j==t.size())
	   		  ind=i;
	   }
	  if(ind==-1)
	    {
	    	cout<<"UNRESTORABLE";
	    	return 0;
	    }
	  for(i=0;i<s.size();i++)
	    {
	    	if(s[i]=='?')
	    	    s[i]='a';
	    }
	//cout<<ind;
	  for(i=ind,j=0;j<t.size();i++,j++)
	     {
	     	s[i]=t[j];
	     }
	    cout<<s; 
	// your code goes here
	return 0;
}

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

int main() {
	int w;
	while (1) {
		cin >> w;
		if (w == -1)break;
		int sum = 0;
		sum += 1150;
		sum += max(0, min(10, w - 10)) * 125;
		sum += max(0, min(10, w - 20)) * 140;
		sum += max(0, w - 30) * 160;
		cout << 4280 - sum << endl;
	}
	return 0;
}

Measured memory_bytes: 2988
/*input
5 8
5 3
2 3
2 4
5 2
5 1
1 4
4 3
1 3


*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
    

 vector<vector<int>> graph;
 vector<bool> visited;
vector<int>dp;
void dfs(int s,int val){
	visited[s] = true;
	int total = 0;
	for(auto i:graph[s]){
		if(!visited[i]) dfs(i,val+1);
		total= max(total,1+(dp[i]));
	}
	dp[s] = max(dp[s],total);
	
}
int32_t main() {
    IOS;
	int n,m;
	cin>>n>>m;
	graph.clear();
	visited.clear();
	graph.resize(n+1);
	visited.resize(n+1);
	dp.clear();
	dp.resize(n+1);
	fill(dp.begin(),dp.end(),0);
	fill(visited.begin(),visited.end(),false);
	for(int i=0;i<m;i++){
		int x,y;cin>>x>>y;
		graph[x].push_back(y);
	}
	for(int i=1;i<=n;i++){
		dfs(i,0);
	}
	cout<<*max_element(dp.begin(),dp.end())<<endl;

	return 0;
}






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

#define int long long
#define For(i, a, b) for (int i = (a); i <= static_cast<int>(b); i++)
#define Forr(i, a, b) for (int i = (a); i >= static_cast<int>(b); i--)
#define rep(i, n) For(i, 0, n - 1)
#define repall(i, arr) for (auto& i : (arr))
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define dump(x) cerr << #x << " = " << (x) << '\n'

template <typename T>
using pq = priority_queue<T>;
template <typename T>
using pqr = priority_queue<T, vector<T>, greater<T>>;
const int INF = INT_MAX / 2;
constexpr int MOD = 1e9 + 7;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vec>;

template <typename T1, typename T2>
ostream& operator<<(ostream& stream, const pair<T1, T2>& p) {
    return stream << p.first << " " << p.second;
}
template <typename T>
void print(const vector<vector<T>> matrix) {
    repall (vec, matrix)
        print(vec);
}
template <typename T>
void print(const vector<T> vec) {
    unsigned int len = vec.size();
    rep (i, len - 1)
        cout << vec[i] << ' ';
    cout << vec[len - 1] << '\n';
}
template <typename Arg>
void print(const Arg arg) {
    cout << arg << '\n';
}
template <typename Head, typename... Args>
void print(const Head head, const Args... args) {
    cout << head << " ";
    print(args...);
}
template <typename T>
T sum_(vector<T> vec, T init = 0) {
    return std::accumulate(all(vec), T(init));
}

void yn(bool tf) { print(tf ? "Yes" : "No"); }
void YN(bool tf) { print(tf ? "YES" : "NO"); }

template <typename T>
void init(vector<vector<T>> m) {
    repall (v, m)
        init(v);
}

template <typename T>
void init(vector<T>& v) {
    rep (i, v.size())
        cin >> v[i];
}

template <typename T, typename U>
void init(vector<T>& v, vector<U>& w) {
    assert(v.size() == w.size());
    rep (i, v.size())
        cin >> v[i] >> w[i];
}

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
// -------------------------------------------------------------------

signed main() {
    cin.tie(0), cout.tie(0), ios::sync_with_stdio(false);
    int d;
    cin >> d;
    cout << "Christmas";
    rep (i, 25 - d)
        cout << " Eve";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, m;
    cin >> n >> m;
    int tim = (n-m)*100+m*1900;
    int ans = (1<<m)*tim;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// ring

#include<stdio.h>
#include<string.h>

int main()
{
    int i=0 ,j=0 ;
    int lens=0 ,lenp=0 ;
    int flg=0 ;
    char mem='\0' ;
    char s[101] = {0} ;
    char p[101] = {0} ;

    scanf("%s %s",s ,p) ;

    lens=strlen(s) ;
    lenp=strlen(p) ;
    for (i=0 ;i<lens ;i++)
    {
        if (strncmp(s ,p ,lenp) == 0)
        {
            flg++ ;
            break ;
        }
        else
        {
            mem=s[0] ;
            for (j=0 ;j<lens ;j++)
            {
                s[j]=s[j+1] ;
            }
            s[lens-1]=mem ;
        }
    }

    if (flg)
    {
        printf("Yes\n") ;
    }
    else
    {
        printf("No\n") ;
    }

    return 0;
}

Measured memory_bytes: 524
#include<iostream>
main(){
  std::string s;
  int d;
  std::cin>>s>>d;
  int n=s.size();
  std::string ans="";
  for(int i=0;i<n;++i){
    if(i%d==0)ans+=s[i];
  }
  std::cout<<ans<<std::endl;
}

Measured memory_bytes: 256