akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var org = new int[N];
            var array = new int[N];

            for (var i = 0; i < N; i++)
            {
                array[i] = int.Parse(Console.ReadLine());
                org[i] = array[i];
            }

            Array.Sort(array);

            for (var i = 0; i < N; i++)
            {
                if (array[N - 1] == org[i])
                    Console.WriteLine(array[N - 2]);
                else
                    Console.WriteLine(array[N - 1]);
            }
        }
    }
}


Measured memory_bytes: 18456
import sys

input = sys.stdin.readline


def main():
    n = int(input())
    btc = 380000
    t = 0
    for _ in range(n):
        v, k = input().split()
        v = float(v)
        t += v if k == "JPY" else v * btc
    print(t)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
#include <bits//stdc++.h>
using namespace std;
int main(void){
    int a,b,c,i,j,ans,frag,s;
    ans=0;
    cin>>a>>b;
    for(i=0;i<a;i++){
        cin>>c;
        if(b<=c)
        ans++;
    }
    cout<<ans<<endl;
    
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define sz(x) (int)(x).size()
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef set<int> S;
typedef queue<int> Q;
typedef queue<P> QP;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
const int MOD = 1000000007;
  
int main() {
  vi a(4);
  rep(i,4) {
    cin >> a[i];
  } 
  sort(rng(a));
  if(a[0] == 1 && a[1] == 4 && a[2] == 7 && a[3] == 9) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int n, w;
    double[] bar;
    double ans;
    
    void run(){
	while(sc.hasNext()){
	    n = sc.nextInt();
	    w = sc.nextInt();
	    if(n==0 && w==0) break;

	    double max = 0;
	    bar = new double[100/w+1];
	    for(int i=0; i<n; i++)
		bar[(int)sc.nextInt()/w]++;

	    for(int i=0; i<bar.length; i++)
		max = Math.max(max, bar[i]);
	    
	    
	    for(int i=0; i<bar.length; i++)
		bar[i] = bar[i]/max;
       

	    double ans = 0;
	    int length = bar.length-1;
	    while(bar[length]==0) length--;
	    int c = length;
	    for(int i=0; c>=0; i++){
		bar[i] = bar[i]*c/length;
		ans += bar[i];
		c--;
	    }
	    ans += 0.01;

	    System.out.println(ans);
	}
    }

    void show(){
	for(int i=0; i<bar.length; i++)
	    System.out.print(bar[i]+" ");
	System.out.println();
    }
}

Measured memory_bytes: 23616
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
typedef long long ll;
using namespace std;

void fail(){
    cout<<"No"<<endl;
    exit(0);
}

int main(){
  int N;
  cin>>N;
  vector<int> x(N);
  for(int i=0;i<N;i++) cin>>x[i];

  int M=N*N;
  vector<int> y(N+2,0);
  for(int i=1;i<=N;i++) y[i]=x[i-1];
  y[N+1]=M+1;
  sort(y.begin(),y.end());

  vector<int> ans(M+1,0);
  for(int i=0;i<N;i++) ans[x[i]]=i+1;
  int cnt=1;
  for(int i=1;i<=N;i++){
      int lef=ans[y[i]]-1;
      while(cnt<y[i]&&lef>0){
          if(ans[cnt]==0){
              ans[cnt]=ans[y[i]];
              lef--;
          }
          cnt++;
      }
      if(lef>0) fail();
  }

  cnt=M;
  for(int i=N;i>=1;i--){
      int rig=N-ans[y[i]];
      while(cnt>y[i]&&rig>0){
          if(ans[cnt]==0){
              ans[cnt]=ans[y[i]];
              rig--;
          }
          cnt--;
      }
      if(rig>0) fail();
  }

  cout<<"Yes"<<endl;
  for(int i=1;i<=M;i++) cout<<ans[i]<<" ";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

using ll = long long;
using ull = uint64_t;
using P = pair<int, int>;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

template<class T>
inline bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}
template<class T>
inline bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

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

    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = b - a + 1;
    ll foo = b / c - a / c;
    if(a % c == 0)  ++foo;
    ll bar = b / d - a / d;
    if(a % d == 0)  ++bar;
    ll g = gcd(c, d);
    ll x = c / g * d;
    ll hoge = b / x - a / x;
    if(a % x == 0)  ++hoge;
    ans -= foo + bar - hoge;
    cout << ans << endl;
}

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

struct st {
	int x, y;
	char c;
};
bool operator<(st a, st b) {
	if (a.x == b.x&&a.y == b.y)return a.c < b.c;
	if (a.x == b.x)return a.y < b.y;
	return a.x < b.x;
}
char s[1000][1001], f[2][3];
int main() {
	int m, n; scanf("%d%d", &m, &n);
	rep(i, m)scanf("%s", s[i]);
	rep(i, 2)scanf("%s", f[i]);
	map<st, int>mp;
	int ans = 0;
	rep(i, m - 1) {
		rep(j, n - 1) {
			bool match[4]{};
			rep(k, 2)rep(t, 2) {
				if (s[i + k][j + t] == f[k][t])
					match[k * 2 + t] = true;
			}
			int cnt = count(match, match + 4, true);
			if (cnt == 4)ans++;
			if (cnt == 3) {
				rep(k, 4) {
					if (!match[k])
						mp[{i + k / 2, j + k % 2, f[k / 2][k % 2]}]++;
				}
			}
		}
	}
	int Max = 0;
	for (auto p : mp) {
		int cnt = 0;
		char c = p.first.c;
		rep(i, 2)rep(j, 2) {
			int x = p.first.x + i, y = p.first.y + j;
			bool ok = true;
			rep(k, 2)rep(t, 2) {
				if (s[x + k][y + t] != f[k][t])ok = false;
			}
			if (ok) {
				swap(s[p.first.x][p.first.y], c);
				if (s[p.first.x][p.first.y] != f[i][j])cnt++;
				swap(s[p.first.x][p.first.y], c);
			}
		}
		Max = max(Max, p.second - cnt);
	}
	printf("%d\n", ans + Max);
}

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

