akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

int fie[210][210][51];

vector<int> d[]={{0,0,0,0},{2,3,5,4},{1,4,6,3},{1,2,6,5},{1,5,6,2},{1,3,6,4},{2,4,5,3}};

class dice{
public:
	int tp,ft;
	int x,y,z;
	dice(int t,int f):tp(t),ft(f),x(100),y(100),z(50){};
	bool fall(){
		if(z-1>=0 && fie[x][y][z-1]==-1){
			z--;
			return true;
		}
		return false;
	}
	
	bool move(){
		if(z==0)return false;
		vector<int> tmp = d[tp];
		int fpos=-1;
		int pos=-1,num=-1;
		rep(i,tmp.size()){
			if(tmp[i]==ft)fpos=i;
		}
		rep(i,tmp.size()){
			if(tmp[i]==4||tmp[i]==5||tmp[i]==6){
				int tdir = (i+4-fpos)%4;
				if(tdir==0 && fie[x][y-1][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
				if(tdir==1 && fie[x+1][y][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
				if(tdir==2 && fie[x][y+1][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
				if(tdir==3 && fie[x-1][y][z-1]==-1)if(num<tmp[i])num=tmp[i],pos=i;
			}
		}
		if(pos==-1)return false;
		int dir = (pos+4-fpos)%4;
		//		cout<<x<<" "<<y<<" "<<z<<" "<<dir<<" "<<fpos<<" "<<pos<<" "<<num<<endl;
		if(dir==0) y--,z--;
		if(dir==1) x++,z--;
		if(dir==2) y++,z--;
		if(dir==3) x--,z--;
		//		cout<<x<<" "<<y<<" "<<z<<" "<<dir<<endl<<endl;
		if(dir==0)ft=tp;
		if(dir==1&&dir==3)ft=ft;
		if(dir==2)ft=7-tp;
		tp = 7-num;
		
		return true;
	}
};

int main(){
	int n;
	while(cin>>n&&n){
		rep(i,210)rep(j,210)rep(k,51)fie[i][j][k]=-1;
		
		rep(i,n){
			int a,b;
			cin>>a>>b;
			dice dc(a,b);
			while(1){
				if(!dc.fall()){
					if(!dc.move()){
						fie[dc.x][dc.y][dc.z] = dc.tp;
						break;
					}
				}
			}
		}
		
		int ans[7]={};
		rep(i,210) rep(j,210) for(int k=50;k>=0;k--){
			if(fie[i][j][k]!=-1){
				ans[fie[i][j][k]]++;
				break;
			}
		}
		cout<<ans[1]<<" "<<ans[2]<<" "<<ans[3]<<" "<<ans[4]<<" "<<ans[5]<<" "<<ans[6]<<endl;
	}
}

Measured memory_bytes: 11900
if __name__ == "__main__":
    num_query = int(input())
    bits = [0] * 64

    for _ in range(num_query):
        op, *v = map(lambda x: int(x), input().split())
        if (0 == op):
            if (1 == bits[v[0]]):
                print(1)
            else:
                print(0)
        elif (1 == op):
            bits[v[0]] = 1
        elif (2 == op):
            bits[v[0]] = 0
        elif (3 == op):
            bits[v[0]] = 1 if bits[v[0]] == 0 else 0
        elif (4 == op):
            if all(bits):
                print(1)
            else:
                print(0)
        elif (5 == op):
            if any(bits):
                print(1)
            else:
                print(0)
        elif (6 == op):
            if not sum(bits):
                print(1)
            else:
                print(0)
        elif (7 == op):
            print(sum(bits))
        else:
            bin_str = "".join([str(elem) for elem in bits[::-1]])
            print(f"{int(bin_str, 2)}")



Measured memory_bytes: 5640
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int main() {
    int n;
    cin >> n;
    vector<tuple<ll, ll, ll>> t;
    for (int i = 0; i < n; ++i) {
        ll x, y, h;
        cin >> x >> y >> h;
        t.emplace_back(h, x, y);
    }
    sort(t.begin(), t.end(), greater<tuple<ll, ll, ll>>());
    for (int i = 0; i <= 100; ++i) {
        for (int j = 0; j <= 100; ++j) {
            ll H = get<0>(t[0]) + abs(get<1>(t[0]) - i) + abs(get<2>(t[0]) - j);
            bool ok = true;
            auto check = [&](ll x, ll y, ll h) {
                return h == max(0LL, H - abs(i - x) - abs(j - y));
            };
            for (int k = 0; k < n; ++k) {
                if (!check(get<1>(t[k]), get<2>(t[k]), get<0>(t[k]))) {
                    ok = false;
                    break;
                }
            }
            if (ok) {
                cout << i << " " << j << " " << H << endl;
                return 0;
            }
        }
    }
    return 0;
}

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

int main() {
    int a, b;
    cin >> a >> b;
    if(a <= 5){
        cout << 0 << endl;
    }else if(6 <= a && a <= 12){
        cout << b / 2 << endl;
    }else{
        cout << b << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

signed main() {
  INIT;
	VAR(int,n,k);
	VEC(int,a,n);

	vector<int> sm(n+1,0);
	vector<int> po_sm(n+1,0);
	REP(i,n){
		sm[i+1] = sm[i] + a[i];
		po_sm[i+1] = po_sm[i] + std::max(0L, a[i]);
	}

	int ans = 0;
	REP(i,n){
		int tmp = 0;
		if (i+k>n) break;
		tmp += std::max((sm[i+k] - sm[i]), 0L);
		debug(tmp);
		tmp += po_sm[i];
		tmp += po_sm[n] - po_sm[i+k];
		debug(i);
		debug(tmp);
	  ans = std::max(ans,tmp);
	}
	OUT(ans)BR;

	
  
  return 0;
}


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


int main()
{
	string str;
	int len;
	int i,j;
	while(1) {
		getline(cin,str);
		if(cin.eof())
			break;

		len = str.length();
		for(i = 0; i < 26; i++ ) {
			for ( j = 0; j < len; j++ ) {
				if ( 'a' <= str[j] && str[j] <= 'z') {
					str[j]++;
					if ( str[j] > 'z')
						str[j] = 'a';
				}
			}
			if( str.find("the") != string::npos || str.find("this") != string::npos
			|| str.find("that") != string::npos ) {
				cout << str << endl;
				break;
			}
		}
	}

	return 0;
}

Measured memory_bytes: 0
n, m, x, y = gets.split(" ").map(&:to_i)
x_s = gets.split(" ").map(&:to_i)
y_s = gets.split(" ").map(&:to_i)
nums = []

i = x + 1
while i <= y
  nums << i
  i += 1
end

nums.each do |n|
  if x_s.max < n && y_s.min >= n
    puts "No War"
    exit
  end
end

puts "War"

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

int main() {

    int w,h,n;
    cin >> w >> h >> n;

    int zahyou[100][100] = {{0}};

    int x, y, a;
    for(int i = 0; i < n; i++){
          cin >> x >> y >> a;

          if( a == 1 ){
              for(int j = 0; j < x; j++){
                  for(int k = 0; k < h; k++){
                      zahyou[j][k] = 1;
                  }
              }
          }

          if( a == 2 ){
              for(int j = x; j < w; j++){
                  for(int k = 0; k < h; k++){
                      zahyou[j][k] = 1;
                  }
              }
          }

          if( a == 3 ){
              for(int j = 0; j < w; j++){
                  for(int k = 0; k < y; k++){
                      zahyou[j][k] = 1;
                  }
              }
          }

          if( a == 4 ){
              for(int j = 0; j < w; j++){
                  for(int k = y; k < h; k++){
                      zahyou[j][k] = 1;
                  }
              }
          }
    }

    int black = 0;
    for(int i = 0; i < w; i++){
        for(int j = 0; j < h; j++){
            black += zahyou[i][j];
        }
    }

    cout << w*h - black << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
//言語は「C++14(GCC 5.4.1)」
//AtCoder Beginner Contest 157-A

int main(void)
{
	int N;
	scanf("%d", &N);
	if (N % 2 == 1)
		printf("%d", (N / 2) + 1);
	else
		printf("%d", N / 2);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main(){
	int n,big,flag=0,sum=0;
	cin >> n;
	vector<int>l(n);
	for (int i = 0; i < n; i++) {
		cin >> l[i];
	}
	big = l[0];
	for (int i = 0; i < n; i++) {
		big = max(big, l[i]);

	}
	for (int i = 0; i < n; i++) {
		if (big == l[i] && flag == 0) {
			flag++;
			continue;
		}
		else {
			sum += l[i];
		}
	}
	if (sum > big) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(I,X,Y) for(int (I)=(X);(I)<(Y);(I)++)
#define REP(I,X,Y) for(int (I)=(Y)-1;(I)>=(X);(I)--)
#define ALL(X) (X).begin(),(X).end()
#define INF 1000000007
#define LINF 1000000000000000007
typedef long long ll;
using namespace std;

ll a[200010];
ll SUM[200010];
ll XOR[200010];

bool check(ll l,ll r){
  if(l)return SUM[r]-SUM[l-1] == (XOR[r]^XOR[l-1]);
  else return SUM[r] == XOR[r];
}

int main(){
  ll ans = 0;
  int N;
  cin >> N;
  FOR(i,0,N)cin >> a[i];
  FOR(i,0,N)SUM[i] = a[i];
  FOR(i,0,N)XOR[i] = a[i];
  FOR(i,1,N+1){
    XOR[i] ^= XOR[i-1];
    SUM[i] += SUM[i-1];
  }
  FOR(i,0,N){
    int l = i;
    int r = N;
    int imid;
    while(r-l > 1){
      imid = (l+r)/2;
      if(check(i,imid))l = imid;
      else r = imid;
    }
    ans += l - i + 1;
  }
  cout << ans << endl;
}


Measured memory_bytes: 4992
///=======================///
/// coder: Andy - Tohrumi ///
///=======================///

#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define fastio ios_base::sync_with_stdio(); cin.tie(0); cout.tie(0);
#define pb push_back
#define mp make_pair
#define all(x) x.begin(), x.end()
#define rep(i, a, b) for(__typeof(b) i = a; i < b; i++)
#define Rep(i, a, b) for(__typeof(a) i = a; i > b; i--)
	
using namespace std;

typedef pair<ll, ll> pll;	typedef pair<int, int> ii;
typedef vector<pll> vll;	typedef vector<string> vs;		typedef vector<ii> vii;
typedef vector<int> vi; 	typedef vector<ll> vl;

///=====code start here=====///

const ld PI = 3.14159265358979323846;

signed main() {
	fastio;
	ld a, b, h, m; cin >> a >> b >> h >> m;
	ld h_angle = 30.0 * h; h_angle = h_angle + m * 30.0 / 60;
	ld m_angle = 6.0 * m, val = PI / 180.0;
	ld angle = fabs(h_angle - m_angle);
	angle = min(angle, (ld)360 - angle);
	ld ans = a * a + b * b;
	if(angle != 90) ans -= 2 * a * b * cos(angle * val);
	ans = sqrt(ans);
	cout << setprecision(12) << fixed << ans;
	return 0;
}


Measured memory_bytes: 4132
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
	int nCount, nCo;
	while (cin >> nCount, nCount)
	{
		int nInput[1000] = { 0 };
		float nSum = 0;
		int i = 0;
		int nIn = 0;

		nCo = nCount;
		while (nCount--)
		{
			cin >> nIn;
			nInput[i++] = nIn;
			nSum += nIn;
		}
		float nAvg = nSum / nCo;
		nSum = 0;
		for (int i = 0; i < nCo; i++)
		{
			nSum += (nInput[i] - nAvg)*(nInput[i] - nAvg);
		}
		nSum /= nCo;
		nSum = sqrtf(nSum);
		printf("%.5f\n", nSum);
	}
	//system("pause");
	return 0;

}

Measured memory_bytes: 3228
/*
AuThOr Gwj
*/
#include<bits/stdc++.h>
#define rb(a,b,c) for(int a=b;a<=c;++a)
#define rl(a,b,c) for(int a=b;a>=c;--a)
#define LL long long
#define IT iterator
#define PB push_back
#define II(a,b) make_pair(a,b)
#define FIR first
#define SEC second
#define FREO freopen("check.out","w",stdout)
#define rep(a,b) for(int a=0;a<b;++a)
#define SRAND mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define random(a) rng()%a
#define ALL(a) a.begin(),a.end()
#define POB pop_back
#define ff fflush(stdout)
#define fastio ios::sync_with_stdio(false)
#define R(a) cin>>a
#define R2(a,b) cin>>a>>b
using namespace std;
const int INF=0x3f3f3f3f;
typedef pair<int,int> mp;
int n;
int u[55],v[55];
int dis[55][55],mask[55];
vector<int> g[55];
map<mp,int> id;
LL dp[50][1<<20];
void dfs(int now,int pre,int st,int dist=0){
	dis[st][now]=dist;
	for(auto it:g[now]){
		if(it!=pre){
			dfs(it,now,st,dist+1);
		}
	}
}
void run(int st,int to,int m){
	if(st==to) return ;
	for(auto it:g[st]){
		if(dis[it][to]+1==dis[st][to]){
			mask[id[II(it,st)]]+=(1<<m);
			run(it,to,m);
			return ;	
		}
	}
}
int main(){
	fastio;
	R(n);
	rb(i,2,n)
	{
		R2(u[i],v[i]);
		id[II(u[i],v[i])]=id[II(v[i],u[i])]=i-1;
		g[u[i]].PB(v[i]);
		g[v[i]].PB(u[i]);
	}
	rb(i,1,n){
		dfs(i,0,i);
	}
	int M;
	R(M);
	rep(i,M){
		int u,v;
		R2(u,v);
		run(u,v,i);
	}	
	dp[0][0]=1;
	rep(i,n-1){
		rep(j,1<<M){
			dp[i+1][j]+=dp[i][j];
			dp[i+1][j|mask[i+1]]+=dp[i][j]; 
		}
	}
	cout<<dp[n-1][(1<<M)-1]<<endl;
	return 0;
}


Measured memory_bytes: 404900
// ALDS1_3_C: Doubly Linked List

use std::collections::VecDeque;

fn main() {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    let n = s.trim().parse::<usize>().unwrap();

    let mut list: VecDeque<i64> = VecDeque::new();

    for _ in 0..n {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let com = s.split_whitespace().collect::<Vec<&str>>();

        match com[0] {
            "insert" => {
                let x = com[1].parse().unwrap_or(0);
                list.push_front(x);
            }
            "deleteFirst" => {
                list.pop_front();
            },
            "deleteLast" => {
                list.pop_back();
            },
            "delete" => {
                let x = com[1].parse().unwrap_or(0);
                let mut i: usize = 0;
                for y in &list {
                    if *y == x {
                        break;
                    }
                    i += 1;
                }
                list.remove(i);
            },
            _ => {
                // Do nothing.
            },
        }
    }

    let a = &list.iter()
        .map(|n| n.to_string())
        .collect::<Vec<String>>()
        .join(" ");
    println!("{}", a);
}


Measured memory_bytes: 21400
import fractions

N = int(input())
A = list(map(int, input().split()))
L = A[0]
for i in range(1, N):
    L = L * A[i] // fractions.gcd(L, A[i])

ans = 0
for i in range(N):
    ans = (ans + L // A[i]) #% 1000000007

print(ans%1000000007)


Measured memory_bytes: 6200
#include <stdio.h>

int	main(void)
{
  	int	n;
  	int	k;
  	int	d[102];
  	int	a[102][102];
  	int ans[102];
  	int i;
  	int j;
  	int cnt;
  
  	scanf("%d %d\n", &n, &k);
  	for (i=1; i<=n; i++)
  	{
  	    ans[i] = 1;
  	}
  	for (i=1; i<=n; i++)
  	{
      	scanf("%d\n", &d[i]);
      	for (j=0; j<d[i]; j++)
        {
            scanf("%d", &a[i][j]);
            ans[ a[i][j] ] = 0;
        }
  	}

  	cnt = 0;
  	for (i=1; i<=n; i++)
  	{
  	    if (ans[i] == 1)
  	        cnt++;
  	}
  
  	printf("%d", cnt);
  
  	return (0);
}

Measured memory_bytes: 1720
n,a,b = map(int,input().split())
x = list(map(int,input().split()))
ans = 0
for i in range(n-1):
    if (x[i+1]-x[i]) * a <= b:
        ans += (x[i+1]-x[i]) * a
    else:
        ans += b
print(ans)

Measured memory_bytes: 14252
// 日本語
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let vs: Vec<u64> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();
    let a = vs[0];
    let b = vs[1];
    let k = vs[2];

    let mut n = 0;
    for i in (1..gcd(a, b)+1).rev() {
        if a % i == 0 && b % i == 0 {
            n += 1;
            if n == k {
                println!("{}", i);
                break;
            }
        }
    }
}

fn gcd(a: u64, b: u64) -> u64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}


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

temp=[]
dif_min=9999999
for i in range(N):
    temp.append(T-0.006*H[i])
for i in range(N):
    if(abs(abs(temp[i])-abs(A))<dif_min):
        dif_min=abs(temp[i]-A)
        ans=i
print(ans+1)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int N,ma,ans;
int main(){
    cin>>N;
    int L[N];
    for(int i=0;i<N;i++)cin>>L[i];
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            for(int k=j+1;k<N;k++){
                if(L[i]==L[j]||L[i]==L[k]||L[j]==L[k])continue;
                ma=max({L[i],L[j],L[k]});
                if(ma<L[i]+L[j]+L[k]-ma){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<ll> vl;
typedef vector<vector<int, int> > vvi;
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define in insert
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int INF = 1e9 + 5;
int main(){
    int n;
    cin >> n;
    vi v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.pb(x);
    }
    ll sum = 0;
    for(int i = 0; i < n-1; i++){
        for(int j = i+1; j < n; j++){
            sum+=v[i]*v[j];
        }
    }
    cout << sum;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<numeric>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
const int MOD = 1000000007;
//scanf("%d", &a); '\n';

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int k,x;
	cin >> k>>x;
	//vector<int> a(n);
	//rep(i, n) cin >> a[i];
	if (500 * k >= x) cout << "Yes";
	else cout << "No";
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) *b;
}

struct edge {
	ll ind;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll n;
	cin >> n;

	vector<ll> a(n + 1);

	repn(i, n) cin >> a[i];

	ll ans1 = 0;
	ll s = 0;

	repn(i, n) {
		s += a[i];
		if (i % 2 == 1 && s <= 0) { ans1 += -s + 1; s = 1; }
		else if (i % 2 == 0 && s >= 0) { ans1 += s + 1; s = -1; }
	}

	ll ans2 = 0;
	s = 0;
	
	repn(i, n) {
		s += a[i];
		if (i % 2 == 0 && s <= 0) { ans2 += -s + 1; s = 1; }
		else if (i % 2 == 1 && s >= 0) { ans2 += s + 1; s = -1; }
	}

	cout << min(ans1, ans2);
	
	system("PAUSE");
}


Measured memory_bytes: 1272
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

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

        int n = sc.nextInt();

        System.out.print(n / 3);
    }

}




Measured memory_bytes: 23892
#include<bits/stdc++.h>
#define int long long int
const int mod=1e9+7;
#define fastinout     ios_base::sync_with_stdio(false); cin.tie(NULL);

using namespace std;
int power(int x, int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % p;
        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int imod(int a, int m)
{
    return power(a, m - 2, m);
}

void myfun()
{
	int n,i,a,b,cn=0;
	cin>>n;
	string ans="No";
	for(i=0;i<n;i++)
	{
		cin>>a>>b;
		if(a==b)
		cn++;
		else
		cn=0;
		if(cn==3)
		ans="Yes";
	}
    cout<<ans<<"\n";
}

signed main()
{
	 fastinout;
	int t=1;
	//cin>>t;
	while(t--)
	myfun();
	return 0;
}

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

#define NDEBUG
#ifdef DEBUG
#include "../cout11.h"
#undef NDEBUG
#endif
#include <cassert>

typedef long long ll;
typedef long double Double;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<long double> vD;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
#define cons make_pair


ll gcd(ll a, ll b) { while(a) swap(a, b%=a); return b; }

const ll MOD=1000000007LL;

ll ADD(ll x, ll y) { return (x+y) % MOD; }
ll SUB(ll x, ll y) { return (x-y+MOD) % MOD; }
ll MUL(ll x, ll y) { return x*y % MOD; }
ll POW(ll x, ll e) { ll v=1; for(; e; x=MUL(x,x), e>>=1) if (e&1) v = MUL(v,x); return v; }
ll DIV(ll x, ll y) { /*assert(y%MOD!=0);*/ return MUL(x, POW(y, MOD-2)); }
// ll comb(ll n, ll k) { ll v=1; for(ll i=1; i<=k; i++) v = DIV(MUL(v, n-i+1),i); return v; }
//

#define INTSPACE 12
char _buf[INTSPACE*1000000 + 3];

int loadint() {
    if (fgets(_buf, INTSPACE+3, stdin)==NULL) return 0;
    return atoi(_buf);
}

int loadvec(vector<int>& v, int N=-1) {
    if (N == -1) {
        N = loadint();
        if (N==0) return 0;
    }
    int bufsize = INTSPACE*N + 3;
    if (fgets(_buf, bufsize, stdin)==NULL) return 0;
    v.resize(N);

    int i=0;
    bool last = false;
    for (char *p=&_buf[0]; ;) {
        char *q = p;
        while (*q > ' ') ++q;
        if (*q == 0x0D || *q == 0x0A) last = true;
        *q = 0;
        v[i++] = atoi(p);
        if (last || i == N) break;
        p = q+1;
    }
    // assert(i <= N);
    return i;
}
void read_cr() {
    fgets(_buf, 256, stdin);
}

int solve(int N, int K, vi& a) {
    int one = -1;
    rep(i,N){
        if (a[i] == 1) { one = i; break; }
    }
    int rem = N-K;
    if (rem == 0) return 1;
    int d = K-1;
    return 1+(rem + d-1)/d;
}

int main() {
    int N,K; cin>>N>>K;
    read_cr();
    vi a(N);
    loadvec(a, N);
    cout << solve(N,K,a) << endl;
    return 0;
}


Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD 1000000007
#define print(A,n) for(ll i=0;i<n;++i)cout<<A[i]<<' ';cout<<endl;
#define take(A,n) for(ll i=0;i<n;++i)cin>>A[i];
//    for(auto& it : m)
void fastio(){ios_base::sync_with_stdio(false);cin.tie(NULL);}
//  priority_queue<ll int> pq;
//  priority_queue <ll int, vector<ll int>, greater<ll int> > pq;
//  vector<ll int> v;
//  vector< pair<ll int,ll int> > v;
//  set<ll int>::iterator it=s.begin();
//  unordered_map<  pair<ll int,ll int>, ll int> mp;

ll int power(ll int x, ll int y, ll int p)  
{  
   ll int res = 1;     // Initialize result  
  
    x = x % p; // Update x if it is more than or  
                // equal to p 
   
    if (x == 0) return 0; // In case x is divisible by p; 
  
    while (y > 0)  
    {  
        // If y is odd, multiply x with result  
        if (y & 1)  
            res = (res*x) % p;  
  
        // y must be even now  
        y = y>>1; // y = y/2  
        x = (x*x) % p;  
    }  
    return res;  
}  
 


 
int main()
{
  fastio();
ll int T;
T=1;


ll int anscount=1,i,j,k;
while(T--)
{
  ll int k,a,b;cin>>k>>a>>b;
  if(a%k==0)
  {
    cout<<"OK"<<endl;
  }
  else
  {
    if((a/k+1)*k<=b)
      cout<<"OK"<<endl;
    else
      cout<<"NG"<<endl;
  }
 

}






    return 0;
}

Measured memory_bytes: 3652
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;

namespace atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var b = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();
            var c = Console.ReadLine().Split(' ').Select(num => int.Parse(num)).ToArray();

            var result = 0;
            for (var i = 0; i < n; i++)
            {
                var current = a[i];
                result += b[current - 1];
                if (i > 0 && a[i - 1] == current - 1) result += c[current - 2];
            }

            Console.WriteLine(result);
        }

    }
}

Measured memory_bytes: 28316
#include <bits/stdc++.h>
#define int long long
using namespace std;
int pr[1000005];
int vis[1000005];
signed main()
{
    int x;
    cin>>x;
    for(int i=2;i<=1000000;i++)
    {
        if(vis[i]==0)
        {
         pr[i]=1;   
        for(int j=i;j<=1000000;j+=i)
        {
            vis[j]=1;
        }
        }
    }
    
    for(int i=x;;i++)
    {
        if(pr[i])
        {
            cout<<i;
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 15872
/*input
9 2
RRRLRLRLL
*/

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

int main() {
    ll n, k;
    cin >> n >> k;
    vector<int> s(n);
    for (int i = 0; i < n; i++) {
        char ch;
        cin >> ch;
        if (ch == 'R') {
            s[i] = 0;
        }
        else {
            s[i] = 1;
        }
    }
    ll left = 0, right = n-1;
    ll ans = 0;
    ll cnt = 0;
    while (left < right) {
        while (left < n-1 && s[left] == s[left+1]) {
            left++;
            ans++;
            if (left == n-1) break;
        }
        while ((s[right] == s[right-1] || s[right] != s[left]) && (left < right)){
            if (s[right] == s[right-1]) ans++;
            right--;
        }
        if (cnt < k && left < right) {
            cnt++;
            if (left <= right-2) ans += 2;
            else ans++;
        }
        left++;
        right--;
    }
    if (cnt < k && s[0] != s[n-1]) {
        ans++;
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  int h, w, n;
  cin >> h >> w;
  cin >> n;
  vector<int> c;
  for (int i = 0; i < n; i++) {
    int d;
    cin >> d;
    while (d--) c.push_back(i+1);
  }

  vector<vector<int> >sol(h, vector<int>(w));
  int cnt = 0;
  for (int i = 0; i < h; i++)
    for (int j = 0; j < w; j++) {
      if (i%2 == 0) sol[i][j] = c[cnt++];
      else sol[i][w-1-j] = c[cnt++];
    }
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++)
      cout << sol[i][j] << " ";
    cout << endl;
  }
  return 0;
}



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

#define lli long long int
#define LLI(n) lli n; scanf("%lld", &n);
#define Sort(n) sort(n.begin(), n.end());
#define Reve(n) reverse(n.begin(), n.end());
#define yes puts("Yes");
#define no puts("No");
#define C45(n) (n + 1) / 2

//素数
bool IsPrime(lli num)
{
  if (num < 2) return false;
  else if (num == 2) return true;
  else if (num % 2 == 0) return false;
  long double sqrtNum = sqrt(num);
  for (lli i = 3; i <= sqrtNum; i += 2)
  {
    if (num % i == 0)return false;
  }
  return true;
}
//各桁の和
lli Sum(lli n)
{
  lli sum=0;
  if (n<0) return 0;
  while (n>0)
  {
    sum += n%10;
    n /= 10;
  }
  return sum;
}

int main(void)
{
  LLI(a)
  LLI(b)
  printf("%lld\n", C45(a+b));
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <cctype>
#include <complex>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second
using ll = long long;
using PII = pair<int, int>;
using PLL = pair<ll, ll>;

const double eps = 1e-10;

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;}

int N;
ll a[10010], b[10010];

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

	cin >> N;
	REP(i, N)
		cin >> a[i];
	REP(i, N)
		cin >> b[i];

	ll cnt1 = 0, cnt2 = 0;
	REP(i, N){
		if(a[i] > b[i]){
			cnt1+=a[i]-b[i];
		}else{
			if((b[i]-a[i])%2){
				cnt1++;
			}
			cnt2 += (b[i]-a[i]+1)/2;
		}
	}
	if(cnt1 <= cnt2)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,T;
    cin >> N >> T;
    vec<ll> A(N),B(N);
    for(int i=0;i<N;i++){
        cin >> A[i] >> B[i];
    }
    vec<int> idx(N);
    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),[&](int i,int j){
        if(A[i]!=0 || A[j]!=0) return A[i]*(B[j]+1)>A[j]*(B[i]+1);
        else return B[i]<B[j];
    });
    ll inf = 1e18;
    int M = 30;
    vvec<ll> dp(N+1,vec<ll>(M+1,inf));
    dp[0][0] = 0;
    int n = N;
    for(int i=0;i<N;i++){
        int id = idx[i];
        if(A[id]==0){
            n = i;
            break;
        }
        for(int j=0;j<M;j++) if(dp[i][j]<T){
            dp[i+1][j+1] = min(dp[i][j+1],(A[id]+1)*dp[i][j]+A[id]+B[id]+1);
            dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
        }
    }
    int ans = 0;
    for(int j=0;j<=M;j++) if(dp[n][j]<=T){
        ll t = dp[n][j];
        int now = j;
        for(int i=n;i<N;i++){
            if(t+B[idx[i]]+1<=T){
                t += B[idx[i]]+1;
                now++;
            }else break;
        }
        ans = max(ans,now);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 58880
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
int X=scan.nextInt();
        int N =scan.nextInt();


        int M[]=new int[N];
        int K=0;
        int Y=0;
        for(int i=0;i<N;i++) {M[i]=scan.nextInt();
        if (M[i]==X){K=1;
        Y=1;
        }}


      int P=X;
        int C=1;
            Arrays.sort(M);
        for(int i=0;i<N&&K==1&&C==1;i++){ C=0;
            K=0;
        for(int j=N-1;j>=0&&K==0;j--) {
            if (M[j] == X +i) {
             C= 1;
             P=M[j];
            }

            if (M[j] == X -i) {
                K = 1;
                P = M[j];
            }
        }

        }
        if (P>X&&Y==1&&C==0){System.out.println(2*X-P-1);}
        if (P>X&&Y==1&&C==1){System.out.println(2*X-P);}
        if (P<X&&Y==1&&K==0){System.out.println(P-1);}
        if (P<X&&Y==1&&K==1&&C==0){System.out.println(2*X-P);}
    
        if (P==X&&Y==1){System.out.println(P-1);}
        if (Y==0){System.out.println(X);}




    }
    }






Measured memory_bytes: 35800
N = int(input())
TS = sorted([[0,0,0]] + [list(map(int, input().split())) for k in range(N)])
result = True
for k in range(N):
    length = [abs(TS[k+1][i] - TS[k][i]) for i in range(3)]
    reminder = length[0] - length[1] - length[2]
    result = result and (reminder >= 0) and (reminder % 2 == 0)
print("Yes") if result else print("No")

Measured memory_bytes: 28068
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>

#include <algorithm>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>

#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

const int P = 1000000007;

void add(int& x, int y) {
  if ((x += y) >= P)
    x -= P;
}

void sub(int& x, int y) {
  if ((x -= y) < 0)
    x += P;
}

int norm(int x) { return x >= P ? x - P : x; }

int main() {
#ifdef LBT
  freopen("test.in", "r", stdin);
  int nol_cl = clock();
#endif
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n;
  cin >> n;
  vector<int> a(n * 2), pos(n * 2, -1);
  cin >> a;
  for (int i = 0; i < n * 2; ++i)
    if (a[i] != -1)
      pos[--a[i]] = i;
  int empties = 0;
  for (int i = 0; i < n; ++i)
    if (a[i * 2] == -1 && a[i * 2 + 1] == -1)
      ++empties;
  vector<vector<int>> dp(n + 1, vector<int>(n + 1));
  dp[0][0] = 1;
  for (int i = 0; i < n * 2; ++i) {
    if (pos[i] != -1 && a[pos[i] ^ 1] != -1)
      continue;
    vector<vector<int>> newDp(n + 1, vector<int>(n + 1));
    if (pos[i] == -1) {
      for (int j = 0; j <= n; ++j)
        for (int k = 0; k <= n; ++k) {
          if (k < n)
            add(newDp[j][k + 1], dp[j][k]);
          if (j < n)
            add(newDp[j + 1][k], dp[j][k]);
          if (k)
            add(newDp[j][k - 1], dp[j][k]);
        }
    } else {
      for (int j = 0; j <= n; ++j)
        for (int k = 0; k <= n; ++k) {
          if (k < n)
            add(newDp[j][k + 1], dp[j][k]);
          if (j)
            add(newDp[j - 1][k], dp[j][k] * (ll)j % P);
        }
    }
    dp = newDp;
  }
  int ans = dp[0][0];
  for (int i = 1; i <= empties; ++i)
    ans = ans * (ll)i % P;
  cout << ans << '\n';

#ifdef LBT
  LOG("Time: %dms\n", int ((clock()
          -nol_cl) / (double)CLOCKS_PER_SEC * 1000));
#endif
  return 0;
}


Measured memory_bytes: 1060
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] xs) {
    int ans = 0;
    int p = 1;
    while (p < xs.length) {
        if (xs[p-1] == xs[p]) {
            ans++;
            p += 2;
        }
        else p++;
    }
    return ans;
}

void main() {
    readint;
    auto xs = readints;

    int ans = calc(xs);
    writeln(ans);
}

Measured memory_bytes: 256
import java.util.*;

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

        int numbers = sc.nextInt();
        int end = sc.nextInt();
        int count = 0;

        while(end<=numbers){
            count++;
            end++;
        }

        System.out.println(count);
    }
}

Measured memory_bytes: 21844
//teja349
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

using namespace std;
#define f(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inf (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define mod (1000*1000*1000+7)
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >

//std::ios::sync_with_stdio(false);   
int arr[123][123];
int main(){
    std::ios::sync_with_stdio(false);
    int a,b,bb,i,j,k;
    cin>>a>>b;
    rep(i,100){
    	arr[0][i]=1;
    }
    bb=b-1;
    f(i,1,100){
    	rep(j,100){
    		if(j%2 || !bb){
    			arr[i][j]=1;
    		}
    		else{
    			arr[i][j]=0;
    			bb--;
    		}
    	}
    	i++;
    	rep(j,100){
    		arr[i][j]=1;
    	}
    	if(bb==0){
    		i++;
    		break;
    	}

    }
    i++;
    bb=a-1;
    for(;i<100;i++){
    	rep(j,100){
    		if(j%2 || !bb){
    			arr[i][j]=0;
    		}
    		else{
    			arr[i][j]=1;
    			bb--;
    		}
    	}
    	i++;
    	if(bb==0){

    		i++;
    		break;
    	}
    	
    }
    cout<<i<<" "<<100<<endl;
    rep(k,i){
    	rep(j,100){
    		if(arr[k][j])
    			cout<<".";
    		else
    			cout<<"#";
    	}
    	cout<<endl;
    }
    return 0;  
    
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int sum1, sum2;
        double m, v, s;
        int[] score;
        while(n != 0) {
            sum1 = 0;
            sum2 = 0;
            score = new int[n];
            for (int j = 0; j < n; j++) {
                score[j] = sc.nextInt();
                sum1 += score[j];
            }
            m = (double) sum1 / n;
            for (int j = 0; j < n; j++) {
                sum2 += score[j] * score[j];
            }
            v = (double) sum2 / n - m * m;
            s = Math.sqrt(v);
            System.out.printf("%f\n", s);
            n = sc.nextInt();
        }
    }
}


