akhauriyash/Code-Regression huggingface dataset:
/* cerberus97 - Hanit Banga */

#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <chrono>
#include <random>

using namespace std;

#define pb push_back
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)

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

const int N = 15;
const ll MX = (1e11 / 9);

ll e[N][N];
set<ll> st[N];
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(int n);
ll get_max(int n);
bool check(int n);

int main() {
	fast_cin();
	int n; cin >> n;
	solve(n);
	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			cout << e[i][j] << ' ';
		}
		cout << '\n';
	}
}

void solve(int n) {
	vector<int> sum_free = {0, 1, 2, 4, 7, 12, 20, 29, 38, 52, 73};
	e[1][2] = e[2][1] = 1;
	ll M = 1;
	for (int i = 3; i <= n; ++i) {
		for (int j = 1; j < i; ++j) {
			e[i][j] = e[j][i] = M * sum_free[(i == 3 ? j + 1 : j)];
		}
		M = get_max(i);
	}
	// cout << M / (1e11) << endl;
	// cout << M << endl;
	// check(n);
	// cout << check(n) << endl;
}

ll get_max(int n) {
	vector<int> perm;
	for (int i = 1; i <= n; ++i) {
		perm.pb(i);
	}
	ll ans = 0;
	do {
		if (perm[0] > perm[n - 1]) {
			continue;
		}
		ll sum = 0;
		for (int i = 0; i < n - 1; ++i) {
			sum += e[perm[i]][perm[i + 1]];
		}
		ans = max(ans, sum);
	} while (next_permutation(perm.begin(), perm.end()));
	return ans;
}

