akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int N, K;
    cin >> N >> K;
    int sum = 0;
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        if(x <= K/2) {
            sum += x*2;
        }else {
            sum += max(x-K, K-x)*2;
        }
    }
    cout << sum << endl;
}

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

#define TRUE 1
#define FALSE 0

int isprime(int);

int main(){
  int i;
  int answer = 0;
  int x,n;

  scanf("%d",&n);

  for (i = 0;i < n;i++){
    scanf("%d",&x);
    answer += isprime(x);
  }

  printf("%d\n",answer);
  
  return 0;
}

int isprime(int x){
  int i;

  if (x == 2)
    return TRUE;

  if (x < 2 || x % 2 == 0)
    return FALSE;
  
  for (i = 3;i <= sqrt(x);i += 2)
    if (x % i == 0)
      return FALSE;

  return TRUE;
}


Measured memory_bytes: 2060
#include<stdio.h>

int main() {
  int i;
  int x,y,z,a,data;

  scanf("%d%d",&x,&y);

  if(x>y){
    z = x%y;
    a = y;
  } else {
    z = y%x;
    if(x == y){
      z = x;
    }
    a = x;
  }

  for(i = z;i >= 0;i--){
    if(a%i == 0 && z%i ==0) {
      data = i;
      break;
    }
  }
  printf("%d\n",data);
}



Measured memory_bytes: 2108
import numpy as np
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

N, M = map(int, input().split())
uf = UnionFind(N)
for i in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)

print(uf.group_count()-1)

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

int main()
{	
  
 string s;
  cin>>s;
  int f1=0,f2=0;
  for(int i=0;i<3;i++)
  {
    if(s[i]=='A')
  		f1++;
    if(s[i]=='B')
      f2++;
  }  
  if(f1>0 && f2>0)
    cout<<"Yes";
  else
    cout<<"No";

 return 0; 
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int cnt = 3;
    int a = sc.nextInt();
    int b = sc.nextInt();
    if (a == b) {
      cnt--;
    }
    int c = sc.nextInt();
    if (a == c || b == c) {
      cnt--;
    }
    System.out.println(cnt);

  }
}

Measured memory_bytes: 35728
n=int(input())
s=[n]
a=n
count=1
while True:
    if n%2==0:
        n=int(n/2)
    else:
        n=3*n+1
    if n in s:
        break
    else:
        s.append(n)
        count=count+1
print(count+1)

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

const ll mod=1e9+7;

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

/*-------------------------------------------*/

