akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include <bits/stdc++.h>
using namespace std;

#define deb(x) cout << #x << " is " << x << "\n"
#define int long long
#define mod 1000000007
#define PI acos(-1)

void solve() {
	int n;
	cin >> n;
	vector<int> arr(n);
	for(auto &ele : arr)
		cin >> ele;
	int ans = 0;
	for(int i = 0; i < n - 1; i++) {
		if(arr[i + 1] < arr[i]) {
			ans += (arr[i] - arr[i + 1]);
			arr[i + 1] = arr[i];
		}
	}
	cout << ans;
}

int32_t main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int tc = 1;
	// cin >> tc;
	while(tc--) {
	    solve();
	}
	return 0;
}


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

using namespace std;

#define fastio cin.tie(NULL); cout.tie(NULL); ios_base::sync_with_stdio(0)
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> matrix;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define int ll
#define tcase int t; cin>> t; for( ; t; --t)
#define s second
#define endl '\n'
const int MAX = 1e6+1;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1);
const double DEG = 180/PI;
const int MOD = 1e9+7;
int mod(int x, int m){ if(x >= 0) return x % m; if(-x < m) return m-(-x); return mod(x%m, m);}
int gcd (int a, int b) {while(b){a = mod(a, b); swap(a, b);} return a;}
int lcm (int a, int b) {return a / gcd(a, b) * b;}
int fexp(int base, int exp, int m){
	int total = 1;
	while(exp > 0){
		if(exp % 2 == 1){
			total = mod(((mod(total, m)) * (mod(base, m))), m);
			exp--;
		}
		base= mod((mod(base, m) * mod(base, m)), m);
		exp /= 2;
	}
	return mod(total, m);
}

int n;

int32_t main(){
	fastio;
	string s;
	cin >> n;
	cin>> s;

	int ans = 1;
	for(int i = 0; i<s.size()-1; ++i)
		if(s[i]!=s[i+1]) ans++;
	cout<< ans<< endl;

	return 0;
}


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