bool check(int n) {
	vector<int> perm;
	for (int i = 1; i <= n; ++i) {
		perm.pb(i);
	}
	set<ll> all_sums;
	int ctr = 0;
	do {
		if (perm[0] > perm[n - 1]) {
			continue;
		}
		++ctr;
		ll sum = 0;
		for (int i = 0; i < n - 1; ++i) {
			sum += e[perm[i]][perm[i + 1]];
		}
		all_sums.insert(sum);
	} while (next_permutation(perm.begin(), perm.end()));
	cout << ctr << ' ' << all_sums.size() << endl;
	return (ctr == all_sums.size());
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010


int main(){
  int n,x,a[SIZE];
  ll ans = 0;
  
  scanf("%d%d",&n,&x);

  for(int i=0;i<n;i++){
    scanf("%d",a+i);
  }

  if(a[0] > x){
    ans = a[0] - x;
    a[0] = x;
  }
  
  for(int i=1;i<n;i++){
    if(a[i-1] + a[i] > x){
      ans += a[i-1] + a[i] - x;
      a[i] -= a[i-1] + a[i] - x;
    }
  }
  
  printf("%lld\n",ans);
  
  return 0;
}


Measured memory_bytes: 764
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000000000000000000000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define REP(i,n) for(long long i = 0;i < n;++i)                                                                             
#define seg_size 524288
int main() {
	long long r, c,n;
	cin >> r >> c >> n;
	vector<pair<int, int>> wow[4];
	REP(i, n) {
		vector<pair<int, int>> nyaw[4];
		int geko_cnt = 0;
		REP(q, 2) {
			int a, b;
			cin >> a >> b;
			if (a == 0) {
				geko_cnt++;
				nyaw[0].push_back(make_pair(b, i));
			}
			else if (b == c) {
				geko_cnt++;
				nyaw[1].push_back(make_pair(a, i));
			}else if(b == 0){
				nyaw[3].push_back(make_pair(r - a, i));
				geko_cnt++;
			}
			else if(a == r){
				geko_cnt++;
				nyaw[2].push_back(make_pair(c - b, i));
			}
		}
		if (geko_cnt == 2) {
			for (int q = 0;q < 4;++q) {
				for (int t = 0;t < nyaw[q].size();++t) {
					wow[q].push_back(nyaw[q][t]);
				}
			}
		}
	}
	stack<int> geko;
	map<int, int> appeared;
	REP(i, 4) {
		sort(wow[i].begin(), wow[i].end());
		for (int q = 0;q < wow[i].size();++q) {
			if (appeared[wow[i][q].second] == true) {
				int nya = geko.top();
				geko.pop();
				if (nya != wow[i][q].second) {
					cout << "NO" << endl;
					return 0;
				}
			}
			else {
				geko.push(wow[i][q].second);
				appeared[wow[i][q].second] = true;
			}
		}
	}
	cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 6576
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    char a,b;
    cin >> a >> b;
    if(a == b) cout << "H" << endl;
    else cout << "D" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (n); i++)
#define RREP(i, n) for (int i = (n); i >= 0; i--)
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;

const int INF = 200000000;
const int MOD = 1e9 + 7;

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

    int a, b, c;
    cin >> a >> b >> c;

    cout << min(b / a, c) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
  int n,h,i=0,j=0,b;
  cin>>n>>h;
  if(n==0){
  while(i!=h){
    j++;
    if(j%100!=0){
      i++;}
  }
  }
  else if(n==1){
    while(i!=h){
    j++;;
    if((j*100)%10000!=0)
      i++;
  }
    j=j*100;
  }
  else{
     while(i!=h){
    j++;;
    if((j*10000)%1000000!=0)
      i++;
  }
    j=j*10000;
  }
    
  cout<<j<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <set>
#include <vector>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define Repr(e, b, i) for(int i = e; i >= b; i--)
#define rep(n, i) Rep(0, n-1, i)
#define repr(n, i) Repr(n-1, 0, i)
#define all(v) (v).begin(), (v).end()
#define pb(v) push_back(v)
#define uniq(v) (v).erase(unique(all(v)),(v).end())
#define bitcnt(x) __builtin_popcount(x)
#define fst first
#define snd second
#define Pqaz(T) priority_queue<T,vector<T>,greater<T>>
#define Pqza(T) priority_queue<T>
#define ENJYU std::ios::sync_with_stdio(false);std::cin.tie(0);

typedef long long ll;
typedef pair<ll, ll> llP;
typedef pair<int, int> intP;

//vector の中身を出力
template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

void solve(void){
	int N;
	cin >> N;
	vector <int> a(N);
	rep(N, i) {
		cin >> a[i];
		a[i]--;
	}
	int ans = 0;
	rep(N, i) {
		ans += a[a[i]] == i;
	}
	cout << ans / 2 << endl;
}

int main(void){
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <iostream>
#include <algorithm>
using namespace std;
#define MOD1 1000000007
#define MOD2 998244353
#define LIMIT1 200002
#define LIMIT2 500002
typedef long long ll;
typedef long double ld;
typedef const void cv;
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define per(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define max(a,b) ((a)>(b) ? (a) : (b))
#define min(a,b) ((a)<(b) ? (a) : (b))
#define zt(a,b) (max((a),(b))-min((a),(b)))
#define absl(v) labs((v))
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll nPr(int n,int r){ll i,result=1;rep(i,r){result*=(ll)(n-i);}return result;}
ll nCr(int n,int r){ll i,result=1;if(n<r) return 0;rep(i,min(r,n-r)){result*=(ll)(n-i);result/=(ll)(i+1);}return result;}
#define nHr(n,r) nCr((int)((n)+(r)+1),(int)(r))
#define sankaku(x) (((x)*((x)+1))/2)
int dx[8]={1,0,-1,0,1,-1,-1,1},dy[8]={0,1,0,-1,1,1,-1,-1};
int upint(cv *a, cv *b) { return *(int *)a < *(int *)b ? -1 : *(int *)a > *(int *)b ? 1 : 0; }
int downint(cv *a, cv *b) { return *(int *)a < *(int *)b ? 1 : *(int *)a > *(int *)b ? -1 : 0; }
int upchar(cv *left, cv *right) {return strcmp((char *)left,(char *)right);}
int downchar(cv *left, cv *right) {return strcmp((char *)right,(char *)left);}
void tmpInit(int *c,ll m) {ll i;rep(i,m) c[i]=i;}
ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1){
      res *= a; if(mod>=1) res %= mod;
    }
    a *= a; if(mod>=1) a %= mod;
    n >>= 1;
  }
  return res;
}
void initialize(){
  
}
int main(void){
  initialize();
  ll n,m,i,j,k,result=0;
  int a[LIMIT2]={0};
  char s[LIMIT1];
  
  cin >> n;
  cin >> s;
  if(n%2 == 1){
    cout << "No" << endl;
    return 0;
  }
  rep(i,n/2){
    if(s[i]!=s[n/2+i]){
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << 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++)
typedef long long ll;


int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    int         N;
    long double sum = 0;
    long double ans = 0;
    int         j   = 0;
    int         fac = 1;
    cin >> N;
    vector <int> v(N);
    vector <int> x(N);
    vector <int> y(N);
    rep(i, N) {
        cin >> x.at(i);
        cin >> y.at(i);
    }

    for (int i = N; i >= 1; i--) {
        fac *= i;
    }
    int pattern[fac][N];
    iota(v.begin(), v.end(), 1);       // v に 1, 2, ... N を設定
    do {
        for (int k = 0; k < N; k++) {
            pattern[j][k] = v.at(k);
        }
        j++;
        // for (auto x : v) { cout << x << " "; } cout << "\n";    // v の要素を表示
    } while (next_permutation(v.begin(), v.end()) );     // 次の順列を生成

    /*rep(i, fac) {
        rep(j, N) {
            cout << pattern[i][j];
        }
        cout << endl;
    }*/
    rep(i, fac) {
        rep(k, N - 1) {
            sum += (long double) sqrt(((x.at(pattern[i][k] - 1)) - (x.at(pattern[i][k + 1] - 1))) * ((x.at(pattern[i][k] - 1)) - (x.at(pattern[i][k + 1] - 1))) + ((y.at(pattern[i][k] - 1)) - (y.at(pattern[i][k + 1] - 1))) * ((y.at(
                                                                                                                                                                                                                                      pattern[i]
                                                                                                                                                                                                                                      [k] -
                                                                                                                                                                                                                                      1)) -
                                                                                                                                                                                                                                 (y.at(
                                                                                                                                                                                                                                      pattern[i]
                                                                                                                                                                                                                                      [k + 1] -
                                                                                                                                                                                                                                      1))));
        }
        ans += sum;
        sum  = 0;
    }
    ans = (long double) ans / (long double) fac;
    cout << (long double) ans << endl;



    return 0;
}


Measured memory_bytes: 1536
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#include <functional>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi   vector<int> 
#define   co(x)  cout << x << '\n' 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

inline void solve(){
    int n,total=0,ans = 0 ; 
    cin>>n; 
    bool  ok = true ; 
    vi a(n+1); 
    for (int  i=0 ; i<=n ; i++ ) { 
    	cin >> a[i] ; 
    	total += a[i] ; 
    } 
    for ( int i = 0,cur = 1 ; i <= n; i++ ) { 
    	ans += cur;
    	if (a[i] > cur) ok = false ; 
    	cur -= a[i];
    	total -= a[i]; 
    	if (cur *2 > total ) cur = total;
    	else cur *= 2;
    } 
    cout << (ok?to_string(ans):to_string(-1)) << endl ; 
}
/*
3
0 1 1 2
*/

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 4056
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

bool in(ll y, ll x, ll h, ll w){
	return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
	ll h,w,k; cin >> h >> w >> k;
	vs s(h); rep(i,h) cin >> s[i];
	vvl d(h,vl(w,inf));
	queue<pair<P,ll>> q, que;
	rep(i,h){
		rep(j,w){
			if(s[i][j]=='S'){
				q.emplace(P(i,j),k);
				que.emplace(P(i,j),0);
				d[i][j] = 1;
			}
		}
	}
	while(!q.empty()){
		auto p = q.front(); q.pop();
		if(p.second == 0) continue;
		ll y = p.first.first;
		ll x = p.first.second;
		rep(i,4){
			ll ny = y + dy[i];
			ll nx = x + dx[i];
			if(in(ny,nx,h,w)){
				if(s[ny][nx] == '#') continue;
				if(d[ny][nx] == 1) continue;
				d[ny][nx] = 1;
				q.emplace(P(ny,nx),p.second-1);
				que.emplace(P(ny,nx),0);
			}
		}
	}
	while(!que.empty()){
		auto p = que.front(); que.pop();
		ll y = p.first.first;
		ll x = p.first.second;
		rep(i,4){
			ll ny = y + dy[i];
			ll nx = x + dx[i];
			if(in(ny,nx,h,w)){
				if(d[ny][nx] != inf) continue;
				ll c = 0, K;
				if(p.second == 0){
					c++;
					K = k - 1;
				}else{
					K = p.second - 1;
				}
				d[ny][nx] = d[y][x] + c;
				que.emplace(P(ny,nx),K);
			}
		}
	}
	ll ans = inf;
	rep(j,w) chmin(ans, min(d[0][j], d[h-1][j]));
	rep(i,h){
		chmin(ans, min(d[i][0], d[i][w-1]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 21300
#include "bits/stdc++.h"
using namespace std;


int main()
{
        int a, b, c, x, y;
        scanf("%d %d %d", &a, &b, &c);
        scanf("%d %d", &x, &y);

        int cc = c * 2;
        int ab = a + b;

        long long ans = 0LL;

        if( cc < ab ) {
                int mi = min(x, y);
                x -= mi;
                y -= mi;
                ans = 1LL * cc * mi;
        }
        if( x ) {
                long long one = 1LL * x * 2LL * c;
                long long two = 1LL * a * x;
                ans += min(one, two);
        }
        if( y) {
                long long one = 1LL * y * 2LL * c;
                long long two = 1LL * b * y;
                ans += min(one, two);
        }

        printf("%lld\n", ans);


        return 0;
}


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

mod = 998244353

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

inv2 = pow(2, mod-2, mod)
dp = [[0]*(S+1) for _ in range(N+1)]

dp[0][0] = pow(2, N, mod)
for i, a in enumerate(A):
    dp[i+1] = dp[i][:]
    for s in range(S-a+1):
        dp[i+1][s+a] = (dp[i+1][s+a] + dp[i][s] * inv2) % mod

print(dp[N][S])

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

int main(){
    long long h,w;
    cin >> h >> w;
    if(h==1 || w==1)
    cout << 1;
    else if(h%2==0 && w%2==0)
    cout << h*w/2;
    else if(h%2==1 && w%2==1)
    cout << (h/2+1)*(w/2+1)+(h/2)*(w/2);
    else if(h%2==1 && w%2==0)
    cout << w/2*h;
    else if(h%2==0 && w%2==1)
    cout << h/2*w;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define ld long double
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) { cin >> A[i]; }

    vector<ll> dp;
    rep(i, N) {
        int j = lower_bound(all(dp), A[i]) - dp.begin();
        if (j == dp.size()) {
            dp.push_back(A[i]);
        } else {
            dp[j] = A[i];
        }
    }

    cout << dp.size() << endl;
}


Measured memory_bytes: 4256
A,B = map(int,input().split())
def button(A,B):
  aa= A+(A-1)
  ab = A+B
  bb = B+(B-1)
  if aa>=bb and aa>=ab:
    return aa
  if bb>=aa and bb>=ab:
    return bb
  if ab>=aa and ab>=bb:
    return ab
print(button(A,B))

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

typedef long long ll;
typedef long double ld;

int main() {
	cin.tie(0);
    ios::sync_with_stdio(false);
 
    ll A, B;
    double b;
    cin >> A >> b;
 
    B = static_cast<ll> ((b + 0.001) * double(100));
 
    cerr << A * B << endl;
 
    cout << A * B / 100LL << endl;
}

Measured memory_bytes: 3728
h,w,k=map(int, input().split( ))
c=[input() for _ in range(h)]
bh=1<<h
bw=1<<w
ans=0
for i in range(bh):
    for j in range(bw):
        cnt=0
        for x in range(h):
            for y in range(w):
                if (1&(i>>x)) or (1&(j>>y)) or c[x][y]==".":
                    continue
                cnt+=1
        if cnt==k:
            ans+=1
                
print(ans)

Measured memory_bytes: 73692
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define dbg(x) cerr << #x << ": " << x << endl
const ll mod = 1000000007;
ll dp[105][10];
int main() {
  int h, w, k;
  cin >> h >> w >> k;
  dp[0][1] = 1LL;
  auto lok = [&](int bm, int j) {
    if(j == 1) return false;
    if(!(bm & (1 << (j - 2)))) return false;
    rep(i, w - 2) if(3 == ((bm >> i) & 3) % 4) return false;
    return true;
  };
  auto rok = [&](int bm, int j) {
    bool res = true;
    if(j == w) return false;
    if(!(bm & (1 << (j - 1)))) return false;
    rep(i, w - 2) if(3 == ((bm >> i) & 3) % 4) return false;
    return true;
  };
  auto cok = [&](int bm, int j) {
    bool res = true;
    if(j != 1)
      if(bm & (1 << (j - 2))) return false;
    if(j != w)
      if(bm & (1 << (j - 1))) return false;
    rep(i, w - 2) if(3 == ((bm >> i) & 3) % 4) return false;
    return true;
  };

  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      rep(bm, (1 << (w - 1))) {
        if(lok(bm, j))
          dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % mod;
        if(rok(bm, j))
          dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % mod;
        if(cok(bm, j))
          dp[i][j] = (dp[i][j] + dp[i - 1][j]) % mod;
      }
    }
  }
  cout << dp[h][k] << endl;
  return 0;
}

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

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

    string contest;
    cin >> contest;

    if (contest == "ABC") cout << "ARC";
    else cout << "ABC";
}

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

#define MAX 200002

int n;

int par[MAX];
int val[MAX];

struct st{
	long long int w;
	long long int b;
	long long int inv;
	int id;
	st(int w_=0,int b_=0,int id_=0){
		w = w_;
		b = b_;
		id = id_;
		inv = 0;
	}
	bool operator !=(const st &a)const{
		return a.w + a.b != w + b;
	}
	bool operator< (const st &a)const {
		return w*a.b < a.w*b;
	}
	void operator += (const st&a){
		inv += b*a.w;
		w += a.w;
		b += a.b;
		inv += a.inv;
	}
};

priority_queue<st> q;

int belong[MAX];
inline int root(int b){
	if (belong[b] == -1){
		return b;
	}
	return belong[b] = root(belong[b]);
}
void merge(int a, int b){
	a = root(a);
	b = root(b);
	if (a == b){

	}
	else{
		belong[a] = b;
	}
}
vector<st> vv;
int main(){
	cin >> n;
	par[0] = -1;
	for (int i = 1; i < n; i++){
		scanf("%d", &par[i]);
		par[i]--;
	}
	for (int j = 0; j < n; j++){
		scanf("%d", &val[j]);
	}
	for (int i = 0; i < n; i++){
		if (val[i] == 0){
			q.push(st( 1, 0 ,i));
			vv.push_back(st(1, 0, i));
		}
		else{
			q.push(st( 0, 1 ,i));
			vv.push_back(st(0, 1, i));
		}
	}
	memset(belong, -1, sizeof(belong));
	while (!q.empty()){
		auto x = q.top();
		if (vv[x.id] != x){
			q.pop();
			continue;
		}
		q.pop();
		int child = x.id;
		if (child == 0)continue;
		int p = -1;
		if (child)p = root(par[x.id]);
		merge(child, p);
		vv[p] += vv[child];
		q.push(vv[p]);
	}
	printf("%lld\n", vv[0].inv);
	return 0;
}

Measured memory_bytes: 18132
#include<bits/stdc++.h>
using namespace std;
int main(void){
    int N,a,count;
    count=0;
    cin>>N>>a;
    for(int i=1;i<N+1;i++){
        if(i%2==1){
            if(a%2==1){
                count++;
            }
        }

        cin>>a;
    }
    cout<<count<<endl;

}

Measured memory_bytes: 3592
import sys, bisect, math, itertools, string, queue, copy
# import numpy as np
# import scipy
# from collections import Counter,defaultdict,deque
# from itertools import permutations, combinations
# from heapq import heappop, heappush
# # input = sys.stdin.readline
# sys.setrecursionlimit(10**8)
# mod = 10**9+7
def inp(): return int(input())
def inpm(): return map(int,input().split())
def inpl(): return list(map(int, input().split()))
def inpls(): return list(input().split())
def inplm(n): return list(int(input()) for _ in range(n))
def inplL(n): return [list(input()) for _ in range(n)]
def inplT(n): return [tuple(input()) for _ in range(n)]
def inpll(n): return [list(map(int, input().split())) for _ in range(n)]
def inplls(n): return sorted([list(map(int, input().split())) for _ in range(n)])

n = int(input())
l = inpl()
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if(l[i] != l[j] and l[j] != l[k] and l[k] != l[i]):
                if(l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]):
                    ans = ans + 1
