akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DerivingVia #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE UndecidableInstances #-}

module Main where

import Control.Category hiding (id, (.))
import Control.Monad
import Control.Monad.State.Strict
import qualified Data.ByteString.Char8 as BS
import Data.IORef
import Data.List as List
import Data.Maybe
import Data.Set as Set
import qualified Data.Vector.Unboxing as U
import qualified Data.Vector.Unboxing.Mutable as UM
import GHC.Generics

readInt :: BS.ByteString -> Int
readInt = fst . fromJust . BS.readInt

readIntList :: BS.ByteString -> [Int]
readIntList = Prelude.map readInt . BS.words

getInt :: IO Int
getInt = readInt <$> BS.getLine

getIntList :: IO [Int]
getIntList = readIntList <$> BS.getLine

-- data Point = Pt {-# UNPACK #-} Int {-# UNPACK #-} Int
--   deriving (Generic)
--   deriving (U.Unboxable) via U.Generics Point

-- ptX :: Point -> Int
-- ptX (Pt x y) = x

-- ptY :: Point -> Int
-- ptY (Pt x y) = y

data Item = Item
  { price :: {-# UNPACK #-} Int,
    idx :: {-# UNPACK #-} Int
  }
  deriving (Eq)

instance Ord Item where
  compare item0 item1 = compare (price item0) (price item1) <> compare (idx item0) (idx item1)

divideItem :: Item -> Item
divideItem item = item {price = price item `div` 2}

divideItems :: Set Item -> Set Item
divideItems s = Set.insert (divideItem . findMax $ s) . deleteMax $ s

sumItems :: Set Item -> Int
sumItems = sum . fmap price . toList

main :: IO ()
main = do
  [n, m] <- getIntList
  as <- getIntList
  let items0 = Set.fromList . fmap (\(idx, a) -> Item {price = a, idx = idx}) $ zip [0 ..] as
      items1 = List.foldl' (\items _ -> divideItems items) items0 [1 .. m]
  print . sumItems $ items1


Measured memory_bytes: 25068
#include <stdio.h>

int
main(void)
{
	char line[80];

	int b[10];

	int n;

	if (fgets(line, sizeof line, stdin) == NULL) {
		return 0;
	}
	if (sscanf(line, "%d", &n) != 1) {
		return 0;
	}

	while (n--) {
		fgets(line, sizeof line, stdin);
		sscanf(line, "%d %d %d %d %d %d %d %d %d %d",
			   &(b[0]), &(b[1]), &(b[2]), &(b[3]), &(b[4]), &(b[5]),
			   &(b[6]), &(b[7]), &(b[7]), &(b[9]));

		bool f = true;
		int s0 = 0;
		int s1 = 0;
		for (int t : b) {
			if (t > s0 && t > s1) {
				if (t - s0 <= t - s1) {
					s0 = t;
				} else {
					s1 = t;
				}
			} else 	if (t > s0) {
				s0 = t;
			} else 	if (t > s1) {
				s1 = t;
			} else {
				f = false;
				break;
			}
		}
		printf("%s\n", (f ? "YES" : "NO"));
	}

	return 0;
}

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

using namespace std;
 
#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

typedef int64_t ll; typedef vector<int> VI; typedef pair<ll,ll> pii;
const int MD = 1e9+7; typedef vector<ll> VL;

void dbg(){ cerr << "\n"; }  
template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }



int main()
{
	
	cin.tie(0); ios_base::sync_with_stdio(false);
	int h,w;
	cin >>h >>w;
	vector<VI> ba(h, VI(w));
	rep(i, h) rep(j, w) cin >>ba[i][j];
	vector<VI> ans;
	rep(i, h) rep(j, w-1){
		if(ba[i][j] &1){
			ba[i][j+1]++;ba[i][j]--;
			ans.push_back(VI{i, j, i, j+1});
		}
	}
	rep(i, h-1){
		if(ba[i][w-1] &1){
			ba[i][w-1]++;ba[i+1][w-1]--;
			ans.push_back(VI{i, w-1, i+1, w-1});
		}
	}
	cout <<sz(ans) <<"\n";
	for(auto x: ans){
		cout <<x[0]+1 <<" "<<x[1]+1<<" "<<x[2]+1<<" "<<x[3]+1<<"\n";
	}
	return 0;
}


Measured memory_bytes: 10032
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
 
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)

const ll mod = 1000000007;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

void solve(){
	
	ll m = 2019;
	string s;
	ll a[m+10];
	mem(a,0);
	cin >> s;
	ll pw = 1;
	ll ans =0;
	ll suf = 0;
	a[0]++;
	for(ll i = s.length()-1; i >= 0; i--){
		suf += (s[i]-'0')*pw;
		suf %= m;
		pw *= 10;
		pw %= m;
		ans += a[suf];
		a[suf]++;
	}
	cout << ans;
	return;
}


int main() {
   
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    	//printf("Case %lld: ",++CT);
		solve();
	}
    
    return 0;
}


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

using namespace std;

template<typename T> void cmax(T &x, const T &y)
{
	if(y > x) x = y;
}

template<typename T> void read(T &x)
{
	x = 0;
	char c = getchar();
	bool f = 0;
	while(!isdigit(c) && c!='-') c = getchar();
	if(c == '-') f = 1, c = getchar();
	while(isdigit(c)) x = x*10+c-'0', c = getchar();
	if(f) x = -x;
}

string calca(string s)
{
	vector<int> pa, pb;
	string ret;
	for(int i=0; i<s.length(); i++)
		if(s[i] == 'a') pa.push_back(i);
		else pb.push_back(i);
	int lst = -1;
	for(int i=0; i<pa.size(); i++)
		if(pa[i] > lst) ret += "ab", lst = pb[i];
	return ret;
}

