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

using namespace std;

typedef long long ll;

const ll MOD = 1e9 + 7;

ll mod_pow(ll a ,ll b, ll p){
    ll res = 1;
    while(b > 0){
        if(b & 1) res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}


ll mod_cmb(int n,int k,ll p){
    ll ans = 1;
    for(int i = 0 ; i < k ; i++){
        ans = ans * (n-i) % p;
        ans = ans * mod_pow(i+1,p-2,p) % p;
    }
    return ans;
}
    

int main(){
    ll n,a,b;
    cin >> n >> a >> b;
    ll ans = 0;
    ans = mod_pow(2,n,MOD) - 1;
    ans -= mod_cmb(n,a,MOD);
    if(ans < 0) ans += MOD;
    ans -= mod_cmb(n,b,MOD);
    if(ans < 0) ans += MOD;
    cout << ans << endl;
    return 0;
}



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

int main() {
    string s; cin >> s;
    int base = 0;
    for (int i = 0; i < 4; i++) {
        if (s[i] == '+') base++;
        else base--;
    }
    cout << base << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
#define maxm 
#define mod 
#define maxn 
 
int main()
{
	int n;
	ll y;
	
	scanf("%d", &n);
	ll x = 1;
	while (n--) {
		scanf("%lld", &y);
		x = x / __gcd(x, y) * y;
	}
	printf("%lld\n", x);
}

Measured memory_bytes: 256
import java.util.*;
class Main{
	public static void main(String args[]){
    	Scanner sc = new Scanner(System.in);
    	int N=sc.nextInt();
      	String S = sc.next();
      	String spt[] =S.split("");
      	int count = 1;
      	
      	for(int i=0;i<spt.length-1;i++){
      	    if(!(spt[i].equals(spt[i+1]))){
      	        count++;
      	    }
      	}
      	
      System.out.println(count);
    }
}


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

int main(){
	int i, j;
	//int n;
	int H = 0;
	int W = 0;

	//for (n = 0; n < 1; n++){
	while (cin >> H >> W){
		//H = 6;
		//W = 5;
		if (H == 0 && W == 0){
			break;
		}
		else {
			for (i = 0; i < H; i++){
				if (i == 0 || i == H-1){
					for (j = 0; j < W; j++){
						cout << "#";
					}
					cout << "\n";
				}
				else {
					for (j = 0; j < W; j++){
						if (j == 0 || j == W-1){
							cout << "#";
						}
						else {
							cout << ".";
						}
					}
					cout << "\n";
				}
			}
			cout << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 1120
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>  // sort, 二分探索, etc
#include <iomanip>  // setprecision (浮動小数点の出力の誤差)
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <numeric>

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=a,i##_len=(b);i<i##_len;++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define cauto const auto&
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))

using namespace std;
using ui = unsigned int;
using ll = long long;
using ull = unsigned long long;

template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return true;}return false;}

int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}

ll comb(int n, int r) {
    vector<vector<ll> > v(n+1, vector<ll>(r+1, 0));
    for(int i=0;i<n+1;i++) {v[i][0]=1; if(i < r+1)v[i][i]=1; }
    for(int i=1;i<n+1;i++) {for(int j=1;j<min(i,r+1);j++) {v[i][j]=v[i-1][j-1]+v[i-1][j];}}
    return v[n][r];
}

// CHAR_MAX  = 127
// INT_MAX   = 2.1e+09 (2147483647)
// LONG_MAX  = 9.2e+18 (9223372036854775807)
// LLONG_MAX = 9.2e+18 (9223372036854775807)


