akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
using namespace std;
#define i64  long long
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000

// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){std::cout << e << std::endl;}
template<class T> void DEBUG(string str, T e){std::cout <<str << ">>" << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ DEBUG(v); } }
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template<typename T> void SORT_(std::vector<T>& v,bool GREATER = 0){if(GREATER == 0)sort(v.begin(),v.end());else{sort(v.begin(),v.end(),std::greater<T>());}}

void solve(void)
{
  int N;
  cin>>N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  
  for (int i = 0; i < N-1; i++)
  {
    vec[i+1] += vec[i];
  }
  vec.insert(vec.begin(),0);
  int ANS = INF;
  for (int i = 1; i < N; i++)
  {
    ANS = min(ANS,abs(vec[N]-vec[i] - vec[i]));
  }
  cout<<ANS<<endl;
    
  
  
  
  
  
  return; 
}


int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

 
  return 0;
}

Measured memory_bytes: 4224
import sys
#import string
from collections import defaultdict, deque, Counter
#import bisect
#import heapq
#import math
#from itertools import accumulate
#from itertools import permutations as perm
#from itertools import combinations as comb
#from itertools import combinations_with_replacement as combr
#from fractions import gcd
#import numpy as np

stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
MIN = -10 ** 9
MOD = 10 ** 9 + 7
INF = float("inf")
IINF = 10 ** 18

def solve():
    n = int(stdin.readline().rstrip())
    #A, B, C = map(int, stdin.readline().rstrip().split())
    #l = list(map(int, stdin.readline().rstrip().split()))
    #numbers = [[int(c) for c in l.strip().split()] for l in sys.stdin]
    word = [stdin.readline().rstrip() for _ in range(n)]
    #number = [[int(c) for c in stdin.readline().rstrip()] for _ in range(n)]
    #zeros = [[0] * w for i in range(h)]
    c = Counter(word)
    ac = c["AC"]
    wa = c["WA"]
    tle = c["TLE"]
    re = c["RE"]
    print("AC x "+str(ac))
    print("WA x "+str(wa))
    print("TLE x "+str(tle))
    print("RE x "+str(re))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 16612
#include<bits/stdc++.h>
using namespace std;
#define endl '\n'

int main(int argc, char const *argv[]) {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(0);
    long long n,a,b;
    cin>>n>>a>>b;
    cout<<(n/(a+b)*a+min(a,n%(a+b)));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

// <arr[0]> <arr[1]> .. <arr[size-1]>
int fget_array(char *arr, int size) {
    int i;
    for(i = 0; i < size; i++) {
        int n;
        scanf("%d", &n);
        arr[i] = n;
    }
    return 0;
}

#define ROW_MAX 500
#define COL_MAX 500
struct point2d {
    int row;
    int col;
};

static struct point2d stack[ROW_MAX*COL_MAX];
static int sidx = 0;
struct point2d pop(void) {
    return stack[--sidx];
}
void push(struct point2d p) {
    stack[sidx++] = p;
}

#define ANS_MAX (ROW_MAX*COL_MAX+50)
struct operation {
    struct point2d cur;
    struct point2d next;
};

int dir4[][2] = {
    {1, 0},
    {0, 1},
};


int main(void) {
    int rs, cs;
    get_int2(&rs, &cs);
    static char map[ROW_MAX+2][COL_MAX+2];
    memset(map, 0xff, (ROW_MAX+2)*(COL_MAX+2));
    int i, j, k;
    for(i = 1; i <= rs; i++) {
        fget_array(&map[i][1], cs);
    }

    int oidx = 0;
    static struct operation ops[ANS_MAX];
    // make coins rightbottom
    for(i = 1; i <= rs; i++) {
        for(j = 1; j <= cs; j++) {
            struct point2d p = {i, j};
            if(!(map[i][j]%2)) continue;
            for(k = 0; k < 2; k++) {
                struct point2d np = {i+dir4[k][0], j+dir4[k][1]};
                if(!map[p.row][p.col]) continue;
                if(map[np.row][np.col] < 0) continue;;
                ops[oidx++] = (struct operation){ p, np };
                map[p.row][p.col] -= 1;
                map[np.row][np.col] += 1;
                break;
            }
        }
    }

    printf("%d\n", oidx);
    for(i = 0; i < oidx; i++) {
        printf("%d %d %d %d\n",
            ops[i].cur.row, ops[i].cur.col,
            ops[i].next.row, ops[i].next.col
        );
    }

    return 0;

}

Measured memory_bytes: 6144
#include <algorithm>
#include <iostream>
#include <set>
#include <vector>

using namespace std;

typedef long long ll;

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

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

int solve(const vector<pair<int, int>> &sc, const int N, const int M) {
    for (int cand = 0; cand < 1000; cand++) {
        int x = cand;
        vector<int> digits;
        digits.push_back(x % 10);
        x /= 10;
        while (x) {
            digits.push_back(x % 10);
            x /= 10;
        }
        reverse(digits.begin(), digits.end());

        if ((int) digits.size() != N) {
            continue;
        }

        bool ok = true;
        for (auto &p : sc) {
            if (digits[p.first] != p.second) {
                ok = false;
                break;
            }
        }

        if (ok) {
            return cand;
        }
    }
    return -1;
}

// based on solution 1 in pdf.
// ref. https://img.atcoder.jp/abc157/editorial.pdf
int main(void) {
    int N, M;
    cin >> N >> M;
    
    vector<pair<int, int>> sc(M);
    for (int i = 0; i < M; i++) {
        int s, c;
        cin >> s >> c;
        s--;
        sc[i] = {s, c};
    }

    cout << solve(sc, N, M) << endl;
    
    return 0;
}


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


int main(){
  int n,k,q;
  cin>>n>>k>>q;
  vector<int>a(q);
  for(int i=0;i<q;i++)cin>>a[i];
  vector<int>score(n,k-q);
  for(int i=0;i<q;i++){
    score[a[i]-1]++;
  }
  for(int i=0;i<n;i++){
    if(score[i]>=1)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
  }
}
    

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s;
  cin >> s;
  int ans = 0;
  for (char c : s) if (c == '1') ans++;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int k;
    string s;
    cin >> k >> s;
    cout << s.substr(0, k);
    if (k < s.size()) cout << "...";
    return 0;
}


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

