akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

long long arr[5];
long long vol;

int pw(int b){
	if(b==0)return 1;
	int ans=1;
	for(int i=1;i<=b;i++) ans*=2;
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	//freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    long long mint=1e11;
    long long temp;
    for(int i=1;i<=4;i++){cin>>arr[i]; if(i!=4) { arr[i]*=(1ll*pw(3-i)); mint=min(mint,arr[i]);} }
    cin>>vol;
    temp=arr[4];
    if(arr[4]%2==0) arr[4]/=2; else { arr[4]/=2; arr[4]+=1;}
	long long mina=1e11;
	for(int i=1;i<=4;i++) mina=min(mina,arr[i]);
	if(mint==mina) cout<<vol*mint<<endl;
	else{
		if(vol%2==0) { if((vol*temp)%2==0) cout<<(vol*temp)/2; else cout<<(vol*temp)/2+1;} 
		else { if(((vol-1)*temp)%2==0) cout<<((vol-1)*temp)/2+mint<<endl; else cout<<((vol-1)*temp)/2+mint+1<<endl; }
	}
    return 0;
	}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pb push_back
#define rep(a,b,c) for(int a=(int)b;a<(int)c;a++)
#define repe(a,b,c) for(int a=(int)b;a<=(int)c;a++)
#define repk(a,b,c,k) for(int a=(int)b;a<(int)c;a+=(int)k)
#define comeback std::ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
#define int long long int
#define pii pair<int,int>
#define ful(a) a.begin(),a.end()
#define ub upper_bound
#define lb lower_bound
#define ff first
#define ss second
using namespace std;
int em(int x,int n)
{
    if(n==0)
    return 1;
    else if(n%2==0)
    return em((x%mod*x%mod)%mod,n/2);
    else
    return (x%mod*em((x%mod*x%mod)%mod,(n-1)/2))%mod;
}
double dp[3009][3009];
signed main()
{
	comeback
	/*#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output1.txt","w",stdout);
	#endif*/
		int n,m,i,j,k,l;
		cin>>n;
		double pr[n+1];
		repe(i,1,n)
			cin>>pr[i];
		memset(dp,0,sizeof(dp));
		dp[0][0]=1;
		repe(i,1,n){
			repe(j,0,i){
				if(j-1>=0)
					dp[i][j]=(dp[i-1][j-1]*(1-pr[i])+dp[i-1][j]*pr[i]);
				else
					dp[i][j]=dp[i-1][j]*pr[i];
			}
		}
		double ans=0;
		repe(i,0,n/2)
		ans+=dp[n][i];
		cout<<fixed<<setprecision(9)<<ans;
}

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++) cin >> A[i];
    sort(A.rbegin(), A.rend());
    int64_t ans = 0;
    int R = N-1;
    for(int i=0; i<N; i++){
        int use = min(R, i ? 2 : 1);
        ans += use*A[i];
        R -= use;
    }
    cout << ans << endl;
    return 0;
}


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

int64_t calc_gcd(int64_t a, int64_t b)
{
    a = a % b;
    if (a == 0)
        return b;
    return calc_gcd(b, a);
}

int64_t calc_lcm(int64_t a, int64_t b)
{
    return a / calc_gcd(a, b) * b;
}

int64_t calc_vec_lcm(const vector<int64_t> &a_vec, int64_t upper)
{
    int64_t lcm = 1;
    for (auto a : a_vec) {
        lcm = calc_lcm(lcm, a);
        if (lcm > upper)
            return upper;
    }
    return lcm;
}
int64_t count_factor2(int64_t a)
{
    int64_t log2 = 0;
    while (a > 0) {
        if (a & 1)
            break;
        ++log2;
        a >>= 1;
    }
    return log2;
}

bool is_feasible(const vector<int64_t> &a_vec)
{
    int64_t cnt, head_cnt = -1;
    int size = a_vec.size();
    head_cnt = count_factor2(a_vec.at(0));
    for (int i = 1; i < size; ++i) {
        cnt = count_factor2(a_vec.at(i));
        if (cnt != head_cnt)
            return false;
    }
    return true;
}

int	main()
{
    int N;
    int64_t M;
    cin >> N >> M;
    vector<int64_t> a_vec(N);
    int64_t a;
    for (int i = 0; i < N; ++i) {
        cin >> a;
        a_vec.at(i) = a / 2;
    }
    if (!is_feasible(a_vec)) {
        cout << 0 << endl;
        return 0;
    }
    int64_t lcm = calc_vec_lcm(a_vec, M + 1);
    cout << M / lcm - M / (2 * lcm) << endl;
}





Measured memory_bytes: 4040
#include <iostream>

const int ms = 10100;

int a[ms], b[ms];

