akhauriyash/Code-Regression huggingface dataset:
import java.util.ArrayList;
import java.util.Scanner;


	public class Main {
		
		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			int n = sc.nextInt();
			int[] b = new int[n+1];
			ArrayList<Integer> list = new ArrayList<Integer>();
			
			
			for(int i=1;i<=n;i++) {
				b[i] = sc.nextInt();
			}
			
			while(true) {
				boolean endflg = true;
				for(int i=n;i>=1;i--) {
					
					int count = 0;
					if(b[i]==i&&b[i]!=0) {
						list.add(i);
						count++;
						endflg = false;
						
						
						for(int j=i;j<n;j++) {
							b[j]=b[j+1];
						}
						b[n+1-count]=0;
						
						
						break;
					}
					
					
				}
				
				if(list.size()==n) {
					break;
				}
				
				if(endflg) {
					System.out.println(-1);
					return;
				}
			}
			
			
			for(int i=list.size()-1;i>=0;i--) {
				System.out.println(list.get(i));
			}
			
	    }
		
	}
	


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

int main(){
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string ans;
    rep(i,n){
        ans += s[i];
        ans += t[i];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF (1<<29)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define CLR(a) memset(a,0,sizeof(a))
const int dx[] = {-1,0,0,1},dy[] = {0,1,-1,0};

typedef long long int ll;

using namespace std;

string query(string s){
    string ret = "";
    s += "h";
    char c = s[0];
    int x = 0;
    REP(i,s.size()){
	if(c != s[i]){
	    ret += to_string(x);
	    ret += c;
	    x = 1;
	    c = s[i];
	}else x++;
    }
    return ret;
}

int main(){
    while(true){
	int n;
	string s;
	cin >> n;
	if(n == 0) break;
	cin >> s;
	REP(i,n){
	    s = query(s);
	}
	cout << s << endl;
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
//#define int long long int
const int MOD = 1000000007;
const ll LINF = (ll)1e18 - 1;
const int INF = 1e9 - 1;
const double EPS = 0.000000001;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

void print(const vector<int> &v) {
  for(auto x : v) {
    cout << x << " ";
  }
  cout << endl;
}

signed main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  ll k;
  cin >> s;
  cin >> k;
  char ans = '1';
  if(s.size() >= k) {
    rep(i, k) {
      if(s[i] != '1') {
        ans = s[i];
        break;
      }
    }
  }
  else {
    rep(i, s.size()) {
      if(s[i] != '1') {
        ans = s[i];
        break;
      }
    }
  }
  out(ans);

  return 0;
}


Measured memory_bytes: 256
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(2);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define sp " "
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI=3.141592653589793;

bool ok[10];

void solve()
{
	int n,k;
	cin>>n>>k;
	while(k--)
	{
		int x;
		cin >> x;
		ok[x] = 1;
	}
	for(int i=n;;i++)
	{
		int cur=i;
		while(cur)
		{
			int c=cur%10;
			if(ok[c]==1)
			{
				break;
			}
			cur/=10;
		}
		if(cur==0)
		{
			cout << i ;
			return ;
		}
	}
}

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T=1;
	while(T--)
	{
		solve();
	}
	return 0;
}


Measured memory_bytes: 3576
#include <bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define N 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))

int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    int l;
    cin >> l;
    double a = l/3.0;
    double b = a;
    double c = l-a-b;
    c = c*a*b;
    printf("%.10lf\n", c);
    return 0;
}






Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

#define int long long

int f(int x) {
	int ans = 0;
	while (x != 0) {
		ans++;
		x %= (__builtin_popcount(x));
	}
	return ans;
}


int bp(int a, int b, int m) {
	int res = 1;
	while (b) {
		if (b & 1) {
			res *= a;
			res %= m;
		}
		a *= a;
		a %= m;
		b >>= 1;
	}
	return res;
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	int n;
	cin >> n;
	string s;
	cin >> s;
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		cnt += (s[i] == '1');
	}
	int modplus = 0;
	int modmius = 0;
	for (int i = 0; i < n; i++) {
		modplus = (2 * modplus + (s[i] - '0')) % (cnt + 1);
		if (cnt > 1) modmius = (2 * modmius + (s[i] - '0')) % (cnt - 1);
	}
	for (int i = 0; i < n; i++) {
		if (s[i] == '0') {
			cout << 1 + f((modplus + bp(2, n - 1 - i, cnt + 1)) % (cnt + 1)) << '\n';
		} else {
			if (cnt == 1) {
				cout << 0 << '\n';
			} else {
				int v = modmius - bp(2, n - 1 - i, cnt - 1);
				v %= (cnt - 1);
				v += (cnt - 1);
				v %= (cnt - 1);
				cout << 1 + f(v) << '\n';
			}
		}
	}
}

Measured memory_bytes: 3776
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    string S;
    cin >> S;
    int l,r;
    rep(i,0,S.size()){
        if(S[i] == 'A'){
            l = i;
            break;
        }
    }
    for(int i = S.size()-1;i >= 0;i--){
        if(S[i] == 'Z'){
            r = i;
            break;
        }
    }
    cout << r - l + 1 << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl "\n"
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using ll = long long;
const int INF = 0x3f3f3f3f;
using namespace std;
const double PI = acos(-1);
const int N = 1e5+1;

int n;
ll h[200001], a[200001], mx;
ll dp[200001*4], ans[200001];

void update(int p, int l, int r, int i, ll v) {
    if (l==r) {
        dp[p] = v;
        return;
    }
    if (i <= (l+r)>>1) {
        update(p<<1, l, (l+r)>>1, i, v);
    } else {
        update((p<<1)+1, ((l+r)>>1)+1, r, i, v);
    }
    dp[p] = max(dp[p<<1], dp[(p<<1)+1]);
}