Measured memory_bytes: 32224
#D Card Eater
N = int(input())
List = [int(i) for i in input().split(" ")]
List.sort()
result = 1
for i in range(1,N):
    if List[i]!=List[i-1]:
        result+=1
if result%2 == 0:
    print(result-1)
else:
    print(result)

Measured memory_bytes: 14396
import qualified Data.ByteString.Char8 as C
import Data.Int
import qualified Data.IntMap.Strict as M
import Data.List

main = C.interact $ C.pack . show . sol . get

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines

sol ::[[Int]] -> Int64
sol [[n],as] = maximum $ zipWith (+) lsum rsum
  where
  lsum = fmap snd $ scanl' f (sl,xl) am
  rsum = fmap snd $ scanr (flip f) (sr,xr) (negate <$> am)
  (al:am:ar:_) = unfoldr (\xs -> if null xs then Nothing else Just (splitAt n xs)) as
  ar' = negate <$> ar
  sl = M.fromListWith (+) $ zip al (repeat 1)
  sr = M.fromListWith (+) $ zip ar' (repeat 1)
  xl = foldl' nsum (0 :: Int64) al
  xr = foldl' nsum (0 :: Int64) ar'

nsum s k = s + fromIntegral k

f (s,x) a = if a>k then (delins a k s, x+fromIntegral (a-k)) else (s,x)
  where k = fst $ M.findMin s