int main() {
	int n;
	std::cin >> n;
	long long up = 0;
	long long down = 0;
	for(int i = 0; i < n; i++) {
		std::cin >> a[i];
	}
	for(int i = 0; i < n; i++) {
		std::cin >> b[i];
		if(a[i] < b[i]) {
			up += (b[i] - a[i]) / 2;
		} else {
			down += a[i] - b[i];
		}
	}
	if(up - down >= 0) {
		std::cout << "Yes\n";
	} else {
		std::cout << "No\n";
	}
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/range/adaptor/reversed.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
typedef long long int ll;

#define PI (acos(-1))
#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumparr(x) cerr << #x ; for(auto elem: x){cerr << " " << elem;} cerr << endl;
#define dumppairs(x) cerr << #x ; for(auto elem: x){cerr << "(" << elem.first << " " << elem.second << ") ";} cerr << endl;
#define dumpline cerr << "**********************" << endl;
#define dumpwline(x) cerr << "******** " << #x << "=" << (x) << " ********" << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))

int main(void){
    ll l; cin >> l;
    ll r; cin >> r;
    ll d; cin >> d;
    ll ans = 0;
    for(int i=l; i<=r; i++){
        ans += (i%d==0);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int h,w;
    cin>>h>>w;
    char fi[h][w];
    rep(i,h){
        rep(j,w){
            cin>>fi[i][j];
        }
    }

    int dp[h][w];
    rep(i,h){
        rep(j,w){
            dp[i][j]=INF;
        }
    }
    if(fi[0][0]=='#') dp[0][0]=1;
    else dp[0][0]=0;

    rep(i,h){
        rep(j,w){
            if(i-1>=0){
                if(fi[i-1][j]=='.' && fi[i][j]=='#') dp[i][j]=min(dp[i][j],dp[i-1][j]+1);
                else dp[i][j]=min(dp[i][j],dp[i-1][j]);
            }
            if(j-1>=0){
                if(fi[i][j-1]=='.' && fi[i][j]=='#') dp[i][j]=min(dp[i][j],dp[i][j-1]+1);
                else dp[i][j]=min(dp[i][j],dp[i][j-1]);
            }
        }
    }

    cout<<dp[h-1][w-1]<<endl;
}
    




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb(t) push_back(t)
#define pt(num) cout << num << "\n"
#define chmax(a, b) (a<b ? a=b : 0)
#define chmin(a, b) (a>b ? a=b : 0)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef map<ll, ll> Map;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;





int main(void) {
    char c;
    cin >> c;
    
    if(c=='A') pt('T');
    if(c=='T') pt('A');
    if(c=='C') pt('G');
    if(c=='G') pt('C');
    
    
    
    
}








Measured memory_bytes: 256
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=pow(10,18);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const ll dx[4]={0,0,1,-1};
const ll dy[4]={-1,1,0,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

bool solve(){
  ll n;cin>>n;
  vector<ll>A(n+1);
  ll sum=0;
  rep(i,n){
    cin>>A[i];
    sum+=A[i];
  }
  if(sum%(n*(n+1)/2)!=0){
    cout<<"NO"<<endl;
    return false;
  }
  ll c=sum/(n*(n+1)/2);
  ll c2=c-n;
  // cout<<c<<c2<<endl;
  A[n]=A[0];
  ll num=0;
  ll num2=0;
  rep(i,n){
    // cout<<((A[i+1]-A[i]))%n<<endl;
    num+=A[i+1]-A[i];
    // cout<<(A[i+1]-A[i]-c)<<endl;
    if((A[i+1]-A[i]-c)%n!=0){
      cout<<"NO"<<endl;
      return false;
    }
    if((A[i+1]-A[i]-c)>0){
            cout<<"NO"<<endl;
      return false;
    }
    num2-=(A[i+1]-A[i]-c)/n;
  }
  if(num!=0 or num2!=c)cout<<"NO"<<endl;
  else cout<<"YES"<<endl;
  return false;
}

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


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	int n; cin>>n;
	n--;
	ll a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	if(n==1){ cout<<2*a[0]; return 0; }
	ll ans = a[0]+a[n-1];
	for(int i=1;i<n;i++) ans += min(a[i],a[i-1]);
	cout<<ans;
	
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=999999999999;

int main(){
    string s,t;
    cin>>s>>t;
    int n=s.length();
    int m=t.length();
    int ans=10000;
    for(int i=0;i<=n-m;i++){
        int buf=m;
        for(int j=i;j<i+m;j++){
            if(s[j]==t[j-i]) buf--;
        }
        //cout<<buf<<endl;
        ans=min(ans,buf);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	int a[n],b[n];
	int c[n]={};
	int d[n]={};
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		if(i==0)c[0]=a[0];
		else c[i]=c[i-1]+a[i];
	}
	for(int i=0;i<n;i++){
		scanf("%d",&b[i]);
		if(i==0)d[0]=b[0];
		else d[i]=d[i-1]+b[i];
	}
	int ans=c[0]+d[n-1];
	int x;
	for(int i=1;i<n;i++){
		x=c[i]+d[n-1]-d[i-1];
		if(ans<x)ans=x;
	}
	printf("%d\n",ans);
	return 0;
}
	
	

Measured memory_bytes: 128
def factorize(n):
    fct = []
    
    for i in range(2, int(n**0.5)+1):
        c = 0
        
        while n%i==0:
            n //= i
            c += 1
            
        if c>0:
            fct.append((i, c))
    
    if n>1:
        fct.append((n, 1))
    
    return fct

N, P = map(int, input().split())
ans = 1

for p, c in factorize(P):
    ans *= p**(c//N)

print(ans)

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


int main()
{
	long long int n,m=1;
	cin>>n;
	vector<long long int>v(1);
	cin>>v[0];
	for(long long int i=1;i<n;i++)
	{
		long long int p;
		cin>>p;
		if(v[v.size()-1]>p)
		{
			m++;
			v.push_back(p);
		}
		
	}
	cout<<m;
	return 0;
}

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

#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define ACC(c) (accumulate(ALL(c), 0LL))
#define PRINT(x) cout << (x) << "\n"

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

inline int in(int& a) {return scanf("%d", &a);}
auto pint_compare = [](pint x, pint y) -> bool{return (x.first < y.first);};


signed main(){
    char b;
    cin >> b;
    map<char, char> m;
    m['A'] = 'T';
    m['T'] = 'A';
    m['C'] = 'G';
    m['G'] = 'C';
    PRINT(m[b]);
    return 0;
}


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

using namespace std;

#define forn for (ll i = 0; i < n; i++)
#define form for (ll j = 0; j < m; j++)
#define NO cout << "NO\n";
#define YES cout << "YES\n";
#define pb push_back
#define mp make_pair
#define rep(i,a,b) for (ll i = a; i < b; i++)

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

ll gcd(ll a, ll b){
    ll r;
    while (b != 0){
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}


ll *calc_z(string s){
    ll n = s.size();
    ll *z = new ll[n] {0};
    ll l = 0, r = 0;
    for (ll i = 1; i < n; i++){
        if (r >= i) z[i] = min(z[i-l], r-i+1);
        while (z[i]+i < n && s[z[i]] == s[z[i]+i]) z[i]++;
        if (i + z[i] - 1 > r){
            l = i;
            r = i+z[i]-1;
        }
    }
    return z;
}

ll find_lower(ll *a, ll n, ll v){
    ll l = -1, r = n;

    while (r>l+1){
        ll m = (l+r)/2;

        if (a[m] >= v) r = m;
        else l = m;
    }
    if (r == n) return n-1;
    if (a[r] == v) return r;
    return r == 0 ? 0 : r-1;
}

void init(){
}

int bin(int *p, int n, int x){
    int l = 0, r = n-1;
    while (r >= l){
        int m = (l+r)/2;
        if (p[m] == x) return m;
        if (p[m] > x) r = m-1;
        else l = m+1;
    }
    return -1;
}

void solve(){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int ans = min(a, k);
    a -= ans;
    k -= ans;
    int t = min(b, k);
    b -= t;
    k -= t;
    t = min(c, k);
    if (k > 0) ans -= t;
    cout << ans << '\n';
}

int main(){
    //init();

    ios::sync_with_stdio(0);
    cin.tie(0);

    //ll t; cin >> t; while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 3632
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#define maxn 100005
using namespace std;
typedef long long ll;
int n,a[maxn],ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	a[0] = 0;
	for(int i=1;i<=n;i++) ans += abs(a[i] - a[i-1]);
	ans += abs(a[n] - a[0]);
	for(int i=1;i<n;i++){
		printf("%d\n",ans - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]));
	}
	printf("%d\n",ans - abs(a[n-1] - a[n]) - abs(a[n] - a[0]) + abs(a[n-1] - a[0]));
	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
const int N=2100;
int n,m,q,sp[N][N],sr[N][N],sl[N][N];
int a,b,c,d;
char s[N][N];
int main()
{
	scanf("%d%d%d",&n,&m,&q);
	for (int i=1;i<=n;i++) scanf("%s",s[i]+1);
	for (int i=1;i<=n;i++)
	{
		for (int j=1;j<=m;j++)
		{
			sp[i][j]=sp[i-1][j]+sp[i][j-1]-sp[i-1][j-1];
			if (s[i][j]=='1') sp[i][j]++;
			sr[i][j]=sr[i-1][j]+sr[i][j-1]-sr[i-1][j-1];
			if (s[i][j]=='1' && s[i-1][j]=='1') sr[i][j]++;
			sl[i][j]=sl[i-1][j]+sl[i][j-1]-sl[i-1][j-1];
			if (s[i][j]=='1' && s[i][j-1]=='1') sl[i][j]++;
		}
	}
	while (q--)
	{
		scanf("%d%d%d%d",&a,&b,&c,&d);
		int point,len;
		point=sp[c][d]-sp[c][b-1]-sp[a-1][d]+sp[a-1][b-1];
		len=sr[c][d]-sr[c][b-1]-sr[a][d]+sr[a][b-1];
		len+=sl[c][d]-sl[c][b]-sl[a-1][d]+sl[a-1][b];
		printf("%d\n",point-len);
	}
}

Measured memory_bytes: 57164
N,M,L = map(int,input().split())

A = [list(map(int,input().split())) for i in range(N)] 
B = [list(map(int,input().split())) for i in range(M)] 
ANS = [[0]*L for i in range(N)] 


for i in range(N):
    for j in range(L):
        for k in range(M):
            ANS[i][j] += B[k][j]*A[i][k]

for row in range(N):
    print("%d"%ANS[row][0],end = "")
    for col in range(1,L):
        print(" %d"%(ANS[row][col]),end = "")
    print()


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

#define pb push_back
#define pii pair<int,int>
#define mp make_pair

using namespace std;

const int N = 1e5 + 123;

int n, sz;

map <pii,int> ans;

vector <int> g[N];

pii p[N];

void dfs (int v = 1, int pr = -1, int forbidden = 0) {
    int color = 0;
    for (auto to : g[v]) {
        if (to != pr) {
            color ++;
            if (color == forbidden) color ++;
            sz = max (sz, color);
            ans[mp (v,to)] = ans[mp (to, v)] = color;
            dfs (to, v, color);
        }
    }
}

int main () {
    cin >> n;
    for (int i = 1;i < n;i ++) {
        int l, r;
        cin >> l >> r;
        p[i] = mp (l, r);
        g[l].pb (r);
        g[r].pb (l);
    }dfs ();
    cout << sz << '\n';
    for (int i = 1;i < n;i ++) {
        cout << ans[p[i]] << '\n';
    }
}


Measured memory_bytes: 21376
# ARC093C - Traveling Plan
N = int(input())
A = [0] + list(map(int, input().rstrip().split())) + [0]
S = 0
for i in range(1, N + 2):
    S += abs(A[i - 1] - A[i])

for i in range(1, N + 1):
    ans = S + abs(A[i - 1] - A[i + 1]) - (abs(A[i - 1] - A[i]) + abs(A[i] - A[i + 1]))
    print(ans)

Measured memory_bytes: 14044
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int a,b,c,x,y,ans=0;
	cin>>a>>b>>c>>x>>y;
	if(c*2<=a+b){
		int dim=min(x,y);
		x-=dim,y-=dim;
		ans+=c*2*dim;
		if(c*2*x+c*2*y<a*x+b*y){
			ans+=c*2*x+c*2*y;
		}
		else{
			ans+=a*x+b*y;
		}
	}
	else{
		ans+=a*x+b*y;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
N,A,B,C = map(int,input().split())
l = [int(input()) for _ in range(N)]

def dfs(a,b,c,cnt):
#     print(a,b,c,cnt)
    if cnt >= len(l):
        if a==0 or b==0 or c==0:
            return 10**10
        return abs(a-A)+abs(b-B)+abs(c-C)
    
    res0 = dfs(a,b,c,cnt+1)
    if a>0:
        res1 = dfs(a+l[cnt],        b, c       ,cnt+1) + 10
    else:
        res1 = dfs(a+l[cnt],        b, c       ,cnt+1)
    
    if b>0:
        res2 = dfs(       a, b+l[cnt], c       ,cnt+1) + 10
    else:
        res2 = dfs(       a, b+l[cnt], c       ,cnt+1)

    if c>0:
        res3 = dfs(       a,        b, c+l[cnt],cnt+1) + 10
    else:
        res3 = dfs(       a,        b, c+l[cnt],cnt+1)
    
    return min(res0,res1,res2,res3)

print(dfs(0,0,0,0))

Measured memory_bytes: 43484
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = (1e+9)+7;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
typedef pair<P, int> PP;
struct edge { int to,cost; };
int V;
int d[700000];
vector<edge> G[700000];
void dijkstra(int s) {
	priority_queue<P, vector<P>, greater<P>>que;
	fill(d, d + V, (int)MOD);
	d[s] = 0;
	que.push(P(0, s));
	while (!que.empty()) {
		P p = que.top(); que.pop();
		int v = p.second;
		if (d[v] < p.first)continue;
		for (int i = 0; i < (int)G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}
map<P, int> mp;
int main() {
	int n, m; cin >> n >> m; V = 700000;
	int cnt = n;
	rep(i, m) {
		int u, v, c; cin >> u >> v >> c; u--; v--;
		int s = mp[{u, c}];
		if (s == 0) {
			s = cnt; cnt++; mp[{u, c}] = s;
		}
		int t = mp[{v, c}];
		if (t == 0) {
			t = cnt; cnt++; mp[{v, c}] = t;
		}
		G[s].push_back({ t,0 });
		G[t].push_back({ s,0 });
		G[s].push_back({ u,0 });
		G[t].push_back({ v,0 });
		G[u].push_back({ s,1 });
		G[v].push_back({ t,1 });
	}
	dijkstra(0);
	if (d[n - 1] == (int)MOD)cout << -1 << endl;
	else cout << d[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 64632
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int n;
	cin>>n;
	set<int>a,b;
	map<int,ll>cnta,cntb;
	rep(i,n){
		int h;
		cin>>h;
		int ite=i+1;
		if(ite>=h){
			cntb[ite-h]++;
			//b.insert(ite-h);
			//cout<<ite-h<<" "<<ite<<endl;
		}
		cnta[ite+h]++;
		//cout<<ite+h<<" "<<ite<<endl;
		a.insert(ite+h);
	}
	ll ans=0;
	for(auto i=a.begin(); i!=a.end();i++){
		int t=*i;
		ans+=(ll)cnta[t]*cntb[t];
	}
	cout<<ans<<endl;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	solve();
	return 0;
}


Measured memory_bytes: 37828
using System;
using System.Collections.Generic;

namespace MyProgram{
    class AtCoder{
        static void Main(string[] args){
            int N = int.Parse(Console.ReadLine());
            long[] a = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
            int max = 0;
            for(var i=0;i<N;i++){
                max += two(a[i]);
            }
            Console.WriteLine(max);
        }

        static int two(long number){
            long num = number;
            for(var i=0;;i++){
                if(num%2==0){
                    num = num/2;
                }else{
                    return i;
                }
            }
        }
    } 
}

Measured memory_bytes: 13920
#include<bits/stdc++.h>
#define L long long
#define pb push_back
#define pi pair<int,int>
#define pii pair<pair<int,int>,int>
#define aa first
#define bb second
#define xx aa.aa
#define yy aa.bb
#define zz bb
#define mp make_pair
#define mpp(a,b,c) mp(mp(a,b),c)
using namespace std;
int n,m,a[200010],b[200010],x[200010],f[600000][2],p;
set<pii> w;
pii u;
inline void modify(int i,int j,int k,int x,int y,int p)
{
	if(j==k)
	  f[i][y]=p;
	else
	  {
	   if(x<=(j+k>>1))
	     modify(i<<1,j,j+k>>1,x,y,p);
	   else
	     modify(i<<1|1,(j+k>>1)+1,k,x,y,p);
	   f[i][y]=min(f[i<<1][y],f[i<<1|1][y]);
	  }
}
inline int minn(int i,int j,int k,int l,int r,int x)
{
	if(l<=j && k<=r)
	  return f[i][x];
	else
	  {
	   int p=1e9;
	   if(l<=(j+k>>1))
	     p=min(p,minn(i<<1,j,j+k>>1,l,r,x));
	   if(r>(j+k>>1))
	     p=min(p,minn(i<<1|1,(j+k>>1)+1,k,l,r,x));
	   return p;
	  }
}
inline void del(int i)
{
	x[++m]=i;
	modify(1,1,p,b[i],b[i]&1,1e9);
}
inline void ins(int l,int r)
{
	if(l<=r)
	  w.insert(mpp(minn(1,1,p,l,r,l&1),l,r));
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	int i,j,l,r;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	  scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
	  b[a[i]]=i;
	for(p=1;p<n;p<<=1);
	for(i=1;i<2*p;i++)
	  f[i][0]=f[i][1]=1e9;
	for(i=1;i<=n;i++)
	  modify(1,1,p,i,i&1,a[i]);
	ins(1,n);
	while(!w.empty())
	  {
	   u=*w.begin();
	   w.erase(u);
	   i=u.xx;
	   j=minn(1,1,p,b[i],u.zz,u.zz&1);
	   del(i);
	   del(j);
	   ins(u.yy,b[i]-1);
	   ins(b[i]+1,b[j]-1);
	   ins(b[j]+1,u.zz);
	  }
	for(i=1;i<=n;i++)
	  printf("%d ",x[i]);
	return 0;
}


Measured memory_bytes: 11136
#include <stdio.h>

#define MAX_N 100

typedef struct{
  char Mark;
  int num;
} Card;

void swap(Card*,Card*);
void bubbleSort(Card*,int);
void selectionSort(Card*,int);
void print(Card*,int);
int isStable(Card*,Card*,int);

int main(){
  int N,i;
  char ch;
  Card a[MAX_N],b[MAX_N];
  scanf("%d\n",&N);
  for(i = 0 ; i < N ; i++){
    scanf("%c%d%c",&a[i].Mark,&a[i].num,&ch);
    b[i] = a[i];
  }
  bubbleSort(a,N);  
  selectionSort(b,N);
  print(a,N);
  puts(isStable(a,a,N) ? "Stable" : "Not stable");
  print(b,N);
  puts(isStable(a,b,N) ? "Stable" : "Not stable");
  return 0;
}

void swap(Card *a,Card *b){
  Card temp;
  temp = *a;
  *a = *b;
  *b = temp;
}

void bubbleSort(Card *c,int N){
  int i,j;
  for(i = 0 ; i < N ; i++){
    for(j = N-1 ; j > i ; j--){
      if(c[j].num < c[j-1].num){
        swap(&c[j],&c[j-1]);
      }
    }
  }
}

void selectionSort(Card *c,int N){
  int i,j,min;
  for(i = 0 ; i < N ; i++){
    min = i;
    for(j = i+1 ; j < N ; j++){
      if(c[j].num < c[min].num){
        min = j;
      }
    }
    swap(&c[i],&c[min]);
  }
}

void print(Card *c,int N){
  int i;
  for(i = 0 ; i < N ; i++){
    printf("%c%d%c",
           c[i].Mark,c[i].num,(i < N-1 ? ' ' : '\n'));
  }
}

int isStable(Card *a,Card *b,int N){
  int i,flag = 1;
  for(i = 0 ; i < N ; i++){
    if(a[i].Mark != b[i].Mark){
      flag = 0;
      break;
    }
  }
  return flag;
}

Measured memory_bytes: 612
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<math.h>

int main(){
	int N;
	scanf("%d",&N);
	while(N != 0){
		int x[N],y[N],r[N],m[N];
		for(int i=0;i<N;i++){
			scanf("%d %d %d %d",&x[i],&y[i],&r[i],&m[i]);
		}
		int max = 0;
		for(int i=0;i<N;i++){
			for(double j=0; j< 2*M_PI; j=j+0.001){
				double a,b,c,ab;
				if(j == 0 || j == M_PI){
					a = 1.0;
					b = 0.0;
					c = -x[i]-r[i]*cos(j);
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}else{
					a = (-1) * tan(M_PI/2 + j);
					if(a < 0.01 && a > -0.01){
						a = 0.0;
					}
					b = 1.0;
					c = (x[i]+r[i]*cos(j)) * tan(M_PI/2 + j) - y[i] - r[i] * sin(j);
					if(a == 0){
						c = (int)(c*10000)/10000;
					}
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}
				int tempmax = 0;
				for(int k=0;k<N;k++){
					if(i==k){
						tempmax++;
					}else{
						double d = fabs(a*x[k] + b*y[k] + c) / ab;
						if(m[k] == 0){
							if((int)(d+0.5) == r[k]){
								tempmax++;
							}
						}else{
							if(d >= r[k] && d <= r[k] + m[k]){
								tempmax++;
							}
						}
					}
				}
				if(max < tempmax){
					max = tempmax;
				}
			}

			/*for(double j=0; j< 2*M_PI; j=j+0.001){
				double a,b,c,ab;
				if(j == 0 || j == M_PI){
					a = 1.0;
					b = 0.0;
					c = -x[i]-(r[i]+m[i])*cos(j);
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}else{
					a = (-1) * tan(M_PI/2 + j);
					if(a < 0.01 && a > -0.01){
						a = 0.0;
					}
					b = 1.0;
					c = (x[i]+( r[i] + m[i] )*cos(j)) * tan(M_PI/2 + j) - y[i] - (r[i] + m[i]) * sin(j);
					if(a == 0){
						c = (int)(c*10000)/10000;
					}
					ab = sqrt(pow(a,2.0)+pow(b,2.0));
				}
				int tempmax = 0;
				for(int k=0;k<N;k++){
					if(i==k){
						tempmax++;
					}else{
						double d = fabs(a*x[k] + b*y[k] + c) / ab;
						if(m[k] == 0){
							if((int)(d+0.5) == r[k]){
								tempmax++;
							}
						}else{
							if(d >= r[k] && d <= r[k] + m[k]){
								tempmax++;
							}
						}
					}
				}
				if(max < tempmax){
					max = tempmax;
				}
			}*/
		}
		printf("%d\n",max);
		scanf("%d",&N);
	}

}

Measured memory_bytes: 1088
import sys

n, m = map(int,input().split())

b = ''
res = []

if n == 1:
  b = ['b']
elif n == 2:
  b = ['b', 'b']
elif n == 3:
  b = ['b', 'b', 'b']

for _ in range(m):
  res.append(list(input().split()))

if n ==1 and m == 0:
  print(0)
  sys.exit()

for i in res:
  if b[int(i[0]) - 1] == 'b':
    b[int(i[0]) - 1] = i[1]
  elif b[int(i[0]) - 1] != 'b':
    if b[int(i[0]) - 1] == i[1]:
      continue
    print(-1)
    sys.exit()

aaa = ''
for i in range(len(b)):
  if b[i] == 'b':
    if i == 0:
      aaa += '1'
    else:
      aaa += '0'
  else:
    aaa += str(b[i])

if n >= 2 and aaa[0] == '0':
  print(-1)
  sys.exit()
elif n == 3 and aaa[0] == '0' and aaa[1] == '0':
  print(-1)
  sys.exit()

print(aaa)

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

int main(){
	int n; cin>>n;
	vector<pair<int,int>> v(n);
	for(int i=0;i<n;++i){
	       cin>>v[i].first;
	       v[i].second=i;
	}
	sort(v.begin(), v.end());
	vector<int> ans(n);
	int mx=v[0].first;
	auto dist=[](int n, int x){
		if(n%2==0) return abs(n/2-x);
		else return min(abs(n/2-x), abs((n+1)/2-x));
	};
	for(int i=0;i<n-1;++i){
		int x=v[i].first;
		if(dist(v.back().first,x) < dist(v.back().first,mx) ) mx=x;
	}
	cout<<v.back().first<<' '<<mx<<endl;
}


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

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

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;



int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string S; cin >> S;
    int dp[2][S.length()];
    rep(i, S.length()) dp[0][i] = 1;
    rep(i, S.length()) dp[1][i] = 0;
    rep(i, S.length()){
        if(S[i] == 'R'){
            dp[0][i+1] += dp[1][i];
            dp[1][i+1] += dp[0][i];
            dp[0][i] = dp[1][i] = 0;
        }
    }
    for(int i = S.length()-1; i >= 0; i--){
        if(S[i] == 'L'){
            dp[0][i-1] += dp[1][i];
            dp[1][i-1] += dp[0][i];
            dp[0][i] = dp[1][i] = 0;
        }
    }
    int ans[S.length()] = {};
    rep(i, S.length()-1){
        if(S[i] == 'R' && S[i+1] == 'L'){
            ans[i] = dp[0][i] + dp[1][i+1];
            ans[i+1] = dp[1][i] + dp[0][i+1];
        }
    }
    rep(i, S.length()) cout << ans[i] << " "; cout << endl;
    return 0;
}

Measured memory_bytes: 1872
#include<bits/stdc++.h>
using namespace std;
int n,k,i,j,a[300010];
int main()
{
    scanf("%d%d",&k,&n);
    if(k%2==1)
    {
        for(i=1;i<=n;i++)
            a[i]=(k+1)/2;
        int last=n;
        for(i=1;i<=n/2;i++)
           { if(a[last]==1) last--;
            else
            {
                a[last]--;
                for(j=last+1;j<=n;j++)
                    a[j]=k;
                last=n;
            }
            }
        for(i=1;i<=last;i++)
            printf("%d ",a[i]);
    }
    else
    {
        printf("%d ",k/2);
        for(i=2;i<=n;i++)
            printf("%d ",k);
    }
    return 0;
}


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

int main() {
 int A,B,K;
 cin >> A >> B >> K;
 int count=0;
 for(int i=100;i >0 ; i--){
   if(A%i==0 && B%i==0){
    count++;
     if(count < K){
     continue;
     }
     if(count == K){
     cout << i << endl;
     break;
     }
   }
  if(A%i !=0 ||B%i !=0){
  continue;
  }
 }
}









Measured memory_bytes: 256
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input { ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! input_inner { ( $ next : expr ) => { } ; ( $ next : expr , ) => { } ; ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } } ; }
#[allow(unused_macros)]
macro_rules! read_value { ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) } ; ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) } ; ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 } ; ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) } ; }

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> { fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering { self.0.partial_cmp(&other.0).unwrap() }}