ll get(int p, int l, int r, int s, int e) {
    if (l >= s && r <= e) {
        return dp[p];
    }
    if (l > e || r < s) {
        return 0;
    }
    return max(get(p<<1, l, (l+r)>>1, s, e), get((p<<1)+1, ((l+r)>>1)+1, r, s, e));
}
int main() {
    //freopen("lazy.in", "r", stdin);
    IOS
    cin >> n;
    vector<pair<int, int>> v;
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        mx = max(mx, h[i]);
        v.emplace_back(h[i], i);
    }
    sort(v.begin(), v.end(), [](const pair<int, int>& a, const pair<int, int>& b) {
         if (a.first == b.first) {
            return b.second < a.second;
         }
         return a.first < b.first;
         });
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    ll ret = 0;
    for (int i = 0; i < n; ++i) {
        ans[v[i].second] = max(ans[v[i].second], get(1, 0, n-1, 0, v[i].second-1)+a[v[i].second]);
        update(1, 0, n-1, v[i].second, ans[v[i].second]);
        ret = max(ret, ans[v[i].second]);
    }

    cout << ret << endl;




    return 0;


}


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

int main() {
    ll n,r[200010],bottom=2000000000,top=0,ans=-9000000000;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> r[i];
    }

    for(int i=0;i<n;i++){
        if(r[i]>=top && i != 0){
            top = r[i];
            ans = max(top - bottom, ans);
        }
        if(r[i]<bottom){
            bottom = r[i];
            top = 0;
        }
    }

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


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

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

class Interval {
public:
    int s, t;
    Interval(int s=0, int t=0) : s(s), t(t) {}
    static int schedule(vector<Interval> v) {
        sort(v.begin(), v.end(), [](const Interval &a, const Interval &b) {
            return a.t < b.t || (a.t == b.t && a.s < b.s);
        });
        int t = -INT_MAX;
        vector<Interval> res;
        for (Interval i: v) {
            if (t <= i.s) {
                res.push_back(i);
                t = i.t;
            }
        }
        return (int)res.size();
    }
};

int main() {
    int N;
    cin >> N;
    vector<Interval> v;
    for (int i=0; i<N; ++i) {
        int X, L;
        cin >> X >> L;
        v.push_back(Interval(X-L, X+L));
    }
    cout << Interval::schedule(v) << endl;

    return 0;
}

Measured memory_bytes: 3316
# -*- coding: utf-8 -*-

import sys
import os
import math


dice0 = list(map(int, input().split()))
dice1 = list(map(int, input().split()))

def dice_roll(dice, c):
    copy = dice[:]
    if c == 'E':
        dice[2] = copy[0]
        dice[5] = copy[2]
        dice[3] = copy[5]
        dice[0] = copy[3]
    elif c == 'N':
        dice[0] = copy[1]
        dice[4] = copy[0]
        dice[5] = copy[4]
        dice[1] = copy[5]
        pass
    elif c == 'S':
        dice[1] = copy[0]
        dice[0] = copy[4]
        dice[4] = copy[5]
        dice[5] = copy[1]
    elif c == 'W':
        dice[0] = copy[2]
        dice[2] = copy[5]
        dice[5] = copy[3]
        dice[3] = copy[0]
    # Y???????????¢
    elif c == 'R':
        dice[2] = copy[1]
        dice[4] = copy[2]
        dice[3] = copy[4]
        dice[1] = copy[3]
    return dice


def check():
    global dice0
    global dice1

    # up???????????????
    num = 0
    while dice0[0] != dice1[0]:
        if num % 2 == 0:
            dice0 = dice_roll(dice0, 'E')
        else:
            dice0 = dice_roll(dice0, 'N')
        num += 1
        if num > 10:
            return False

    # front???????????????
    num = 0
    while dice0[1] != dice1[1]:
        dice0 = dice_roll(dice0, 'R')
        num += 1
        if num > 10:
            return False

    if dice0[2] == dice1[2] and dice0[3] == dice1[3] and dice0[4] == dice1[4] and dice0[5] == dice1[5]:
        return True
    else:
        return False

result = check()
if result:
    print('Yes')
else:
    # ????????????
    dice0 = dice_roll(dice0, 'N')
    result = check()
    if result:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 7940
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=3e5+10,oo=0x3f3f3f3f,MOD=998244353;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    int r,g,b,n;
    cin>>r>>g>>b>>n;
    int res=0;
    loop(n+1,i,0){
        loop(n+1,j,0){
            if(n-i*r-j*g<0)
                continue;
            int x=(n-i*r-j*g);
            if(x%b==0)
                res++;
        }
    }
    cout<<res<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


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