int main() {
    int n, m;
    cin >> n >> m;
    vector<int> vec;
    rep(i, n) {
        int x;
        cin >> x;
        vec.push_back(x);
    }

    sort(all(vec), greater<>());
    int total = accumulate(vec.begin(), vec.end(), 0);

    if (vec[m-1] >= total / (4.0 * m)) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 888
/*
    Problem 87
    https://atcoder.jp/contests/abc120/tasks/abc120_d
*/
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* class */
class DisjointSet {
public:
    vector<int> d;
    DisjointSet () {}
    DisjointSet (int size) {
        d.assign(size, -1);
    }

    int find (int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite (int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x, y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same (int x, int y) { return find(x) == find(y); }
    int size (int x) { return -d[find(x)];}
};
/* global variables */
/* function */
ll comb2(ll x) { return x * (x-1) / 2; }
/* main */
int main(){
    int N, M;
    cin >> N >> M;
    vector<pii> v(M);
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        v[i] = pii(x, y);
    }
    reverse(v.begin(), v.end());
    DisjointSet ds = DisjointSet(N);
    vector<ll> totalVec;
    ll totalPair = comb2(N);
    for (pii p : v) {
        totalVec.push_back(totalPair);
        int x = p.first, y = p.second;
        if (ds.same(x, y)) continue;
        ll c1 = comb2(ds.size(x)), c2 = comb2(ds.size(y));
        ds.unite(x, y);
        ll cAfter = comb2(ds.size(x));
        totalPair += c1 + c2;
        totalPair -= cAfter;
    }
    for (int i = totalVec.size()-1; i>=0; i--)
        cout << totalVec[i] << '\n';
}

Measured memory_bytes: 5416
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

static const ll MAX = 100001;
ll dp[MAX] = {};
ll h[MAX] = {};

int main() {
    

    ll n;
    cin >> n;
    for (ll i=1;i<=n;i++){
        cin >> h[i];
    }
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for (ll i=3;i<=n;i++){
        dp[i] = min(dp[i-2] + abs(h[i] - h[i-2]), dp[i-1] + abs(h[i] - h[i-1]));
    }
    cout << dp[n] << endl;




}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long int
#define ull unsigned long long int
#define forr(i,n) for(int i=0;i<n;i++)
#define f(i,a,b) for(ll i=a;i<b;i++)
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define endl '\n'
#define ce(ele) cout<<ele<<' '
#define cs(ele) cout<<ele<<'\n'
#define CASE(t) int t; cin>>t; while(t--)
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define vi vector<ll>
const ll md=1e9 +7;const ll M1=998244353;
ll mod(ll n){return ((n%M1)+M1)%M1;}
ll power(ll x,ll y){ll res=1;x=x;while(y>0){if(y&1)res=res*x;x=x*x;y=y>>1;}return res;}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
 
    ll n,k;cin>>n>>k;
    vector<pair<ll,ll>> v(k);
    f(i,0,k)cin>>v[i].F>>v[i].S;
 
    vi dp(n+1,0);
    dp[0]=0,dp[1]=1;
    f(i,2,n+1){
        ll cur=0;
        f(j,0,k){
            if(v[j].F>=i)continue;
            ll l=max(1LL,i-v[j].S);
            ll r=i-v[j].F;
            cur+=dp[r]-dp[l-1];
        }
        cur=mod(cur);
        dp[i]=mod(dp[i-1]+cur);
    }cs(mod(dp[n]-dp[n-1]));
    //f(i,1,n+1)cs(dp[i]);
}

Measured memory_bytes: 4716
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors

N = int(input())

if N < 105:
    print(0)
    exit()
cnt = 1
for i in range(107, N+1, 2):
    divisors = make_divisors(i)
    if len(divisors) == 8:
        cnt += 1
print(cnt)

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

#define ll long long
#define scan(x) scanf("%lld",&x)
#define pb push_back
#define mp make_pair

ll gcd(ll a, ll b)
{
    if(a<b)
        std::swap(a,b);
    if(a%b==0)
        return b;
    return gcd(b,a%b);
}



using namespace std;

ll arr[100005];
ll gcl[100005],gcr[100005];

int main()
{
    ll i,j,k,x,l,m,n;
    cin >> n;
    for(i=1;i<=n;i++)
        cin >> arr[i];

    gcl[1]=arr[1];
    for(i=2;i<=n;i++)
    {
        gcl[i]=gcd(arr[i],gcl[i-1]);
    }
    gcr[n]=arr[n];

    for(i=n-1;i>0;i--)
    {
        gcr[i]=gcd(arr[i],gcr[i+1]);
    }
    ll ans=1;

    for(i=1;i<=n;i++)
    {
        ll p;
//p= gcd(gcl[i-1],gcr[i+1]);
        if(i==1)
            p=gcr[2];
        else
            if(i==n)
            p=gcl[n-1];
        else
            p= gcd(gcl[i-1],gcr[i+1]);

        ans=max(ans,p);
    }
    cout << ans;



}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
string R, S;

int main(void){
	//IO("test.in", "test.out");
	cin >> R;
	for(int i = 0; i < R.length(); i++)
		if(R[i] == '0') S += '0';
		else if(R[i] == '1') S += '1';
		else if(S.length() > 0) S.erase(S.begin() + S.length() - 1);
	cout << S << endl;
}

Measured memory_bytes: 256
N=int(input())
s=0
m=10**9
pl=0
mi=0

arr=list(map(int,input().split(" ")))

for z in arr:
  s+=abs(z)
  if z>0:
    pl+=1
  elif z<0:
    mi+=1
  if m>abs(z):
    m=abs(z)

if mi%2==0:
  ans=s
else:
  ans=s-2*m
print(ans)

Measured memory_bytes: 14468
import sys
import socket

hostname = socket.gethostname()

if hostname == 'F451C':
    sys.stdin = open('b1.in')


def read_int_list():
    return list(map(int, input().split()))


def read_str_list():
    return input().split()


def read_int():
    return int(input())


def read_str():
    return input()


def main():
    n = read_int()
    a = [0] * n
    b = [0] * n
    for i in range(n):
        a[i], b[i] = read_int_list()

    m = min(b)
    for i in range(n):
        if b[i] == m:
            res = a[i] + b[i]
    print(res)


main()


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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int n,k; string s; cin>>n>>k>>s;
	int ans=0;
	char f=s.front();
	for(int i=1;i<s.size();++i){
		if(f==s.at(i))++ans;
		else f=s.at(i);
	}
	cout<<min(ans+k*2,n-1)<<"\n"s;
}


Measured memory_bytes: 3740
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n;
	cin >> n;
	long long int i = 1;
	long long int a = 1, b = n;
	while(i*i<=n){
		if(n%i == 0){
			a = i;
			b = n/i;
		}
		i++;
	}
	cout << a+b-2 << endl;
	return 0;
}

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

long long getgcd(long long N,long long X);

int main(void){
    long long N,X;
    long long buf;
    long long buf2;
    long long cur;
    scanf("%lld %lld",&N,&X);
    buf=(long long)getgcd(N,X);
    buf2=(long long)(N-buf);
    printf("%lld\n",(long long)(3*buf2));
}

