akhauriyash/Code-Regression huggingface dataset:
#![allow(non_snake_case, unused_mut)]
use std::collections::HashMap;
fn main() {
    proconio::input! {
        n:usize,
        A:[usize;n]
    }
    let mut B = HashMap::new();
    for i in 0..n {
        *B.entry(A[i]).or_insert(0) += 1;
    }
    let mut sum = 0usize;
    for (_, &v) in B.iter() {
        sum += if v <= 1 { 0 } else { v * (v - 1) / 2 };
    }
    for i in 0..n {
        let val = B.get(&A[i]).unwrap();
        let ans = sum + 1 - val;
        println!("{}", ans);
    }
}


Measured memory_bytes: 11548
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Nmax = 1e5;
int N, A[Nmax];

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

	int amax=0, amin=1e5;
	for(int i=0; i<N; i++){
		amin = min(A[i], amin);
		amax = max(A[i], amax);
	}

	int nmax=0, nmin=0;
	for(int i=0; i<N; i++){
		if(A[i]==amax) nmax++;
		else if(A[i]==amin) nmin++;
	}

	if(nmax+nmin != N || amax-amin > 1){
		cout << "No" << endl;
		return 0;
	}

	if(nmin == 0 && amax == N-1){
		cout << "Yes" << endl;
		return 0;
	}

	//cout << nmax << " " << nmin << endl;
	//cout << amax << " " << amin << endl;
	if(1 <= amax-nmin && amax-nmin <= nmax/2){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}


	return 0;
}


Measured memory_bytes: 640
N = int(input())
A = [int(_) for _ in input().split()]
B = [int(_) for _ in input().split()]


def count(n, a, b):
    a0, a1, a2 = a
    b0, b1, b2 = b
    dp = [0] * (n + 1)
    for i in range(n + 1):
        c0 = dp[i - a0] + b0 if i - a0 >= 0 else 0
        c1 = dp[i - a1] + b1 if i - a1 >= 0 else 0
        c2 = dp[i - a2] + b2 if i - a2 >= 0 else 0
        dp[i] = max(i, c0, c1, c2)
    return dp[n]


print(count(count(N, A, B), B, A))

# https://atcoder.jp/contests/diverta2019-2/submissions/5942579


Measured memory_bytes: 230040
#include<bits/stdc++.h>
using namespace std;
#define ALL(v) (v).begin(),(v).end()
#define REP(i,p,n) for(int i=p;i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SZ(x) ((int)(x).size())
#define debug(x) cerr << #x << ": " << x << '\n'
const char newl = '\n';
typedef long long int Int;
typedef pair<int,int> P;
using ll = long long;
using VI = vector<int>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const long long INF = 1LL<<60;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> nums(N,1),can(N,0);
    can[0] = 1;
    for(int i=0;i<M;i++){
        int a,b;cin >> a >> b;
        a--,b--;
        if(can[a]) can[b] = 1;
        if(nums[a]==1) can[a] = 0;
        nums[a]--;
        nums[b]++; 
    }
    int res = 0;
    rep(i,N) if(can[i]&&nums[i]) ++res;
    cout << res << endl;
}

Measured memory_bytes: 4060
#include <bits/stdc++.h>
typedef  long long  ll;
typedef unsigned long long ull;
typedef long double ld;
#define mp make_pair
#define F first
#define S second
#define pb push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define all(v) v.begin(),v.end()
const ll INF = ll(1e9);
const int N = 2e5 + 5;
const ll mod = 1000000007 ;
using namespace std;

ll binpow(ll x, ll y) {
	ll z = 1;
	while (y) {
		if (y % 2) z = (z * x) % mod;

		y = y / 2;
		x = (x * x) % mod;
	}
	return z % mod;
}