int main() {
  char c;
  cin >> c;
  if (c == 'a'||c == 'i'||c == 'u'||c == 'e'||c == 'o')
    cout << "vowel" << endl;
  else
    cout << "consonant" << endl;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;

const int inf = 1e9;

int n, k;
int id[maxn], L[maxn], R[maxn];
vector<int> g[maxn];

void dfs(int at, int p=0) {
    L[at]=-inf-1;
    R[at]=inf+1;
    if (id[at] != -inf) {
	L[at]=R[at]=id[at];
    }

    for (int to: g[at]) {
	if (to == p) continue;
	dfs(to, at);
	if (L[to] < -inf/2) continue; //`to` is leaf
	if (L[at] < -inf/2) {
	    L[at] = L[to]-1;
	    R[at] = R[to]+1;
	} else {
	    if (L[at]%2 == L[to]%2) out("No");
	    L[at] = max(L[at], L[to]-1);
	    R[at] = min(R[at], R[to]+1);
	}
    }
    if (L[at]>R[at]) out("No");
}

void make(int at, int p=0) {
    if (at==1 && id[at]==-inf) {
	id[at] = L[at];
    }
    
    for (int to: g[at]) {
	if (to == p) continue;
	if (id[to]==-inf) {
	    if (L[to]<=id[at]-1 && id[at]-1<=R[to]) {
		id[to]=id[at]-1;
	    } else if (L[to]<=id[at]+1 && id[at]+1<=R[to]) {
		id[to]=id[at]+1;
	    }
	}
	assert(id[to]!=-inf);
	assert(abs(id[to]-id[at])==1);
	make(to, at);
	
    }
}

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

    cin>>n;
    for (int i=0; i<n-1; i++) {
	int u,v; cin>>u>>v;
	g[u].push_back(v);
	g[v].push_back(u);
    }

    for (int i=1; i<=n; i++) {
	id[i] = -inf;
    }

    cin>>k;
    for (int i=0; i<k; i++) {
	int v,p;cin>>v>>p;
	id[v]=p;
    }

    dfs(1);

    make(1);

    cout<<"Yes\n";
    for (int i=1; i<=n; i++) {
	cout<<id[i]<<"\n";
    }

    return 0;
}


Measured memory_bytes: 39040
#include <stdio.h>

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = long long;
using ld = long double;

inline int gcd(int a, int b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);

  int k;
  cin >> k;
  ll ans = 0;
  for (int a = 1; a <= k; ++a) {
    for (int b = 1; b <= k; ++b) {
      for (int c = 1; c <= k; ++c) {
        ans += gcd(a, gcd(b, c));
      }
    }
  }
  cout << ans;
}


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

using namespace std;

typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define rInt(a) scanf("%d",&a);

main(){
    int n; scanf("%d",&n);
    vi arr (n);
    rep(i,n) scanf("%d",&arr[i]);
    sort(arr.begin(),arr.end());
    int great = arr[n-1];
    int l = great/2, r = great/2 + 1;
    if(n%2==0) r = l;
    int val = 1<<30, pos = 0;
    rep(i,n-1){
        if(abs(l-arr[i])<val or abs(r-arr[i])<val){
            pos = i;
            val = min(abs(l-arr[i]),abs(r-arr[i]));
        }
    }
    printf("%d %d\n",great,arr[pos]);
}

Measured memory_bytes: 640
/*
  author: ruruvuvu
  GitHub account: colon-ku

  created at: 2020-01-04 16:15:55
*/

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

#define all(x) (x).begin(),(x).end()
#define rep(x, y) for (int x = 0; x < y; x++)
#define MOD 1000000007

typedef long long LL;
typedef long double LD;

bool compare_by_b(pair<int, int> a, pair<int, int> b)
{
    if (a.second != b.second) {
        return a.second < b.second;
    } else {
        return a.first < b.first;
    }
}

ostringstream oss_global;
string s_global = oss_global.str();

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

    int ans = 0;
    for (int i = 1; i <= n; i += 2) {
        int cnt = 0;

        for (int j = 1; j <= i; j++) {
            if (i % j == 0) cnt++;
        }

        if (cnt == 8) ans++;
    }

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


Measured memory_bytes: 256
#include <cstdio>

int abs(int a) { return a<0?-a:a; }
int n, a[55];
int max_val = -1e9, max_idx;

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        if (max_val < abs(a[i])) {
            max_val = abs(a[i]);
            max_idx = i;
        }
    }

    printf("%d\n", 2*n-1);
    for (int i = 1; i <= n; i++) {
        a[i] += a[max_idx];
        printf("%d %d\n", max_idx, i);
    }
    if (a[max_idx] < 0) {
        for (int i = n; i >= 2; i--) {
            printf("%d %d\n", i, i-1);
        }
    }
    else {
        for (int i = 1; i <= n-1; i++) {
            printf("%d %d\n", i, i+1);
        }
    }

    return 0;
}

Measured memory_bytes: 128
import math

n, k = map(int, input().split())
sum_p = 0
for first_score in range(1,n+1):
    if first_score >= k:
        sum_p += 1/n
        continue
    sum_p += (1/n )*((1/2)**math.ceil(math.log2(k/first_score)))
print(sum_p)

Measured memory_bytes: 2940
N,M,K = list(map(int,input().split()))
A = list(map(int,input().split()))
B = list(map(int,input().split()))

sumA = [0] * (N+1)
sumB = [0] * (M+1)
for i in range(N):
    sumA[i+1] = sumA[i] + A[i]
for i in range(M):
    sumB[i+1] = sumB[i] + B[i]

ans = 0
import bisect
for i in range(N+1):
    if K - sumA[i] >= 0:
        idx = bisect.bisect_right(sumB,K-sumA[i])
        ans = max(ans,i + idx - 1)
#         print(idx-1)
print(ans)

Measured memory_bytes: 47540
#include <stdio.h>

int main(void){
  int A, B, i, count = 0, digit_A[5], digit_B[5];
  scanf("%d %d", &A, &B);
  for(i=0; i<5; i++){
    digit_A[i] = A % 10;
    A = A / 10;
    digit_B[i] = B % 10;
    B = B / 10;
  }
  count = (digit_B[4] - digit_A[4]) * 100 + 
          (digit_B[3] - digit_A[3] - 1) * 10 +
          9 - digit_A[2] + digit_B[2];
  if(digit_A[1] * 10 + digit_A[0] <= digit_A[3] * 10 + digit_A[4])
    count++;
  if(digit_B[1] * 10 + digit_B[0] >= digit_B[3] * 10 + digit_B[4])
    count++;
  printf("%d",count);
  return 0;
}

Measured memory_bytes: 1728
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
# from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var): sys.stdout.write(' '.join(map(str, var)) + '\n')
def out(var): sys.stdout.write(str(var) + '\n')
from decimal import Decimal
# from fractions import Fraction
# sys.setrecursionlimit(100000)
mod = 998244353
INF=float('inf')

