akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>                                           
 
#define int long long
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast,no-stack-protector") 
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb; 
typedef long long ll;  
typedef double db;                         
 
 
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}, block = 555;
const int inf = 1e9, N = 3e3 + 48, mod = 1e9 + 7, maxn = 2e5 + 11;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int h, w, n, f[maxn], rf[maxn], dp[N];
pii a[N];


int binpow (int a, int n) {
	int res = 1;
	while (n) {
		if (n & 1)
			res = res * 1ll * a % mod;
		a = a * 1ll * a % mod;
		n >>= 1;
	}

	return res;
}

int rev (int x) {
	return binpow(x, mod - 2);
}

void precalc () {
	f[0] = 1;
	forn (i, 1, maxn - 1)
		f[i] = f[i - 1] * 1ll * i % mod;

	rf[maxn - 1] = rev(f[maxn - 1]);
	forev (i, maxn - 2, 0) 		
		rf[i] = rf[i + 1] * 1ll * (i + 1) % mod;
}


int cnk (int n, int k) {
	return f[n] * 1ll * rf[k] % mod * rf[n - k] % mod;
}

int get (int xa, int ya, int xb, int yb) {
	if (xa > xb || ya > yb)
		return 0;

	int X = xb - xa;
	int Y = yb - ya;	
	return cnk(X + Y, X);
}


void add (int &x, int y) {
	x += y;
	if (x >= mod)
		x -= mod;

	if (x < 0)
		x += mod;
}


main () {
	precalc();
	cin >> h >> w >> n;
	forn (i, 1, n)
		cin >> a[i].f >> a[i].s;
	
	sort(a + 1, a + 1 + n);
	int ans = get(1, 1, h, w);
	forn (i, 1, n) {
		dp[i] = get(1, 1, a[i].f, a[i].s);
		forn (j, 1, i - 1)
			add(dp[i], -dp[j] * 1ll * get(a[j].f, a[j].s, a[i].f, a[i].s) % mod);
		add(ans, -dp[i] * 1ll * get(a[i].f, a[i].s, h, w) % mod);
	}

	cout << ans << endl;				
}          
 

Measured memory_bytes: 3456
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
const ll mod=1e9+7;
const int MAXN=4010;
const int MAX=2001;
const int M=2e5+10;
int n;
ll fac[MAXN<<2],inv[MAXN<<2],f[MAXN][MAXN];
int a[M],b[M];
ll ans;
ll poww(ll x,ll y){ll ans=1; for (;y;y>>=1,x=(x*x)%mod) if (y&1) ans=(ans*x)%mod;  return ans;}
void init()
{
    fac[0]=1;
    for (int i=1;i<=(MAX<<2);i++) fac[i]=(fac[i-1]*(ll)i)%mod;
    inv[0]=1;
    for (int i=1;i<=(MAX<<2);i++) inv[i]=(inv[i-1]*poww((ll)i,mod-2))%mod;
}
int main()
{
    scanf("%d",&n);
    init();
    for (int i=1;i<=n;i++)
    {
        scanf("%d%d",&a[i],&b[i]);
        f[2001-a[i]][2001-b[i]]++;
    }
    for (int i=1;i<=(MAX<<1);i++)
     for (int j=1;j<=(MAX<<1);j++)
     f[i][j]=(f[i-1][j]+f[i][j-1]+f[i][j])%mod;
    for (int i=1;i<=n;i++)  
    {
         ans=(ans+f[a[i]+2001][b[i]+2001])%mod;
 //        printf("%lld\n",f[a[i]+2001][b[i]+2001]);
         ans=(ans-fac[a[i]*2+b[i]*2]*inv[a[i]*2]%mod*inv[b[i]*2]%mod+mod)%mod;
    }
    printf("%lld\n",(ans*inv[2])%mod);
}

