akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;
const int N=300010;
int n,m;
int a[N];
ll ans[N],c[N],f1[N],f2[N],g[N];
inline int gi(){
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
struct Dat {ll k,b;} q[N];
vector <Dat> v[N];
inline ll calc(Dat &A,int x) {return A.k*x+A.b;}
inline bool cross(Dat &A,Dat &B,Dat &C) {
    return (A.b-B.b)*(A.k-C.k)>=(A.b-C.b)*(A.k-B.k);
}
inline void work(ll *f) {
    int tp=1;
    q[1]=(Dat){0,0};
    for(int i=1;i<=n;i++) {
	c[i]=c[i-1]+a[i];
	while(tp>1&&calc(q[tp],i)<=calc(q[tp-1],i)) --tp;
	f[i]=max(f[i-1],calc(q[tp],i)+1LL*i*i-c[i]+i);
	Dat g=(Dat){-2*i,1LL*i*i-i+c[i]+f[i]};
	while(tp>1&&cross(q[tp-1],q[tp],g)) --tp;
	q[++tp]=g;
    }
}
inline void solve(int l,int r) {
    if(l==r) return;
    int mid=(l+r)>>1,tp=0;
    solve(l,mid),solve(mid+1,r);
    for(int i=l-1;i<=mid;i++) {
	Dat g=(Dat){-2*i,1LL*i*i-i+c[i]+f1[i]};
	while(tp>1&&cross(q[tp-1],q[tp],g)) --tp;
	q[++tp]=g;
    }
    for(int i=mid+1;i<=r;i++) {
	while(tp>1&&calc(q[tp],i)<=calc(q[tp-1],i)) --tp;
	g[i]=calc(q[tp],i)+1LL*i*i-c[i]+i+f2[n-i];
    }
    for(int i=r;i>mid;i--)
	ans[i]=max(ans[i],g[i]),g[i-1]=max(g[i-1],g[i]);
    tp=0;
    for(int i=mid;i<=r;i++) {
	Dat g=(Dat){-2*i,1LL*i*i-c[i]+i+f2[n-i]};
	while(tp>1&&cross(q[tp-1],q[tp],g)) --tp;
	q[++tp]=g;
    }
    for(int i=l-1;i<mid;i++) {
	while(tp>1&&calc(q[tp],i)<=calc(q[tp-1],i)) --tp;
	g[i+1]=calc(q[tp],i)+1LL*i*i+c[i]-i+f1[i];
    }
    for(int i=l;i<=mid;i++)
	ans[i]=max(ans[i],g[i]),g[i+1]=max(g[i+1],g[i]);
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi()*2;
    memset(ans,-127,sizeof(ans));
    work(f1),reverse(a+1,a+1+n);
    work(f2),reverse(a+1,a+1+n);
    for(int i=1;i<=n;i++) c[i]=c[i-1]+a[i];
    solve(1,n);
    cin>>m;
    while(m--) {
	int x=gi(),y=gi();
	printf("%lld\n",max(ans[x]-y-y+a[x],f1[x-1]+f2[n-x])>>1);
    }
    return 0;
}

Measured memory_bytes: 25088
#include <bits/stdc++.h>
//#define int long long

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

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

template<typename T,typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v){ t = v; }

template<typename T,typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v){ for(auto &e : t) fill_v(e, v); }

const int INF = (int)1e9;
const LL INFL = (LL)1e18;
const int MOD = 1e9 + 7;

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, k;
    cin >> n >> k;
    cout << (k == 1 ? 0 : n - k) << endl;
}

Measured memory_bytes: 256
while True :
    n = input().split()
    x = int(n[0])
    y = int(n[1])
    if x == 0 and y == 0:
        break
    if x < y:
        print(str(x) + " " + str(y))
    else :
        print(str(y) + " " + str(x))
    


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

#pragma region Macro
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define SORT(v) sort(v.begin(), v.end())
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define vvi vector<vector<int>>
#define chmax(x,y) (x = max(x,y))
#define chmin(x,y) (x = min(x,y))

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

int h, w, k;
int c[6][6];

void solve(){
	#define int ll
	// ここに処理を記述
	// コンパイル時はエイリアス「gpp」--> c++17でコンパイル
	cin >> h >> w >> k;
	// マス目
	rep(i,h){
		rep(j,w){
			char t;
			cin >> t;
			if(t == '#'){
				c[i][j] = 1;
			}
			else{
				c[i][j] = 0;
			}
		}
	}

	// bit全探索
	int black = 0;
	int ans = 0;
	for(int hbit = 0; hbit < (1<<h); ++hbit){
		for(int wbit = 0; wbit < (1<<w); ++wbit){
			black = 0;
			rep(i,h){
				rep(j,w){
					if(!(hbit & (1<<i)) && !(wbit & (1<<j))){
						black += c[i][j];
					}
				}
			}
			if(black == k){
				ans += 1;
			}
		}
	}

	cout << ans << endl;
}

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	
	solve();
	return 0;
}

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

const int MOD=998244353;

ll ppow(ll a,ll b){
	a%=MOD;
	ll res=1;
	while(b){
		if(b&1)res=(res*a)%MOD;
		a=(a*a)%MOD;
		b>>=1;
	}
	return res;
}

ll a[300000];
ll sum[20000000],sum2[2000000];
ll dp[2000000];