n,k=mdata()
set1=set()
dp=[0]*(n)
s=[0]*n
lis=sorted([mdata() for i in range(k)],key=lambda x:x[0])
for i,j in lis:
    for m in range(i,j+1):
        set1.add(m)
m=lis[0][0]
for i in range(m,n):
    for j in range(k):
        if lis[j][0]>=i:
            break
        dp[i]+=s[i-lis[j][0]]-s[i-min(lis[j][1],i-1)-1]
    if i in set1:
        dp[i]+=1
    dp[i]%=mod
    s[i]=dp[i]+s[i-1]
out(dp[-1])

Measured memory_bytes: 43192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, N, B;
  cin >> N >> A;
 
  B = N % 500;
  
  if (A < B ) {
    cout << "No" << endl;
  }
  else 
  { cout << "Yes" << endl;
  }
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var x, n int
	fmt.Scan(&x, &n)
	
	p := make(map[int]bool)
	
	num := 0
	for i := 0; i < n; i++ {
		fmt.Scan(&num)
		p[num] = true
	}
	
	min := 101
	ans := 101
	for j := 101; j >= 0; j-- {
		if !p[j] {
			abs := Abs(x, j)
			if min >= abs {
				min = abs
				ans = j
			}
		}
	}
	fmt.Println(ans)
}

func Abs(num1, num2 int)int {
	if num1 < num2 {
		return num2 - num1
	}
	return num1 - num2
}


Measured memory_bytes: 1852
#include <stdio.h>
#define N 100
#define A 100

int main(){
  int a,b[N],i,j,minj,k,count=0;

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

  for(i=0;i<a;i++){

    minj = i;
    // printf("%d\n",i);

    for(j=i;j<a;j++){
      if(b[j] < b[minj]){
	minj = j;
      }
    }
    if(minj!=i){
      k = b[i];
      b[i] = b[minj];
      b[minj] = k;
      count++;
    }
  }
  for(k=0;k<a-1;k++)
  printf("%d ",b[k]);
  printf("%d",b[k]);
  printf("\n");
  printf("%d\n",count);
  


  
  return 0;
}
      
      
    



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

/* REPmacro */
#define REP(i,n) for(int i=0,i##_len=(n);i<i##_len;++i)
#define REPR(i,n) for(int i=((int)(n)-1);i>=0;--i)
#define FOR(i,m,n) for(int i=(int)(m);i<(int)(n);++i)

/*alias*/
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define PB push_back
#define MP make_pair 

#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev

/*using*/
using ll = long long;
using ull = unsigned long long;
using unsi = unsigned;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using db = double;
using plex = complex<double>;
using vs = vector<string>;

/*template*/
template<class T>inline bool amax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>inline bool amin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

/* func */
int gcd(int a,int b){return b?gcd(b,a%b):a;}

/*struct*/
struct aaa{
    aaa(){
        cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);
    };
}aaaaaaa;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7; //10^9
const db EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

//#define int ll
//#define int long long

signed main()
{
  //4$:cake 7$:donuts
  int check; cin >> check;
  int cnt = 0;
  int total = 0;
  
  for(int i = 0; i <= check/4; ++i){
    for(int j = 0; j <= check/7; ++j){
     total = 4*i+7*j;
     if(total == check) ++cnt;
    }
  }
  
  if(cnt > 0)
   cout << "Yes";
  else
   cout << "No";
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>

#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define VS vector<string>
#define VL vector<long long>
#define VI vector<int>
#define VVI vector<vector<int>>
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort(ALL(x))
#define RSORT(x) sort((x).rbegin(),(x).rend())
#define PAIR pair<ll,ll>
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

using  ll = long long;
constexpr int MOD = 1000000007;
using namespace std;

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

VL prime_decomposition(ll n) {
	ll i = 2;
	VL table{};
	while (i * i <= n) {
		while (n % i == 0) {
			n /= i;
			table.emplace_back(i);
		}
		++i;
	}
	if (n > 1) {
		table.emplace_back(n);
		return table;
	}
}

ll max(ll a, ll b) { return std::max(a, b); }

int main() {
	ll n, m;
	cin >> n >> m;
	if (n > 1) { n -= 2; }
	if (m > 1) { m -= 2; }

	cout << n*m << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main (String[] args){
    int a,b,S,R;
    Scanner scan =new Scanner(System.in);
    a=scan.nextInt();
    b=scan.nextInt();
    S=a*b;
    R=2*a+2*b;
    System.out.println(S+" "+R);



  }
}



Measured memory_bytes: 26272
#include <bits/stdc++.h>
using namespace std;
string s;
int main(void) {
    std::ios::sync_with_stdio(0);
    cin.tie(), cout.tie(0);
    int num[3];
    while(cin >> s) {
        num[0] = num[1] = num[2] = 0;
        for(int i = 0; s[i]; ++i)
            ++num[s[i] - 'a'];
        sort(num, num + 3);
        int a = num[2] - num[0];
        cout << (a <= 1 ? "YES" : "NO") << endl;
    }
}


Measured memory_bytes: 512
from sys import stdin
import fractions

N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]

lcm_a = int(A[0] * A[1]) // fractions.gcd(A[0], A[1])

if len(A) > 2:
    for k in A[2:]:
        lcm_a = int(lcm_a * k) // fractions.gcd(lcm_a, k)

modulo_sum = 0

for k in A:
    modulo_sum += (lcm_a - 1) % k

print(modulo_sum)


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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, tmp=0;
vector<vector<ll>> ans;