int main() {


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


	ll tc = 1;

//	cin >> tc;

	while (tc--) {
		
		ll a, b, c, k;
		cin >> a >> b >> c >> k;
		
		ll ans = 0;
		ans += 1*min(a, k);
		k -= min(a,k);
		
		ans += 0 * min(b,k);
		k -= min(b, k);
		
		ans += -1*min(c,k);
		k -= min(c, k);
		
		cout << ans << endl;
		
	}

}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
#define int long long int
using namespace std;
signed main()
{
	int n, l, flag=0;
	cin>>n>>l;
	int total=0,  a[n+1];
	for (int i = 1; i <= n; ++i)
	{
		cin>>a[i];
		total += a[i];
	}
	if(total<l)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	for (int i = 1; i < n; ++i)
	{
		if(a[i]+a[i+1]>=l)
		{
			cout<<"Possible"<<endl;
			flag = i;
			break;
		}
	}
	if(flag==0)
	{
		cout<<"Impossible"<<endl;
		return 0;
	}
	for (int i = 1; i < flag; ++i)
	{
		cout<<i<<endl;
	}
	for (int i = n-1; i >= flag ; i--)
	{
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 4416
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define si set <ll>
#define vi vector <ll>
#define mii map <ll,ll>
#define vpi vector <pair <ll,ll> >
#define ll long long
#define sc second
#define pb push_back
#define mp make_pair
#define ff(i,a,n) for(int i=a;i<n;i++)
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    #endif
    ios::sync_with_stdio(false);
    cin.tie(0);ll x,p=100,c=0;
    cin>>x;
    while(p<x)
    {
        p+=p/100;c+=1;
    }
    cout<<c;



    return 0;
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
#include<string.h>
 
typedef long long int ll;
#define all(x) (x).begin(), (x).end()
 
using namespace std;

int nxt() {
    int x;
    cin >> x;
    return x;
}

ll nxtl(){
    ll x;
    cin>>x;
    return x;
}
 
void SieveOfEratosthenes(int n,vector <int> &primes) 
{ 
    // Create a boolean array "prime[0..n]" and initialize 
    // all entries it as true. A value in prime[i] will 
    // finally be false if i is Not a prime, else true. 
    bool prime[n+1]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        // If prime[p] is not changed, then it is a prime 
        if (prime[p] == true) 
        { 
            // Update all multiples of p greater than or  
            // equal to the square of it 
            // numbers which are multiple of p and are 
            // less than p^2 are already been marked.  
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
  
    // Print all prime numbers 
    for (int p=2; p<=n; p++) 
       if (prime[p]) 
          primes.push_back(p);
} 
 
ll max(ll a,ll b)
{
    if(a>b)
        return a;
    return b;
}
 
ll power(ll x, ll y,ll mod) 
{ 
    ll temp; 
    if( y == 0) 
        return 1; 
    temp = power(x, y/2,mod); 
    if (y%2 == 0) 
        return (temp*temp)%mod; 
    else
        return (((x*temp)%mod)*temp)%mod; 
} 

ll modPow(ll a, ll x, ll p) {
    //calculates a^x mod p in logarithmic time.
    ll res = 1;
    while(x > 0) {
        if( x % 2 != 0) {
            res = (res * a) % p;
        }
        a = (a * a) % p;
        x /= 2;
    }
    return res;
}

ll modInverse(ll a, ll p) {
    //calculates the modular multiplicative of a mod m.
    //(assuming p is prime).
    return modPow(a, p-2, p);
}
ll modBinomial(ll n, ll k, ll p) {
// calculates C(n,k) mod p (assuming p is prime).

    ll numerator = 1; // n * (n-1) * ... * (n-k+1)
    for (int i=0; i<k; i++) {
        numerator = (numerator * (n-i) ) % p;
    }

    ll denominator = 1; // k!
    for (int i=1; i<=k; i++) {
        denominator = (denominator * i) % p;
    }

    // numerator / denominator mod p.
    return ( numerator* modInverse(denominator,p) ) % p;
}

ll f[200001];
 
ll pow(ll a, ll b, ll MOD)
{
 ll x=1,y=a; 
 while(b > 0)
    {
        if(b%2 == 1)
    {
        x=(x*y);
        if(x>MOD) x%=MOD;
    }
    y = (y*y);
    if(y>MOD) y%=MOD; 
    b /= 2;
    }
 return x;
}
 
/* Modular Multiplicative Inverse
 Using Euler's Theorem
 a^(phi(m)) = 1 (mod m)
 a^(-1) = a^(m-2) (mod m) */
ll InverseEuler(ll n, ll MOD)
{
 return pow(n,MOD-2,MOD);
}
 
ll C(ll n, ll r, ll MOD)
{
 
 return (f[n]*((InverseEuler(f[r], MOD) * InverseEuler(f[n-r], MOD)) % MOD)) % MOD;
}
 


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int a=nxt(),b=nxt();
    cout<<a*b<<endl;


    return 0;   
}


 
 


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

using ll = long long;
using namespace std;
constexpr ll inf = 1e15;
constexpr ll mod = 1e9+7;

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

    string S;
    cin>>S;

    int i = S.length() - 1;
    while (i >= 0) {
        if (i >= 4 && S.substr(i-4, 5) == "dream") i -= 5;
        else if (i >= 6 && S.substr(i-6, 7) == "dreamer") i -= 7;
        else if (i >= 4 && S.substr(i-4, 5) == "erase") i -= 5;
        else if (i >= 5 && S.substr(i-5, 6) == "eraser") i -= 6;
        else {
            cout<<"NO"<<endl;
            return 0;
        }
    }

    cout<<"YES"<<endl;

    return 0;
}

Measured memory_bytes: 512
#import"bits/stdc++.h"
#define r(n) for(i=0;i<n;i++)
using namespace std;main(int N){cin>>N;int A[2*N],c[N+1]={},n,t,i;r(2*N)cin>>A[i];r(2*N)c[A[i]]++;if(*max_element(c,c+N+1)>N)cout<<"No";else{cout<<"Yes ";queue<int>s;r(N)if(A[i]==A[N+i])s.push(i);while(s.size()){n=s.front(),t=N+rand()%N;if(A[n]!=A[t]&A[t-N]!=A[n+N])swap(A[n+N],A[t]),s.pop();}r(N)cout<<A[i+N]<<" ";}}

Measured memory_bytes: 6376
a=int(input())
Number=[l for l in range(a+1)]
Number.pop(0)
List=[]
import math
for i in Number:
    for j in Number:
        b=math.gcd(i,j)
        for  k in Number:
            c=math.gcd(b,k)
            List.append(c)
print(sum(List))

Measured memory_bytes: 71512
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
typedef long long ll;
const int maxn = 2000 + 10;
const ll INF = 1LL << 60;

int n, h[maxn], ecnt;
ll Ans;
struct enode{
	int v, n;
	enode() {}
	enode(int _v, int _n):v(_v), n(_n) {}
}e[maxn << 1];
char s[maxn];

inline void addedge(int u, int v) { ecnt ++; e[ecnt] = enode(v,h[u]); h[u] = ecnt; }

int sz[maxn], f[maxn], g[maxn], dep[maxn];

inline void Merge(int p, int u, int v) {
	sz[p] = sz[u] + sz[v];
	f[p] = f[u] + f[v];
	if(g[u] > g[v]) swap(u,v);
	if(f[u] > g[v]) g[p] = f[p] % 2;
	else g[p] = g[v] - f[u];
}

void dfs(int u, int fa) {
	sz[u] = f[u] = g[u] = 0;
	for(int i = h[u];~ i;i = e[i].n) {
		int v = e[i].v;
		if(v == fa) continue;
		dep[v] = dep[u] + 1;
		dfs(v,u);
		f[v] += sz[v]; g[v] += sz[v];
		int p = 0; Merge(p,u,v);
		sz[u] = sz[p]; f[u] = f[p]; g[u] = g[p];
	}
	if(s[u] == '1') sz[u] ++;
}

inline void solve(int r) {
	dep[r] = 0;
	dfs(r,0);
	if(g[r] == 0) {
		ll tmp = 0;
		for(int i = 1;i <= n;i ++) if(s[i] == '1') tmp += (ll)dep[i];
		Ans = min(Ans,tmp / 2);
	}
}

int main() {
	scanf("%d", &n); ecnt = 0;
	memset(h,-1,sizeof(h));
	scanf("%s", s + 1);
	for(int i = 1;i < n;i ++) {
		int u, v;
		scanf("%d%d", &u, &v);
		addedge(u,v);
		addedge(v,u);
	}
	Ans = INF;
	for(int i = 1;i <= n;i ++) {
		solve(i);
	}
	if(Ans == INF) Ans = -1;
	printf("%lld\n", Ans);
	return 0;
}

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

int main(){
    bool card[4][14];
    int n,a;
    char suit;
    
    for(int s=0;s<4;s++){
        for(int r=1;r<=13;r++){
            card[s][r]=0;
        }
    }
    
    cin >> n;
    for (int i=0;i<n;i++){
        cin >> suit >> a;
        if(suit=='S') card[0][a]=1;
        else if(suit=='H') card[1][a]=1;
        else if(suit=='C') card[2][a]=1;
        else card[3][a]=1;
        
    }
    for(int s=0;s<4;s++){
        for(int r=1;r<=13;r++){
            if(card[s][r]) continue;
            if(s==0) suit='S';
            if(s==1) suit='H';
            if(s==2) suit='C';
            if(s==3) suit='D';
            cout << suit << " " << r << endl;
            
        }
    }
    return 0;
}


Measured memory_bytes: 3072
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int inf = 1e9;

int main(){
	int n;
	cin >> n;
	vector<vector<int> > c(n, vector<int>(256, 0));
	for(int i=0; i<n; i++){
		string s;
		cin >> s;
		for(int j=0; j<(int)s.length(); j++){
			c[i][s[j]]++;
		}
	}
	string ans = "";
	for(int i='a'; i<='z'; i++){
		int num = inf;
		for(int j=0; j<n; j++){
			num = min(num, c[j][i]);
		}
		ans += string(num, (char)i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main{

    void solve(){
        Scanner sc = new Scanner(System.in);

        int max = (int)Math.pow(2, 15) + 2;
        int[][] dp = new int[max][5];
        dp[0][0] = 1;
        for(int k=1; k*k<max; k++){
            for(int i=0; i<max; i++){
                if(i-k*k<0) continue;
                for(int j=1; j<5; j++){
                    dp[i][j] += dp[i-k*k][j-1];
                }
            }
        }

        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            int sum = 0;
            for(int i=0; i<5; i++) sum += dp[n][i];
            System.out.println(sum);
        }
    }

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

Measured memory_bytes: 23368
import java.util.*;
import java.io.*;

public class Main{

    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        //test cases
        int n = in.nextInt();
        int sn =0;
        int temp = n;
        while(n>=10){
        sn = sn + n%10;
       // System.out.println(sn);
        n = n/10;
        }
        sn = sn +n;
        if(temp%sn==0) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 21844
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE BangPatterns          #-}
{-# LANGUAGE CPP                   #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedStrings     #-}
{-# LANGUAGE RecordWildCards       #-}
{-# LANGUAGE TupleSections         #-}
{-# LANGUAGE TypeFamilies          #-}

import           Control.Applicative
import           Control.Monad
import           Control.Monad.Primitive
import           Control.Monad.ST
import           Control.Monad.State.Strict
import           Data.Bool
import qualified Data.ByteString.Char8       as B
import qualified Data.ByteString.Unsafe      as B
import           Data.Char
import           Data.Function
import qualified Data.IntMap.Strict          as IM
import qualified Data.IntSet                 as IS
import           Data.List
import qualified Data.Map.Strict             as M
import           Data.Monoid
import           Data.Ord
import           Data.Primitive.MutVar
import qualified Data.Set                    as S
import           Data.Tuple
import qualified Data.Vector                 as V
import qualified Data.Vector.Generic         as G
import qualified Data.Vector.Generic.Mutable as GM
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM
import           Debug.Trace
import           Foreign                     hiding (void)
import           Unsafe.Coerce

main :: IO ()
main = do
    n <- readLn :: IO Int
    cs <- U.unfoldrN n B.uncons <$> B.getLine
    q <- readLn :: IO Int
    ks <-map read.words <$> getLine
    mapM_ (print.solve cs) ks

solve :: U.Vector Char -> Int -> Int
solve cs k = fst $ U.foldl' step (U.foldl' step0 (0, emptyQ) pre) $ U.zip cs post
  where
    (pre, post) = U.splitAt k cs
    step0 (res, q) c = (res', q')
      where
        !q' = push c q
        !res' | c == 'C' = res + score q'
              | otherwise = res

    step (res, q) (ck, c) = (res', q')
      where
        !q' = push c $ pop ck q
        !res' | c == 'C' = res + score q'
              | otherwise = res

data Q = Q !Int !Int !Int

emptyQ :: Q
emptyQ = Q 0 0 0

push :: Char -> Q -> Q
push c q@(Q d m dm) = case c of
    'D' -> Q (d + 1) m dm
    'M' -> Q d (m + 1) (dm + d)
    _   -> q

pop :: Char -> Q -> Q
pop c q@(Q d m dm) = case c of
    'D' -> Q (d - 1) m (dm - m)
    'M' -> Q d (m - 1) dm
    _   -> q

score :: Q -> Int
score (Q _ _ dm) = dm


Measured memory_bytes: 8828
#include<bits/stdc++.h>
using namespace std;
#define IO {ios_base::sync_with_stdio(false); cin.tie(0);}
#define ll   long long
#define pi pair<ll,ll>

ll a[300000],dp[3000][3000];

ll f(ll n, ll s, ll mod)
{
    if(3*n>s) return 0;
    if(!n && !s) return 1;
    if(s<0 || !n) return 0;
    if(dp[n][s]!=-1) return dp[n][s];
    dp[n][s] = (f(n-1,s-3,mod)+f(n,s-1,mod))%mod;
    return dp[n][s];
}
int main()
{
    IO;
    ll i, j, k = 1, n, g=1, r, mod=1e9+7, l=1, t, mn;
        cin>>n; k=n/3;
        for(i=0; i<=n; i++){
            for(j=0; j<=k; j++) dp[j][i]=-1;
        }
        for(i=1; i<=k; i++) f(i,n,mod); j=0;
        for(i=1; i<=k; i++)
            j = (j+dp[i][n])%mod;

        cout<<j<<endl;
        return 0;
}


Measured memory_bytes: 16800
#include<bits/stdc++.h>;
using namespace std;
int main(){
	int a,b,c,d;
	cin>>a>>b>>c;
	cin>>d;
	int e=abs(a-b);
	int f=abs(b-c);
	int g=abs(a-c);
	if(f<=d&&e<=d||g<=d) cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const long long EVENINF = 100100100100100;  //でかい偶数
//二冪
//ケンチョンさんの写経

int main(){

    int n; cin >> n;
    vector<pair<long long, long long> > pos(n); //pos := position
    for(int i = 0; i < n; i++) cin >> pos[i].first >> pos[i].second;

    //x[i] + y[i]のパリティが不一致なら -1 を出力
    bool par1 = (pos[0].first + pos[0].second + EVENINF) % 2;
    for(int i = 0; i < n; i++){
        bool par2 = (pos[i].first + pos[i].second + EVENINF) % 2;
        pos[i] = {pos[i].first + pos[i].second, pos[i].first - pos[i].second};
        if(par1 != par2){
            cout << -1 << endl;
            return 0;
        }
    }


    //ロボットアームを構成
    vector<long long> d;
    for(int i = 30; i >= 0; i--) d.push_back(1LL << i);
    if(!par1) d.push_back(1LL);
    
    //ロボットアームの情報を出力
    cout << d.size() << endl;
    for(int i = 0; i < (int)d.size(); i++){
        if(i + 1 == (int)d.size()) cout << d[i] << endl;
        else cout << d[i] << " ";
    }

    for(int i = 0; i < n; i++){
        int xdir, ydir;
        long long xsum = 0LL, ysum = 0LL;
        for(int j = 0; j < (int)d.size(); j++){
            
            //cout << xsum << " " << ysum << endl;

            if(xsum <= pos[i].first){
                xdir = 1;
                xsum += d[j];
            }else{
                xdir = -1;
                xsum -= d[j];
            }

            if(ysum <= pos[i].second){
                ydir = 1;
                ysum += d[j];
            }else{
                ydir = -1;
                ysum -= d[j];
            }
            
            if (xdir == 1 && ydir == 1) cout << "R";
            else if (xdir == 1 && ydir == -1) cout << "U";
            else if (xdir == -1 && ydir == -1) cout << "L";
            else cout << "D";

        }
        //cout << "( " << xsum << ", " << ysum << ")" << endl;
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
int main()
{
    int a[2],ans=0;
    std::cin>>a[0]>>a[1];
    std::sort(a,a+2);
    ans+=a[1];
    a[1]--;
    std::sort(a,a+2);
    ans+=a[1];
    std::cout<<ans;
    return 0;
}

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

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

using namespace std;

typedef long long int ll;

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

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N, M;
    ll K;
    cin >> N >> M >> K;
    vector<ll> A(N);
    REP(i, 0, N) {
        cin >> A[i];
    }
    auto dp = make_v(2, M + 1, 1LL << 50);
    vector<ll> Min(M + 1, 1LL << 50), Max(M + 1, 0);
    dp[0][0] = 0;
    REP(i, 0, N + 1) {
        dp[(i + 1) % 2] = vector<ll>(M + 1, 1LL << 50);
        REP(j, 0, M + 1) {
            if (i - j < 0) continue;
            ll cost = (Max[j] - Min[j]);
            chmin(dp[i % 2][0], dp[i % 2][j] + K + j * cost);
        }
        if (i != N) {
            for (int j = M - 1; j >= 0; j--) {
                Min[j + 1] = min(Min[j], A[i]);
                Max[j + 1] = max(Max[j], A[i]);
            }
        }
        REP(j, 0, M + 1) {
            if (i != N && j - 1 >= 0) {
                chmin(dp[(i + 1) % 2][j], dp[i % 2][j - 1]);
            }
        }
    }
    /*
    REP (i, 0, N + 1) {
        REP (j, 0, M + 1) {
            cout << dp[i][j] << " ";
        }
        cout << endl;
    }
    //*/
    cout << dp[N % 2][0] << endl;

    return 0;
}



Measured memory_bytes: 3280
#include <iostream>

using namespace std;

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

    int cnt = 0;
    int total = 0;
    for(int i=0; i <= a; i++){
        for(int j=0; j <= b; j++){
            for(int k=0; k <= c; k++){
                total = 500*i + 100*j + 50*k;
                if(total == x) cnt++;
            }
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
using namespace std;
int main(){
    int N, K;
    cin >> N >> K;
    long long ans = 0;
    vector<long long> V(N);
    for(int i = 0; i < N; i++) cin >> V[i];
    int kosu = min(N, K);
    for(int i = (kosu + 1) / 2; i <= kosu; i++){
        for(int j = i - 1; j >= -1; j--){
            priority_queue<long long, vector<long long>, greater<long long>> q;
            for(int k = 0; k < i; k++){
                q.push(V[(j - k + N) % N]);
            }
            for(int k = 0; k < K - i; k++){
                if(q.top() > 0 || q.empty()) break;
                q.pop();
            }
            long long res = 0;
            while(!q.empty()){
                res += q.top();
                q.pop();
            }
            ans = max(ans, res);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

from collections import deque
inf = 10**18
H, W, K = mapint()
y1, x1, y2, x2 = mapint()
query = [list(str(input())) for _ in range(H)]
dirc = [(0, 1), (-1, 0), (0, -1), (1, 0)]

checked = [[-1]*W for _ in range(H)]
checked[y1-1][x1-1] = 0

queue = deque([(y1-1, x1-1)])
def bfs(queue):
    while len(queue):
        y, x = queue.popleft()
        if y==y2-1 and x==x2-1:
            return checked[y][x]
        for dy, dx in dirc:
            for i in range(1, K+1):
                ny, nx = y+(dy*i), x+(dx*i)
                if ny>=H or ny<0 or nx>=W or nx<0:
                    break
                if query[ny][nx]=='@':
                    break
                if checked[ny][nx]<0:
                    checked[ny][nx] = checked[y][x]+1
                    queue.append((ny, nx))
                elif checked[ny][nx]<=checked[y][x]:
                    break
    return -1

print(bfs(queue))


Measured memory_bytes: 135856
#include<stdio.h>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
 
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main()
{
    int d;
    scanf("%d",&d);
    printf("Christmas");
    REP(i,25-d)printf(" Eve");
    printf("\n");
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int a[1000], b[1000], n, q;
void riffle_shuffle() {
	for (int i = 0 * n + 1; i <= 2 * n; i += 1) { b[i] = a[i]; }
	for (int i = 0 * n + 1; i <= 1 * n; i += 1) { a[i * 2 - 1] = b[i]; }
	for (int i = 1 * n + 1; i <= 2 * n; i += 1) { a[(i - n) * 2] = b[i]; }
}
void cuts(int k) {
	int c1 = 1;
	for (int i = 1; i <= 2 * n; i++) { b[i] = a[i]; }
	for (int i = k + 1; i <= 2 * n; i++) { a[c1] = b[i]; c1++; }
	for (int i = 1; i <= k; i++) { a[c1] = b[i]; c1++; }
}
int main() {
	cin >> n >> q;
	for (int i = 1; i <= 2 * n; i++)a[i] = i;
	for (int i = 0; i < q; i++) {
		int r; cin >> r;
		if (r == 0)riffle_shuffle();
		if (r >= 1)cuts(r);
	}
	for (int i = 1; i <= 2 * n; i++)cout << a[i] << endl;
	return 0;
}

Measured memory_bytes: 3084
def main():
    N, M = map(int, input().split())

    t = [-1] * N
    for _ in range(M):
        s, c = map(int, input().split())
        s -= 1
        if t[s] != -1 and t[s] != c:
            print(-1)
            exit()
        t[s] = c
        
    if N != 1:
        if t[0] == 0:
            print(-1)
            exit()
        
        if t[0] == -1:
            t[0] = 1

        for i in range(1, N):
            if t[i] == -1:
                t[i] = 0
    else:
        if t[0] == -1:
            t[0] = 0
    
    print(''.join(map(str,t)))

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
N = int(input())
C0 = 0
C1 = 0
C2 = 0
C3 = 0
for i in range(N):
  result = input()
  if result == "AC":
    C0 += 1
  elif result == "WA":
    C1 += 1
  elif result == "TLE":
    C2 += 1
  else:
    C3 += 1
    
print("AC x", C0)
print("WA x", C1)
print("TLE x", C2)
print("RE x", C3)

Measured memory_bytes: 9104
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
static const int INF = 1<<29;

int gcd(int a, int b){
  if(a % b == 0) return b;
  else return gcd(b, a%b);
}

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int b = a[0];
  for (int i = 1; i < n; i++){
    b = gcd(b, a[i]);
  }
  cout << b << endl;
}

Measured memory_bytes: 640
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    public static void Main()
    {
	int[] tmp = ReadIntArray();
	int n = tmp[0], w = tmp[1];

	int[] weight = new int[n];
	int[] v = new int[n];
	
	for (int i = 0; i < n; i++)
	{
	    tmp = ReadIntArray();
	    weight[i] = tmp[0];  v[i] = tmp[1];
	}
	
	long[,] dp = new long[n+1, w+1];

	// DP loop
	for (int i = 0; i < n; i++)
	{
	    for (int ww = 0; ww <= w; ww++)
	    {
		// when choosing the item #i
		if (ww  >= weight[i])
		    dp[i+1, ww] =
			Math.Max(dp[i+1, ww], dp[i, ww - weight[i]] + v[i]);

		// when not choosing it
		dp[i+1, ww] = Math.Max(dp[i+1, ww], dp[i,ww]);
		
	    }
       
	}

	WriteLine(dp[n, w]);
    }
}


Measured memory_bytes: 89824
#include<bits/stdc++.h>
#define int long long
#define P pair<int,int>
#define PP pair<P,int>
#define F first
#define S second
#define f(i,n) for(int i=0;i<(n);i++)
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define mod (int)(1000000007)
#define pie 3.141592653589793238462643383279
#define Bpri priority_queue
#define Spri priority_queue<P,vector<P>,greater<P>>
using namespace std;
int x[500],y[500],z[500];
signed main(){
	int n;
	cin>>n;
	f(i,n-1)cin>>x[i]>>y[i]>>z[i];
	f(i,n){
		int ans=0;
		for(int j=i;j<n-1;j++){
			ans=max(y[j]+x[j],(ans+z[j]-1)/z[j]*z[j]+x[j]);
		}
		cout<<ans<<endl;
	}
}


Measured memory_bytes: 256
using System;
using System.Linq;
public class Hello{
    static long XOR(long n){
        switch(n % 4){
            case 0:
            return n;
            break;
            case 1:
            return 1;
            break;
            case 2:
            return n + 1;
            break;
            default:
            return 0;
            break;
        }
    }
    public static void Main(){
        var line = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var A = line[0];
        var B = line[1];
        
        Console.WriteLine(XOR(A - 1) ^ XOR(B));
        
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
#define int int64_t
#define REP(i, n) for (int i = 0; (i) < (int)(n); ++ (i))
#define REP3(i, m, n) for (int i = (m); (i) < (int)(n); ++ (i))
#define REP_R(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define REP3R(i, m, n) for (int i = (int)(n) - 1; (i) >= (int)(m); -- (i))
#define REPP(i, n) for (int i = 1; (i) < (int)(n+1); ++ (i))
#define REPR(i, n) for (int i = (int)(n) - 1; (i) >= 0; -- (i))
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, m, n) for(int i=(m)-1; i>=(n); i--)
#define ALL(v) v.begin(), v.end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define SORTR(c) sort((c).begin(),(c).end(),greater<int>());
#define BIT(n) (1LL<<(n))
#define PCNT(x) __builtin_popcountll(x)
#define GCD(x,y) __gcd(x,y)
#define LCM(x,y) x/__gcd(x,y)*y
#define PB push_back
#define MP make_pair
#define endl "\n"
#define pa cout << ans << endl
#define p(x) cout << x << endl
#define pall(x) for(auto iter : x) p(iter)
#define yes cout << "Yes" << endl
#define no cout << "No" << endl
#define yn(x) cout << (x ? "Yes" : "No") << endl
using namespace std;
using Graph = vector<vector<int> >;
using WeightedGraph = vector<vector<pair<int, int> > >;
typedef long double LD;
typedef vector<int> VI;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const int INF = 2000000000;
const long double PI = acosl(-1);
const int MOD = 1000000007;


signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    int A, B;
    cin >> A >> B;


    int ans = 0;
    p(A*B);
    

    
    
    return 0;
}

/*
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_a && sh test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_a && sh etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_a && sh submit_cpp.sh
*/
/*
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_a && sh test_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_a && sh etest_cpp.sh
cd ~/Desktop/Programming/AtCoder/contest/abc169/abc169_a && sh submit_cpp.sh
*/


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

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

typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(void){
    //消えるたびに上から落としていけばいい
    int H;
    while(true){
        cin >> H;
        if(H == 0) break;
        vector<vector<int>> grid(H);
        rep(i, H) grid[i].resize(5);
        rep(i, H) rep(j, 5) cin >> grid[i][j];
        bool cont = true;
        int score = 0;
        while(cont){
            cont = false;
            rep(i, H){
                rep(j, 3){
                    if(grid[i][j] != -1 && grid[i][j] == grid[i][j+1] && grid[i][j] == grid[i][j+2]){
                        if(j <= 1 && grid[i][j] == grid[i][j+3]){
                            if(j == 0 && grid[i][j] == grid[i][j+4]){
                                score += grid[i][j]*5;
                                for(int k = i; k >= 0; k--){
                                    if(k == 0) rep(l, 5) grid[0][l] = -1;
                                    else rep(l, 5) grid[k][l] = grid[k-1][l];
                                }
                            }
                            else{
                                score += grid[i][j]*4;
                                for(int k = i; k >= 0; k--){
                                    if(k == 0) for(int l = j; l < j+4; l++) grid[0][l] = -1;
                                    else for(int l = j; l < j+4; l++) grid[k][l] = grid[k-1][l];
                                }
                            }
                        }
                        else{
                            score += grid[i][j]*3;
                            for(int k = i; k >= 0; k--){
                                if(k == 0) for(int l = j; l < j+3; l++) grid[0][l] = -1;
                                else for(int l = j; l < j+3; l++) grid[k][l] = grid[k-1][l];
                            }
                        }
                        cont = true;
                        break; //同じ行で二個以上の消滅は無い
                    }
                }
            }
        }
        cout << score << endl;
    }
    return 0;
}


Measured memory_bytes: 3104
#include<string>
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x) - 1 * 100);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define mp make_pair
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>

using namespace std;
int n, m;
int s[100];
int main(void) {
	cin >> n;
	int sum = 0;
	rep(i, n) {
		cin >> s[i];
		sum+= s[i];

	}
	if (sum % 10 == 0) {
		sort(s, s + n);
		int mn = 0;
		rep(i, n) {
			if (s[i] % 10) {
				mn = s[i];
				cout << sum - mn << endl;
				return 0;
			}

		}
		sum = 0;
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import deque
n,m = map(int, input().strip().split())
to = [[] for _ in range(n)]
 
for _ in range(m):
    a,b = map(int, input().strip().split())
    to[a-1].append(b-1)
    to[b-1].append(a-1)
 
q=deque([0,])
ans=[None]*n
while q:
    cur=q.popleft()
    for nxt in to[cur]:
        if ans[nxt] is not None: # visited
            continue
        ans[nxt]=cur+1
        q.append(nxt)
 
print("Yes")
print(*ans[1:])

Measured memory_bytes: 38144
#pragma region // {{{ by unolight
#include <bits/stdc++.h>
#include <unistd.h>
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wunused-function"
#define SZ(x) ((int)(x).size())
#define ALL(x) begin(x),end(x)
#define RALL(x) rbegin(x),rend(x)
#define REP(i,n) for ( int i=0; i<int(n); i++ )
#define REP1(i,a,b) for ( int i=(a); i<=int(b); i++ )
#define MP make_pair
#define PB push_back
using namespace std;
typedef int64_t LL;
typedef pair<int,int> PII;
typedef vector<int> VI;

namespace { namespace unolight {
// Read Input
template<class T> void _R( T &x ) { cin>>x; }
void _R( int &x ) { scanf("%d",&x); }
void _R( int64_t &x ) { scanf("%" PRId64,&x); }
void _R( double &x ) { scanf("%lf",&x); }
void _R( char &x ) { scanf(" %c",&x); }
void _R( char *x ) { scanf("%s",x); }
void R() {}
template<class T, class... U> void R( T& head, U&... tail ) { _R(head); R(tail...); }
// Write Output
template<class T> void _W( const T &x ) { cout<<x; }
void _W( const int &x ) { printf("%d",x); }
void _W( const int64_t &x ) { printf("%" PRId64,x); }
void _W( const double &x ) { printf("%.16f\n",x); }
void _W( const char &x ) { putchar(x); }
void _W( const char *x ) { printf("%s",x); }
template<class T> void _W( const vector<T> &x ) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W( const T& head, const U&... tail ) { _W(head); putchar(sizeof...(tail)?' ':'\n'); W(tail...); }

#ifdef UNOLIGHT
#include "dump.hpp"
#else
#define dump(...)
#endif

template<class T> inline bool chmax( T &a, const T &b ) { return b>a ? a=b,true : false; }
template<class T> inline bool chmin( T &a, const T &b ) { return b<a ? a=b,true : false; }
template<class T> using MaxHeap = priority_queue<T>;
template<class T> using MinHeap = priority_queue<T, vector<T>, greater<T>>;
template<class T, class F=less<T>> void sort_uniq( vector<T> &v, F f=F() ) {
    sort(begin(v),end(v),f);
    v.resize(unique(begin(v),end(v))-begin(v));
}
#pragma endregion // }}}


void main() {
    int n,k;
    R(n,k);
    VI a(n), b(n);
    REP(i,n) R(a[i],b[i]);
    k++;
    LL ans=0;
    int cant=0;
    for ( int t=30; ~t; t-- ) {
        LL cur=0;
        if ( k>>t&1 ) {
            cant^=(1<<t);
            REP(i,n) if ( (cant&a[i])==0 ) cur+=b[i];
            cant^=(1<<t);
        } else {
            cant^=(1<<t);
        }
        chmax(ans,cur);
    }
    W(ans);
}

}} // {{{ main
int main() { unolight::main(); return 0; }
// }}}


Measured memory_bytes: 4084
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

void map_add(map<int,int> & mp, int A)
{
  auto itr = mp.find(A);
  if(itr != mp.end())
  {
    itr->second++;
  }
  else
  {
    mp[A] = 1;
  }
  return;
}
void solve(void)
{
  char A,B;
  cin>>A>>B;
  if(A == B)
  {
    cout<<"H"<<endl;
  }
  else
  {
    cout<<"D"<<endl;
  }
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
vector<int> v1,v2,v3,vet;
int n,m,k,t;

main(){
  cin >> n >> m >> k >> t;
  v1.resize(n);
  v2.resize(m);
  v3.resize(k);
  vector<int> veto;
  for(int i= 0;i<n;i++) cin >> v1[i];
  for(int i= 0;i<m;i++) cin >> v2[i];
  for(int i =0 ;i<k;i++) cin >> v3[i];
  sort(v3.begin(),v3.end(),greater<int>());
  for(int i= 0;i<n;i++)
    for(int j =0;j<m;j++)
      	vet.push_back(v1[i]+v2[j]);
	sort(vet.begin(),vet.end(),greater<int>());
  for(int i =0 ;i<min(t,(int)vet.size());i++){
    for(int j = 0;j<k;j++)
      	veto.push_back(vet[i]+v3[j]);  
  }
  sort(veto.begin(),veto.end(),greater<int>());
  for(int i =0 ;i<t;i++)
    	cout<<veto[i]<<"\n";
  
}

Measured memory_bytes: 43060
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
namespace io{
    const int L = (1 << 20) + 1;
     
    char buf[L], *S , *T, c;
      
    char getchar() {
        if(S == T) {
            T = (S = buf) + fread(buf, 1, L, stdin);
            return (S == T ? EOF : *S++);
        }
        return *S++;
    }
     
    int inp() {
        int x = 0, f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    ll inp_ll() {
        ll x = 0; int f = 1; char ch;
        for(ch = getchar(); !isdigit(ch); ch = getchar())
            if(ch == '-') f = -1;
        for(; isdigit(ch); x = x * 10 + ch - '0', ch = getchar());
        return x * f;
    }
     
    char B[25], *outs=B+20, *outr=B+20;
    template<class T>
    inline void print(register T a,register char x=0){
        if(x) *--outs = x, x = 0;
         
        if(!a)*--outs = '0';
        else
            while(a)
                *--outs = (a % 10) + 48, a /= 10;
         
        if(x)
            *--outs = x;
         
        fwrite(outs, outr - outs , 1, stdout);
        outs = outr;
    }
};
  
using io :: print;
using io :: inp;
using io :: inp_ll;
const int INF = 1e9 ;
const int maxN = 1e6 + 10; 

int a[maxN];
double b[maxN];
int n,T,A;
int main()
{
	n = inp();
	T = inp();
	A = inp();
	for(int i=1;i<=n;i++)	
	{
		a[i] = inp();
	}

	int flag;
	double minf = 1.0*INF/1.0;
	for(int i=1;i<=n;i++)
	{
		double tmp = - a[i]*0.006 + T;
		b[i] = abs(A - tmp);
		if(b[i] < minf)
		{
			minf = b[i];
			flag = i;
		}
	}
	printf("%d\n",flag);
    return 0;
}

Measured memory_bytes: 4352
fun main(args:Array<String>):Unit {
    val n = readLine()!!.trim().toInt()
    val metronome = Array(n){readLine()!!.toInt()}.sortedArray()
    val fact = factor(metronome.last())
    println(metronome.sumBy{
        val num = fact[fact.upperBound(it)]
        num - it
    })
}
fun <T> Array<T>.upperBound(factor:T):Int {
    val idx = this.binarySearch(factor)
    return if (idx < 0) -idx - 1
    else idx
}
fun factor(num:Int):Array<Int> {
    return (1 .. num).filter{num % it == 0}.toTypedArray()
}


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

int main(){
    int n;
    cin >> n;
    vector<int> a;
    int b;
    for(int i=0; i<n; i++){
        cin >> b;
        a.push_back(b);
    }
    int max = *max_element(a.begin(),a.end());
    int min = *min_element(a.begin(),a.end());
    int ans = max - min;
    cout << ans << endl;
}

Measured memory_bytes: 256
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
import itertools

def main():
    a,b,c,x,y = map(int, input().split())
    num = max(x,y)
    ans = INF
    for i in range(0,num*2+1,2): # cをi枚買うとする
        half = i//2
        c_cst = i*c
        a_cst = max(x-half,0)*a
        b_cst = max(y-half,0)*b
        ans = min(ans,(c_cst+a_cst+b_cst))
    print(ans)



if __name__=="__main__":
    main()


Measured memory_bytes: 69984
s=input()
n=len(s)
ans=0
for i in range(2**(n-1)):
  S=format(i,"12b")
  A=[0]
  for j in range(1,n):
    if S[-j]=="1":
      A.append(j)
  A.append(n)
  for j in range(len(A)-1):
    ans=ans+int(s[A[j]:A[j+1]])
print(ans)

Measured memory_bytes: 3064
def main():
    N,K = map(int, input().split())
    R,S,P = map(int, input().split())
    T = list(input())
    score=0
    for i in range(N):
        if T[i] == 'r':
            score+=P
            if i+K<N and T[i+K]=='r':
                T[i+K]='x'
        if T[i]=='s':
            score+=R
            if i+K<N and T[i+K]=='s':
                T[i+K]='x'
        if T[i]=='p':
            score+=S
            if i+K<N and T[i+K]=='p':
                T[i+K]='x'
    print(score)







if __name__ == '__main__':
    main()

Measured memory_bytes: 77620
import sys
input = sys.stdin.readline
def main():
  from collections import deque
  from collections import defaultdict
  n=int(input())
  ab=[list(map(int,input().split())) for _ in range(n-1)]
  g=[[] for _ in range(n)]
  for i,abi in enumerate(ab):
    a,b=abi
    g[b-1].append(a-1)
    g[a-1].append(b-1)
  todo=deque([(0,-1)])
  dc={}
  while len(todo)>0:
    a,pc=todo.popleft()
    l=g[a]
    c=0
    for li in l:
      d,e=min(a,li),max(a,li)
      if (d,e) not in dc:
        c+=1 if c+1!=pc else 2
        dc[(d,e)]=c
        todo.append([li,c])
  print(max(dc.values()))
  for a,b in ab:
    print(dc[(a-1,b-1)])
if __name__=='__main__':
  main()


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

using std::cerr;
using std::cin;
using std::cout;

using std::abs;
using std::min;
using std::max;
using std::swap;

using std::map;
using std::pair;
using std::set;
using std::string;
using std::vector;

using ll = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define ff first
#define ss second
#define pb emplace_back
template<typename T> 
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h <<"\n"; 
}
template<typename T, typename... Ts>
void _dbg(const char* _s, T _h, Ts... _t) {
    int _b = 0;
    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++; 
    cerr << " = " << _h << ","; 
    _dbg(_s+1, _t...);
}
#ifdef LOCAL
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...) 
#endif

struct init {
    init() {
        cin.tie(0); 
        std::iostream::sync_with_stdio(0);
        cout << std::fixed << std::setprecision(10);
        cerr << std::fixed << std::setprecision(5);
        #ifdef LOCAL
        srand(300); 
        #else
        using namespace std::chrono;
        srand(duration_cast<nanoseconds>(high_resolution_clock::now().time_since_epoch()).count()); 
        #endif
    }
    ~init() {
        #ifdef LOCAL
        cerr << "Time elapsed: " << (double)clock() / CLOCKS_PER_SEC << "s.\n";
        #endif
    }
} init;

const int MAXN = 1e5 + 1;
ll a[MAXN];

void no() {
    cout << "-1\n";
    exit(0);
}

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

    if (a[n - 1] > 2) no();

    ll mn = 2, mx = 2;
    for (int i = n - 1; i > 0; --i) {
        dbg(mn, mx);
        mn = (mn + a[i - 1] - 1) / a[i - 1] * a[i - 1];
        mx = (mx + a[i] - 1) / a[i - 1] * a[i - 1];
        if (mn > mx) no();
    }

    mx += a[0] - 1;

    if (mn > mx) no();
    cout << mn << ' ' << mx << '\n';
    
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
int next[9][4] = {
  {0,1,0,3},
  {0,2,1,4},
  {1,2,2,5},
  {3,4,0,6},
  {3,5,1,7},
  {4,5,2,8},
  {6,7,3,6},
  {6,8,4,7},
  {7,8,5,8}
};
int n;
int s,t,b;
char s_,t_,b_;
int main(){
  while(cin>>n,n){
    cin>>s_>>t_>>b_;
    s = s_-'A';
    t = t_-'A';
    b = b_-'A';
    double dp[20][10] = {};
    dp[0][s] = 1;
    REP(time,n)REP(place,9)REP(r,4){
      int next_place = next[place][r];
      if(next_place == b) next_place = place;
      dp[time+1][next_place] += dp[time][place] * 0.25;
    }
    cout<<dp[n][t]<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include <vector>
using namespace std;
class carditem{
public:
	char suits;	//???????????????'S'???????????????'H'???????????????'C'???????????????'D'
	int value;	//0???9
	int index;
	void setIndex() {
		index = g_index++;
	}
private:
	static int g_index;
};
int carditem::g_index = 0;

void InputCard(std::vector<carditem> & a) {
	int n;
	cin >> n;
	a.resize(n);
	for(int i=0;i<n;++i) {
		string s;
		cin >> s;
		carditem & card = a.at(i);
		card.setIndex();
		card.suits = s.at(0);
		card.value= s.at(1) - '0';
	}
}
void Printf(std::vector<carditem> & a) {
	for(int i=0;i<(int)a.size();++i) {
		if (i>0){ 
			cout << " ";
		}
		carditem & card = a.at(i);
		cout  << card.suits << card.value;
	}
	cout << std::endl;
}
bool isStable(std::vector<carditem> & a) {
	for(int i=0,j;i<(int)a.size();++i) {
		if (i==0 || a.at(j).value != a.at(i).value){
			j = i;
		} else if (a.at(j).index > a.at(i).index){
			return	false;
		}
	}
	return true;
}
template<class T>
void BubbleSort(std::vector<T> & A,int & swaptimes)
{
	for(int i=0;i<(int)A.size();i++){
		for(int j=(int)A.size()-1;j>i;--j){
			if (A[j].value < A[j-1].value) {
				T tmp = A[j];
				A[j] = A[j-1];
				A[j-1]=tmp;
				swaptimes++;
			}
		}
	}
}
template<class T>
void SelectionSort(std::vector<T> & A,int & swaptimes)
{
	for(int i=0;i<(int)A.size();++i){
		int mini=i;
		for(int j=i;j<(int)A.size();++j){
			if (A[j].value < A[mini].value) {
				mini = j;
			}
		}
		if (mini != i) {
			T tmp = A[mini];
			A[mini] = A[i];
			A[i]=tmp;
			swaptimes++;
		}
	}
}

int main(){
	std::vector<carditem> A,B;
	::InputCard(A);
	B.resize(A.size());
	copy(A.begin(),A.end(),B.begin());
	int swaptimes=0;
	::BubbleSort(A,swaptimes);
	::Printf(A);
	bool isstable = ::isStable(A);
	cout  << (isstable ? "Stable" : "Not stable") << std::endl;

	swaptimes=0;
	::SelectionSort(B,swaptimes);
	::Printf(B);
	isstable = isStable(B);
	cout  << (isstable ? "Stable" : "Not stable") << std::endl;
}

Measured memory_bytes: 1228