delins a k = M.insertWith (+) a 1 . 
  M.update (\c -> if c==1 then Nothing else Just (c-1)) k

Measured memory_bytes: 214396
import java.util.*;
public class Main {
	public static void main(String args[]){
		Scanner scanner = new Scanner(System.in);
		int A = Integer.parseInt(scanner.nextLine()); //500
		int B = Integer.parseInt(scanner.nextLine()); //100
		int C = Integer.parseInt(scanner.nextLine()); //50
		int X = Integer.parseInt(scanner.nextLine()); //total
		int count = 0;
		
		for(int a=0; a<=A; a++){
			for(int b=0; b<=B; b++){
				for(int c=0; c<=C; c++){
					if((500*a + 100*b + 50*c) == X){
						count++;
					}
				}
			}
		}
		
		System.out.println(count);
	}
}

Measured memory_bytes: 22612
fun main(args: Array<String>) {
    readLine()
    val array = readLine()
        ?.split(" ".toRegex())
        ?.map(String::toInt)
        ?.toIntArray()
        ?: intArrayOf()
    println(array.joinToString(" ", postfix = "\n${array.mergeSort()}"))
}

fun IntArray.mergeSort(): Int {
    return this.mergeSort(0, this.size)
}

fun IntArray.mergeSort(left: Int, right: Int): Int {
    var cnt = 0
    if (left + 1 < right) {
        val mid = (left + right) / 2
        cnt += this.mergeSort(left, mid)
        cnt += this.mergeSort(mid, right)
        cnt += this.merge(left, mid, right)
    }
    return cnt
}