string calcb(string s)
{
	vector<int> pa, pb;
	string ret;
	for(int i=0; i<s.length(); i++)
		if(s[i] == 'a') pa.push_back(i);
		else pb.push_back(i);
	for(int i=0; i<pa.size(); i++)
	{
		string cur;
		auto ia = pa.begin()+i, ib = pb.begin()+i;
		while(ia!=pa.end() && ib!=pb.end())
			if(*ia < *ib) cur.push_back('a'), ia++;
			else cur.push_back('b'), ib++;
		while(ia != pa.end()) cur.push_back('a'), ia++;
		while(ib != pb.end()) cur.push_back('b'), ib++;
		cmax(ret, cur);
	}
	return ret;
}

int main()
{
	int n;
	string str;
	read(n);
	cin >> str;
	int sum = 0;
	string cur, nxt;
	vector<string> ans;
	for(auto c : str)
	{
		if(c == 'a') sum--;
		else sum++;
		cur.push_back(c);
		if(sum == 0)
		{
			if(*cur.begin() == 'a') nxt = calca(cur);
			else nxt = calcb(cur);
			while(ans.size())
			{
				bool greater = 0;
				for(int i=0; i<min(nxt.length(), ans.back().length()); i++)
					if(nxt[i] != ans.back()[i])
					{
						if(ans.back()[i] < nxt[i]) greater = 1;
						break;
					}
				if(greater) ans.pop_back();
				else break;
			}
			ans.push_back(nxt);
			cur.clear();
		}
	}
	for(auto i : ans) cout << i;
	cout << endl;
	return 0;
}

Measured memory_bytes: 384
import           Control.Applicative
import           Data.Bool

main :: IO ()
main = do
  n <- readLn
  xs <- map read.words <$> getLine
  putStrLn.bool"NO""YES" $ solve n xs

solve :: Int -> [Int] -> Bool
solve n xs = r == 0 && map(flip rem n)ys == [rem(y+rem(i*m)n)n|i<-[0..n-1]]
  where
    s = n*(n+1)`div`2
    (m, r) = sum xs `divMod` s
    ys@(y:_) = map (subtract m) xs

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

