akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int N;
int C,K,T[100010];
int ans = 0,now,fi;

int main()
{
    scanf("%d%d%d",&N,&C,&K);
    for(int i = 0; i < N; i++)scanf("%d",T + i);

    sort(T,T + N);

    now = 0;

    for(int i = 0; i < N; i++)
    {
        if(now == 0)
        {
            fi = T[i];
            ans++;
        }
        else if(T[i] > fi + K || now == C)
        {
            i--;
            now = 0;
            continue;
        }
        now++;
    }
    printf("%d\n",ans);
    return 0;
}


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

int main() {
	ll n;
	cin >> n;
	ll a[n+1], c = 1;
	multiset <ll> ss;
	multiset <ll> :: iterator it;
	for(int i = 1; i < n+1; i++) cin >> a[i];
	ss.insert(a[1]);
	for(int i = 2; i < n+1; i++)
	{
		ss.insert(a[i]);
		if(ss.find(a[i]) == ss.begin()) c++;
		else
		{
		    it = ss.find(a[i]);
		    it--;
		    ss.erase(it);
		}
	}
	cout << c;
	// your code goes here
	return 0;
}


Measured memory_bytes: 5760
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        ArrayList<Arm> li = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int m = sc.nextInt();
            int h = sc.nextInt();
            li.add(new Arm(m-h, m+h));
        }
        Collections.sort(li);
        int ans = 0;
        int right = -Integer.MAX_VALUE;
        for(Arm a : li){
            if(right <= a.l){
                ans++;
                right = a.r;
            }else if(right > a.r){
                right = a.r;
            }
        }
        System.out.println(ans);
    }
}

class Arm implements Comparable<Arm>{
    int l,r;
    public Arm(int l, int r){
        this.l = l;
        this.r = r;
    }
    
    public int compareTo(Arm a){
        if(this.l < a.l){
            return -1;
        }else if(this.l > a.l){
            return 1;
        }else{
            if(this.r < a.r){
                return -1;
            }else if(this.r > a.r){
                return 1;
            }else{
                return 0;
            }
        }
    }
}
class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}

Measured memory_bytes: 44696
N, K = map(int, input().split())
x_list = [0]*N
y_list = [0]*N
for i in range(N):
    x_list[i], y_list[i] = map(int, input().split())

x_element = sorted(x_list)
y_element = sorted(y_list)
ans = float("inf")

for i in range(len(x_element)):
    for j in range(len(y_element)):
        for k in range(i+1, len(x_element)):
            for l in range(j+1, len(y_element)):
                num = 0
                for m in range(N):
                    if x_element[i] <= x_list[m] <= x_element[k] and y_element[j] <= y_list[m] <= y_element[l]:
                        num += 1
                if num >= K:
                    ans = min((x_element[k] - x_element[i]) * (y_element[l] - y_element[j]), ans)

print(ans)


Measured memory_bytes: 47196
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define MAXX 1005
#define PI 3.14159265358979323846264338327950
#define ll signed long long int
using namespace std;
ll t , n, k,  x = 0, y = 2, m, ans = 0 ;
ll a[MAXX][MAXX], b[MAXX], c[MAXX], d;
double f = 0.5;
vector<ll> v[MAXX];
bool used[MAXX];

signed main()
{
	
	cin >> n ;
	ans = pow(n, 3);
	cout <<ans;
	return 0;
    
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef tuple<int, int, int> tp;
typedef long long LL;
typedef long double LD;
typedef pair<int, int> pii;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
typedef pair<LL, LL> pll;
typedef pair<pii, int> piipi;
typedef pair<int, pii> pipii;
typedef pair<pii, pii> piipii;
typedef pair<LL, pii> plpii;
typedef pair<LD, LD> pdd;
typedef pair<LD, int> pdi;
typedef pair<LD, LL> pdl;
typedef pair<int, LD> pid;
typedef pair<LL, LD> pld;
const int mod = 1e9 + 7;
const int hf = 999983;
const int N = 1e6;
LL res[55][55], M[55][55], tmp[55][55];
int main(){
    int m;
    LL n;
    scanf("%d%lld", &m, &n);
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            scanf("%lld", &M[i][j]);
        }
    }
    bool st = 0;
    while(n){
        if(n%2){
            if(!st) for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) res[i][j] = M[i][j];
            else{
                memset(tmp, 0, sizeof(tmp));
                for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) for(int k=1;k<=m;k++) tmp[i][j] = (tmp[i][j] + M[i][k]*res[k][j])%mod;
                for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) res[i][j] = tmp[i][j];
            }
            st = 1;
        }
        memset(tmp, 0, sizeof(tmp));
        for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) for(int k=1;k<=m;k++) tmp[i][j] = (tmp[i][j] + M[i][k]*M[k][j])%mod;
        for(int i=1;i<=m;i++) for(int j=1;j<=m;j++) M[i][j] = tmp[i][j];
        n/=2;
    }

    LL ans = 0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=m;j++){
            ans = (ans + res[i][j])%mod;
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int r;
    cin>>r;
    if(r<1200)
    {
        cout<<"ABC";
    }
    else if(r<2800)
    {
        cout<<"ARC";
    }
    else if(r<4209)
    {
        cout<<"AGC";
    }
}

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

al = list(map(int,input().split()))


# a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


# a,bの最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)