fun IntArray.merge(left: Int, mid: Int, right: Int): Int {
    var cnt = 0
    val array1 = IntArray((mid - left) + 1)
    val array2 = IntArray((right - mid) + 1)
    for (i in 0 until array1.size - 1) {
        array1[i] = this[left + i]
    }
    for (i in 0 until array2.size - 1) {
        array2[i] = this[mid + i]
    }
    array1[array1.lastIndex] = Int.MAX_VALUE
    array2[array2.lastIndex] = Int.MAX_VALUE
    var i = 0
    var j = 0
    for (k in left until right) {
        this[k] = if (array1[i] < array2[j]) {
            array1[i++]
        } else {
            array2[j++]
        }
        cnt++
    }
    return cnt
}


Measured memory_bytes: 164628
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <sstream>
#include <math.h>
using namespace std;

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

    if(X>=2000){
        cout << 1 << endl;
        return 0;
    }
    for (int x1 = 0; x1 < 20; x1++)
    {
        for (int x2 = 0; x2 < 20; x2++)
        {
            for (int x3 = 0; x3 < 20; x3++)
            {
                for (int x4 = 0; x4 < 20; x4++)
                {
                    for (int x5 = 0; x5 < 20; x5++)
                    {
                        for (int x6 = 0; x6 < 20; x6++)
                        {
                            if((100*x1+101*x2+102*x3+103*x4+104*x5+105*x6) == X){
                                cout << 1 << endl;
                                return 0;
                            }
                        }
                        
                    }
                    
                }
                
            }
            
        }
        
    }
    cout << 0 << endl;
}