int main()
{
  int a;
  string s;
  cin >> a;
  cin >> s;

  if(a >= 3200) cout << s << endl;
  else cout << "red" << endl;
  
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N, K; cin >> N >> K;

	int cnt[200005]; memset(cnt,0,sizeof(cnt));
	int kind = 0;

	for (int i = 0;i < N;i++){
		int A; cin >> A;
		if(cnt[A] == 0) kind++;
		cnt[A]++;
	}

	sort(cnt,cnt+200005);

	int idx = 0;

	while(cnt[idx] == 0) idx++;
	int ans = 0;

	for (int i = 0;i < kind-K;i++){
		ans += cnt[idx];
		idx++;
	}

	cout << ans << endl;

	return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

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

	int a, b, m;
	cin >> a >> b >> m;
	vector<int> f(a);
	vector<int> s(b);
	for (auto &t : f) cin >> t;
	for (auto &t : s) cin >> t;
	int ans = *min_element(f.begin(), f.end()) + *min_element(s.begin(), s.end());
	while (m--) {
		int kek, lol, c;
		cin >> kek >> lol >> c;
		ans = min(ans, f[kek - 1] + s[lol - 1] - c);
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
using namespace std;
int N;
long double ans = 0;
void permutation(vector<int> perm, vector<long double> &X, vector<long double> &Y) {
    int S = perm.size();
    do {
        for (int i = 0; i < S - 1; ++i) {
            ans += sqrt(powl(X[perm[i] - 1] - X[perm[i + 1] - 1], 2.0) + powl(Y[perm[i] - 1] - Y[perm[i + 1] - 1], 2.0));
        }
    } while (next_permutation(perm.begin(), perm.end()));
    return ;
}
int main() {
    cin >> N;
    vector<long double> X(N, 0);
    vector<long double> Y(N, 0);
    vector<int> vec(N, 0);
    long double MX = 1.0;
    for (int i = 1; i <= N; ++i) {
        MX *= i;
        vec[i - 1] = i;
    }
    for (int i = 0; i < N; ++i) {
        cin >> X[i] >> Y[i];
    }
    permutation(vec, X, Y);
    cout << fixed << setprecision(10) << ans / MX << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
using namespace std;
typedef long long int lli;
typedef pair<lli, lli> pll;
const int inf = 1e9;

int main(){
	lli n,d,a;
	cin >> n >> d >> a;
	vector<pll> xh(n);
	for(int i=0; i<n; i++){
		lli x,h;
		cin >> x >> h;
		h = (h+a-1)/a;
		xh[i] = pll(x,h);
	}
	sort(xh.begin(), xh.end());

	queue<pll> wait;
	lli curr = 0;
	lli ans = 0;
	for(int i=0; i<n; i++){
		//cout << i << " " << ans << " " << curr << endl;
		while(!wait.empty() and wait.front().first<xh[i].first){
			curr -= wait.front().second;
			wait.pop();
		}
		if(xh[i].second <= curr) continue;
		lli num = xh[i].second -curr;
		ans += num;
		curr += num;
		wait.push(pll(xh[i].first+2*d, num));
	}
	cout << ans << endl;
	return 0;
}

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

int main(int argc, const char *argv[])
{
    string S;
    cin >> S;
    bool n, s, e, w;
    n = s = e = w = false;
    for (int i = 0; i < S.length(); i++)
    {
        switch (S[i])
        {
        case 'N':
            n = true;
            break;
        case 'W':
            w = true;
            break;
        case 'S':
            s = true;
            break;
        case 'E':
            e = true;
            break;
        }
    }

    if (n && s && w && e || !n && !s && !w && !e)
    {
        cout << "Yes" << endl;
    }
    else if (n && s && !w && !e || !n && !s && w && e)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
main(){
  while(1){
    int T,N,s,f,sum=0;
    scanf("%d",&T);
    if(T==0) break;
    scanf("%d",&N);
    for(int i=0;i<N;i++){
      scanf("%d %d",&s,&f);
      sum+=(f-s);
    }
    if(sum>=T) puts("OK");
    else printf("%d\n",T-sum);
  }
}

Measured memory_bytes: 1196
#include<stdio.h>
int main()
{
    int b[100],i,e=0,f=0,c;
    float avg,d,s=0,a;
    scanf("%f",&a);
    for(i=0;i<a;i++)
    {
        scanf("%d",&b[i]);
        s=s+b[i];
    }
    avg=s/a;
    c=s/a;
    d=(avg-c);
    if(d>=.5)
    {
        for(i=0;i<a;i++)
        {
            e=e+abs(b[i]-(c+1))*abs(b[i]-(c+1));
        }
        printf("%d",e);
    }
    if(d<.5)
    {
        for(i=0;i<a;i++)
        {
           f=f+abs(b[i]-c)*abs(b[i]-c);
        }
        printf("%d",f);
    }
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-


def main():
    """Function."""
    x = int(input())

    max_val = 0
    min_diff = 1000
    for i in range(1, 32):
        for j in range(2, 10):
            temp = i ** j
            if temp > x:
                break
            else:
                temp_dif = x - temp
                if temp_dif < min_diff:
                    min_diff = temp_dif
                    max_val = temp

    print(max_val)


if __name__ == "__main__":
    main()


Measured memory_bytes: 2940
H, W = map(int, input().split())
S = [list(input()) for _ in range(H)]


def bfs():
    q = [(0, 0, 1)]
    m = []
    while len(q) > 0:
        x, y, c = q.pop(0)
        for xx, yy in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
            if (H, W) == (yy + 1, xx + 1):
                return c + 1
            if 0 <= yy < H and 0 <= xx < W and S[yy][xx] == '.' and \
                    (xx, yy) not in m:
                m.append((xx, yy))
                q.append((xx, yy, c + 1))
    return -1


def main():
    dc = 0
    for i in range(H):
        for j in range(W):
            if S[i][j] == '.':
                dc += 1
    c = bfs()
    if c == -1:
        print(-1)
    else:
        print(dc - c)


main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define ull unsigned long long int 
#define pb push_back
#define xx first
#define yy second
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ull t;
	t=1;
	while(t--)
	{
		ll n,i;
		cin>>n;
		
		ll a[n],b[n];
		
		for(i=0;i<n;i++)
		{
			cin>>a[i]>>b[i];
		}
		
		for(i=0;i<=n-3;i++)
		{
			if(a[i]==b[i] && a[i+1]==b[i+1] && a[i+2]==b[i+2])
			{
				cout<<"Yes";
				return 0;	
			}	
		}
		cout<<"No";
	}
}

Measured memory_bytes: 3620
const main = (input) => {
  const args = input.trim().split("\n");
  const nums = args[1].split(" ").map((n) => BigInt(n));
  const limit = 10n ** 18n;
  const isZero = nums.filter((n) => n === 0n).length > 0;
  if (isZero) {
    console.log(0);
    return;
  }
  const multipliedValue = nums.reduce((accum, current) => {
    if (accum > limit) {
      return 0n;
    }
    return accum * current;
  });

  if (multipliedValue === 0n || multipliedValue > limit) {
    console.log(-1);
  } else {
    console.log(multipliedValue.toString());
  }
};

main(require('fs').readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 44060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,mod=1e9+7;
int n,k,tot,head[N],nex[N<<1],to[N<<1],d[N],dep[N],son[N];
bool flag;
ll ans,f[N],invf[N];
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
ll c(ll n,ll m)
{
    return f[n]*invf[n-m]%mod*invf[m]%mod;
}
void add(int u,int v)
{
    to[++tot]=v;nex[tot]=head[u];head[u]=tot;
}
void dfs1(int u,int fa,int dis)
{
    for(int i=head[u];i;i=nex[i])
        if(to[i]!=fa)
        dfs1(to[i],u,dis+1),son[u]++;
}
void dfs2(int u,int fa)
{
    if(son[u]==0||flag) return;
    int sum=k-2;
    if(u==1) sum++;
    if(sum<son[u]) {flag=true;return;}
    ans=ans*f[son[u]]%mod*c(sum,son[u])%mod;//一层一层染 
    for(int i=head[u];i;i=nex[i])
    {
        int v=to[i];
        if(v==fa) continue;
        dfs2(v,u);
    }
}
int main()
{
    f[0]=invf[0]=1;
    scanf("%d%d",&n,&k);
    for(int i=1;i<=max(n,k);i++)
        f[i]=f[i-1]*i%mod,invf[i]=qpow(f[i],mod-2);
    for(int i=1;i<n;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        add(u,v);
        add(v,u);
    }
    dfs1(1,0,1);
    ans=k;
    dfs2(1,0);
    if(flag) printf("0\n");
    else printf("%lld\n",ans);
}



Measured memory_bytes: 8320
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset

#include <math.h>
#include <stdlib.h>


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

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

//INT_MAX	2,147,483,647 = 2*1.0e9

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

  for(int i = 0; i * 7 <= N; i++){
    if((N-i*7)%4 == 0){
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define ULL unsigned long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define pi acosl(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
#define EPS 1e-4
#define arg ARG
#define cpdd const pdd
#define rank Rank
#define MAXN 205
//#define N 262144
#define ULL unsigned long long
#define ll long long
int main(){
    int n,k;
    scanf("%d %d",&n,&k);
    LL a[200005];
    for(int i = 1;i<=n;i++){
        a[i]=0;
        scanf("%lld",&a[i]);
    }
    LL d[200005];
    int ok=0;
    for(int i = 0;i<k;i++){
        int ook=1;
        fill(d,d+n+1,0);
        for(int j = 1;j<=n;j++){
            int l=max(1ll,j-a[j]);
            int r=min(n*1ll,a[j]+j);
            if(l!=1||r!=n)ook=0;
            d[l]++;
            d[r+1]--;
           // printf("%d %d\n",l,r+1);
        }
        if(ook){
            for(int j = 1;j<=n;j++){
                a[j]=n;
            }
            break;
        }
        int now=0;
        for(int j = 1;j<=n;j++){
            now+=d[j];
            a[j]=now;
        }
    }
    for(int i = 1;i<=n;i++){
        printf("%lld ",a[i]);
    }
    printf("\n");
}
/*
1000000000000000000
1000000000000000000 1 1 1 1000000000
*/


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

int main() {
	double x[2], y[2], l;
	scanf("%lf %lf %lf %lf", &x[0], &y[0], &x[1], &y[1]);
	l = hypotl(x[1] - x[0], y[1] - y[0]);
	printf("%f\n", l);
	return 0;
}


Measured memory_bytes: 2088
n,k=map(int,input().split())
d=list(map(int,input().split()))

num=[]
for i in range(10):
    if i not in d:
        num.append(i)
#print(num)
num.sort()
digit=len(str(n))
ns=str(n)

ans=''
cnt=0
while cnt<digit:

    for i in num:
        if int(ns[cnt])>i:continue
        if int(ns[cnt])==i:
            ans+=str(i)
            break
        else:
            ans+=str(i)+(digit-cnt-1)*str(num[0])
            cnt=digit
            break
    else:
        ans=str(num[0]) if num[0]!=0 else str(num[1])
        ans+=str(num[0])*digit
        cnt=digit
    cnt+=1
print(ans)

Measured memory_bytes: 3064
import sys
MAX_INT = int(10e12)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

a,b,c = IL()
if b*2 == a + c:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 38384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e9+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(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; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	int ans = 0;
	int a;
	string s;
	cin >> a >> s;

	if (3200 <= a) cout << s << endl;
	else cout << "red" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
struct Combination{
private:
    ll N;
    vector<ll> fac, facinv;

public:
    Combination(ll n){
        N = n;
        fac.push_back(1); fac.push_back(1);
        rep(i,2,N+1) fac.push_back(fac[i-1] * i % MOD);
        rep(i,0,N+1) facinv.push_back(power(fac[i], MOD-2));
    }
    ll power(ll x, ll n){
        if(n == 0) return 1LL;
        ll res = power(x * x % MOD, n/2);
        if(n % 2 == 1) res = res * x % MOD;
        return res;
    }
    ll nck(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[k] % MOD * facinv[n-k] % MOD;
    }
    ll npk(ll n, ll k){
        if(k == 0 || n == k) return 1LL;
        return fac[n] * facinv[n-k] % MOD;
    }
    ll get(ll x){return fac[x];};
    ll getinv(ll x){return facinv[x];};
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    Combination cb(100010);
    rep(i,1,K+1){
        ll ans = cb.nck(K-1,i-1);
        ll nokori = N - K - (i-1);
        if(nokori < 0){
            print(0);
            continue;
        }
        ll v = 2 + i-1;
        (ans *= cb.nck(v + nokori - 1, nokori)) %= MOD;
        print(ans);
    }

}

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

using ld = long double;
const ld eps = 1e-8, pi = acos(-1.0);

bool eq(ld a, ld b) {
	return abs(a - b) < eps;
}

using Point = complex<ld>;
class Line {
public:
	Point a, b;
};
class Circle {
public:
	Point p;
	ld r;
};

int nct(Circle c1, Circle c2) {
	int d = abs(c1.p - c2.p);
	ld r1 = max(c1.r, c2.r), r2 = min(c1.r, c2.r);
	if (d > r1 + r2 + eps) return 4;
	if (eq(d, r1 + r2)) return 3;
	if (d > r1 - r2 + eps) return 2;
	if (eq(d, r1 - r2)) return 1;
	return 0;
}

int main()
{
	ld x1, x2, y1, y2, r1, r2;
	cin >> x1 >> y1 >> r1 >> x2 >> y2 >> r2;
	Circle c1 = { (Point) { x1, y1 }, r1 };
	Circle c2 = { (Point) { x2, y2 }, r2 };
	cout << nct(c1, c2) << endl;
	return 0;
}

Measured memory_bytes: 3268
#include <bits/stdc++.h>
using namespace std;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sz(a)((int)(a).size())
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);iostream::sync_with_stdio(0);cout<<fixed<<setprecision(10);cerr<<fixed<<setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());const int D=4,dx[]={+1,0,-1,0},dy[]={0,+1,0,-1};
int f(int x){
    int res=0;
    while(x){
        res+=x%10;
        x/=10;
    }
    return res;
}
const int N=1e5;
int solve(int n){
    while(n%2==0)n/=2;
    while(n%5==0)n/=5;
    int ff=f(n);
    int ans=ff;
    if(n==1)return 1;
    // if(ff%9){
        int t=1;
        bitset<N+N> u,dp,ndp;
        forn(i,n){
            u[t]=1;
            (t*=10)%=n;
        }
        if(u[n-1]){
            upn(ans,2);
        }else{
            dp=u;
            for(int r=3;r<=18;++r){
                ndp.reset();
                forn(i,n){
                    if(u[i]){
                        ndp|=dp<<i;
                    }
                }
                ndp|=ndp>>n;
                for(int i=n;i<n+n;++i)ndp.reset(i);
                dp=ndp;
                if(dp[n-1]){
                    upn(ans,r);
                    break;
                }
            }
        }
    // }
    return ans;
}
int32_t main(){
    int n;
    cin>>n;
    cout<<solve(n)<<'\n';
    return 0;
}

Measured memory_bytes: 3804
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll mod=998244353;
ll bigmod(ll a,ll p,ll m)
{
    if(p==0)
        return 1%m;
    if(p%2!=0)
    {
        return (a*(bigmod(a,p-1,m)))%m;
    }
    else
    {
        ll x=(bigmod(a,p/2,m))%m;
        return (x*x)%m;
    }
}
int d[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    map<ll,ll> mp;
    for(int i=1; i<=n; i++)
    {
        cin>>d[i];
        mp[d[i]]++;
    }
    if(d[1]!=0 || mp[0]>1)
    {
        cout<<0<<endl;
    }
    else
    {
        bool chk=0;
        for(int i=1; i<n; i++)
        {
            if(mp[i]==0)
            {
                chk=1;
            }
            if(mp[i]>0 && chk)
            {
                cout<<0<<endl;
                return 0;
            }
        }
        ll ans=1;
        for(int i=1; i<(n-1); i++)
        {
            if((mp[i]>0))
            {
                ans=ans*(bigmod(mp[i],mp[i+1],mod));
                ans=ans%mod;
            }
            else
            {
                break;
            }
        }
        cout<<ans<<endl;

    }


    return 0;
}


Measured memory_bytes: 7040
//Bokan ga bokka--nn!!
//Daily Lunch Special Tanoshii !!
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
typedef long long ll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
#define f first
#define s second
#define rep(i,x) for(int i=0;i<x;i++)
struct bar
{
	int le,ri;
	int lev,riv;
	bar(){}
	bar(int le,int ri,int lev,int riv):
	le(le),ri(ri),lev(lev),riv(riv){}
}s[105];
ll rec(int cur)
{
	if(!cur) return 1ll;
	int lef,rig;
	lef=rec(s[cur].lev);
	rig=rec(s[cur].riv);
	ll a=1LL*lef/__gcd(lef,s[cur].ri);
	ll b=1LL*rig/__gcd(rig,s[cur].le);
	ll c=1LL*a*b/__gcd(a,b);
	return c*(s[cur].le+s[cur].ri);
}
int main()
{
	srand((unsigned int)time(NULL));
while(1)
{
	int n; scanf("%d",&n); if(!n) return 0;
	bool used[105]={};
	for(int i=1;i<=n;i++)
	{
		int a,b,c,d;
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int v=__gcd(a,b);
		a/=v; b/=v;
		s[i]=bar(a,b,c,d);
		used[c]=used[d]=true;
	}
	ll ret;
	for(int i=1;i<=n;i++)
	{
		if(!used[i])
		{
			ret=rec(i);
		}
	}
	printf("%lld\n",ret);
}
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define max(p,q)((p)>(q)?(p):(q))


//*
//遅延セグ木ここから
//↓ここを変える
typedef struct sayouso{ll k;}sayouso;
typedef struct atai{ll a;}atai;
//↑ここを変える

typedef struct node{sayouso T;atai x;}node;
node lsegN[1<<21],*lseg;
ll lsegNUM,lsegk;

//↓ここから変える
//区間add+区間max
sayouso id={0};
atai xx(atai x,atai y){
	atai ret;
	ret.a=max(x.a,y.a);
	return ret;
}
atai Tx(sayouso T,atai x){
	atai ret;
	ret.a=T.k+x.a;
	return ret;
}
sayouso TT(sayouso S,sayouso T){
	sayouso ret;
	ret.k=S.k+T.k;
	return ret;
}
sayouso fT(sayouso T,ll k){
	return T;
}
//↑ここまで変える

//要素数(2ベキ)でこれを呼ぶ
void lseguse(ll n){
	lsegNUM=n;
	lseg=lsegN+lsegNUM;
	lsegk=0;while(n/=2)lsegk++;
}
//lseg[i].xに値を与えてから初期化
void lseginit(){
	for(ll i=lsegNUM-1;i>0;i--)lsegN[i].x=xx(lsegN[2*i].x,lsegN[2*i+1].x);
	rep(i,1,2*lsegNUM)lsegN[i].T=id;
}
void lsegupdatesub(ll l,ll r,sayouso T,ll i,ll cl,ll cr,ll ck){
	//disjointなとき
	if(cr<=l||r<=cl)return;
	//完全に含むとき
	if(l<=cl&&cr<=r){
		lsegN[i].T=TT(T,lsegN[i].T);
		return;
	}
	//どちらでもないとき
	//遅延伝播
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	//再帰的に更新
	ll cm=(cl+cr)/2;
	lsegupdatesub(l,r,T,2*i  ,cl,cm,ck-1);
	lsegupdatesub(l,r,T,2*i+1,cm,cr,ck-1);
	//自身のnodeを更新
	lsegN[i].x=xx(Tx(fT(lsegN[2*i].T,ck-1),lsegN[2*i].x),Tx(fT(lsegN[2*i+1].T,ck-1),lsegN[2*i+1].x));
	lsegN[i].T=id;
}
void lsegupdate(ll l,ll r,sayouso T){lsegupdatesub(l,r,T,1,0,lsegNUM,lsegk);}
atai lsegcalcsub(ll l,ll r,ll i,ll cl,ll cr,ll ck){
	//完全に含むとき
	if(l<=cl&&cr<=r)return Tx(fT(lsegN[i].T,ck),lsegN[i].x);

	ll cm=(cl+cr)/2;
	//遅延伝播(変更はないので配るだけで良い)
	lsegN[2*i  ].T=TT(lsegN[i].T,lsegN[2*i  ].T);
	lsegN[2*i+1].T=TT(lsegN[i].T,lsegN[2*i+1].T);
	lsegN[i].x=Tx(fT(lsegN[i].T,ck),lsegN[i].x);
	lsegN[i].T=id;

	//左側だけ
	if(r<=cm)return lsegcalcsub(l,r,2*i  ,cl,cm,ck-1);
	//右側だけ
	if(cm<=l)return lsegcalcsub(l,r,2*i+1,cm,cr,ck-1);
	//両方
	return xx(lsegcalcsub(l,r,2*i,cl,cm,ck-1),lsegcalcsub(l,r,2*i+1,cm,cr,ck-1));
}
atai lsegcalc(ll l,ll r){return lsegcalcsub(l,r,1,0,lsegNUM,lsegk);}
//遅延セグ木ここまで
//*/



typedef struct interval{ll l,r,s;}I;
int c(const void*a,const void*b){
	I*p=(I*)a,*q=(I*)b;
	if((*p).r<(*q).r)return -1;
	return 1;
}

I a[200010];
int main(){
	ll n,m;
	scanf("%lld%lld",&n,&m);
	rep(i,0,m){
		ll l,r,s;
		scanf("%lld%lld%lld",&l,&r,&s);
		a[i].l=l;
		a[i].r=r;
		a[i].s=s;
	}
	qsort(a,m,sizeof(I),c);
	a[m].r=1e9;//番兵
	
	int ptr=0;
	lseguse(1<<18);
	rep(i,0,n){
		//i+1文字目を決める
		sayouso T;
		T.k=lsegcalc(0,i+1).a;
		lsegupdate(i+1,i+2,T);
		while(a[ptr].r==i+1){
			T.k=a[ptr].s;
			lsegupdate(a[ptr].l,a[ptr].r+1,T);
			ptr++;
		}
	}
	printf("%lld\n",lsegcalc(0,n+10).a);
	return 0;
}

Measured memory_bytes: 12616
#include <algorithm>
#include <iostream>
#define N 100
using namespace std;

int main(){
  int n,c[N][N];
  long long ans=0;
  cin>>n;
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++) cin>>c[i][j];
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++) ans+=min(c[i][j],c[j][i]);
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1196
//
//  main.cpp
//  Atcoder1
//
//  Created by Hamske on 2020/09/17.
//  Copyright © 2020 Author. All rights reserved.
//

#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>

using namespace std;

//#define pb push_back
//#define mp make_pair
//
//#define F first
//#define S second

typedef long long ll;

#define rept(_i,iv,n,type) for(type _i=(type)(iv);_i<(type)(n);++_i)
//#define repi(_i,iv,n) rept(_i,iv,n,int)
//#define repl(_i,iv,n) rept(_i,iv,n,ll)

#define rept0(_i,n,type) rept(_i,0,n,type)
#define repi0(_i,n) rept(_i,0,n,int)
#define repl0(_i,n) rept(_i,0,n,ll)

//#define repst(_i,iv,n,type) for(type _i=iv;_i<=(type)(n);++_i)
//#define repsi1(_i,n) repst(_i,1,n,int)

#define REPT(_i,iv,_l,n,type) for(type _i=(type)(iv),_l=(type)(n);_i<_l;++_i)
//#define REPI(_i,iv,_l,n) REPT(_i,iv,_l,n,int)
//#define REPL(_i,iv,_l,n) REPT(_i,iv,_l,n,ll)
//
#define REPT0(_i,_l,n,type) REPT(_i,0,_l,n,type)
#define REPI0(_i,_l,n) REPT(_i,0,_l,n,int)
#define REPL0(_i,_l,n) REPT(_i,0,_l,n,ll)


//#define rrept(_i,x,e,type) for(type _i=((type)(x)-1);_i>=e;--_i)
//
//#define rrept0(_i,x,type) rrept(_i,x,0,type)
//
//#define RREPT(_i,x,_e,e,type) for(type _i=((type)(x)-1),_e=(type)(e);_i>=_e;--_i)
//
//#define RREPT0(_i,x,_e,type) RREPT(_i,x,_e,0,type)
//
//#define RREPS(i,x) for(int i=((int)(x));i>0;i--)

//#define all(x) (x).begin(),(x).end()
#define REPV(v,_itr,_end) for(auto _itr=(v).begin(),_end=(v).end();_itr!=_end;++_itr)
#define REPVC(v,_itr,_end) for(auto _itr=(v).cbegin(),_end=(v).cend();_itr!=_end;++_itr)

#define td typedef
//#define tds(stl,type,name) typedef stl<type > name;
#define tdv(type,name) typedef vector<type > name;


//typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<vb > vvb;
typedef vector<int> vi;
typedef vector<vi > vvi;
typedef vector<ll> vll;
//typedef vector<vll > vvll;

#define mod99 998244353

int main(int argc, const char * argv[]) {
    int X;
    cin>>X;
    int mod=X%100;
    repi0(i2, 50){
        int s2=i2*2;
        repi0(i3, 34){
            int s3=s2+i3*3;
            repi0(i4, 25){
                int s4=s3+i4*4;
                repi0(i5, 20){
                    int s=s4+i5*5;
                    int i1;
                    if(mod<s){
                        i1=(s-mod)%100;
                    }else{
                        i1=mod-s;
                    }
                    int sum=i1*101+i2*102+i3*103+i4*104+i5*105;
                    if(sum<=X){
                        cout<<1<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<0<<endl;
    
    return 0;
}


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

int main()
{
	int n, x, y, minValue, minArray[2000] = {0};
	cin >> n >> x >> y;
	for (int i = 1; i <= n-1; i++) {
		for (int j = i + 1; j <= n; j++) {
			minValue = min( abs(j - i), abs(x - i) + 1 + abs(j - y));
			minValue = min(minValue, abs(y - i) + 1 + abs(j - x));
			minArray[minValue]++;
		}
	}
	for (int i = 1; i < n; i++) {
		cout << minArray[i] << endl;
	}

}

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

int main(void)
{
    int n;
    cin >> n;
    vector<int> a(n);
    for (size_t i = 0; i < a.size(); i++) {
        cin >> a[i];
    }

    int max1 = 0;
    size_t max1i = 0;
    int max2 = 0;
    for (size_t i = 0; i < a.size(); i++) {
        if (a[i] >= max1) {
            max2 = max1;
            max1 = a[i];
            max1i = i;
        } else if (a[i] >= max2) {
            max2 = a[i];
        }
    }
    for (size_t i = 0; i < a.size(); i++) {
        if (i == max1i) {
            cout << max2 << endl;
        } else {
            cout << max1 << endl;
        }
    }

    return 0;
}



Measured memory_bytes: 2432
n = int(input())
numbers = input().split()

numbers = [int(num) for num in numbers]

def show(numbers):
    for i in range(len(numbers)):
        if i != len(numbers) - 1:
            print(numbers[i], end=" ")
        else:
            print(numbers[i])

for i in range(1, n):
    show(numbers)
    key = numbers[i]
    j = i - 1
    while j >= 0 and numbers[j] > key:
        numbers[j+1] = numbers[j]
        j -= 1

    numbers[j+1] = key
show(numbers)



Measured memory_bytes: 5976
import std.algorithm, std.conv, std.range, std.stdio, std.string;

void main()
{
  auto n = readln.chomp.to!size_t;

  auto rd = readln.chomp.splitter;
  auto ai = new int[](n);
  foreach (i; n.iota) {
    ai[i] = rd.front.to!int;
    rd.popFront;
  }

  auto i = partition(ai, 0, n - 1);

  foreach (j, a; ai) {
    writef(i == j ? "[%d]" : "%d", a);
    if (j < n - 1) write(" ");
  }
  writeln;
}

size_t partition(ref int[] ai, size_t p, size_t r)
{
  auto x = ai[r];
  auto i = p - 1;

  foreach (j; p..r) {
    if (ai[j] <= x) {
      ++i;
      swap(ai[i], ai[j]);
    }
  }
  swap(ai[i + 1], ai[r]);

  return i + 1;
}

Measured memory_bytes: 3172
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>

using namespace std;

int main() {
	int h, w;
	cin >> h >> w;
	vector< vector <char> > cc(h, vector<char>(w));

	string abc = "abcdefghijklmnopqrstuvwxyz";

	vector<int> d(26, 0);


	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> cc[i][j];
			for (int k = 0; k < 26; k++) {
				if (cc[i][j] == abc[k]) {
					d[k]++;
				}
			}
		}
	}

	priority_queue<int> pq;
	for (int i = 0; i < 26; i++) {
		if (d[i] != 0) {
			pq.push(d[i]);
		}
	}

	int hh = h / 2;
	int ww = w / 2;
	int p = hh * ww;
	int q = h * w - p * 4;
	int r = q % 2;
	int s = q / 2;

	bool pqr = true;

	while (!pq.empty()) {
		int aa = pq.top();
		pq.pop();
		if (p > 0) {
			if (aa >= 4) {
				aa -= 4;
				if (aa > 0) {
					pq.push(aa);
				}
			}
			else {
				pqr = false;
				break;
			}
			p--;
		}
		else if (s > 0) {
			if (aa >= 2) {
				aa -= 2;
				if (aa > 0) {
					pq.push(aa);
				}
			}
			else {
				pqr = false;
				break;
			}
			s--;
		}
		else if (r > 0) {
			if (aa >= 1) {
				aa--;
				if (aa > 0) {
					pq.push(aa);
				}
			}
			else {
				pqr = false;
				break;
			}
			r--;
		}
		else {
			break;
		}
	}

	if (pqr) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 384
using System;
using System.Text;

namespace AOJ_Hello_World {
	class Program {
		static void Main (string[] args) {
			var sab = Console.ReadLine();
			long[] a = new long[3];
			for (int i = 0;i < 3;i++) {
				a[i] = long.Parse( sab.Split(' ')[i]);
			}

			if(a[0]<a[1] && a[1] < a[2])
				Console.WriteLine("Yes");
			else
				Console.WriteLine("No");
		}
	}
}

Measured memory_bytes: 5304
/*
    Mbak Rose Dong
*/
#include<bits/stdc++.h>
using namespace std;
vector<int> vi;
int prime[100100];
void sieve()
{
    int i,j;
    prime[0] = prime[1] = 1;
    for(i=2;i<=100000;i++)
    {
        if(!prime[i])
        {
            vi.push_back(i);
            for(j=i*2;j<=100000;j+=i)
                prime[j] = 1;
        }
    }
}
int main()
{
    int n,i,j,k,x,y,ans,curr,temp,m;
    cin >> n;
    sieve();
    int cnt = 0;
    for(i=0;i<vi.size();i++)
    {
        if(vi[i] % 5 == 1)
        {
            printf("%d ",vi[i]);
            cnt++;
        }
        if(cnt == n)
            break;
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;

class D
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var a = Console.ReadLine().Split().Select(double.Parse).ToArray();

		var q = new PQ<double>(a, (x, y) => -x.CompareTo(y));
		for (var i = 0; i < h[1]; i++) q.Push(q.Pop() / 2);
		Console.WriteLine(q.Sum(x => (long)x));
	}
}

class PQ<T> : List<T>
{
	Comparison<T> _c;
	public T First => this[0];

	public PQ(IEnumerable<T> vs = null, Comparison<T> c = null)
	{
		_c = c ?? Comparer<T>.Default.Compare;
		if (vs != null) foreach (var v in vs) Push(v);
	}

	void Swap(int i, int j)
	{
		var t = this[i];
		this[i] = this[j];
		this[j] = t;
	}

	void UpHeap(int i) { for (int j; i > 0 && _c(this[(j = (i - 1) / 2)], this[i]) > 0; Swap(i, j), i = j) ; }
	void DownHeap(int i)
	{
		for (int j; (j = 2 * i + 1) < Count; i = j)
		{
			if (j + 1 < Count && _c(this[j], this[j + 1]) > 0) j++;
			if (_c(this[i], this[j]) > 0) Swap(i, j); else break;
		}
	}

	public void Push(T v) { Add(v); UpHeap(Count - 1); }
	public T Pop()
	{
		var r = this[0];
		this[0] = this[Count - 1];
		RemoveAt(Count - 1);
		DownHeap(0);
		return r;
	}
}


Measured memory_bytes: 31580
N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

N = factorization(N)
ans = 0
for p, a in N:
    if p == 1:
        break
    for i in range(1, a+1):
        if i*(i+1) >= 2*a:
            if i*(i+1) == 2*a:
                ans += i
            else:
                ans += (i - 1)
            break

print(ans)


Measured memory_bytes: 9488
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
int count(int n){
    int cnt=0;
    for(int i=1; i<=n; i++){
        if(n%i==0)cnt++;
    }
    return cnt;
}
int main(){
    int n; cin >> n;
    int ans=0;
    for(int j=1; j<=n; j+=2){
        if(count(j)==8)ans++;
    }
    cout << ans  << endl;
    return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
 
int main()
{
	int a,b,c;
	int ans=0;
	
	cin>>a>>b>>c;
	
	if(a==b&&a!=c)
		ans=2;
	if(a==b&&b==c&&a==c)
		ans=1;
	if(a==c&&a!=b)
		ans=2;
	if(a!=b&&b!=c&&a!=c)
		ans=3;
  	if(b==c&&a!=b)
      	ans=2;
	
  	cout<<ans;
	return 0;
	
}

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

int main(){
	
	vector<int> vec(3);
	for(int i=0; i<3; i++){
		
		cin >>vec.at(i);
		
	}
	
	sort(vec.begin(), vec.end());
	cout << vec.at(2)*10+vec.at(1)+vec.at(0) <<endl;
	
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef pair <ll, ll> pll;
typedef pair <int, int> pii;

typedef tree <ll, null_type, less <ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// order_of_key(val): returns the number of values less than val
// find_by_order(k): returns an iterator to the kth largest element (0-based)

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz(a) (ll)(a.size())
#define endl "\n"

template <class Ch, class Tr, class Container>
basic_ostream <Ch, Tr> & operator << (basic_ostream <Ch, Tr> & os, Container const& x) 
{
    os << "{ ";
    for(auto& y : x) 
    {
        os << y << " ";
    }
    return os << "}";
}

template <class X, class Y>
ostream & operator << (ostream & os, pair <X, Y> const& p) 
{
    return os << "[" << p.ff << ", " << p.ss << "]";
}

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

    return gcd(b, a%b);
}

ll modexp(ll a, ll b, ll c)
{   
    a%=c;

    ll ans = 1;

    while(b)
    {
        if(b&1)
        {
            ans = (ans*a)%c;
        }

        a = (a*a)%c;
        b >>= 1;
    }

    return ans;
}

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

const ll L = 1e5+5;

void solve()
{
    ll a, b, c, d, k;
    cin >> a >> b >> c >> d >> k;

    ll ff = a * 60 + b;
    ll ss = c * 60 + d;

    cout << max(0LL, ss - ff - k) << endl;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    
    ll T = 1;
    // T = nxt();

    while(T--)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main()
{
int N,i,j,l,m,flag=0;
string S;
cin>>N;
cin>>S;
l=S.size();m=(l/2);
    if(l%2!=0) cout<<"No"<<endl;
else
{
for(i=0,j=m;i<m,j<l ;i++,j++)
       { if(S[i]!=S[j])
        flag=1;}
    if(flag==1)
 cout<<"No"<<endl;
    else cout<<"Yes"<<endl;}return 0;}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define MAX 10000007
#define PI acos(-1)
#define eps 1e-8
#define eq(x,y) (fabs((x)-(y)) < eps)
#define debug(x) cout<<x<<endl;
#define endl "\n"
#define MEM(a,x) memset(a,x,sizeof(a))

using namespace std;
typedef long long ll ;
const int INF= 1e9+7;

/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<long long,null_type,less<long long>, rb_tree_tag,tree_order_statistics_node_update>
using namespace __gnu_pbds;
*/
/*
bool sortbysec(const pair<int,int>&a, const pair<int,int>&b)
{
    return (a.second<b.second);
}
*/
int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    //cout.tie(NULL);
    int a[]={111,222,333,444,555,666,777,888,999};

    int n;
    cin>>n;

    for(int i=0;i<9;i++)
    {
        if(n<=a[i]){
            cout<<a[i]<<endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 1e5 + 10;
const int INF = 0x3f3f3f3f;

int w[maxn], v[maxn];
long long dp[maxn];

int main() {
    int n, W, V = 0;
    scanf("%d %d", &n, &W);
    for (int i = 1; i <= n; ++i) {
        scanf("%d %d", &w[i], &v[i]);
        V += v[i];
    }

    memset(dp, INF, sizeof(dp));
    dp[0] = 0;
    for (int i = 1; i <= n; ++i) {
        for (int j = V; j >= v[i]; --j) {
            dp[j] = min(dp[j], dp[j - v[i]] + w[i]);
        }
    }
    for (int i = V; i >= 0; --i) {
        if (dp[i] <= W) {
            printf("%d\n", i);
            return 0;
        }
    }
}

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

vector<int> x, y, r, c;

bool overlap(int a, int b) {
  int hypot2 = (x[a] - x[b]) * (x[a] - x[b]) + (y[a] - y[b]) * (y[a] - y[b]);
  int d2 = (r[a] + r[b]) * (r[a] + r[b]);
  return (hypot2 < d2);
}

int main() {
  int n;
  while (cin >> n, n) {
    x = vector<int>(n);
    y = vector<int>(n);
    r = vector<int>(n);
    c = vector<int>(n);
    for (int i = 0; i < n; i++) {
      cin >> x[i] >> y[i] >> r[i] >> c[i];
    }
    int ans = 0;
    vector<int> dp(1 << n, 0);
    queue<int> q;
    q.push(0);
    while (!q.empty()) {
      int b = q.front(); q.pop();
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
          if (i >= j || b >> i & 1 || b >> j & 1) continue;
          if (c[i] != c[j]) continue;
          bool ok = true;
          for (int k = 0; k < i; k++) {
            if (b >> k & 1) continue;
            if (overlap(k, i)) ok = false;
          }
          for (int k = 0; k < j; k++) {
            if (b >> k & 1) continue;
            if (overlap(k, j)) ok = false;
          }
          int nb = b | (1 << i) | (1 << j);
          if (ok && dp[nb] < dp[b] + 2) {
            dp[nb] = dp[b] + 2;
            ans = max(ans, dp[nb]);
            q.push(nb);
          }
        }
      }
    }
    cout << ans << endl;
  }
}



Measured memory_bytes: 69804
n=int(input())
A=list(map(int,input().split()))
a=sorted(A)
counter=1
ans=0
value=a[0]
dict={}
for i in range(1,n):
    if a[i]==value:
        counter+=1
    else:
        dict[value]=counter
        if counter<2:
            pass
        else:
            ans+=counter*(counter-1)//2
        counter=1
        value=a[i]
dict[value]=counter
if counter<2:
    pass
else:
    ans+=counter*(counter-1)//2
for j in range(n):
    count=dict[A[j]]-1
    if count==0:
        print(ans)
    elif count==1:
        print(ans-1)
    else:
        c=ans-(count+1)*count//2+count*(count-1)//2
        print(c)


Measured memory_bytes: 26072