print(ans)

Measured memory_bytes: 76536
import math

# 0以上整数x「未満」の素数をリストに格納して返す
def primes(x):
    if x < 2: return []

    primes = [i for i in range(x)]
    primes[1] = 0 # 1は素数ではない

    # エラトステネスのふるい
    for prime in primes:
        if prime > math.sqrt(x): break
        if prime == 0: continue
        for non_prime in range(2 * prime, x, prime): primes[non_prime] = 0

    return [prime for prime in primes if prime != 0]


# 整数xが素数かどうかを判定する
def is_prime(x):
    if x < 2: return False # 2未満に素数はない
    if x == 2 or x == 3 or x == 5: return True # 2,3,5は素数
    if x % 2 == 0 or x % 3 == 0 or x % 5 == 0: return False # 2,3,5の倍数は合成数

    # ためし割り: 疑似素数(2でも3でも5でも割り切れない数字)で次々に割っていく
    prime = 7
    step = 4
    while prime <= math.sqrt(x):
        if x % prime == 0: return False

        prime += step
        step = 6 - step

    return True

plist = primes(55555)
N = int(input())

ans = []
for i in plist:
  if i % 5 == 1:
    ans.append(i)

#print(ans[0:N])
print(" ".join(list(map(str,ans[0:N]))))


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