long long getgcd(long long N,long long X) {
    
    long long buf;
    long long a;
    long long b;
    a=N;
    b=X;
    buf=(long long)(a%b);
    if (buf!=0){
        while(1){
            a=b;
            b=buf;
            buf=(long long)a%b;
            if(buf==0) break;
        }
    }
    return (long long)b;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define fir first
#define sec second
#define pb 	push_back
#define ll  long long
//#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define pii pair<int,int>
#define debug(x) cerr<<#x<<" =: "<<x<<endl;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
#define Find find_by_order
#define Order order_of_key
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 mrand(random_device{}());
ll rnd(ll x) { return mrand() % x;}
ll ksm(ll a,ll b,ll mod){ll ans=1;a%=mod;while(b){if(b&1) ans=ans*a%mod;b>>=1;a=a*a%mod;}return ans;}
ll phi(ll n){ll ans=n;for(ll i=2;i*i<=n;i++){if(n%i==0) {while(n%i==0) n/=i;ans=ans*(i-1)/i;}}if(n>1) ans=ans*(n-1)/n;return ans;}
//head

const int maxn=2e6+7;

	int a,b,c,d;
ll solve(ll T){
	int n;cin>>n;
	while(n--){
		string ss;cin>>ss;
		if(ss=="AC") a++;
		if(ss=="WA") b++;
		if(ss=="TLE") c++;
		if(ss=="RE") d++;
//		cout<<"AC x "<<a<<endl;

	}
		cout<<"AC x "<<a<<endl;
		cout<<"WA x "<<b<<endl;
		cout<<"TLE x "<<c<<endl;
		cout<<"RE x "<<d<<endl;
	return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll T=1;
//    cin>>T;
    for(ll cas=1; cas<=T; cas++) {
        solve(T);
    }
	return 0;
}


Measured memory_bytes: 3648
#include<stdio.h>
#include<math.h>

int main(void){
        int a[11][11],n,d,i,j,k,l=0,p=0;
        double s[50]={0},b[11][11];

        scanf("%d%d",&n,&d);

        for(i=0;i<n;i++){
            for(j=0;j<d;j++){
                scanf("%d",&a[i][j]);
                b[i][j]=a[i][j];
            }
        }

       for(i=0;i<n-1;i++){
            for(k=i+1;k<n;k++){
                for(j=0;j<d;j++){
                    s[p]=s[p]+(pow((b[i][j]-b[k][j]),2));
                }
                s[p]=sqrt(s[p]);
                if(round(s[p])-(s[p])==0){
                    l++;
                }
                p++;
            }
       }
       printf("%d",l);

       return 0;
}


Measured memory_bytes: 2148
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int x, y;
	scanf("%d%d", &x, &y);
	for (int c = 0; c <= x; c++){
		int t = x - c;
		int feet = 2 * c + 4 * t;
		if (feet == y) {
			printf("Yes\n");
			return 0;
		}
	}
	printf("No\n");
	return 0;
}

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

const int N = 2e5 + 5;

int n;
deque<int> Q;

int main() {
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; ++i) {
		int x;
		cin >> x;
		if (i & 1) Q.push_back(x);
		else Q.push_front(x);
	}
	if (n & 1) {
		for (auto it = Q.rbegin(); it != Q.rend(); ++it)
			cout << *it << ' ';
		cout << endl;
	} else {
		for (auto it = Q.begin(); it != Q.end(); ++it)
			cout << *it << ' ';
		cout << endl;
	}
	return 0;
}

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

int get_sum(set<int> a){
  int sum=0;
  set<int>::iterator it;
  for(it=a.begin();it!=--a.end();it++)sum+=(*it);
  return sum;
}

int get_num(set<int> &a){
  int res=*(--a.end());
  return res;
}



int main(){

  while(1){
  int a,b;
  cin>>a>>b;
  if(!a&&!b)return 0;
  set<int> A,B;
  for(int i=2;a!=1;i++){
    if(a%i==0)A.insert(i);
    while(a%i==0)a/=i;
  }

  for(int i=2;b!=1;i++){
    if(b%i==0)B.insert(i);
    while(b%i==0)b/=i;
  }

  a=get_num(A)-get_sum(A);
  b=get_num(B)-get_sum(B);
  if(a>b) cout<<"a"<<endl;
  else cout<<"b"<<endl;
  }
  return 0;
}

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

typedef long long ll;
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define all(x) (x).begin(), (x).end()
#define en '\n'
#define FILL(x, v) memset(x, v, sizeof(x))
#define pb push_back
#define fast                     \
	ios::sync_with_stdio(false); \
	cin.tie(NULL);               \
	cout.tie(NULL);
#define F_OR(i, a, b, s) for (int i = (a); ((s) > 0 ? i < (b) : i > (b)); i += (s))
#define F_OR1(e) F_OR(i, 0, e, 1)
#define F_OR2(i, e) F_OR(i, 0, e, 1)
#define F_OR3(i, b, e) F_OR(i, b, e, 1)
#define F_OR4(i, b, e, s) F_OR(i, b, e, s)
#define GET5(a, b, c, d, e, ...) e
#define F_ORC(...) GET5(__VA_ARGS__, F_OR4, F_OR3, F_OR2, F_OR1)
#define FOR(...)       \
	F_ORC(__VA_ARGS__) \
	(__VA_ARGS__)

#define E_ACH2(x, a) for (auto &x : a)
#define E_ACH3(x, y, a) for (auto &[x, y] : a)
#define E_ACH4(x, y, z, a) for (auto &[x, y, z] : a)
#define E_ACHC(...) GET5(__VA_ARGS__, E_ACH4, E_ACH3, E_ACH2)
#define EACH(...)       \
	E_ACHC(__VA_ARGS__) \
	(__VA_ARGS__)

template <typename A, typename B>
inline void chmin(A &a, B b)
{
	if (a > b)
		a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b)
{
	if (a < b)
		a = b;
}

struct UnionFind
{
	vector<int> d;
	UnionFind(int n = 0) : d(n, -1) {}

	int find(int x)
	{
		// not visited or parent
		if (d[x] < 0)
			return x;
		return d[x] = find(d[x]); // dont really need to assign again
	}

	bool unite(int x, int y)
	{
		x = find(x);
		y = find(y);
		if (x == y)
			return false;
		if (x > y)
			swap(x, y);
		if (d[x] > d[y])
			swap(x, y);
		d[x] += d[y];
		d[y] = x;

		return true;
	}

	bool same(int x, int y) { return find(x) == find(y); }

	int size(int x) { return -d[find(x)]; }
};