Measured memory_bytes: 384
class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        fi = [pow(f[-1], mod - 2, mod)]
        for idx in range(max_fact, 0, -1):
            fi += [fi[-1] * idx % mod]
        fi = fi[::-1]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = 5 * 10**5
mod = 10**9 + 7
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation

N, M = [int(_) for _ in input().split()]
ans = 0
for p in range(N + 1):
    ans += (-1)**p * comb(N, p) * perm(M - p, N - p)
    ans %= mod
ans *= perm(M, N)
ans %= mod
print(ans)


Measured memory_bytes: 112204
#include <bits/stdc++.h>
#include <vector>
using namespace std;
int main() {
  int a,b,c;
  c = 0;
  cin >> a >> b;
  vector<int> v(a);
  for (int i=0; i<a; i++) {
    cin >> v.at(i);
  }
  sort(v.begin(), v.end());
  for (int i=0; i<b; i++) {
    c += v.at(i);
  }
  cout << c;
}

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

int main(){
  int N;
  cin >> N;
  
  for ( int i = N ; i < 1000 ; i++ ){
  	int h = i/100;
  	int t = (i%100)/10;
  	int o = i%10;
    
    if ( h == t && t == o && o == t ){
      cout << h << t << o << endl;
      break;
    }
  }
}  