using namespace std;

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



    return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100000
int times(void);
int partition(int*, int, int);
void temp(int*,int*);
void view(int*,int,int);
int main() {
	int n,i,A[N],q;
	n = times();
	for (i = 0;i < n;i++) {
		scanf("%d", &A[i]);
	}
	q = partition(A, 0, n);
	view(A, n, q);
}
int partition(int*A, int p, int r) {
	int x, i,j;
	x = A[r-1];
		i = p;
		if (A[i] <= x)i++;
		for (j = p+1; j < r; j++) {
			if (A[j] <= x) {
				//A[i] �� A[j] ������
				temp(&A[i],&A[j]);
				i++;
			}
		}
   return i;
}
void temp(int* x, int* y) {
	int t;
	t = *x;
	*x = *y;
	*y = t;
}
int times() {
	int n;
	scanf("%d",&n);
	return n;
}
void view(int*A,int n,int q) {
	int i;
	for (i = 0; i < n; i++) {
		if (i)printf(" ");
		if (i == q-1)printf("[");
		printf("%d",A[i]);
		if (i == q-1)printf("]");
	}
	printf("\n");
}


Measured memory_bytes: 2144
n=int(input())
s=input()


ev=[0]
for c in s:
    if c=='(':
        ev.append(ev[-1]+1)
    else:
        ev.append(ev[-1]-1)