Measured memory_bytes: 127360
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K = INT()
print((K-K//2) * (K//2))

Measured memory_bytes: 5328
class Proces
  def initialize(name,time)
    @name = name
    @time = time.to_i
  end
  def act limit
    if @time > limit
      @time -= limit
      true
    end
  end
  attr_reader :name,:time
end

queue = Array.new()
time = 0
temp = gets.split(" ").map{|x| x.to_i}
q = temp.pop
num =  temp.pop
num.times do
 temp = gets.split(" ")
 queue.push(Proces.new(temp[0],temp[1]))
end
until (p = queue.shift) == nil ? true:false
 if p.act(q)
  queue.push(p)
  time += q
 else
  time+=p.time
  printf("%s %d\n",p.name,time) 
 end
end

Measured memory_bytes: 13352
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <deque>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cstring>
#include <iomanip>
#include <utility>

#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;

using namespace std;

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

    int n,h[25];
    cin>>n;

    int maxh=0,sum=0;
    rep(i,n){
	cin>>h[i];

	if(maxh<=h[i]){
	    sum++;
	    maxh=h[i];
	}
    }
    cout<<sum<<'\n';
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int a, b, c;
    cin >> a >> b >> c;
    int k;
    cin >> k;

    for (int i = 0; i < k; i++) {
        if (a >= b && a >= c) {
            a *= 2;
        } else if (b >= a && b >= c) {
            b *= 2;
        } else {
            c *= 2;
        }
    }

    cout << a + b + c << endl;

    return 0;
}

Measured memory_bytes: 256
A, B, M = map(int, input().split())
As = list(map(int, input().split()))
Bs = list(map(int, input().split()))
Ds = []
for i in range(M):
  x, y, c = map(int, input().split())
  x, y = x-1, y-1
  D = As[x]+Bs[y]-c
  Ds.append(D)
r = min(min(As)+min(Bs), min(Ds))
print(r)


Measured memory_bytes: 18608
{-# LANGUAGE BangPatterns #-}
import Control.Arrow (second)
import Control.Monad
import Control.Monad.Fix
import Data.Foldable (foldl')
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM
import qualified Data.ByteString.Char8 as B
import Data.ByteString.Internal (accursedUnutterablePerformIO)
import Debug.Trace

uread :: VUM.Unbox a => Int -> VUM.IOVector a -> a
uread i v = accursedUnutterablePerformIO $ VUM.unsafeRead v i

uwrite :: VUM.Unbox a => Int -> a -> VUM.IOVector a -> VUM.IOVector a
uwrite i a v = accursedUnutterablePerformIO $ VUM.unsafeWrite v i a >> return v

uswap :: VUM.Unbox a => Int -> Int -> VUM.IOVector a -> VUM.IOVector a
uswap i j v = accursedUnutterablePerformIO $ VUM.unsafeSwap v i j >> return v

ufreeze :: VUM.Unbox a => VUM.IOVector a -> VU.Vector a
ufreeze v = accursedUnutterablePerformIO $ VU.unsafeFreeze v

uthaw :: VUM.Unbox a => VU.Vector a -> VUM.IOVector a
uthaw v = accursedUnutterablePerformIO $ VU.unsafeThaw v

newtype UnionFind = UnionFind (VUM.IOVector Int, VUM.IOVector Int)

findUF :: UnionFind -> Int -> Int
findUF (UnionFind (elems, _)) k = fix
  ( \f (elems, k, path) -> case uread k elems of
    n | n == k -> foldl' (\acc p -> uwrite p n acc) elems path `seq` n
    n          -> f (elems, n, n : path)
  )
  (elems, k, [k])

sizeUF :: UnionFind -> Int -> Int
sizeUF uf@(UnionFind (_, sizes)) i = uread (findUF uf i) sizes

unionUF :: UnionFind -> Int -> Int -> UnionFind
unionUF uf@(UnionFind (elem, sizes)) i j =
  let pi  = findUF uf i
      pj  = findUF uf j
      si  = uread pi sizes
      sj  = uread pj sizes
      sij = si + sj
  in  if pi == pj
        then uf
        else
          let (t1, t2) = if si < sj then (pi, pj) else (pj, pi)
          in  UnionFind (uwrite t1 t2 elem, uwrite t1 0 $ uwrite t2 sij sizes)

solve :: Int -> Int -> VU.Vector (Int, Int) -> VU.Vector Int
solve n m abs = VU.init $ ufreeze $ (\(_, _, _, acc) -> acc) $ VU.foldr'
  go
  ( group
  , m - 1
  , nC2
  , uwrite m nC2 $ accursedUnutterablePerformIO $ VUM.unsafeNew (m + 1)
  )
  abs
 where
  go (a, b) (uf, k, prev, acc) =
    let ga  = findUF uf a
        gb  = findUF uf b
        n1  = sizeUF uf a
        n2  = sizeUF uf b
        res = prev - n1 * n2
    in  ( unionUF uf a b
        , k - 1
        , if ga == gb then prev else res
        , uwrite k prev acc
        )

  nC2 = n * (n - 1) `div` 2

  group :: UnionFind
  group = UnionFind
    (uthaw $ VU.enumFromN 0 n, accursedUnutterablePerformIO $ VUM.replicate n 1)

main = do
  let readInt = fmap (second B.tail) . B.readInt

  nm  <- VU.unfoldrN 2 readInt <$> B.getLine
  abs <- VU.replicateM
    (nm VU.! 1)
    (   (\vec -> (vec VU.! 0 - 1, vec VU.! 1 - 1))
    .   VU.unfoldrN 2 readInt
    <$> B.getLine
    )

  VU.mapM_ print $ solve (nm VU.! 0) (nm VU.! 1) abs


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

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int& a : A)
		cin >> a;
	sort(A.begin(), A.end(), greater<int>());
	long long res = A[0];
	for (int i = 0; i < n - 2; ++i)
		res += A[i/2+1];
	cout << res << '\n';

	return 0;
}

Measured memory_bytes: 4032
#include<map>
#include<queue>
#include<time.h>
#include<limits.h>
#include<cmath>
#include<ostream>
#include<iterator>
#include<set>
#include<stack>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define rep(i,m,n) for(int i=m;i<=n;i++)
#define mem(st) memset(st,0,sizeof st)
int read()
{
	int res=0,ch,flag=0;
	if((ch=getchar())=='-')             //判断正负
		flag=1;
	else if(ch>='0'&&ch<='9')           //得到完整的数
		res=ch-'0';
	while((ch=getchar())>='0'&&ch<='9')
		res=res*10+ch-'0';
	return flag?-res:res;
}
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
typedef pair<double,double> pdd;
const int inf = 0x3f3f3f3f;
const int N=1e6+10;
#define int long long
int a[N];
int b[N];
int sum1[N];
int sum2[N];
void solve()
{
	int n,m,k;
	cin>>n>>m>>k;
	int ans=0;
	for(int i=1; i<=n; i++)
		cin>>a[i],sum1[i]=sum1[i-1]+a[i];
	for(int i=1; i<=m; i++)
		cin>>b[i],sum2[i]=sum2[i-1]+b[i];

	for(int i=0; i<=n; i++)
	{
		int l=0,r=m;
		while(l<r)
		{
			int mid=l+r+1>>1;
			if(sum2[mid]+sum1[i]<=k)
				l=mid;
			else
				r=mid-1;
		}
		if(sum2[l]+sum1[i]<=k)
			ans=max(ans,l+i);
	}
	cout<<ans<<endl;
}
signed main()
{
	int t=1;
	while(t--)
		solve();
	return 0;
}


Measured memory_bytes: 9884
/**
 * Program name:Selection Sort
 * author:Xin Peng
 * date:2020/1/5
 * Pragram problem source: AOJ
*/
#include <iostream>
using namespace std;

#define MAX 100

/**
 * @brief Trace display
 * @param data Data to display
 * @param length Length of the data
*/
void trace(int data[], int length)
{
    for (int i = 0; i < length; i++)
    {
        cout << data[i];
        if (i != length - 1)
        {
            cout << " ";
        }
    }
    cout << endl;
}

//Selection Sort
void SelectionSort(int data[], int length, bool ascent, void (*traceHandler)(int data[], int length, void *x), void *x, bool firstLoopOrSecond)
{
    int position;

    for (int i = 0; i < length - 1; i++)
    {
        position = i;

        for (int j = i + 1; j < length; j++)
        {
            if (ascent && (data[j] < data[position]))
            {
                position = j;
            }
            else if (!ascent && (data[j] > data[position]))
            {
                position = j;
            }

            if (traceHandler && firstLoopOrSecond)
            {
                traceHandler(data, length, x);
            }
        }
        if (position == i)
        {
            continue;
        }
        int tmp = data[i];
        data[i] = data[position];
        data[position] = tmp;

        if (traceHandler && !firstLoopOrSecond)
        {
            traceHandler(data, length, x);
        }
    }
}

/**
 * @brief Handler for count
 * @param data Data to display
 * @param length Length of the data
 * @param count Count Variable.
*/
void countHandler(int data[], int length, void *count)
{
    int *pp = (int *)count;
    (*pp)++;
}

int main()
{
    int n;
    int R[MAX];
    int count = 0;

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> R[i];
    }

    SelectionSort(R, n, true, countHandler, &count, false);
    trace(R, n);
    cout << count << endl;

    return 0;
}


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

