akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////
ll D;
ll T = 26;//タイプ数
ll c[27];
ll s[366][27];


int main() {
	cin >> D;
	repn(i, T) cin >> c[i];
	repn(i, D)repn(j, T) cin >> s[i][j];

	
	repn(i, D) {
		ll id = 1;
		repn(j, T) {
			if (s[i][id] < s[i][j]) { id = j; }
			}
		cout << id << endl;
	}
	
}

Measured memory_bytes: 3712
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>

unsigned int solv(unsigned int const N, unsigned int const M) {
  unsigned int const MaxPrime = std::sqrt(M);
  std::vector<bool> is_prime(MaxPrime+1, true);
  std::vector<unsigned int> prime;
  is_prime[0] = false;
  is_prime[1] = false;

  for (size_t i=2; i<=std::sqrt(MaxPrime); i++) {
    if (is_prime[i]) {
      for (size_t j=i*i; j<=MaxPrime; j+=i) {
        is_prime[j] = false;
      }
    }
  }

  for (size_t i=2; i<=MaxPrime; i++)
    if (is_prime[i]) {
      prime.push_back(i);
    }

  std::vector<unsigned int> factors(1, 1);
  auto m = M;

  for (auto const p : prime) {
    if (m < p) break;

    size_t b = 0;
    while (m % p == 0) {
      for (size_t e = factors.size(); b!=e; b++) {
        factors.push_back(factors[b] * p);
      }
      m /= p;
    }
  }

  for (size_t i=0, e=factors.size(); i<e; i++) {
    factors.push_back(M / factors[i]);
  }

  std::sort(factors.begin(), factors.end());

  auto f = *std::find_if(factors.begin(), factors.end(),
                         [=](unsigned int f){return f >= N;});
  return M / f;
}