ans = al[0]

for a in al:
    ans = gcd(a, ans)

print(ans)

Measured memory_bytes: 62704
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int A,B;
    cin>>A>>B;
    if(A==B){
            cout<<"Draw"<<endl;
    }
    else if(A==1||A>B){
            if(B==1){
                    cout<<"Bob"<<endl;
            }
            else{
                    cout<<"Alice"<<endl;
            }
    }
    else{
            cout<<"Bob"<<endl;
    }
}


Measured memory_bytes: 3600
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        N:usize
    }
    let mut ans = 0;
    for i in 1..N + 1 {
        ans += i * (N / i) * (N / i + 1) / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2116
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
  int n,mini;
  cin >> n;
  vector <string> data1(n),data2(n);
  for(int i=0;i<n;i++){
    cin >> data1[i];
    data2[i] = data1[i];
  }
  for(int i=0;i<n-1;i++){
    for(int j=n-1;j>i;j--){
      if(data1[j][1]<data1[j-1][1]) swap(data1[j],data1[j-1]);
    }
  }
  for(int i=0;i<n;i++){
    mini = i;
    for(int j=i;j<n;j++){
      if(data2[j][1]<data2[mini][1]) mini = j;
    }
    if(mini != i) swap(data2[i],data2[mini]);
  }
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data1[i];
  cout << endl << "Stable" << endl;
  for(int i=0;i<n;i++) cout << (i!=0?" ":"") << data2[i];
  if(data1==data2) cout << endl << "Stable" << endl;
  else cout << endl << "Not stable" << endl;
}



Measured memory_bytes: 3164
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using static kyoupuro.Input;
using static kyoupuro.MyMath;

namespace kyoupuro {

    class MainClass {

        public static void Main() {
            // エラトステネスの篩
            var sums = Enumerable.Repeat(1, 100001).ToArray();
            sums[0] = sums[1] = 0;
            for (int i = 2; i <= 100000;) {
                for (int j = i * 2; j <= 100000; j += i) {
                    sums[j] = 0;
                }

                for (i = i + 1; i <= 100000 && sums[i] == 0; i++) {}
            }

            // 降順累積和
            for (int i = 100000 - 1; i > 0; i--) {
                if (sums[i] == 0 || sums[(i + 1) / 2] == 0) sums[i] = 0;
                sums[i] += sums[i + 1];
            }

            // クエリ
            var Q = NextInt();
            for (int i = 0; i < Q; i++) {
                var l = NextInt();
                var r = NextInt();
                Console.WriteLine(sums[l] - sums[r + 1]);
            }
        }
    }

    class MyMath {
        static long Gcd(long a, long b) {
            return b == 0 ? a : Gcd(b, a % b);
        }
    }

    class Input {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line() {
            return Console.ReadLine();
        }

        public static int NextInt() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return int.Parse(enumerator.Current);
        }

        public static long NextLong() {
            while (!enumerator.MoveNext()) {
                enumerator = StrArr().AsEnumerable().GetEnumerator();
            }
            return long.Parse(enumerator.Current);
        }

        public static string[] StrArr() {
            return Line().Split(' ');
        }

        public static List<int> IntList() {
            return StrArr().Select(int.Parse).ToList();
        }

        public static List<long> LongList() {
            return StrArr().Select(long.Parse).ToList();
        }

        public static void Skip(int line = 1) {
            enumerator.Reset();
            for (int i = 0; i < line; i++) Console.ReadLine();
        }

        public static void Reset() {
            enumerator.Reset();
        }
    }
}

Measured memory_bytes: 16960
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<ll> A(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> A[i];
	}
	sort(A.begin(), A.end());

	auto num = 1;
	auto sum = 0ll;
	for (auto i = 0; i < N - 1; ++i)
	{
		sum += A[i];
		if (sum * 2 >= A[i + 1])
		{
			++num;
		}
		else
		{
			num = 1;
		}
	}

	cout << num << endl;

	return 0;
}

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

struct ca
{
  int idx,st,et,aidx;
};

int prime[1000001]={};

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p; 
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  
         
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1; 
        x = (x*x) % p;  
    }  
    return res;  
}  

void pr()
{
  prime[1]=0;

 for(int i=2;i*i<1000001;i++)
  if(prime[i]==0)
  for(int j=i*i;j<1000001;j+=i)
  prime[j]=1;

}

int countSetBits( int n) 
{ 
     int count = 0; 
    while (n) { 
        count += n & 1; 
        n >>= 1; 
    } 
    return count; 
} 
  
bool cmp1(ca c1,ca c2)
{
  if(c1.st<c2.st)
   return true;

  if(c1.st==c2.st && c1.idx<c2.idx)
   return true;

  return false;
}

bool cmp2(ca c1,ca c2)
{
  
  if(c1.idx<c2.idx)
  return true;
  return false;
}








int main()
{

  ios_base::sync_with_stdio(false);
    cin.tie(NULL);

   //pr();
  int t;
  // cin>>t;
   t=1;
  int id=1;

  while(t--)
{
     int n;
      cin>>n;

    int arr[200001]={};

   for(int i=0;i<n-1;i++)
  {
    int a;
     cin>>a;
     arr[a]++;
   }

  for(int i=1;i<=n;i++)
  cout<<arr[i]<<"\n";

    //double d= 2*pi*n;

    //cout<<d;
   
}



return 0;
}


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