ll n;
vector<ll> s;

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

    cin>>n;
    s.resize(n);
    rep(i,n)cin>>s[i];

    ll ans=0;

    FOR(i,1,n){
        ll now=0,l=0,r=n-1;
        while(r>i&&(r%i||l<r)){
            now+=s[l]+s[r];
            chmax(ans,now);
            l+=i;
            r-=i;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>

int main()
{
	int a, b;
	std::cin >> a >> b;
	
	if ((a + b) % 2 == 0)
	{
		std::cout << (a + b) / 2 << std::endl;
	}
	else
	{
		std::cout << "IMPOSSIBLE" << std::endl;		
	}
	
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public void main(Scanner sc) {
        int w = sc.nextInt();
        int h = sc.nextInt();
        long p[] = new long[w];
        long q[] = new long[h];

        long ans = 0;
        for (int i = 0; i < w; i++) {
            p[i] = sc.nextInt();
            ans += p[i];
        }

        for (int i = 0; i < h; i++) {
            q[i] = sc.nextInt();
            ans += q[i];
        }

        Arrays.sort(q);
        long qsum[] = new long[h + 1];
        for (int i = 0; i < h; i++) {
            qsum[i + 1] = qsum[i] + q[i];
        }

        for (int i = 0; i < w; i++) {
            int cnt = search(q, p[i]);
            ans += (h - cnt) * p[i] + qsum[cnt];
        }
        System.out.println(ans);
    }

    private int search(long n[], long p) {
        int l = 0;
        int r = n.length - 1;

        if (n[0] > p) {
            return 0;
        }
        if (n[r] < p) {
            return r + 1;
        }

        while ((r - l) > 1) {
            int c = (l + r) / 2;
            if (n[c] < p) {
                l = c;
            } else {
                r = c;
            }
        }

        return l + 1;
    }

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


Measured memory_bytes: 85440
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
  ll n;
  cin >> n;
  map<ll,ll> mp;
  rep(i,n){
    ll a;
    cin >> a;
    mp[a]++;
  } 
  vector<ll> a;
  for(auto itr = mp.begin(); itr != mp.end(); itr++){
    if(itr->second > 1) a.push_back(itr->first);
  }
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end());
  if(a.size() == 0 || (a.size() == 1 && mp[a.at(0)] < 4)){
    cout << 0 << endl;
    return 0;
  }
  else{
    ll ans;
    if(mp[a.at(0)] >= 4) ans = a.at(0)*a.at(0);
    else ans = a.at(0)*a.at(1);
    cout << ans << endl;
  }
  
  
}

Measured memory_bytes: 9836
#include<bits/stdc++.h>
using namespace std;
#define FastRead ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define endl '\n'
#define ld long double
#define FOR(i,a,n) for (ll i=(a);i<=(n);++i)
#define RFOR(i,a,n) for (ll i=(n);i>=(a);--i)
#define FI(i,n) for (ll i=0; i<(n); ++i)
#define ZERO(a) memset((a),0,sizeof((a)))
#define MINUS(a) memset((a),-1,sizeof((a)))
#define f first
#define s second
#define pb push_back
#define mk make_pair
#define all(g) g.begin(),g.end()
int fastMax(int x, int y) { return (((y-x)>>(32-1))&(x^y))^y; }
int fastMin(int x, int y) { return (((y-x)>>(32-1))&(x^y))^x; }
 
// I want to be the very best, like no one ever was, I will battle everyday to claim my rightful place
// Not gonna give up until it's over
// #include <ext/pb_ds/assoc_container.hpp> // Common file
// #include <ext/pb_ds/tree_policy.hpp>     // Including tree_order_statistics_node_updat
// using namespace __gnu_pbds;
// typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
 
// I am questioning life and universe and 
// everything else after looking at this

const ll MAXN = 1e5 + 10;
const ll MOD = 1e9 + 7;
vector<ll> graph[MAXN];
ll dp[MAXN][2];

void dfs(ll u,ll p){
    dp[u][0] = dp[u][1] = 1;

    for(ll v:graph[u]){
        if(v == p) continue;
        dfs(v,u);
        dp[u][0] = (dp[u][0]*(dp[v][0] + dp[v][1]))%MOD;
        dp[u][1] = (dp[u][1]*(dp[v][0]))%MOD;
    }
}

void solve(){
    ll n; cin>>n;

    FOR(i,1,n-1){
        ll u,v; cin>>u>>v;
        graph[u].push_back(v);
        graph[v].push_back(u);
    }

    dfs(1,0);

    cout<<(dp[1][0] + dp[1][1])%MOD<<endl;
}

signed main(){
 
   FastRead;    
 

    ll t;
    t = 1; 
    // cin>>t;
    FOR(i,1,t){
        // cout<<"Case #"<<i<<": ";
        solve();
    }
}

Measured memory_bytes: 14208
#include <bits/stdc++.h>
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end() 
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define INF 1000000000
using namespace std;
typedef long long ll;

int main() {
    string S, T, U;
    int A, B;

    cin >> S >> T;
    cin >> A >> B;
    cin >> U;

    if(S == U){
        cout << A-1 << " " << B << endl;
    }
    if(T == U){
        cout << A << " " << B-1 << endl;
    }
}

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

using namespace std;

int H, W;

vector<string> map;

const vector<int> dx = { 0, 1, 0, -1 };
const vector<int> dy = { 1, 0, -1, 0 };

void rec(int x, int y, char c)
{
    map[y][x] = '.';
    
    for(int i = 0; i < 4; i++)
    {
        if(0 <= x + dx[i] && x + dx[i] < W && 0 <= y + dy[i] && y + dy[i] < H)
        {
            if(map[y + dy[i]][x + dx[i]] == c)
            {
                rec(x + dx[i], y + dy[i], c);
            }
        }
    }
}

int solve()
{
    int ret = 0;
    
    for(int i = 0; i < H; i++)
    {
        for(int j = 0; j < W; j++)
        {
            if(map[i][j] != '.')
            {
                rec(j, i, map[i][j]); ret++;
            }
        }
    }
    
    return ret;
}

int main()
{
    while(true)
    {
        cin >> H >> W;
        
        if(H == 0 && W == 0) { break; }
        
        map = vector<string>(H);
        
        for(int i = 0; i < H; i++)
        {
            cin >> map[i];
        }
        
        cout << solve() << endl;
    }
    
    return 0;
}

Measured memory_bytes: 3848
#!/usr/bin/env python
# coding: utf-8

# In[14]:


N,M = map(int, input().split())
A = list(map(int, input().split()))
BC = []
for _ in range(M):
    BC.append(list(map(int, input().split())))


# In[15]:


bc_sorted = sorted(BC, key=lambda x:x[1], reverse=True)
mylist = [a for a in A]
for i in range(M):
    mylist += [bc_sorted[i][1]]*bc_sorted[i][0]
    if len(mylist) > N*2:
        break
ans = sorted(mylist, reverse=True)[:N]
print(sum(ans))


# In[ ]:






Measured memory_bytes: 38324
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
#import heapq
from fractions  import gcd
#input=sys.stdin.readline
import bisect
n,m=map(int,input().split())
num=[1]*n
s=set()
s.add(1)
ans=1
for i in range(m):
    x,y=map(int,input().split())
    num[x-1]-=1
    num[y-1]+=1
    if x in s:
        if num[x-1]!=0 and y not in s:
          ans+=1
        elif num[x-1]==0:
          s.discard(x)
          if y in s:
            ans-=1
        s.add(y)
print(ans)

Measured memory_bytes: 92588
#include <stdio.h>
n[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
char *w[]={"Wednesday","Thursday","Friday","Saturday","Sunday","Monday","Tuesday"};
int main(m,d){
	for(m=2;m<13;m++)n[m]+=n[m-1];while(scanf("%d%d",&m,&d),m)puts(w[(n[m-1]+d)%7]);exit(0);
	}

Measured memory_bytes: 584
import bisect

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

A.sort()
C.sort()

ans = 0
for b in B:
    ai = bisect.bisect_left(A, b)
    ci = bisect.bisect_right(C, b)
    ans += ai * (N-ci)
print(ans)

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

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rep2(i, a, b) for (ll i = (a); i < (b); i++)
typedef uint64_t ull;
typedef int64_t ll;
typedef std::pair<ll, ll> PLL;

using namespace std;

template <std::int64_t M>
class modint {
 public:
  int64_t a;

  explicit constexpr modint(const int64_t x = 0) noexcept : a((x % M + M) % M) {}
  constexpr int64_t &value() noexcept { return a; }
  constexpr const int64_t &value() const noexcept { return a; }
  constexpr modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  constexpr modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= M) {
      a -= M;
    }
    return *this;
  }
  constexpr modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += M;
    }
    a -= rhs.a;
    return *this;
  }
  constexpr modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % M;
    return *this;
  }
  constexpr modint &operator/=(modint rhs) noexcept {
    int64_t exp = M - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
using mint = modint<1000000007>;

signed main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N);
  rep(i, N)
    cin >> a[i];
  auto sa = a;
  sort(begin(sa), end(sa));
  mint ans(0);
  rep(i, N) {
    auto t = mint(distance(upper_bound(begin(sa), end(sa), a[i]), end(sa)));

    mint p(0);
    rep(j, i)
      if (a[j] > a[i])
        p+=mint(1);

    ans += t * mint(K) * mint(K-1) / mint(2)+ mint(K) * p;
  }
  cout << ans.value() << endl;
  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
