akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define INF (int)(1123456789)
#define LINF (long long int)(112345678901234567)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()

ll mpow(ll a, ll b){
	if(b==0){
		return a;
	}else if(b%2==0){
		ll memo = mpow(a,b/2);
		return memo*memo%MOD;
	}else{
		return mpow(a,b-1) * a % MOD;
	}
}

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

int main(void){
	vector<int> p;
	int n;
	cin>>n;
	int P;
	rep(i,n){
		cin>>P;
		p.push_back(P);
	}
	int ans = 0;
	rep(i,n-2){
		if(p[i+1] > min(p[i],p[i+2]) && p[i+1] < max(p[i],p[i+2])){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
solve []      = "No"
solve (x:xs)
  | x=='9'    = "Yes"
  | otherwise = solve xs

solve2 x = if any (=='9') x then "Yes" else "No"

solve3 []       = "No"
solve3 ('9':xs) = "Yes"
solve3 (x:xs)   = solve3 xs

main = do
  a <- getLine
  putStrLn $ solve3 a

Measured memory_bytes: 380
x,y = input().split()
num = [str(i) for i in range(10)]
num += ['A', 'B', 'C', 'D', 'E', 'F']
x = num.index(x)
y = num.index(y)
if x == y:
  print('=')
elif x < y:
  print('<')
else:
  print('>')

Measured memory_bytes: 3060
{-# OPTIONS_GHC -O2 #-}
import Control.Applicative
import Data.List
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString as BS
import Data.Maybe (fromJust)

f :: [Int] -> Int
f xs = xs !! m - xs !! (m-1)
    where m = (length xs) `div` 2
    
main :: IO()
main = interact $ show.f.sort.map read.words.last.lines


Measured memory_bytes: 28028
#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> a(n);
	rep(i, k) {
		int d;
		scanf("%d", &d);
		rep(j, d) {
			int p;
			scanf("%d", &p);
			a[p - 1]++;
		}
	}
	int ans = 0;
	rep(i, n) if (!a[i]) ans++;
	printf("%d\n", ans);
	return 0;
}

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

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

Measured memory_bytes: 256
import sys, math
sys.setrecursionlimit(200010)

def input():
    return sys.stdin.readline()[:-1]

def main():
    N, Q = map(int,input().split())
    G = [[] for k in range(N)]
    for k in range(N-1):
        a, b = map(int,input().split())
        G[a-1].append(b-1)
        G[b-1].append(a-1)

    V = [0]*N
    D = [0]*N
    for k in range(Q):
        p, x = map(int,input().split())
        D[p-1] += x

    def dfs(visited,distance,graph,ima):
        for e in graph[ima]:
            if visited[e] == 0:
                visited[e] = 1
                distance[e] += distance[ima]
                dfs(visited,distance,graph,e)
    V[0] = 1
    dfs(V,D,G,0)

    print(*D)

if __name__ == '__main__':
    main()


Measured memory_bytes: 269992
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

import numpy as np

N = int(readline())
XS = np.array(read().split(),np.int64)

"""
・右端を固定するごとに考える
・左端まで全部とる状態を基準点とする
・x座標：xの節約
・sの累積和：諦めるs
"""

X = XS[::2]; S = XS[1::2]

Scum = S.cumsum()

x = X.copy()
x[1:] -= Scum[:-1]

answer = (-X+Scum+np.maximum.accumulate(x)).max()
print(answer)

Measured memory_bytes: 40696
#include<bits/stdc++.h>
#include<cstdio>
#include<iostream>
#include<map>
#include<string>
#include<queue>
#include<map>
#include<vector>
#include<set>
#include<cstring>
using namespace std;
typedef long long ll;
ll a[15][15];
ll k;
ll sum=0;
void dfs(ll num,ll wei)
{
	printf("%lld",num,wei);
	if(wei==0) return;
	if(num>0&&sum+a[wei][num-1]>=k)
	{
		dfs(num-1,wei-1);
		return;
	}
//	printf("1\n");
	if(num>0) sum+=a[wei][num-1];
	if(sum+a[wei][num]>=k)
	{
		dfs(num,wei-1);
		return;
	}
//	printf("2\n");
	sum+=a[wei][num];
	dfs(num+1,wei-1);
}
int main()
{
	scanf("%lld",&k);
	for(ll i=0;i<=9;i++)
	{
		a[1][i]=1;
	}
	for(ll i=1;i<=13;i++)
	{
		for(ll j=0;j<=9;j++)
		{
			if(j-1>=0) a[i][j]+=a[i-1][j-1];
			a[i][j]+=a[i-1][j];
			if(j+1<=9) a[i][j]+=a[i-1][j+1];
		}
	}
	ll wei,num;
	for(ll i=1;i<=13;i++)
	{
		for(ll j=1;j<=9;j++)
		{
			if(sum+a[i][j]>=k)
			{
				num=j;
				wei=i;
				goto end;
			}
			sum+=a[i][j];
		}
	}
	end:;
//	printf("%lld",num);
	dfs(num,wei-1);
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rep3(i, l, n) for (int i = l; i < n; ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) rep(_, n) cout << a[_] << " "; cout << endl
#define SZ(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n], b[n], c[n];
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a, a + n);
    sort(b, b + n);
    sort(c, c + n);
    ll ans = 0;
    rep(i, n) {
        auto it = lower_bound(a, a + n, b[i]) - a;
        auto it2 = upper_bound(c, c + n, b[i]) - c;
        // out(it << " " << it2);
        ans += (ll)(it + 1 - 1) * (n - it2);
    }
    out(ans);
}


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(int i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define rep(i, n) FOR(i,0,n)
#define irep(i, n) IFOR(i,0,n)
template<class T> inline bool chmax(T & a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T & a, T b) { if (a > b) { a = b; return true; } return false; }
using ll = long long;

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> me(n);

    rep(i, n) cin >> me[i].first >> me[i].second;

    int aaa = 0;
    rep(i, n) {
        if (me[i].first == me[i].second) aaa++;
        else aaa = 0;

        if (aaa == 3) {
            cout << "Yes" << endl;

            return 0;
        }
    }

    cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 3632
import java.util.*;
//import java.util.stream.Collectors;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int n = Integer.parseInt(sc.next());
		int[] a = new int[n];
		Arrays.setAll(a, i -> Integer.parseInt(sc.next()));
		long d = 0;
		for(int i=1; i<n; i++){
			if(a[i] < a[i-1]){
				int temp = a[i-1] - a[i];
				d += temp;
				a[i] += temp;
			}
		}
		
		System.out.println(d);
	}
}


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

int sei(int a){
    if(a<0){
        a*=(-1);
    }
    return a;
}

int main(){
    int n;
    cin >> n;
    int t1=0,x1=0,y1=0;
    int t2,x2,y2;
    bool ans=true;
     for(int i=0;i<n;i++){
         cin >> t2 >> x2 >> y2;
         if(t2-t1>=sei(x2-x1)+sei(y2-y1)){
             if(((t2-t1)-(sei(x2-x1)+sei(y2-y1)))%2==0){
                 
             }else{ans=false;}
         }else{
             ans=false;
         }
         t1=t2;
         x1=x2;
         y1=y2;
     }
     if(ans){
         cout << "Yes" << endl;
     }else{
         cout << "No" << endl;
     }
    
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define db double
#define RE register
#define ll long long
#define P 1000000007
#define INF 1000000000
#define get(x) x=read()
#define PLI pair<ll,int>
#define PII pair<int,int>
#define pb(x) push_back(x)
#define ull unsigned long long
#define put(x) printf("%d\n",x)
#define getc(a) scanf("%s",a+1)
#define putl(x) printf("%lld\n",x)
#define rep(i,x,y) for(RE int i=x;i<=y;++i)
#define fep(i,x,y) for(RE int i=x;i>=y;--i)
#define go(x) for(int i=link[x],y=a[i].y;i;y=a[i=a[i].next].y)
using namespace std;
const int N=510;
ll s[N],t[N],n,p[N][N];
int R[N][2],L[N][2],cntr[N][2],cntl[N][2];//R/L表示在当前位上.行列需要满足的要求. 
ull u[N],v[N],c[N][N];
bool vis[N][N];
inline ll read()
{
	ll x=0,ff=1;
	char ch=getchar();
	while(!isdigit(ch)) {if(ch=='-') ff=-1;ch=getchar();}
	while(isdigit(ch)) {x=(x<<1)+(x<<3)+(ch^48);ch=getchar();}
	return x*ff;
}

inline void init()
{
	get(n);
	rep(i,1,n) get(s[i]);
	rep(i,1,n) get(t[i]);
	rep(i,1,n) cin>>u[i];
	rep(i,1,n) cin>>v[i];
}

inline bool solve(int id)
{
	memset(p,0,sizeof(p));
	memset(vis,0,sizeof(vis));
	memset(cntr,0,sizeof(cntr));
	memset(cntl,0,sizeof(cntl));
	rep(i,1,n) 
	{
		if(R[i][1]==n||R[i][0]==n)
		{
			int k=R[i][1]==n?1:0;
			rep(j,1,n) p[i][j]=k,vis[i][j]=1;
		}
		if(L[i][1]==n||L[i][0]==n)
		{
			int k=L[i][1]==n?1:0;
			rep(j,1,n) p[j][i]=k,vis[j][i]=1;
		}
	}
	rep(i,1,n) rep(j,1,n)
	{
		if(!vis[i][j])
		{
			if((R[i][0]&&L[j][0])||(R[i][1]&&L[j][1]))
			{
				int k;
				if(R[i][0]&&L[j][0]) k=0;
				else k=1;
				p[i][j]=k;
				vis[i][j]=1;
			}
		}
	}
	rep(i,1,n) rep(j,1,n) cntr[i][p[i][j]]++;
	rep(i,1,n) rep(j,1,n) cntl[i][p[j][i]]++;
	rep(i,1,n) rep(j,1,n)
	{
		if(!vis[i][j])
		{
			if(cntr[i][1]>=R[i][1]&&cntl[j][1]>=L[j][1]) continue;
			else if(cntr[i][0]-1>=R[i][0]&&cntl[j][0]-1>=L[j][0])
			{
				p[i][j]=1;
				cntr[i][0]--;cntl[j][0]--;
				cntr[i][1]++;cntl[j][1]++;
			}
		}
	} 
	rep(i,1,n) rep(k,0,1) if(cntr[i][k]<R[i][k]||cntl[i][k]<L[i][k]) return false;
	rep(i,1,n) rep(j,1,n) c[i][j]|=(ull)p[i][j]<<id;
	return true;
}

int main()
{
	//freopen("1.in","r",stdin);
	init();
	rep(i,0,63)
	{
		memset(R,0,sizeof(R));
		memset(L,0,sizeof(L));
		rep(j,1,n) 
		{
			if(!s[j]&&u[j]>>i&1) R[j][1]=n;
			else if(!s[j]&&!(u[j]>>i&1)) R[j][0]=1;
			else if(s[j]&&!(u[j]>>i&1)) R[j][0]=n;
			else R[j][1]=1;
		}
		rep(j,1,n) 
		{
			if(!t[j]&&v[j]>>i&1) L[j][1]=n;
			else if(!t[j]&&!(v[j]>>i&1)) L[j][0]=1;
			else if(t[j]&&!(v[j]>>i&1)) L[j][0]=n;
			else L[j][1]=1;
		}
		if(!solve(i)) {puts("-1");return 0;}
	}
	rep(i,1,n) 
	{
		rep(j,1,n) printf("%llu ",c[i][j]);
		puts("");
	}
	return 0;
} 




Measured memory_bytes: 9804
INF = 10**9 + 7


def main():
    import sys
    input = sys.stdin.buffer.readline
    N, M = (int(i) for i in input().split())
    A = []
    B = []
    C = []
    for _ in range(M):
        a, b = (int(i) for i in input().split())
        A.append(a)
        B.append(b)
        bit = 0
        for s in input().split():
            c = int(s)
            bit |= (1 << (c-1))
        C.append(bit)

    dp = [[INF]*(1 << N) for _ in range(M+1)]
    dp[0][0] = 0
    for i in range(M):
        for j in range(1 << N):
            dp[i+1][j] = min(dp[i+1][j], dp[i][j])
            if dp[i][j] != INF:
                next_bit = j | C[i]
                dp[i][next_bit] = min(dp[i][next_bit], dp[i][j] + A[i])
    ans = dp[M][(1 << N) - 1]
    if ans == INF:
        print(-1)
    else:
        print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 74732
#include <iostream>
#include <vector>
using namespace std;
typedef long long int ll;
ll N,M;
int main(){
	cin >> N >> M;
	if(M <= 2*N) {
		cout << M/2 << endl;
	}else{
		cout << (M-2*N)/4 + N << endl;
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

int main(){
    int a, b;
    std::cin >> a >> b;
    int diff = b - a;
    int snow = -a;
    for(int i = 1; i < diff; i++){
        snow += i;
    }
    std::cout << snow << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

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

	
	if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') cout << '3' << '\n';
	else if (s[0] == 'R' && s[1] == 'R' || s[1] == 'R' && s[2] == 'R') cout << "2\n";
	else if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') cout << "1\n";
	else cout << "0\n";


	return 0;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int vacationDays = scanner.nextInt();
        int noOfAssignments = scanner.nextInt();
        int sum = 0;
        for (int i = 0; i < noOfAssignments; i++) {
            sum += scanner.nextInt();
        }
        if (vacationDays >= sum) {
            System.out.println(vacationDays - sum);
        } else {
            System.out.println(-1);
        }

    }
}


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

using namespace std;

using ll = long long;
using Graph = vector< vector<int> >;

const ll MOD = 1000000007;
const ll INV2 = (MOD + 1) / 2;

ll modpow(ll x, ll n, ll mod = MOD) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * x % mod;
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

void pre_dfs(int cur, int par, const Graph& g, vector<ll>& cnt) {
    cnt[cur] = 1;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        pre_dfs(nex, cur, g, cnt);
        cnt[cur] += cnt[nex];
    }
}

void dfs(int cur, int par, const Graph& g, const vector<ll>& cnt, ll& ans) {
    int n = g.size();
    ll par_cnt = n - 1;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        par_cnt -= cnt[nex];
    }

    ll hoge = modpow(INV2, n - 1);
    ll res = (MOD + 1 - hoge) % MOD;
    res = (res + MOD - hoge * modpow(2, par_cnt) % MOD * (MOD + 1 - modpow(INV2, par_cnt)) % MOD) % MOD;
    for (int nex : g[cur]) {
        if (nex == par) continue;
        res = (res + MOD - hoge * modpow(2, cnt[nex]) % MOD * (MOD + 1 - modpow(INV2, cnt[nex])) % MOD) % MOD;
        dfs(nex, cur, g, cnt, ans);
    }   
    (res *= INV2) %= MOD;
    (ans += res) %= MOD;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    cin >> n;
    
    Graph g(n);
    for (int i = 1; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        --a; --b;

        g[a].push_back(b);
        g[b].push_back(a);
    }

    vector<ll> cnt(n, 0);
    pre_dfs(0, -1, g, cnt);

    ll ans = 0;
    dfs(0, -1, g, cnt, ans);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 28288
#include <iostream>

using namespace std;

int main()
{
    long long N, M;
    cin >>  N >> M;
    
    long long ans = N;
    if (M - N*2 > 0) {
        ans += (M - N*2) / 4;
    } else {
        ans = M / 2;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
a = list(map(int, input().split()))
b = 1
c = [-1]*n
c[0] = 0
for i in range(n):
    b = a[b-1]
    if c[b-1] == -1:
        c[b-1] = i+1
    else:
        d = i+1-c[b-1]
        e = c[b-1]
        break;
b = 1
for i in range(min(k, e+(k-e)%d)):
    b = a[b-1]
print(b)

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

int max_n = 1e6 + 6;
vector<int> spf;

void sieve()
{
	spf.resize(max_n, 1);
	
	for(int num = 2; num < max_n; num++)
		spf[num] = num;

	for(int num = 2; num < max_n; num++)
	{
		if(spf[num] != num)
			continue;

		for(int mult = 2*num; mult < max_n; mult += num)
			spf[mult] = num;
	}
}

void solve()
{
	int n;
	cin >> n;

	vector<int> a(n);
	for(auto &ele : a)
		cin >> ele;

	vector<bool> present(max_n, false);
	bool first = true;

	for(int i = 0; i < n; i++)
	{
		int num = a[i];
		while(num != 1)
		{
			int pf = spf[num];
			if(present[pf] == true)
				first = false;
			
			present[pf] = true;
			while(num % pf == 0)
				num /= pf;
		}
	}
	
	int g = a[0];
	for(int i = 1; i < n; i++)
		g = __gcd(g, a[i]);

	if(first)
		cout << "pairwise coprime" << endl;
	else if(g == 1)
		cout << "setwise coprime" << endl;
	else
		cout << "not coprime" << endl;
}

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

	sieve();
	solve();
	return 0;
}


Measured memory_bytes: 11336
#include <cstdio>
#include <iostream>
using namespace std;
int main()
{
    int a[5],b[5],t1,t2;
	while(scanf("%d%d%d%d",a+1,a+2,a+3,a+4)!=EOF)
	{
		scanf("%d%d%d%d",b+1,b+2,b+3,b+4);
		t1=t2=0;
		for (int i=1;i<=4;i++)
		{
			if (a[i]==b[i]) t1++;
			for (int j=1;j<=4;j++) if (i!=j&&a[i]==b[j]) t2++;
		}
		cout<<t1<<" "<<t2<<endl;
	}
	return 0;
}

Measured memory_bytes: 1208
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main() {
    int n;
    cin >> n;
    string s;
    cin >> s;
    int maxx = 0;
    for (int i = 0; i < n; i++) {
        int cnt = 0;
        set<char> chr1, chr2;
        for (int j = 0; j < i; j++) {
            chr1.insert(s[j]);
        }
        for (int j = i; j < n; j++) {
            chr2.insert(s[j]);
        }
        for (auto c : chr1) {
            if (chr2.count(c))
                cnt++;
        }
        maxx = max(maxx, cnt);

    }
    cout << maxx << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main (){
	char name [2];
	scanf ("%c", name);
	for(int i = 0; name[i] != '\0'; i++) {
    if(name[i] >= 'a' && name[i] <= 'z') {
      printf ("a");
    } else if(name[i] >= 'A' && name[i] <= 'Z') {
      printf ("A");
    }
  }


	
	
	return 0;
}

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  each(x,vec) is >> x;
  return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
  rep(i,vec.size()) {
    if (i) os << " ";
    os << vec[i];
  }
  return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
  rep(i,vec.size()) {
    if (i) os << endl;
    os << vec[i];
  }
  return os;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n, m; cin >> n >> m;
  vector<ll> a(n); cin >> a;
  vector<ll> start(2*m), end(2*m), endlen(2*m);
  ll sum = 0;
  rep(i, n-1) {
    ll l = a[i]-1, r = a[i+1]-1;
    if (r < l) r += m;
    sum += r - l;
    ++l;
    start[l]++;
    if (m+l < 2*m) start[m+l]++;
    end[r]++;
    endlen[r] += r-l;
    if (m+r < 2*m) {
      end[m+r]++;
      endlen[m+r] += r-l;
    }
  }
  ll ans = 0, now = 0, cnt = 0;
  rep(i, 2*m) {
    now += cnt;
    cnt += start[i];
    cnt -= end[i];
    chmax(ans, now);
    // cout << i << " " << now << endl;
    now -= endlen[i];
  }
  ans = sum - ans;
  cout << ans << endl;
}


Measured memory_bytes: 5760
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n,m=LI()

  l=[]

  for _ in range(m):
    a,b=LI()
    if a==1:
      l.append(b)
    elif b==1:
      l.append(a)
    elif a==n:
      l.append(b)
    elif b==n:
      l.append(a)

  if len(l)==len(set(l)):
    print('IMPOSSIBLE')
  else:
    print('POSSIBLE')

main()
# print(main())


Measured memory_bytes: 25852
import sys
#import numpy as np
import math
#from fractions import Fraction
#import itertools
from collections import deque
#import heapq
from fractions  import gcd

input=sys.stdin.readline
x=[int(input()) for _ in range(5)]
w=[0]*5
for i in range(5):
    if x[i]%10==0:
        j=10
    else:
        j=x[i]%10
    w[i]=10-j
w.sort()
ans=sum(x)+sum(w[:4])
print(ans)

Measured memory_bytes: 63852
#include<iostream>
using namespace std;
int fun(int x,int y)
{
    int a,b,c,d,e,h=0;
    for (int i=x;i<=y;i++)
    {
        a=i%10;
        b=(i%100-a)/10;
        c=(i%1000-a-b*10)/100;
        d=(i%10000-a-b*10-c*100)/1000;
        e=(i-a-b*10-c*100-d*1000)/10000;
        if ((a==e)&&(b==d))
        {
            h=h+1;
        }
    }
    return h;
}
int main()
{
    int a,b,sum;
    cin>>a>>b;
    sum=fun(a,b);
    cout<<sum<<endl;
    return 0;
}


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

typedef long long ll;
// #define int ll
#define pb push_back
// const int INF = 1e18;
const int inf = 1e9;

signed main(){

	ios_base::sync_with_stdio(false);
	cin.tie(0);


	

	int a,b,c,k;
	cin>>a>>b>>c>>k;
	if (k<=a+b)
		cout<<min(k,a);
	else
		cout<<a-(k-a-b);
	

	return 0;
}

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

using VS = vector<string>;    using LL = long long;
using VI = vector<int>;       using VVI = vector<VI>;
using PII = pair<int, int>;   using PLL = pair<LL, LL>;
using VL = vector<LL>;        using VVL = vector<VL>;

#define ALL(a)  begin((a)),end((a))
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) int((a).size())
#define SORT(c) sort(ALL((c)))
#define RSORT(c) sort(RALL((c)))
#define UNIQ(c) (c).erase(unique(ALL((c))), end((c)))
#define FOR(i, s, e) for (int(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (int(i) = (s); (i) > (e); (i)--)
//#pragma GCC optimize ("-O3") 
#ifdef YANG33
#include "mydebug.hpp"
#else
#define DD(x) 
#endif
const int INF = 1e9;                          const LL LINF = 1e16;
const LL MOD = 1000000007;                    const double PI = acos(-1.0);
int DX[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };    int DY[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2019/03/08  Problem: ABC 093 D / Link: http://abc093.contest.atcoder.jp/tasks/abc093_d  ----- */


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

	LL Q; cin >> Q;
	auto f = [](LL A, LL B) {
		if (A == B)return 2 * (A - 1);
		LL upMax = A * B - 1;

		LL L = 1, R = 10LL*INF;
		while (R - L > 1) {
			LL mid = (L + R) / 2;
			LL mulmax = (
				mid & 1 ?
				(mid / 2 + 1)*(mid / 2 + 1)
				:
				(mid / 2)*(mid / 2 + 1)
				);
			if (mulmax > upMax)R = mid;
			else L = mid;

		}

		return L - 1;
	};
	FOR(_, 0, Q) {
		LL A, B; cin >> A >> B;
		LL ans = f(A, B);
		cout << (ans) << "\n";
	}



	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<string> w(n);
    map<string,int>mp;
    REP(i,n){
        cin >> w[i];
        mp[w[i]]++;
    }

    REP(i,n){
        if(mp[w[i]]!=1){
            cout << "No" << endl;
            return 0;
        }
    }
    
    REP(i,n-1){
        if(w[i][w[i].length()-1]!=w[i+1][0]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
         int i = 0;

        while (true){
            int a = sc.nextInt();
            if( a == 0 )
            	break;
            i += 1;
            System.out.println("Case "+ i + ": "+ a );
        }
        sc.close();
    }
} 


Measured memory_bytes: 41764
S = input()
frag = False
for i in range(97, 123):
    if chr(i) not in S:
        print("".join([S, chr(i)]))
        frag = True
        break
if frag == False:
    for i in range(2, len(S) + 1):
        for j in range(97, 123):
            if chr(j) not in S[:1-i] and j > ord(S[1-i]):
                frag = True
                break
        if frag:
            break
    if frag:
        print("".join([S[:1-i], chr(j)]))
    else:
        if S[0] == "z":
            print(-1)
        else:
            print(chr(ord(S[0]) + 1))

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

int main() {
    int h,n;
    cin >> h >> n;
    vector<int> a(n,0);
    ll sum = 0;
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    if(sum >= h){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

/*
やっほい！
　　　　　　　やほほい！
　　　　+　　 　*
　　　 ∧∧　　. ∧∞∧　*
*　ヽ(=´ω｀)人(´ω｀*)ﾉ
　.～（ O x.） （ 　 O)～　+
。*　 　∪　　　　∪
*/

Measured memory_bytes: 640
#include <bits/stdc++.h>
 
#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
 
struct S002 {
  int n;
  S002& operator > (long& x) {
    n = x;
    return *this;
  }
  S002& operator > (long&& x) {
    n = x;
    return *this;
  }
  S002& operator >= (long& x) {
    if( scanf("%ld", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (double& x) {
    if( scanf("%lf", &x) <= 0 ) exit(0);
    return *this;
  }
  S002& operator >= (std::string& s) {
    if( not (std::cin >> s) ) exit(0);
    return *this;
  }
  template<typename a>
  S002& operator >= (std::vector<a>& v) {
    v.resize(n);
    for(long i = 0; i < n; ++i) {
      *this >= v[i];
    }
    return *this;
  }
  template<typename a, std::size_t s>
  S002& operator >= (std::array<a, s>& x) {
    for(long i = 0; i < (long)s; ++i) {
      *this >= x[i];
    }
    return *this;
  }
};

struct Solver {
  long a, b;
  std::vector<std::array<long, 2>> xs;
  Solver() {
    S002 reader;
    reader >= a >= b;
  }
  void solve() {
    long res = (a + b) % 24;
    printf("%ld\n", res);
  }
};
 
int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
  return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

vector<pll> adj[MAXN];
ll n , v , u , w , dist[MAXN];

void DFS(ll v , ll p = 1)
{
    for(pll i : adj[v])
    {
        ll u = i.X , w = i.Y;
        if(u != p)
        {
            dist[u] = dist[v] + w;
            DFS(u , v);
        }
    }
}

int main() {
    fast_io;

    cin >> n;
    for(ll i = 1 ; i < n ; i++)
    {
        cin >> v >> u >> w;
        adj[v].push_back({u , w});
        adj[u].push_back({v , w});
    }

    DFS(1);
    for(ll i = 1 ; i <= n ; i++)    cout << dist[i] % 2 << endl;

    return 0;
}
/*
todo :
    1- set constants
    2- check TimeLimit and MemoryLimit
    3- check special test cases
    4- don't forget BS can help you that is good idea(use for loop for floats)
    5- don't forget printf and scanf can help you in your code speed
*/


Measured memory_bytes: 33024
#!/usr/bin/env python3
class Osa_k:
    def __init__(self, n_max):
        self.n_max = n_max
        self.min_factor = min_factor = list(range(n_max + 1))
        min_factor[2::2] = [2] * (n_max // 2)
        min_factor[3::6] = [3] * ((n_max + 3) // 6)
        for i in range(5, int(n_max ** .5) + 1, 2):
            if min_factor[i] == i:
                for j in range(i*i, n_max + 1, i):
                    if min_factor[j] == j:
                        min_factor[j] = i

    def __call__(self, n):
        if not 1 <= n <= self.n_max: raise ValueError("Invaild Value!")
        min_factor = self.min_factor
        n_twoes = (n & -n).bit_length() - 1
        res = [2] * n_twoes
        n >>= n_twoes
        resappend = res.append
        while n > 1:
            p = min_factor[n]
            resappend(p)
            n //= p
        return set(res)

from math import gcd
_, *a = map(int, open(0).read().split())
D = set()
t = 0
k = True
fac = Osa_k(max(a))
for b in a:
    s = fac(b)
    if D & s: k = False
    D |= s
    t = gcd(t, b) if t else b
if k:
    print("pairwise coprime")
elif t == 1:
    print("setwise coprime")
else:
    print("not coprime")

Measured memory_bytes: 210660
function Main(input) {
  const n = +input[0];
  const strs = input[1].split(' ');

  var answer = '';
  for (var i = 0; i < n; i++) {
    answer += strs[0][i];
    answer += strs[1][i];
  }

  console.log(answer);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 21064
st = input()
N = len(st)
gc = 0
ret = 0
for s in st:
    if s == 'g':
        gc += 1
    else:
        gc -= 1
for s in reversed(st):
    if s == 'g':
        gc -= 1
        if gc > 0:
            gc -= 1
            ret += 1
                        
print(ret)

Measured memory_bytes: 3316
#include<iostream>
#include<string>
#include<vector>
#include<map>
using namespace std;

long gcd(long A, long B){
    long v0 = A, v1 = B, v2 = A % B;
    while(v2 != 0){
        v0 = v1;
        v1 = v2;
        v2 = v0 % v1;
    }
    return v1;
}

long lcm(long A, long B){
    return A/gcd(A, B)*B;
}

int main() {
    long N, M;
    cin>>N>>M;
    string S, T;
    cin>>S>>T;
    if(N<M){
        swap(N, M);
        swap(S, T);
    }
    long L = lcm(N, M);
    map<long, char> ans;
    for(int i=0;i<N;++i){
        ans[(L/N)*i] = S[i];
    }
    bool check = true;
    for(int i=0;i<M;++i){
        if(ans[(L/M)*i]!=T[i] & ans[(L/M)*i]!='\0')check = false;
    }
    if(check)cout<<L<<endl;
    else cout<<-1<<endl;
}


Measured memory_bytes: 10880
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
using namespace std;

int main(){
  int W,H,x,y;
  cin >> W >> H >> x >> y;
  double max = double(W)*double(H)/2;
  int judge = 0;
  if(x + x == W && y + y == H){
    judge = 1;
  }
  cout << fixed << setprecision(6) << max << " ";
  cout << judge << endl;
}


Measured memory_bytes: 3772
#include<stdio.h>

int main()
{
	int n, m, k;
	scanf("%d %d %d", &n, &m, &k);
	int sum1 = k/n;
	int sum2 = k/m;
	int ctr =  0;
	int temp;
	if(sum1 > sum2){
		for(int i = 1; i <= 100; i++){
			temp = m * i;
			++ctr;
			if(temp >= k){
				break;
			}
		}
	}else{
		for(int i = 1; i <= 100; i++){
			temp = n * i;
			++ctr;
			if(temp >= k){
				break;
			}
		}
	}
	printf("%d\n", ctr);
}

Measured memory_bytes: 1708
#include <algorithm>
#include <iostream>
#include <cstring>
#include <climits>
#include <cstdio>

using namespace std;

#define Set(a, b) memset(a, b, sizeof a)

typedef long long LL;

const LL Inf = LONG_LONG_MAX / 2;
const int N = 1e5 + 10;

int n, e, t;
LL f[N], p[N];

int main() {

	scanf("%d %d %d", &n, &e, &t);
	for (int i = 1; i <= n; ++i) 
		scanf("%lld", &p[i]);
	Set(f, 60);
	f[0] = 0;
	LL mn = Inf;
	for (int i = 1, j = 0; i <= n; ++i) {
		for (; t <= 2 * (p[i] - p[j + 1]); ++j) 
			mn = min(mn, f[j] - 2 * p[j + 1]);
		if (j < i)
			f[i] = min(f[i], f[j] + t);
		f[i] = min(f[i], mn + 2 * p[i]);
	}
	printf("%lld\n", e + f[n]);

	return 0;
}


Measured memory_bytes: 1792
#!/usr/bin/env python3
# https://atcoder.jp/contests/abc088/tasks/abc088_b

def main():
    n = int(input())
    i = list(map(int,input().split()))
    # j = list(map(int,input().split()))

    i.sort(reverse=True)
    # print(i)

    # print(i[::2])
    # print(i[1::2])
    print(sum(i[::2]) - sum(i[1::2]))

main()


Measured memory_bytes: 2940
#! env python
# -*- coding: utf-8 -*-

import os
import sys

# ac_py.main.py
# Date: 2020/06/08
# Filename: main.py 

__author__ = 'acto_mini'
__date__ = "2020/06/08"


def main():
    n = int(input())
    t_prev = 0
    x_prev = 0
    y_prev = 0
    for i in range(n):
        t, x, y = map(int, input().split())
        dt = t - t_prev
        dist = abs(x - x_prev) + abs(y - y_prev)
        if dt < dist or ((dt % 2) != (dist % 2)):
            print("No")
            exit()
        t_prev, x_prev, y_prev = t, x, y

    print("Yes")
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.BufferedWriter;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

/**
 * Built using CHelper plug-in Actual solution is at the top
 *
 * @author @Ziklon
 */
public class Main {
  public static void main(String[] args) {
    InputStream inputStream = System.in;
    OutputStream outputStream = System.out;
    InputReader in = new InputReader(inputStream);
    OutputWriter out = new OutputWriter(outputStream);
    AIrreversibleOperation solver = new AIrreversibleOperation();
    solver.solve(1, in, out);
    out.close();
  }

  static class AIrreversibleOperation {
    public void solve(int testNumber, InputReader in, OutputWriter out) {

      String s = in.readString();
      int blacks = 0;
      long ans = 0;
      for (char c : s.toCharArray()) {
        if (c == 'B') blacks++;
        else {
          ans += blacks;
        }
      }
      out.printLine(ans);
    }
  }

  static class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
      this.stream = stream;
    }

    public int read() {
      if (numChars == -1) {
        throw new InputMismatchException();
      }
      if (curChar >= numChars) {
        curChar = 0;
        try {
          numChars = stream.read(buf);
        } catch (IOException e) {
          throw new InputMismatchException();
        }
        if (numChars <= 0) {
          return -1;
        }
      }
      return buf[curChar++];
    }

    public String readString() {
      int c = read();
      while (isSpaceChar(c)) {
        c = read();
      }
      StringBuilder res = new StringBuilder();
      do {
        if (Character.isValidCodePoint(c)) {
          res.appendCodePoint(c);
        }
        c = read();
      } while (!isSpaceChar(c));
      return res.toString();
    }

    public boolean isSpaceChar(int c) {
      if (filter != null) {
        return filter.isSpaceChar(c);
      }
      return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
      return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public interface SpaceCharFilter {
      public boolean isSpaceChar(int ch);
    }
  }

  static class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
      writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
      this.writer = new PrintWriter(writer);
    }

    public void close() {
      writer.close();
    }

    public void printLine(long i) {
      writer.println(i);
    }
  }
}


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

using ll = long long;
#define int long long

#define LOG(variable) cout << #variable":\t" << (variable) << endl
#define LOGCON(i, container) for(int (i) = 0; (i) < (container).size(); ++(i)) cout << (i) << ":\t" << (container)[(i)] << endl
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPS(i, r, n) for (int i = (r); i < (n); ++i)
#define REPR(i, n) for(int i = (n); i >= 0; --i) // from n to 0
#define REPRS(i, r, n) for(int i = (n); i >= (r); --i) // from n to r
#define REPOBJ(itr, obj) for(auto itr = (obj).begin(); itr != (obj).end() ; ++itr)
#define REPROBJ(itr, obj) for(auto itr = (obj).rbegin(), e = (obj).rend(); itr != e; ++itr)
#define COUTB(x) cout << (x) << "\n"
#define COUTS(x) cout << (x) << " "
#define PB push_back
#define SORT(obj) sort((obj).begin(), (obj).end())
#define SORTR(obj) sort((obj).begin(), (obj).end(), greater<>())
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define PI (acos(-1))
/***** MAIN *****/
signed main() {
  int n;
  cin >> n;
  int cur_power[n];
  vector<int> extra_power;
  int shorten_total = 0;
  REP(i,n) {
    cin >> cur_power[i];
  }
  ll ans = 0;
  REP(i,n) {
    int nece_power;
    cin >> nece_power;
    int diff = cur_power[i] - nece_power;
    if(diff == 0) continue;
    if(diff > 0) {
      extra_power.PB(diff);
    } else {
      shorten_total -= diff;
      ++ans;
    }
  }

  SORTR(extra_power);
  REP(i,extra_power.size()) {
    if(shorten_total <= 0) break;
    shorten_total -= extra_power[i];
    ++ans;
  }
  if(shorten_total <= 0) {
    cout << ans;
  } else {
    cout << -1;
  }
  
  cout << "\n";
  return 0;
}
/***** MAIN *****/


Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int dfs(long long n,int k){
    int c=0;
    while(n!=0){
        n/=k;
        c++;
    }return c;
}
int main() {
    ll n;cin>>n;
    ll a[n+1];ll ans=1e18;
    for(int i=0;i<n;i++)cin>>a[i];
	for(int i=1;i<=101;i++){
            ll sum=0;
           // cout<<i<<" ";
        for(int j=0;j<n;j++){
            ll ab=abs(i-a[j]);
    sum+=(ab*ab);
        }
        if(ans>sum)ans=sum;
	}
	cout<<ans;
}


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

int main() {
    int n, k, q;
    cin >> n >> k >> q;

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

    for (int i = 0; i < q; i++) {
        int person;
        cin >> person;
        --person;
        ++numAnswer[person];
    }

    for (int i = 0; i < n; i++) {
        if (k - (q - numAnswer[i]) > 0) {
            cout << "Yes" << endl;
        } else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<string>
#include<unordered_set>
using namespace std;

int main() {
	int N;
	cin >> N;
	vector<string> word(N);
	unordered_set<string> s;
	for (int i = 0; i < N; i++) {
		cin >> word[i];
	}
	s.insert(word[0]);
	for (int i = 1; i < N; i++) {
		if (s.find(word[i]) != s.end()) {
			cout << "No";
			break;
		}
		if (word[i][0] != word[i - 1][word[i-1].length()-1]) {
			cout << "No";
			break;
		}
		s.insert(word[i]);
		if (i == N - 1)
			cout << "Yes";	
	}
	return 0;

}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def gdc(p, q):
    if q == 0:
        return p
    return gdc(q, p%q)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if N == 1:
        print(A[0])
        return
    res = A[0]
    for i in range(1,N):
        res = gdc(res, A[i])
    print(res)

if __name__ == '__main__':
    main()

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

int main()
{
	int n;
    cin>>n;
    int a[n];
    for(int i = 0; i < n; i++)
    	cin>>a[i];
    int m;
    cin>>m;
    for(int i = 0; i < m; i++)
    {
    	int p, x;
        cin>>p>>x;
        int temp = a[p-1];
        a[p-1] = x;
        int sum = 0;
     	for(int i = 0; i < n; i++)
        	sum += a[i];
        cout<<sum<<"\n";
        a[p-1] = temp;
    }
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define dump(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

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

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

#define COUT(x) cout << (x) << endl

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

void selectionSort(int A[], int N) {
    int cnt = 0;
    rep(i, N) {
        int minj = i;
        for(int j = i; j < N; j++) {
            if(A[j] < A[minj]) {
                minj = j;
            }
        }
        swap(A[i], A[minj]);
        if(i != minj) cnt++;
    }
    rep(i, N) {
        if(i) cout << " ";
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
}

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

    int n; cin >> n;
    int A[100];
    rep(i, n) cin >> A[i];
    selectionSort(A, n);
}


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

using namespace std;

int calc(int a, int b);

int main()
{
    int n;
    vector<int> a;
    int sum = 0;

    cin >> n;

    a.reserve(n + 2);
    a.push_back(0);
    for(int i = 0; i < n; i++)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    a.push_back(0);

    for(int i = 0; i < n + 1; i++)
    {
        sum += calc(a[i], a[i + 1]);
    }

    for(int i = 1; i <= n; i++)
    {
        int cost = sum;

        cost -= calc(a[i - 1], a[i]);
        cost -= calc(a[i], a[i + 1]);
        cost += calc(a[i - 1], a[i + 1]);

        cout << cost << endl;
    }

    return 0;
}

int calc(int a, int b)
{
    int result = a - b;
    if(result < 0)
    {
        result = -result;
    }
    return result;
}


Measured memory_bytes: 1664
#include<bits/stdc++.h> 
using namespace std; 
#define ll long long
#define MOD 1000000007

void max_self(ll& a, ll b ){
    a = max(a, b);
}

int main() {
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // #endif

    int N, W;
    cin>>N>>W;

    vector<ll> dp(W+1, 0);
    ll weight, value;
    for( int i=0; i<N; i++ ) {
        cin>>weight>>value;
        for( int i=W-weight; i>=0; i-- ) {
            max_self(dp[i+weight], dp[i]+value);
        }
    }

    ll res = 0;
    for( int i=0; i<=W; i++ )
        max_self(res, dp[i]);

    cout<<res<<endl;
    return 0;
}

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

typedef long long ll;

using namespace std;

int main(){
    ll a, b, k;
    cin >> a >> b >> k;
    ll t = k - min(a, k);
    a -= min(a, k);
    b -= min(b, t);
    cout << a << " " << b;
    return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc142/tasks/abc142_c
n = int(input())
nums = [int(i) for i in input().split()]

students = []
for i in range(n):
    students.append((nums[i], i + 1))
students.sort(key=lambda x: x[0])

ans = []
for i in range(n):
    ans.append(students[i][1])
print(*ans)

Measured memory_bytes: 68140
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0,i##_len=int(n);i<i##_len;++i)
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define All(x) (x).begin(),(x).end()
#define rAll(x) (x).rbegin(),(x).rend()
using namespace std;
using ll = long long;

int main(){
    int N;cin>>N;
    vector<int> A(N);
    REP(i, N) cin >> A[i];
    int cnt=0;
    REP(i,N) if(A[i]&1) cnt++;
    if(cnt&1) cout<<"NO"<<endl;
    else cout<<"YES"<<endl;
}


Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
	"strings"
)

// VMAX is the maximum value of element in progression.
const VMAX = 10000

func main() {
	fmt.Println(answer(os.Stdin))
}

func answer(r io.Reader) string {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)

	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())

	// A[0], B[0] and C[0] won't be used due to handling the inconsistency
	// between the size of slice and its number of element.
	A := make([]int, n+1)
	C := make([]int, VMAX+1)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i+1], _ = strconv.Atoi(sc.Text())
		C[A[i+1]]++
	}

	B := countingSort(A, C, n)
	return String(B)
}

func countingSort(A, C []int, n int) []int {
	B := make([]int, n+1)
	for i := 1; i <= VMAX; i++ {
		C[i] += C[i-1]
	}

	for j := 1; j <= n; j++ {
		B[C[A[j]]] = A[j]
		C[A[j]]--
	}
	return B
}

func String(B []int) string {
	// trim junk element B[0] when stringifying the entire elements of progression.
	return strings.Trim(fmt.Sprint(B[1:])[1:], "[]")
}



Measured memory_bytes: 74232