int main()
{
	int i;
	char cc;
	int A, B, M;
	int *a, *b, *c, *x, *y;
	scanf("%d %d %d", &A, &B, &M);
	a = (int *) malloc(sizeof(int) * A);
	b = (int *) malloc(sizeof(int) * B);
	x = (int *) malloc(sizeof(int) * M);
	y = (int *) malloc(sizeof(int) * M);
	c = (int *) malloc(sizeof(int) * M);


	
	int ma, mb, mx;
	ma = -1;
	mb = -1;
	mx = -1;
	
	for(i = 0; i < A; i++)
	{
		scanf("%d", a + i);
		if(ma > a[i] || ma == -1)
			ma = a[i];
	}
	
	
	
	for(i = 0; i < B; i++)
	{
		scanf("%d", b + i);
		if(mb > b[i] || mb == -1)
			mb = b[i];
	}
	
	
	
	for(i = 0; i < M; i++)
	{
		scanf("%d %d %d", x + i, y + i, c + i);
		if(mx > a[x[i] - 1] + b[y[i] - 1] - c[i] || mx == -1)
			mx = a[x[i] - 1] + b[y[i] - 1] - c[i];
	}
	
	if(ma + mb < mx)
		printf("%d", ma + mb);
	else
		printf("%d", mx);
	
}

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

int main() {
    double x1, y1;
    double x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;

    double x = abs(x1 - x2);
    double y = abs(y1 - y2);

    double dist = sqrt(x*x + y*y);

    printf("%.4f\n", dist);
    return 0;
}


Measured memory_bytes: 3292
#include<stdio.h>

int main(){

    int person;
    int high_restrict;
    int permit = 0;

    scanf("%d%d\n",&person,&high_restrict);
    int high_array[person];
    for(int i = 0; i < sizeof(high_array)/sizeof(int); i++){
        scanf("%d\n",&high_array[i]);
        if(high_restrict <= high_array[i]){
            permit++;
        }
    }
    printf("%d\n",permit);
    return 0;
}

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

long long dp[101][100001];

long long knapsack(long long w,long long* wt,long long* val,long long n)
{
	if(n==0||w==0)
	return 0;
	
	if(dp[n][w]!=-1)
	return dp[n][w];
	
	
	if(wt[n-1]<=w)
		return dp[n][w]= max(val[n-1]+knapsack(w-wt[n-1],wt,val,n-1),knapsack(w,wt,val,n-1));
	
	
	
	
	else if(wt[n-1]>w)
	return dp[n][w]= knapsack(w,wt,val,n-1);

}
int main() {
	// your code goes here
	
	memset(dp,-1,sizeof(dp));
	
	long long n,w;
	
	cin>>n>>w;
	
	long long wt[n];
	
	long long val[n];
	
	for(long long i=0;i<n;i++)
	{
		cin>>wt[i]>>val[i];
	}
	
	long long ans=knapsack(w,wt,val,n);
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 79104
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define PB push_back

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'[';
  REP(i, a.size()) {out<<a[i];if(i!=a.size()-1)out<<',';}
  out<<']';
  return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

const int MAX_N = 300;
struct edge {int to, cap, rev;};
vector<edge> G[MAX_N+1];
bool used[MAX_N+1];

void add_edge(int from, int to, int cap) {
  G[from].push_back((edge){to, cap, (int)G[to].size()});
  G[to].push_back((edge){from, 0, (int)G[from].size()-1});
}

int dfs(int v, int t, int f) {
  if(v == t) return f;
  used[v] = true;
  REP(i, G[v].size()) {
    edge &e = G[v][i];
    if(!used[e.to] && e.cap > 0) {
      int d = dfs(e.to, t, min(f, e.cap));
      if(d > 0) {
        e.cap -= d;
        G[e.to][e.rev].cap += d;
        return d;
      }
    }
  }
  return 0;
}

int max_flow(int s, int t) {
  int flow = 0;
  while(true) {
    memset(used, 0, sizeof(used));
    int f = dfs(s, t, INF);
    if(f == 0) return flow;
    flow += f;
  }
}

int g[305][305];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  int n, m, s, t;
  cin >> n >> m;
  REP(i, m) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    g[y][x] = i+1;
    add_edge(x, y, 1);
    add_edge(y, x, 1);
  }
  cin >> s >> t;
  s--, t--;

  cout << max_flow(s, t) << endl;
  VI ans;
  REP(i, n) {
    for(edge e: G[i]) {
      // i->e.toの辺について
      if(e.cap == 0 && G[e.to][e.rev].cap == 1) {
        if(g[i][e.to]) {
          ans.PB(g[i][e.to]);
        }
      }
    }
  }
  sort(ALL(ans));
  ans.erase(unique(ALL(ans)), ans.end());
  cout << ans.size() << endl;
  for(int i: ans) cout << i << endl;

  return 0;
}



Measured memory_bytes: 4100
N,M = map(int,input().split())
PS = [list(input().split()) for i in range(M)]
PS = [[int(PS[i][0])-1,PS[i][1]] for i in range(M)]
AC = [0]*N
WA = [0]*N