int main()
{
	fast;
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	vvi adj(n);
	int c, ans = 0;
	FOR(m)
	{
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		if (!i)
		{
			c = x;
		}
		adj[x].pb(y);
		adj[y].pb(x);
		uf.unite(x, y);
	}
	FOR(n)
	{
		if (uf.size(c) == n)
			break;
		if (!uf.same(c, i))
		{
			uf.unite(c, i);
			ans++;
		}
	}
	cout << ans << en;
}

Measured memory_bytes: 8744
//#include <bits/stdc++.h>
#include <stack>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	//入力
	long a[100000], b[100000],x[100000];
	long N, M=1000000000, ans=0,K;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	//処理
	sort(a,a+N);
    //M = a[N - 1] - a[N - K];
	for (int j = 0; j <= N - K; j++) {
		if (M > a[N - 1 - j] - a[N - j - K]) M = a[N - 1 - j] - a[N - j - K];
	}
	//出力
	cout << M << endl;
}

Measured memory_bytes: 1024
n = int(input())
P_n = list(map(int, input().split()))

ans = 0
for i in range(1, n - 1):
    P_list = [P_n[i - 1], P_n[i], P_n[i + 1]]
    P_list.sort()

    if P_n[i] == P_list[1]:
        ans += 1

print(ans)


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

 using namespace std;

 int main() {
   int N, i, j;
   cin >> N;

   vector<int> A(N + 1);

   for(i = 1; i <= N; i++) cin >> A.at(i);

   int ans = 0;
   bool finished = false;

   while (!finished) {
     for (i = 1; i <= N; i++) {
       if (A.at(i) % 2 == 1) {
         finished = true;
         break;
       }
       else A.at(i) /= 2;
     }
     if(!finished) ans++;
   }

   cout << ans << endl;
 }


Measured memory_bytes: 256
import itertools


def read():
    N, T = list(map(int, input().strip().split()))
    A = list()
    B = list()
    for i in range(N):
        a, b = list(map(int, input().strip().split()))
        A.append(a)
        B.append(b)
    return N, T, A, B


def solve(N, T, A, B):
    dp1 = [[0 for j in range(T)] for i in range(N+2)]
    dp2 = [[0 for j in range(T)] for i in range(N+2)]
    for i, t in itertools.product(range(N), range(T)):
        u = t - A[i]
        if u >= 0:
            dp1[i+1][t] = max(dp1[i][u] + B[i], dp1[i][t])
        else:
            dp1[i+1][t] = dp1[i][t]
        u = t - A[N-1-i]
        if u >= 0:
            dp2[N-i][t] = max(dp2[N+1-i][u] + B[N-1-i], dp2[N+1-i][t])
        else:
            dp2[N-i][t] = dp2[N+1-i][t]
    v = 0
    for i, t in itertools.product(range(N), range(T)):
        v = max(v, dp1[i][t] + dp2[i+2][(T-1) - t] + B[i])
    return v


if __name__ == '__main__':
    inputs = read()
    print("%s" % solve(*inputs))


Measured memory_bytes: 195716
#include <stdio.h>
#include <ctype.h>

#define ARR_LIMIT 1201

int main(void) {
	int idx;
	char input;
	char result[26] = { 0 };

	while((input = getchar()) != EOF) {
		if (isalpha(input)) {
			input = tolower(input);
			result[input - 'a']++;
		}
	}

	for (idx = 0; idx < 26; idx++) {
		printf("%c : %d\n", 'a' + idx, result[idx]);
	}
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
//typedef pair<int, int> P;
typedef pair<ll, ll> P;
//const double INF = 1e10;
const ll INF = LONG_LONG_MAX;
//const int INF = INT_MAX  ;
#define mins(x, y) x = min(x, y)
#define maxs(x, y) x = max(x, y)

const int mod = 1000000007;

vector<pair<ll, int >> factorize(ll n) {
    vector<pair<ll, int >> res;

    for (ll i = 2; i * i <= n; i++) {
        if (n % i != 0) {
            continue;
        }
        res.emplace_back(n, 0);
        while (n % i == 0) {
            n /= i;
            res.back().second++;
        }
    }

    if (n != 1) res.emplace_back(n, 1);
    return res;

}

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

    vector<ll> fact;
    for (ll i = 1; i <= a && i <= b; i++) {
        if (a % i == 0 && b % i == 0) {
            fact.push_back(i);
        }
    }

    reverse(fact.begin(), fact.end());
    cout << fact[k - 1] << endl;

}



Measured memory_bytes: 256
#include<iostream>

using namespace std;