lowest = -min(ev)


numL = lowest + s.count('(')
numR = s.count(')')

Left = lowest
Right = numL-numR

for i in range(Left):
    print('(',end="")
print(s,end="")
for i in range(Right):
    print(')',end="")
print()


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

using namespace std;

#define ll long long
#define endl '\n'
const int N = 1e5 + 5;
ll a[N], st[N * 10], b[N], sum[N];
void upd(ll k, ll l, ll r, ll x, ll v){
        if (x > r || x < l) return;
        if (l == r){
                st[k] = st[k] + v;
                return;
        }
        ll mid = (l + r) >> 1;
        upd(k << 1, l, mid, x, v);
        upd(k << 1 | 1, mid + 1, r, x, v);
        st[k] = st[k << 1] + st[k << 1 | 1];
}
ll get(ll k, ll l, ll r, ll x, ll y){
        if (x > r || y < l) return 0;
        if (x <= l && y >= r) return st[k];
        ll mid = (l + r) >> 1;
        return get(k << 1, l, mid, x, y) + get(k << 1 | 1, mid + 1, r, x, y);
}
int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(0);
        if (fopen("VietCT.INP", "r")){
                freopen("VietCT.INP", "r", stdin);
                freopen("VietCT.OUT", "w", stdout);
        }
        ll n;
        cin >> n;
        for (int i = 1; i <= n; i++) cin >> a[i];
        ll l = 1, h = 1e9;
        ll total = n * (n - 1) / 2 + n;
        while (l <= h){
                ll mid = (l + h) >> 1;
                for (int i = 1; i <= n; i++){
                        if (a[i] >= mid) b[i] = 1;
                        else b[i] = -1;
                }
                memset(st, 0, sizeof(st));
                for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + b[i];
                upd(1, 1, 2 * n + 1, n + 1, 1);
                ll res = 0;
                for (int i = 1; i <= n; i++){
                        res = res + get(1, 1, 2 * n + 1, 1, sum[i] + n + 1);
                        upd(1, 1, 2 * n + 1, sum[i] + n + 1, 1);
                }
                if ((res * 2) >= total) l = mid + 1;
                else h = mid - 1;
        }
        cout << h;
}
/*
*/


Measured memory_bytes: 13728
#include<bits/stdc++.h>
using namespace std;
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define pa pair<int,int>
#define mod 1000000007
#define ll long long
#define mk make_pair
#define pb push_back
#define fi first
#define se second
#define cl(x) memset(x,0,sizeof x)
#ifdef Devil_Gary
#define bug(x) cout<<(#x)<<" "<<(x)<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#else
#define bug(x)
#define debug(...)
#endif