for i in range(M):
    # print(PS[i][0])
    if AC[PS[i][0]] == 0:
        if PS[i][1] == "AC":
            AC[PS[i][0]] = 1
        else:
            WA[PS[i][0]] += 1
        # print(AC,WA)
w = 0
for i in range(N):
    if AC[i] == 1:
        w += WA[i]
print(sum(AC),w)

Measured memory_bytes: 39368
/**Bismillahir Rahmanir Raheem
    Author:Refatul Fahad**/

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

#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pb push_back
#define vi vector<int>
#define pii pair<int,int>
#define pil pair<int,ll>
const int N = 1e5 + 5;
const ll M = (ll)1e9 + 7;
const double pi=2*acos(0.0);
const double esp=1e-9;
int Set(int N,int pos) {
    return N=N | (1<<pos);
}
int reset(int N,int pos) {
    return N= N & ~(1<<pos);
}
bool check(int N,int pos) {
    return (bool)(N & (1<<pos));
}

int dx[]= {0,0,1,-1};
int dy[]= {1,-1,0,0};

vector<ll> ar,br;
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    /// freopen("input.txt","r",stdin);
    /// freopen("output.txt","w",stdout);

    int test=1;
    //cin>>test;
    for(int cs=1; cs<=test; ++cs) {
        int n,m,k,ans=0;

        br.pb(0ll);
        ar.pb(0ll);
        cin>>n>>m>>k;
        for(int i=1; i<=n; ++i) {
            ll x;
            cin>>x;
            ar.pb(x);
        }
        for(int i=1; i<=m; ++i) {
            ll x;
            cin>>x;
            br.pb(x);
        }
        for(int i=1; i<=n; ++i) {
            ar[i]+=ar[i-1];
        }
        for(int i=1; i<=m; ++i) {
            br[i]+=br[i-1];
        }
        for(int i=0; i<=n; ++i) {
            if(ar[i]>k)continue;
            int pos=upper_bound(br.begin(),br.end(),k-ar[i])-br.begin();
            //cout<<pos<<" ";
            ans=max(ans,i+pos-1);
        }
        cout<<ans<<endl;
    }
    return 0;
}