B = B[::-1]
SumA, SumB = [0],[0]
for i in range(N):
    SumA.append(SumA[-1] + A[i])
    SumB.append(SumB[-1] + B[i])
ans = 0
for i in range(N):
    ans = max(ans, SumA[i+1]+SumB[N-i])
print(ans)

Measured memory_bytes: 3064
#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()
typedef long long ll;
int main(){
    int n,d;
    cin >> n >> d;
    vector<double>x(n);
    vector<double>y(n);
    rep(i,n)cin >> x[i] >> y[i];
    int cnt = 0;
    rep(i,n){
        double a = sqrt(pow(x[i],2) + pow(y[i],2));
        if(a <= d)cnt++;
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 6376
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

    int x; cin>>x;

    vector<bool> dp(x+1, false);
    dp[0] = true;

    for(int i=0; i<6; i++){
        int c = 100 + i;
        for(int j=0; j<=x; j++){
            if(j - c >= 0) dp[j] = dp[j] || dp[j - c];
        }
    }

    cout << dp[x] << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
a = [0] + [1] + [0 for _ in range(N-1)]
b = [0] + [1 for _ in range(N)]
for _ in range(M):
    x, y = map(int, input().split())
    b[x] -= 1
    b[y] += 1
    if a[x] == 1:
        a[y] = 1
        if b[x] == 0:
            a[x] = 0
    
print(sum(a))

Measured memory_bytes: 5384
import Control.Applicative

solve :: [Int] -> String
solve [a,b]
    | a > b = "a > b"
    | a < b = "a < b"
    | a == b = "a == b"

main :: IO()
main = do
    [a,b] <- map read . words <$> getLine
    putStrLn $ solve [a,b]

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

using ll = long long;
using pii = pair<int, int>;
template <class T>
using V = vector<T>;
template <class T>
using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define ALL(c) (c).begin(), (c).end()

constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }

template <class T, class U>
void chmin(T& t, const U& u) {
    if (t > u) t = u;
}
template <class T, class U>
void chmax(T& t, const U& u) {
    if (t < u) t = u;
}

template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << "," << p.second << ")";
    return os;
}

template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "{";
    rep(i, v.size()) {
        if (i) os << ",";
        os << v[i];
    }
    os << "}";
    return os;
}

#ifdef LOCAL
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}
#define debug(...) \
    cerr << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define dump(x) cerr << __LINE__ << " " << #x << " = " << (x) << endl
#else
#define debug(...) (void(0))
#define dump(x) (void(0))
#endif

bool cmp(ll a, ll b, ll c, ll d) {
    return (__int128)a * d - (__int128)b * c > 0;
}