int main(){
	int n;cin>>n;
	rep(i,n){
		scanf("%lld",&a[i]);
		(sum[a[i]]+=a[i])%=MOD;
		(sum2[a[i]]+=a[i]*a[i])%=MOD;
	}
	ll t=(MOD+1)/2;
	for(int i=1;i<=1000000;i++){
		for(int j=2*i;j<=1000000;j+=i){
			(sum[i]+=sum[j])%=MOD;
			(sum2[i]+=sum2[j])%=MOD;
		}
		dp[i]=(sum[i]*sum[i]+MOD-sum2[i])%MOD*t%MOD;
	}
	ll ans=0;
	for(int i=1000000;i>=1;i--){
		for(int j=2*i;j<=1000000;j+=i)(dp[i]+=MOD-dp[j])%=MOD;
		(ans+=dp[i]*ppow(i,MOD-2))%=MOD;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

template<typename T>
map<T, ll> factorize(T x) {
	map<T, ll> res;
	for (int i = 2; i * i <= x; i++) {
		while (x % i == 0) {
			x /= i;
			res[i]++;
		}
	}
	if (x != 1) res[x]++;
	return res;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		if (i % 2 == 0) continue;
		map<int, ll> mp = factorize(i);
		int tmp = 1;
		for (auto& c : mp) {
			tmp *= (c.second + 1);
		}
		if (tmp == 8) ans++;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
void main()
{
    long n = readln.chomp.to!long;
    long[] a = readln.split.to!(long[]);

    long psum, msum;
    long pcnt, mcnt;
    foreach (i; 0 .. n)
    {
        psum = psum + a[i];
        msum = msum + a[i];

        if (i & 1)
        {
            if (psum >= 0)
            {
                pcnt += psum + 1;
                psum = -1;
            }
            if (msum <= 0)
            {
                mcnt += msum.abs + 1;
                msum = 1;
            }
        }
        else
        {
            if (psum <= 0)
            {
                pcnt += psum.abs + 1;
                psum = 1;
            }
            if (msum >= 0)
            {
                mcnt += msum + 1;
                msum = -1;
            }
        }
    }

    min(pcnt, mcnt).writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 4340
#pragma once
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	if (N == M) {
		cout << "Yes" << endl;

	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

using namespace std;
typedef int itn;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<vector<int>> VVI;
typedef map<int, int> M;
typedef pair<int, int> P;

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

    string s;
    cin >> s;
    bool f = false;
    if (s[0] == 'A')
    {
        for (int i = 1; i < (int)s.size(); ++i)
        {
            if (isupper(s[i]))
            {
                if ((f == false) && (s[i] == 'C') && (i >= 2) && (i <= ((int)s.size() - 2)))
                {
                    f = true;
                }
                else 
                {
                    cout << "WA" << endl;
                    return 0;
                }
            }
        }
        if (f)
        {
            cout << "AC" << endl;
        }
        else 
        {
            cout << "WA" << endl;
        }
    } else {
        cout << "WA" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define pll pair<ll, ll>
#define str string
#define fi first
#define se second
#define pb push_back
#define SET(a, b) memset(a, b, sizeof(a))
#define eps 1e-6
#define pi atan(1) * 4
#define mod 1000000007
#define inf 1000000000
#define llinf 1000000000000000000
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
#define FORl(i, a, b) for (ll i = (a); i <= (b); i++)
#define FORDl(i, a, b) for (ll i = (a); i >= (b); i--)
using namespace std;
int main () {
  int n, k;
  scanf("%d %d", &n, &k);
  ll ans = 0;
  FOR(i, k, n + 1) {
    ans += 1LL * (n - i + 1) * i + 1;
  }
  printf("%lld\n", ans % mod);
  return 0;
}

Measured memory_bytes: 3760
#include<stdio.h>

void swap(int *x, int *y){
	int temp = *x;
	*x = *y;
	*y = temp;
}

int main(void) {
	int i=0, j, k, n;
	int a[100]={0}, count[100]={0};
	
	while( scanf("%d",&n) != EOF ) {
		int flag=0;
				
		for(j=0; j<=i; j++) {
			if(a[j]==n){
				count[j]++;
				flag=1;
				break;
			}
		}
		if(flag==0) {a[i]=n; count[i]++; i++;}
	}

	for(j=0; j<i; j++) {
		for(k=j; k<i; k++) {
			if(count[j]<count[k]) {
				swap(&count[j],&count[k]);
				swap(&a[j],&a[k]);
			}
		}
	}
	
	int max=count[0];
	i=0;
	while(count[i++]==max);
		
	for(j=0; j<i-1; j++) {
		for(k=j; k<i-1; k++) {
			if(a[j]>a[k]) 
				swap(&a[j],&a[k]);
		}
	}	
	for(j=0;j<i-1;j++)
		printf("%d\n",a[j]);

	return 0;
}

Measured memory_bytes: 596
main :: IO ()
main = do
    [a,b] <- map read . words <$> getLine :: IO [Double]
    let res = [ i | i <- [1..10000]
              , let k = fromIntegral i :: Double
                 in floor (k * 0.08) == floor a 
                 && floor (k * 0.1 ) == floor b ]
    print $ case res of
                [] -> -1
                xs -> minimum xs


Measured memory_bytes: 892
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
           // dp[i+1][j+1] = max(dp[i+1][j+1],dp[i][j+1]);

#define rep(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define rrep(i,a,n) for(int (i)=(a);(i)>=(n);(i)--)

typedef long long ll;

using namespace std;

int gcd(long long int a,long long int b){
    long long int r;
    if(a < b){
        int tmp;
        tmp = a;
        a = b;
        b = tmp;
    }
    while(r != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return r;
}

void Integer_factorization(long long int b,long long int n){
    long long int a = 2;
    long long int count = 0;
    long long int ans = 1;
    long long int ndash = n;
    if(b == 1) cout << n << endl;
    else{
    while(ndash >= a*a){
        if(n % a  == 0){
            count++;
            n/=a;

        if(count % b == 0){
            ans *= a;
        }
        }else{a++;count = 0;}
    }

    cout<<  ans << endl;
    }
}
int linersearch(int s[],int n,int key){

        s[n] = key;
        int j = 0; 
        while(key != s[j]) j++;
        return j != n;
}

int main(){
    int n;
    cin >> n;
    int s[n+1];
    rep(i,0,n) cin >> s[i];
    int q;
    cin >> q;
    int key;
    int sum = 0;

    rep(i,0,q){
        cin >> key;
        if(linersearch(s,n,key))sum++;
    }

    cout << sum << endl;


}


Measured memory_bytes: 3120
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#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__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

int main() {
	ll h, w;
	vector<string> v;
	string s0 = "";

	cin >> h >> w;

	REP(i, w + 2) {
		s0 += "#";
	}

	v.push_back(s0);

	REP(i, h) {
		string s;
		string s1 = "#";
		cin >> s;
		s1 += s;
		s1 += "#";
		v.push_back(s1);
	}

	v.push_back(s0);

	REP(i, v.size()) {
		cout << v[i] << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
main(){
  int i,n;
  scanf("%d",&n);
  double a[n],b[n],c[n],d[n],e[n],f[n];
  for(i=0;i<n;i++)
    scanf("%lf%lf%lf%lf%lf%lf",&a[i],&b[i],&c[i],&d[i],&e[i],&f[i]);
  for(i=0;i<n;i++)
    if((a[i]-d[i])*(a[i]-d[i])+(b[i]-e[i])*(b[i]-e[i])>(c[i]+f[i])*(c[i]+f[i]))
      puts("0");
    else{
      if(sqrt((a[i]-d[i])*(a[i]-d[i])+(b[i]-e[i])*(b[i]-e[i]))+c[i]<f[i]){
    puts("-2");
    continue;
      }
      if(sqrt((a[i]-d[i])*(a[i]-d[i])+(b[i]-e[i])*(b[i]-e[i]))+f[i]<c[i]){
    puts("2");
    continue;
      }
      puts("1");
    }
  return 0;
}

Measured memory_bytes: 616
# https://atcoder.jp/contests/abc109/tasks/abc109_c
# Xを中心にしたときの最大公約数かな
import sys
sys.setrecursionlimit(1 << 25)
read = sys.stdin.readline
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(read())


def ints(): return list(map(int, read().split()))


from functools import reduce
from math import gcd

N, zero = ints()
X = [abs(x - zero) for x in ints()]
# if N == 1:
#     exit(X[0] - zero)
print(reduce(gcd, X))


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

int main() {

	ll n; cin >> n;

	deque<string> d;

	for (ll i = 0; i < n; i++) {
		string a; cin >> a;
		if (i % 2 == 0) {
			d.push_back(a);
		}
		else {
			d.push_front(a);
		}
	}
	if (n % 2 == 0) {
		for (ll i = 0; i < n; i++) {
			cout << d.front() << " ";
			d.pop_front();
		}
		cout << endl;
	}
	else {
		for (ll i = 0; i < n; i++) {
			cout << d.back() << " ";
			d.pop_back();
		}
		cout << endl;

	}

	cout << endl;
	return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <iomanip>
#include <string>
#include <unordered_map>
#include <cmath>

typedef long long ll;
typedef long double ld;

using namespace std;
int main()
{
  ll n, m, a, sum = 0;

  cin >> n >> m;
  for (int i = 0; i < m; i++)
  {
    cin >> a;
    sum += a;
  }

  cout << (n < sum ? -1 : n - sum) << endl;
  return 0;
}


Measured memory_bytes: 3620
//*Sample program for Pointers*/

#include<iostream>
#include<string>
#include <algorithm>


void swap_ref(int &a, int &b) {
  int tmp = a;
  a = b;
  b = tmp;
}

int main()
{
  // 整数の入力
  int n;
  std::cin >> n;
  // スペース区切りの整数の入力
  int a[n];
  for(int i=0;i<n;i++){
    std::cin >> a[i];
    //std::cout << a[i] << std::endl;
  }

  int count[100002];
  for(int i=0;i<100002;i++){
    count[i]=0;
  }

  for(int i=0;i<n;i++){
    count[a[i]] += 1;
    count[a[i]+1] += 1;
    count[a[i]+2] += 1;
  }

  int max = *std::max_element(count, count+100002);
  //int index = distance(a, max);
  std::cout<<max<<std::endl;

  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n, minv=0, maxv=-2000000000;
    cin >> n;
    int r[n];
    for(int i=0;i<n;i++){
        cin >> r[i];
    }
    
    minv = r[0];
    for(int i=1;i<n;i++){
        maxv = max(maxv, r[i]-minv);
        minv = min(minv, r[i]);
    }
    
    cout << maxv << endl;
    
    return 0;
}



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

int main(){
    int n, m;
    while(true){
        cin >> n >> m;
        if(n == 0 && m == 0) return 0;
        vector<int> a(n), b(m);
        int A = 0, B = 0;
        for(int i=0; i<n; i++){
            cin >> a[i];
            A += a[i];
        }
        for(int i=0; i<m; i++){
            cin >> b[i];
            B += b[i];
        }
        bool flag = false;
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(A - a[i] + b[j] == B - b[j] + a[i]){
                    flag = true;
                    cout << a[i] << " " << b[j] << endl;
                    i = n-1;
                    j = m-1;
                }
            }
        }
        if(flag == false) cout << -1 << endl;
    }
}


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

int main() {
	string s;
	while (getline(cin,s)) {
		if (s == "END OF INPUT")break;
		else {
			int sa=0;
			queue<int>q;
			for (int i = 0;i < s.size();i++) {
				if (s[i] != ' ')sa++;
				else {
					q.push(sa);
					sa = 0;
				}
			}
			q.push(sa);

			int b = q.size();

			for (int i = 0;i < b;i++) {
				cout << q.front();
				q.pop();
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3112
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const long long INF = 1LL << 60; //intじゃ扱えないことに注意！
using P = pair<int,int>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++) //範囲外参照とループの初期化に注意！

string f(ll n){
    if(n == 0) return "";
    n--;
    return f(n/26) + string(1, 'a' +n%26);
}
int main() {
    ll n;
    cin >> n;
    cout << f(n) << endl;
    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
using namespace std;
int main()
{
	int n,x;
	cin >> n >> x;
	int m[n];
	int min = 10001;
	int k = n;
	for(int i = 0;i < n;i++){
		cin >> m[i];
		if (min > m[i]){
			min = m[i];
		}
	}	


	int s = 0;
	for(int i = 0;i < n;i++){
		s += m[i];
	}
	x -= s;
	while(1){
		if(x - min >= 0){
			x -= min;
			k++;
		}else {
			break;
		}
	}
	cout << k << 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 a = sc.nextInt();
		int b = sc.nextInt();

		while(a != 0 && b!=0){

			for(int i=1;i<=a;i++){
				for(int j=1;j<=b;j++){
					System.out.printf("#");
				}
					System.out.printf("\n");
			}
			System.out.printf("\n");

			a = sc.nextInt();
			b = sc.nextInt();

		}
		
	}
}


Measured memory_bytes: 61028
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;for(char c;c=gcu(),c!=' '&&c!='\n'&&c!=EOF;)s+=c;return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
	_HT _OUT(H &&h, T... t){out(h);out(t...);}
	template <typename... T> _OUTL(T... t){out(t...);outl();}
	struct range{
		int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
		struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
			it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

struct P { int c, i; };
auto cmp = [](auto a, auto b) {return a.second.c == b.second.c ? a.first < b.first : a.second.c < b.second.c;};

int main() {
	for (int n; (n = in);) {
		vector<int> h(n + 1);
		map<int, P> d;
		for (int &i: h)
			i = in;
		for (int i: range(n)) {
			auto &t {d[h[i + 1] - h[i]]};
			t = {t.c + 1, i};
		}
		if (d.size() == 2) {
			auto t = min_element(begin(d), end(d), cmp)->second;
			outl(t.c == 2 ? h[t.i] : t.i == 0 ? h[0] : h[t.i + 1]);
		} else {
			d.erase(max_element(begin(d), end(d), cmp));
			int i {};
			for (auto j: d)
				i = max(i, j.second.i);
			outl(h[i]);
		}
	}
}


Measured memory_bytes: 2700
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e9;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
vector<pairs> p;


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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}
// ------------------------------------

int main(){
    ll n, a, b;
    cin>>n>>a>>b;
    vector<ll> p(n);
    ll x=0, y=0, z=0;
    for(ll i=0;i<n;++i){
        cin>>p[i];
        if(p[i] <= a){
            x++;
        }else if(p[i] >= b+1){
            z++;
        }else{
            y++;
        }
    }
    ll ans = min(min(x, y), z);
    cout<<ans<<endl;

    return 0;
}

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

int main(){
  int n, k;
  cin >> n >> k;
  if(k == 1) cout << 0 << endl;
  else cout << n-k << endl;
  return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

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

    static class TaskI {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            double[] dp = new double[n + 1];
            dp[0] = 1;
            for (int i = 0; i < n; i++) {
                double p = in.nextDouble();
                for (int j = i + 1; j >= 0; j--)
                    dp[j] = (j == 0 ? 0 : dp[j - 1] * p) + dp[j] * (1 - p);
            }
            double ans = 0;
            for (int heads = 1; heads <= n; heads++) {
                int tails = n - heads;
                if (heads > tails)
                    ans += dp[heads];
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

        public double nextDouble() {
            return Double.parseDouble(next());
        }

    }
}



Measured memory_bytes: 24660
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
#include <iostream>
using namespace std;

int main (){
    string a, b;
    string c;
    cin >> a >> b;
    
    for (int i = 0; i < b.size(); i++) {
        c += a[i];
        c += b[i];
    }
    if (a.size() != b.size()) {
        c += a[a.size() - 1];
    }
    cout << c;
}


Measured memory_bytes: 256
n,m = map(int, input().split())
s = [list(map(int, input().split())) for i in range(m)]
p = list(map(int, input().split()))

x = []
for i in range(2**n):
    x.append(format(i,'0b').zfill(n))

ans = 0
for i in range(2**n):
    for j in range(m):
        b = 0
        for k in range(len(s[j])-1):
            if x[i][s[j][k+1]-1]=='1':
                b+=1
        if b%2!=p[j]:
            break
        if j==m-1:
            ans += 1

print(ans)

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

#define rep(a,b) for(int ii=a;ii<b;ii++)
#define ll long long int
#define test() int tt; cin>>tt; while(tt--) 
#define fst_io ios_base::sync_with_stdio(false);cin.tie(NULL);
#define endl '\n'

int main()
{
  fst_io;
  ll n,c=0;
  cin>>n;
  while(n>c)
    c+=1000;
  cout<<abs(c-n)<<endl;
  return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()		 //sort(all(vi S)) sort(all(string S))
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }

using P = pair<int, int>;		//P.first, P.second
typedef long long ll;
typedef vector<int> vi;
typedef set<int> seti;
typedef vector<string> vs;

const int MOD = 1e9+7;
const int INF = 1e9;
int main() {
    ll N,K;
    cin>>N>>K;
    ll ans = 0;
    vector<ll> A(N);
    rep(i,N)cin>>A[i];
    //O(N^2)
    K%=MOD;
    for(int i = 0; i < N; ++i){
        ll nowA = A[i];
        for(int j = 0; j < N; ++j){
            //cerr<<nowA<<" "<<A[j]<<endl;
            if(nowA>A[j]){
                if(i<j)ans += ((K*(K+1)))/2;
                else ans += K*(K-1)/2;
                ans %= MOD;
            }
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <atcoder/all>
using namespace std;
// using namespace atcoder;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
#define rreps(i, n) for(int i=((int)(n)); i>0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((int)(x).size())
#define pl(s) cout << (s) << "\n";
#define pls(...) {bool space = false; for(auto i : __VA_ARGS__) (cout << (space?" ":"") << i), space = true; cout << "\n";}
#define plexit(s) {cout << (s) << "\n"; exit(0);}
#define yes(s) cout << ((s)?"Yes":"No") << "\n";
#ifdef __LOCAL
#include <dump.hpp>
#define dump(...) DUMPOUT << "  " << string(#__VA_ARGS__) << ": " << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl << "    ", dump_func(__VA_ARGS__)
#else
#define dump(...)
#endif
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
struct IOInit { IOInit() { cin.tie(nullptr); ios::sync_with_stdio(false); dump("READY"); /*cout << unitbuf;*/} } IO_INIT;
using ll = long long; using ull = unsigned long long; using ld = long double;
template<typename T = int> using V = vector<T>; template<typename T = int> using P = pair<T, T>;
using Vi = V<int>; using Vl = V<ll>; using Vd = V<ld>; using VVi = V<Vi>; using VVl = V<Vl>; using Pi = P<int>; using Pl = P<ll>; using Pd = P<ld>;
constexpr ll MOD = 1000000007; constexpr int INF = (1 << 30) - 1; constexpr ll INFL = 1LL << 60; constexpr ld EPS = 1e-12; constexpr ld PI = 3.141592653589793238462643383279;


signed main(void) {
  int n; cin >> n;
  Vl dt(n+1);
  reps(i,n) {
    for(int j = i; j <= n; j += i) dt[j]++;
  }
  ll ans = 0;
  reps(i,n) {
    ll c = n-i;
    ans += dt[c];
  }
  pl(ans)
  return 0;
}


Measured memory_bytes: 11024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    ll H,W;
    cin>>H>>W;
    ll h,w;
    cin>>h>>w;
    cout<<H*W-(H*w+h*W-h*w)<<endl;
}

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

typedef long long ll;

#define pf(n) cout << n << endl
#define ps() cout <<" ";
#define sf(n) cin >> n
#define in(i,n) for (int i = 0; i < n; i++)
#define vi vector<int>
#define vp vector<pair<int, int>>
#define graph vector< vector<int> >
#define vs vector<string>
/**  '' "\n" ^ **/


typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;


int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  vi a(100001);
  for(int i=1;i<=100000;i++)
  {
      if(i>=1&&i<=9)a[i]=a[i-1]+1;
      else if(i>=100&&i<=999)a[i]=a[i-1]+1;
      else if(i>=10000&&i<=99999)a[i]=a[i-1]+1;
      else a[i]=a[i-1];
  }
  int n;
  cin>>n;
  cout<<a[n];
}


Measured memory_bytes: 640
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(N-2):
    for j in range(i+1, N-1):
        for k in range(j+1, N):
            a, b, c = sorted([A[i], A[j], A[k]])
            if a != b and b != c and c < a + b:
                ans += 1
print(ans)

Measured memory_bytes: 9204
#include<iostream>
#include<string>
#include<string.h>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<vector>
#include<utility>
#define FOR(i, a, b) for(int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for(int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;

int main(void) {
	long long int a, b, c;
	long long int p, q, r;
	long long int mini;
	cin >> a >> b >> c;
	if ((a % 2 == 0) || (b % 2 == 0) || (c % 2 == 0)) {
		cout << 0 << endl;
	}
	else {
		p = a*b;
		q = b*c;
		r = c*a;
		mini = p;
		mini = min(mini, q);
		mini = min(mini, r);
		cout << mini << endl;
	}

	
	return 0;
}

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

int main() {
    int H, W;
    string sharp;
    cin >> H >> W;

    sharp = "";
    for (int i = 0; i < W + 2; i++) {
        sharp += "#";
    }
    cout << sharp << endl;

    for (int i = 0; i < H; i++) {
        string str;
        cin >> str;
        cout << "#" << str << "#" << endl;
    }

    cout << sharp << endl;
}


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

#define f first
#define sec second
#define pb push_back
#define endl '\n'
#define all(a) begin(a),end(a)
#define sz(a) (int)(a.size())
#define deb(a) cout << #a << ": " << a << endl;
#define fore(i, a, b) for(int i(a), ThkMk(b); i < ThkMk; ++i)
#define fori(i, a, b) for(int i(a), ThkMk(b); i <= ThkMk; ++i)
#define _ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

typedef long long lli;
typedef unsigned long long ulli;
typedef long double ld;
typedef pair<lli, lli> ii;
typedef vector<lli> vi;

///-----------------------------------------------------------
///-----------------------------------------------------------



///-----------------------------------------------------------

int main()
{   _

    int h, w, k, suma = 0, totalFormas = 0;
    cin >> h >> w >> k;
    vector<int> mat(h, 0);
    for (int i=0; i<h; ++i)
    {
        for (int j=0; j<w; ++j)
        {
            char ch;
            cin >> ch;
            if (ch == '#')
            {
                mat[i] += (1 << j);
                ++suma;
            }
        }
    }
    int TH = (1 << h);
    int TW = (1 << w);
    for (int i=0; i<TH; ++i)
    {
        for (int j=0; j<TW; ++j)
        {
            int quitados = 0;
            for (int k=0; k<h; ++k)
            {
                for (int l=0; l<w; ++l)
                {
                    if (mat[k] & (1 << l) && (i & (1 << k) || j & (1 << l)))
                        ++quitados;
                }
            }
            if (suma - quitados == k)
                ++totalFormas;
        }
    }
    cout << totalFormas << endl;

    return 0;
}

Measured memory_bytes: 3624
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	string s; cin >> s;
	Graph G(10);
	rep(i, 0, s.size()) {
		int x = s[i] - '0';
		G[x].push_back(i);
	}
	int ans = 0;
	rep(i, 0, 10) {
		string a = string('0', 3);
		char ch = '0';
		a[0] = ch + i;
		rep(j, 0, 10) {
			a[1] = ch + j;
			rep(k, 0, 10) {
				a[2] = ch + k;
				int cnt = 0, index = -1;
				rep(l, 0, 3) {
					int x = a[l] - '0';
					for (auto p : G[x]) {
						if (index < p) {
							cnt++;
							index = p;
							break;
						}
					}
				}
				if (cnt == 3)ans++;
			}
		}
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define F first
#define S second
#define endl '\n'
#define MP make_pair
#define pb push_back

using namespace std;

typedef pair<int, int> P;
typedef pair<int, P> i_P;
typedef long long LL;

static const int INF = INT_MAX;
static const int MIN = INT_MIN;
static const LL L_INF = LLONG_MAX;
static const int MOD = 1000000000 + 7;
static const int SIZE = 100005;

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

    int n;
    cin >> n;
    string S, T;
    cin >> S >> T;
    LL res = 3;
    int pos = 0;
    string s, t;

    while( pos < n ) {
        if( pos == n - 1 ) {
            s += S[pos];
            t += T[pos];
            break;

        }
        if( S[pos] == S[pos + 1] ) {
            s += '.';
            t += '.';
            pos += 2;

        } else {
            s += S[pos];
            t += T[pos];
            ++pos;

        }
    }

    pos = 0;
    if( s[0] == '.' ) res = 6;
    while( pos < s.size() - 1 ) {

        if( s[pos] != '.' && s[pos + 1] != '.' || s[pos] != '.' && s[pos + 1] == '.' ) {
            res = res * 2 % MOD;

        } else if( s[pos] == '.' && s[pos + 1] == '.' ) {
            res = res * 3 % MOD;

        }
        ++pos;

    }


    cout << res << endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")

using namespace std;

#define FOR(a,b) for(int a=0;a<b;a++)
#define F0R(a,b,c) for(int a = b; a<=c; a++)
#define f first
#define s second
#define m0(x) memset(x,0,sizeof(x))

typedef pair<int,int> pi;
typedef long long ll;
typedef vector<int> vi;
typedef vector<pi> vpi;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n;
    vi A(n), B(n);
    vi counting(n+1);
    FOR(i,n){
        cin >> A[i];
        counting[A[i]]++;
    }
    FOR(i,n){
        cin >> B[i];
        counting[B[i]]++;
    }
    F0R(i,1,n) if(counting[i] > n){
        cout << "No\n"; return 0;
    }
    int ptr1 = 0, ptr2 = 0;
    vi problem(n+1);
    while(ptr2 < n){
        while(ptr1 < n && A[ptr1] < B[ptr2]) ptr1++;
        if(ptr1 >= n) break;
        if(A[ptr1] != B[ptr2]){
            ptr2++; continue;
        }
        int start = ptr1, en = start;
        while(ptr1 < n && A[ptr1] == B[ptr2]) en = ptr1++;
        int us = ptr2, ue = us;
        while(ptr2 < n && B[ptr2] == B[us]) ue = ptr2++;
        int dif1 = us-en, dif2 = ue-start;
        if(dif1 < 0) dif1 += n;
        if(dif2 < 0) dif2 += n;
//        cerr << dif1 << " " << dif2 << "\n";
        problem[dif1]++;
        problem[dif2+1]--;
        if(dif1 > dif2){
            problem[0]++;
            problem[n]--;
        }
    }
    int found = -1;
    FOR(i,n){
        if(i != 0) problem[i] += problem[i-1];
        if(problem[i] == 0){
            found = i;
            break;
        }
    }
    if(found == -1){
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
    FOR(i,n) cout << B[(i+found)%n] << " ";
    cout << "\n";
    return 0;
}


Measured memory_bytes: 6300
#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 a,b;
    priority_queue <int> q;
    int k;
    cin >> a >> b >> k;
    rep(i,100){
        if(a%(i+1)==0 and b%(i+1)==0){
            q.push(i+1);
        }
    }

    int ans;
    rep(i,k){
        ans=q.top();
        q.pop();
    }

    cout << ans << endl;
    

    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define pb push_back
typedef pair<int, int> ii;
typedef long long ll;
 
int n, x, y, z;
 
const int md = 1e9+7;
 
void add(int &a, int b)
{
	a += b;
	if(a>= md) a-= md;
}
int mul(int a, int b)
{
	return (1LL*a*b)%md;
}
 
int dp[50][2][1<<18];
int pw10[50];

int ok(vector<int> &vec)
{
	vector<int> foo(vec);
	for(int i = 1; i< (int) foo.size(); i++) foo[i] += foo[i-1];
	int check = 0;
	for(int i = 0; i< (int) foo.size(); i++)
	{
		if(foo[i] == x) check += 1;
		if(foo[i] == x+y) check += 2;
		if(foo[i] == x+y+z) check += 4;
	}
	return check;
}
 
vector<int> Dec(int enc)
{
	vector<int> res;
	for(int i = 1; i<= 17; i++)
	{
		if(enc & (1<<i)) res.pb(i);
	}
	for(int i = res.size()-1; i>= 1; i--)
	{
		res[i] -= res[i-1];
	}
	return res;
}

int Enc(vector<int> &dec)
{
	int sm = 0;
	int res = 0;
	for(int x : dec)
	{
		sm += x;
		res += (1<<sm);
	}
	return res;
}

int solve(int u, int fin, int enc)
{
	if(dp[u][fin][enc] != -1) return dp[u][fin][enc];
	
	vector<int> vec = Dec(enc);
	int sum = 0;
	for(int k : vec) sum += k;
	if(sum == x+y+z && ok(vec) == 7) fin = 1;
	if(fin) return pw10[n-u+1];
	if(u == n+1) return 0;
	
	while((sum> x+y && (ok(vec)&2) == 0) || (sum> x && (ok(vec)&1) == 0))
	{
		sum -= vec[0];
		vec.erase(vec.begin());
	}

	int ans = 0;
	for(int num = 1; num<= 10; num++)
	{
		if(num> 7)
		{
			add(ans, solve(u+1, fin, 0));
			continue;
		}
		vector<int> foo(vec);
		foo.pb(num);
		reverse(foo.begin(), foo.end());
		int tmp = sum+num;
		while(tmp> x+y+z)
		{
			tmp -= foo.back();
			foo.pop_back();
		}
		while(foo.back()> x)
		{
			tmp -= foo.back();
			foo.pop_back();
		}
		reverse(foo.begin(), foo.end());
		add(ans, solve(u+1, fin, Enc(foo)));
	}
	return dp[u][fin][enc] = ans;
}
 
int main()
{
	memset(dp, -1, sizeof dp);
	scanf("%d %d %d %d", &n, &x, &y, &z);
	double x = clock();
	pw10[0] = 1;
	for(int i = 1; i<= n; i++) pw10[i] = mul(pw10[i-1], 10); 
	printf("%d\n", solve(1, 0, 0));
	// printf("took %.2lf seconds\n", (clock()-x)/CLOCKS_PER_SEC);
}

Measured memory_bytes: 102784
#include<iostream>
#include<algorithm>
#include<ctype.h>
#include<vector>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	string a;
	cin >> a;
	string b;
	cin >> b;
	string c;
	cin >> c;
	a[0] = toupper(a[0]);
	b[0] = toupper(b[0]);
	c[0] = toupper(c[0]);
//	transform(a.begin(), a.end(), a.begin(), toupper);
	//transform(b.begin(), b.end(), b.begin(), toupper);
	//transform(c.begin(), c.end(), c.begin(), toupper);
		cout << a.front() << b.front() << c.front() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
using ll = long long;
int main(){ 
    string s;
    cin>>s;
    REP(i,s.size()){
        if(i%2==1){
            if(s[i]=='R'){
                cout<<"No";
                return 0;
            }
        }else{
            if(s[i]=='L'){
                cout<<"No";
                return 0;
            }
        }
    }
    cout<<"Yes";
    return 0;
}


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

int main()
{
    std::vector<int> inputs(5);
    for (int i = 0; i < inputs.size(); ++i)
    {
        std::cin >> inputs[i];
    }

    std::sort(inputs.begin(), inputs.end(), [](int a, int b) { return ((a - 1) % 10) > ((b - 1) % 10); });

    int ans = 0;
    int index = 0;
    while (index < inputs.size())
    {
        if (ans % 10 != 0)ans += (10 - (ans % 10));
        ans += inputs[index];
        index++;
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	int n;
	ll k;
	cin>>n>>k;
	int arr[n];
	vector<int> g[n];
	bool vis[n]={};
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	k--;
	int x = arr[0];
	bool cycle = false;
	int cnt=0;
	for(int i=0; i<k && !cycle; i++){
		if(!vis[x-1]){
			vis[x-1]=1;
			x = arr[x-1];
			cnt++;
		}
		else {
			cycle = true;
		}
	}
	k-=cnt;
	memset(vis, 0, sizeof(vis));
	int comp = 0;
	vector<int> path;
	while(!vis[x-1]){
		path.push_back(x);
		vis[x-1]=1;
		x = arr[x-1];
		comp++;
	}
	int m = k%comp;
	cout<<path[m]<<endl;
}


Measured memory_bytes: 9908
#include<bits/stdc++.h>
#define ll long long
#define endl "\n"
#define pb push_back
#define f(i,n) for(int i=0;i<n;i++)
#define f1(i,n) for(int i=1;i<n;i++)
#define rf(i,n) for(int i=n-1;i>=0;i--)
#define rf1(i,n) for(int i=n-1;i>=1;--i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)
#define PI 3.1415926535897932384626433832795
#define fi first
#define se second
#define mp(x,y) make_pair(x,y)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define BIN(n,x) bitset<n>(x)  //bitshift works on 32 bit integers only
#define mod (ll)1000000007
#define mod1 (ll)998242353
using namespace std;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<pair<int,int>> vpi;
typedef vector<pair<ll,ll>> vpl;

//nC2
ll C2(ll n){
    ll ans= max(((n*(n-1))/2),(ll)0);
    return ans;
}
//square
ll sq(ll n){
    return n*n;
}

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

//LCM
ll lcm(ll a,ll b){
    if(a==0 || b==0){
        return 0;
    }
    else{
        return((ll)((a*b)/gcd(a,b)));
    }
}

//sort pair by second values
bool sortsec(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.second < b.second); 
}
//sort pair by first vals in descending
bool sortinrev(const pair<ll,ll> &a, const pair<ll,ll> &b){ 
    return (a.first > b.first); 
} 

//Binary Exponentiation
ll BinExp(ll a, ll b, ll m){
    a%=m;
    ll res =1;
    while(b>0){
        if(b&1){
            res = (res * a)%m;
        }
        a=(a*a)%m;
        b>>=1;
    }
    return res;
}

//All Non-Empty SubSequences(O(2*n))
vvi SubSeq;
void allSub(vector<int> arr, int index,vector<int> subarr){
    if (index == arr.size()){ 
        int l = subarr.size(); 
        if (l != 0){
            SubSeq.pb(subarr); 
        }
    } 
    else{ 
        allSub(arr, index + 1, subarr); 
        subarr.push_back(arr[index]); 
        allSub(arr, index + 1, subarr); 
    } 
    return; 
} 

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

    int n;
    cin>>n;
    ll a[n];
    ll x=0;
    f(i,n){
        cin>>a[i];
        x=x^a[i];
    }
    ll ans[n];
    f(i,n){
        ans[i]=x^a[i];
        cout<<ans[i]<<" ";
    }
    cout<<endl;

    


    return 0;
}



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

int main() {
	string s;
	cin >> s;
	int n=s.size(),flag=1;
	int x=(n-1)/2 - 1;
	for(int i=0;i<x;i++){
	    if(s.at(i)!=s.at(x-i)) flag=0;
	}
	x=(n+3)/2 -1;
	for(int i=x;i<n;i++){
	    if(s.at(i)!=s.at(n-1-i)) flag=0;
	}
	if(flag) cout << "Yes" << endl;
	else cout << "No" << endl;
}


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

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

        int n = sc.nextInt();
        int m = sc.nextInt();
        int[] x = new int[m];
        for (int i = 0; i < m; i++) {
            x[i] = sc.nextInt();
        }

        Arrays.sort(x);
        
        int[] l = new int[m-1];
        for (int i = 1; i < m; i++) {
            l[i-1] = x[i] - x[i-1];
        }

        Arrays.sort(l);
        int cnt = 0;
        for (int i = 0; i < m-n; i++) {
            cnt += l[i];
        }
        
        System.out.println(cnt);
    }
}


Measured memory_bytes: 49396
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<cstdio>
#include<vector>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<utility>
#include<algorithm>
#include<cstring>
#include<sstream>
#include <iomanip>

using namespace std;

typedef long long ll ;
typedef double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector< pair<int,int> > vii;
const double pi = 2*acos(0) ;

#define pf		  	printf
#define sf			  scanf
#define pb(a)         push_back(a)
#define mp			make_pair
#define fi			 first
#define se			 second
#define for0(i,n)        for(int i=0;i<n;i++)
#define for1(i,n)        for(int i=1;i<=n;i++)
#define forab(i,a,b)       for(int i=a;i<=b;i++)
#define lcm(a, b)     ((a)*((b)/gcd(a,b)))
#define sq(a)		   (a)*(a)
#define nw				"\n"
#define abs(x)		fabs(x)
#define pcase(z,x)    cout<<"Case "<<z<<": "<<x<<"\n"
ll gcd(ll a, ll b){
	while(b){
		ll r = a%b;
		a=b;
		b=r;
		}
	return a;
	}
int main()
{
	ll a,b,c,x;
	cin>>a>>b>>c;
	x = gcd(a,b);
	if(c%x==0) pf("YES\n");
	else pf("NO\n");
	return 0;
}

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

using namespace std;

int main() {
    long long int a, b, c;
    long double d;
    long double eps = 1e-10;
    cin >> a >> b >> c;

    d = 2.0 * sqrtl(a * b);

    if (static_cast<long double>(c - a - b) - d > eps) {
        cout << "Yes" << endl;
    }

    else {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256