const int INF = 0x7fffffff;
const int N=6e5+5;
/*
char *TT,*mo,but[(1<<15)+2];
#define getchar() ((TT==mo&&(mo=(TT=but)+fread(but,1,1<<15,stdin),TT==mo))?-1:*TT++)//*/
inline int read(){
    int x=0,rev=0,ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')rev=1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
    return rev?-x:x;
}/*
struct Edge{
	int nxt,v;
//	int w;
//	int id;
}e[N<<1];
void add(int u,int v){
	e[++tot].v=v,e[tot].nxt=head[u],head[u]=tot;
	e[++tot].v=u,e[tot].nxt=head[v],head[v]=tot;
}*/
ll n,m,ans,a[N],t[N],val[N];
void add(int l,int r,int op,int pos){
//	bug(1);
//cerr<<l<<" "<<r<<endl;
	ll ret,tt,p2;
	for(int i=l;i<=r;i++){
		tt=0,ret=1,p2=a[i]+(n/2)-1;
//		bug(p2),bug(val[i]);
		while(p2){
//			bug(p2); 
			if(!op) (t[p2]+=val[i]*ret)%=mod;
			else (ans+=(t[p2]-tt+mod)*ret%mod*val[i]%mod*p2%mod*pos%mod)%=mod,(tt=t[p2]*p2%mod)%=mod;
			ret=ret*p2%mod,p2>>=1;
		}
	}
}
void clear(int l,int r){
	for(int i=l;i<=r;i++){
		int p2=a[i]+(n/2)-1;
		while(p2){
			t[p2]=0,p2>>=1;
		}
	}
}
void dfs(int pos,int l,int r){
	if(l==r) {
		val[l]=1LL;
//		bug(1);
//		bug(pos);
		return;
	}
	
	int mid=l+r>>1;
	dfs(pos<<1,l,mid),dfs(pos<<1|1,mid+1,r);
	
	for(int i=l;i<=mid;i++) val[i]=val[i]*(pos<<1)%mod;
	for(int i=mid+1;i<=r;i++) val[i]=val[i]*(pos<<1|1)%mod;
	
	add(l,mid,0,pos),add(mid+1,r,1,pos);
	clear(l,r);
//	for(int i=l;i<=mid;i++)
}
int main(){
#ifdef Devil_Gary
    freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
#endif	
	m=read(),n=pow(2,m);
	for(int i=1;i<=n/2;i++) a[i]=read();
	dfs(1,1,n/2);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8156
S = list(input())
a = ['0' if x%2==0 else '1' for x in range(len(S))]
b = ['1' if x%2==0 else '0' for x in range(len(S))]
ca, cb = 0, 0
         
for i in range(len(S)):
  if S[i] != a[i]:
    ca += 1
  if S[i] != b[i]:
    cb += 1
    
print(min(ca, cb))   

Measured memory_bytes: 5540
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const int INF = 1e9;
const int MOD = 1000000007;
#define rep(i,n) for(int i=0;i<n;i++)
vector<ll> len(51,1);

ll dfs(int i,ll j){
  if(i==0) return 1;
  if(j<=1) return 0;
  if(j<=len.at(i-1)+1) return dfs(i-1,j-1);
  if(j<=len.at(i-1)+2) return dfs(i-1,len.at(i-1))+1;
  if(j<=len.at(i)-1) return dfs(i-1,len.at(i-1))+dfs(i-1,j-len.at(i-1)-2)+1;
  return 2*dfs(i-1,len.at(i-1))+1;
}
 
int main() {
  int n;
  ll x;
  cin >> n >> x;
  rep(i,50) len.at(i+1) = 2*len.at(i) + (3);
  cout << dfs(n,x) << endl;  
  return 0;
}







Measured memory_bytes: 256
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        return mint(*this) /= a;
    }
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int n, k;
    cin >> n >> k;

    vector<pair<int, int>> lr;
    REP(i, k) {
        int l, r;
        cin >> l >> r;
        lr.eb(l, r);
    }

    vector<mint> dp(n, 0);
    dp[0] = 1;

    vector<mint> s(k, 0);
    FOR(i, 1, n) {
        REP(j, k) {
            int l = lr[j].fi, r = lr[j].se;
            if (i - l >= 0) s[j] += dp[i - l];
            if (i - r - 1 >= 0) s[j] -= dp[i - r - 1];

            dp[i] += s[j];
        }

        debug(s)
    }

    print(dp[n - 1]);
    
}


Measured memory_bytes: 4780
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>

using namespace std;

#define ll long long
#define ld long double
#define EPS 0.0000000001
#define INF 1e9
#define rep(i,n) for(i=0;i<n;i++)
#define loop(i,a,n) for(i=a;i<n;i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

typedef vector<int> vi;
typedef pair<int,int> pii;

int main(void) {
  int i,j;
  int n;
  while(1){
    cin>>n;
    if(n==0)break;
    string s;
    cin>>s;
    vi num(n,0);
    int p=0;
    rep(i,100){
      if(s[i]=='M')
        num[i%n]++;
      else if(s[i]=='S'){
        p+=num[i%n]+1;
        num[i%n]=0;
      }else{
        num[i%n]+=p+1;
        p=0;
      }
    }
    sort(all(num));
    rep(i,n)
      cout<<num[i]<<" ";
    cout<<p<<endl;
  }
}

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

const ll mod = 1'000'000'007;


int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	int n; cin >> n;
	vector<ll> a(n); 
	rep(i,n) cin >> a.at(i);
	sort(a.begin(), a.end(), greater<ll>());
	ll ans = 0, tmp = 1; int d = 0;
	while((a.at(0) >> d) > 0){
		ll cnt0 = 0, cnt1 = 0;
		for(int j = 0; j < n; j++){
			if((a.at(j) >> d) & 1) cnt1++;
			else cnt0++;
		}
		d++;
		ll mul = cnt1 * cnt0; mul %= mod;
		ans += mul * tmp;
		ans %= mod;
		tmp *= 2;
		tmp %= mod;
	}
	cout << ans << endl;
} 

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

//using namespace std;


int main(){
  string moji;cin>>moji;
  int pcount;
  int len = moji.size();
  for(int i=0;i<len;i++){
    if(moji[i]=='p'){
      pcount+=1;
    }

  }
  cout<<(len/2)-pcount<<endl;
}