int main() {
    int N;
    cin >> N;
    V<int> A(N), B(N);
    ll sum = 0;
    rep(i, N) {
        cin >> A[i] >> B[i];
        sum += A[i];
    }

    V<pair<ll, int>> vec(N);
    rep(i, N) { vec[i] = mp(max(A[i], B[i]), i); }
    sort(ALL(vec));
    reverse(ALL(vec));
    V<ll> acm(N + 1);
    rep(i, N) acm[i + 1] = acm[i] + vec[i].fi;

    ll a = TEN(18), b = 1;

    rep(i, N) {
        int id = vec[i].se;
        int k;
        ll rem;

        if (acm[i] + B[id] <= sum) {
            ll t = sum - acm[i];
            ll lo = i + 1, hi = N;
            while (hi - lo > 1) {
                int m = (hi + lo) / 2;
                if (t - (acm[m] - acm[i + 1]) <= B[id]) {
                    hi = m;
                } else {
                    lo = m;
                }
            }
            rem = t - (acm[hi] - acm[i + 1]);
            if (rem < 0) {
                continue;
            }
            k = hi - 1;
        } else {
            ll t = sum;
            ll lo = 0, hi = i;
            while (hi - lo > 1) {
                int m = (hi + lo) / 2;
                if (t - acm[m] <= B[id]) {
                    hi = m;
                } else {
                    lo = m;
                }
            }
            rem = t - acm[hi];
            if (t - acm[hi] < 0) {
                continue;
            }
            k = hi;
        }
        ll p = rem + (ll)B[id] * k, q = B[id];
        if (cmp(a, b, p, q)) {
            a = p, b = q;
        }
    }
    b *= N;
    a = b - a;
    if (a < 0) a = 0;
    {
        ll d = __gcd(a, b);
        a /= d;
        b /= d;
    }
    cout << a << " " << b << endl;

    return 0;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 100005;

/* ...o(^-^)o... */
int main(){
    int n; cin >> n;
    vector<P> v(n);
    rep(i, n){
        lint x; cin >> x;
        v[i] = P(x, i);
    }
    sort(all(v));
    int ans = 0;
    rep(i, n){
        if((i + v[i].se) % 2) ans++; 
    }
    out(ans / 2);
}

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

using namespace std;

#define sz(v)           ((int)((v).size()))
#define clr(v, d)       memset(v, d, sizeof(v))
#define rep(i, v)       for(int i=0; i<sz(v); ++i)
#define lp(i, n)        for(int i=0; i<(int)(n); ++i)
#define lpi(i, j, n)    for(int i=(j); i<(int)(n); ++i)
#define lpd(i, j, n)    for(int i=(j); i>=(int)(n); --i)
//#define INF             1000000000
//#define INF             100000000000000

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;

int main()
{
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int r;
	cin >> r;
	cout << r*r;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<unordered_map>
#include<functional>
#include<set>
#include<numeric>

#pragma region
using namespace std;
#define FOR(i,r,n) for(ll i = (ll)(r); i < (ll)(n); i++)
#define rep(i,n) FOR(i,0LL,n)
#define RFOR(i,r,n) for(ll i=(ll)(n-1);i>=r;i--)
#define rrep(i,n) RFOR(i,0LL,n)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define COUNT(a,y,x) upper_bound(all(a), y) - lower_bound(all(a), x)
#define UNIQUE(a) sort(all(a)); a.erase(unique(all(a)), a.end())
#define SUM(a) accumulate(all(a),0LL)
#define pb push_back
#define endl '\n'
typedef long long int ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef map<ll, ll> MAP;
const ll inf = 2222222222222222222LL;
const ll mod = 1000000007LL;

ll n = 0, m = 0, ans = 0, cnt = 0, tmp = 0, ma = -inf, mi = inf;
string s;
bool ok = true, flag = false;
ll dx[9] = { 0,1,-1,0,0,1,1,-1,-1 }, dy[9] = { 0,0,0,1,-1,1,-1,1,-1 };
#pragma endregion
#define MAX 222222




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


  cin >> s;
  ans = inf;
  rep(i, s.length() - 2) ans = min(ans, abs(753 - stoll(s.substr(i, 3))));
  cout << ans << endl;



  return 0;
}



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

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repc(i, s, n) for (int i = (s); i <= (n); i++)
#define rrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rrepc(i, s, n) for (int i = (s); i >= (n); i--)
#define print_array(ary, size) cout << ary[0]; rep1(i, 1, size - 1) cout << ' ' << ary[i]; cout << endl;
typedef long long ll;
typedef unsigned long long ull;

vector<int> T[200001];
vector<int> depth[200001];
int cnt[200001] = { 0 };
int parent[200001] = { 0 };
int max_depth = 0;

void setChild(int index, int dep, int par)
{
	int next;

	parent[index] = par;
	depth[dep].push_back(index);
	max_depth = max(max_depth, dep);

	rep(i, T[index].size()) {
		next = T[index][i];

		if (parent[next] == 0) {
			setChild(next, dep + 1, index);
		}
	}
}

int main()
{
	int N, Q;
	int a, b;
	int p, x;

	cin >> N >> Q;

	rep(i, N - 1) {
		cin >> a >> b;
		T[a].push_back(b);
		T[b].push_back(a);
	}

	setChild(1, 0, -1);

	rep(i, Q) {
		cin >> p >> x;
		cnt[p] += x;
	}

	repc(i, 1, max_depth + 1) {
		rep(j, depth[i].size()) {
			p = depth[i][j];
			cnt[p] += cnt[parent[p]];
		}
	}

	cout << cnt[1];
	repc(i, 2, N) cout << ' ' << cnt[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 35200
# include <iostream>
# include <string>
# include <algorithm>
# include <vector>
# include <cstring>
# include <stdio.h>
# include <map>
# include <queue>

# define ll long long
# define pii pair<int,int>
# define FOR(a,b) for(int a=1; a<=b; a++)
# define REP(a,b) for(int a=0; a<b; a++)
# define FORU(a,b,c) for(int a=b; a<=c; a++)
# define FORD(a,b,c) for(int a=b; a>=c; a--)

using namespace std;

struct Edge {
  int from, to, weight;
  Edge(){}
  Edge(int f, int t, int w){
    from = f;
    to = t;
    weight = w;
  }
};

int getValue(int x){
  int res = 0, cur = 1;
  while(cur * 2 <= x){
    cur *= 2;
    res++;
  }
  return res;
}

vector<Edge> getAns(int L, int N){
  vector<Edge> res;
  for(int i=0; i<N; i++){
    res.push_back(Edge(i+1, i+2, 0));
    res.push_back(Edge(i+1, i+2, 1<<i));
  }
  for(int t=N; t>=0; t--){
    if(L - (1<<t) >= (1<<N)){
      res.push_back(Edge(t+1, N+1, L-(1<<t)));
      L -= 1<<t;
    }
  }
  return res;
}

int main(){

  ios :: sync_with_stdio(false);
  int L;
  cin >> L;

  int N = getValue(L);
  vector<Edge> ans = getAns(L, N);

  cout << N+1 << " " << ans.size() << endl;
  for(auto e : ans) cout << e.from << " " << e.to << " " << e.weight << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main () {
	
	int L, R, d, count = 0;
	scanf("%d %d %d", &L, &R, &d);
	
	for (int i=L; i<=R; i++){
		if (i % d == 0){
			count++;
		}
	}
	printf("%d", count);
	
	return 0;
}

Measured memory_bytes: 1704
N = int(input())
digit = 1
for i in range(1,11):
    if N > 26**i:
        digit += 1
        N -= 26**i
    else:
        break
ans = []
for i in reversed(range(1,digit)):
    ans.append((N-1)//(26**i))
    N -= ans[-1]*(26**i)
ans.append(N-1)
ans = [chr(i+97) for i in ans]
print("".join(ans))

Measured memory_bytes: 61884
#include <stdio.h>

int main(void){

	int x = 1, y = 1, temp;
	while(1){
		scanf("%d %d", &x, &y);
		temp = x;
		if(x != 0 || y != 0){
			x = (x < y)?x:y;
			y = (temp < y)?y:temp;
			printf("%d %d\n", x, y);
		}else{
			break;
		}
	}

	return 0;
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)

#define mt              make_tuple
#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;

    ll a , b , c , k;

    cin >> a >> b >> c >> k;

    if((a+b+c)<=k)
    {
        cout << a-c << endl;
        return 0;
    }
    else
    {

        if(a>=k)
        {
            cout << min(a,k) << endl;
            return 0;
        }

        ll sum = 0;


      ll baki = k-(a+b);

     // cout << baki << endl;


      sum += a;

      sum += 0;

      if(baki>0)
      {
          sum -= min(baki,c);
      }

      cout << sum << endl;
    }





    return 0;
}



Measured memory_bytes: 3656
# from math import factorial,sqrt,ceil #,gcd
# from itertools import permutations,combinations,combinations_with_replacement
# from collections import deque,Counter
# import re
# from bisect import bisect_left
# from heapq import heappush,heappop
# from numba import njit
# from functools import lru_cache # 簡単メモ化 @lru_cache(maxsize=1000)
# from fractions import gcd

# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# import networkx as nx
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix
# from scipy.special import comb,perm #permはnPk

# slist = "abcdefghijklmnopqrstuvwxyz"
MOD = 10**9 + 7
N = input()
num = int(N[-1])

if num in [2,4,5,7,9]:
    print("hon")
elif num in [0,1,6,8]:
    print("pon")
else:
    print("bon")

# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 999999797
#define N 100001

int n, ar[100001][3], dp[100001][4];

int solve(int idx, int lst) {
        if (idx == n)
                return 0;
        int &ret = dp[idx][lst];
        if (ret != -1)
                return ret;
        ret = -1e9;
        for (int i = 0; i < 3; i++) {
                if (lst != i)
                        ret = max(ret, solve(idx + 1, i) + ar[idx][i]);
        }
        return ret;
}

int main(){
ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
        cin >> n;
        for (int i = 0; i < n; i++) {
                for (int j = 0; j < 3; j++) {
                        cin >> ar[i][j];
                }
        }
        for (int i = 0; i <= 1e5; i++) {
                for (int j = 0; j < 4; j++)
                        dp[i][j] = -1;
        }
        cout << solve(0, 3);
return 0;
}


Measured memory_bytes: 10752
/* include c++ libraries */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <queue>
#include <set>

/* include c-lang libraries */
#include <climits>
#include <cmath>

/* include my libraries */
//#include <show_vec.hh>

using namespace std;

#define LINE DEBUG{ printf("LINE : %d\n", __LINE__); }
#define DEBUG if(false)

using ll = long long;
template<class T> using vec = vector<T>;

const int MOD = 1000000007;

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

  vec<int> Ans(4, 0);
  for(int i = 0; i < N; i++){
    string S;
    cin >> S;
    if(S[0] == 'A'){
      Ans[0]++;
    }else if(S[0] == 'W'){
      Ans[1]++;
    }else if(S[0] == 'T'){
      Ans[2]++;
    }else if(S[0] == 'R'){
      Ans[3]++;
    }

  }

  cout << "AC x " << Ans[0] << endl;
  cout << "WA x " << Ans[1] << endl;
  cout << "TLE x " << Ans[2] << endl;
  cout << "RE x " << Ans[3] << endl;

  return 0;
}


Measured memory_bytes: 3620
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

int main(){
  int X;
  int A;
  cin >> X >> A;
  if(X<A){
    cout << "0" << endl;
  }
  else{
    cout << "10" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
#include <algorithm>
#include <map>
#include <numeric>
#include <iomanip>

using namespace std;

/* typedef */

typedef long long ll;

/* constant */

const int INF = 1 << 30;
const int MAX = 100;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */

/* function */

/* main */
int main() {

    int n; cin >> n;
    vector< list<int> > v(n, list<int>());
    int q; cin >> q;
    while (q--) {

        int op; cin >> op;
        int t; cin >> t;

        if (op == 0) {
            int x; cin >> x;
            v[t].push_back(x);

        }
        else if (op == 1) {
            if (v[t].empty()) {
                cout << '\n';
                continue;
            }
            list<int>::iterator itr = v[t].begin();
            cout << *itr;
            itr++;
            for (;itr != v[t].end(); itr++) {
                cout << ' ' << *itr;
            }
            cout << '\n';
        }
        else {
            int s; cin >> s;
            swap(s, t);
            if (v[s].empty())
                continue;
            v[t].splice(v[t].end(), move(v[s]));
            v[s].clear();
        }
    }
}



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

int main(){
    string S;
    cin >> S;
    
    int num;
    num = atoi(S.c_str());
    
    int num1100, num0011;
    num1100 = num / 100;
    num0011 = num % 100;
    
    if(num1100 > 12 && num0011 > 12){
        cout << "NA" << endl;
        return 0;
    }else if(num1100 > 12 && num0011 == 0){
        cout << "NA" << endl;
        return 0;
    }else if(num0011 > 12 && num1100 == 0){
        cout << "NA" << endl;
    }else if(num1100 == 0 && num0011 == 0){
        cout << "NA" <<  endl;
        return 0;
    }else if(num1100 == 0 && num0011 <= 12){
        cout << "YYMM" << endl;
    }else if(num1100 <= 12 && num0011 == 0){
        cout << "MMYY" << endl;
    }else if(num1100 <= 12 && num0011 > 12){
        cout << "MMYY" << endl;
        return 0;
    }else if(num1100 > 12 && num0011 <= 12){
        cout << "YYMM" << endl;
        return 0;
    }else{
        cout << "AMBIGUOUS" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
# include <cmath>
# include <iostream>
# include <queue>
# include <set>
# include <stack>
# include <string>
# include <vector>


using namespace std;


vector<int> int2bits(int i, int n) {
    vector<int> bits(n, 0);
    for (int k=0; k<n; k++) {
        if (i>>k & 1) bits[k] = 1;
    }
    return bits;
}


int main() {
    int n; cin >> n;
    vector<int> a(n);
    vector<vector<int>> x(n);
    vector<vector<int>> y(n);

    for (int i=0; i<n; i++) {
        cin >> a[i];
        x[i].resize(a[i]);
        y[i].resize(a[i]);
        for (int j=0; j<a[i]; j++) {
            cin >> x[i][j] >> y[i][j];
            x[i][j]--;
        }
    }

    int ans = 0;

    for (int i=0; i<(int)pow(2, n); i++) {
        vector<int> cand = int2bits(i, n);

        vector<int> type(n);
        for (int k=0; k<n; k++) {
            type[k] = cand[k];
        }

        // cand が定まったときのシミュレーション
        // cout << "cand: ";
        // for (auto elem: cand) cout << elem << ' '; cout << endl;

        int invalid = 0;
        for (int k=0; k<n; k++) {

            if (!cand[k]) continue;

            for (int j=0; j<a[k]; j++) {
                if (type[x[k][j]] != y[k][j]) {
                    invalid = 1;
                    // cout << k << ", " << j << endl;
                    break;
                }
            }
        }

        // cout << "invalid: " << invalid << endl;
        if (invalid) continue;
        // cout << "cand: ";
        // for (auto elem: cand) cout << elem << ' ';
        // cout << endl;
        int n_ones = 0;
        for (auto elem: cand) if (elem) n_ones++;
        // cout << "-> " << n_ones << endl;
        ans = max(ans, n_ones);
        // cout << n_ones << endl;
    }

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



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

using namespace std;

int main(){
    int N, K;
    cin >> N >> K;
    priority_queue<int, vector<int>, greater<int>> q;
    for (int n = 0; n < N;n++){
        int x;
        cin >> x;
        q.push(x);
    }
    int s = 0;
    for (int i = 0; i < K;i++){
        s += q.top();
        q.pop();
    }
    cout << s << "\n";
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n,m;
    cin>>n>>m;
    int l,r,ml,mr;
    ml=1;mr=10000000;
    int flag=1;
    while(m--)
    {
        cin>>l>>r;
        ml=max(ml,l);
        mr=min(mr,r);
    }
    if(mr>=ml)
    {
        if(n>=ml){
            if(n>=mr)
            cout<<mr-ml+1<<endl;
            else
            cout<<n-ml+1<<endl;
            }
            else cout<<0<<endl;

    }
    else
        cout<<0<<endl;

}


Measured memory_bytes: 384
#include <stdio.h>
char B[101];
int A[10];
void Search(int num);
int main(void){
	int i;
	for(i=1;i<=6;i++)
		scanf("%d",&A[i]);
	scanf("%s",B);
	for(i=0;B[i] !='\0';i++){
		switch(B[i]){
			case 'N': Search(2); break;
			case 'W': Search(3); break;
			case 'E': Search(4); break;
			case 'S': Search(5); break;
		}
	}
	printf("%d\n",A[1]);
	return 0;
}
			
void Search(int num){
	int tmp;
	tmp = A[1];
	A[1] = A[num];
	A[num] = A[6];
	A[6] = A[7-num];
	A[7-num] = tmp;
}
		

Measured memory_bytes: 596
#include<stdio.h>
#define N 100
void insertionSort(int *,int);
int main()
{
  int a,b[N],i;
    scanf("%d",&a);
    for(i=0;i<a;i++){
        scanf("%d",&b[i]);
       
    }
    for(i=0;i<a-1;i++)
      printf("%d ",b[i]);
    printf("%d\n",b[a-1]);
    insertionSort(b,a);
    return 0;
}
void insertionSort(int *A,int B){
  int i,v,j,k;
  for(i=1;i<B;i++){
    v=A[i];
    j=i-1;
    while(j>=0&&A[j]>v){
      A[j+1]= A[j];
      j--;
    }
    A[j+1] = v;
    for(k=0;k<B-1;k++)
      printf("%d ", A[k]);
    printf("%d\n", A[B-1]);
  }
}
    



Measured memory_bytes: 2048
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
    ll n,m,i,j,k;
    string s,t;
    cin>>s>>t;
    n=s.size();
    m=t.size();
    ll dp[n+1][m+1];
    
    for(i=0;i<=n;i++)
    {
        for(j=0;j<=m;j++)
        {
            if(i==0||j==0)
            {
                dp[i][j]=0;
                continue;
            }
            if(s[i-1]==t[j-1])
            {
                dp[i][j]=1+dp[i-1][j-1];
            }
            else
            {
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    i=n,j=m;
    string ans="";
    while(i>0&&j>0)
    {
        if(s[i-1]==t[j-1])
        {
            ans=s[i-1]+ans;
            i--;j--;
        }
        else
        {
            if(dp[i-1][j]>dp[i][j-1])
                i--;
            else
                j--;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 70656
import java.util.Scanner;

public class Main {

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

		String S = sc.next();

		boolean hante = true;
		String code = "";
		for (int i = 0; i < S.length(); i++) {
			if (code.equals(String.valueOf(S.charAt(i))) && i != 0) {
				hante = false;
				break;
			}
			code = String.valueOf(S.charAt(i));
		}
		if (hante) {
			System.out.println("Good");
		} else {
			System.out.println("Bad");
		}

	}
}


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

const int MAX=1000000;

vector<int> dx={0,1,0,-1};
vector<int> dy={1,0,-1,0};

int main(){

  int H,W;
  cin>>H>>W;

  vector<char> S(H*W);
  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
      cin>>S[j+i*W];
    }
  }

  //0からkまでとiとjを使うiからjへの最短路dp[k+1][i][j]
  //k=-1のときは辺あれば1なければMAX

  vector<vector<int>> dp(H*W,vector<int>(H*W));
  for(int i=0;i<H;++i){
    for(int j=0;j<W;++j){
      for(int a=0;a<4;++a){
        int ni=i+dx[a];
        int nj=j+dy[a];
        if(ni<0 || ni>=H || nj<0 || nj>=W) continue;
        if(S[j+i*W]=='.' && S[nj+ni*W]=='.'){
          dp[j+i*W][nj+ni*W]=1;
          dp[nj+ni*W][j+i*W]=1;
        }
        else{
          dp[j+i*W][nj+ni*W]=MAX;
          dp[nj+ni*W][j+i*W]=MAX;
      }
    }
  }
}

  for(int i=0;i<H*W;++i){
    for(int j=0;j<H*W;++j){
      if(i!=j && dp[i][j]==0){
        dp[i][j]=MAX;
      }
    }
  }
  
    for(int k=0;k<H*W;++k){
    for(int i=0;i<H*W;++i){
    for(int j=0;j<H*W;++j){
      dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]);
    }
    }
    }

  int ans=0;
  for(int i=0;i<H*W;++i){
    for(int j=0;j<H*W;++j){
      if(dp[i][j]<MAX){
      ans=max(ans,dp[i][j]);
    }
    }
  }

  cout<<ans<<endl;
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

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

void func(long long n, std::vector<long long> a){

    lli ans = INF;

    lli cnt = 0;
    lli sum = 0;
    REP(i,0,n){
        sum+=a[i];
        if((i%2)==0){
            if(sum<=0){
                cnt += (abs(sum)+1);
                sum = 1;
            }
        }
        else{
            if(sum>=0){
                cnt += (abs(sum)+1);
                sum = -1;
            }
        }
    }
    chmin(ans,cnt);

    cnt=0;
    sum=0;
    REP(i,0,n){
        sum+=a[i];
        if((i%2)==0){
            if(sum>=0){
                cnt += (abs(sum)+1);
                sum = -1;
            }
        }
        else{
            if(sum<=0){
                cnt += (abs(sum)+1);
                sum = 1;
            }
        }
    }
    chmin(ans,cnt);
    cout<<ans<<endl;
}

int main(){
    // cout << fixed << setprecision(5);

    long long n;
    scanf("%lld",&n);
    std::vector<long long> a(n);
    for(int i = 0 ; i < n ; i++){
        scanf("%lld",&a[i]);
    }
    func(n, std::move(a));
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--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))
#define lambda(RES_TYPE, ...) (function<RES_TYPE(__VA_ARGS__)>)[&](__VA_ARGS__) -> RES_TYPE
#define method(FUNC_NAME, RES_TYPE, ...) function<RES_TYPE(__VA_ARGS__)> FUNC_NAME = lambda(RES_TYPE, __VA_ARGS__)
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 debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  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;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

int main(){
  int n = in();
  vector<int> line(n);
  foreach(i,line)i=in();
  int q=in();
  rep(_,q){
    int a = in();
    int b = in();
    reverse(line.begin()+a,line.begin()+b);
  }
  foreach(i,line){
    output(i);
  }
  outendl();
}



Measured memory_bytes: 3172
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s[10];
int a[10], b[10], num[10], sum[10];

int main(){
	REP(i, 9){
		cin >> s[i] >> a[i] >> b[i];
		num[i] = a[i] + b[i];
		sum[i] = a[i] * 200 + b[i] * 300;
	}
	REP(i, 9){
		cout << s[i] << " " << num[i] << " " << sum[i] << endl;
	}
}

Measured memory_bytes: 1204
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <iostream>
#include <locale>
#include <numeric>
#include <string>
#include <vector>

using namespace std;

int main(int argc, char const *argv[]) {
    cin.tie(0);
    int n;
    cin >> n;
    int y[n];
    int m[n];
    int d[n];

    for (int i = 0; i < n; i++) {
        cin >> y[i] >> m[i] >> d[i];
    }
    long now;
    now = 999 * 195 + 999 / 3 * 5 + 1;
    long days[n];
    for (int i = 0; i < n; i++) {
        int uruudosi = (y[i] - 1) / 3;
        days[i]      = (y[i] - 1) * 195 + uruudosi * 5;
        if (y[i] % 3 != 0) {
            days[i] += (m[i] - 1) * 20 - (m[i] - 1) / 2 + d[i];
        } else {
            days[i] += (m[i] - 1) * 20 + d[i];
        }
    }

    for (int i = 0; i < n; i++) {
        cout << now - days[i] << endl;
    }
    return 0;
}



Measured memory_bytes: 3080
A, B, K = [int(x) for x in input().split()]

ans = set()
for i in range(A, A + K):
    if i <= B:
        ans.add(i)
for i in range(B - K + 1, B + 1):
    if i>=A:
        ans.add(i)

ans = list(ans)
ans.sort()
for a in ans:
    print(a)


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

int main() {
    int A, B;
    cin >> A >> B;
    int ans = max(max(A + B, A - B), A*B);
    cout << ans << endl;
    return 0;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int32 cnt = 0;
    char prev = '#';
    REP(i,n){
        if(s[i] != prev)cnt++;
        prev = s[i];
    }
    if(cnt / 2 <= k){
        ANS(n-1);
        return 0;
    }
    ANS(n - cnt + 2 * k);
    return 0;
}

Measured memory_bytes: 512