int main()
{
    int numPoint;
    int numDim;

    cin >> numPoint >> numDim;

    vector<vector<int>> point(numPoint + 1, vector<int>(numDim + 1, 0));

    for (int i = 1; i <= numPoint; i++)
    {
        for (int j = 1; j <= numDim; j++)
        {
            cin >> point.at(i).at(j);
        }
    }

    int ans = 0;

    //ここから距離を計算。
    for (int i = 1; i <= numPoint; i++)
    {
        for (int j = i + 1; j <= numPoint; j++)
        {
            //点iと点jの距離を計算する
            float distance;
            float temp0 = 0;
            for (int k = 1; k <= numDim; k++)
            {
                float temp = point.at(i).at(k) - point.at(j).at(k);
                temp0 = temp0 + (temp * temp);
            }

            distance = sqrt(temp0);

            int distanceInteger = distance;

            float distanceFloat = distanceInteger;

            if(distance - distanceFloat == 0)
            {
                ans++;
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import*
from numpy import*
n,*a=map(int,open(0).read().split())
a=array(a)
count=0
ans=0
while 1:
    if sum(a)==0:break
    count=min(a[a!=0])
    ans+=count*sum(k for k,v in groupby(a>0)if k==True)
    a=a-min(a[a!=0])
    a[a<0]=0
print(ans)

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

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var weathers = new string[]{"Sunny", "Cloudy", "Rainy", "Sunny"};
            var w = Console.ReadLine().Trim();
            var i = Array.FindIndex(weathers, s => s.Equals(w));

            Console.WriteLine(weathers[i+1]);
        }
    }
}


Measured memory_bytes: 11092
A, B = map(int,input().split())
result = 'Draw'
if A > B:
    if B == 1:
        result = 'Bob'
    else:
        result = 'Alice'
elif A<B:
    if A==1:
        result = 'Alice'
    else:
        result = 'Bob'
print(result)

Measured memory_bytes: 3064
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <stack>
#include <utility>
#include <tuple>
using namespace std;

const double pi = acos(-1);
#define nyan cout << "(=^•ω•^=)" << endl;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define loop while(true)

int ans;
int n,k;
int w[200000];

bool judge(int p){
    int i=0;
    for(int j=0;j<k;j++){
        int weight=0;
        while(weight+w[i]<=p){
            weight+=w[i];
            i++;
            if(i==n)return true;
        }
    }
    return false;
}

int l=1,r=1000000000;

signed main(){
    cin>>n>>k;
    rep(i,n)cin>>w[i];
    while(r-l>1){
        if(judge((l+r)/2))r=(l+r)/2;
        else l=(l+r)/2;
    }
    if(judge(l))ans=l;
    else ans=r;
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3908
#include <bits/stdc++.h>
using namespace std;
#define int                     long long   
#define double                  long double
#define endl                    "\n"
#define pb                      push_back
#define PI                      3.1415926535897932384626433832795l
#define F                       first
#define S                       second
#define mp                      make_pair
#define f(i,n)                  for(int i=0;i<n;i++)
#define fastio                  ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(v)                  (v).begin(),(v).end()
#define rall(v)                 (v).rbegin(),(v).rend()
#define gcd(a,b)                __gcd((a),(b))
#define fill(a,value)           memset(a,value,sizeof(a));
#define minn(v)                 *min_element(v.begin(), v.end());
#define maxx(v)                 *max_element(v.begin(), v.end());
#define print(x)                cout<<(x)<<endl;
#define sum(v)+x                accumulate(v.begin(), v.end(),x);
#define debug(x)                cout<<#x<<'='<<(x)<<endl;
typedef pair<int,int>           pii;
typedef vector<int>             vi;
signed main() 
{
    fastio;
    cout << fixed << setprecision(12);
    int n;
    cin>>n;
    vi a(n);
    f(i,n)cin>>a[i];
    int arr[n+1]={0};
    f(i,n)arr[a[i]]++;
    int choices[n+1]={0};
    for(int i=1;i<=n;i++)
    {
        choices[i]=(arr[i]*(arr[i]-1))/2;
    }
 
    int total=0;
    for(int i=1;i<=n;i++)
    {
        total+=choices[i];
    }
    for(int i=0;i<n;i++)
    {
        int x=total-choices[a[i]]+((arr[a[i]]-1)*(arr[a[i]]-2))/2;
        print(x)
    }
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 7948
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
int A,B,ans;
int main(){
	scanf("%d%d",&A,&B);
	if(B==1){
		puts("0");return 0;
	}
	ans=(B-2)/(A-1)+1;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
x, y = map(int, input().split())
mod = 10**9 + 7
if (2*x-y)%3 == 0 and (2*y-x)%3 == 0 and 2*x-y >= 0 and 2*y-x >= 0:
    u = (2*x-y)//3
    v = (2*y-x)//3
    n = u + v
    x = 1
    y = 1
    for i in range(u):
        x = x*(n-i)%mod
        y = y*(i+1)%mod
    print((x * pow(y, mod-2, mod))%mod)
else:
    print(0)

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

const int MAXN = 2e3 + 5;

int N;
int a[MAXN];
bool dp[MAXN][100 * MAXN];

void load() {
	scanf("%d", &N);
	for (int i = 1; i <= N; i++)
		scanf("%d", a + i);
}

int solve() {
	dp[0][50 * MAXN] = true;
	for (int i = 1; i <= N; i++)
		for (int j = 0; j < 100 * MAXN; j++)
			if (dp[i - 1][j]) {
				if (j + a[i] < 100 * MAXN)
					dp[i][j + a[i]] = true;
				if (j >= a[i])
					dp[i][j - a[i]] = true;
			}
		
	int diff = 100 * MAXN;
	for (int i = 0; i < 100 * MAXN; i++)
		if (dp[N][i])
			diff = min(diff, abs(i - 50 * MAXN));
	
	int sum = 0;
	for (int i = 1; i <= N; i++)
		sum += a[i];
	
	return (sum + diff) / 2;
}

int main() {
	load();
	printf("%d\n", solve());
	return 0;
}

Measured memory_bytes: 390272
N = int(input())
T, A = map(int, input().split())
H = list(map(int, input().split()))

min_A = 100000
min_num = 0
for i in range(len(H)):
    t = T - H[i] * 0.006
    if min_A > abs(t - A):
        min_A = abs(t - A)
        min_num = i + 1

print(min_num)

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


def main():
    from collections import Counter

    s = Counter(input())

    if len(s.keys()) == 2:
        count = 0

        for v in s.values():
            if v == 2:
                count += 1

        if count == 2:
            print('Yes')
        else:
            print('No')
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<55;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n;

int main(){
	cin>>n;
	cout<<n/3<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include <algorithm> 
using namespace std;

# define p(s) std::cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) std::cout << (j ? "Yes" : "No") << endl;

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

    for(int i=0;i*4<=n;i++){
        if((n-i*4)%7==0){
            Yes(1)
            return 0;
        }
    }
    Yes(0)

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define debug(x) (cout << "#x = " << (x) << endl)
#define R register
#define For(i, j, k) for(R int i = (j), ED = (k); i <= ED; ++i)
#define Rep(i, j, k) for(R int i = (j), ED = (k); i >= ED; --i)
#define Cross(i, j, k) for(R int i = (j); i; i = (k))
using namespace std;
typedef long long ll;
const ll N = 21;
const ll M = (1 << 16) + 3;
const ll INF = 5e16, P = 1e9 + 7;

namespace IO {
	
	inline char gc() {
		static char buf[100000], *p1 = buf, *p2 = buf;
		return (p1 == p2) && (p2 = (p1 = buf) + 
			fread(buf, 1, 100000, stdin), p1 == p2)? EOF: *p1++;
	}
	
	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; int f = 0; char dd;
		for (; !isdigit(ch); dd) f ^= (ch == '-');
		for (; isdigit(ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd
	
	inline void write ( ll x ) {
		if (x < 0) x = -x, putchar('-');
		if (x > 9) write(x / 10); putchar(x % 10 | 48);
	}
	
	inline void wrn ( ll x ) { write(x), putchar(' '); }
	
	inline void wln ( ll x ) { write(x), putchar('\n'); }
	
	inline void wlnn ( ll x, ll y ) { wrn(x), wln(y); }
	
}

using IO::wln;
using IO::read;

namespace Cesare {
	
	/*
		设 f[S]	表示不合法的子树的状态为 S 的方案数。
	*/
	
	ll Ans, a[N];
	ll n, m, k, inv[M], fac[M], f[M];
	
	inline ll power ( ll a, ll b, ll res = 1 ) {
		for (; b; b >>= 1, a = a * a % P) 
			res = (b & 1)? res * a % P: res;
		return res;
	}
	
	inline void Init (const int n = (1 << 16)) {
		fac[0] = 1;
		For ( i, 1, n ) fac[i] = fac[i - 1] * i % P;
		inv[n] = power(fac[n], P - 2);
		Rep ( i, n - 1, 0 ) inv[i] = inv[i + 1] * (i + 1) % P;
	}

	inline void Add ( ll &a, ll b ) {
		(a += b) >= P && (a -= P);
	}

	inline ll C ( ll n, ll m ) {
		return n < m? 0: fac[n] * inv[m] % P * inv[n - m] % P;
	}
	
namespace Subtask1 {
	
	inline void Solve() {
		wln(fac[1 << n]), exit(0);
	}
	
}

namespace Subtask {

	inline ll Count ( ll x, ll res = 0 ) {
		for (; x; x -= lowbit(x)) ++res;
		return res;
	}

	inline void Solve() {
		f[0] = 1;
		ll Max = (1 << n) - 1;
		reverse(a + 1, a + m + 1);
		For ( i, 1, m ) Rep ( S, Max, 0 ) if (f[S]) 
			For ( j, 0, n - 1 ) if (!(S & (1 << j))) {
				ll Way = C(Max + 1 - a[i] - S, (1 << j) - 1);
				Add(f[S | (1 << j)], f[S] * Way % P * fac[1 << j] % P);
			}
		For ( S, 0, Max ) 
			Add(Ans, ((Count(S) & 1)? -1: 1) * f[S] * fac[Max ^ S] % P);
		wln((Ans * (1 << n) % P + P) % P), exit(0);
	}

}

	int main() {
		Init();
		n = read(), m = read();
		For ( i, 1, m ) a[i] = read();
		
		if (m == 0) Subtask1 :: Solve();
		else Subtask :: Solve(); return 0;
	}
	
}

int main()
{
	// freopen("dicky.in", "r", stdin);
	// freopen("dicky.out", "w", stdout);
	
	return Cesare :: main();
}

/*

*/





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

using namespace std;

int main()
{
    const long double pi=atan(1)*4;
    long double a,b,x;
    cin >> a >> b >> x;
    long double l=0,r=pi/2;
    long double cs=atan(b/a);
    for(int i=0;i<1000;i++)
    {
        long double m=(l+r)/2;
        long double volume;
        if(m<=cs)
        {
            long double d=a*tan(m);
            volume=a*a*b-d*a*a/2;
        }
        else
        {
            long double e=b/tan(m);
            volume=e*b*a/2;
        }
        if(volume>=x) l=m;
        else r=m;
    }
    cout << fixed << setprecision(14) << l*180/pi << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define MP make_pair
#define PB push_back

using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;

int read(){
	int i;
	scanf("%d",&i);
	return i;
}

struct Edge{
	int a,b;
};

bool used[114514],cur[114514];
vi g[114514];

int main(){
	int n=read(),m=read();
	map<int,vector<Edge>> es;
	REP(i,m){
		int a=read()-1,b=read()-1,t=read();
		es[t].PB(Edge{a,b});
	}
	int ans=-1;
	cur[0]=true;
	for(auto kv:es){
		queue<int> q;
		for(auto e:kv.second){
			g[e.a].PB(e.b);
			if(cur[e.a]&&!used[e.a]){
				used[e.a]=true;
				q.push(e.a);
			}
		}
		while(!q.empty()){
			int v=q.front();q.pop();
			for(auto u:g[v])if(!cur[u]){
				cur[u]=true;
				q.push(u);
			}
		}
		for(auto e:kv.second){
			g[e.a].clear();
			used[e.a]=false;
		}
		if(cur[n-1]){
			ans=kv.first;
			cur[n-1]=false;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 23832
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n; string s;
	cin>>s;
	n=s.size();
	int ans=0;
	rep(i,100000){
		i=max(0,i);
		if(i+1>=s.size())break;
		if(s[i]!=s[i+1]){
			ans++;
			s=s.substr(0,i)+(i+1>=s.size()?"":s.substr(i+2));
			i-=2;
		}
	}
	puta(ans*2);
	return 0;
}

Measured memory_bytes: 768
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String moji = sc.next();
        String[] ar = moji.split("");
        Arrays.sort(ar);
        if((ar[0].equals(ar[1]))  && (ar[2].equals(ar[3])) && (ar[0].equals(ar[3]))){
            System.out.println("No");
        }
        else if((ar[0].equals(ar[1])) && (ar[2].equals(ar[3]))){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}


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

int main() {
  int n; cin >> n;
  vector<int> a(n-1);
  rep(i, n - 1){
    cin >> a[i];
  }

  vector<int> tmp(n);
  rep(i, n - 1){
    tmp[a[i] - 1] += 1;
  }

  rep(i, n){
    cout << tmp[i] << endl;
  }
}

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

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

    int a_cnt=0, b_cnt=0, bar_cnt=0;
    int length = s.size();
    for(int i=0; i<length; i++){
        if(s.at(i) == '-'){
            bar_cnt++;
            continue;
        }
        if(bar_cnt < 1) a_cnt++;
        else b_cnt++;
    }
    if(bar_cnt != 1){
        cout << "No\n";
    }
    else if(a_cnt == a && b_cnt == b){
        cout << "Yes\n";
    }
    else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cinf(n,x,y,z) for(int i=0;i<(n);i++) cin >> x[i]>>y[i]>>z[i];
typedef long long int ll;
using namespace std;

int main(){
	string s; cin>>s;
	bool a= false;
	if(s == "AKIHABARA") a= true;
	if(s == "KIHABARA") a= true;
	if(s == "AKIHBARA") a= true;
	if(s == "AKIHABRA") a= true;
	if(s == "AKIHABAR") a= true;
	if(s == "KIHBARA") a= true;
	if(s == "KIHABRA") a= true;
	if(s == "KIHABAR") a= true;
	if(s == "AKIHBRA") a= true;
	if(s == "AKIHBAR") a= true;
	if(s == "AKIHABR") a= true;
	if(s == "KIHBRA") a= true;
	if(s == "KIHBAR") a= true;
	if(s == "KIHABR") a= true;
	if(s == "AKIHBR") a= true;
	if(s == "KIHBR") a= true;
	cout << (a?"YES":"NO") <<endl; 
}


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

int main() {
  int n, a, b, c, d;
  cin >> n;
  d = n % 10;
  c = n % 100 / 10;
  b = n % 1000 / 100;
  a = n / 1000;
  if (a == b && b == c) {
	cout << "Yes" << endl;
  }
  else if (b == c && c == d) {
	cout << "Yes" << endl;
  }
  else {
	cout << "No" << endl;
  }
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const double PI = acos(-1);  

int main(){
  string s; cin >> s;
  int ans=0;
  for(int i=0; i<s.size(); i++)
    if(s[i]=='+') ans += 1;
    else ans -= 1;
  cout << ans << endl;
}


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

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    os << "{";
    for (int i = 0; i < (int)vec.size(); ++i) {
        os << vec[i] << (i + 1 == (int)vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, pair<T, U>& pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
template <typename T, typename U>
ostream& operator<<(ostream& os, map<T, U>& map_var) {
    os << "{";
    for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
        os << "(" << itr->first << ", " << itr->second << ")";
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T>& set_var) {
    os << "{";
    for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
        os << *itr;
        ++itr;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
void dump_func() {
    cerr << "\n";
}
template <class Head, class... Tail>
void dump_func(Head&& head, Tail&&... tail) {
    cerr << head;
    if (sizeof...(Tail) == 0) {
        cerr << " ";
    } else {
        cerr << ", ";
    }
    dump_func(std::move(tail)...);
}
#define dump(...) cerr << "[" << to_string(__LINE__) << "]"        \
                       << "    " << string(#__VA_ARGS__) << " = ", \
                  dump_func(__VA_ARGS__)

using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<double>;
using VVI = vector<VI>;
using VVL = vector<VL>;
using PI = pair<int, int>;
using PL = pair<ll, ll>;
using VPI = vector<PI>;
using VPL = vector<PL>;
using VS = vector<string>;

#define ln '\n'
#define REP(t, n) for (int t = 0; t < (n); ++t)
#define FOR(t, a, b) for (int t = (a); t <= (b); ++t)
#define FORR(t, a, b) for (int t = (a); t >= (b); --t)
#define ALL(c) (c).begin(), (c).end()
#define CAUTO const auto&

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

    int n;
    cin >> n;
    VI A(n);
    REP(i, n) {
        cin >> A[i];
    }
    VI even(n), odd(n);
    even[0] = A[0];
    odd[0] = -A[0];
    FOR(i, 1, n - 1) {
        if (i % 2 == 1) {
            even[i] = even[i - 1] - A[i];
            odd[i] = odd[i - 1] + A[i];
        } else {
            even[i] = even[i - 1] + A[i];
            odd[i] = odd[i - 1] - A[i];
        }
    }
    REP(i, n) {
        int ans = 0;
        if (i % 2 == 0) {
            if (i == 0)
                ans = even[n - 1];
            else
                ans = even[n - 1] + 2 * odd[i - 1];
        } else {
            ans = odd[n - 1] + 2 * even[i - 1];
        }
        cout << ans << " ";
    }
    cout << ln;

    return 0;
}


Measured memory_bytes: 2560
#include <iostream>
#include <cmath>

using namespace std;

string s;

int main () {
	cin>>s;
	int br=0;
	for(int i=0;i<s.length();i++){
		if(s[i]=='x') br++;
	}
	if(br>=8) cout<<"NO";
	else cout<<"YES";


return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define lb(v,n) lower_bound(v.begin(),v.end(),n)
#define ub(v,n) upper_bound(v.begin(),v.end(),n)
#define mae(v) max_element(v.begin(),v.end())
#define mie(v) min_element(v.begin(),v.end())
#define INF 0x7FFFFFFF
#define mod 1000000007
typedef long long ll;
////////////////////////////////////////////////////////////

int main(){
	int n;

	while( cin >> n ){
		ll cnt = 0;
		rep(a,0,10){
			rep(b,0,10){
				rep(c,0,10){
					
					int d = n - a - b - c;
					if( d>=0 && d < 10 ){
						cnt++;
						//cout << "a:" << a << " b:" << b << " c:" << c << endl;
					}
				}
			}
		}

		cout << cnt << endl;
	}

	ret 0;
}


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

using namespace std;

int main()
{
    int N, M, X;
    cin >> N >> M >> X;
    int c[N];
    int a[N][M];
    for (int i = 0; i < N; i++) {
        cin >> c[i];
        for (int j = 0; j < M; j++)
            cin >> a[i][j];
    }

    int ans = 100000000;
    int money;
    for (int i = 1; i < pow(2, N); i++)
    {
        money = 0;
        int skill[M] = {0};
        for (int j = 0; j < N; j++)
        {
            if (i & (1 << j)) {
                money += c[j];
                for (int k = 0; k < M; k++)
                    skill[k] += a[j][k];
            }
        }
        int flag = 1;
        for (int k = 0; k < M; k++)
        {
            if (skill[k] < X) {
                flag = 0;
                break;
            }
        }
        if (flag == 1 && ans > money)
            ans = money;
    }
    if (ans == 100000000)
        cout << "-1" << '\n';
    else
        cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3996
import java.util.*;

class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    long n=sc.nextLong();
    long m=sc.nextLong();
    if(Math.abs(n-m)>=2){
      System.out.println(0);
      return;
    }
    long ans=(calc(n)*calc(m))%1000_000_007;
    if(n==m){
      System.out.println((ans*2)%1000_000_007);
    }else{
      System.out.println(ans);
    }
  }
  static long calc(long n){
    long res=1;
    for(long i=1;i<=n;i++){
      res*=i;
      res%=1000_000_007;
    }
    return res;
  }
}


Measured memory_bytes: 21844
n, k = map(int, input().split())
a = list(map(int, input().split()))

d = [0] * 40
for i in range(n):
  for j in range(40):
    if a[i] & (1<<j):
      d[j] += 1
s = 0
for i in range(39,-1,-1):
  if s + 2**i > k:
    continue
  if d[i] > n//2:
    continue
  s += 2**i

res= 0
for i in range(n):
  res += a[i] ^ s
print (res)


Measured memory_bytes: 87292
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int r; cin>>r;
    cout << r*r << endl;
    return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.algorithm;
import std.math;
import std.conv;
import std.string;

T readNum(T)(){
  return readStr.to!T;
}

T[] readNums(T)(){
  return readStr.split.to!(T[]);
}

string readStr(){
  return readln.chomp;
}

void main(){
  auto abck = readNums!int;
  int qty, ret;

    if(abck[0] > 0 && qty != abck[3]){
      ret += min(abck[3] - qty, abck[0]);
      qty += min(abck[3] - qty, abck[0]);
    }

    if(abck[1] > 0 && qty != abck[3]){
      qty += min(abck[3] - qty, abck[1]);
    }

    if(abck[2] > 0 && qty != abck[3]){
      ret -= min(abck[3] - qty, abck[2]);
      qty += min(abck[3] - qty, abck[2]);
    }
  writeln(ret);
}


Measured memory_bytes: 3144
#include <stdio.h>

int main() {
  int n, ans = 0;
  scanf("%d", &n);
  int V[n];
  for (int i = 0; i < n; i++) {
    scanf("%d", V+i);
  }
  for (int i = 0; i < n; i++) {
    int s;
    scanf("%d", &s);
    s = V[i] - s;
    if(s > 0){
      ans += s;
    }
  }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
def func():
    N = int(input())
    A = list(map(lambda x: int(x) -1, input().split()))
    B = list(map(int, input().split()))
    C = list(map(int, input().split()))

    prevIdx = -1
    value = 0
    for i in A:
        value += B[i]
        if prevIdx != -1 and prevIdx + 1 == i:
            value += C[i-1]
        
        prevIdx = i

    print(value)

if __name__ == '__main__':
    func()


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define INF (int)1e9+4
#define INFL (ll)1e18+4
#define md (int)1e9+7
#define mx 10000000  //use fixed<<setprecion
#define mk make_pair
#define pi pair<int,int>
#define ss second
#define ff first
#define pb emplace_back
#define onell(x) __builtin_popcountll(x)
#define one(x) __builtin_popcount(x)
#define maxi(a) *max_element(a.begin(),a.end());
#define mini(a) *min_element(a.begin(),a.end());
#define all(s) s.begin(),s.end()
#define rall(x) (x).rbegin(), (x).rend()
#define trav(x, a) for (auto& x: a)
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define rf(i,a,b) for(int i=a;i>=b;i--)
#define sz(x) ((long long)x.size())
#define mez(s) memset(s,0,sizeof s)
#define mex(s) memset(s,-1,sizeof s)
#define metr(s) memset(s,true, sizeof s)
typedef vector<int> vi;
typedef vector<ll>vl;
typedef map<int,int> mp;
typedef queue<int> que;
typedef vector<pi> vp;
const int mxn=2e5+50;
vi ans;int d=0;
vi adj[mxn];bool vis[mxn];
void dfs(int node){
	vis[node]=1;
	d++;
	for(int x:adj[node]){
		if(!vis[x]){
			dfs(x);
		}
	}
}
void solve(){
int n=0,x=0,y=0,z=0,m=0,k=0;ll an=0;
cin>>n>>m;
rep(i,0,m){
	cin>>y>>z;
	adj[y].pb(z);
	adj[z].pb(y);
}
fr(i,1,n){
	if(!vis[i]){
		d=0;
		dfs(i);
		ans.pb(d);
	}
}
sort(all(ans));
//rep(i,0,sz(ans))cout<<ans[i]<<" ";
//cout<<"\n";
rep(i,0,sz(ans)-1){
	an+=(ans[i+1]-ans[i]);
}
an+=ans[0];
cout<<an;
}
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t=1;
  //cin>>t;
  while(t--){
  	solve();
  }
  return 0;
}


Measured memory_bytes: 21036
import scala.io.StdIn.readInt

object Main {
  val r = Array(2,3,5,7)

  def twoPow(d:Int,s:Int):(Int,Int) = {
    if(d%2 == 1) (d,s)
    else twoPow(d>>1,s+1)
  }

  def maybePrime(i:Int,d:Int,s:Int, n:Int):Boolean = {
    if(i>3) true
    else {
      val a = r(i)
      val x = BigInt(a).modPow(d,n).toLong

      if(x==1 || x==n-1) maybePrime(i+1,d,s,n)
      else repeat(s-1,BigInt(x).modPow(2,n).toLong, i, d, s, n)
    }
  }

  def repeat(j:Int, x:Long, i:Int, d:Int, s:Int, n:Int):Boolean = {
    if(j==0) false
    else if(x==1) false
    else if(x==n-1) maybePrime(i+1,d,s,n)
    else repeat(j-1,BigInt(x).modPow(2,n).toLong,i,d,s,n)
  }

  def isPrime(n:Int):Boolean = {
    if(n<3000) (2 to Math.sqrt(n).toInt).forall(n%_ != 0)
    else if(n%2==0) false
    else {
      val (d,s) = twoPow(n-1,0)
      maybePrime(0,d,s,n)
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    println((0 until n).count{ _=> {
        val m = readInt; isPrime(m)
      }
    })
  }
}

Measured memory_bytes: 67048
#include <bits/stdc++.h>
using namespace std;
#define SELECTER(_1, _2, _3, SELECT, ...) SELECT
#define REP1(i, n) for(int i=0; i<n; i++)
#define REP2(i, a, b) for(int i=a; i<b; i++)
#define REP(...) SELECTER(__VA_ARGS__, REP2, REP1,) (__VA_ARGS__)
#define MOD 1'000'000'007

template <class T> ostream& operator<<(ostream& os, const vector<T>& v){ os << "{"; for(size_t i=0; i<v.size(); i++) os << v[i] << (i+1==v.size() ? "" : ", "); os << "}"; return os; }
template <class T, class U> ostream& operator<<(ostream& os, const pair<T, U>& p){ return os << "{" << p.first << ", " << p.second << "}"; }

int main(){
    int N;
    cin >> N;
    vector<double> x(N), y(N);
    REP(i, N) cin >> x[i] >> y[i];

    double ans = 0;
    REP(i, N) REP(j, i+1, N){
        double dx = x[i]-x[j];
        double dy = y[i]-y[j];
        double dist = sqrt(dx*dx+dy*dy);
        ans += dist;
    }
    double fac[10];
    fac[0] = 1;
    for(int i=1; i<10; i++) fac[i] = fac[i-1]*i;
    double a = 2*(N-1)*fac[N-2];
    double b = fac[N];
    ans *= a/b;
    cout << fixed << setprecision(32) << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9+7;
typedef long long ll;

ll a[1001];

void fof(long long n){
  ll b = 2;
  /*for(int i = 0;i < n+1;i++){
    a[i] = 0;
    }*/
  while(n >= b){
    if(n%b == 0){
      while(n%b == 0){
	a[b]++;
	n /= b;
      }
    }
    b++;
  }
}

int main(){
  long long n;
  cin >> n;
  for(int i = 0;i < n+1;i++){
    a[i] = 0;
  }
  
  for(int i = n;i > 0;i--){
    fof(i);
  }
  
  /*for(int i = 0;i < n+1;i++){
    cout << a[i] << endl;
    }*/
  ll sum = 1;
  REP(i,n+1){
    if(a[i] != 0){
      sum = sum * (a[i]+1);
      sum %= INF;
    }
  }
  cout << sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> Pint;
typedef pair<int64_t, int64_t> Pll;


int main() {
    int N, H, W, ans = 0;
    cin >> N >> H >> W;
    for (int i = 0; i < N; i++){
        int a, b;
        cin >> a >> b;
        if (a >= H && b >= W){
            ans++;
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using intl = long long;
using itnl = long long;
using itn = int;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define rrep(i, n) for(intl i = (intl)(n) - 1; i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define rrepi(i, a, b) for(intl i = (intl)(a); i > (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define itn int
#define double ld
#define pb push_back
#define mp make_pair
#define pii pair<intl,intl>
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool f){cout << (f ? "Yes" : "No") << endl;}
void fp(bool f, string s, string t){cout << (f ? s : t) << endl;}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl lcm(intl a,intl b){
    return a / gcd(a, b) * b;
}
intl digit10(intl a){
    intl b = 0;
    do{
        a /= 10;
        b++;
    }while(a);
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    intl n,m;
    cin >> n >> m;
    cout << max(0,n - 2 * m) << endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int C=1, I;
  int ans=0;
  for (int i=1; i<=N; i++) {
    I=i;
    C=1;
    while (I/10>0) {
      I/=10;
      C++;
    }
    if (C%2==1) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3636
a, b, c, x, y = map(int, input().split())

ans1 = (a * x) + (b * y)
if x > y:
    ans2 = c * (y * 2)
    ans2 += a * (x - y)
else:
    ans2 = c * (x * 2)
    ans2 += b * (y - x)
ans3 = c * (max(x, y) * 2)
    
print(min(ans1, ans2, ans3))


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std; 
#define LIM 1000003

#define M 1000000007
#define inf 99999999999999999LL	//long long inf
typedef long long ll;

#define sc(x) scanf("%d",&x);
#define sc2(x,y) scanf("%d%d",&x,&y);
#define sc3(x,y,z) scanf("%d%d%d",&x,&y,&z);
#define scl(x) scanf("%lld",&x);
#define scl2(x,y) scanf("%lld%lld",&x,&y);
#define scl3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z);

#define pb push_back
#define mp make_pair
#define fi first
#define se second 
ll power(ll x,ll y,ll z) {	ll ret = 1;	while(y > 0) {	if(y & 1) ret = (ret*x)%z;x = (x*x)%z;y >>= 1;}return ret;}


#define debug(x) cerr<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define debug4(x,y,z,a) cerr<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\t"<<#a<<" :: "<<a<<"\n";




int n, k ;
int f(int x) {
	if( x >=1 && x <= 12)
		return 1;
	return 0;
}
int main() {
	int i, j, t;
	string s;
	cin >> s ;
	int a = s[0]-'0' ;
	int b = s[1]-'0' ;
	int c = s[2]-'0' ;
	int d = s[3]-'0' ;
	int emp = a*10 + b ;
	int temp = c*10+d ;
	//debug2(emp, temp);
	int xx = f(emp) ;
	int yy = xx ;
	xx += f(temp) ;

	//debug2(yy, xx) ;
	if(xx == 0) {
		cout << "NA" << endl ;
	}
	else if(xx == 1) {
		if(yy)
			cout << "MMYY" << endl ;
		else
			cout << "YYMM" << endl ;
 	
	}
	else {
		cout << "AMBIGUOUS" << endl ;
	}
	return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template
template <typename T> inline void voutput(T &v){
    rep(i, v.size()){
        if (i) cout << " " << v[i];
        else cout << v[i];
    }
    cout << endl;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    int A, B, Q;
    cin >> A >> B >> Q;
    vector<ll> S(A + 2), T(B + 2), NS(A + 2), NT(B + 2), X(Q);
    S[0] = (1LL << 60) * (-1);
    rep(i, A) {
        cin >> S[i + 1];
    }
    S[A + 1] = 1LL << 60;
    T[0] = (1LL << 60) * (-1);
    rep(i, B) {
        cin >> T[i + 1];
    }
    T[B + 1] = 1LL << 60;
    rep(i, A + 2) NS[i] = -S[i];
    rep(i, B + 2) NT[i] = -T[i];
    reverse(all(NS));
    reverse(all(NT));
    
    rep(i, Q) cin >> X[i];
    rep(i, Q) {
        ll ans = 1LL << 55;
        
        ll tmp = 0;
        ll SL = *lower_bound(all(S), X[i]);
        tmp += abs(SL - X[i]);
        tmp += min(abs(SL - (*lower_bound(all(T), SL))), abs(SL + (*lower_bound(all(NT), -SL))));
        ans = min(ans, tmp);
//        cout << tmp << endl;
        tmp = 0;
        ll SR = -(*lower_bound(all(NS), -X[i]));
        tmp += abs(SR - X[i]);
        tmp += min(abs(SR - (*lower_bound(all(T), SR))), abs(SR + (*lower_bound(all(NT), -SR))));
        ans = min(ans, tmp);
//        cout << tmp << endl;
        tmp = 0;
        ll TL = *lower_bound(all(T), X[i]);
        tmp += abs(TL - X[i]);
        tmp += min(abs(TL - (*lower_bound(all(S), TL))), abs(TL + (*lower_bound(all(NS), -TL))));
        ans = min(ans, tmp);
//        cout << tmp << endl;
        tmp = 0;
        ll TR = -(*lower_bound(all(NT), -X[i]));
        tmp += abs(TR - X[i]);
        tmp += min(abs(TR - (*lower_bound(all(S), TR))), abs(TR + (*lower_bound(all(NS), -TR))));
        ans = min(ans, tmp);
//        cout << tmp << endl;
//        cout << SL << "," << SR << "," << TL << "," << TR <<  endl;
        
        
        output(ans);
    }
    
    return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n, k;
    scanf("%d %d", &n, &k);
    int arr[n];
    for (int i = 0; i < n; i++)
    {
        scanf("%d", &arr[i]);
    }
    sort(arr, arr + n);
    int sum = 0;
    for (int i = 0; i < k; i++)
    {
        sum += arr[i];
    }
    printf("%d\n", sum);
}

Measured memory_bytes: 3820
#include <stdio.h>
#define ll long long

int main(void) {
    ll N, A, B, ab, remainder, b;
    scanf("%lld %lld %lld", &N, &A, &B);
    
    ab = A + B;
    remainder = N % ab;
    b = A * (N / ab);
    if (remainder > 0) {
        if (A < remainder) {
            b += A;
        } else {
            b += remainder;
        }
    }
    
    printf("%lld\n", b);
    return 0;
}

Measured memory_bytes: 128
#include<map>
#include<list>
#include<queue>
#include<iostream>
#include<unordered_set>
#include<set>
#include<vector>
#include<cmath>

#define ull unsigned long long
#define ll long long
#define mp make_pair
#define imei(...)   "[ "<< #__VA_ARGS__ <<" = "<< __VA_ARGS__ <<" ] "

using namespace std;

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

int main(int argc, char *argv[])
{
    char c;
    cin >> c;

    if (c >= 'A' && c <= 'Z')
        cout << "A"<<endl;
    else
        cout <<"a"<<endl;

    return 0;
}


Measured memory_bytes: 3632
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

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

	cout << max({ a + b, a - b, a * b }) << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#define _USE_MATH_DEFINES
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
double mysqrt(double x) {
	double l = 0, r = x;
	for (int i = 0; i < 64; ++i) {
		double m = (l + r) / 2.0;
		if (m*m < x)l = m;
		else r = m;
	}
	return l;
}
///////////////////////////////////////


int main() {
	ll T[2];
	ll A[2], B[2];
	REP(i, 2)cin >> T[i];
	REP(i, 2)cin >> A[i];
	REP(i, 2)cin >> B[i];
	A[0] *= T[0];
	B[0] *= T[0];
	A[1] *= T[1];
	B[1] *= T[1];
	ll P = A[0] - B[0];
	ll S = A[0] + A[1] - B[0] - B[1];
	if ((P > 0 && A[0] + A[1] > B[0] + B[1]) || (P < 0 && B[0] + B[1] > A[0] + A[1])) {
		cout << 0 << endl;
	}
	else if (S == 0) {
		cout << "infinity" << endl;
	}
	else {
		if (P > 0) {
			S *= -1;
			if (P % S == 0) {
				cout << 2 * ll(P / S) << endl;
			}
			else {
				cout<< 1+ll(P/S)*2 << endl;
			}
		}
		else {
			P *= -1;
			if (P % S== 0) {
				cout << 2 * ll(P / S) << endl;
			}
			else {
				cout << 1 + ll(P / S)*2 << endl;
			}
		}
	}
}

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

using namespace std;

#define int long long
#define MOD 1000000007


#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define rrep(i, n) for(int i = (n) - 1; i >= 0; i--)
#define all(i) (i).begin(),(i).end()å
#define rall(i) (i).begin(),(i).end(),greater<int>()


#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T> void print(T x) { std::cout << x << '\n'; }
 
//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

class num{
public:
    int a,b,c;

    num(int _a,int _b,int _c){
        a=_a;
        b=_b;
        c=_c;
    }

    bool operator<(const num& other) const {
		return a < other.a;
	}
   

};


 
signed main(){
 
    int x,y,z,k;
    cin>>x>>y>>z>>k;

    vector<int> a(x);
    vector<int> b(x);
    vector<int> c(x);

    rep(i,x){
        cin >> a[i];
    }
    rep(i,y){
        cin >> b[i];
    }
    rep(i,z){
        cin >> c[i];
    }

    sort(a.begin(),a.end(),greater<int>());
    sort(b.begin(),b.end(),greater<int>());
    sort(c.begin(),c.end(),greater<int>());

    a.pb((int)-1e17);
    b.pb((int)-1e17);
    c.pb((int)-1e17);


    priority_queue<pair<int,num>> pq;
    pq.push(mp(a[0]+b[0]+c[0],num(0,0,0)));

    vector<int> ans;
    set<int> index;

    while(ans.size()<k){
        auto v = pq.top();pq.pop();
        ans.pb(v.first);


         rep(i,3){
        int a2 = v.second.a;
        int b2 = v.second.b;
        int c2 = v.second.c;


       
            if(i==0){a2++;}
            if(i==1){b2++;}
            if(i==2){c2++;}
            int hash = (a2<<20)+(b2<<10)+c2;
            if(index.find(hash)==index.end()){
                index.insert(hash);
                pq.push(mp(a[a2]+b[b2]+c[c2],num(a2,b2,c2)));
            }
        }

    }


    rep(i,k){
        cout << ans[i] <<endl;
    }
 
    return 0;
 
}


Measured memory_bytes: 896
N = gets.to_i
X = gets.strip.split.map(&:to_i)
a = X.sort
b = a[N/2]
c = a[(N/2)-1]

for i in 0..N-1

    if X[i] <= a[(N/2)-1]

        puts b

    else

        puts c

    end

end



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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;

const ll LongINF = 1e13 + 7;
const ll INF = 3981;
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

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;
}
template <class T, class Y>
T GCD(T a, Y b)
{
    if (a < b)
    {
        int c = a;
        a = b;
        b = c;
    }
    if (a % b == 0)
    {
        return b;
    }
    return GCD(b, a % b);
}
template <class T, class Y>
T LCM(T a, Y b) { return (a * b) / GCD(a, b); }
void clear(queue<pair<int, int>> &q)
{
    queue<pair<int, int>> empty;
    swap(q, empty);
} //queueの中身の型は適時変更を忘れない

using vi = vector<int>;
using vii = vector<vi>;

#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define rep(i, n) REP(i, 0, n)
#define pb push_back
#define rv reverse
#define ALL(a) (a).begin(), (a).end()
#define decimal(x) fixed << setprecision(x)

/*
a^n-b^n=(a-b)...より、
*/

int main()
{
    ll x;
    cin >> x;
    for (ll a = -INF; a < INF + 1; a++)
    {
        ll c;
        for (ll b = -INF; b < INF + 1; b++)
        {
            c=-b;
            if (a - b == 0)
                continue;
            if (x == (a - b) * (a * a * a * a + a * a * a * b + a * a * b * b + a * b * b * b + b * b * b * b))
            {
                cout << a << " " << b << endl;
                return 0;
            }
            else if (x == (a - c) * (a * a * a * a + a * a * a * c + a * a * c * c + a * c * c * c + c * c * c * c))
            {
                cout << a << " " << c << endl;
                return 0;
            }
        }
    }
    return 0;
}

//a=97,z=122

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
    int n,k;
    cin >> n >> k;
    int ans = 0;
    int t;
    for(int i = 0;i<n;i++){
        cin >> t;
        if(t>=k) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256