class UnionFind{
public:
    //親の番号を格納。親の場合は-(集合のサイズ)
    vector<int> Parent;

    //最初に作るときはParentの要素は-1
    UnionFind(int N){
        Parent = vector<int>(N, -1);
    }

    //Aがどのグループにいるのか
    int root(int A){
        if(Parent[A]<0) return A;
        return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループのサイズを調べる
    int size(int A){
        return -Parent[root(A)];
    }

    bool connect(int A, int B){
        A = root(A);
        B = root(B);
        if(A==B){
            return false;
        }

        if(size(A)<size(B)) swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

int main(){
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i = 0; i < M; i++)
    {
        cin >> A[i] >> B[i];
        A[i]--;
        B[i]--;
    }
    vector<ll> ans(M);
    ans[M-1] = (ll)N*(N-1)/2;

    UnionFind Uni(N);

    for(int i = M - 1; i >= 1; i--)
    {
        ans[i-1] = ans[i];
        if(Uni.root(A[i]) != Uni.root(B[i])){
            ans[i-1] -= (ll)Uni.size(A[i])*Uni.size(B[i]);
            Uni.connect(A[i], B[i]);
        }
    }
    
    for(int i = 0; i < M; i++)
    {
        cout << ans[i] << endl;
    }
    
    
}

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

int main() {
  int N,A,B,C,D;
  cin>>N;
  
  A=N/1000;
  B=N%1000/100;
  C=N%1000%100/10;
  D=N%1000%100%10;
  
  if(A==B&&A==C){
    cout <<"Yes"<<endl; 
  }
  
  else if(B==C&&B==D){
    cout <<"Yes"<<endl; 
  }
  
  else{
    cout<<"No"<<endl;
  }
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
#define mod 1000000007

using namespace std;
#define maxn 100005
vector<int> a;
string s;

int dp[maxn][13];

int solve(int idx, int rem)
{
	if(idx == s.length())
		return rem % 13 == 5;
	
	if(dp[idx][rem] != -1)
		return dp[idx][rem];
	
	int res = 0;
	if(s[idx] != '?')
	{
		res += solve(idx+1, ( rem*10 % 13 + (s[idx] - '0')) % 13 );
		res %= mod;
	}
	else
	{
		for(int i=0; i<=9; i++)
		{
			res += solve(idx+1, (rem*10 % 13 + i) % 13);
			res %= mod;
		}
	}
	dp[idx][rem] = res % mod;
	return res;
}

signed main()
{
	//freopen("input.txt", "r", stdin);
	cin>>s;
	int n = s.length();
	memset(dp, -1, sizeof(dp));
	cout << solve(0, 0) % mod<<"\n";	
}


Measured memory_bytes: 18432
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	cin>>n;
	int t=0,flag=0;
	while(n--)
	{
		int x,y;
		cin>>x>>y;
		if(x==y)
		{
			t++;
		}
		else
		t=0;
		if(t==3)
		{
			flag=1;
			break;
		}
	}
	if(flag==1)printf("Yes\n");
	else printf("No\n");
}

Measured memory_bytes: 3536
import java.util.Scanner;
import java.util.Stack;

public class Main {
    static int n;
    static Scanner sc = new Scanner(System.in);
    
    static boolean aun(){
        Stack<String> au = new Stack<>();
        for(int i=0;i<n;i++){
            String say = sc.next();
            //System.err.println(say);
            if(say.equals("A")){
                au.push("A");
            }
            if(say.equals("Un")){
                if(au.isEmpty()){
                    return false;
                }else{
                    au.pop();
                }
            }
            //System.err.println(au);
        }
        if(au.isEmpty()){
        	return true;
        }else {
        	return false;
        }
    }
    
    public static void main(String[] args) {
        n = sc.nextInt();
        if(n%2 == 1) {
        	System.out.println("NO");
        	return;
        }
        if(aun()){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }    
    }
}


Measured memory_bytes: 26396
gets
ARGF.each_line do |line|
  x1, y1, x2, y2, x3, y3 = line.split.map(&:to_f)
  
  px = -((y2 - y1) * y3**2 + (-y2**2 + y1**2 - x2**2 + x1**2) * y3 + y1 * y2**2 + (-y1**2 + x3**2 - x1**2) * y2 + (x2**2 - x3**2) * y1) /
        ((2 * x2 - 2 * x1) * y3 + (2 * x1 - 2 * x3) * y2 + (2 * x3 - 2 * x2) * y1)
  py = ((x2 - x1) * y3**2 + (x1 - x3) * y2**2 + (x3 - x2) * y1**2 + (x2 - x1) * x3**2 + (x1**2 - x2**2) * x3 + x1 * x2**2 - x1**2 * x2) /
       ((2 * x2 - 2 * x1) * y3 + (2 * x1 - 2 * x3) * y2 + (2 * x3 - 2 * x2) * y1)
  r = Math.sqrt((px - x1)**2 + (py - y1)**2)

  px = sprintf("%.3f", (px * 1000).round / 1000.0)
  py = sprintf("%.3f", (py * 1000).round / 1000.0)
  r  = sprintf("%.3f", (r  * 1000).round / 1000.0)
  puts [px, py, r].join("\s")
end

Measured memory_bytes: 8580
a,z;c(char*p){a=*p-*1[&p];}d(char*p){a=*1[&p]-*p;}main(b,s){for(;~scanf("%s",s);)z++?qsort(s,8,1,d),b=atoi(s),qsort(s,8,1,c),printf("%d\n",b-atoi(s)):0;}

Measured memory_bytes: 0
#include <stdio.h>
 
int main(){
   int n,h[101],i,j,m;
    
   scanf("%d",&n);
   for (i=0;i<n;i++) scanf("%d",&h[i]);
   for (i=m=0;i<n;i++) {
     while (h[i]>0) {
        m++;
        for (j=i;j<n && h[j]>0;j++) h[j]--;
     }
   }
   printf("%d\n",m);
   return 0;
}


Measured memory_bytes: 128
# C

N = int(input())
A = [input().split(), input().split()]

for i in range(2):
    for j in range(N):
        A[i][j] = int(A[i][j])

B = [[0 for j in range(N)] for i in range(2)]
B[0][0] = A[0][0]
B[1][0] = A[0][0] + A[1][0]

for j in range(1, N):
     B[0][j] = B[0][j-1] + A[0][j]

for j in range(1, N):
     B[1][j] = max(B[1][j-1], B[0][j]) + A[1][j]

print(B[i][N-1])

Measured memory_bytes: 3064
from sys import stdin
# import sys

# A, B, C = [int(x) for x in stdin.readline().rstrip().split()]
N = [int(x) for x in stdin.readline().rstrip().split()]
# U = input().split()
# A, B = [str(x) for x in stdin.readline().rstrip().split()]

A = list(map(int, input().split()))

# print(A)
d = {}
for i in range(len(A)):
    d[A[i]] = d.get(A[i], 0)+1
for i in range(1, N[0]+1):
    print(d.get(i, 0))


Measured memory_bytes: 33528
#標準入力

N,M = map(int, input().split())

#[1,1,…,1]というリストを作成する
#最終的に良い展望台の数を和で求めるため、１で始める

good = [1 for i in range(N)]


#標準入力で高さの一覧を取得

height = list(map(int, input().split()))
 
#道の数Mだけ、入力を繰り返す

for i in range(M):
  a,b = map(int, input().split())

#一括で受け取らず、受取→処理をM回繰り返す
#高さのリストと一致させるため-1

  a -= 1
  b -= 1

#２つの高さを比較し、低い方の展望台を、最初のリストで０にする

  if height[a] <= height[b]:
    good[a] = 0

  if height[a] >= height[b]:
    good[b] = 0

#goodリストで「１」のままの展望台は、つながっている道でいけるどの展望台よりも高い

print(sum(good))

Measured memory_bytes: 20732
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(
				new InputStreamReader(System.in))) {

			String in = br.readLine();
			String inp = br.readLine();
			int n = Integer.parseInt(in);
			int a = Integer.parseInt(inp);
			System.out.println(n*n-a);

		}
	}
}