#[allow(dead_code)]
const MAX:usize = 100006;
#[allow(dead_code)]
const INF_U32:u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32:i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64:u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64:i64 = 1 << 62;


fn main() {
    input! {
        x: i64,
        y: i64,
    }

    if x%y==0 {
        println!("-1");
    } else {
        println!("{}", x);
    }

}


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

int main(){
	string s; cin >> s;
	while (s.size() >= 5) {
		string fi, si, sv;
		if (s.size() >= 5) fi = s.substr(0, 5);
		if (s.size() >= 6) si = s.substr(0, 6);
		if (s.size() >= 7) sv = s.substr(0, 7);
		if (sv == "dreamer" && s[7] != 'a') s.erase(0, 7); else
		if (si == "eraser"  && s[6] != 'a') s.erase(0, 6); else
		if (fi == "erase" || fi == "dream") s.erase(0, 5);
		else break;
	}
	cout << (s.size() ? "NO" : "YES") << '\n';
}


Measured memory_bytes: 512
//
#include <vector>
#include <set>
#include <array>
#include <iostream>
#include <cstdio>
#include <cstdint>
#include <algorithm>
#include <numeric>
#include <bitset>
//
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i,n) for(ll i=0;i<(n);++i)
inline void yes(bool cond) { cond ? puts("Yes") : puts("No"); }
template<typename Type> inline void chmin(Type& a, Type b) { if (a > b) a = b; }
template<typename Type> inline void chmax(Type& a, Type b) { if (a < b) a = b; }
template<typename Arr, typename Type> inline void fill(Arr& arr, Type v) { std::fill(arr.begin(), arr.end(), v); }
template<typename Type> inline void sort(Type& arr) { std::sort(arr.begin(), arr.end()); }
template<typename Type> inline Type nth(vector<Type>& arr, size_t pos) { std::nth_element(arr.begin(), arr.begin() + pos, arr.end()); return arr[pos]; }
constexpr ll BIGP = 1000000007L;
constexpr ll INF_I = std::numeric_limits<ll>::max();
constexpr ld INF_F = std::numeric_limits<float>::infinity();
constexpr ld PI = 3.14159265358979323846L;
//
int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    ll l;
    cin >> l;
    //
    double L = double(l);
    double s = L / double(3.0);
    double s3 = s * s * s;
    printf("%16.16f", s3);
    return 0;
}