Measured memory_bytes: 512
class exist_negative_cycle(Exception):
    pass
def bellman_ford(g, size, start=0):
    d = [float('inf')] * size
    d[start] = 0
   
    for _ in range(size):
        for u in g:
            for length, v in g[u]:
                if d[v] > d[u] + length:
                    d[v] = d[u] + length

    for u in g:
        for length, v in g[u]:
            if d[v] > d[u] + length:
                raise exist_negative_cycle    
    return d
from sys import stdin
readline = stdin.readline
import math
from collections import defaultdict

vertex, edge, r = map(int, readline().split())

g = defaultdict(list)
for i in range(edge):
    s, t, length = map(int, readline().split())
    g[s].append((length, t))
try:
    d = bellman_ford(g, vertex, r)
    for di in d:
        print('INF' if math.isinf(di) else di)
except exist_negative_cycle:
    print('NEGATIVE CYCLE')

Measured memory_bytes: 7188
#include<bits/stdc++.h>
#define mod 1000000007
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
signed main()
{   
      senky_bansal
      IIIT_ALLAHABAD
       
      ll a,b,c;
  cin>>a>>b>>c;
  cout<<min(a*b,c);
      
      
      
      
}









Measured memory_bytes: 256
n = int(input())
a = [0] + list(map(int, input().split()))

dp = [0, 0] + [1e17]*(n+10)
dp[2] = abs(a[2] - a[1])
for i in range(3,n+1):
    dp[i] = min(dp[i-1]+abs(a[i]-a[i-1]), dp[i-2] + abs(a[i]-a[i-2]))
print(dp[n])

Measured memory_bytes: 13980
#include <iostream>
#include <cmath>
#include <string>

using namespace std;

int main() {
    long long n;
    cin >> n;
    bool enable = false;
    long long price;
    for (long long i = 1; i <= n; ++i) {
        if (floor(i * 1.08) == n) {
            enable = i;
            price = i;
            break;
        }
    }
    cout << (enable ? to_string(price) : ":(") << endl;
    return EXIT_SUCCESS;
}

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