Measured memory_bytes: 25324
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()

using namespace std;

int main() {
    int n, ans = 1000;
    cin >> n;
    vector<int> a(n);
    rep(i, n){
        int cnt=0;
        cin >> a.at(i);
        while(a.at(i)%2 == 0){
            cnt++;
            a.at(i)/=2;
        }
        ans = min(ans, cnt);
    }
    cout << ans;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(ll i = x; i <= n; i++)
#define rep3(i, x, n) for(ll i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    ll N, K;
    cin >> N >> K;
    ll A[N];
    rep(i, N) cin >> A[i];
    sort(A, A+N);
    //解は[l,r]に存在
    ll l = -1e18, r = 1e18;
    while(l < r){
        ll n = (l+r)/2;
      	if(l+r < 0 && 2*n != l+r) n--;
        //n以下になるものが何個あるか判定
        ll sum = 0;
        rep(i, N){
            if(A[i] < 0){
                ll x = n/A[i];
                rep2(j, x-1, x+1){
                    if(A[i]*j <= n){
                        sum += A+N - lower_bound(A, A+N, j);
                        break;
                    }
                }
            }
            elif(A[i] == 0){
                if(n >= 0) sum += N;
            }
            else{
                ll x = n/A[i];
                rep3(j, x+1, x-1){
                    if(A[i]*j <= n){
                        sum += upper_bound(A, A+N, j)- A;
                        break;
                    }
                }
            }
            if(A[i]*A[i] <= n) sum--;
        }
        sum /= 2;
        if(sum < K) l = n+1;
        else r = n;
    }
    cout << l << endl;
}

Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
#include<queue>
using namespace std;
#define vel vector<long long>
#define vvel vector<vel>
#define int long long
#define rep(i,n) for(long long i=0;i<n;i++)
#define sor(v) sort(v.begin(),v.end())
#define mmax(a,b) a=max(a,b)
#define mmin(a,b) a=min(a,b)
#define mkp make_pair
#define pin pair<int,int>
#define V vector
long long p = 998244353;
vel kai(4001, 1);
vel ink(4001, 1);
vel uni(vel &list) {
	if (list.size() == 0) { return list; }
	sort(list.begin(), list.end());
	vel ql(1, list[0]);
	rep(i, list.size() - 1) {
		if (list[i] != list[i + 1]) { ql.push_back(list[i + 1]); }
	}
	return ql;
}
int ru(int a, int r) {
	if (r == 0) { return 1; }
	int ans = ru(a, r / 2);
	ans *= ans; ans %= p;
	if (r % 2 == 1) { ans *= a; }
	return ans % p;
}
int inv(int a) {
	return ru(a, p - 2);
}
void make_kai() {
	rep(i, 4000) { kai[i + 1] = (kai[i] * (i + 1)) % p; }
	rep(i, 4001) { ink[i] = inv(kai[i]); }
}
int com(int n, int r) {
	int ans = kai[n] * ink[r];
	ans %= p; ans *= ink[n - r]; ans %= p;
	return ans;
}
signed main() {
	int m, k; cin >> m >> k;
	if ((1 << m) <= k) { cout << -1 << endl; return 0; }
	if (m == 0) { cout << 0 << " " << 0 << endl; }
	else if (m == 1) {
		if (k == 0) { cout << 0 << " " << 0 << " " << 1 << " " << 1 << endl; }
		else { cout << -1 << endl; }
	}
	else {
		vel ans(1 << (m+1));
		rep(i, 1 << m) { ans[i] = i; ans[i] ^= k; }
		rep(i, 1 << m) {
			if (i == 0) { ans[i+(1<<m)] = 0; }
			else { ans[i+(1<<m)] = (1 << m) - i; }
			ans[i+(1<<m)] ^= k;
		}
		rep(i, ans.size()-1) { cout << ans[i] << " "; }
		cout << ans[ans.size() - 1] << endl;
	}
	return 0;
}

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