Measured memory_bytes: 256
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2

int n, M[N][N];
int color[N], d[N], f[N], t;

void visit(int i)
{
   int v;
   color[i] = G;
   d[i] = ++t;

   for (v=0; v<n; v++){
      if (M[i][v]==0)
         continue;
      if (color[v]==W)
         visit(v);
   }
   color[i] = B;
   f[i] = ++t;
}

void dfs()
{
   int i;
   for (i=0; i<n; i++)
      color[i] = W;
      t=0;
   for (i=0; i<n; i++){
      if (color[i]==W)
            visit(i);
   }
   for (i=0; i<n; i++)
      printf("%d %d %d\n", i+1, d[i], f[i]);
}

int main()
{
   int u, v, k, i, j;

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

   for (i=0; i<n; i++){
      scanf("%d %d",  &u, &k);
      u--;
      for (j=0; j<k; j++){
         scanf("%d", &v);
         M[u][v-1] = 1;
      }
   }

   dfs();

   return 0;
}



Measured memory_bytes: 2052
//#include </Users/piyush/Desktop/nodejs/first-app/CP/bits/stdc++.h>
 #include <bits/stdc++.h>
typedef long long ll;
using namespace std;


#define print(x) for(auto iuiuiuiuiui:x){ cout<<iuiuiuiuiui<<" ";}br;
#define pb(qwerty) push_back(qwerty)