Measured memory_bytes: 3200
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	 float q,p,c=0;
	while(scanf("%f%f",&q,&p) != EOF){
		if(35.50>q&&71.00>p)cout << "AAA"<<endl;
		else if(37.50>q&&77.00>p)cout << "AA"<<endl;
		else if(40.00>q&&83.00>p)cout << 'A'<<endl;
		else if(43.00>q&&89.00>p)cout << 'B'<<endl;
		else if(50.00>q&&105.00>p)cout << 'C'<<endl;
		else if(55.00>q&&116.00>p)cout <<'D'<<endl;
		else if(70.00>q&&148.00>p)cout <<'E'<<endl;
		else cout << "NA" << endl;
	}
	return 0;
}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
    int n,x,t,d,m;
    cin>>n>>x>>t;
    d=n%x;
    if(d==0)
    {
        m=n/x;
        cout<<m*t;
    }
    else
    {
        m=(n/x)+1;
        cout<<m*t;
    }

    return 0;
}


Measured memory_bytes: 3624
#include<bits/stdc++.h>
    #define int ll
    #define M 1000000007
    #define hell 998244353
    #define inf 1e18
    #define pb push_back
    #define pi 3.1415926536
    #define mp make_pair
    #define ub upper_bound
    #define lb lower_bound
    #define all(a) a.begin(),a.end()
    #define ll long long
    #define vec vector <int>
    #define pii pair<int,int>
    #define endl "\n"
    #define gcd __gcd
    using namespace std;
    int power(int x, unsigned int y, unsigned int m) 
    { 
        if (y == 0) 
            return 1; 
        int p = power(x, y/2, m) % m; 
        p = (p * p) % m; 
  
        return (y%2 == 0)? p : (x * p) % m; 
    } 
    int modInverse(int a, int m) 
    {   
        return power(a, m-2, m);
    }
    int nCrModPFermat(int n, int r, int p) 
    { 
           if (r==0) 
              return 1; 
  
        int fac[n+1]; 
        fac[0] = 1; 
        for (int i=1 ; i<=n; i++) 
            fac[i] = fac[i-1]*i%p; 
  
        return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
    } 
    signed main()
    {
        ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
        ll t=1;
        // cin >> t;
        /*SAARE INPUTS LENA*/
        /*VARIABLES KI RANGE DEKHLENA*/
        /*EXPONENT RANGE OF OUTPUT KA DHYAN RAKHNA*/
        while(t-->0)
        {
            ll n=0;
            cin>>n;
            vector <int> v(n);
            for (int i = 0; i < n; ++i)
            {
                cin>>v[i];
            }
            int dp[n];
            dp[0]=0;
            for (int i = 1; i < n; ++i)
            {
                if(i==1)
                    dp[i]=abs(v[i]-v[i-1]);
                else
                    dp[i]=min(dp[i-1]+abs(v[i]-v[i-1]),dp[i-2]+abs(v[i]-v[i-2]));
            }
            cout<<dp[n-1];
        }
        return 0;
    }

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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<(b);i++)
#define repr(i,b,a) for(int i=int(b);i>=(a);i--)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
bool valid(int lx,int ux,int ly,int uy,int x,int y){
	return lx<=x&&x<ux&&ly<=y&&y<uy; 
}
ll power(ll x,ll p){
	if(p==0)return 1;
	ll res=power(x*x%mod,p/2);
	if(p%2==1)res=res*x%mod;
	return res;
}