int main() {
long A,B,K;
cin>>A>>B>>K;

int i=0;
while(K>i){
  if(i%2==0){
    B+=A/2;
    A/=2;
    i++;
  }
  else{
    A+=B/2;
    B/=2;
    i++;
  }
}
cout<<A<<" "<<B<<endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    int sum[n];
    int a = 0;
    for (int i = 0; i < n; i++) sum[i] = 0;
    for (int i = 0; i < 2*m; i++) {
        cin >> a;
        sum[a-1]++;
    }
    for (int i = 0; i < n; i++) {
        cout << sum[i] << endl;
    }
}

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

if K%2==0:
    print(-1)
    exit()


now=0
count=0
N=0
flag=False
while True:
    now+=(7*pow(10,count, K))%K
    now%=K
    #print(N)
    if not flag:
        N+=7*10**(count)
    if N>=K:
        flag=True
    #print(now, count)
    if now==0 and flag:
        print(count+1)
        exit()
    count+=1
    if count>10**6:
        break


print(-1)

Measured memory_bytes: 63544
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if x == 500 * i + 100 * j + 50 * k:
                ans += 1
print(ans)


Measured memory_bytes: 3060
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            string S = Console.ReadLine();
            string ans = "Sunny";
            if (S == "Sunny")
            {
                ans = "Cloudy";
            }
            else if (S == "Cloudy")
            {
                ans = "Rainy";
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
ll maxl(ll a, ll b){ return ((a<b)?b:a);}
ll minl(ll a, ll b){ return ((a>b)?b:a);}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int n,w;
    cin >> n >> w;
    pair<int,int> arr[n];
    for (int i=0;i<n;i++){
        cin >> arr[i].first; // Weight
        cin >> arr[i].second; // Value
    }
    vector<vector<int>> dp(n,vector<int>(1e5+1,INT_MAX));
    dp[0][0] = 0;
    dp[0][arr[0].second] = arr[0].first;
    for (int i=0;i<n-1;i++){
        for (int j=0;j<=1e5;j++){
            if (dp[i][j] == INT_MAX)
                continue;
            if (dp[i][j] + arr[i+1].first <= w)
                dp[i+1][j + arr[i+1].second] = min(dp[i+1][j + arr[i+1].second],dp[i][j] + arr[i+1].first);
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    int ans = 0;
    for (int i=0;i<n;i++){
        for (int j=0;j<=1e5;j++){
            if (dp[i][j] == INT_MAX)
                continue;
            ans = max(ans,j);
        }
    }
    cout << ans << "\n";
}


Measured memory_bytes: 42800
a,b=map(int, input().split())
K = b-1
S = list(input())
if S[K] == 'A':
    S[K] = 'a'
elif S[K] == 'B':
    S[K] = 'b'
elif S[K] == 'C':
    S[K] = 'c'
print(''.join(S))

Measured memory_bytes: 3060
import numpy as np
N = int(input())
A = list(map(int, input().split()))
d = {}
x = 0

for i, a in enumerate(A):
    if i+a not in d:
        d[i+a] = 1
    else:
        d[i+a] += 1
    if i-a in d:
        x += d[i-a] 

print(x)

Measured memory_bytes: 57972
//#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
// 293206GT
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <unordered_set>
#include <stack>
#include <string>
#include<algorithm>
#include <random>
#include <bitset>
#include <chrono>

typedef long long ll;
#define int ll
using namespace std;
#define put(a) cout << (a) << '\n'
#define sqr(x) (x) * (x)
typedef pair<ll, ll> pii;
typedef long double ld;

typedef pair<ld, ld> pld;
#define rep(x, y, a) for (int x = (y); x < (int)(a); ++x)
#define all(a) a.begin(), a.end()
#define chkmax(a, b) a = max(a, (b))
#define chkmin(a, b) a = min(a, (b))
#define prev asasdasd
#define next aasdasda
#define left asdasdasdasd
#define right asnabsdkasdl
#define rank asdasdknlasd
#define move asdasdas

typedef vector<int> vi;
typedef vector<pii> vpii;
namespace IO {
    template<class A, class B>
    ostream &operator<<(ostream &out, pair<A, B> &a) {
        out << a.first << " " << a.second;
        return out;
    }

    template<class A, class B>
    ostream &operator<<(ostream &out, vector<pair<A, B>> &a) {
        for (pair<A, B> x: a)
            out << x.first << " " << x.second << '\n';
    }

    template<class A>
    ostream &operator<<(ostream &out, vector<A> &a) {
        for (A x: a) out << x << ' ';
        return out;
    }

    template<class A, class B>
    istream &operator>>(istream &in, pair<A, B> &a) {
        in >> a.first >> a.second;
        return in;
    }

    template<class A>
    istream &operator>>(istream &in, vector<A> &a) {
        for (A &x: a) in >> x;
        return in;
    }
}
using namespace IO;

void solve() {
   int n, m;
   cin >> n >> m;
   rep(i, 0, m) {int a;cin >> a; n -= a;}
   if (n < 0) put(-1);
   else put(n);
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

//    freopen("input.txt", "r", stdin);
    int t = 1;
//    cin >> t;
    while (t--) solve();
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef long int li;
typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<float, float> ff;
typedef pair<double, double> dd;
typedef unsigned int ui;
typedef vector<ii> vii;
typedef vector<ff> vff;
typedef set<int> si;
typedef set<lli> slli;
typedef vector<lli> vlli;
typedef long long ll;
typedef long long ll;
typedef vector<ll> vll;
typedef unsigned long long int ulli;
#define MOD 1000000007
#define INF (unsigned)(~0)>>1
typedef pair<int, ii> iii;
void arr_int(int* given_arr, int n){
  for(int i=0;i<n;i++)
    scanf("%d", &given_arr[i]);
  return;
}
void solve();
int main(int argc, char const *argv[]){
  solve();
  return 0;
}
void solve(){
  int N, R;
  scanf("%d %d", &N, &R);
  int ans;
  if(N<10)
    ans = R + 100*(10-N);
  else
    ans = R;
  printf("%d\n", ans);
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cstdlib>

int count[4];
std::string in;

int main(){
    std::cin >> in;
    for(int i = 0; i < in.size(); ++i){
        char c = in[i];
        switch (c) {
            case 'K':
                ++count[0];
                break;
            case 'U':
                ++count[1];
                break;
            case 'P':
                ++count[2];
                break;
            case 'C':
                ++count[3];
                break;
       }
    }
    
    int ans = 0;
    while (true) {
        bool flag1 = false, flag2 = false;
        for(int i = 0; i < 4; ++i){
            if(count[i] == 0){
                flag1 = true;
                break;
            }
            --count[i];
        }
        if(!flag1)
            ++ans;
        else
            break;
    }
    
    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
int main(){
  int i,j,N,minj,count=0;
  int tmp;
  scanf("%d",&N);
  int A[N];
  for(i=0;i<N;i++)scanf("%d",&A[i]);

  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    tmp=A[i];
    A[i]=A[minj];
    A[minj]=tmp;
    if(A[i]!=A[minj])count++;
  }


  for(i=0;i<N-1;i++)printf("%d ",A[i]);
  printf("%d",A[N-1]);
  printf("\n%d\n",count);
  return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace Main
{
    public static class Program
    {
        public static List<int> list = new List<int>();
 
        static void Main(string[] arg)
        {
            int n = int.Parse(Console.ReadLine());
            var v = GetIntList(Console.ReadLine());
            var c = GetIntList(Console.ReadLine());

            var answer = 0;

            var sublist = new List<int>();

            for(int i = 0;i<n;i++){
                int s = v[i] - c[i];
                answer += s > 0?s:0;
            }


            Console.WriteLine(answer);
            Console.ReadLine();
 
        }
        
        #region libraries
        private static int[] GetIntList(string line)
        {
            return line.Split(' ').Select(x => int.Parse(x)).ToArray();
 
        }
        private static double[] GetDoubleList(string line)
        {
            return line.Split(' ').Select(x => double.Parse(x)).ToArray();
 
        }
        private static ulong[] GetUlongList(string line)
        {
            return line.Split(' ').Select(x => ulong.Parse(x)).ToArray();
        }
        private static long[] GetLongList(string line)
        {
            return line.Split(' ').Select(x => long.Parse(x)).ToArray();
        }
        private static int SearchNearest(this IEnumerable<int> list, int target)
        {
            var min = list.Min(c => Math.Abs(c - target));
            return list.First(c => Math.Abs(c - target) == min);
        }
        public static bool IsOdd(int i)
        {
            return i % 2 == 1 ? true : false;
        }
        public static int Gcd(int a,int b)
        {
            if(a < b)
            {
                Gcd(b, a);
            }
            while (b != 0)
            {
                var rm = a % b;
                a = b;
                b = rm;
            }
            return a;
        }
        #endregion
    }
}


Measured memory_bytes: 13396
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        var S = ReadLine();
        if (S.Length < 26) {
            char c = 'a';
            while (S.Contains(c)) {
                c++;
            }
            WriteLine(S + c);
            return;
        } else {
            if (S == "zyxwvutsrqponmlkjihgfedcba") {
                WriteLine(-1);
                return;
            }

            for (int i = S.Length - 1; i >= 0; i--) {
                if (S.Substring(i, S.Length - i).Any(c => c > S[i])) {
                    WriteLine(S.Substring(0, i) + S.Substring(i, S.Length - i).Where(c => c > S[i]).OrderBy(c => c).First());
                    break;
                }
            }
        }
    }
}



class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13396
#include <stdio.h>

int main(){
  int a, b;
  char s;
  scanf("%d%d", &a, &b);
  if (a < b){
    printf("a < b\n");
  }
  if (a > b){
    printf("a > b\n");
  }
  if (a == b){
    printf("a == b\n");
  }
  return 0;
}

Measured memory_bytes: 580
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);
	    Integer A = scanner.nextInt();
	    Integer B = scanner.nextInt();
	    Integer C = scanner.nextInt();

	    Integer res1 = A + B;
	    Integer res2 = A + C;
	    Integer res3 = B + C;

	    if(res1<res2) {
	    	if(res1<res3) {
	    		System.out.println(res1);
	    	}else {
	    		System.out.println(res3);
	    	}
	    }else if (res2<res3) {
			System.out.println(res2);
		}else {
			System.out.println(res3);
		}

	}

}

Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long
#define ull unsigned long long
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