#define br cout<<"\n"
//const int INF=1e9+5;
const ll INF=1e18L+5;

const ll mod=1e9L+7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n,k;
    cin>>n>>k;

    vector<vector<char>> grid(n,vector<char>(k));
    vector<vector<ll>> dp(n,vector<ll>(k,0));

    for(ll i=0;i<n;i++){
        for(ll j=0;j<k;j++){
            cin>>grid[i][j];
        }
    }

    for(ll i=0;i<n;i++){
        if(grid[i][0]=='#')
        {
            break;
        }else{
            dp[i][0]=1;
        }
    }

    for(ll i=0;i<k;i++){
        if(grid[0][i]=='#')
        {
            break;
        }else{
            dp[0][i]=1;
        }
    }

    for(ll i=1;i<n;i++){
        for(ll j=1;j<k;j++){
            if(grid[i][j]=='#'){
                dp[i][j]=0;
            }else{
                dp[i][j]=(dp[i-1][j]%mod +dp[i][j-1]%mod)%mod;
            }
        }
    }

//    for(ll i=0;i<n;i++){
//        for(ll j=0;j<k;j++){
//            cout<<dp[i][j]<<" ";
//        }
//        br;
//    }

    cout<<dp[n-1][k-1] % mod;




}

Measured memory_bytes: 9088
N = int(input())
p1 = tuple(map(int,input().split()))
p2 = tuple(map(int,input().split()))
def dfs(pair=[]):
  global lst
  if len(pair) == N:
    lst.append(tuple(pair))
  else:
    for j in range(1,N+1):
      if j not in pair:
        pair.append(j)
        dfs(pair)
        pair.pop()

lst = []
dfs()
lst.sort()
print(abs(lst.index(p1) - lst.index(p2)))

Measured memory_bytes: 54236