int main()
{
	int n,m;
	cin>>n>>m;
	cout<<(n==0?0:n*(n-1)/2) + (m==0?0:m*(m-1)/2)<<endl;
	return 0;
}

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

#define fill(a,val) memset(a, (val), sizeof a)
#define pb push_back
#define lli long long int
#define scantype int
#define endl "\n"
#define unique(x) x.erase(unique(x.begin(),x.end()), x.end())
#define sort_f(x)  sort(x.begin(),x.end());
#define sort_r(x)  sort(x.rbegin(),x.rend());

lli MOD  = 1000000007;
lli inf = 1e15;

void scan(scantype &x);
lli powermod(lli _a,lli _b,lli _m){lli _r=1;while(_b){if(_b%2==1)_r=(_r*_a)%_m;_b/=2;_a=(_a*_a)%_m;}return _r;}
lli string_to_number(string s){lli x=0; stringstream convert(s); convert>>x; return x;}
lli add(lli a,lli b){lli x = (a+b)%MOD; return x; }
lli mul(lli a,lli b){lli x = (a*b)%MOD; return x; }
lli sub(lli a,lli b){lli x = (a-b+MOD)%MOD; return x; }
lli divi(lli a,lli b){lli x = a;lli y = powermod(b,MOD-2,MOD);lli res = (x*y)%MOD;return res;}