typedef long long ll;
typedef long long llong;
typedef long double ld;
typedef unsigned long long ull;

using namespace std;

/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/
const int MAXN = 120000;

struct st {
	ll l, r, st;
	int t;
};

ll x;
int k;
ll t[MAXN];
st a[MAXN];

st upd(st cur, ll t) {
	if (cur.t == 0) {
		ll go = max(0ll, t - cur.st) + cur.l;
		if (go > cur.r) {
			cur.l = 0;
			cur.r = 0;
			cur.st = 0;
		}
		else {
			cur.st -= t;
			cur.st += go - cur.l;
			cur.l = go;
		}
	}
	else {
		ll go = cur.r - max(0ll, t - (x - (cur.st + (cur.r - cur.l))));
		if (go < cur.l) {
			cur.l = 0;
			cur.r = 0;
			cur.st = x;
		}
		else {
			cur.st += t;
			cur.r = go;
		}
	}
	return cur;
}


int main() {
	scanf("%lld", &x);
	scanf("%d", &k);
	for (int i = 0; i < k; ++i)
		scanf("%lld", t + i);
	st cur;
	cur.l = 0;
	cur.r = x;
	cur.st = 0;
	cur.t = 0;
	a[0] = cur;
	int pr = 0;
	for (int i = 0; i < k; ++i) {
		int go = t[i] - pr;
		cur = upd(cur, go);
		cur.t ^= 1;
		a[i + 1] = cur;
		pr = t[i];
	}
	int q;
	scanf("%d", &q);
	while (q--) {
		ll tt, aa;
		scanf("%lld%lld", &tt, &aa);
		int x = lower_bound(t, t + k, tt) - t;
		int go = tt;
		if (x != 0)
			go = tt - t[x - 1];
		st cur = upd(a[x], go);
		if (aa < cur.l)
			printf("%lld\n", cur.st);
		else if (aa > cur.r)
			printf("%lld\n", cur.st + (cur.r - cur.l));
		else
			printf("%lld\n", cur.st + aa - cur.l);
	}
	return 0;
}




Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a, b, a1, a2, a3;
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
	cin >> a >> b;
	a1 = a+b;
	a2 = a-b;
	a3 = a*b;
	if (a1 >= a2 && a1 >= a3){
		cout << a1;
		}else if (a2 >= a1 && a2 >= a3){
			cout << a2;
			}else {
				cout << a3;
				}

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
const int D = 60;
ll to[D][200005];

signed main(){
	//cout << fixed << setprecision(10);
	int a,b,c;
	cin>>a>>b>>c;
	int cnt=0;
	rep(i,a,b+1){
		if(c%i==0)cnt++;
	}
	cout << cnt << endl;


	return 0;
}


Measured memory_bytes: 3128
<?php

fscanf(STDIN, "%d%d%d%d%d", $X, $Y, $A, $B, $C);

$red_list = explode(" ", trim(fgets(STDIN)));
$green_list = explode(" ", trim(fgets(STDIN)));
$white_list = explode(" ", trim(fgets(STDIN)));

rsort($red_list);
rsort($green_list);
rsort($white_list);

$red_slice = array_slice($red_list,0, $X);
$green_slice = array_slice($green_list,0, $Y);
$list = array_merge($red_slice,$green_slice);
sort($list);

$i =0;
$sum=0;
foreach($list as $value){
    if($value < $white_list[$i]){
        $sum += $white_list[$i];
        $i++;
    }else{
        $sum+=$value;
    }
}
echo $sum;



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

template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

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


const long long MOD = 1000000007;
const long long INF = 1LL << 60;
#define int long long

const int MAX_N = 100010;


int x, y;

long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> x >> y;
	int a = (2 * x - y) / 3; int b = (2 * y - x) / 3;
	if (a < 0 || b < 0) {
		cout << 0 << endl; return 0;
	}
	int ans = 1;
	int tmp = a+b;
	if ((x + y) % 3 != 0) {
		cout << 0 << endl; return 0;
	}
	for (int i = tmp; i >= tmp-a+1; i--) {
		ans *= i; ans %= MOD;
	}
	int tmp2 = a;
	int now = 1;
	for (int i = tmp2; i >= 1; i--) {
		now *= i; now %= MOD;
	}
	cout << ans * modinv(now,MOD)%MOD<< endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <chrono> 
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fr(i,a,b) for (ll i=(a); i<(b);++i)
#define frr(i,a,b) for(int i=(a-1);i>=(b);--i)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
#define endl "\n"
#define po(a,b) (ll)(pow(a,b)+0.5)
#define double long double
#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
const ll M=1e17+7;
const int MaxM=501;



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

    int tt=1;
    //cin>>tt;
    while(tt--){

ll n,m,k;
cin>>n>>m>>k;
ll a[n],b[m];
fr(i,0,n)cin>>a[i];
fr(i,0,m)cin>>b[i];

ll pa[n+1]={};
fr(i,1,n+1)pa[i]=pa[i-1]+a[i-1];
ll pb[m+1]={};
fr(i,1,m+1)pb[i]=pb[i-1]+b[i-1];

ll ans=0;
fr(i,0,n+1)
{
    if(pa[i]>k)break;
    ll num=k-pa[i]; 
    ll lb=lower_bound(pb,pb+m+1,num+1)-pb;
  lb--;

    lb=max(0ll,lb);
    ans=max(ans,i+lb); 
}
cout<<ans;
   
  }}