int gcd(int a,int b){
    if(a<b)return gcd(b,a);
    if(a==b)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
int main(){
    int a,b;
    cin >> a >> b;
    int ans = gcd(a,b);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define erep(i, n) for (ll i = 0; i <= (ll)(n); ++i)
#define FOR(i,a,b) for (ll i = (a); i < (ll)(b); ++i)
#define EFOR(i,a,b) for (ll i = (a); i <= (ll)(b); ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } }

#include <iostream>
#include <vector>
#include <queue>
using namespace std;
using Graph = vector<vector<int>>;
using P = pair<int, int>;

vector<string> solve(string s) {
    set<char> st;
    rep(i, s.size()) st.insert(s[i]);
    vector<string> ret;
    char last = '_';
    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        ret.push_back(s+*itr);
        last = *itr;
    }
    ret.push_back(s+char(last+1));
    return ret;
}

int main() {
    int n; cin >> n;
    string first = "a";

//    char last = 'a';
//    cout << first + char(last+1) << endl;

    set<string> st;
    vector<string> now;
    now.push_back(first);
    rep(i, n-1) {
        vector<string> tmp;
        rep(j, now.size()) {
            vector<string> re = solve(now[j]);
            copy(re.begin(), re.end(), back_inserter(tmp));
        }
        now = tmp;
    }

    rep(i, now.size()) {
        cout << now[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 11036
fun main(args: Array<String>) {
    val a = readInt()
    val b = readInt()
    val c = readInt()
    val d = readInt()
    println((if (a >= b) b else a) + (if (c >= d) d else c))
}

fun printYesOrNo(flag: Boolean) {
    println(if (flag) "Yes" else "No")
}

fun readIntList(): List<Int> = readLine()!!.split(' ').map { it.toInt() }

fun readInt(): Int = readLine()!!.toInt()

fun err(print: Any) {
    System.err.println(print)
}

Measured memory_bytes: 31704
#include<iostream>

using namespace std;
int main(){
  for (;;){
  int n,m,l;
  cin >> n >> m >> l;
  if(n==0&&m==0&&l==0){
    break;
  }
  int check[n+m+l];
  for(int i=0; i<n+m+l; i++){
    check[i]=3;
  }
  int o;
  cin >> o;
  int p[4*o];
  for(int i=0; i<4*o; i++){
    cin >> p[i];
  }
  for(int i=3; i<4*o; i+=4){
    if(p[i]==1){
      check[p[i-3]-1]=check[p[i-2]-1]=check[p[i-1]-1]=1;
    }
    if(p[i]==0){
      if(check[p[i-3]-1]==3){
        check[p[i-3]-1]=2;
      }
      if(check[p[i-2]-1]==3){
        check[p[i-2]-1]=2;
      }
      if(check[p[i-1]-1]==3){
        check[p[i-1]-1]=2;
      }
    }
  }
  for(int i=3; i<4*o; i+=4){
    if(check[p[i-3]-1]==2&&check[p[i-2]-1]==1&&check[p[i-1]-1]==1){
      check[p[i-3]-1]=0;
    }
    if(check[p[i-3]-1]==1&&check[p[i-2]-1]==1&&check[p[i-1]-1]==2){
      check[p[i-1]-1]=0;
    }
    if(check[p[i-3]-1]==1&&check[p[i-2]-1]==2&&check[p[i-1]-1]==1){
      check[p[i-2]-1]=0;
    }
  }
  for(int i=0; i<n+m+l; i++){
    if(check[i]==3){
      check[i]=2;
    }

  }
  for(int i=0; i<n+m+l; i++){
    cout << check[i] << endl;
  }
}
}



Measured memory_bytes: 3028
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		while(true){
			int m = Integer.parseInt(std.next());
			int f = Integer.parseInt(std.next());
			int r = Integer.parseInt(std.next());
			String grade = "";
			if(m==-1 && f==-1 && r==-1){
				break;
			}else{
				if(m==-1 || f==-1){
					grade = "F";
				}else if(m+f>=80){
					grade = "A";
				}else if(m+f>=65){
					grade = "B";
				}else if(m+f>=50){
					grade = "C";
				}else if(m+f>=30){
					if(r>=50){
						grade = "C";
					}else{
						grade = "D";
					}
				}else {
					grade = "F";
				}
			}
			System.out.println(grade);
		}
	}
}

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

using namespace std;


#define uniq(x)  x.erase(unique(x.begin(),x.end()), x.end()) //Unique value find from vector
#define upper(arr,n,fixed) upper_bound(arr,arr+n,fixed)-arr  //Upper value search  >
#define lower(arr,n,fixed) lower_bound(arr,arr+n,fixed)-arr  //Lower value search  >=
#define FOR(i,a,n) for(int i=a; i<(int)n; i++)
#define FORI(i,a,n) for(int i=a; i>=(int)n; i--)
#define pii pair<LL,LL>
#define vpii vector<pii>
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz(a) int((a).size())
#define fastIO() ios_base::sync_with_stdio(0); cin.tie(0)
#define endl "\n"
#define all(a) a.begin(), a.end()
#define MEMSET(p,i) memset(p,i,sizeof(p))

typedef long long LL;
typedef unsigned long long ULL;

pii memo[3010][3010];
LL v[3010];
int n;


pii dp(int i, int j, int k)
{
	auto &dpm = memo[i][j];
	if(dpm != mp((LL)-1,(LL)-1))
		return dpm;
	if(i == j){
		if(k == 1){
			return dpm = {v[i],0};
		}
		else
			return dpm = {0,v[i]};
	}

	auto x = dp(i+1, j, -k);
	auto y = dp(i, j-1, -k);

	if(k == 1) // maximiza fi
	{
		x.fi += v[i];
		y.fi += v[j];

		if(x.fi-x.se > y.fi-y.se)
			dpm = x;
		else
			dpm = y;
	}
	else{
		x.se += v[i];
		y.se += v[j];

		if(x.fi-x.se < y.fi-y.se)
			dpm = x;
		else
			dpm = y;
	}
	return dpm;
}

int main(void)
{
	fastIO();

	cin >> n;
	FOR(i,0,n)
		cin >> v[i];

	FOR(i,0,n)
		FOR(j,0,n)
			memo[i][j] = mp(-1,-1);

	pii ans = dp(0,n-1,1);
	cout << ans.fi - ans.se << endl;


	
	
}

Measured memory_bytes: 141824
N,M = map(int,input().split())
first = [False for i in range(N)]
second = [False for i in range(N)]

for i in range(M):
    a,b = map(int,input().split())
    a,b = a-1, b-1
    if a == 0:
        first[b] = True
    if b == N-1:
        second[a] = True
for i,e in enumerate(first):
    if e:
        if second[i]:
            print('POSSIBLE')
            exit()
print('IMPOSSIBLE')

Measured memory_bytes: 6436
#include <bits/stdc++.h>
using namespace std;
#define MOD1 1000000007
#define MOD2 1000000009
#define ll long long int
#define li long int
#define fi first
#define se second
#define ffl fflush(stdout);
#define whT int t; cin>>t; while(t--)
int main() 
{
	int x,n;
	cin>>x>>n;
	set<int> s;
	for(int i=0;i<n;i++) {
		int t;
		cin>>t;
		s.insert(t);
	}
	int f=x,b=x;
	while(true) {
		if(s.find(f)==s.end() && s.find(b)==s.end()) {
			if(abs(f-x)>abs(b-x)) {
				cout<<b;
				return 0;
			} else if(abs(f-x)<abs(b-x)) {
				cout<<f;
				return 0;
			} else {
				if(f>b) {
					cout<<b;
					return 0;
				} else {
					cout<<f;
					return 0;
				}

			}
		}
		if(s.find(f)!=s.end()) f++;
		if(s.find(b)!=s.end()) b--;
	}
}


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

int main() {
  int a1, a2, a3; cin >> a1 >> a2 >> a3;
  if (a1 + a2 + a3 >= 22) cout << "bust";
  else cout << "win";
  return 0;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code
ll co[N];

int main()
{
  ll n,k;
  cin>>n>>k;
  rep(i, 0, n)
  {
    ll a, b;
    cin>>a>>b;
    co[a] += b;
  }
  ll i = 0;
  while(k > 0)
  {
    i++;
    k -= co[i];
  }
  cout<<i<<endl;
  return 0;
}


Measured memory_bytes: 14848
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;

int main() {
  int a, b, c, d, e, k;
  cin>>a>>b>>c>>d>>e>>k;
  cout <<
    ((e-a <= k) ? "Yay!" : ":(" )
<< '\n';
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    long long a;
    double b;
    cin >> a >> b;
    //cout << b*100 << endl;
    //cout << round(b*100)<< endl;
    b = round(b*100);
    cout << a*(long long)(b)/100;
    return 0;
}

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

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define mod1 1000000007
#define mod2 1000000009
int getTheAnswer() {
    return 42;
}

using namespace std;
using ll=long long;

class ACalc {
public:
	void solve(std::istream& cin, std::ostream& cout) {
        int a;
        cin>>a;
        cout<<a+a*a+a*a*a<<endl;
	}
};


int main() {
	ACalc solver;
	std::ios::sync_with_stdio(false);
	std::cin.tie(NULL);
	std::cout.tie(NULL);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define repb(i, n) for(ll i = (n)-1; i >= 0; i--)
#define repr(i, a, b) for(ll i = (a); i < (b); i++)
#define reprb(i, a, b) for(ll i = (b)-1; i >= (a); i--)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((ll)(x).size())
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
const ld EPS = 1e-12L;
const ld PI = 3.1415926535897932385L;
inline ll GCD(ll a, ll b){ return b?GCD(b, a % b):a; }
inline ll LCM(ll a, ll b){ return a/GCD(a, b)*b; }
inline ll powint(ull x, ll y){ ll r=1; while(y){ if(y&1) r*=x; x*=x; y>>=1; } return r; }
inline ll powmod(ll x, ll y, ll m = MOD){ ll r=1; while(y){ if(y&1) r*=x; x*=x; r%=m; x%=m; y>>=1; } return r; }
template<class S, class T>inline bool chmax(S &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class S, class T>inline bool chmin(S &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }
#ifdef OJ_LOCAL
#include "dump.hpp"
#else
#define dump(...) ((void)0)
#endif

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll n;
    cin >> n;
    if(n%2==0){
        cout << n/2-1 << endl;
    }else{
        cout << n/2 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S = input()
ANS = []

x = N
while x:
    for i in range(max(x-M, 0), x):
        if S[i] == "0":
            ANS.append(x-i)
            x = i
            break
    else:
        print(-1)
        break
else:
    print(*ANS[::-1])


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

typedef long long lint;
lint gcd(lint a,lint b){
    if(a%b==0) return b;
    if(b%a==0) return a;
    if(a>b) return gcd(b,a%b);
    else return gcd(a,b%a);
}
int main(){
    lint N,X;
    cin >> N >> X;
    lint g=gcd(N,X);
    
    cout << (g*(N/g-1)*3) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a),_b=(b);i<=_b;i=i+1)
#define FORD(i,b,a) for (int i=(b),_a=(a);i>=_a;i=i-1)
#define REP(i,n) for (int i=0,_n=(n);i<_n;i=i+1)
#define FORE(i,v) for (__typeof((v).begin()) i=(v).begin();i!=(v).end();i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define fi first
#define se second+++
#define SZ(x) ((int)(x).size())
#define double db
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
const int MAXN = 1E5+3;
const ll oo = 1e18+3;


int ans, n, a[MAXN];

int main() {
	cin >> n;	
	FOR(i,1,n) cin >> a[i];
	FOR(i,1,n) {
		while (a[i] % 2 == 0) {
			ans++;
			a[i] /= 2;
		}
	}
	cout << ans;
   	return 0;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(500000)

N, X = map(int, input().split())

a, p = [1], [1]
for i in range(N):
    a.append(a[i] * 2 + 3)
    p.append(p[i] * 2 + 1)

def f(N, X):
    if N == 0:
        return 0 if X <= 0 else 1
    # Xがバンズ1枚とL-1バーガー1個分以下なら、
    # バンズ1枚を除いて(X-1)、L-1バーガーで同じ探索をするのと変わらない
    elif X <= 1 + a[N-1]:
        return f(N-1, X-1)
    # Xがバンズ1枚とL-1バーガー1個分より大きければ、
    # L-1バーガー1個分に入っているパティ + 1パティ+ Xを-2(一番下のバンズと真ん中のパティ)-(L-1バーガー1個分)で同じ探索をするのと変わらない
    else:
        return p[N-1] + 1 + f(N-1, X-2-a[N-1])

print(f(N, X))

Measured memory_bytes: 38384
/* I have already deleted My old account because somebody stole my code
and i have no idea how. If you are copying this code atleast make it look different 
Yours Faithfully
Shobhit Yadav */

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

int N;
/*ll freq[200005];*/
void solve(){
	 /*memset(freq,0,sizeof(freq));*/
	cin>>N;
	int a[N];
	ll sum = 0;

	for(ll i = 0 ; i<N ; i++)
		cin>>a[i];

	for(ll i = 0 ; i<N ; i++){
		for(ll j = i+1 ; j<N ; j++)
			sum += a[i]*a[j];
	}

	cout<<sum<<'\n';

}



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

	return 0;
}

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

ll c[60][60],f[60];
int num[110],h[110];
int cnt[262144],d[110],n,k,s,t,tt;

int Cnt[262144];
bool vis[262144];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void pre_gao()
{
	for (int i=0;i<=50;i++)
	{
		c[i][0]=1;
		for (int j=1;j<=i;j++) c[i][j]=c[i-1][j-1]+c[i-1][j];
	}
	for (int i=0;i<=50;i++) for (int j=1;j<=k;j++) f[i]+=c[i][j];
}

inline ll work(int x)
{
	for (int i=1;i<=n;i++) Cnt[h[i]&x]++;
	ll res=0;
	for (int i=1;i<=n;i++) if (!vis[h[i]&x]) vis[h[i]&x]=true,res+=f[Cnt[h[i]&x]];
	for (int i=1;i<=n;i++) vis[h[i]&x]=Cnt[h[i]&x]=0;
	return res;
}

int main()
{
	n=rd();k=rd();s=rd();t=rd();pre_gao();
	for (int i=1;i<=n;i++)
	{
		num[i]=rd();
		if ((num[i]&s)!=s||(num[i]|t)!=t) n--,i--;
	}
	if (!n) { puts("0");return 0; }
	for (int i=0;i<18;i++) if (((s^t)>>i)&1)
	{
		if ((s>>i)&1) { puts("0");return 0; }
		d[++tt]=i;
	}
	for (int i=1;i<=n;i++) for (int j=1;j<=tt;j++) if ((num[i]>>d[j])&1) h[i]|=(1<<(j-1));
	for (int i=1;i<(1<<tt);i++) cnt[i]=cnt[i>>1]+(i&1);
	ll ans=0;
	for (int i=0;i<(1<<tt);i++)
	{
		if (cnt[i]&1) ans-=work(i);
		else ans+=work(i);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 6100
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define AC 100100
#define LL long long 

int n;
LL ans = 1e18, sum;
LL s[AC];

inline int read()
{
	int x = 0;char c = getchar();bool z = false;
	while(c > '9' || c < '0') 
	{
		if(c == '-') z = true;
		c = getchar();
	}
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	if(!z) return x;
	else return -x;
}

void pre()
{
	n = read();
	for(R i = 1; i <= n; i ++) s[i] = read();
}

void cal(LL sum, LL rnt)
{
	LL x;
	for(R i = 2; i <= n; i ++)
	{
		x = s[i];
		if(sum > 0)
		{
			if(x + sum < 0) {sum += x; continue;}	
			rnt += x + sum + 1;
			x = - sum - 1;
			sum += x;
		}
		else 
		{
			if(x + sum > 0) {sum += x; continue;}
			rnt += - sum - x + 1;
			x = - sum + 1;
			sum += x;
		}
	}
	ans = min(ans, rnt);
}

void work()
{
	if(s[1] >= 0) 
	{
		if(s[1] == 0) cal(1, 1), cal(-1, 1);	
		else cal(s[1], 0), cal(-1, s[1] + 1);
	}
	else cal(s[1], 0), cal(1, -s[1] + 1);
	printf("%lld\n", ans);
}

int main()
{
	//freopen("in.in", "r", stdin);
	pre();
	work();
	//fclose(stdin);
	return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cassert>
#include<cstring>
#include<algorithm>
using namespace std;

long N;

int search(string &S, long i){
    static long ind;
    static char prev = 0;

    if (S[i] == 'L') {
        if (prev != 'L')
            ind = S.rfind('R', i);
            prev = 'L';
        return (i - ind) % 2 ? ind+1 : ind; 
    } else {
        if (prev != 'R')
            ind = S.find('L', i);
            prev = 'R';
        return (ind - i) % 2 ? ind-1 : ind;
    }
}

int main(void)
{
    string S;
    cin >> S;

    N = S.size();
    vector<long> cnt(N, 0);
    long ind;
    for(long i = 0; i < N; i++){
        ind = search(S, i);
        cnt[ind]++;
    }

    for (long i = 0; i < N; i++) {
        cout << cnt[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <tuple>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

using T = tuple<ll,ll>;
using Graph = vector<vector<T>>;

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

    ll a, b, n;
    cin >> a >> b >> n;

    ll x = n;
    if (n >= b-1)
        x = b-1; 

    ll ans = floor(a*x/b)-floor(a*(x/b));

    cout << ans << endl;

    return 0;
}


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

ll GCD(ll X, ll Y) {
    return (X ? GCD(Y % X, X) : Y);
}

ll LCD(ll X, ll Y) {
    ll g = GCD(X, Y);
    ll y = Y/g;
    ll x = X/g; 
    ll G = x*y*g;
    return G;
}

int main() {
    ll A, B, C, D;
    cin >> A >> B >> C >> D;
    ll whole = B-A+1;
    ll ac = A/C;
    ll bc = B/C;
    ll canC = bc-ac;
    if (A % C == 0) canC ++;

    ll ad = A/D;
    ll bd = B/D; 
    ll canD = bd-ad;
    if (A % D == 0) canD ++;

    ll lcd = LCD(C, D);
    ll acd = A/lcd;
    ll bcd = B/lcd;
    ll canboth = bcd-acd;
    if (A % lcd == 0) canboth++;

    ll ans = whole-(canC+canD-canboth);
    // cout << canC << endl;
    // cout << canD << endl;
    // cout << canboth << endl;
    // cout << whole << endl;
    cout << ans << 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;
using ll = long long;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int t; cin >> t;
    while (t--) {
        int n; cin >> n;
        vector<ll> a(n); REP(i, n) cin >> a[i];
        string s; cin >> s;

        int ans = 0;
        vector<ll> dp;
        for (int i = n; i--;) {
            for (auto j : dp) a[i] = min(a[i], a[i]^j);
            if (a[i]) {
                if (s[i] == '0') dp.push_back(a[i]);
                else {
                    ans = 1;
                    break ;
                }
            }
        }
        cout << ans << '\n';
    }
    return 0;
}

Measured memory_bytes: 3572
N = int(input())
l = [int(x) for x in input().split()]
s = [0] * (N+1)
for i in range(N):
    s[i+1] = s[i] + l[i]
s.sort()

#count
table= {}
for i in range(N+1):
    if s[i] in table:
        table[s[i]] += 1
    else:
        table[s[i]] = 1
ans = 0
for key,val in table.items():
    if val >= 2:
        ans += val*(val-1)//2
print(ans)

Measured memory_bytes: 41312
#include<stdio.h>

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

Measured memory_bytes: 128
N=int(input())
A=list(map(int, input().split()))
if N==0:
  if A[0]==1:
    print(1)
    exit()
  else:
    print(-1)
    exit()

D=[0]*(N+1)
D[0]=1
goal=sum(A)
goal-=A[0]
D[0]-=A[0]
for i in range(N):
  ma=D[i]*2
  if ma<A[i+1]:
    print(-1)
    exit()
  else:
    if D[i]<=goal<=2*D[i]:
      D[i+1]=goal
    else:
      D[i+1]=D[i]*2
    D[i+1]-=A[i+1]
    if D[i+1]<0:
      print(-1)
      exit()
    goal-=A[i+1]
print(sum(D)+sum(A))  

Measured memory_bytes: 20016
#include <iostream>
#include <map>
using namespace std;
int main(void){
    int n;
    cin >> n;
    
    map<string,int> m{};
    for (int i=0; i<n; i++) {
        string str;
        cin >> str;
        if (m.find(str) != m.end()) {
            m[str]++;
        } else {
            m[str] = 1;
        }
    }
    
    cout << m.size() << endl;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
#define REP(i, n) for(int i=0; i<n; i++)

ll A[100100];
ll B[100100];
pair<ll, int> D[100100];
int main(){
    int N;
    cin >> N;
    REP(i, N){
        ll a, b;
        cin >> a >> b;
        A[i] = a;
        B[i] = b;
        D[i] = make_pair(a + b, i);
    }

    sort(D, D+N);

    ll t = 0;
    ll a = 0;
    bool taka = true;
    REP(i,N){
        pair<ll, int> p = D[N-1-i];
        int idx = p.second;
        if(taka){
            t += A[idx];
        }
        else{
            a += B[idx];
        }
        taka = !taka;
        //printf("t:%lld, a:%lld, idx:%d\n", t, a, idx);
    }

    cout << t-a << endl;

    return 0;
}


Measured memory_bytes: 3328
from sys import stdin

def main():
    N, M = map(int, input().split())
    AB = [tuple(map(int, input().split())) for _ in [0] * N]

    AB.sort()
    ans = 0
    for a, b in AB:
        n = min(b, M)
        M -= n
        ans += n * a
        if M <= 0:
            break
    print(ans)

input = lambda: stdin.readline()
main()


Measured memory_bytes: 17400
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;

public class Main {

	public static void solve() {
		int h = s.nextInt();
		int w = s.nextInt();
		int n = s.nextInt();
//		int min = Integer.min(h, w);
		int max = Integer.max(h, w);
		int count = 0;
		int moves = 0;
		while(count < n) {
			count += max;
			moves ++;
		}
		out.println(moves);
	}

	public static void main(String[] args) {
		new Thread(null, null, "Thread", 1 << 27) {
			public void run() {
				try {
					out = new PrintWriter(new BufferedOutputStream(System.out));
					s = new FastReader(System.in);
					solve();
					out.close();
				} catch (Exception e) {
					e.printStackTrace();
					System.exit(1);
				}
			}
		}.start();
	}

	public static PrintWriter out;
	public static FastReader s;

	public static class FastReader {

		private InputStream stream;
		private byte[] buf = new byte[4096];
		private int curChar, snumChars;

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

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

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int number = 0;
			do {
				number *= 10;
				number += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return number * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			long sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long number = 0;
			do {
				number *= 10L;
				number += (long) (c - '0');
				c = read();
			} while (!isSpaceChar(c));
			return number * sgn;
		}

		public int[] nextIntArray(int n) {
			int[] arr = new int[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextInt();
			}
			return arr;
		}

		public long[] nextLongArray(int n) {
			long[] arr = new long[n];
			for (int i = 0; i < n; i++) {
				arr[i] = this.nextLong();
			}
			return arr;
		}

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

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndofLine(c));
			return res.toString();
		}

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

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

	}

	
}


Measured memory_bytes: 23252
#pragma GCC optimize(2)
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, int> pdd;

const ll mod = 1e9 + 7;
const int N = 1e2 + 10, M = 1e3 + 10;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;
const int eps = 1e-6;

#define pi acos(-1)
#define mk make_pair


int main()
{
    ll h, w;
    cin >> h >> w;
    if(h == 1 || w == 1)
    {
        puts("1");
        return 0;
    }
    int d1 = (h + 1) / 2, d2 = (w + 1) / 2;
    ll ans = d1 * ll(d2) + w / 2 * ll(h / 2);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256