int main()
{
    ios::sync_with_stdio(false);
    vector<int> v(5);
    int k;

    for(int i=0;i<5;i++){
        cin >> v[i];
    }

    cin >> k ;

    for (int i = 0; i < 5; i++)
    {
        for (int j = i+1; j < 5; j++)
        {
            if(v[j]-v[i]>k){
                cout<<":("<<endl;
                return 0;
            }
        }
    }

    cout<<"Yay!"<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define prime 1000000007
#define INF 40000000000000000
int dx8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
int dy8[8] = {1, 1, 1, 0, -1, -1, -1, 0};
int dx4[4] = {-1, 0, 1, 0};
int dy4[4] = {0, -1, 0, 1};
signed main(void) {
    int fib[48];
    fib[0] = 1;
    fib[1] = 1;
    rep(i, 45) fib[i + 2] = fib[i + 1] + fib[i];
    int n;
    cin >> n;
    cout << fib[n] << endl;
}



Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(0);cin.tie();cout.tie();
#define ff first
#define ss second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const ll mod = 1e9 + 7;
const ll inf = 9223372036854775807;
const ll mininf = -9223372036854775807;
const ll nax = 0;
long long duit=100, n, cnt=0;

int main(){
	IOS
	cin >> n;
	while(duit<n){
		cnt++;
		duit+=(duit/100);
	}
	cout << cnt << '\n';
}

Measured memory_bytes: 3620
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function bsearch(a,x)
	l,r = 1, length(a)
	while l <= r
		m = l+div(r-l,2)
		if a[m] < x
			l = m+1
		else
			r = m-1
		end
	end
	return(l-1)
end

function main()
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	b = Array{Int}(n)
	b[1] = a[1]
	for i in 2:n
		b[i] = b[i-1] + a[i]
	end
	m = 200000000000000
	indm = 0
	for i in 2:n-2
		j = max(bsearch(b,b[i]/2),1)
		k = max(bsearch(b,b[i]+(b[n]-b[i])/2),i+1)
		fhsa = max(b[j],b[i]-b[j])
		fhia = min(b[j],b[i]-b[j])
		fhsb = max(b[j+1],b[i]-b[j+1])
		fhib = min(b[j+1],b[i]-b[j+1])
		shsa = max(b[k]-b[i],b[n]-b[k])
		shia = min(b[k]-b[i],b[n]-b[k])
		shsb = max(b[k+1]-b[i],b[n]-b[k+1])
		shib = min(b[k+1]-b[i],b[n]-b[k+1])
		m = min(m,max(fhsa,shsa)-min(fhia,shia),max(fhsa,shsb)-min(fhia,shib),max(fhsb,shsa)-min(fhib,shia),max(fhsb,shsb)-min(fhib,shib))
	end
	println(m)
end

main()


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

const int MAXN = 1e2+5;
const int MAXNN = 1e5+7;
const int INF = 1e9+7;
#define ll long long
#define pb push_back
#define endl '\n'
#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second

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

ll MOD(ll a){
    return ((a%INF)+INF)%INF;
}

ll inv(ll a){
    return poww(a,INF-2,INF);
}

ll w[MAXN],val[MAXN],dp[MAXN][MAXNN];

int main()
{
    fast_io;
    //cout << fixed << setprecision(15);

    int n,cap;cin >> n >> cap;
    for(int i=1;i<=n;++i) cin >> w[i] >> val[i];

    for(int i=1;i<=n;++i){
        for(int j=1;j<=cap;++j){
            dp[i][j] = dp[i-1][j];
            if(j >= w[i]) dp[i][j] = max(dp[i][j],dp[i-1][j-w[i]] + val[i]);
        }
    }
    cout << dp[n][cap];
}


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

ll mpow(ll a, ll b){
	if(b==0) return 1;
	else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
	else return mpow(a,b-1) * a % MOD;
}
ll gcd(ll a, ll b){
	if(b==0) return a;
	else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
	if(kaijo_memo.size() > n) return kaijo_memo[n];
	if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
	while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
	return kaijo_memo[n];
}
ll nCr(ll n, ll r){
	if(n < r || r < 0) return 0;
	ll ret = 1;
	ret *= kaijo(n); ret %= MOD;
	ret *= mpow(kaijo(r), MOD-2); ret %= MOD;
	ret *= mpow(kaijo(n-r), MOD-2); ret %= MOD;
	return ret;
}

vector<int> G[(int)(1e5+3)];
int D[(int)(1e5+3)];
int color[(int)(1e5+3)];

void nuru(int v,int d,int c){
	if(D[v] >= d) return;
	D[v] = d;
	if(color[v] == 0) color[v] = c;
	rep(i, G[v].size()){
		int next = G[v][i];
		nuru(next, d-1, c);
	}
}

int main(void){
	ll n,m;
	cin>>n>>m;
	ll a,b,c,d,v;
	rep(i,m){
		cin>>a>>b;
		a--;b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	rep(i,n){
		D[i] = -1;
		color[i] = 0;
	}
	int q;
	cin>>q;
	vector<ll> vv,dd,cc;
	rep(i,q){
		cin>>v>>d>>c;
		v--;
		vv.push_back(v);
		dd.push_back(d);
		cc.push_back(c);
	}
	REP(i,q){
		nuru(vv[i], dd[i], cc[i]);
	}
	rep(i,n){
		cout<<color[i]<<endl;
	}
	return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1000000000;

int main()
{
  ll N, C; scanf("%lld %lld", &N, &C);
  vector<ll> X(N), V(N);
  for (int i = 0; i < N; ++i) {
    scanf("%lld %lld", &X[i], &V[i]);
  }
  vector<ll> clockw1(N), clockw2(N), aclockw1(N), aclockw2(N);
  clockw1[0] = clockw1[0] = V[0] - X[0];
  for (int i = 1; i < N; ++i) {
    clockw1[i] = clockw1[i - 1] + V[i] - abs(X[i] - X[i - 1]);
    clockw2[i] = max(clockw1[i], clockw2[i - 1]);
  }

  ll ans = max(0LL, *max_element(clockw1.begin(), clockw1.end()));

  aclockw1[N - 1] = aclockw2[N - 1] = V[N - 1] - (C - X[N - 1]);
  for (int i = N - 2; i >= 0; --i) {
    aclockw1[i] = aclockw1[i + 1] + V[i] - abs(X[i + 1] - X[i]);
    aclockw2[i] = max(aclockw1[i], aclockw2[i + 1]);
  }

  ans = max(ans, *max_element(aclockw1.begin(), aclockw1.end()));
  // clockwise => anti-clockwise
  for (int i = 0; i < N - 1; ++i) {
    ll val = clockw1[i] - X[i] + aclockw2[i + 1];
    ans = max(ans, val);
  }
  // anti-clockwise => clockwise
  for (int i = N - 1; i > 0; --i) {
    ll val = aclockw1[i] - (C - X[i]) + clockw2[i - 1];
    ans = max(ans, val);
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 4992
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Numerics;

using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(Console.ReadLine().Contains("9")?"Yes":"No");
        }
    }
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int main() {
  int a , b , c ;
  scanf("%d %d %d", &a, &b,&c) ; 

  for(int i = 1 ;i<=1000 ; i++){
    if((a*i)%b == c){
      printf("YES") ;
      return 0 ;
    }
  }
  printf("NO") ;
	
  return 0 ;
}



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

using namespace std;

int main() {
    int A,B,C;
    cin >> A >> B >> C;
    if (A == B && B == C) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int l[10];
int main()
{
	int N, A[3];
	cin >> N >> A[0] >> A[1] >> A[2];
	for (int i = 0; i < N; i++) {
		cin >> l[i];
	}
	int ans = mod;
	for (int bit = 0; bit < (1 << 2 * N); bit++) {
		int cnt[4] = { 0 };
		int stick[4] = { 0 };
		int tmp = bit;
		for (int i = 0; i < N; i++) {
			cnt[tmp % 4]++;
			stick[tmp % 4] += l[i];
			tmp /= 4;
		}
		int sum = 0;
		for (int i = 0; i < 3; i++) {
			if (cnt[i] == 0) {
				sum = mod;
				break;
			}
			sum += (cnt[i] - 1) * 10;
			sum += abs(A[i] - stick[i]);
		}
		ans = min(ans, sum);
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
n, k = gets.chomp.split.map(&:to_i)
array = gets.chomp.split.map(&:to_i)

kitaitis = array.map.with_index do |e, i|
  (1 + e) / 2.0
end

ruisekiwas = [0]
kitaitis.each do |e|
  ruisekiwas << e + ruisekiwas.last
end
size = ruisekiwas.size

anses = []
ruisekiwas.map.with_index do |e, i|
  if i + k > size - 1
    break
  end

  anses << ruisekiwas[i + k] - e
end

puts anses.max


Measured memory_bytes: 21948