Measured memory_bytes: 9900
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const long long INF = 1e18;
const double PI = 2 * asin(1);

int main(){
  int N; cin >> N;
  vector <int> graph[N];
  for (int i = 0; i < N - 1; i++){
    int A, B; cin >> A >> B;
    A--; B--;
    graph[A].push_back(B);
    graph[B].push_back(A);
  }

  vector <int> dist(N);
  vector <bool> visited(N);

  queue <int> que;
  que.push(0); visited[0] = true;
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < graph[Q].size(); i++){
      int next = graph[Q][i];
      if (visited[next] == false){
        visited[next] = true;
        que.push(next);
        dist[next] = dist[Q] + 1;
      }
    }
  }

  int M = 0, edge = 0;
  for (int i = 0; i < N; i++){
    if (M < dist[i]){
      M = dist[i]; edge = i;
    }
  }
  
  fill(visited.begin(), visited.end(), false);
  fill(dist.begin(), dist.end(), 0);

  que.push(edge); visited[edge] = true;
  int R = 0;
  while (!que.empty()){
    int Q = que.front(); que.pop();
    for (int i = 0; i < graph[Q].size(); i++){
      int next = graph[Q][i];
      if (visited[next] == false){
        visited[next] = true;
        que.push(next);
        dist[next] = dist[Q] + 1;
        R = dist[next] + 1;
      }
    }
  }

  if (R % 3 == 2){
    cout << "Second" << endl;
  }else{
    cout << "First" << endl;
  }
  
  return 0;
}


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

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

// 150 -c
int main() {
    ll a, b, n;
    cin >> a >> b >> n;
    /* 前提: floor(a/b) =  (a-(a%b))/b
     *
     * floor(ax/b) - a(floor(x/b)) = (ax-(ax%b))/b - a(x-(x%b))/b
     *                             = (ax-(ax%b) - ax+a(x%b)) /b
     *                             = (a(x%b) - (ax%b)) /b
     *                             = (a(x%b) - a(x%b)%b) /b  <- a1*a2 %b = (a1%b)*a2 %b
     *                             = floor(a(x%b)/b)         <- 前提
     *
     *  MAX (floor(ax/b) - a(floor(x/b))) = MAX(floor(a(x%b)/b)
     *                                    = MAX(x%b)         <- a, b, x >= 0 よりfloor()は単調増加
     *  MAX (x%b) => n   (if. n < b-1)
     *            => b-1 (otherwise)
     */

    if (n < b - 1)
        cout << floor(a * (n % b) / b) << endl;
    else
        cout << floor(a * ((b - 1) % b) / b) << endl;

    return 0;
}



Measured memory_bytes: 3740
<?php
fscanf(STDIN,"%d",$n);
$arr=explode(' ',trim(fgets(STDIN)));
$cnt=0;
$max_arr=array();
for($i=0;$i<$n-1;$i++){
	if($arr[$i]>=$arr[$i+1]){
		$cnt++;
		$max_arr[$i]=$cnt;
	}else{
		$cnt=0;
	}
}

//print_r($max_arr);
if(count($max_arr)<>0){
	echo max($max_arr);
}else{
	echo 0;
}
?>

Measured memory_bytes: 35372
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#define max(a, b) (a > b ? a : b)

int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	int cnt = 0;
	while (n > 0) {
		cnt++;
		n /= k;
	}
	printf("%d", cnt);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int64_t dp[5010*5010];