Measured memory_bytes: 7932
/*
[ ( ^ _ ^ ) ]
*/

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    int n;
    ArrayList<ArrayList<Integer>> g;
    boolean[] vis;
    int[] l;

    int go(int v) {
        if(vis[v]) {
            return l[v];
        }
        int rs = 0;
        vis[v] = true;
        for(int u: g.get(v)) {
            rs = Math.max(rs, go(u)+1);
        }
        l[v] = rs;
        return rs;
    }

    void solve(InputReader in, PrintWriter out) throws IOException {
        n = in.nextInt();
        int m = in.nextInt();
        g = new ArrayList<ArrayList<Integer>>();
        for(int i=0; i<n; i++) {
            g.add(new ArrayList<Integer>());
        }
        for(int i=0; i<m; i++) {
            int x = in.nextInt()-1;
            int y = in.nextInt()-1;
            g.get(x).add(y);
            // g.get(y).add(x);
        }
        vis = new boolean[n];
        l = new int[n];
        int rs = 0;
        for(int i=0; i<n; i++) {
            if(!vis[i]) {
                rs = Math.max(rs, go(i));
            }
        }
        out.println(rs);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

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

using namespace std;

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

int main()
{
  int n;
  cin >> n;
  vector<ll> v(n, 0);
  for (int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());
  cout << v[n-1] << ' ';
  // v.erase(v.begin() + n - 1);
  // for(ll i : v)
  //   cout << i << endl;

  ll minv = INT_MAX;
  int tmp;
  for (int i = 0; i < n-1; i++){
    // cout << abs((v[n-1]+1)/2 - v[i]) << endl;
    if (abs((v[n-1]+1)/2 - v[i]) <= minv) {
      minv = abs((v[n-1]+1)/2 - v[i]);
      tmp = i;
    }
  }
  cout << v[tmp] << endl;
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int main()
{
	int n = 3;
	int sum=0;
	vector<int>vec(n);
	
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	for (int i = 0; i < n; i++) {
		sum += vec.at(i);
	}
	if (sum >= 22) {
		cout << "bust" << endl;
	}
	else {
		cout << "win" << endl;
	}
}



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

int main()
{
	bool flag = false;
	string s1;
	cin >> s1;

	for (int i = 0; i < s1.size(); i++)
	{
		for (int j = i + 1; j < s1.size(); j++)
		{
			if (s1[i] == s1[j]) flag = true;
		}
	}
	if (!flag) cout << "yes" << endl;
	else cout << "no" << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())

lst = [1] * n
for i in range(2, n+1):
  counter = 1
  while i * counter <= n:
    lst[i*counter - 1] += 1
    counter += 1

ans = 0
for i in range(n):
  ans += lst[i] * (i + 1)
print(ans)


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

template<class T> inline void chmin(T& a, T b) {if (a > b) a = b;}
template<class T> inline void chmax(T& a, T b) {if (a < b) a = b;}

ll const mod = 1e9+7;

int main() {
  int N,M,a,b;
  cin >> N >> M;
  vector<ll> H(N);
  vector<bool> memo(N,true);
  rep(i,N) {
    cin >> H[i];
  }
  rep(i,M) {
    cin >> a >> b;
    a--;b--;
    if (H[a]>=H[b]) memo[b] = false;
    if (H[a]<=H[b]) memo[a] = false;
  }
  int cnt=0;
  rep(i,N) {
    if (memo[i]) cnt++;
  }
  cout << cnt << endl;
}

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

int main() {
  int n,m,total=0,ans=0;
  cin >> n >> m;
  vector<int> vec(n);
  for(int i=0; i<n; i++) {
    cin >> vec[i];
    total += vec[i];
  }
  double flag = total/4.0/m;
  for(int i : vec) if(flag <= i) ans++;
  if(ans >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int minn=1e9+1,maxn=-1;
    int n,m;
    scanf("%d",&n);
    while(n--)
    {
        scanf("%d",&m);
        if(m<minn) minn=m;
        if(m>maxn) maxn=m;
    }
    long long ans=abs(minn-maxn);
    printf("%lld\n",ans);
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<functional>
#define ll long long
#define inf 0x3f3f3f3f
#define mod 998244353
#define maxn 200010
inline ll read()
{
	ll x=0; char c=getchar(),f=1;
	for(;c<'0'||'9'<c;c=getchar())if(c=='-')f=-1;
	for(;'0'<=c&&c<='9';c=getchar())x=x*10+c-'0';
	return x*f;
}
inline void write(ll x)
{
	static char buf[20];
	int len=0;
	if(x<0)putchar('-'),x=-x;
	for(;x;x/=10)buf[len++]=x%10+'0';
	if(!len)putchar('0');
	else while(len)putchar(buf[--len]);
}
inline void writesp(ll x){write(x); putchar(' ');}
inline void writeln(ll x){write(x); putchar('\n');}
ll sum[maxn];
int a[maxn];
int n,m,v,p;
int main()
{
	n=read(); m=read(); v=read(); p=read();
	for(int i=1;i<=n;i++)
		a[i]=read();
	std::sort(a+1,a+n+1,std::greater<int>());
	sum[0]=0;
	for(int i=1;i<=n;i++)
		sum[i]=sum[i-1]+a[i];
	int tot=0;
	for(int i=1;i<=n;i++)
		if(i<=p)++tot;
		else{
			int pos=std::lower_bound(a+1,a+n+1,a[i]+m,std::greater<int>())-a;
			if(pos>p)continue;
			ll rest=(ll)(i-p+1)*(a[i]+m)-(sum[i]-sum[p-1]);
			if(rest>=(ll)(v-(p-1)-(n-i))*m)++tot;
		}
	writeln(tot);
	return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
#define WHATIS(x) cout << #x << " is " << x << endl;
#define ERROR(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, ll> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << *it << " = " << a << endl;
    err(++it, args...);
}

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 35;
const int MAXK = 510;
const int MAXQ = 200010;

int n, d[100010];

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    FOR(i,0,n-1) d[i] = 1000000000;
    d[1] = 1;
    deque<int> q;
    q.push_front(1);
    while (!q.empty()) {
        int u = q.front();
        q.pop_front();
        if (d[(10 * u) % n] > d[u]) {
            d[(10 * u) % n] = d[u];
            q.push_front((10*u) % n);
        }
        if (d[(u + 1) % n] > d[u] + 1) {
            d[(u + 1) % n] = d[u] + 1;
            q.push_back((u+1) % n);
        }
    }
    cout << d[0];
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int n,k,s,a[5005];
bool f[5005]={1};
int read()
{
    int re=0;
    char ch=getchar();
    while(!isdigit(ch)) ch=getchar();
    while(isdigit(ch)) re=re*10+ch-'0',ch=getchar();
    return re;
}
int main()
{
    n=read(),k=read();
    for(int i=1;i<=n;i++) a[i]=min(k,read()),s+=a[i];
    sort(a,a+n+1);
    for(int i=n;i>=0;i--)
    {
        bool flag=true;
        for(int j=k-1;j>=max(0,k-s);j--)
            if(f[j])
            {
                flag=false;
                break;
            }
        if(flag)
        {
            printf("%d",i);
            return 0;
        }
        for(int j=a[i];j<k;j++)
            f[j]|=f[j-a[i]];
        s-=a[i];
    }
}


Measured memory_bytes: 256
h, w, k = map(int, input().split())

M = [0]*h
for i in range(h):
  r = list(input())
  r = [0 if j == '.' else 1 for j in r ]
  M[i] = r
  

total = sum([sum(r) for r in M])

import copy
ans = 0
for i in range(2**h):
  for j in range(2**w):
    del_cnt = 0
    MC = copy.deepcopy(M)
    for x in range(h):
      if i>>x&1:
        for y in range(w):
          if MC[x][y]==1:
            MC[x][y] = 0
            del_cnt += 1
    for x in range(w):
      if j>>x&1:
        for y in range(h):
          if MC[y][x] == 1:
            MC[y][x] = 0
            del_cnt += 1
    if del_cnt == total - k:
      ans += 1
  
print(ans)
    

Measured memory_bytes: 9320
#include <iostream>
    #include <stdio.h>
    #include <string>
    #include <math.h>
    #include<algorithm>
    #include <numeric>
    using namespace std;
     
    long long GCD(long long a, long long b) {
        if (b == 0) return a;
        else return GCD(b, a % b);
    }
     
    long long extGCD(long long a, long long b, long long &x, long long &y) {
        if (b == 0) {
            x = 1;
            y = 0;
            return a;
        }
        long long d = extGCD(b, a%b, y, x);
        y -= a/b * x;
        return d;
    }
     
    int main(){
      long long T;
      cin >> T;
      int count=0;
      long long A[T],B[T],C[T],D[T];
      for(long long i=0;i<T;i++){
       cin >> A[i] >> B[i] >> C[i] >> D[i]; 
      }
      for(long long i=0;i<T;i++){
          bool flag=true;
        bool subflag=false;
        long long k=A[i]%B[i];
        long long x,y;
        long long g=GCD(B[i],D[i]);
        if(B[i]>A[i])flag=false;
        if(B[i]>D[i])flag=false;
        if(flag==true && C[i]>=B[i]){
         subflag=true; 
        }
        if(flag==true && subflag==false){
         if(B[i]+(A[i]%g)-g>C[i])flag=false; 
        }
        if(flag==true) cout << "Yes" << endl;
        else{cout << "No" << endl;}
        
      }
        
        
      return 0;}

Measured memory_bytes: 256
/*
title:

url:
*/

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <queue>
#include <limits>
#include <string>
#include <utility>
#include <cstring>
#include <map>
#include <cmath>
#include <iterator>

using namespace std;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define INF 1000000007

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

int main()
{
    int x, a, b;
    cin >> x >> a >> b;
    x -= a;
    x %= b;
    cout << x << endl;
}

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

int main(){
    string s;
    cin >> s;
    int w;
    cin >> w;
    int size = s.size();
    for(int i=0;i<size;i+=w){
        cout << s[i];
    }
    cout << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 3009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e14 + 15;
ll dp[maxn][maxn][3];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;
    cin>>n;
    ll vet[n+2];
    rep(i,0,n){
        cin>>vet[i];
    }
    per(i,n+1,0){
        rep(j,0,n+1){
            if(i>j){
                continue;
            }
            else{
                dp[i][j][1]=max(dp[i+1][j][2]+vet[i],dp[i][j-1][2]+vet[j]);
                dp[i][j][2]=min(dp[i+1][j][1]-vet[i],dp[i][j-1][1]-vet[j]);
            }
        }
    }
    cout<<dp[0][n-1][1]<<'\n';
    return 0;   
}

Measured memory_bytes: 211200
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950L
int main()
{
        fast;
        int t=1;
        //cin>>t;
        while(t--)
        {
                int n,k,d;
                cin>>n>>k;
                set<int> s;
                for(int i=0;i<k;i++)
                {
                        cin>>d;
                        for(int j=0;j<d;j++)
                        {
                                int x;
                                cin>>x;
                                s.insert(x);
                        }
                }
                cout<<(n-s.size())<<endl;

        }
}

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

int main(){
    string n;
    cin >> n;
    int count;
    for(int i = 0; i < n.length();i++){
        if(i % 2 == 0){
            if(n.at(i) == 'L'){
                count++;
            }
        }else{
            if(n.at(i) == 'R')
                count++;
        }
    }
    if(count > 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

Measured memory_bytes: 256
//#define NDEBUG
#include <cstddef>
#include <cstdint>
#include <vector>

using i8 = ::std::int_least8_t;
using i32 = ::std::int_least32_t;
using i64 = ::std::int_least64_t;
using u8 = ::std::uint_least8_t;
using u32 = ::std::uint_least32_t;
using u64 = ::std::uint_least64_t;
using isize = ::std::ptrdiff_t;
using usize = ::std::size_t;

template <class T = usize> class rep {
	const T f, l;

public:
	class itr {
		friend rep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { ++i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr rep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(f); }
	constexpr itr end() const noexcept { return itr(l); }
};
template <class T = usize> class revrep {
	const T f, l;

public:
	class itr {
		friend revrep;
		T i;
		constexpr itr(T x) noexcept : i(x) {}

	public:
		void operator++() noexcept { --i; }
		constexpr T operator*() const noexcept { return i; }
		constexpr bool operator!=(const itr x) const noexcept { return i != x.i; }
	};
	constexpr revrep(const T first, const T last) noexcept : f(first), l(last) {}
	constexpr itr begin() const noexcept { return itr(l - 1); }
	constexpr itr end() const noexcept { return itr(f - 1); }
};
template <class T> bool amax(T &a, const T &b) {
	return a <= b ? (a = b, 1) : 0;
}
template <class T> bool amin(T &a, const T &b) {
	return b <= a ? (a = b, 1) : 0;
}
template <class T> bool asmax(T &a, const T &b) {
	return b <= a ? 0 : (a = b, 1);
}
template <class T> bool asmin(T &a, const T &b) {
	return a <= b ? 0 : (a = b, 1);
}
template <class T> using vec_alias = ::std::vector<T>;
template <class T> auto md_vec(usize n, const T &value) {
	return ::std::vector<T>(n, value);
}
template <class... Args> auto md_vec(usize n, Args... args) {
	return ::std::vector<decltype(md_vec(args...))>(n, md_vec(args...));
}
template <class T> const T &as_const(const T &v) noexcept { return v; }
template <class T> constexpr T difference(const T &a, const T &b) {
	return a <= b ? b - a : a - b;
}

#include <algorithm>
#include <iostream>
#include <utility>

int main() {
	usize n, m;
	std::cin >> n >> m;
	std::vector<std::pair<u64, usize>> s(n);
	for (auto &e : s) {
		std::cin >> e.first >> e.second;
	}
	std::sort(s.begin(), s.end());

	u64 ans = 0;
	for (const auto &e : s) {
		if (m >= e.second) {
			ans += e.first*e.second;
			m -= e.second;
		}
		else {
			ans += e.first*m;
			m = 0;
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
//typedef tree <int,null_type,less <int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define rep(g, i, n) for (ll g = i; g < n; g++)
#define rev(g, n, i) for (ll g = n - 1; g >= i; g--)
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define all(v) v.begin(), v.end()
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define um unordered_multiset
#define us unordered_set
#define mxe(v) *max_element(v.begin(),v.end())
#define mne(v) *min_element(v.begin(),v.end())
#define bs binary_search
#define lb lower_bound
#define ub upper_bound
#define ve vector
#define cc continue
#define bb break
#define rem 1000000007
#define debug(n1) cout<<"debug... "<<n1<<"\n"
//fflush(stdin);
// do {
// // process permutation
// } while (next_permutation(permutation.begin(),permutation.end()));
int main()
{
    FAST
    // freopen("input1.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    /*ll tests;
    cin>>tests;
    rep (gg,0,tests)
    {}*/
    ll a,b;
    cin>>a>>b;
    if (a<=9&&b<=9)
    {
        cout<<a*b<<"\n";
    }
    else
    {
        cout<<"-1\n";
    }
}


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

int main() {
  long A, B, C;
  cin >> A >> B >> C;
  int cnt = 0;
  for(int i = 0; i<= C; i++){
    B -= A;
    if(B<0)break;
    cnt++;
    if(C<=cnt)break;
  }
  cout << cnt;
}


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

def main():

    C = input()

    alphabet = 'a b c d e f g h i j k l m n o p q r s t u v w x y z'
    listAlphabet = alphabet.split()

    for i, name in enumerate(listAlphabet):
        if name == C:
            ans = listAlphabet[i + 1]
            break

    print(ans)


if __name__ == "__main__":
    main()

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

using namespace std;
#define LL long long
#define Rint register int
#define U unsigned
#define forn(i,a,b) for(int i = a;i <= b;++i)
#define nfor(i,a,b) for(int i = a;i >= b;--i)
#define pii pair<int ,int>
#define MS0(X) memset(X,0,sizeof(X))
#define MSf(X) memset(X,false,sizeof(X))
#define MS1(X) memset(X,-1,sizeof(X))
#define BR printf("--------------------\n")
#define pb push_back
#define rep(i,a,b) for(Rint i=a;i<=b;++i)
#define DEBUG(x) std::cerr << #x << '=' << x << std::endl
const double PI=atan(1.)*4.;
const int maxn=1e6+5;
const int inf = 0x3f3f3f3f;
const int mod=1e9+7;
const double e=2.71828182845904523536;
int dirx[8]={1,0,-1,0,1,-1,-1,1};
int diry[8]={0,1,0,-1,1,1,-1,-1};
int n,t;
struct node
{
    int a,b;
}st[maxn];
bool cmp(node a,node b)
{
    return a.a<b.a;
}
int dp[3005][6005];
int mx[3005];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>t;
    for(int i=1;i<=n;i++)
    {
        cin>>st[i].a>>st[i].b;
    }
    sort(st+1,st+n+1,cmp);
    for(int i=n;i>=1;i--)
    {
        mx[i]=max(mx[i+1],st[i].b);
    }
    int ans=0;
    for(int i=1;i<=n;i++)
    {
        /*for(int j=t+st[i].a-1;j>=st[i].a;--j)
        {
            dp[i][j]=max(dp[i-1][j],dp[i-1][j-st[i].a]+st[i].b);
            ans=max(ans,dp[i][j]);
        }
        for(int j=st[i].a-1;j>=0;--j)
        {
            dp[i][j]=dp[i-1][j];
        }*/
        for(int j=t-1;j>=0;j--)
        {
            dp[i][j]=dp[i-1][j];
            if(j>=st[i].a)
                dp[i][j]=max(dp[i][j],dp[i-1][j-st[i].a]+st[i].b);
        }
        ans=max(ans,dp[i][t-1]+mx[i+1]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 71296
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, x=0;
  cin >> N;
  
  for (int i = 0; i < N; i++){
	string S;
    cin >> S;
    if(S=="Y"){
      x=1;
      cout << "Four" << endl;
      break;
	}
  }
  if(x!=1)  cout << "Three" << endl;
  
 }
  

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
   
int main(int argc, char *argv[])
{
  int n,i,j,k;
  int *A;
  int cnt,m,G[12],v;
   
  scanf("%d",&n);
   
  A=(int *)malloc(sizeof(int)*n);
   
  for(i=0;i<n;i++) scanf("%d",&A[i]);
   
  cnt=0;
  m=1;
  G[0]=1;
  while(3*G[m-1]+1 < n)
  {
    G[m]=3*G[m-1]+1;
    m++;
  }
   
  for(i=0;i<m/2;i++)
  {
    v=G[i];
    G[i]=G[m-1-i];
    G[m-1-i]=v;
  }
   
  printf("%d\n",m);
  for(i=0;i<m;i++)
  {
    if(i!=m-1)printf("%d ",G[i]);
    else printf("%d\n",G[i]);
  }
   
  for(i=0;i<m;i++)
  {
    for(j=G[i];j<n;j++)
    {
      v=A[j];
      k=j-G[i];
        
      while(k>=0 && A[k]>v)
      {
        A[k+G[i]]=A[k];
        k-=G[i];
        cnt++;
      }
      A[k+G[i]]=v;
    }
  }
   
  printf("%d\n",cnt);
  for(i=0;i<n;i++)printf("%d\n",A[i]);
   
  return 0;
}

Measured memory_bytes: 5756
X,N=[int(x) for x in input().strip().split(" ")]
P=list(map(int,input().split()))
f=0
if len(P)==0:
    print(X)
else:
    for i in range(int(N/2)+2):
        if X-i not in P:
            print(X-i)
            f=1
        elif X+i not in P:
            print(X+i)
            f=1
        if f==1:
            break


Measured memory_bytes: 9196
#include <iostream>

using namespace std;

int main(){
    int y;
    int m;
    int d;
    char a;
    char b;
    cin >> y >> a >> m >> b >> d;
    if(4 < m){
        cout << "TBD" << endl;
    }
    else{
        cout << "Heisei" << endl;
    }
}

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

int main(){
    int a,b;
    string op;
    while(1){
        cin>>a>>op>>b;
        if(op=="?"){
            break;
        }
        
        if(op=="+"){
            cout<<a+b<<endl;
        }
         if(op=="-"){
            cout<<a-b<<endl;
        }
         if(op=="*"){
            cout<<a*b<<endl;
        }
         if(op=="/"){
            cout<<a/b<<endl;
        }
    } 
}


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

using namespace std;
const int maxn = 1e5+10;
const long long mod = 1e9+7;

int n;
vector<int> graph[maxn];
long long dp[maxn][10];

void dfs(int x, int parr) {
	//if (graph[x].size() == 0 || (graph[x].size() == 1 && parr != -1)) dp[x][0] = dp[x][1] = 1;
	dp[x][0] = dp[x][1] = 1;
	for (int i = 0; i < graph[x].size(); i++) {
		int tren = graph[x][i];
		if (tren != parr) {
			dfs(tren, x);
			dp[x][0] *= dp[tren][0] + dp[tren][1], dp[x][0] %= mod;
			dp[x][1] *= dp[tren][0], dp[x][1] %= mod;
		}
	}
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i < n; i++) {
		int a, b;
		scanf("%d%d", &a, &b);
		graph[a].push_back(b);
		graph[b].push_back(a);
	}
	
	dfs(1, -1);
	printf("%lld", (dp[1][0] + dp[1][1]) % mod);	
	return 0;
}


Measured memory_bytes: 20480
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
#define int long long
const int maxn = 1020;
int n, x[maxn], y[maxn], odd, even;
namespace sol{
    int a[59], k, ham;
    const int dx[] = {0, 0, 1, -1}, dy[] = {1, -1, 0, 0};
    const char dr[] = "DULR";
    void dfs(int x, int y, int cur) {
        if(cur == 0) return;
        int chg = 1LL << (cur - 1);
        for(int dir = 0; dir < 4; ++dir) {
            int xf = x + dx[dir] * chg, yf = y + dy[dir] * chg;
            if(abs(xf) + abs(yf) < (1LL << (cur - 1)) ) {
                putchar(dr[dir]);
                dfs(xf, yf, cur - 1);
                break;
            }
        }
    }
    inline void solve() {
        rep(i, n) ham = max(ham, x[i] + y[i]) + 2;
        for(k = 0; (1LL << k) < ham; ++k) ;
        if(even) printf("%lld\n1 ", ++k + 1);
        else printf("%lld\n", ++k);
        for(int i = k; i ; --i) {
            a[i] = 1LL << (i - 1);
            printf("%lld%c", a[i], i == 1LL ? '\n' : ' ');
        }
        for(int i = 1; i <= n; ++i){
            if(even) putchar('L'), x[i]++;
            dfs(x[i], y[i], k);
            putchar('\n');
        }
    }
}
signed main(){
    scanf("%lld", &n);
    odd = even = true;
    rep(i, n) scanf("%lld%lld", &x[i], &y[i]);
    rep(i, n) {
        int sum = abs(x[i]) + abs(y[i]);
        if(sum & 1) even = false; else odd = false;
    }
    if((odd | even) == 0) {puts("-1"); return 0;}
    sol::solve();
    return 0;
}
////

Measured memory_bytes: 256
using System.Linq;
using System.Collections.Generic;
using System;

public class P
{
    public List<int> from { get; set; }
    public List<int> to { get; set; }
}

public class Hello
{
    public static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var e = int.Parse(line[1]);
        var d = new Dictionary<int, P>();
        for (int i = 0; i < n; i++) d[i] = new P { from = new List<int>(), to = new List<int>() };
        for (int i = 0; i < e; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            var s = int.Parse(line[0]);
            var t = int.Parse(line[1]);
            d[s].to.Add(t);
            d[t].from.Add(s);
        }
        tsort(d, n);
    }
    public static void tsort(Dictionary<int, P> d, int n)
    {
        var q = new Queue<int>();
        for (int i = 0; i < n; i++) q.Enqueue(i);
        while (q.Count() > 0)
        {
            var w = q.Dequeue();
            if (d[w].from.Count == 0)
            {
                Console.WriteLine(w);
                foreach (var x in d[w].to) d[x].from.Remove(w);
            }
            else q.Enqueue(w);
        }
    }
}




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

#define PI 3.14159265359
#define rep(i,a,n) for(int i=a;i<(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define descsort(a) sort(a.begin(),a.end(),std::greater<int>())
using namespace std;
typedef long long ll;
const ll INF = 1e9 + 7;

int main(void)
{
    int n,a,b;
    cin>>n>>a>>b;
    int ma=min(a,b);
    int mi=max(0,a+b-n);
    cout<<ma<<" "<<mi<<endl;
    return 0;
}

Measured memory_bytes: 3572
import math


"""
e.g. N=3 a=[-1 1 1]
 -1 2  1 :1
 -1 2 -2 :4

e.g. N=3 a=[0 0 -1]
 1  0 -1 :1
 1 -2 -1 :3
 1 -2  2 :6

 -1 0 -1 :1
 -1 2 -1 :3
 -1 2 -2 :4

e.g. N=3 a=[0 0 1]
 1  0 1 :1
 1 -2 1 :3
 1 -2 2 :4

 -1 0  1 :1
 -1 2  1 :3
 -1 2 -2 :6

e.g. N=4 a=[0 0 0 -1]
 1  0 0 -1 :1
 1 -2 0 -1 :3
 1 -2 2 -1 :5
 1 -2 2 -2 :6

 -1 0  0 -1 :1
 -1 2  0 -1 :3
 -1 2 -2 -1 :5
 -1 2 -2  2 :8

e.g. N=4 a=[0 0 0 1]
 1  0 0  1 :1
 1 -2 0  1 :3
 1 -2 2  1 :5
 1 -2 2 -2 :8

 -1 0  0 1 :1
 -1 2  0 1 :3
 -1 2 -2 1 :5
 -1 2 -2 2 :6
"""


def main2():
    """
    累積和は、偶奇,奇偶のどちらかの数列になるので２種類試す
    """
    n = int(input())
    A = list(map(int, input().split()))

    ans = float("inf")
    for sign in (1, -1):
        s, n_op = 0, 0
        for a in A:
            s += a
            # if sign == 1 and s <= 0:
            # elif sign == -1 and s >= 0:
            if s * sign <= 0:
                # 調整
                n_op += abs(s) + 1
                s = sign

            # 偶奇の入れ替え
            sign *= -1

        ans = min(ans, n_op)

    print(ans)


def main():
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0

    # 最初から0続きのとき、操作が少なくなるように同じ符号にする
    def sign(x):
        if x == 0:
            return 0
        return int(math.copysign(1, x))

    if a[0] == 0:
        for i in range(1, n):
            if a[i] != 0:
                sign_a = sign(a[i])
                if i % 2 == 0:
                    # odd: 1-indexed
                    a[0] = sign_a
                else:
                    a[0] = -sign_a

                ans += 1
                break
    s = a[0]

    for i in range(1, n):
        s1 = s + a[i]
        sign_s = sign(s)
        sign_s1 = sign(s1)

        if s1 == 0 or sign_s == sign_s1:
            # 逆方向に変更
            # new_s1 = -sign_s = s+a[i] + diff
            diff = -(sign_s + s + a[i])
            a[i] += diff
            ans += abs(diff)

        s += a[i]

        #print(i, a, sep="\t")
    print(ans)

if __name__ == '__main__':
    main2()


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

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

int main(){
	int X,Y,a,b,c;
	cin >> X >> Y >> a >> b >> c;
	vector<ll> A,B,C;

	rep(i,a){ll t; cin >> t; A.push_back(t); }
	rep(i,b){ll t; cin >> t; B.push_back(t); }
	rep(i,c){ll t; cin >> t; C.push_back(t); }
	sort(A.begin(),A.end());
	reverse(A.begin(),A.end());
	sort(B.begin(),B.end());
	reverse(B.begin(),B.end());

	rep(i,X){ C.push_back(A[i]); }
	rep(i,Y){ C.push_back(B[i]); }
	sort(C.begin(),C.end());
	reverse(C.begin(),C.end());

	ll ans = 0;
	rep(i,X+Y){ ans += C[i];}

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

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

int main(){
  int n;
  cin >> n;
  vector<tuple<ll, ll, ll>> vec;
  rep(i, n){
    ll a, b;
    cin >> a >> b;
    vec.push_back(make_tuple(a+b, a, b));
  }
  sort(all(vec), greater<tuple<ll, ll, ll>>());
  ll sumA=0, sumB=0;
  rep(i, n){
   	 if(i%2==0){
       sumA += get<1>(vec[i]);
     }else{
       sumB += get<2>(vec[i]);
     }
  }
  cout << sumA-sumB << endl;
  return 0;
}

Measured memory_bytes: 6304
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include<bits/stdc++.h>
using namespace std;
const int N=1000005,M=998244353;
#define int long long
int * v[N];
int miu[N],flag[N],tot,b[N],f[N],now[N],s[N],dp[N],ans,inv[N],n,p[N],a[N],fflag[N];
inline int * New_int(int sz){
	static int pool[1 << 25],*now = pool,*ret;
	ret = now; now += sz;
	return ret;
}
void init(){
	miu[1]=1;
	for (int i=2;i<N;i++){
		if (!flag[i]){
			miu[i]=-1;
			b[++tot]=i;
		}
		for (int j=1;j<=tot;j++){
			int k=i*b[j];
			if (k>=N)break;
			flag[k]=1;
			if (i%b[j]==0){
				miu[k]=0;
				break;
			}
			miu[k]=-miu[i];
		}
	}
	for (int i=1;i<N;i++) for (int j=i;j<N;j+=i)
		now[j]++;
	for (int i=1;i<N;i++)v[i] = New_int(s[i] = now[i]);	
	for (int i=1;i<N;i++)
		for (int j=i;j<N;j+=i)v[j][--now[j]]=i;	
}
int ksm(int x,int y){
	int ans=1;
	for (;y;y>>=1,x=x*x%M)
		if (y&1)(ans*=x)%=M;
	return ans;	
}
signed main(){
	init();
	scanf("%lld",&n);
	for (int i=0;i<N;i++)inv[i]=ksm(i,M-2);
	for (int i=1;i<=n;i++)
		scanf("%lld",&a[i]),(p[a[i]]+=a[i])%=M,fflag[a[i]]=1;
	for (int i=1;i<N;i++)
		for (int j=2*i;j<N;j+=i)
			(p[i]+=p[j])%=M;
	for (int i=1;i<N;i++)if (fflag[i]){
		for (int j=0;j<s[i];j++){
			int num=0,pp=v[i][j];
			for (int k=0;k<s[i/pp];k++)
				num+=miu[v[i/pp][k]]*p[v[i/pp][k]*pp];
			num%=M;	
			(dp[i]+=inv[pp]*num)%=M;
		}
	}
	for (int i=1;i<=n;i++)(ans+=dp[a[i]]*a[i])%=M;
	for (int i=1;i<=n;i++)(ans+=M-a[i])%=M;
	printf("%lld\n",(ans+M)*inv[2]%M);
	return 0;
}

Measured memory_bytes: 188672
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;

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

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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = (B % A == 0) ? (A + B) : (B - A);
  cout << ans << endl;
}

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

int main() {
	string S;
	cin >> S;
	int N = S.size();
	vector<char> vec(N);

	for (int i = 0; i < N; i++)
		vec.at(i) = S.at(i);
	int count1 = 0;
	int count2 = 0;

	for (int i = 0; i < N; i += 2) {
		if (vec.at(i) == 'L')
			count1++;
	}

	for (int i = 1; i < N; i += 2) {
		if (vec.at(i) == 'R')
			count2++;
	}

	if (count1 == 0 && count2 == 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 384