string s;
int a[3];

int main(){
  cin>>s;

  rep(i,s.size()){
    a[s[i]-'a']++;
  }

  if(abs(a[0]-a[1])<2&&abs(a[0]-a[2])<2&&abs(a[1]-a[2])<2){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }

  return 0;
}


Measured memory_bytes: 512
def resolve():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    dp = [False]*(K+1)
        
    for i in range(K+1):
        for j in range(N):
            if i - A[j] >= 0:
                dp[i] |= not dp[i-A[j]]
    if dp[K]:
        print("First")
    else:
        print("Second")


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 9668
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("[DEBUG] ");W(__VA_ARGS__);}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1<<20;
const LL INF = 1e18;
int main(){
    int N;
    R(N);
    VL a(N);
    LL v=1;
    REP(i,N){
        R(a[i]);
        if(!a[i]){
            W(0);
            return 0;
        }
    }
    REP(i,N){
        if(v>INF/a[i]){
            W(-1);
            return 0;
        }
        v*=a[i];
    }
    W(v);
    return 0;
}


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
int main () {
  long N, M;
  cin >> N >> M;
  vector<vector<long>> data(N, vector<long> (2));
  for(int i = 0; i < N; i++){
    cin >> data.at(i).at(0);
  }
  long a, b;
  for(int i = 0; i < M; i++){
    cin >> a >> b;
    a--;
    b--;
    data.at(a).at(1) = max(data.at(a).at(1), data.at(b).at(0));
    data.at(b).at(1) = max(data.at(b).at(1), data.at(a).at(0));
  }
  long ans = 0;
  for(int i = 0; i < N; i++){
    if(data.at(i).at(0) > data.at(i).at(1))ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 8804
#include <iostream>
#include <algorithm>
using namespace std;
const int INF = 1e9 + 7;
typedef long long LL;

LL type1(LL H, LL W){
    if(H < 3)return W;
    else{
        LL s[3], res = INF;
        for(LL i = 1; i <= H - 2; i ++){
            s[0] = i * W;
            s[1] = ( (H - i) / 2 ) * W;
            s[2] = ((H - i) - (H - i) / 2 ) * W;
            sort(s, s + 3);
            res = min(s[2] - s[0], res);
        }
        return res;
    }
}

LL type2(LL H, LL W){
    LL s[3], res = INF;
    for(int i = 1; i <= H - 1; i ++){
        s[0] = i * W;
        s[1] = (H - i) * (W / 2);
        s[2] = (H - i) * (W - W / 2);
        sort(s, s + 3);
        res = min(s[2] - s[0], res);
    }
    return res;
}
int main(){
    LL H, W, ans;
    cin>>H>>W;
    ans = min(type1(H, W), type1(W, H));
    ans = min(type2(H, W), ans);
    ans = min(type2(W, H), ans);
    cout<<ans;
    return 0;
}


Measured memory_bytes: 256
import sys
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))