int main() {
	int64_t n; cin>>n;
	int64_t ga,sa,ba; cin>>ga>>sa>>ba;
	int64_t gb,sb,bb; cin>>gb>>sb>>bb;
	// A -> B
	rep(i,5010*5010) dp[i]=i;
	for(int i=1;i<=n;i++){
		if(i-ga>=0) dp[i]=max(dp[i],dp[i-ga]+gb);
		if(i-sa>=0) dp[i]=max(dp[i],dp[i-sa]+sb);
		if(i-ba>=0) dp[i]=max(dp[i],dp[i-ba]+bb);
	}
	// B -> A
	n=dp[n];
	rep(i,5010*5010) dp[i]=i;
	for(int i=1;i<=n;i++){
		if(i-gb>=0) dp[i]=max(dp[i],dp[i-gb]+ga);
		if(i-sb>=0) dp[i]=max(dp[i],dp[i-sb]+sa);
		if(i-bb>=0) dp[i]=max(dp[i],dp[i-bb]+ba);
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 196352
#include <iostream>
#include <cmath>
using namespace std;
using ll = long long;

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

	ll X, K, D;
	cin >> X >> K >> D;
	X = abs(X);
	if (X / D > K) {
		cout << X - K * D << "\n";
	} else {
		ll i = X / D;
		if ((K - i) % 2 == 0) {
			cout << X - i * D << "\n";
		} else {
			cout << D - (X - i * D) << "\n";
		}
	}
	return 0;
}


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

#define	MAX(X, Y)	X > Y ? X : Y

using namespace std;

int main()
{
	int N;
	int *board;

	cin >> N;
	board = new int[N];
	for(int i = 0; i < N; i++)
		cin >> board[i];

	// 1が最大でいくつ連続しているかを調べる
	// その数を超える目を持つサイコロが答え
	int max = 0;
	for(int i = 0; i < N;){
		int count = 0;
		while(board[i] && i++ < N)
			count++;

		if(!board[i])
			i++;
		if(count)
			max = MAX(count, max);
	}

	cout << max + 1 << endl;

	return 0;
}


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

int main()
{
    int num;
    std::cin >> num;
    long A[num];
    std::vector<long long> B(num + 1, 0);
    for (int i = 0; i < num; i++)
    {
        std::cin >> A[i];
        B[i + 1] = B[i] + A[i];
    }

    int mod = 1000000007;
    long ans = 0;
    for (int i = 0; i < num; i++)
    {
        long long sum = (B[num] - B[i + 1]) % mod;
        //std::cout << sum_all << std::endl;
        ans += sum * A[i];
        ans %= mod;
    }

    //std::cout << (long)141421356*17320508 << std::endl;
    std::cout << ans << std::endl;
    return 0;
}

Measured memory_bytes: 6400
def max_heapify(x = 1)
  l = 2*x
  r = 2*x+1
  if l <= $n && $heap[l][0] > $heap[x][0]
    maximum = l
  else
    maximum = x
  end
  if r <= $n && $heap[r][0] > $heap[maximum][0]
    maximum = r
  end
  if maximum != x
    $heap[x], $heap[maximum] = $heap[maximum], $heap[x]
    max_heapify(maximum)
  end
end

def extract
  key = $heap[1]
  $heap[1] = $heap[$n]
  $n -= 1
  max_heapify
  key
end

def insert(key)
  $n += 1
  $heap[$n] = key
  i = $n
  while i > 1 && $heap[i/2][0] < $heap[i][0]
    $heap[i], $heap[i/2] = $heap[i/2], $heap[i]
    i /= 2
  end
end

def find(x)
  x == $sibling[x] ? x : $sibling[x] = find($sibling[x])
end

n, m = gets.split.map(&:to_i)
$sibling = Array.new(n + 1) { |i| i }
p = [ 0, *n.times.map { gets.split.map(&:to_f) } ]
q = m.times.map { gets.split.map(&:to_i) }
sum = 0
$n = 0
$heap = []
q.each do |a, b|
  insert( [ Math.sqrt( (p[a][0] - p[b][0]) ** 2 + (p[a][1] - p[b][1]) ** 2 ), a, b ] )
end
until $n < 1
  d, p0, p1 = extract
  if ( p0 = find(p0) ) != ( p1 = find(p1) )
    $sibling[p1] = p0
  else
    sum += d
  end
end
p sum

Measured memory_bytes: 15368
from collections import defaultdict
dic = defaultdict(int)
N,M = map(int,input().split())
A = []
for i in range(M):
  a,b = map(int,input().split())
  A.append((a,b,i))
A.sort()
#print(A)
ans = [-1 for _ in range(M)]
for i in range(M):
  dic[A[i][0]] += 1
  #print(dic[A[i][0]])
  temp = "0"*(6-len(str(A[i][0])))+str(A[i][0])+"0"*(6-len(str(dic[A[i][0]])))+str(dic[A[i][0]])
  ans[A[i][2]] = temp
  #print(i,temp)
for t in ans:
  print(t)
  

Measured memory_bytes: 110716
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
//#include "h.h"
using namespace std;

#define MOD 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define pm(first, second) pb(mp(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()

int main(){

	char c;
	cin >> c;
	if(c == 'A')cout << 'T' << endl;
	if(c == 'T')cout << 'A' << endl;
	if(c == 'C')cout << 'G' << endl;
	if(c == 'G')cout << 'C' << endl;

	return 0;
}

Measured memory_bytes: 256
fun check(s: String): Boolean {
    if (s[0] != 'A') return false
    if (s.slice(2..s.length-2).count {it == 'C'} != 1) {
        return false
    }
    return s.count { it.isLowerCase() } == s.length - 2
}

fun main(args: Array<String>) {
    val s = readLine()!!;
    println(if (check(s)) "AC" else "WA")
}

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

template<class Type>
Type Pow(Type a, Type n)
{
	ll res = 1;
	while (0 < n) {
		if (n & 1) res *= a;
		a *= a;
		n >>= 1;
	}
	return res;
}

int main()
{
	ll n, m;
	cin >> n >> m;
	cout << (1900 * m + 100 * (n - m))*Pow(2LL, m) << endl;
}


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

typedef long long ll;
typedef pair<ll, ll> P;


#define rep(i,n) for(ll (i)=0; (i)<(ll)(n); (i)++)
#define frep(i,m,n) for(ll (i)=(m); (i)<=(ll)(n); (i)++)
#define rrep(i,n) for(ll (i)=(n)-1; (i)>-1; (i)--)
#define frrep(i,m,n) for(ll (i)=(n); (i)>(ll)(m); (i)--)
#define ALL(x) (x).begin(), (x).end()

const ll INF = 100100100100100100;
const ll MOD = 1000000007;

// get abs
ll my_abs(ll a);
// a^n
ll a_n(ll a, ll n);
// get gcd
ll my_gcd(ll a, ll b);
// a^(-1) % MOD 
ll inv(ll a);
// (a+b+c)%MOD
ll madd(ll a, ll b, ll c);
// (a-b)%MOD
ll msub(ll a, ll b);
// (a*b*c)%MOD
ll mtime(ll a, ll b, ll c);


int main() {
    ll d, g; cin >> d >> g;
    vector<ll> p(d), c(d);
    rep(i, d) {
        cin >> p[i] >> c[i];
    }
    ll ans = INF;
    // 全探索
    frep(i, 0, (1<<d)-1) {
        set<ll> s; // 全部解く
        ll sum = 0, num = 0;
        rep(j, d) {
            // 選ばれたら全部足す
            if(i & (1 << j)) {
                s.insert(j);
                sum += 100*(j+1)*p[j];
                sum += c[j];
                num += p[j];
            }
        }
        if(sum >= g) {
            if(ans > num) ans = num;
        }
        else {
            ll left = g - sum, index; // 後どれだけほしいか、解く問題のindex
            rep(j, d) {
                if(s.count(d-1-j)) continue;
                else {
                    index = d-1-j;
                    break;
                }
            }
            // 全部解いても足りない
            if(left > 100*(index+1)*(p[index]-1)) continue;
            else {
                num += (left+100*(index+1)-1)/(100*(index+1));
                if(ans > num) ans = num;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

ll my_abs(ll a) {
    if(a >= 0) return a;
    else return -1 *a;
}

ll a_n(ll a, ll n) { 
    if(n == 0) return 1;
    
    ll ret = a, count = 1;
    while(count * 2 < n) {
        ret *= ret;
        count *= 2;
    }
    if(count == n) return ret;
    else return (ret * a_n(a, n-count));
}

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

ll inv(ll a) {
    return a_n(a, MOD-2);
}

ll madd(ll a, ll b, ll c) {
    ll ret = (a+b) % MOD;
    return (ret+c) % MOD;
}

ll msub(ll a, ll b) {
    if(a < b) return (a-b+MOD) % MOD;
    else return (a-b) % MOD;
}

ll mtime(ll a, ll b, ll c) {
    ll ret = (a*b) % MOD;
    return (ret*c) % MOD;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define MID ((l+r)>>1)
#define lc (rt<<1)
#define rc (rt<<1|1)
#define ls lc,l,MID
#define rs rc,MID+1,r
#define st 1,1,n
#define PII pair<int,int>
#define PLL pair<LL,LL>
using namespace std;
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
const int N=1e5+1;
const LL M=1e18;
int main(){Accel
	LL n,h,s=0,md=0,x,y;
	cin>>n>>h;
	priority_queue<LL>q;
	REP(i,n){
		cin>>x>>y;	
		q.push(y);
		md=max(md,x);
	}
	LL t=0,R=0;
	while(t<h&&q.size()){
		if(q.top()<=md)break;
		t+=q.top(),R++,q.pop();
	}
	h-=t,s+=R;
	while(h>0)h-=md,s++;
//	if(h>0&&h<=t)s+=R;
	cout<<s<<endl;
}

Measured memory_bytes: 1400
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

    vector<ll> A(N);
    vector<ull>absA(N);
    for(int i=0; i<N; i++) {
        cin >> A[i];
        absA[i] = abs(A[i]);
    }

    int s = 1;
    for(auto i=A.begin(); i!=A.end(); i++)
        s *= (*i >= 0) ? 1 : -1;

    ull sum = 0;
    for(auto i=absA.begin(); i!=absA.end(); i++)
        sum += *i;

    ull mini = 0;
    if(s == -1)
        mini = *min_element(absA.begin(), absA.end());

    cout << sum - 2*mini << endl;

    return 0;
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define SORT(c) sort((c).begin(),(c).end())
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(void){
  int n;
  cin >> n;
  int t[n], x[n], y[n];
  bool flag = true;
  rep(i, n) {
    cin >> t[i] >> x[i] >> y[i];
    if(t[i] % 2 == 0) {
      if((x[i] + y[i]) % 2 == 1) flag = false;
    }
    else {
      if((x[i] + y[i]) % 2 == 0) flag = false;
    }
  }
  if(t[0] < x[0] + y[0]) flag = false;
  for(int i = 1; i < n; i++){
    if(t[i] - t[i - 1] < abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1])) flag = false;
  }
  cout << (flag ? "Yes" : "No") << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
struct Node
{
	int x,y;
}a[1444444];
int W[1444444];
bool cmp(Node x,Node y)
{
	return x.y<y.y||x.y==y.y&&x.x<y.x;
}
int main()
{
	int i,cnt,h,w,n,now,ans=1000000000;
	scanf("%d%d%d",&h,&w,&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d%d",&a[i].x,&a[i].y);
	}
	cnt=n;
	for(i=1;i<=w;i++)
		a[++cnt].x=h+1,a[cnt].y=i;
	n=cnt;
	sort(a+1,a+n+1,cmp);
	now=1;
	W[0]=0;
	for(i=1;i<=w;i++)
	{
		W[i]=W[i-1]+1;
//		printf("%d %d|\n",i,W[i]); 
		while(now<=cnt&&a[now].y<i||a[now].y==i&&a[now].x<W[i])
			now++;
		while(now<=cnt&&a[now].y==i&&a[now].x==W[i])
			W[i]++,now++;
//		printf("%d|%d %d\n",i,a[now].y,now);
		if(a[now].y==i)
			ans=min(ans,a[now].x);
	}
	printf("%d\n",ans-1);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 7168
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <algorithm>
#include <climits>
#include <cstring>
#include <cmath>
#include <stack>
#include <iomanip>
#include <tuple>
#include <functional>
#include <cfloat>
#include <map>
#include <stdio.h>
#include <string.h>
using ll = long long;

//LLONG_MAX
#define int long long
#define CONTAINS(v,n) (find((v).begin(), (v).end(), (n)) != (v).end())
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define ARY_SORT(a, size) sort((a), (a)+(size))
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#define REMOVE(v,a) (v.erase(remove((v).begin(), (v).end(), (a)), (v).end()))
#define REVERSE(v) (reverse((v).begin(), (v).end()))
#define LOWER_BOUND(v,a) (lower_bound((v).begin(), (v).end(), (a)))
#define UPPER_BOUND(v,a) (upper_bound((v).begin(), (v).end(), (a)))
#define REP(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define CONTAINS_MAP(m, a) (m).find((a)) != m.end()
using namespace std;

vector<int> connect[300000];
int counter[300000];
bool flg[300000];
int ans[300000];

int N, Q;

signed main()
{
	cin >> N >> Q;
	REP(i, N - 1)
	{
		int a, b;
		cin >> a >> b;
		connect[a].push_back(b);
		connect[b].push_back(a);
	}

	REP(i, Q)
	{
		int p, x;
		cin >> p >> x;
		counter[p] += x;
	}


	queue<int> q;
	queue<int> c;

	q.push(1);
	c.push(counter[1]);
	flg[1] = true;
	ans[1] = counter[1];

	while (q.size() > 0)
	{
		int n = q.front();
		q.pop();
		int a = c.front();
		c.pop();

		for (int l : connect[n])
		{
			int m = a;

			if (!flg[l])
			{
				flg[l] = true;
				m += counter[l];
				ans[l] = m;
				q.push(l);
				c.push(m);
			}
		}
	}

	for (int i = 1; i <= N; i++)
	{
		cout << ((i == 1) ? "" : " ") << ans[i];
	}

	cout << endl;
}




Measured memory_bytes: 24816
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 5100000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int prime[MAX];
bool isprime[MAX];

int sieve(int n){
	int p = 0;
	for(int i=0; i<=n; i++) isprime[i] = true;
	isprime[0] = isprime[1] = false;
	for(int i=2; i<=n; i++){
		if(isprime[i]){
			prime[p++] = i;
			for(int j=2*i; j<=n; j+=i) isprime[j] = false;
		}
	}
	return p;
}

int main(){
	sieve(2020202);
	while(1){
		ll k; cin >> k;
		if(!k) break;
		if(isprime[k]) cout << 0 << endl;
		else{
			ll cnt = 0;
			for(ll i=k+1;; i++){
				if(isprime[i]) break;
				cnt++;
			}
			for(ll i=k-1; i>=1; i--){
				if(isprime[i]) break;
				cnt++;
			}
			cout << cnt+2 << endl;
		}
	}
}


Measured memory_bytes: 5664
x = list(map(int, input().split()))
y = list(map(int, input().split()))
z = [[0, 1, 2, 3], [0, 2, 1, 1], [1, 0, 2, 1], [2, 0, 1, 0], [1, 2, 0, 0], [2, 1, 0, 1]]
for i in range(6):
    order = [0, 0, 0]
    for j in range(3):
        if {x[j], x[-j-1]} != {y[z[i][j]], y[-z[i][j]-1]}:
            break
        if x[j] == y[z[i][j]]:
            order[j] = 1
            if x[j] == x[-j-1]:
                order[j] = 2
    else:
        if 2 in order:
            print('Yes')
            break
        if z[i][3] in [0, 3] and sum(order) % 2:
            print('Yes')
            break
        if z[i][3] == 1 and not sum(order) % 2:
            print('Yes')
            break
else:
    print('No')

Measured memory_bytes: 7704
"use strict";
var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

// number一個取得
// eslint-disable-next-line no-unused-vars
const next = () => +cin[cid++];

// 文字列一個取得
// eslint-disable-next-line no-unused-vars
const nextstr = () => cin[cid++];

// BigInteger一個取得
// eslint-disable-next-line no-unused-vars
const nextbig = () => BigInt(cin[cid++]);

// 長さnの配列として取得。aは文字列フラグ
// eslint-disable-next-line no-unused-vars
const nexts = (n, a) =>
    a ? cin.slice(cid, (cid += n)) : cin.slice(cid, (cid += n)).map((a) => +a);

// w個ずつを組にして長さhの配列。aは文字列フラグ。
// eslint-disable-next-line no-unused-vars
const nextm = (h, w, a) => {
    var r = [],
        i = 0;
    if (a) for (; i < h; i++) r.push(cin.slice(cid, (cid += w)));
    else for (; i < h; i++) r.push(cin.slice(cid, (cid += w)).map((a) => +a));
    return r;
};
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
// eslint-disable-next-line no-unused-vars
const xArray = (...args) => {
    var a = args,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + a[0] + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
};

console.log(main().toString());

function main() {
    let N = next();
    let A = xArray(0, N);
    let S = xArray(-1, N - 1, 2);
    for (let i = 0; i < N; i++) {
        A[i] = next();
        S[i] = nextm(A[i], 2).map((v) => [v[0] - 1, v[1]]);
    }

    let ans = 0;
    let pat_bits = Array(N);
    for (let pat = 2 ** N - 1; pat > 0; pat--) {
        // nビット目を対応させることに等しい。
        for (let n = 0; n < N; n++) {
            pat_bits[n] = (pat >> n) % 2;
        }
        //console.log("test set", pat_bits);

        let flag = true;
        //console.log("Pattern=", pat_bits);
        for (let i = 0; i < N; i++) {
            // 証言者iについて。
            if (pat_bits[i] == 0) {
                // 不親切の証言は聞く必要がない。
                continue;
            }
            if (!flag) {
                continue;
            }
            //console.log(" person:" + i);
            for (let n = 0; n < A[i]; n++) {
                //console.log("  says, " + S[i][n][0] + " is " + S[i][n][1]);
                if (pat_bits[S[i][n][0]] != S[i][n][1]) {
                    // 間違った証言なので、iは不親切。
                    //console.log("  ... wrong");
                    flag = false;
                    break;
                }
                // console.log("  ... YES!");
            }
            //console.log("Value=" + value, "accept!");
        }
        // flagがtrueならば、この組み合わせは成立している。
        if (flag) {
            let honests = 0;
            pat_bits.forEach((h) => {
                honests += h;
            });
            ans = Math.max(ans, honests);
        }
    }
    return ans;
}


Measured memory_bytes: 33060
#include<stdio.h>
#include<math.h>

int main(){
    int n,m,X,Y;
    scanf("%d%d%d%d",&n,&m,&X,&Y);
    int x[n],y[m];
    int x_max,y_min;
    x_max = X;
    y_min = Y;
    for(int i = 0;i < n;i++){
        scanf("%d",&x[i]);
        x_max = fmax(x_max,x[i]);
    }
    for(int i = 0;i < m;i++){
        scanf("%d",&y[i]);
        y_min = fmin(y_min,y[i]);
    }
    if(x_max < y_min && X < y_min && x_max < y_min) printf("No War\n");
    else printf("War\n");

}

Measured memory_bytes: 128
#include <iostream>
#include <cmath>
#include <string>
#include <typeinfo>
#include <climits>
#include <algorithm>
#include <cctype>
#include <cstring>
#include <stdio.h>
#include <cstdlib>
using namespace std;

int main(){
    int n,m,x,y,frag=0;
    cin >> n >> m >> x >> y;
    int xx[n],yy[m];
    for(int i=0;i<n;i++){
        cin >> xx[i];
    }
    for(int i=0;i<m;i++){
        cin >> yy[i];
    }
    sort(xx,xx+n);
    sort(yy,yy+m);
    for(int i=x+1;i<=y;i++){
        if(xx[n-1]<i&&i<=yy[0]){
            cout << "No War";
            frag=1;
            break;
        }
    }
    if(frag==0){
        cout << "War";
    }
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int A, B, ans = 0;
	scanf("%d %d", &A, &B);

	if (A > B)
		ans = A * 2 - 1;
	else if (A < B)
		ans = B * 2 - 1;
	else
		ans = A + B;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include <queue>
#include <iostream>
using namespace std;
int main () {
  int n,q;
  int time = 0;
  queue<int> Q,Qout;
  queue<string> P,Pout;
  cin >> n;
  cin >> q;
  while (n>0) {
    string N;
    int T;
    cin >> N;
    cin >> T;
    P.push(N);
    Q.push(T);
    n--;
  }
  while (! P.empty()) {
    int T;
    T = Q.front();
    Q.pop();
    if (T>q) {
      T -= q;
      Q.push(T);
      P.push(P.front());
      P.pop();
      time += q;
    }
    else {
      time += T;
      cout << P.front() << " " << time << endl;
      P.pop();
    }
  }
}
      

Measured memory_bytes: 4176
def main():
    D = int(input())
    C = [0] * 26
    C = list(map(int,input().split()))
    S = [ list(map(int,input().split(" "))) for i in range(D)]
    
    last = [0] * 26
    for i in range(D):
        max = -9999999999999
        max_t = 0
        for t in range(26):
            score = 0
            for j in range(26):
                if j == t:
                    #last[j] = 0
                    score += S[i][j]
                else:
                    #last[j] += 1
                    score -= (last[j]+1)*C[j]
            if  score > max:
                max = score
                max_t = t
        for j in range(26):
            if j == max_t:
                last[j] = 0
            else:
                last[j] += 1
        print(max_t + 1)
if __name__ == '__main__':
    main()

Measured memory_bytes: 9400
import math
N, K = map(int, input().split())
S = list(map(int, input().split()))

K = min(K, 41)
dp = [[0]*N for _ in range(K)]

for i in range(N):
    temp = S[i]
    m = max(0, i-temp)
    dp[0][m] += 1
    if N > i+temp+1:
        dp[0][i+temp+1] -= 1

for i in range(K-1):
    temp = 0
    for j in range(N):
        temp += dp[i][j]
        m = max(0, j-temp)
        dp[i+1][m] += 1
        if N > j+temp+1:
            dp[i+1][j+temp+1] -= 1

ans = [0]*N
ans[0] = dp[K-1][0]

for i in range(1, N):
    ans[i] = ans[i-1] + dp[K-1][i]

print(" ".join(map(str, ans)))


Measured memory_bytes: 167304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
//#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
/* clang-format on */

int main() {
  // ios::sync_with_stdio(false);
  // cin.tie(nullptr);
  string s;
  cin >> s;
  ll n = s.size();
  ll ans = 1 + (n * (n - 1)) / 2;
  REP(a, 26) {
    ll cnt = 0;
    REP(i, n) {if (s[i] == 'a' + a) cnt++; }
    ans -= cnt * (cnt - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3728
import heapq
def f(s):
  return -int(s)
N,M = map(int,input().split())
A = list(map(f,input().split()))

h = []
for a in A:
  heapq.heappush(h,a)

for i in range(M):
  a = heapq.heappop(h)
  heapq.heappush(h,a/2)
ans=0
for a in h:
  ans += int(-a)
print(ans)

Measured memory_bytes: 86808
#include <stdio.h>
#define N 8
#define FREE 0
#define UNFREE 1

int Q[N][N];
int row[N],col[N],dpos[2*N-1],dneg[2*N-1];

int putQueen(int i){
  int j, k, l;
  if(i == N){
    for(k = 0; k < N; k++){
      for(l = 0; l < N; l++){
    if(Q[k][l] == FREE)
      printf(".");
    else
      printf("Q");
      }
      printf("\n");
    }
    return;
  }
  if(row[i] == UNFREE)
    putQueen(i+1);
  else{
    for(j = 0; j < N; j++){
      if(col[j] == UNFREE || dpos[i+j] == UNFREE || dneg[i-j+N-1] == UNFREE)
    continue;
      col[j] = dpos[i+j] = dneg[i-j+N-1] = Q[i][j] = UNFREE;
      putQueen(i+1);
      col[j] = dpos[i+j] = dneg[i-j+N-1] = Q[i][j] = FREE;
    }
  }
}

int main(){
  int i,k,r,c;
  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d %d",&r,&c);
    Q[r][c]=row[r]=col[c]=dpos[r+c]=dneg[r-c+N-1]=UNFREE;
  }
  putQueen(0);
  return 0;
}

Measured memory_bytes: 572
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
const LL INF = 1LL << 60;

int main(){
    LL N, W;
    cin >> N >> W;
    vector<LL>  w(N+1), v(N+1);
    for(int i = 1;i <= N;i++)   cin >> w[i] >> v[i];
    vector<vector<LL>>  dp(N+1, vector<LL>(W+1, 0));
    for(int i = 1;i <= N;i++){
        for(int j = 1;j <= W;j++){
            if(j-w[i] < 0){
                dp[i][j] = dp[i-1][j];
            }else{
                dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
            }
        }
    }
    cout << dp[N][W] << endl;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
using namespace std;
long long mod = 1e9 + 7;
vector<long long>fact(1e6 + 20);
long long bigmod(long long a, long long p){
    if(p == 0){
        return 1;
    }
    long long ans = bigmod(a, p/2);
    ans = (ans * ans) % mod;
    if(p % 2 == 1){
        ans = (ans * a) % mod;
    }
    return ans;
}
long long nCr(long long n, long long m){
    long long cur = (fact[m] * fact[n - m]) % mod;
    cur = bigmod(cur, mod - 2);
    cur = (cur * fact[n]) % mod;
    return cur;
}

int main(){
    fact[0] = 1;
    for(long long i = 1; i <= 1000000; i++){
        fact[i] = (fact[i - 1] * i) % mod;
    }
    long long n, m;
    cin >> n >> m;
    long long ans = (nCr(m, n) * fact[n]) % mod;
    long long cur = 0;
    for(long long i = 0; i <= n; i++){
        long long cur2 = (nCr(n, i) * nCr(m - i, n - i)) % mod;
        cur2 = (cur2 * fact[n - i]) % mod;
        if(i % 2 == 1){
            cur2 = (2 * mod - cur2) % mod;
        }
        cur = (cur + cur2) % mod;
    }
    ans = (ans * cur) % mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 11000
#include <bits/extc++.h>

#ifndef DUMP
#define DUMP(...) (void)0
#endif

using namespace std;

int main() {
  cin.tie(nullptr)->sync_with_stdio(false);
  int n;
  cin >> n;
  int64_t d;
  cin >> d;
  int res = 0;
  while (n--) {
    int64_t x, y;
    cin >> x >> y;
    res += x * x + y * y <= d * d;
  }
  cout << res << '\n';
}


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

int main(){
  int a,b,c,k,cnt=0;
  cin>>a>>b>>c>>k;
  for(int i=0;i<k;i++){
    if(a>=b&&a>=c)a*=2;
    else if(b>=a&&b>=c)b*=2;
    else if(c>=a&&c>=b)c*=2;
  }
  cout<<a+b+c<<endl;
  return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
p=[]
for i in range(m):
    t1,t2=map(int,input().split())
    p.append([i,t1,t2])
p.sort(key=lambda x:x[2])
c=[1 for i in range(n+1)]
num=[]
for i,pre,yea in p:
    tmp=str(pre).zfill(6)+str(c[pre]).zfill(6)
    num.append([i,tmp])
    c[pre]+=1
num.sort()
for i in num:
    print(i[1])

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

int main(void)
{
    int a,b;
    cin>> a >> b;
    if(a == b)
    {
        cout << "Draw" << endl;
    }
    else if(a== 1 && b !=1)
    {
        cout << "Alice" << endl;
    }
    else if(a !=1 && b ==1)
    {
        cout << "Bob" << endl;
    }
    else if(a<b)
    {
        cout <<"Bob" << endl;
    }
    else if(a>b)
    {
        cout <<"Alice" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}

signed main() {
	string s;
	cin >> s;
	int ans = s.size() * (s.size() - 1) / 2;
	ans++;
	rep(i, 26) {
		int cnt = 0;
		rep(j, s.size()) {
			if (s[j] == 'a' + i) {
				cnt++;
			}
		}
		ans -= (cnt - 1) * cnt / 2;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
#define int long long int
#define ldouble long double
#define vin vector<int>
#define pqueue priority_queue
#define rep(a,n) for(int i=(a);i<(n);i++)
#define INF (int)1000000007

//setprecision()<<

using namespace std;

void fin(int n,vin &a){
    rep(0,n){
        cin>>a.at(i);
    }
}

signed main(){
    typedef pair<int,int> P;
    int N,R;
    cin>>N>>R;
    if(N>=10){
        cout<<R<<endl;
    }
    else{
        cout<<R+100*(10-N)<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};


int main() {
    cin.tie(0);
   	ios::sync_with_stdio(false);
    ll n;
    ll a,b;
    ll k,t;
    string str;
    ll h,w;
    char c,ko;
    cin>>n;
    ll sum=0;
    ll i=335;
    while(i<=n){
         ll m=i;
        a=0;b=0;k=0;
        while(m>0){
            
            if(m%10==3) a++;
            else if(m%10==5) b++;
            else if(m%10==7) k++;
            else {
                a=0;
                break;
            }
                    m/=10;
        }
        if(a&&b&&k) sum++;
       // cout<<"a"<<endl;
        if(i%10==3||i%10==5){
            i+=2;
        }else{
            i+=6;
        }
       
        }
cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
	int n,ans=1e9;
	cin>>n;
	int a[n],w[n],A[n];
	r(i,n)cin>>a[i];
	r(i,n)cin>>w[i];
	r(i,n)A[i]=i;
	do{
		int sum=0;
		for(int i=0;i<n;i++){
			int X=a[A[i]];
			int Y=a[A[(i+1)%n]];
			if(X&&!Y){
				sum+=w[A[(i+1)%n]]+w[A[i]];
			}
		}
		ans=min(sum,ans);
	}while(next_permutation(A,A+n));

	cout<<ans<<endl;
}


Measured memory_bytes: 3088