#define N 200003

long  divisors(long x) {
    long limit = x;
    long numberOfDivisors = 0;

    if (x == 1) return 1;

    for (long i = 1; i < limit; ++i) {
        if (x % i == 0) {
            limit = x / i;
            if (limit != i) {
                numberOfDivisors++;
            }
            numberOfDivisors++;
        }
        if(numberOfDivisors>=4)
        {
            break;
        }
    }

    return numberOfDivisors;
}
 bool isPrime(long n)
{
   
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
 
    for (long i=5; i*i<=n; i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
           return false;
 
    return true;
}
#define max_a 100001
bool visit[max_a]={false};
vector<long> a[max_a];
long sum=0;
long cost[max_a];
void dfs(long node)
{
    visit[node]=true;
    
    for(int i=0;i<(int)a[node].size();i++)
    {
        if(visit[a[node][i]]==false)
        {
            sum+=cost[a[node][i]];
            dfs(a[node][i]);
            
        }
    }
    
}
void SieveOfEratosthenes(int n)
{
   
    bool prime[n+1];
    memset(prime, true, sizeof(prime));
 
    for (int p=2; p*p<=n; p++)
    {
        
        if (prime[p] == true)
        {
           
            for (int i=p*2; i<=n; i += p)
                prime[i] = false;
        }
    }
 
   
    for (int p=2; p<=n; p++)
       if (prime[p])
          cout << p << " ";
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   lli x,y,z;
   cin>>x>>y>>z;
   x-=z;
   cout<<x/(y+z);
    
    return 0;
}



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

int main()
{
  string s, t = "";
  cin >> s;
  int a = 0, b = 0;
  rep(i, s.size()){
    if(s[i] == '0') a++;
    else b++;
  }
  cout << min(a, b) * 2 << endl;
    
  return 0;
}


Measured memory_bytes: 3672
from sys import stdin


def cmb(n,r):
    return n*(n-1)//2



if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N, M = list(map(int,_in[0].split(' ')))  # type:list(int)
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    cnt = cmb(N,2) + cmb(M,2)
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(cnt)


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



int main(){
	int n;
	cin>>n;
	vector<int> v(3);
	vector<int> dp(3);
	for(int i=0;i<n;i++){
		cin>>v[0]>>v[1]>>v[2];
		vector<int> temp(3,0);
		temp[0]=v[0]+max(dp[1],dp[2]);
		temp[1]=v[1]+max(dp[0],dp[2]);
		temp[2]=v[2]+max(dp[0],dp[1]);
		dp=temp;
	}
	cout<<max(dp[0],max(dp[1],dp[2]));
	
	return 0;
}

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

#define ll long long

using namespace std;

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

    // 降順ソート
    sort(a, a + N, greater<int>());

    int ans = 0;
    for (int i = 0; i < N; i++) {
        // 偶数ならAliceが取るのでplus
        // 奇数ならBobが取るのでminus
        ans += a[i] * (i % 2 == 0 ? 1 : -1);
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,fma")

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

#define sz(a) (int) (a).size()
#define all(a) (a).begin(), (a).end()
#define x first
#define y second

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0), cout.tie(0);

    string s, t;
    cin >> s >> t;
    if (s == t.substr(0, sz(s))) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
string s, t;

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

//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);

    cin >> s >> t;
    int n = s.size(), m = t.size();

    int ans = INT_MAX;
    for (int i = 0; i <= n - m; i++) {
        int cnt = 0;
        for (int j = 0; j < m; j++) {
            if (s[i + j] != t[j]) cnt++;
        }
        ans = min(ans, cnt);
    }

    cout << ans << '\n';

    return 0;
}


Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],ans=0;
pair<int,int> pp[220000];
string s,sa[220000];
char c;
queue<int> que;
signed main(){
    cin>>n;
    if(n%1000==0){
        cout<<0;
    }else{
        cout<<1000-n%1000;
    }
}