def main():
    N = INT()
    print(N//3)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
#define LEN 100005

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

P Q[LEN];
int head, tail, n;

void enqueue(P x){
  Q[tail] = x;
  tail=(tail+1)%LEN;
}

P dequeue(){
  P x = Q[head];
  head=(head+1)%LEN;
  return x;
}
int min(int a,int b){return a<b ? a:b;}

int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  head=1;
  tail=n+1;
  while(head!=tail){
    u=dequeue();
    c=min(q,u.t);
    u.t-=c;
    elaps+=c;
    if(u.t>0)
      enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}

Measured memory_bytes: 10756
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        d: [(usize, usize); n],
    }

    for i in 0..n - 2 {
        if d[i].0 == d[i].1 && d[i + 1].0 == d[i + 1].1 && d[i + 2].0 == d[i + 2].1 {
            println!("Yes");
            return;
        }
    }

    println!("No");
}


Measured memory_bytes: 2200
#include <iostream>
#include <string>

using namespace std;

bool isHeisei(int y, int m, int d)
{
	if (y < 2019) return true;
	if (y > 2019) return false;
	if (m < 4) return true;
	if (m > 4) return false;
	if (d <= 30) return true;
	return false;
}

int main()
{
	int y, m, d;
	char slash;
	cin >> y >> slash >> m >> slash >> d;
	if (isHeisei(y, m, d)) {
		cout << "Heisei" << endl;
	}
	else {
		cout << "TBD" << endl;
	}
}


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