int main() {

  unsigned int N, M;

  std::cin >> N >> M;

  std::cout << solv(N, M) << std::endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
  
using namespace std;
  
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
  
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
  
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
  
int F()
{
    char ch;
    int x, a;
    while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    if (ch == '-') ch = getchar(), a = -1;
    else a = 1;
    x = ch - '0';
    while (ch = getchar(), ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + ch - '0';
    return a * x;
}
  
const int mod = 1e9 + 7;
  
int n;
  
int dp[4010][4010];
  
PII x[200010];
  
int& f(int x, int y) { return dp[x + 2005][y + 2005]; }
  
int inc(int x, int y)
{
    x += y;
    if (x >= mod) x -= mod;
    return x;
}
  
int dec(int x, int y)
{
    x -= y;
    if (x < 0) x += mod;
    return x;
}
  
int fpow(int a, int x)
{
    int ret = 1;
    for (; x; x >>= 1)
    {
        if (x & 1) ret = 1LL * ret * a % mod;
        a = 1LL * a * a % mod;
    }
    return ret;
}
  
int fac[8010], ifac[8010];
  
int C(int n, int m)
{
    if (n < m || m < 0) return 0;
    return 1LL * fac[n] * ifac[m] % mod * ifac[n - m] % mod;
}
  
int main()
{
    fac[0] = 1;
    for (int i = 1; i <= 8000; ++i)
        fac[i] = 1LL * fac[i - 1] * i % mod;
    ifac[8000] = fpow(fac[8000], mod - 2);
    for (int i = 8000; i; --i)
        ifac[i - 1] = 1LL * ifac[i] * i % mod;
    gi(n);
    for (int i = 1; i <= n; ++i)
        gii(x[i].fi, x[i].se), ++f(-x[i].fi, -x[i].se);
    for (int i = -2000; i <= 2000; ++i)
        for (int j = -2000; j <= 2000; ++j)
            f(i, j) = inc(f(i, j), f(i - 1, j)), f(i, j) = inc(f(i, j), f(i, j - 1));
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        ans = inc(ans, f(x[i].fi, x[i].se));
    for (int i = 1; i <= n; ++i)
        ans = dec(ans, C((x[i].fi + x[i].se) << 1, x[i].fi << 1));
    ans = 1LL * ans * fpow(2, mod - 2) % mod;
    printf("%d\n", ans);
    return 0;
}

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

int main() {
  int n; cin >> n;
  bool f = false;
  for(int i = 0; i <= n/7; i++){
    for(int j = 0; j <= n/4; j++){
      if(7*i + 4*j == n) f = true;
    }
  }
  if(f) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>

using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define RREP(i, n) for(int i = n - 1; i >= 0; i--)
#define REP2(i, n, k) for(int i = 0; i < n; i += k)


int main() {
    ll n, p[5] = {};
    
    cin >> n;
    REP(i, n){
        string s;
        cin >> s;
      
      	if(s[0] == 'M'){
            p[0]++;
        }
        else if(s[0] == 'A'){
            p[1]++;
        }
        else if(s[0] == 'R'){
            p[2]++;
        }
        else if(s[0] == 'C'){
            p[3]++;
        }
        else if(s[0] == 'H'){
            p[4]++;
        }
    }
    
    sort(p, p + 5);
    /*
    REP(i, 5){
        cout << p[i] << ' ';
    }
    cout << endl;
    */
    
    if(p[3] == 0){
        cout << 0 << endl;
        return 0;
    }
    
    ll ans = 0;
    REP(i, 3){
        if(p[i]){
            for(int j = i + 1; j < 4; j++){
                ll t = 0;
                for(int k = j + 1; k < 5; k++){
                    t += p[k];
                }
                ans += p[i] * p[j] * t;
                // cout << p[i] << ' ' << p[j] << ' ' << t << endl;
                // cout << i << ' ' << j << ' ' << endl;
            }
        }
    }
    
    cout << ans << endl;
}


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

using namespace std;

typedef long long ll;

const int N=2e5+50;
ll n,m,k,arr[N],brr[N];

int solve(ll val){
    int low=1,high=m,mid,x=0;
    while(low<=high){
        mid=low+(high-low)/2;
        if (brr[mid]<=val){
            x=mid;
            low=mid+1;
        }
        else
            high=mid-1;
    }
    return x;
}

int main()
{
    cin>>n>>m>>k;
    for (int i=1;i<=n;i++){
        cin>>arr[i];
        arr[i]+=arr[i-1];
    }
    for (int i=1;i<=m;i++){
        cin>>brr[i];
        brr[i]+=brr[i-1];
    }
    int ans=0;
    for (int i=0;i<=n;i++){
        if (arr[i]>k)
            break;
        ans=max(ans,solve(k-arr[i])+i);
    }
    cout<<ans;

    return 0;
}


Measured memory_bytes: 6696
#include<stdio.h>



int main()
{
  int dan,ans,count,i,DAN[31];
  DAN[1]=1;
  DAN[2]=2;
  DAN[3]=4;


  while(1){
    scanf("%d",&dan);
    if(dan==0)break;
    count=1;


    for(i=4;i<=dan;i++)
      {
	DAN[i]=DAN[i-1]+DAN[i-2]+DAN[i-3];
      }
    while(1){
    if(DAN[dan]>=3650)
      {
	DAN[dan]=DAN[dan]-3650;
	count++;
      }
    else{break;}

    }
    printf("%d\n",count);
  }
  return 0;
}

Measured memory_bytes: 0
# -*- coding: utf-8 -*-
from copy import copy
from heapq import *
from collections import deque


N, K = list(map(int, input().split()))
jewels = deque(list(map(int, input().split())))
score = []

def startLoop(jewels, k, i, j):
    hand = []
    if k >= N:
        for _ in range(N):
            heappush(hand, jewels.pop())
    else:
        for _ in range(i):
            heappush(hand, jewels.popleft())
        for _ in range(j):
            heappush(hand, jewels.pop())
    return hand

def maximize(l, hand):
    s_max = 0
    s = 0
    for _ in range(min(l, len(hand))):
        s -= heappop(hand)
        if s > s_max:
            s_max = s
    return s_max

for k in range(K+1):
    current_score = -10**10
    for i in range(0, k+1):
        hand = startLoop(copy(jewels), k, i, k-i)
        temp_score = sum(hand) + maximize(K-k, copy(hand))
        if current_score < temp_score:
            current_score = temp_score
    score.append(current_score)

print(max(score))


Measured memory_bytes: 61788
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int MOD = 998244353;
long long INF = 1e18;
long long repow(long long x, long long y){
    if(y == 0) return 1;
    long long res = 1;
    while(y != 0){
        if(y & 1) res = res * x % MOD;
        y >>= 1;
        x = x * x % MOD;
    }
    return res;
}
int main(){
    long long N, S;
    cin >> N >> S;
    vector<long long> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    vector<vector<long long>> dp(N + 1, vector<long long> (S + 1, 0));
    long long t = repow(2, N - 1);
    long long invt = repow(2, MOD - 2);
    for(int i = 0; i < N; i++){
        for(int j = 0; j < S + 1; j++){
            dp[i + 1][j] += dp[i][j];
            dp[i + 1][j] %= MOD;
            if(j != 0 && dp[i][j] == 0) continue;
            if(j + A[i] > S) continue;
            if(dp[i][j] == 0) dp[i + 1][j + A[i]] += t;
            else dp[i + 1][j + A[i]] += dp[i][j] * invt % MOD;
            dp[i + 1][j + A[i]] %= MOD;
        }
    }
    cout << dp[N][S] << endl;
}

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

int main(){

	ios::sync_with_stdio(0);
	cin.tie(0);

	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	
	long long int x;
	cin>>x;

	long long int amt = 100,ans=0;

	while(amt < x){
		ans++;
		amt = amt+ amt/100;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;int main(){
   // int t;cin>>t;while (t--) {
        int n;
        cin >> n;
        if (n == 1) {
            cout << "Yes" << endl;
        } else {
            vector<int> v;
            // Note that this loop runs till square root
            for (int i = 1; i <= sqrt(n); i++) {
                if (n % i == 0) {
                    // If divisors are equal, print only one
                    if (n / i == i)
                        v.push_back(i);

                    else {
                        v.push_back(i);
                        v.push_back(n / i);
                    }
                }
            }
            sort(v.begin(), v.end());
            int ans = v.size();
            int mid = ans / 2;
            if (ans % 2 != 0) {
                int k = v[mid];
                int l = v[mid - 1];
                if ((k >= 1) && (k <= 9) && (l >= 1) && (l <= 9))
                    cout << "Yes" << endl;
                else
                    cout << "No" << endl;
            } else {
                int k = v[mid];
                if ((k >= 1) && (k <= 9))
                    cout << "Yes" << endl;
                else
                    cout << "No" << endl;
            }
        }
    }

    




Measured memory_bytes: 256
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N,L=MI()
    S=[ST() for _ in range(N)]
    S.sort()
    print(*S,sep="")
if __name__ == '__main__':
    main()

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

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int main(){
  ll h,w;
  cin >> h >> w;
  string s[h];
  vector<vector<char>> t(h, vector<char>(w));
  rep(i,h) cin >> s[i];
  rep(i,h)rep(j,w) t[i][j]='.';
  
  rep(i,h)rep(j,w){
    if(s[i][j]=='.') continue;
    rep(k,4){
      int ii = i+dx[k];
      int jj = j+dy[k];
      if(ii<0 || ii>h-1) continue;
      if(jj<0 || jj>w-1) continue;
      if(s[ii][jj]=='#'){
        t[ii][jj]='#';
        t[i][j]='#';
        break;
      }
    }
  }
  int cnt=0;
  rep(i,h)rep(j,w){
    if(s[i][j]==t[i][j]) cnt++;
  }
  if(cnt==h*w) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
#include <string.h>
int main()
{
    char s1[10],s2[10],s3[10];
    scanf("%s %s %s",&s1,&s2,&s3);
    int s11,s22,s33;
    s11=strlen(s1);
    s22=strlen(s2);
    s33=strlen(s3);
    if(s1[s11-1]==s2[0]&&s2[s22-1]==s3[0])
        printf("YES");
    else
        printf("NO");

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#include <stdarg.h>
#include <assert.h>
#include <ctype.h>

using namespace std;
typedef long long int lli;
typedef vector<int> iv;
typedef vector<bool> bv;
typedef vector<string> sv;
typedef vector<long long int> llv;
typedef vector<double> dv;

#define sor_(vec) sort(vec.begin(),vec.end())
#define rev_(vec) reverse(vec.begin(),vec.end())
#define rep(i,n) for(int i=0;i<static_cast<int>(n);i++)
#define reps(i,n,s) for(int i=static_cast<int>(s);i<static_cast<int>(n);i++)
#define isposi(num) if(num>0)
const long long mod = 1000000007;

void printm(char const *format,...){
    va_list arguments;
    va_start(arguments,format);
    unsigned index=0;
    while (format[index]!='\0') {
        if(format[index]=='%'){
            index++;
            if(format[index]=='d')printf("%d",va_arg(arguments, int));
            else if(format[index]=='c')printf("%c",va_arg(arguments, int));
            else if(format[index]=='x')printf("%x",va_arg(arguments,int));
            else if(format[index]=='o')printf("%o",va_arg(arguments,int));
            else if(format[index]=='f')printf("%f",va_arg(arguments, double));
            else if(format[index]=='s')printf("%s",va_arg(arguments, char const *));
            else if(format[index]=='p')printf("%p",va_arg(arguments,void*));
            else if(format[index]=='y')printf("Yes");
            else if(format[index]=='n')printf("No");
            else if(format[index]=='%')printf("%%");
            else assert(!"Unknown format with %.");
        }
        else printf("%c",format[index]);
        index++;
    }
    va_end(arguments);
    return;
}

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c;
    std::cin>>a>>b>>c;
    printm("%d %d %d",c,a,b);
    return 0;
}


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

int main() {
  vector<int> a(3);
  for(int i=0; i<3; i++){
    cin >> a.at(i);
  }

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

  cout << a.at(0)+a.at(1) << endl;

return 0;  
}

Measured memory_bytes: 256
import math
from itertools import accumulate

def eratosthenes(n):
    if not isinstance(n, int):
        raise TypeError('n is int type.')
    if n < 2:
        raise ValueError('n is more than 2')
    prime = [2]
    limit = int(n**0.5)
    data = [i + 1 for i in range(2, n, 2)]
    while True:
        p = data[0]
        if limit <= p:
            return prime + data
        prime.append(p)
        data = [e for e in data if e % p != 0]

max_lr = 100000
er_list = eratosthenes(max_lr)
count = [0] * max_lr


for i in range(len(er_list)):
    if (er_list[i]+1)//2 in er_list:
        count[er_list[i]] = 1
            
count = list(accumulate(count))
            
Q = int(input())
for i in range(Q):
    l, r = map(int, input().split())
    print(count[r]-count[l-1])

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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    int n;
    cin >> n;
    vll a(n);
    rep(i, n) cin >> a[i];

    if (a[0] != 0) {
        cout << -1 << endl;
        return 0;
    }

    int x = 0;
    rep(i, n) {
        if (x + 1 >= a[i]) x = a[i];
        else {
            cout << -1 << endl;
            return 0;
        }
    }

    ll cur = 0;
    ll ans = 0;
    rep(i, n) {
        if (cur + 1 == a[i]) {
            ans += 1;
        } else {
            ans += a[i];
        }
        // cout << i << " " << cur << " " << ans << endl;
        cur = a[i];
    }

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


Measured memory_bytes: 1792
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<bitset>
using namespace std;

typedef long long ll;
#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1;} return 0;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1;} return 0;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    string s, t; cin >> s >> t;
    int ans = 0;
    rep(i,s.size()) {
        if(s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3920
N, x = map(int, input().split())
X = list(map(lambda p: abs(int(p) - x), input().split()))


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


q = X[0]
for i in range(1, N):
    q = gcd(q, X[i])

print(q)

Measured memory_bytes: 14252
import math

EPS = 1e-10

def equals(a, b):
    return abs(a - b) < EPS


class Point:
    def __init__(self, x=0, y=0):
        self.x = x
        self.y = y

    def __add__(self, p):
        return Point(self.x + p.x, self.y + p.y)

    def __sub__(self, p):
        return Point(self.x - p.x, self.y - p.y)

    def __mul__(self, a):
        return Point(self.x * a, self.y * a)

    def __rmul__(self, a):
        return self * a

    def __truediv__(self, a):
        return Point(self.x / a, self.y / a)

    def norm(self):
        return self.x * self.x + self.y * self.y

    def abs(self):
        return math.sqrt(self.norm())

    def __lt__(self, p):
        if self.x != p.x:
            return self. x < p.x
        else:
            return self.y < p.y

    def __eq__(self, p):
        return equals(self.x, p.x) and equals(self.y, p.y)


class Segment:
    def __init__(self, p1, p2):
        self.p1 = p1
        self.p2 = p2


def dot(a, b):
    return a.x * b.x + a.y * b.y


def cross(a, b):
    return a.x * b.y - a.y * b.x


def ccw(p0, p1, p2):
    COUNTER_CLOCKWISE = 1
    CLOCKWISE = -1
    ONLINE_BACK = 2
    ONLINE_FRONT = -2
    ON_SEGMENT = 0
    a = p1 - p0
    b = p2 - p0
    if cross(a, b) > EPS:
        return COUNTER_CLOCKWISE
    if cross(a, b) < -EPS:
        return CLOCKWISE
    if dot(a, b) < -EPS:
        return ONLINE_BACK
    if a.norm() < b.norm():
        return ONLINE_FRONT
    return ON_SEGMENT


def intersect(s1, s2):
    p1 = s1.p1
    p2 = s1.p2
    p3 = s2.p1
    p4 = s2.p2
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
            ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)


def getDistanceLP(l, p):
    v = l.p2 - l.p1
    return abs(cross(v, p - l.p1) / v.abs())


def getDistanceSP(s, p):
    if dot(s.p2 - s.p1, p - s.p1) < 0:
        v = p - s.p1
        return v.abs()
    if dot(s.p1 - s.p2, p - s.p2) < 0:
        v = p - s.p2
        return v.abs()
    return getDistanceLP(s, p)


def getDistance(s1, s2):
    if intersect(s1, s2):
        return 0
    return min(
        getDistanceSP(s1, s2.p1),
        getDistanceSP(s1, s2.p2),
        getDistanceSP(s2, s1.p1),
        getDistanceSP(s2, s1.p2)
    )


if __name__ == '__main__':
    q = int(input())
    ans = []
    for i in range(q):
        x0, y0, x1, y1, x2, y2, x3, y3 = [int(v) for v in input().split()]
        s1 = Segment(Point(x0, y0), Point(x1, y1))
        s2 = Segment(Point(x2, y2), Point(x3, y3))
        ans.append(getDistance(s1, s2))

    for v in ans:
        print('{0:.10f}'.format(v))


Measured memory_bytes: 5908
#include <bits/stdc++.h>
#define int long long
using namespace std;
int knapsack(int *weight, int *value, int n, int w)
{
    int sum = accumulate(value, value + n, 0);
    int dp[n][sum + 1];

    for (int i = 0; i < n; i++)
        for (int j = 0; j <= sum; j++)
            dp[i][j] = INT_MAX;

    for (int r = 0; r < n; r++)
        dp[r][0] = 0;
    dp[0][value[0]] = weight[0];
    for (int i = 1; i < n; i++)
    {
        for (int j = 1; j <= sum; j++)
        {
            dp[i][j] = dp[i - 1][j];
            if (j >= value[i])
            {
                dp[i][j] = min(dp[i][j], dp[i - 1][j - value[i]] + weight[i]);
            }
        }
    }
    int ans = 0;
    for(int i=0;i<=sum;i++)
    {
        if(dp[n-1][i]<=w)
        {
            ans = i;
        }
    }
    return ans;
}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n, w;
    cin >> n >> w;
    int weight[n];
    int value[n];

    for (int i = 0; i < n; i++)
    {
        cin >> weight[i] >> value[i];
    }
    cout << knapsack(weight, value, n, w);
    return 0;
}

Measured memory_bytes: 78336
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    VVI e(n);
    REP(i,n-1){
        int u = in() - 1, v = in() - 1;
        e[u].push_back(v);
        e[v].push_back(u);
    }
    VL c(n);
    ll sum = 0;
    REP(i,n){
        c[i] = in();
        sum += c[i];
    }
    sort(ALL(c));
    reverse(ALL(c));
    sum -= c[0];

    queue<int> que;
    VI ans(n), visit(n);
    int x = 0;
    que.push(0);
    visit[0] = 1;
    while (!que.empty()){
        int now = que.front();
        que.pop();
        ans[now] = c[x++];
        for (int next : e[now]){
            if (visit[next]) continue;
            visit[next] = 1;
            que.push(next);
        }
    }
    cout << sum << endl;
    REP(i,n) cout << ans[i] << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1152
f=-1
N=int(input())
S=[];T=[];U=[]
for i in range(N):
  a=list(input())
  S.append(a)
#print(S)
for i in range(1,N):
  if S[i-1][-1]!=S[i][0]:
    f=1
for i in range(N):
  T.append("".join(S[i]))
U=set(T)
if f!=1 and len(T)==len(U):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 3064
// I can !

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define pb push_back
#define mp make_pair
#define forn(i,n) for(ll i=0;i<n;i++)
#define fore(i,a,b) for(ll i=a;i<=b;i++)
#define ford(i,n) for(ll i=n-1;i>=0;i--)
#define fi first
#define se second
#define endl "\n"
#define all(a) a.begin(),a.end()
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

const ll maxn=1e6+1,mod=1e9+7;

vector<vector<ll> > g(maxn);
vector<pair<ll,ll> > lvl;

void dfs(ll cur,ll par,ll l){
    lvl.pb(mp(l,cur));
    // cout<<cur<<endl;
    for(auto it:g[cur]){
        if(it==par) continue;
        dfs(it,cur,l+1);
    }
}


int main(){

    sync
    
   
    ll n;
    cin>>n;
    forn(i,n-1){
        ll x,y;
        cin>>x>>y;
        g[x].pb(y);
        g[y].pb(x);
    }
    dfs(1,1,1);
    sort(all(lvl));
    vector<ll> val;
    ll maxi = -1;
    ll sum = 0;
    forn(i,n){
        ll x;
        cin>>x;
        maxi = max(maxi,x);
        sum+=x;
        val.pb(x);
    }
    sum-=maxi;
    sort(all(val));
    reverse(all(val));

    ll itr = 0;
    vector<int> vall(n+1);
    for(auto it:lvl){
        vall[it.se] = val[itr++];
    }
    cout<<sum<<endl;
    fore(i,1,n){
        cout<<vall[i]<<" ";
    }
    
    return 0;
}

Measured memory_bytes: 25216
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	private void run() throws IOException {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			int[][] map = new int[n][2];
			for (int i = 0; i < n; i++) {
				map[i][0] = scanner.nextInt();
			}
			for (int i = 0; i < n; i++) {
				map[i][1] = scanner.nextInt();
			}

			int[] ans = new int[2];
			for (int i = 0; i < 2; i++) {
				int x = i;
				int y = 0;
				int count = 0;
				boolean[][] b = new boolean[n][2];
				while (true) {
					if (b[y][x]) {
						ans[i] = Integer.MAX_VALUE;
						break;
					}
					if (y == n - 1 && map[y][x] != 2) {
						ans[i] = count;
						break;
					}
					b[y][x] = true;
					if (y < n - 1 && map[y][x] == 1 && map[y + 1][x] == 1)
						y++;
					else if (map[y][x] == 2)
						y--;
					else {
						if (x == 0)
							x = 1;
						else
							x = 0;
						if (y == n - 2)
							y += 1;
						else
							y += 2;
						count++;
					}
				}
			}
			if (ans[0] == Integer.MAX_VALUE && ans[1] == Integer.MAX_VALUE)
				System.out.println("NA");
			else
				System.out.println(ans[0] < ans[1] ? ans[0] : ans[1]);
		}
	}
}

Measured memory_bytes: 26396
N,L = map(int,input().split())
a = list()
ans = 0
wa = 0
for i in range(1,N+1):
  a.append(L+i-1)
  ans += L+i-1
mi = 10**7
for i in range(N):
  if abs(a[i]) < mi:
    mi = abs(a[i])
    wa = a[i]
print(ans-wa)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")
using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define forn(i, a, n) for (int i = (int)(a); i < (int)(n); ++i)
#define ford(i, a, n) for (int i = (int)(n) - 1; i >= (int)(a); --i)
#define fore(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
    for (auto i : a) cerr << i << ' ';\
    cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

template<typename T>
inline void setmax(T& a, T b) {
    if (a < b) a = b;
}

template<typename T>
inline void setmin(T& a, T b) {
    if (a > b) a = b;
}

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

const int N = 5555;
vector<int> e[N];
int sz[N];
int n;

int find_sz(int u, int p) {
    sz[u] = 1;
    for (int v : e[u]) {
        if (v == p) continue;
        sz[u] += find_sz(v, u);
    }
    return sz[u];
}

pair<int, int> find_centroid(int u, int p) {
    int best = -1;
    for (int v : e[u]) {
        if (v == p) continue;
        if (best == -1 || sz[v] > sz[best])
            best = v;
    }
    if (best == -1 || 2 * sz[best] <= n)
        return {u, p};
    return find_centroid(best, u);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); 
    srand((unsigned)chrono::high_resolution_clock::now().time_since_epoch().count());
    cin >> n;
    forn(i, 1, n) {
        int u, v;
        cin >> u >> v;
        --u, --v;
        e[u].eb(v);
        e[v].eb(u);
    }
    find_sz(0, -1);
    pair<int, int> c = find_centroid(0, -1);
    vector<int> sizes;
    int sum = 0;
    for (int u : e[c.fs]) {
        if (u == c.sn) continue;
        sizes.eb(sz[u]);
        sum += sz[u];
    }
    if (c.sn != -1) sizes.eb(n - 1 - sum);
    //trace(sizes);
    vector<ll> fact(n + 1);
    fact[0] = 1;
    fore(i, 1, n) fact[i] = fact[i - 1] * i % MOD;
    vector<vector<ll>> binom(n + 1, vector<ll>(n + 1));
    fore(i, 0, n) fore(j, 0, n) {
        if (j == 0) {
            binom[i][j] = 1;
            continue;
        }
        if (i == 0) {
            binom[i][j] = 0;
            continue;
        }
        binom[i][j] = binom[i - 1][j] + binom[i - 1][j - 1];
        if (binom[i][j] >= MOD) binom[i][j] -= MOD;
    }
    vector<ll> part(n + 1);
    part[0] = 1;
    for (int x : sizes) {
        vector<ll> npart(n + 1);
        fore(i, 0, n)
            fore(j, 0, x) {
                if (i + j > n) break;
                npart[i + j] += part[i] * binom[x][j] % MOD * binom[x][j] % MOD * fact[j];
                npart[i + j] %= MOD;
            }
        part = npart;
    }
    ll ans = 0;
    fore(i, 0, n) {
        ans += (n % 2 == i % 2 ? 1 : -1) * fact[i] * part[n - i];
        //cerr << i << ' ' << fact[i] << ' ' << part[n - i] << '\n';
        ans %= MOD;
    }
    if (ans < 0) ans += MOD;
    cout << ans << '\n';
}


Measured memory_bytes: 196480
#include <iostream>

int main()
{
	using namespace std;

	int n;
	cin >> n;

	int max = 0;
	int result = 0;
	for (int i = 0; i < n; i++)
	{
		int h;
		cin >> h;

		if (h >= max)
		{
			result++;
			max = h;
		}
	}

	cout << result << endl;
}

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

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

    int d[210];
    rep(i, n-1) {
        if (a[i] < a[i+1]) d[i] = 1;        /* 明日は上がるのでi日は手持ちすべて安く買うべき. */
        else if (a[i] > a[i+1]) d[i] = -1;  /* 明日は下がるのでi日は手持ちすべて高く売るべき. */
        else d[i] = 0;                      /* 昨日と変わらず. */
    }
    d[n-1] = 0;

    /* 最後の売り日をチェック. */
    int last = 0;
    rep(i, n) if(d[i] != 1) last = i;

    /* 負け戦はすぐにやめる. */
    if (last == 0) {
        cout << 1000 << endl;
        return 0;
    }

    ll money = 1000;
    ll kabu  = 0;
    rep(i, n) {
        if (d[i] == 1) {
            kabu += (money/a[i]);
            money %= a[i];
        }
        if ((d[i] == -1) || (d[i] == 0)) {
            money += (kabu * a[i]);
            kabu = 0;
        }
//        cout << i << ": " << "mone = " << money << endl;
//        cout << i << ": " << "kabu = " << kabu << endl;
        if (i == last) break;
    }

    cout << money << endl;
	return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define For(a,b,c) for(int a=b,_=c;a<=_;++a)
using namespace std;
int n,m,A[(1<<18)|5];
multiset<int> S;
int main() {
	scanf("%d",&n);
	For(i,1,1<<n) {
		int x;
		scanf("%d",&x);
		S.insert(-x);
	}
	A[m=1]=-*S.begin(); S.erase(S.begin());
	For(i,1,n) {
		sort(A+1,A+1+m,greater<int>());
		For(j,1,m) {
			multiset<int>::iterator it=S.upper_bound(-A[j]);
			if(it==S.end()) {
				puts("No");
				return 0;
			}
			A[++m]=-*it;
			S.erase(it);
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
#define PI 3.141592653589793
#define MOD 1000000007
//#define MOD 998244353
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 60;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,ans=0;
    cin >> n;
    bool x[200];
    fill(x,x+200,false);
    for (ll i=0;i<n;i++){
        ll a;
        cin >> a;
        if (x[a]){
            continue;
        }
        x[a]=true;
        ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__


a,b,m = map(int, input().split())
aa = list(map(int, input().split()))
bb = list(map(int, input().split()))
ans = min(aa) + min(bb)

for i in range(m):
    x,y,c = map(int, input().split())
    x,y = x-1, y-1
    tmp = aa[x] + bb[y] - c
    ans = min(ans, tmp)
print(ans)

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

int main(){
	const int limit = 101;
	int x;
	int integers[limit];
	for(int i = 1; i < limit; i++)
		integers[i] = 0;
	while(cin >> x) integers[x]++;
	int kmax = 0;
	for(int i = 1; i < limit; i++)
		kmax = max(kmax, integers[i]);
	for(int j = 1; j < limit; j++)
		if(integers[j] == kmax)
			cout << j << endl;
	return 0;
}

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

int reverseNum(int d) {
	int r_d;
	if (d == 1) {r_d = 9;} else if(d = 9) {r_d = 1;}
	return r_d;
}

int main() {
	int n, d1, d10, d100;
	cin >> n;
	d100 = n / 100;
	d10 = (n - d100 * 100) /10;
	d1 = n - d100 * 100 - d10 * 10;
	
	d1 = reverseNum(d1);
	d10 = reverseNum(d10);
	d100 = reverseNum(d100);
	
	cout << d100 << d10 << d1 << endl;
	return 0;
}

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


#define li			long long int
#define rep(i,to)	for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)	for(li i=(li)(start);i<((li)(to));i++)
#define pb			push_back
#define sz(v)		((li)(v).size())
#define bgn(v)		((v).begin())
#define eend(v)		((v).end())
#define allof(v)	(v).begin(), (v).end()
#define dodp(v,n)		memset(v,(li)n,sizeof(v))
#define bit(n)		(1ll<<(li)(n))
#define mp(a,b)		make_pair(a,b)
#define rin	rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)		idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)		idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)		idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)	for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)		idp p2((x).F, (x).S)
#define dump(x,n)	idp{rep(iii,n){cout<<x[iii]<<" ";}puts("");}
#define dump2(x,n)	idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)	idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)	idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)	rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)	rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


// table for [n][split point of last 17 numbers]
li dp[44][bit(17)];

void print_binary(li x) {
	rep(i, 32) {
		cout << ((x & bit(i)) ? 1 : 0);
	} cout << endl;
}

int main() {
	li n, a[3];
	cin >> n;
	rep(i, 3)cin >> a[i];
	li sum = a[0] + a[1] + a[2];

	// (2,3,4) => 101001000
	li ok = bit(a[2] - 1) +
	        bit(a[2] + a[1] - 1) +
	        bit(a[2] + a[1] + a[0] - 1);

	rep(i, bit(sum)) {
		dp[0][i] = 0;
	}
	dp[0][0] = 1;
	rin {
		rep(j, bit(sum)) {
			dp[i + 1][j] = 0;
		}
		rep(j, bit(sum)) {
			if (dp[i][j] == 0)continue;
			repp(k, 1, 11) {
				li new_number = (j << k) + bit(k - 1);
				new_number &= bit(sum) - 1;
				if (new_number >= bit(17)) {
					puts("oops");
					return 0;
				}
				if ((new_number & ok) != ok) {
					dp[i + 1][new_number] = (dp[i + 1][new_number] + dp[i][j]) % MOD;
					//print_binary(j);
					//print_binary(new_number);
					//p3(k, dp[i][j], dp[i + 1][new_number]);
				}
			}
		}
		//dump(dp[i], bit(sum));
		//dump(dp[i + 1], bit(sum));
	}

	li res = 1;
	rin{res = (res * 10) % MOD;}
	rep(i, bit(sum)) {
		res = (res + MOD - dp[n][i]) % MOD;
	}
	cout << res << endl;


	return 0;
}

Measured memory_bytes: 42240
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "debug" << endl;
#define pb push_back
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int p[N];
    REP(i,N) cin >> p[i];
    int cnt = 0;
    REP(i,N){
        if(p[i] != i+1) cnt++;
    }
    if(cnt == 2 || cnt == 0){
        cout << "YES" << endl;
    }
    else{
    cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
from collections import deque

N,Q=map(int,input().split())
name_time=[[0]*2 for _ in range(N)]
for i in range(N):
    tmp=input().split()
    name_time[i][0]=tmp[0]
    name_time[i][1]=tmp[1]

q=deque()
q.extend(name_time)
now=0
while q:
    tmp=q.popleft()
    name=tmp[0]
    time=int(tmp[1])
    if time <= Q:
        now += time
        print(name,now)
    else:
        now += Q
        time -= Q
        q.append([name,time])





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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define P pair<int,int>
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl
#define possible(n) cout << ((n) ? "possible" : "impossible"  ) << endl
#define Size(n) (n).size()

typedef long long ll;

using namespace std;

const int INF = 1e9,MOD = 1e9 + 7;
const ll LINF = 1e18;

//long long int kaizyo(long long int hh){
  //  cmp=1;
    //while(hh>1){
      //  cmp=(cmp*hh)%MOD;
        //hh--;
    //}
    //return cmp;
//}

//while(x!=0){
            //sum+=x%10;
           // x/=10;
        //}
        //各桁の和

//pair<int,int> p[100000];
//P r[100000];
//cin >> tmp;
//p[i]=make_pair(tmp,i);
//cout << p[i].second+1 << endl;//ペアの右側つまりiを出力

//s.find(w[i])==string::npos
//findの使い方

//for(int i=0;i<n;i++){
   // b[i]=x%2;
    //x/=2;
  //}二進数

//visited=vector<vector<bool>>(10,vector<bool>(10,false));アを全部falseに


long long int n,cnt=0,ans=0,a,b,c,cmp,cmpp,m,h,w,x,y,sum=0,pos;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl=false;

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

       cin >> s;
       sort(all(s));
       rep(i,Size(s)){
          if(s[i]!=s[i+1]){
              //cout << s[i];
              if(s[i]=='z'){
                  fl=true;
              }
              if(s[i]!=alph[cnt]){
                  Cout(alph[cnt]);
                  return 0;
              }
              else{
                  cnt++;
              }
              //Cout(cnt);
              
             
          }
       }
       if(!fl){
           Cout("z");
       }
       else{
       Cout("None");
       }
return 0;
}


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

int main(){
  int a, b, c, d, e, k;
  bool flag=true;
  cin >> a >> b >> c >> d >> e >> k;
  
  if(e-a>k) cout << ":(" << endl;
  else cout << "Yay!" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
#define endl "\n"
#define pb push_back
#define f() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)

int main() {
  f();
  ll n,d,count=0;
  cin>>n;
  ll ar[n];
  for(ll i=0;i<n;i++)
  {
    //for(ll j=0;j<d;j++)
    {
      cin>>ar[i];
    }
  }
  for(ll i=1;i<n-1;i++)
  {

    ll a=ar[i-1];
    ll b=ar[i];
    ll c=ar[i+1];
    ll p=min(a,min(b,c));
    ll q=max(a,max(b,c));
    if(ar[i]!=p && ar[i]!=q)

   {
      count++;
   }
    
  }
    /* double d =sqrt(ans);
    ll t=sqrt(ans);
    if(d==t)
    {
count++;
    }
  }*/
  cout<<count<<endl;
  return 0;
}


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

int main() {
	int n, W;
	while ( cin >> n >> W ) {
		long long min_W[ 1000*n+5 ]; fill( min_W, min_W+1000*n+5, 1LL << 60 );
		min_W[0] = 0;
		int sum_V = 0;
		
		for (int i = 0; i < n; ++i) {
			int wi, vi; cin >> wi >> vi;
			sum_V += vi;
			
			for (int j = sum_V; j >= vi; --j) {
				min_W[j] = min( min_W[j], min_W[ j-vi ] + wi );
			}
		}
		
		for (int i = sum_V; i >= 0; --i) {
			if ( W >= min_W[i] ) {
				cout << i << '\n';
				break;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 1024
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a%b); }

const int MAXN = 100000;

int n;
int a[MAXN];

int b[MAXN], nb;
int c[MAXN], nc;

pair<int, int> d[MAXN]; int nd;
pair<int, int> e[MAXN]; int ne;

void run() {
	scanf("%d", &n);
	REP(i, n) scanf("%d", &a[i]);

	nb = nc = 0; REP(i, n) if (i % 2 == 0) b[nb++] = a[i]; else c[nc++] = a[i]; sort(b, b + nb); sort(c, c + nc);
	nd = 0; for (int l = 0, r = l; l < nb; l = r) { while (r < nb&&b[l] == b[r]) ++r; d[nd++] = MP(-(r - l), b[l]); } sort(d, d + nd);
	ne = 0; for (int l = 0, r = l; l < nc; l = r) { while (r < nc&&c[l] == c[r]) ++r; e[ne++] = MP(-(r - l), c[l]); } sort(e, e + ne);
	int ret = INT_MAX;
	REPE(di, 2) REPE(ei, 2) {
		int cd = di < nd ? d[di].second : -1, ce = ei < ne ? e[ei].second : -1;
		if (cd != -1 && ce != -1 && cd == ce) continue;
		int cur = nb - (di < nd ? -d[di].first : 0) + nc - (ei < ne ? -e[ei].first : 0);
		ret = min(ret, cur);
	}
	printf("%d\n", ret);
}

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


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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(br.readLine());
        int max = Integer.MIN_VALUE;
        int prospectMin = 0;
        for (int i = 0; i < n; i++) {
            int a = Integer.parseInt(br.readLine());
            if (i == 0) {
                prospectMin = a;
                continue;
            }
            int profit = a - prospectMin;
            if (profit > max) {
                max = profit;
            }
            if (a < prospectMin) {
                prospectMin = a;
            }
        }
        System.out.println(max);

    }
}

Measured memory_bytes: 42116
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
using ll = long long;
using ldb = long double;
using pa = pair < ll, ll >;
using vec = vector < ll >;
 
template < typename T > using index_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#define pb push_back
#define po pop_back
#define mp make_pair
#define mt make_tuple
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))
#define F  first
#define S  second
#define f(i,x,n) for(ll i=x;i<n;i++) 
#define all(c) c.begin(),c.end()
#define str string
#define edl "\n"
#define add insert
#define cot continue
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)

const int MOD = 1e9 + 7, INF = INT_MAX, N = 1e5 + 10;
const double PI = acos(-1);
const ll LINF = LLONG_MAX;
ll a,b,c,n,ans;
str s,s1,s2,s3;
vec q(100000);
int main() {
    fast();
    // #ifndef ONLINE_JUDGE
    //   freopen("input.txt", "r", stdin);
    //   freopen("output.txt","w",stdout);
    // #endif
    cout<<setprecision(10)<<fixed;
    cin >> n;
    ll n1=n;
    if(n&1)
    {
        n/=2;
        n++;
    }
    else
        n/=2;
    cout<<1.0*n/n1;
    

    cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
    return 0;
}
 

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

void print(int[], int);

int main(){
//	BubbleSort(A)
//	1 for i = 0 to A.length-1
//	2     for j = A.length-1 downto i+1
//	3         if A[j] < A[j-1]
//	4             swap A[j] and A[j-1]
	int N, i, j, cnt = 0;
	cin >> N;
	int A[N];
	for(i = 0; i < N; i++){
		cin >> A[i];
	}
	for(i = 0; i < N; i++){
		for(j = N-1; j > i; j--){
			if(A[j] < A[j-1]){
				swap(A[j], A[j-1]);
				cnt++;
			}
		}
	}
	print(A, N);
	cout << cnt << endl;
	return 0;
}

void print(int A[], int N){
	cout << A[0];
	for(int k = 1; k < N; k++){
		cout << ' ' << A[k];
	}
	cout << endl;
}


Measured memory_bytes: 3072