Measured memory_bytes: 10504
N,A,B,C,D=map(int, input().split())
S=input()
result = ""

for i in range(A,max(C,D)-1):
    if S[i:i+2]=="##":
        result ="No"
        break

if result == "":
    if C < D:
        result ="Yes"
    else: # D < C
        if S[B-2] == "." and S[B] == ".":
            result = "Yes"
        else:
#            for i in range(B-2,D+1):
#                if S[i:i+3] == "...":
#                    result = "Yes"
            if S[B-2:D+1].count('...')>0:
                result = 'Yes'
      
if result == "":
    result = "No"

print(result)


Measured memory_bytes: 3572
#include <stdio.h>

int main(void)
{
	int n,i,min,max,k;
	
	scanf("%d",&n);
	
	int R[n];
	
	for(i=0; i<n; i++)
	{
		scanf("%d",&R[i]);
	}
	
	min=R[0];
	max=R[1]-R[0];
	
	for(i=0; i<n; i++)
	{
		if(R[i]<min)
		{
			min=R[i];
		}
		
		if(i !=n-1)
		{
		    
		k=R[i+1]-min;
		if(k>max)
		{
			max=k;
		}
		}
	}
	
	printf("%d\n",max);
	
	return 0;
	
}



Measured memory_bytes: 3468
#include <iostream>