int main(){
  string s;
  cin >>s;
  int l=s.size();
  if(s[0] != 'A'){
    cout << "WA" <<endl;
    return 0;
  }
  int c=0;
  int e=s[1];
  if(e <97){
    cout << "WA" <<endl;
    return 0;
  }
  e=s[l-1];
      if(e <97){
    cout << "WA" <<endl;
    return 0;
  }

  


  for(int i=2;i<l-1;i++){
    int x;
    x=s[i];
    if(x<97){
      if(x == 67) c++;
      else{
        cout << "WA" <<endl;
        return 0;
      }
    }
  }
  if(c != 1){
    cout << "WA" <<endl;
    return 0;
  }
  cout << "AC" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;

int main(){
  ll N , M , K; cin >> N >> M >> K;
  vector<ll> a(N); rep(i,N) cin >> a[i];
  vector<ll> b(M); rep(i,M) cin >> b[i];

  vector<ll> asum(N + 1);
  vector<ll> bsum(M + 1);
  rep(i,N){
    asum[i + 1] += asum[i] + a[i];
  }
  rep(i,M){
    bsum[i + 1] += bsum[i] + b[i];
  }

  ll ans = 0;
  rep(i,N + 1){
    ll tmp = 0;
    if(asum[i] > K) break;
    else{
      tmp = i;
      tmp += POSU(bsum , K - asum[i]) - 1;
      ans = max(tmp , ans);
    }
  }
  cout << ans << endl;
}


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

const int N = 2e3 + 5;

int n , k , q , A[N] , L[N] , R[N] , id[N] , fa[N]  , S[N];

bool cmp(int x , int y) {
	return A[x] < A[y];
}

int getf(int x) {
	return (fa[x] == x) ? x : fa[x] = getf(fa[x]);
}

bool pd(int x) {
	for(int i = 1;i <= n;++ i) {
		int now = 0;
		for(int ii = 1;ii <= n;++ ii)
		S[ii] = 0 , fa[ii] = ii;
		for(int j = 1;j <= n;++ j) {
			if(A[j] < A[i])
			continue;
			else {
				if(j == 1 || A[j - 1] < A[i])
				S[j] = 1;
				else {
					fa[j] = getf(j - 1);
					++ S[getf(j)];
				}
			}
		}
		for(int j = 1;j <= n;++ j) {
			if(A[id[j]] >= A[i] && A[id[j]] - A[i] <= x) {
				if(S[getf(id[j])] >= k) {
					-- S[getf(id[j])];
					++ now;
				}
			}
		}
		if(now >= q)
		return 1;
	}
	return 0;
}

int main() {
	cin >> n >> k >> q;
	for(int i = 1;i <= n;++ i) {
		scanf("%d" , &A[i]);
		id[i] = i;
	}
	sort(id + 1 , id + n + 1 , cmp);
	int L = 0 , R = 1e9 , res = -1;
	while(L <= R) {
		int mid = (L + R) >> 1;
		if(pd(mid)) {
			R = mid - 1; res = mid;
		}
		else L = mid + 1;
	}
	cout << res << endl;
}

Measured memory_bytes: 384
#include<stdio.h>
int main(void){
	int a,b,c;
	scanf("%d%d%d",&a,&b,&c);
	if(a>b){
		a=b;
	}
	if(a>c){
		a=c;
	}
	scanf("%d%d",&b,&c);
	if(b>c){
		b=c;
	}
	printf("%d\n",a+b-50);
	return 0;
}

Measured memory_bytes: 592
//g++ -std=c++14 test.cpp -o test.out
//問題URL
//https://atcoder.jp/contests/abc109/tasks/abc109_d

//参考
//https://www.hamayanhamayan.com/entry/2018/09/09/004851

//まず各行についてできるだけ右へ右へずらしていく
//そうすると各行の一番右端が奇数かそうでないか、といった状態が完成する
//今度は縦に見ていって下へ下へずらしていく
//最終的に一番右下の1マスが奇数かそうでないか、といった状態が出来上がる

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (1LL<<60);
const int INF_INT = 2147483647-1e6-1;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

LL H,W;
LL a[500][500];

//コインをfirstからsecondへ移動する操作
vector<pair<pair<LL,LL>,pair<LL,LL>>> ans;

void add_move(LL y,LL x,LL to_y,LL to_x){
	ans.push_back(pair<pair<LL,LL>,pair<LL,LL>>(pair<LL,LL>(y,x),pair<LL,LL>(to_y,to_x)));
}
 
void solve(){
	vector<LL> right_edge_h;
	for(int h=0;h<H;h++){
		bool carring = false;//奇数を運んでいる状態かどうか
    	for(int w=0;w<W-1;w++){
    		if(carring){
    			if(a[h][w]%2==1) carring = false;
    			else add_move(h+1,w+1,h+1,w+2);
    		}else{
    			if(a[h][w]%2==1){
    				carring = true;
    				add_move(h+1,w+1,h+1,w+2);
    			}
    		}
    	}
    	if((carring && a[h][W-1]%2==0) || (!carring &&  a[h][W-1]%2==1)) right_edge_h.push_back(h);
    }
    if(right_edge_h.size()%2==0){
    	for(int i=0;i<right_edge_h.size();i+=2){
	    	for(int h=right_edge_h[i];h<right_edge_h[i+1];h++){
	    		add_move(h+1,W,h+2,W);
	    	}
	    }
    }else{
    	for(int i=0;i<right_edge_h.size()-1;i+=2){
	    	for(int h=right_edge_h[i];h<right_edge_h[i+1];h++){
	    		add_move(h+1,W,h+2,W);
	    	}
	    }
	    for(int h=right_edge_h[right_edge_h.size()-1];h<H-1;h++){
    		add_move(h+1,W,h+2,W);
    	}
    }
}
 
int main(){
    cin >> H >> W;
    for(int h=0;h<H;h++){
    	for(int w=0;w<W;w++){
    		cin >> a[h][w];
    	}
    }
 
    solve();
 
    cout << ans.size() << endl;
    for(int i=0;i<ans.size();i++){
    	cout << ans[i].first.first <<" "<< ans[i].first.second;
    	cout << " ";
    	cout << ans[i].second.first <<" "<< ans[i].second.second;
    	cout << endl;
    }
    return 0;
}

Measured memory_bytes: 8176
from bisect import bisect_right
s = input()
n = len(s)
l = [0, 1]
for i in range(len(s) - 1):
    if s[i] == s[i + 1]:
        l[-1] += 1
    else:
        l.append(l[-1]+1)
i = bisect_right(l, n // 2)
print(min(n - l[i - 1], l[i]))

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dump_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */
vector<ll> G[2 * e5];
vector<ll> ans(2 * e5);
unordered_map<ll, ll> pl;
vector<bool> seen(2 * e5);

void dfs(ll now, ll value) {
    seen[now] = true;
    ans[now] = value;
    each(e, G[now]) {
        if (!seen[e]) {
            dfs(e, value + pl[e]);
        }
    }
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        ll n, q;
        cin >> n >> q;
        rep(i, n - 1) {
            ll a, b;
            cin >> a >> b;
            a--, b--;
            G[a].eb(b);
            G[b].eb(a);
        }

        rep(i, q) {
            ll p, x;
            cin >> p >> x;
            p--;
            pl[p] += x;
        }
        dfs(0, pl[0]);

        rep(i, n) cout << ans[i] << '\n';

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

Measured memory_bytes: 32584
#include<iostream>
#include<string>
using namespace std;
int main()
  {
  int n, j=0,k=0,g=0,m=0;
string s;
string s1="AC";
string s2="WA";
string s3="TLE";
string s4="RE";
  cin>>n;
//if(n>=1 && n<=100000){
    for(int i=0;i<n;i++)
    {
      cin>>s;
      if(s=="AC")
        j++;
   else if(s=="WA")
     k++;
     else if(s=="TLE")
       g++;
      else 
        m++;
    }
    cout<<"AC x "<<j<<"\n";
  cout<<"WA x "<<k<<"\n";
     cout<<"TLE x "<<g<<"\n";
    cout<<"RE x "<<m<<"\n";
return 0;
}


Measured memory_bytes: 3564
import math
n=int(input())
p=list(map(int,input().split()))
q=list(map(int,input().split()))

pjun=[i+1 for i in range(n)]
qjun=[i+1 for i in range(n)]

pord=0
qord=0
for i in range(n):
    pi=p[i]
    pord+=pjun.index(pi)*math.factorial(len(pjun)-1)
    pjun.remove(pi)

    qi=q[i]
    qord+=qjun.index(qi)*math.factorial(len(qjun)-1)
    qjun.remove(qi)

print(abs(pord-qord))


Measured memory_bytes: 3064
N, T = map(int, input().split())
li = []

for i in range(N):
    li.append(list(map(int, input().split())))

min = float("inf")
for i in li:
    if i[1] <= T:
        if i[0] < min:
            min = i[0]

if min == float("inf"):
    print("TLE")
else:
    print(min)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define lolololololol ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
const ll mod=998244353;
ll mdx(ll b, ll e){
	ll rs=1ll;
	while(e>0){
		if(e%2==1) rs=(rs*b)%mod;
		b=(b*b)%mod; e/=2;
	}
	return rs;
}
ll fact[200005], inv[200005];
ll choose(ll n, ll k){
	ll ans=fact[n];
	ans=(inv[n-k]*ans)%mod;
	ans=(inv[k]*ans)%mod;
	return ans;
}
int main(){ lolololololol
	fact[0]=1ll;
	for(ll i=1; i<200005; i++)
		fact[i]=(fact[i-1]*i)%mod;
	inv[200004]=mdx(fact[200004], mod-2);
	for(ll i=200003; i>=0; i--)
		inv[i]=(inv[i+1]*(i+1ll))%mod;
	ll n, m, k; cin>>n>>m>>k;
	ll ans=0ll;
	for(ll kk=0; kk<=k; kk++){
		ll nw=choose(n-1ll, kk);
		nw=(nw*m)%mod;
		nw=(nw*mdx(m-1, n-1ll-kk))%mod;
		ans=(ans+nw)%mod;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6780
#include <stdio.h>
int main(void){
	int a,b;
	double c,d,e;
	scanf("%d",&a);
	scanf("%d",&b);
	c=a/b;
	d=a%b;
	e=1.0*a/b;
	printf("%.8lf %.8lf %.8lf\n",c,d,e);
	return 0;}


Measured memory_bytes: 2084
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<ll,P> P2;
const ll mod=1e9+7;
P2 mk_P(ll a,ll b,ll c){return P2(a,P(b,c));}
ll pow(ll x,ll y){
  if(y==0) return 1;
  ll res=pow(x,y/2);
  res*=res;
  res%=mod;
  if(y%2==1) res*=x;
  return res%mod;
}
ll gyaku(ll x){
  return pow(x,mod-2);
}
vector<ll> frac,gfrac;
void set_frac(ll n){
  frac.push_back(1);
  gfrac.push_back(1);
  for(ll i=1;i<=n;i++){
    frac.push_back(frac[i-1]*i%mod);
    gfrac.push_back(gyaku(frac[i]));
  }
}
ll nCr(ll n,ll r){
  ll res=frac[n]*gfrac[r]%mod;
  res*=gfrac[n-r];
  return res%mod;
}
vector<ll> node[200005];
vector<P2> dp[200005];
ll ans[200005]={0};
P2 kans[200005];
bool used[200005]={0};
P2 dfs1(ll pos){
  ll num=0;
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i];
    if(!used[to]){
      used[to]=true;
      P2 p=dfs1(to);
      num+=p.second.second;
      dp[pos].push_back(p);
    }
  }
  ll res=1,rnum=num;
  for(int i=0;i<dp[pos].size();i++){
    res*=dp[pos][i].second.first;
    res%=mod;
    ll knum=dp[pos][i].second.second;
    res*=nCr(num,knum);
    res%=mod;
    num-=knum;
  }
  return kans[pos]=mk_P(pos,res,rnum+1);
}
void dfs2(ll pos,ll X,ll n){
  ll a1=kans[pos].second.first,b1=kans[pos].second.second;
  ll nx=X*gyaku((nCr(n-1,b1)*a1)%mod);
  nx%=mod;
  ll val=1,num=n-1;
  for(int i=0;i<dp[pos].size();i++){
    ll a=dp[pos][i].second.first,nm=dp[pos][i].second.second;
    val*=(nCr(num,nm)*a)%mod;
    val%=mod;
    num-=nm;
  }
  val*=nx;
  val%=mod;
  ans[pos]=val;
  for(int i=0;i<node[pos].size();i++){
    ll to=node[pos][i];
    if(!used[to]){
      used[to]=true;
      dfs2(to,val,n);
    }
  }
}
int main(){
  ll n;
  cin>>n;
  set_frac(n+5);
  for(int i=1;i<n;i++){
    ll s,t;
    cin>>s>>t;
    node[s].push_back(t);
    node[t].push_back(s);
  }
  for(int i=1;i<=n;i++) used[i]=false;
  used[1]=true;
  ans[1]=dfs1(1).second.first;

  for(int i=1;i<=n;i++) used[i]=false;
  used[1]=true;
  for(int i=0;i<node[1].size();i++){
    ll to=node[1][i];
    used[to]=true;
    dfs2(to,ans[1],n);
  }
  for(int i=1;i<=n;i++) cout<<ans[i]<<endl;
}


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

int main(){
  string s;
  cin >> s;
  int a, b;
  for(int i=0; i<s.size()-1; i++){
    if(s.at(i)=='A'){
      a=i;
      break;
    }
  }
  for(int i=s.size()-1; i>0; i--){
    if(s.at(i)=='Z'){
      b=i;
      break;
    }
  }
  cout << b-a+1 << endl;
}  

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

int main() { 	
 int A,B,Ab,N,ans;
 cin >>A>>B;
 vector<int> AA(1);
  vector<int> BB(1);
  N=B*2+1;
 


 if(A%N==0){
	 cout <<A/N <<endl;
 }else{
	cout <<A/N +1<<endl; 
 }
}

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

int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> ai(n);
  vector<ll> tot(n+1);
  for(int i=0; i<n; ++i){
    cin >> ai.at(i);
    --ai.at(i);
    tot.at(i+1) = (tot.at(i) +ai.at(i))%k;
  }
  
  ll ans=0;
  map<ll,ll> mp;
  for(int i=0; i<n+1; ++i){
    ++mp[tot.at(i)];
    if(i-k>=0) --mp[tot.at(i-k)];
    ans += mp[tot.at(i)]-1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 15872
#include<cstdio>
int main()
{
	int m,n,t;
	while(scanf("%d%d%d",&m,&n,&t)!=EOF)
	{
		if(m+n==t||m+t==n||n+t==m)
		printf("Yes\n");
		else
		printf("No\n");
	}
return 0;
}

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

int main() {
    char a;
    cin >> a;
    if (isupper(a)) cout << "A" << endl;
    else cout << "a" << endl;
}

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

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

	// int l, m, s;
	// if (a < b) {
	// 	if (b < c) {
	// 		l = c;
	// 		m = b;
	// 		s = a;
	// 	} else {
	// 		l = b;
	// 		if (a < c) {
	// 			m = c;
	// 			s = a;
	// 		} else {
	// 			m = a;
	// 			s = c;
	// 		}
	// 	}
	// } else {
	// 	if (b > c) {
	// 		l = a;
	// 		m = b;
	// 		s = c;
	// 	} else {
	// 		s = b;
	// 		if (a < c) {
	// 			l = c;
	// 			m = a;
	// 		} else {
	// 			l = a;
	// 			m = c;
	// 		}
	// 	}
	// }

	// answer
	int s = a;
	int m = b;
	int l = c;
	int tmp;

	if (s > m) {
		tmp = s;
		s = m;
		m = tmp;
	}
	if (m > l) {
		tmp = m;
		m = l;
		l = tmp;
	}
	if (s > m) {
		tmp = s;
		s = m;
		m = tmp;
	}
	cout << s << " " << m << " " << l << "\n";

	return 0;
}

Measured memory_bytes: 1168
import java.io._
import java.util.StringTokenizer

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new Abc153(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())

    def nextLong(): Long = java.lang.Long.parseLong(next())

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Abc153(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val h = ni()
    val a = ni()

    out.println(math.ceil(h/a.toDouble).toInt)
  }
}


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

int main(){
    int N;
    long A, B;
    cin >> N >> A >> B;
    long back;
    cin >> back;
    long ans = 0;
    for(int i = 1; i < N; i++){
        long num;
        cin >> num;
        ans += min(B, (num - back) * A);
        back = num;
    }
    cout << ans << endl;
}


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

int main(void){
  int k,x; cin>> k >> x;
  if(500*k >= x) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
int main()
{
    int n; cin >> n;
    int a;
    ll ans = 0;
    int front, d;
    cin >> front;
    FOR(i, 1, n) {
        cin >> a;
        if (front <= a) {
            front = a;
        }else{
            d = front - a;
            front = a + d;
            ans += d;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;

int main() {
  int input;
  int count=1;
  while(cin >> input) {
    if(input == 0) break;
    printf("Case %d: %d", count, input);
    printf("\n");
    count++;
  }
  return 0;
}

Measured memory_bytes: 1148
fun main(args: Array<String>) {
    fun calcDist(l1: List<Double>, l2: List<Double>): Double {
        var sum = 0.0
        for (i in 0 until l1.size) {
            sum += (l1[i] - l2[i]) * (l1[i] - l2[i])
        }
        return Math.sqrt(sum)
    }
    val (n, d) = readLine()!!.split(' ').map(String::toInt)
    val xListList = mutableListOf<List<Double>>()
    (1..n).forEach { xListList.add(readLine()!!.split(' ').map(String::toDouble)) }

    var count = 0
    for (i in 0 until n - 1) {
        val xList1 = xListList[i]
        for (j in i + 1 until n) {
            val xList2 = xListList[j]
            val dist = calcDist(xList1, xList2)
            if (dist % 1 == 0.0) {
                count++
            }
        }
    }

    println(count)
}

Measured memory_bytes: 38184
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const ll K_MAX=1e5+5;



int main(){
  int k,a,b;
  cin>>k>>a>>b;
  
  for(int i=a; i<=b;i++){
    if (i%k==0){
      cout<<"OK"<<endl;
      return 0;
    }
  }
  cout<<"NG"<<endl;
  return 0;
  
 
}


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

int sumd(int n){
  int a = 0;
  while(n > 0){
    a += n % 10;
    n /= 10;
  }
  return a;
}

int main() {
  int n, a, b, s = 0;
  cin >> n >> a >> b;
  rep(i, n){
    int d = sumd(i+1);
    if(d >= a && d <= b) s += i+1;
  }
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <cctype>
using namespace std;
typedef long long lint;
#define cout cerr
#define ni (next_num<int>())
template<class T>inline T next_num(){
	T i=0;char c;
	while(!isdigit(c=getchar())&&c!='-');
	bool flag=c=='-';
	flag?c=getchar():0;
	while(i=i*10-'0'+c,isdigit(c=getchar()));
	return flag?-i:i;
}
template<class T1,class T2>inline void apmax(T1 &a,const T2 &b){if(a<b)a=b;}
template<class T1,class T2>inline void apmin(T1 &a,const T2 &b){if(b<a)a=b;}
const int N=200010;
#define f(i) (a[i]<=m)
int a[N],n,n2;
inline bool check(int m){
	int l=n,r=n;
	for(;l>1&&f(l-1)!=f(l);l--);
	for(;r<n2&&f(r+1)!=f(r);r++);
	return n-l<r-n?f(l):f(r);
}
int main(){
	n=ni,n2=(n<<1)-1;
	for(int i=1;i<=n2;i++){
		a[i]=ni;
	}
	int l=1,r=n2;
	while(l<r){
		int m=(l+r)>>1;
		if(check(m)){
			r=m;
		}else{
			l=m+1;
		}
	}
	printf("%d\n",l);
	return 0;
}

Measured memory_bytes: 1024
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define mod 1000000007

bool isKaibun(string s) {
	for (int i = 0; i < s.length() / 2; i++) {
		if (s[i] != s[s.length() - 1 - i]) return false;
	}
	return true;
}

int main() {
	string s;
	cin >> s;
	int n = s.length();
	string s1 = s.substr(0, (n - 1) / 2);
	string s2 = s.substr((n + 3) / 2 - 1);
	if (isKaibun(s1) && isKaibun(s2) && isKaibun(s))
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 256
from collections import defaultdict

N = int(input())
nums = list(map(int,input().split()))
Q = int(input())

res = 0

dct = defaultdict(int)
for _ in range(N):
  n = nums.pop()
  dct[n] += 1
  res += n

for _ in range(Q):
  B, C = map(int,input().split())
  if B in dct:
    n = dct.pop(B)
    res += (C - B) * n
    if C in dct:
      dct[C] += n
    else:
      dct[C] = n
  
  print(res)


Measured memory_bytes: 21604
/*  ex4_1
    hangan2020 */

#include <stdio.h>
#include <math.h>
#define _USE_MATH_DEFINES

//プロトタイプ宣言
double ClockHandsDistance(double LHLength, double SHLength, double Hour, double Minute);

int main(void){
    double lhlength, shlength, hour, minute;
    double distance; 
    scanf("%lf %lf %lf %lf", &lhlength, &shlength, &hour, &minute);
    distance = ClockHandsDistance(lhlength, shlength, hour, minute);
    printf("%0.15lf\n", distance);
    return 0;
}

//関数定義
double ClockHandsDistance(double LHLength, double SHLength, double Hour, double Minute){
    double handsangle, hands_distance;
    //Hour時間になるときの角度
    handsangle = 30*Hour;
    //そのMinute分後の角度 
    handsangle = handsangle - 5.5*Minute;
    //ラジアンに変換
    handsangle = handsangle*(M_PI/180);
    hands_distance = pow(LHLength, 2) + pow(SHLength, 2) - 2*LHLength*SHLength*cos(handsangle);
    hands_distance = sqrt(hands_distance);
    return(hands_distance);
}

Measured memory_bytes: 2568
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef map<int, int> mi;
typedef set<int> si;
#define VV(T) vector<vector< T > >
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define rep(i, n) REP(i, 0, n)                              // 0, 1, ..., n-1
#define REP(i, x, n) for(int i = x; i < n; i++)             // x, x + 1, ..., n-1
#define FOREACH(x,a) for(auto& (x) : (a) )
#define SORT(x) sort(x.begin(), x.end())

#define ALL(v) (v).begin() , (v).end()
#define RALL(v) (v).rbegin(), (v).rend()

#define pb push_back
#define pu push
#define mp make_pair
#define fi first
#define sc second

#define COUT(x) cout << (x) << endl
#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

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, M; cin >> N >> M;
    vi number[100001];
    int P[100000], Y[100000];
    rep (i, M) {
        cin >> P[i] >> Y[i];
        number[P[i]].push_back(Y[i]); // 連結リスト
    }

    rep (i, N) {
        sort(number[i + 1].begin(), number[i + 1].end()); // 0は含まないため1~ソートする
    }
    
    rep (i, M) {
        printf("%012lld\n", ll(P[i]) * 1000000 + int(lower_bound(number[P[i]].begin(), number[P[i]].end(), Y[i]) - number[P[i]].begin()) + 1); // Y[i]の位置　- 先頭のイテレータ + 1
    }
}

Measured memory_bytes: 7808
import Data.List ( sort )
import qualified Data.ByteString.Char8 as C
import Data.Maybe ( fromJust )

getParm
  :: IO [Int]
getParm = map (fst . fromJust . C.readInt) . C.words <$> C.getLine

main :: IO ()
main = do
  [n,x] <- getParm
  as    <- getParm
  print $ f n x as

f :: Int -> Int -> [Int] -> Int
f n x as
  | t < x     = n-1
  | k <= n    = k   
  | otherwise = 0
  where
    ai = head as'
    t = sum as
    lengthUpto x = length . takeWhile (<= x) 
    k = lengthUpto x sums
    sums = scanl1 (+) as'
    as' = sort as

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

int main() {
  int n;
  cin>>n;
  vector<int>a(n);
  for(int i=0;i<n;i++) cin>>a[i];
  sort(a.begin(),a.end());
  int al=0;
  int b=0;
  for(int i=n-1;i>=0;i--){
    if((n-1-i)%2==0) al+=a[i];
    else b+=a[i];
  }
  cout<<al-b<<endl;
}


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

using namespace std;

typedef long long LL;
int L_data[3];
long long data[3][1005];


typedef pair<long long,long long> node; 

struct param{
  LL x;
  LL y;
  LL z;
  param(LL x,LL y,LL z):x(x),y(y),z(z){}
};

long long conv(long long x,long long y,long long z){
  return x*(LL)(1e8)+y*(LL)(1e4)+z;
}


bool f [1004][1004][1004];

param rev(long long v){
  param re=param(0,0,0);
  re.z=v%(LL)(1e4);
  v/=(LL)(1e4);
  re.y=v%(LL)(1e4);
  v/=(LL)(1e4);
  re.x=v;
  return re;
}

long long sum_p(param p){
  return data[0][p.x]+data[1][p.y]+data[2][p.z];
}

int main(){

  priority_queue<node> que;
  LL X,Y,Z,K;
  for(int i=0;i<3;i++){
    cin>>L_data[i];
  }
  cin>>K;
  for(int i=0;i<3;i++){
    for(int j=0;j<L_data[i];j++)cin>>data[i][j];
    sort(data[i],data[i]+L_data[i]);
  }
  long long sum=0;
  for(int i=0;i<3;i++)sum+=data[i][L_data[i]-1];
  int count=0;
  que.push(node(sum,conv(L_data[0]-1,L_data[1]-1,L_data[2]-1)));
  while(count++<K){
    node now;
    while(1){
      now=que.top();
      que.pop();
      param t =rev(now.second);
      if(!f[t.x][t.y][t.z]){
       f[t.x][t.y][t.z]=true;
       break;
      }
    }
    cout<<now.first<<endl;
    param tmp=rev(now.second);
    if(tmp.x>0)que.push(node(sum_p(rev(conv(tmp.x-1,tmp.y,tmp.z))),conv(tmp.x-1,tmp.y,tmp.z)));
    if(tmp.y>0)que.push(node(sum_p(rev(conv(tmp.x,tmp.y-1,tmp.z))),conv(tmp.x,tmp.y-1,tmp.z)));
    if(tmp.z>0)que.push(node(sum_p(rev(conv(tmp.x,tmp.y,tmp.z-1))),conv(tmp.x,tmp.y,tmp.z-1)));
    
  }


}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

vector<vector<ll>> G;

int main() {
  ll n, ans = 0;
  cin >> n;
  vector<ll> a(n);
  G.assign(n, vector<ll>());
  rep(i, n) {
    cin >> a[i];
    a[i]--;
  }

  rep(i, n) if (a[a[i]] == i) ans++;
  cout << ans / 2 << endl;
  return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using ld = long double;
const ll ATCODER_AMARI = 1000000007; //10^9 + 7
const ll INF = 10000000000000;

//階乗関数
ll factorial(ll k){
  ll sum = 1;
  for(int i = 1 ; i < k + 1; i++) {
    sum *= i;
    sum = sum % ATCODER_AMARI;
  }
  return sum;
}

int main() { 
  rep(i,5){
    int k; cin >> k;
    if(k == 0) {
      cout << i + 1 << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 3632
from collections import Counter


def factor(N):
    ret = []
    i = 2
    while N > 1:
        if N % i == 0:
            ret.append(i)
            N //= i
        else:
            i += 1
    return ret


def solve(N, As):
    iter = Counter(factor(min(As)))

    for a in As:
        for k, v in iter.items():
            if a % k != 0:
                iter[k] = 0
            else:
                count = 0
                kk = k
                while a % kk == 0:
                    kk *= k
                    count += 1
                iter[k] = min(v, count)
    d = 1
    for k, v in iter.items():
        if v != 0:
            d *= k ** v
    return d

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))


Measured memory_bytes: 14636
import sys
if sys.argv[-1] == 'ONLINE_JUDGE':
    import os, zlib, base64
    open('solve.pyx', 'wb').write(zlib.decompress(base64.b85decode("c$|e)+isjN5PkPoj1*-9SuS1WrHVp+Bt^(JW@FVDWSfWd>pKQYutPVz80K>3oEbBB&`RqjCzX8$MfG)}S5fivncVF?Qgb!6qG_eERrx;jqU3{i!aAy5S*U?iRVvBK@x#3j`l<L?TIobSQvMqOZK<bz{J<O|$`y-rX6ONPcwt?OCve%1gK^MPg@74!MhHT9D>~qcS_`e6o(bSH+oX2T=<xe-q(*4h45qR24`zF>cQy@|TDqo55Cp7HT{b7^bU}<zpn{kA?R907Xm|t<Idlm+(saw}1_Kh)z+m@8vIq3f_$F&a%P*VN7cUx(MjhHh?&u%){97>-*(umn@~uh^KvEL+M+w>r6ZL@ZfMj>X<&D<x0zX1!M!3mnptnT$#A<P@rH_L?+qt41hec{E?M19*Ie_gn?IBkdG=(bU#o|`^k~bQ)g62m=!%8vhUYP5DXtVe>y6uxjeWaf)WAH`FZk*IBW#5br;|`U~b3gR3I)rpcf(91Pm<1M3)O~kd&efrZ)i)Da9n{|hhFeAs+mf-IYHa>!u<sq&hNCm+Gd~W76Ul&+IWBp)Z|~cO3{L1j_30AtM>t_wJn^?D(IV*ASw;W|eOd=J70Xqi`339cmoE_ic8Q<P6f4HH@(O%+U;LIih$4$b&)}Cv20SHy0fYF)@&")))
    os.system('cythonize -i -3 -b solve.pyx')
import solve

Measured memory_bytes: 9832
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200003,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long double L;cin>>L;
    cout<<setprecision(25)<<pow((L/3.0),3.0)<<endl;
}


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

int main() {
  int a, b, c;

  cin >> a >> b >> c;

  if (a - b == b - c){
    std::cout << "YES" << '\n';
    return 0;
  }


  cout << "NO" <<'\n';
  return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n) - 1; i >= 0; i--)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i > (b); i--)
#define ALL(a) (a).begin(), (a).end()

int main() {
    int N, a, max_a = -1, min_a = 10000;
    cin >> N;
    REP(i, N) {
        cin >> a;
        max_a = max(a, max_a);
        min_a = min(a, min_a);
    }
    cout << max_a - min_a << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef unsigned long long llu;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
const ll MOD = 1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

pii red[100];
pii blue[100];
set<int> se;
// first 순으로 정렬하고, first에서는 투포인터 돌리고, 나머지 set으로 관리해서 풀면 될듯.

int main() {
	int n;
	scanf("%d", &n);

	for (int i = 0; i < n; i++)
		scanf("%d %d", &red[i].first, &red[i].second);

	for (int i = 0; i < n; i++)
		scanf("%d %d", &blue[i].first, &blue[i].second);
	sort(red, red + n);
	sort(blue, blue + n);

	int l = 0, cnt = 0;
	for (int i = 0; i < n; i++) {
		while (l < n && blue[i].first > red[l].first) {
			se.insert(red[l].second);
			l++;
		}

		auto k = se.lower_bound(blue[i].second);
		if (k == se.begin()) continue;
		cnt++; se.erase(--k);
	}

	printf("%d", cnt);
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int[] A = new int[3];
		for(int i = 0; i < 3; i++) {
			A[i] = sc.nextInt();
		}
		
		Arrays.sort(A);
		System.out.println(A[0] + " " + A[1] + " " + A[2]);
		
		sc.close();
	}
}



Measured memory_bytes: 26136