signed main(){
    cin >> N;    
    for(int i=1;i<=1000;i++) {
        if(i*(i+1)/2==N) {
            ans.resize(i+1);
            ll num = 1;
            for(int j1=0;j1<i;j1++) {
                for(int j2=j1+1;j2<i+1;j2++) {
                    ans[j1].push_back(num);
                    ans[j2].push_back(num);
                    num++;
                }
            }
            cout << "Yes" << endl;
            cout << i+1 << endl;
            for(int l=0;l<i+1;l++) {
                cout << i;
                for(int k=0;k<ans[l].size();k++) {
                    cout << " " << ans[l][k];
                }
                cout << endl;
            }
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(v) v.begin(),v.end()
#define len(x) (ll)(x).length()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll gcd(int a,int b){if(a%b==0){return b;}else{return(gcd(b,a%b));}}
ll lcm(int a,int b){return a*b/gcd(a,b);}
const int INF=1e9;
const ll INFS=1e18;
const int MOD=INF+7;
const int di[] = {-1,0,1,0};
const int dj[] = {0,-1,0,1};
const double PI=acos(-1);

int main() {     // 0 4 0 0 0 0 0
  int n;
  cin>>n;
  int cnt2=0,cnt4=0;
  rep(i,n){
    int a;
    cin>>a;
    if(a%2==0&&a%4!=0) cnt2++;
    if(a%4==0) cnt4++;
  }
  if(n%2==0){
    if(n/2<=cnt4){
      cout<<"Yes"<<endl;
      return 0;
    }
    if((n/2-cnt4)*2<=cnt2){
      cout<<"Yes"<<endl;
      return 0;
    }
    cout<<"No"<<endl;
    return 0;
  }
  if(n%2==1){
    if(n/2<=cnt4){
      cout<<"Yes"<<endl;
      return 0;
    }
    if((n/2-cnt4)*2+1<=cnt2){
      cout<<"Yes"<<endl;
      return 0;
    }
    cout<<"No"<<endl;
    return 0;
  }
}

Measured memory_bytes: 3644
#ライブラリの読み込み
import math

#入力値の格納
n = int(input())
numbers = input().split()

#変数の初期化
text = "APPROVED"

#計算
for i in numbers:
    if (int(i) % 2 == 0) and (int(i) % 3 != 0) and (int(i) % 5 != 0):
        text = "DENIED"
        break

#表示
print(text)


Measured memory_bytes: 2940
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
Max = sys.maxsize
def l():
	return list(map(int,input().split()))
def m():
	return map(int,input().split())
def s(x):
	a = []
	aa = x[0]
	su = 1
	for i in range(len(x)-1):
		if aa == x[i+1]:
			a.append([aa,su])
			aa = x[i+1]
			su = 1
		else:
			su += 1
	a.append([aa,su])
	return a
def jo(x):
	return " ".join(map(str,x))
n,m = m()


dp = [0 for i in range(n+1)]
dp[0] = 1
dp[1] = 1
k = []

for i in range(m):
	k = int(input())
	dp[k] = -1

for i in range(2,n+1):
	if dp[i] == -1:
		continue
	elif dp[i-1] == -1 and dp[i-2] == -1:
		continue
	elif dp[i-1] == -1:
		dp[i] += dp[i-2]
	elif dp[i-2] == -1:
		dp[i] += dp[i-1]
	else:
		dp[i] += dp[i-1] + dp[i-2]
print(dp[-1]%(10**9+7))

Measured memory_bytes: 470452
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
char c[500050];
int main()
{
    ll i,j,len;
    scanf("%s",c);
    len=strlen(c);
    ll ci=0;
    for(i=0;i<len;i++)
        ci+=c[i]-'0';
    if(ci%9==0)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}


Measured memory_bytes: 3740
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
A = []
B = []
C = []
for _ in range(N):
    a, b, c = map(int, input().split())
    A.append(a)
    B.append(b)
    C.append(c)

dp = [[0]*N for _ in range(3)]

dp[0][0] = A[0]
dp[1][0] = B[0]
dp[2][0] = C[0]

for i in range(1, N):
    dp[0][i] = max(dp[1][i-1], dp[2][i-1])+A[i]
    dp[1][i] = max(dp[2][i-1], dp[0][i-1])+B[i]
    dp[2][i] = max(dp[0][i-1], dp[1][i-1])+C[i]

ans = max(dp[0][-1], dp[1][-1], dp[2][-1])
print(ans)


Measured memory_bytes: 60252
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <unordered_map>
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;
using namespace std;
using LL = long long;

char maze[21][21];
bool ok[21][21];
int h, w;
int sx, sy;

void dfs(int hpos, int wpos) {
	ok[hpos][wpos] = true;
	maze[hpos][wpos] = '#';
	int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
	for (int i = 0; i < 4; i++) {
		int nx = wpos + dx[i], ny = hpos + dy[i];
		if (0 <= nx&&nx < w && 0 <= ny&&ny < h&&maze[ny][nx] == '.')dfs(ny, nx);
	}
}

int main() {
	while (cin >> w >> h&&w&&h) {
		for (int i = 0; i < 20; i++) {
			for (int j = 0; j < 20; j++) {
				ok[i][j] = false;
			}
		}
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				cin >> maze[i][j];
				if (maze[i][j] == '@')sx = j, sy = i;
			}
		}
		dfs(sy, sx);
		int ans = 0;
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (ok[i][j])ans++;
			}
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(n);++i)
#define per(i, n) for(int i=(n)-1;i>=0;--i)
#define repa(i, n) for(int i=1;i<(n);++i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
using namespace std;
using ll = long long;
const ll MOD = (ll)1e9+7;
//const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}

#ifdef DEBUG
#define OUTPUT(x) (output(x), outendl())
#else
#define OUTPUT(x) (void)0
#endif

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

ll modinv(ll x){
	return modpow(x, MOD-2);
}

bool was_output = false;
template<class t>
void output(t a){
	if(was_output)cout << " ";
	cout << a;
	was_output = true;
}
void outendl(){
	was_output = false;
	cout << endl;
}

int n;
vector<int> hotel;
vector<ll> sum;
int l;

vvector<int> dp;

int func(int place, int remain){
	if(place==n+1)return n+1;
	if(dp[place][remain]>=0)return dp[place][remain];
	if(remain>0){
		return dp[place][remain] = func(func(place, remain-1), remain-1);
	}
	int p = upper_bound(all(sum), sum[place]+l) - sum.begin() - 1;
	return dp[place][remain] = p;
}

int main(){
	cin >> n;
	hotel.resize(n);
	sum.resize(n+2);
	rep(i, n){
		cin >> hotel[i];
		sum[i+1] = hotel[i];
	}
	sum[0] = 0;
	sum[n+1] = INFLL;
	dp.resize(n+4, vector<int>(30, -1));
	cin >> l;
	int q;
	cin >> q;
	rep(i, q){
		int a, b;
		cin >> a >> b;
		if(a>b)swap(a, b);
		int ans = 0;
		per(j, 29){
			if(func(a, j)>=b)continue;
			a = func(a, j);
			ans += bit(j);
		}
		if(a!=b)++ans;
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 16896
#include<stdio.h>
int main()
{
	int n,x,y,cnt,i;
	scanf("%d",&n);
	x=0;
	cnt=0;
	for(i=1;i<=n;i++){
		x=i;
		y=0;
		while(x!=0){
			x/=10;
			y++;
		}
		if(y%2!=0){
			cnt++;
		}
	}
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int henkan(string);
int main(){
	bool *dictionary;
	dictionary=new bool[henkan("TTTTTTTTTTTT")];
	for(int i=0;i<sizeof(dictionary)/sizeof(bool);++i){
		dictionary[i]=false;
	}
	int n;
	cin>>n;
	string code,word;
	for(int i=0;i<n;++i){
		cin>>code>>word;
		if(code[0]=='i'){
			dictionary[henkan(word)]=true;
		}else{
			if(dictionary[henkan(word)]==true)cout<<"yes"<<endl;
			else cout<<"no"<<endl;
		}
	}
	return 0;
}

int henkan(string str){
	int a=0;
	switch(str[0]){
		case 'A':
			a+=1;
			break;
		case 'C':
			a+=2;
			break;
		case 'G':
			a+=3;
			break;
		case 'T':
			a+=4;
			break;
	}
	a*=5;
	for(int i=1;i<str.size();++i){
		switch(str[i]){
		case 'A':
			a+=1;
			break;
		case 'C':
			a+=2;
			break;
		case 'G':
			a+=3;
			break;
		case 'T':
			a+=4;
			break;
		}
		a*=5;
	}
	return a;
}

Measured memory_bytes: 24000
#include<stdio.h>
#include<string.h>
#define LEN 100005

typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
int head, tail, n;

void enqueue(P x){
  Q[tail]=x;
  if(tail+1==100000){
    tail=0;
  }
  else tail++;
}

P dequeue(){
  P x;
  x=Q[head];
  if(head+1==100000){
    head=0;
  }
  else head++;
  return x;
}


int main(){
  int elaps = 0, c;
  int i, q;
  P u;
  scanf("%d %d", &n, &q);

  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
    enqueue(Q[i]);
  }
 
while(head!=tail){
    u=dequeue();
 
    if(q<u.t){
      elaps=elaps+q;
      u.t=u.t-q;
      enqueue(u);
    }
    else {
      elaps=elaps+u.t;
      u.t=elaps;
    
      printf("%s %d\n",u.name,u.t);
       
    }
  }
  
  return 0;
}

Measured memory_bytes: 10756
#include <bits/stdc++.h>
#define int long long
#define ll long long 
#define rep(i,a,b) for(signed i=a;i<(b);++i)
#define erep(i,a,b) for(signed i=a;i<=(b);++i)
#define per(i,a,b) for(signed i=(a);i>(b);--i)
#define eper(i,a,b) for(signed i=(a);i>=b;--i)
#define fore(i, x, a) for(auto &&x:a) 
#define ITR(i,b,e) for(auto i=(b);i!=(e);++i)
#define pb push_back
#define mp make_pair
#define ALL(x) begin(x),end(x)
#define F first
#define S second
#define debug(x)  cout << #x << ": " << (x) << '\n';
const long long INF=1001001001001001001;
const int MOD=(int)1e9 + 7;
const double EPS=1e-9;
using namespace std;
using Pii = pair<int,int>;
using vii = vector<int>;
template<class T>using  PS_queue = priority_queue<T, vector<T>, greater<T> >;
template<class T>using vv = vector<T>;
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; }
template<typename A, size_t N, typename T> void Fill(A (&array)[N], const T &val){fill( (T*)array, (T*)(array+N), val );}
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    ITR(i,begin(v),end(v))os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    ITR(i,begin(v),end(v)) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T>T gcd(T a, T b){ return b ? gcd(b, a % b) : a; }
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct edge { int from, to, cost; };
int dy[]={0, 1, -1, 0}; int dx[]={1, 0, 0, -1};
// cout << fixed;
// cout << setprecision(10) << val;

int n, k;
signed main() {
 cin.tie(0);
 ios::sync_with_stdio(false);
  cin >> n >> k;
  vv<Pii> sushi;
  PS_queue<int> que;
  stack<int> dup;
  set<int> S;
  rep(i, 0, n) {
    int t, d;
    cin >> t >> d;
    sushi.pb({d, t});
  }
  sort(ALL(sushi), greater<Pii>());
  int ans = 0, sum = 0, kind = 0;
  rep(i, 0, k) {
    sum += sushi[i].F;
    if (S.count(sushi[i].S)) {
      dup.push(sushi[i].F);
    } else {
      kind++;
      S.insert(sushi[i].S);
    }
  }
  ans = sum + kind * kind;
  rep(i, k, n) {
    if (dup.empty()) {
      break;
    }
    if (S.count(sushi[i].S) == 0) {
      sum -= dup.top(); 
      dup.pop();
      kind++;
      sum += sushi[i].F;
      S.insert(sushi[i].S);
      chmax(ans, sum + kind * kind);
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main(){
  int A,B,C,D,E;
  cin >> A >> B >> C >> D >> E;
if(A <= 0){
  cout << 1 << endl;
}
  if(B <= 0){
  cout << 2 << endl;
}
  if(C <= 0){
  cout << 3 << endl;
}
  if(D <= 0){
  cout << 4 << endl;
}
  if(E <= 0){
  cout << 5 << endl;
}
}


Measured memory_bytes: 3620
use std::io::stdin;
use std::str::FromStr;
use std::cmp::min;

fn main(){
    let _: usize = get_one();
    let xs: Vec<i64> = get_vec();

    let ans1 = solve(&xs);
    let ans2 = solve(&(xs.iter().map(|&x| -x).collect()));

    println!("{}", min(ans1, ans2));
}

fn solve(xs: &Vec<i64>) -> i64 {
    let mut acc = 0;
    let mut ans = 0;

    for i in 0..xs.len() {
        acc += xs[i];
        if acc * (1 - 2*(i%2) as i64) <= 0 {
            ans += (1 - 2*(i%2) as i64 - acc).abs();
            acc = 1 - 2*(i%2) as i64;
        }
    }

    ans
}

#[allow(dead_code)]
fn get_line() -> String {
    let mut s = String::new();
    match stdin().read_line(&mut s){
        Ok(_) => {s.trim().to_string()}
        Err(_) => String::new()
    }
}

#[allow(dead_code)]
fn get_vec<T: std::str::FromStr>() -> Vec<T> {
    let line = get_line();
    line.split_whitespace().filter_map(|x| x.parse().ok()).collect()
}

#[allow(dead_code)]
fn get_one<T: FromStr + Copy>() -> T {
    let v = get_vec();
    v[0]
}

#[allow(dead_code)]
fn get_pair<T: FromStr + Copy>() -> (T, T) {
    let v = get_vec();
    (v[0], v[1])
}

#[allow(dead_code)]
fn get_triple<T: FromStr + Copy>() -> (T, T, T) {
    let v = get_vec();
    (v[0], v[1], v[2])
}

#[allow(dead_code)]
fn get_chars() -> Vec<char> {
    get_line().chars().collect()
}


Measured memory_bytes: 8444
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long int
#define loop(i,a,b)           for(ll i=a;i<=b;++i)
#define pb                    push_back
#define F                     first
#define S                     second
#define mp                    make_pair
#define clr(x)                x.clear()
#define MOD                   1000000007
#define itoc(c)               ((char)(((int)'0')+c))
#define vl                    vector<ll>
#define SZ(x)                 (x).size()
#define all(p)                p.begin(),p.end()
#define mid(s,e)              (s+(e-s)/2)
#define sv()                  ll t,n; scanf("%lld",&t);n=t; while(t--)
#define tcase()               ll t,n; cin>>t;n=t; while(t--)
#define iscn(num)             scanf("%d",&num);
#define scn(num)              scanf("%lld",&num);
#define scn2(num,num2)        scanf("%lld%lld",&num,&num2);
#define dbg(x)                cerr <<"( "<<#x << " = " << x << " )"<<endl
using namespace std;
const ll INF = 2e18 + 99;
typedef pair<ll,ll> Pair;
typedef vector<ll> vec;;
void FAST_IO();
void ara_read(vec &v,ll n);
////////////////////////

int main()
{
	ll n, knapsack ;
	scanf("%lld%lld",&n,&knapsack);
	/* now in this problem knapsack size is huge,
	 * so we can't use it as dp dimension. but here now value 
	 * is kinda small , we can this as dp dimension..
	 * we will use raw swapping to solve this dp problem */
	ll nax = n* 1000 + 10;
	vector< vector<ll > > dp(2,vector<ll> (nax,INF));
	bool prev=0, next =1;
	dp[0][0]=0 ;
	ll w, v ;
	
	for(int i=0 ; i < n ; i++){
		scanf("%lld%lld",&w,&v);
		for(int value =0 ; value < nax ; ++value){
			if(value<v){
				dp[next][value]= dp[prev][value];
			}else{
				dp[next][value]= min(dp[prev][value],dp[prev][value-v]+ w);
				
			}
		}
		swap(prev, next);
	}
	cerr << knapsack << endl;
	ll ans =0 ;
	for (int x = 0 ; x < nax ; ++x){
		if(dp[prev][x] <= knapsack){
			ans = x ;
			
		}
	}
	
	printf("%lld\n",ans);
    return 0;
}

void FAST_IO()
{
    // ios_base::sync_with_stdio(0);
    //cin.tie(NULL);
    //cout.tie(NULL);
    //cout.setf(ios::fixed);
    //cout.precision(2);

}
void ara_read(vec &v,ll n){
	ll temp;
	for(ll i=0; i<n; i++){
		scanf("%lld",&temp);
		v.emplace_back(temp);
	}
	
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
using ll = long long;
const int inf = 1e9;  // 1(1倍)e(指数)9(10^9)
int main() {
    int n, k;
    scanf("%d%d", &n, &k);
    vector<ll> x(n);
    rep(i, n) scanf("%lld", &x[i]);

    // 単純に考えれば選ぶのは原点から近いもの。また、選ぶろうそくの間を開けるのは明らかに非効率です。よって、原点を含む連続したK本のろうそくの選び方のうち、一番短いものはどれか。原点0からスタートして計算する、というのは忘れる。絶対値の長さだけ考える。
    ll ans = inf;
    for (int i = 0; i + k - 1 < n; ++i) {
        ll left = x[i], right = x[i + k - 1];
        // 左端と右端が原点をまたぐ場合がある。その場合、原点から距離が短い方から先に計算すると、絶対値を最小にできる。 min(abs(left), abs(right))
        ans = min(ans, min(abs(left), abs(right)) + right - left);
    }

    printf("%lld\n", ans);
    return 0;
}


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

using namespace std;

//using Matrix = vector< vector<int> >;
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1 << 30;
int dx[5] = {0, 0, 1, -1, 0}, dy[5] = {1, -1, 0, 0, 0};
bool cmp(P a, P b) { return a.second < b.second; } //End sort (Interval scheduling problem)

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

ll n, x;

int main(void){
	cin>>n>>x;

	cout<< 3 * (n - gcd(n, x)) <<endl;
	
	return 0;
}

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

int main()
{
    string T;
    cin >> T;
    if(T.at(0)=='?')
    {
        T.at(0)='D';
    }
    if(T.at(T.size()-1)=='?')
    {
        T.at(T.size()-1)='D';
    }
    for(int i=1;i<T.size()-1;i++)
    {
        if(T.at(i)=='?')
        {
            if((T.at(i-1))=='P')
            {
                T.at(i)='D';
            }
            if((T.at(i-1))=='D')
            {
                if(T.at(i+1)=='P')
                {
                    T.at(i)='D';
                }
                else
                {
                    T.at(i)='P';
                } 
            }
            
        }
    }
    cout << T << endl;
}

Measured memory_bytes: 3752
import heapq
n=int(input())
a=list(map(int,input().split()))

zero_count=0
minus_count=0
for i in range(n):
    if a[i]<0:
        minus_count+=1
    if a[i]==0:
        zero_count+=1
        break

for i in range(n):
    a[i]=abs(a[i])

if zero_count==1 or minus_count%2==0:
    ans=sum(a)
else:
    heapq.heapify(a)
    mn=heapq.heappop(a)
    ans=sum(a)-mn

print(ans)


Measured memory_bytes: 20288
#include <iostream>
using namespace std;
int main(){
string s;
cin>>s;
for(int i=0;i<5;++i){
cout<<s[i];
}
cout<<" ";
for(int i=6;i<13;++i){
cout<<s[i];
}
cout<<" ";
for(int i=14;i<19;++i){
cout<<s[i];
}}

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


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long long n,a,b;
    cin >> n >> a >> b;
    long long ans=a*(n/(a+b));
    ans+=min(a,n%(a+b));
    cout << ans << "\n";

    
}    


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

int main() {
  string s;
  int result=0;
  cin >> s ;
  if(s[0]=='1'){result++;}
  if(s[1]=='1'){result++;}
  if(s[2]=='1'){result++;}  
  cout << result << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
//pair<> p;

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> vec;
  for(int i = 1;i<=n;i++){
    int a;
    cin >> a;
    pair<int,int> pa = make_pair(a,i);
    vec.push_back(pa);
  }
  sort(vec.begin(),vec.end());
  for(int i = 0;i<n;i++){
    cout << vec[i].second << endl;
  }
  
}


Measured memory_bytes: 1780
#!/usr/bin/env -S JULIA_VERSION=1.4.0 julia
# contest: abc165, problem: abc165_a, alphabet: A
const YES = "OK"
macro Y() :( println(YES); return ) end
const NO = "NG"
macro N() :( println(NO); return ) end

function solve(K::Int, A::Int, B::Int)
  for i in A:B
    i % K==0 && @Y
  end
  @N
end

function main()
  tokens = Channel{String}(32)
  Task() do
    for line in eachline(@static VERSION < v"0.6" ? STDIN : stdin)
      startswith(line, '\0') && break
      for token in split(chomp(line))
        put!(tokens, token)
      end
    end
    close(tokens)
  end |> schedule
  K = parse(Int, take!(tokens))
  A = parse(Int, take!(tokens))
  B = parse(Int, take!(tokens))
  solve(K, A, B)
end

if isempty(get(ENV, "ATCODER_LOCAL", ""))
  isempty(ARGS) && main()
else
  @eval begin
    const samples = [("7\n500 600", "OK"), ("4\n5 7", "NG"), ("1\n11 11", "OK")]
    function test(sampleids...)
      isempty(sampleids) && return test(collect(1:length(samples))...)
      ostdin, ostdout = @static VERSION < v"0.6" ? (STDIN, STDOUT) : (stdin, stdout)
      rd, wr = first(redirect_stdout()), last(redirect_stdin())
      try
        map(sampleids) do sampleid
          input, output = samples[sampleid]
          print(ostdout, "Testing sample #$(sampleid)..."); flush(ostdout)
          println(wr, input)
          println(wr, "\0")
          t = @elapsed main()
          println()
          result = strip(String(readavailable(rd)))
          if result == output
            println(ostdout, "OK ($t sec).")
            true
          else
            println(ostdout, "ERROR ($t sec)")
            println(ostdout, "== expected ==\n$output")
            println(ostdout, "== actual ==\n$result\n")
            false
          end
        end |> all
      finally
        redirect_stdin(ostdin)
        redirect_stdout(ostdout)
      end
    end
    submit() = test() && (program=@__FILE__; run(`echo atcoder-submit $program`))
    !isinteractive() && submit()
  end
end


Measured memory_bytes: 179596