using namespace std;

int main()
{
	int c[3];

	while(cin >> c[0] >> c[1] >> c[2])
	{
		int card[11] = {0}, cont = 0;
		card[c[0]] = 1;
		card[c[1]] = 1;
		card[c[2]] = 1;

		for(int i=1; i<11; i++)
		{
			if(!(card[i])){
				if(c[0] + c[1] + i <= 20){
					cont++;
				}
			}
		}

		if(cont >= 4)	cout << "YES" << endl;
		else			cout << "NO"  << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int h;
  int w;
  while(1){
    cin>>h>>w;
    if(h==0 && w==0) break;
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if((i+j)%2==0)
	  cout<<"#";
	else
	  cout<<".";
      }
      cout<<endl;
    }
    cout<<endl;
  }
  return 0;  
}



Measured memory_bytes: 3100
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main(){
        int c1x, c1y, c1z;
        int c2x, c2y, c2z;
        int z1, z2;

        double result;

        scanf("%d %d %d", &c1x, &c1y, &c1z);
        scanf("%d %d %d", &c2x, &c2y, &c2z);

        result = sqrt((c1x - c2x) * (c1x - c2x) + (c1y - c2y) * (c1y - c2y));

        z1 = c1z + c2z;
        z2 = c1z - c2z;

        if(result > z1)
                {
                        printf("4\n");
                }else if(result == z1)
                {
                        printf("3\n");
                }else if((result > abs(z2)) && (result < z1)){
                        printf("2\n");
                }else if(result == abs(z2)){
                        printf("1\n");
                }else if(result < abs(z2)){
                        printf("0\n");
                }

                return 0;
}


Measured memory_bytes: 2112