const int maxn=1e5+10;
typedef long long ll;

ll v[maxn],d[maxn],n,c,s[maxn];

ll want(){
	for(int i=0;i<=n;i++) s[i]=-(1e17);
	ll sum=0,ret=0;
	for(int i=1;i<=n;i++){
		sum+=v[i];
		s[i]=max(s[i-1],sum-d[i]);
	}
	sum=0;
	for(int i=n;i>=1;i--){
		sum+=v[i];
		ret=max(ret,s[i-1]+(sum-(c-d[i])*2));
	}
	ret=max(ret,s[n]);
	return ret;
}

int main(){
	scanf("%lld%lld",&n,&c);
	for(int i=1;i<=n;i++) scanf("%lld%lld",&d[i],&v[i]);
	ll sum1=want();
	for(int i=1;i<=n;i++) d[i]=c-d[i];
	reverse(v+1,v+n+1);
	reverse(d+1,d+n+1);
	ll sum2=want();
	ll ans=0;
	ans=max(ans,max(sum1,sum2));
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<vector>
#include <algorithm>
using namespace std;
int main() {
    int s;
    cin >> s ;
    int num;
    num =0;
    num = (s / 100) + ( (s - (s/100)*100) /10 ) + (s - (s/100)*100 - ( (s - (s/100)*100) /10 )*10 );
    cout << num << endl;
}

Measured memory_bytes: 3636
#include<iostream>
using namespace std;
int main(){
    int num;
    cin >> num;
    for(int i=1;i<=num;i++){
        int x = i;
        if(i%3==0){
            cout << " " << i;
        }else{
            while(x>0){
                if(x%10==3){
                    cout << " " << i;
                    break;
                }
                x/=10;
            }
        }
    }
    cout << endl;
    return 0;
}



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

# def num_divisors_trial_division(n):
#     num = 0
#     for i in range(1, int(n ** (1 / 2)) + 1):
#         if n % i == 0:
#             num += 1
#             if n != i ** 2:
#                 num += 1
#     return num
#
# ans = 0
# for j in range(1, n):
#     ans += num_divisors_trial_division(j)
#     #print(i , ans)
# print(ans)

ans = 0
for i in range(1, n):
    ans += (n - 1) // i
print(ans)


Measured memory_bytes: 9156
package main

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

func scanInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func scanInt64() int64 {
	sc.Scan()
	i, _ := strconv.ParseInt(sc.Text(), 10, 64)
	return i
}

func scanInts(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = scanInt()
	}
	return res
}

func scanInts64(n int) []int64 {
	res := make([]int64, n)
	for i := range res {
		res[i] = scanInt64()
	}
	return res
}

func scanText() string {
	sc.Scan()
	return sc.Text()
}

var sc = bufio.NewScanner(os.Stdin)

const maxCapacity = 2*1e5 + 10

func main() {
	buf := make([]byte, maxCapacity)
	sc.Buffer(buf, maxCapacity)
	sc.Split(bufio.ScanWords)

	s := scanText()
	t := scanText()

	sum := 0
	for i := 0; i < len(s); i++ {
		if s[i:i+1] != t[i:i+1] {
			sum++
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 2376
#include"bits/stdc++.h"
using namespace std;

#define endl "\n"
#define int long long

int ar[1000000];
int dp[1000000];

int f( int i, int n ){
    if( i == n )return 0;
    if( dp[i] != -1 )return dp[i];
    int cost = abs(ar[i] - ar[i+1]) + f(i+1, n);
    if( i+2 <= n ){
        cost = min(cost, abs(ar[i]-ar[i+2]) + f(i+2, n));
    }
    return dp[i] = cost;
}

int32_t main(){
    int n;
    cin >> n;
    for( int i = 1; i <= n; i++ ){
        cin >> ar[i];
    }
    memset(dp, -1, sizeof(dp));
    cout << f(1, n);
} 

Measured memory_bytes: 15104
#include <iostream>
#include <vector>
#include <queue>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;
using graph = vector<vector<int>>;

const int INF = 1001001001;

int main(){
	int n,m;
	cin >> n >> m;
	graph G(n);
	rep(i,m){
	int a,b;
    cin >> a >> b;
    a--,b--;
	G[a].push_back(b);
	G[b].push_back(a);
	}
	
	vector<int> dist(n,INF);
	queue<int> q;
  	vector<int> kari(n, -1);
	
	dist[0] = 0;
	q.push(0);
	
	while(!q.empty()){
		int e = q.front();
		q.pop();
		
		for(int f : G[e]){
			if(dist[f] != INF) continue;
			
			dist[f] = dist[e] + 1;
          	kari[f] = e;
			q.push(f);
		}
	}
  cout << "Yes" << endl;
	rep(i,n){
      	if(i == 0) continue;
      	int an = kari[i];
      	an++;
		cout << an << endl;
	}
}


Measured memory_bytes: 10636