akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define DEBUG if(0)
#define lli long long int
#define ldouble long double
using namespace std;

const int maxN = 2e5; int n; lli d, a;
struct Monster
{
  lli x, h;
  void read() { scanf("%lld %lld", &x, &h); }
  bool operator<(const Monster &other) const { return x < other.x; }
};
Monster monsters[maxN];

int main()
{
  while (scanf("%d %lld %lld", &n, &d, &a) != EOF)
  {
    for (int i = 0; i < n; i ++)
      monsters[i].read();
    sort(monsters, monsters+n);

    lli ans = 0, acc = 0;
    int prv = 0, j = 0, end = 0;

    for (int i = 0; i < n;)
    {
      lli rem = monsters[i].h - acc;
      DEBUG printf("\t\t%d %lld\n", i, rem);
      lli turns = max(0LL, rem / a + (rem % a != 0));
      ans += turns;
      acc += turns * a;

      prv = max(i, prv);
      while (prv + 1 < n && monsters[i].x + 2*d >= monsters[prv + 1].x) prv ++;
      j = max(i, j);
      while (j + 1 < n && monsters[i].x + 2*d >= monsters[j + 1].x && monsters[j + 1].h <= acc) j ++;

      if (j == n - 1) break;

      end = max(end, j + 1);
      while (end + 1 < n && monsters[j + 1].x + 2*d >= monsters[end + 1].x) end ++;

      for (int jj = prv + 1; jj <= end; jj ++)
        monsters[jj].h += acc;

      DEBUG printf("\t%d %d %d %d | %lld %lld %lld\n", i, prv, j, end, rem, acc, turns);
      i = j + 1;
    }
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 3328
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;

int main(){

ld a,b;
cin >> a >> b;
ll c=a*b;
cout << c << endl;
}


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

#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { return a * b / GCD(a, b); }

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

inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

bool went[305][305];
int g[305][305];

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll h,w,k;
  cin>>h>>w>>k;
  vector<string> s(h);
  rep(i,h) cin>>s[i];
  vector<bool> exist(h,false);
  rep(i,h){
    rep(j,w){
      if(s[i][j]=='#')exist[i]=true;
    }
  }
  
  int cnt=1;
  rep(i,h){
    if(!exist[i])continue;
    bool firstSharp=true;
    rep(j,w){
      if(s[i][j]=='#'&&!firstSharp){
        cnt++;
        g[i][j]=cnt;
      }else{
        if(s[i][j]=='#')firstSharp=false;
        g[i][j]=cnt;
      }
    }
    cnt++;
  }
  rep(i,h){
    if(!exist[i]){
      if(i-1>=0&&g[i-1][0]!=0){
        rep(j,w){
          g[i][j]=g[i-1][j];
        }
      }else{
        rep(j,w){
          g[i][j]=g[i+1][j];
        }
      }
    }
  }
  rrep(i,h){
    if(!exist[i]){
      if(g[i][0]==0){
        if(i-1>=0&&g[i-1][0]!=0){
          rep(j,w){
            g[i][j]=g[i-1][j];
          }
        }else{
          rep(j,w){
            g[i][j]=g[i+1][j];
          }
        }
      }
    }
  }
  rep(i,h){
    rep(j,w){
      cout<<g[i][j];
      if(j!=w-1)cout<<" ";
    }
    cout<<endl;
  }
}


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

int main(){
    int n; cin >> n;
    int t[10][10];
    int c = 0;  

    for(int i = 1; i < 10; i++){
        for(int j = 1; j < 10; j++){
            t[i][j] = 0;
        }
    }

    for(int i = 1; i <= n; i++){
        int head,tail;
        int w  = i;
        tail = w % 10;
        while(w != 0){
            head = w%10;
            w/=10;
        }
        t[head][tail]++;

    }
    for(int i = 1; i < 10; i++){
        for(int j = i; j < 10; j++){
            int b = c;
            if(i == j) c += t[i][j]*t[i][j];
            else c += t[i][j] * t[j][i] * 2;
        }
    }

    cout << c << endl;
    return 0;
}

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

long long MOD = (long long)1e9 + 7;
int main() {
  string s;
  cin>>s;
  reverse(s.begin(), s.end());
  long long a[13];
  for (int i=0; i<13; i++) a[i] = 0;
  if (s[0] == '?') {
    for (int i=0; i<10; i++) a[i] = 1;
  } else {
    int c = s[0] - '0';
    a[c] = 1;
  }
  int len = s.length();
  long long x = 1;
  for (int i=1; i<len; i++) {
    long long b[13];
    x = 10 * x;
    x %= 13;
    for (int j=0; j<13; j++) b[j] = 0;
    if (s[i] == '?') {
      for (int j=0; j<10; j++) {
        for (int k=0; k<13; k++) {
          int m = (x*j + k) % 13;
          b[m] += a[k];
          b[m] %= MOD;
        }
      }
    } else {
      int c = s[i] - '0';
      for (int j=0; j<13; j++) {
        int m = (x*c + j) % 13;
        b[m] += a[j];
        b[m] %= MOD;
      }
    }
    for (int j=0; j<13; j++) a[j] = b[j];
  }
  cout<<a[5]<<endl;
}

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

using namespace std;

int main(){
    int k;
    int a,b;
    cin>>k;
    cin>>a>>b;
    for(int i=a;i<=b;i++)
    {
        if(i%k==0)
        {
            cout<<"OK";
            return 0;
        }
    }
    cout<<"NG";
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <list>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
  for(;;){
    int n,w,d;
    cin >> n >> w >> d;
    if(n == 0 && w == 0 && d == 0) break;
    list<pair<int,int> > v;
    v.push_back(make_pair<int,int>(w,d));
    for(int i=0; i<n; i++){
      int p,s;
      cin >> p >> s;
      list<pair<int,int> >::iterator r = v.begin();
      for(int j = 0; j<p-1; j++){
        r++;
      }
      s %= ((*r).first + (*r).second);
      if(s > (*r).first){
        s -= (*r).first;
        if(s < (*r).second - s){
          v.push_back(make_pair<int,int>((*r).first,s));
          v.push_back(make_pair<int,int>((*r).first,(*r).second-s));
        }else{
          v.push_back(make_pair<int,int>((*r).first,(*r).second-s));
          v.push_back(make_pair<int,int>((*r).first,s));
        }
      }else{
        if(s < (*r).first - s){
          v.push_back(make_pair<int,int>(s,(*r).second));
          v.push_back(make_pair<int,int>((*r).first-s,(*r).second));
        }else{
          v.push_back(make_pair<int,int>((*r).first-s,(*r).second));
          v.push_back(make_pair<int,int>(s,(*r).second));
        }
      }
      v.erase(r);
    }
    vector<int> a;
    for(list<pair<int,int> >::iterator p = v.begin(); p != v.end(); p++){
      a.push_back((*p).first * (*p).second);
    }
    sort(a.begin(),a.end());
    for(int i=0; i<a.size(); i++){
      if(i!=0) cout << " ";
      cout << a[i];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1224
/*

Sviatoslav Bidzilia 2019
CF: anakib1

*/

#include <iostream>
#include <cmath>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <string>
#include <cstdlib>
#include <vector>
#include <bitset>
#include <map>
#include <chrono>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <queue>
#include <ctime>
#include <stack>
#include <set>
#include <list>
#include <deque>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <stdarg.h>
#include <utility>

using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define ull unisgned long long
#define ld long double
#define all(a) a.begin(), a.end()
#define SORT(a) sort(all(a))
#define pii pair<int, int>
#define tii triple<int, int, int>
#define e 1e-7
#define PI acos(-1)
#define inf 1e17
#define vi vector<int>
#define F first
#define S second
#define rng(x) for(int _ = 0; _ < (x); _++)
#define rngi(i, x) for(int i = 0; i < (x); i++)
#define rngsi(s, i, x) for(int i = (s); i <(x); i++)
#define int long long

template<typename A, typename B, typename C>
struct triple
{
	A X;
	B Y;
	C Z;
	triple(A a = 0, B b = 0, C c = 0) :X(a), Y(b), Z(c) {}
};
template<typename A, typename B, typename C>
triple<A, B, C> make_triple(A a = 0, B b = 0, C c = 0)
{
	return triple<A, B, C>(a, b, c);
}
template<typename A, typename B, typename C>
bool operator<(const triple<A, B, C>& a, const triple<A, B, C>& b)
{
	if (a.X != b.X)
		return a.X < b.X;
	if (a.Y != b.Y)
		return a.Y < b.Y;
	return a.Z < b.Z;
}
template<typename T, typename SS>
ostream& operator<<(ostream& ofs, const pair<T, SS>& p)
{
	ofs << "( " << p.F << " , " << p.S << " )";
	return ofs;
}
template<typename T>
void print(T a)
{
	for (auto i : a)
		cout << i << ' ';
	cout << '\n';
}
template<typename T>
T max(T a, T b, T c)
{
	return max(a, max(b, c));
}
template<typename T>
T min(T a, T b, T c)
{
	return min(a, min(b, c));
}
struct custom_hash
{
	static uint64_t splitmix64(uint64_t x)
	{
		x += 0x9e3779b97f4a7c15;
		x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
		x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
		return x ^ (x >> 31);
	}

	size_t operator()(uint64_t x) const
	{
		static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
		return splitmix64(x + FIXED_RANDOM);
	}
};
signed main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	srand(time(NULL));
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	int ans = n + 1;
	for (int d = 2; d * d <= n; d++)
		if (n % d == 0)
			ans = min(ans, d + n / d);
	cout << ans - 2 << '\n';
}

Measured memory_bytes: 384
#include<iostream>
#include<string>
#include<algorithm>    
#include<cmath>
#include<map>
#include<vector>
#include<math.h>
#include<stdio.h>
#include<stack>
#include<queue>
#include<tuple>
#include<cassert>
#include<set>
#include<functional>
//#include<bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define rep(i, x) for(ll i = 0; i < x; i++)
#define rep2(i, x) for(ll i = 1; i <= x; i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1000000000000000000;
const ll mod = 1000000007;
const ll MOD = 998244353;
const ld pi = 3.141592653589793238;

bool isprime(int p) {
	if (p == 1) return false;
	for (int i = 2; i < p; i++) {
		if (p % i == 0) return false;
	}
	return true;
}
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll keta(ll n) {
	ll res = 0;
	while (n >= 1) {
		res += n % 10; n /= 10;
	}
	return res;
}
ll modpow(ll x, ll y) {
	ll res = 1;
	while (y) {
		if (y % 2) { res *= x; res %= mod; }
		x = x * x % mod; y /= 2;
	}
	return res;
}
ll nCk(ll n, ll k) {
	ll a = 1, b = 1;
	for (int h = n - k + 1; h <= n; h++) { a *= h; a %= mod; }
	for (int h = 1; h <= k; h++) { b *= h; b %= mod; }
	return a * modpow(b, mod - 2) % mod;
}
//printf("%.10f\n", n);

ll dp[123456][15];
signed main() {
	ios::sync_with_stdio(false);
	std::cin.tie(nullptr);

	string s; cin >> s;
	ll n = s.size();
	dp[0][0] = 1;
	rep(i, n) {
		if (s[i] == '?') {
			rep(j, 13) {//前回
				rep(k, 10) {//今回の0~9
					dp[i + 1][(j * 10 + k) % 13] += dp[i][j];
					dp[i + 1][(j * 10 + k) % 13] %= mod;
				}
			}
		}
		else {
			rep(j, 13) {
				dp[i + 1][(j * 10 + (s[i] - '0')) % 13] += dp[i][j];
				dp[i + 1][(j * 10 + (s[i] - '0')) % 13] %= mod;
			}
		}
	}
	cout << dp[n][5] << endl;
	return 0;
}

Measured memory_bytes: 15380
mod=1000000007
n=int(input())
d={}
for i in range(2,1001):
    cnt=1
    for j in range(2,i//2+1):
        if i%j==0:
            cnt=0
    if cnt==1:
        d[i]=0
p=list(d.keys())
for k in range(2,n+1):
    for i in p:
        cnt=0
        while k%i==0:
            k=k//i
            cnt+=1
        if cnt!=0:
            d[i]+=cnt
a=list(d.values())
ans=1
for i in a:
    if i!=0:
        ans*=(i+1)
        ans%=mod
print(ans)




Measured memory_bytes: 3064
import heapq

n = int(input())
alist = [(a, 1) for a in map(int, input().split())]

heapq.heapify(alist)

for _ in range(n-1):
  a1 = heapq.heappop(alist)
  a2 = heapq.heappop(alist)
  if a1[0] < a2[0]:
    if a1[0] * 2 < a2[0]:
      heapq.heappush(alist, (a1[0]+a2[0], a2[1]))
    else:
      heapq.heappush(alist, (a1[0]+a2[0], a1[1]+a2[1]))
  elif a2[0] < a1[0]:
    if a2[0] * 2 < a1[0]:
      heapq.heappush(alist, (a1[0]+a2[0], a1[1]))
    else:
      heapq.heappush(alist, (a1[0]+a2[0], a1[1]+a2[1]))
  else:
    heapq.heappush(alist, (a1[0]+a2[0], a1[1]+a2[1]))

print(alist[0][1])


Measured memory_bytes: 21420
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

a,b=map(int,input().split())
print(a*b)

Measured memory_bytes: 61704
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
const int MAXN = 2e5 + 5;

int ans[MAXN];

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

Measured memory_bytes: 2508
#include <iostream>
#include <string>

using namespace std;

int main(){
	string str;
	getline(cin, str);
	for (int i = 0; i < str.size(); i++) {
		char charactor = str.at(i);
		if ('A' <= charactor && charactor <= 'Z')
			charactor += 32;
		else if ('a' <= charactor && charactor <= 'z')
			charactor -= 32;
		cout << charactor;
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 1172
#include <iostream>
#include <string>

using namespace std;

int main()
{
    string s[3];
    for( int i = 0; i < 3; ++i )
        cin >> s[i];
    
    for( int i = 0; i < 3; ++i )
        cout << char(s[i].c_str()[0]-'a'+'A');
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
/********************************************************************************
	
	Code by a weak man who named CYJian, and he hopes the code can get more points.

	Algorithm: 

 ********************************************************************************/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

//{{{ FAST IO AND SOME FUNCTIONS
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define ra read_alpha()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline char read_alpha() { char c = ge; while(!isalpha(c) && c != EOF) c = ge; return c; }
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

int x[1010];
int y[1010];
int len[33];

int main() {
#ifdef LOCAL
	FILE("");
#endif
	int n = ri;
	for(int i = 1; i <= n; i++)
		x[i] = ri, y[i] = ri;
	int tmp = abs(x[1] + y[1]) & 1;
	for(int i = 1; i <= n; i++)
		if((abs(x[i] + y[i]) & 1) != tmp)
			return puts("-1"), 0;
	printf("%d\n1", 32 - tmp);
	len[1] = 1; int N = 1;
	if(tmp) {
		for(int i = 1; i <= 30; i++) printf(" %d", len[++N] = 1 << i);
		puts("");
	} else {
		for(int i = 0; i <= 30; i++) printf(" %d", len[++N] = 1 << i);
		puts("");
	}
	char s[40];
	memset(s, 0, sizeof(s));
	for(int i = 1; i <= n; i++) {
		ll nx = 0, ny = 0;
		for(int j = N; j; --j) {
			ll dx = x[i] - nx, dy = y[i] - ny;
			if(abs(dx) > abs(dy)) {
				if(dx > 0) nx += len[j], s[j] = 'R';
				else nx -= len[j], s[j] = 'L';
			} else {
				if(dy > 0) ny += len[j], s[j] = 'U';
				else ny -= len[j], s[j] = 'D';
			}
		} printf("%s\n", s + 1);
	}
	return 0;
}

Measured memory_bytes: 256
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>

#define ALL(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i < (r); ++i)

using ll = long long;
using ld = long double;
using ull = unsigned long long;

using namespace std;


/*
ll pw(ll a, ll b) {
	ll ans = 1; while (b) {
		while (!(b & 1)) b >>= 1, a = (a * a) % MOD;
		ans = (ans * a) % MOD, --b;
	} return ans;
}
*/

const int N = 210;

ll dd[N][N];

const ll INF = 1e9;

int n;

int main() {
	ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	cout.setf(ios::fixed), cout.precision(20);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            char c;
            cin >> c;
            if (c == '1') {
                dd[i][j] = 1;
            } else {
                dd[i][j] = INF;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        dd[i][i] = 0;
    }
    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                dd[i][j] = min(dd[i][k] + dd[k][j], dd[i][j]);
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            if (dd[i][j] == 1) {
                if (dd[0][i] % 2 == dd[0][j] % 2) {
                    cout << -1 << "\n";
                    return 0;
                }
            }
        }
    }
    ll mx = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            mx = max(mx, dd[i][j]);
        }
    }
    cout << mx + 1 << "\n";
	return 0;
}




Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

int main()
{
    int t;
    cin >> t;
    while(t--){
        int n;
        cin >> n;
        ll a[205];
        for(int i = 0; i < n; i++) cin >> a[i];
        string s;
        cin >> s;
        ll b[64]{0};
        bool f = false;
        for(int i = n - 1; i >= 0; i--){
            if(s[i] == '0'){
                for(int j = 61; j >= 0; j--){
                    if((a[i] >> j) & 1){
                        if(b[j]){
                            a[i] ^= b[j];
                        }
                        else{
                            b[j] = a[i];
                            break;
                        }
                    }
                }
            }
            else{
                for(int j = 61; j >= 0; j--){
                    if((a[i] >> j) & 1){
                        if(b[j]){
                            a[i] ^= b[j];
                        }
                        else{
                            f = true;
                        }
                    }
                }
            }
        }
        if(f) cout << 1 << endl;
        else cout << 0 << endl;
    }
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI (3.1415926535897932384)

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S sum(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
int sgn(const double&r){return (r>EPS)-(r<-EPS);} // a>0  : sgn(a)>0
int sgn(const double&a,const double&b){return sgn(a-b);} // b<=c : sgn(b,c)<=0

template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>void tf(bool b,S t,T f){if(b)puta(t);else puta(f);}
void YN(bool b){tf(b,"YES","NO");}
void Yn(bool b){tf(b,"Yes","No");}
void yn(bool b){tf(b,"yes","no");}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1;for(auto s:t){os<<(a?"":" ")<<s;a=0;}return os;}
template<class S>auto&operator>>(istream&is,vector<S>&t){for(S&a:t)cin>>a;return is;}

/*他のライブラリを入れる場所*/


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    string s;

    cin>>n>>s;
    if(n%2==0 and s.substr(0,n/2)==s.substr(n/2))puta("Yes");
    else puta("No");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#define rep0(i,n) for (int i = 0; i <= (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)
using namespace std;
int main(){
	int n, x;
	int ans = 0;
	cin >> n >> x;
	vector<int>L(n);
	vector<int>LL(n + 1);
	LL[0] = 0;
	rep0(i,n-1){
		cin >> L[i];
		LL[i + 1] = L[i];
	}
	rep1(j, n) {
		LL[j] = LL[j - 1] + LL[j];
	}
	rep0(k, n) {
		if (x >= LL[k])
			++ans;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import sys
N = int(input())
D = [[int(x) for x in input().split()] for _ in range(N)]
D2 = [x[0] == x[1] for x in D]
for i in range(N-2):
    if D2[i] and D2[i+1] and D2[i+2]:
        print("Yes")
        sys.exit()
print("No")


Measured memory_bytes: 9168
//go:generate echo "https://atcoder.jp/contests/abc174/tasks/abc174_b"
package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

type scanner struct{ *bufio.Scanner }

func newScanner(r io.Reader) *scanner {
	s := bufio.NewScanner(r)
	s.Split(bufio.ScanWords)
	s.Buffer(nil, 100000000)
	return &scanner{s}
}

func (s *scanner) Int() int {
	s.Scan()
	n, _ := strconv.Atoi(s.Text())
	return n
}

func (s *scanner) Ints(l int) []int {
	if l == 0 {
		return []int{}
	}
	sl := make([]int, l, l)
	for i := range sl {
		sl[i] = s.Int()
	}
	return sl
}

func (s *scanner) Float64() float64 {
	s.Scan()
	f, _ := strconv.ParseFloat(s.Text(), 64)
	return f
}

func (s *scanner) Floats64(l int) []float64 {
	if l == 0 {
		return []float64{}
	}
	sl := make([]float64, l, l)
	for i := range sl {
		sl[i] = s.Float64()
	}
	return sl
}

func solve(D float64, ps [][]float64) (c int) {
	for _, p := range ps {
		if math.Sqrt(math.Pow(p[0], 2)+math.Pow(p[1], 2)) <= D {
			c++
		}
	}
	return c
}

func main() {
	scan := newScanner(os.Stdin)
	N, D := scan.Int(), scan.Float64()
	ps := make([][]float64, N, N)
	for i := range ps {
		ps[i] = []float64{scan.Float64(), scan.Float64()}
	}
	fmt.Println(solve(D, ps))
}


Measured memory_bytes: 13152
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <set>
#include <vector>
#include <map>
#include <list>
#include <stack>
#define REP(i, n) for(i=0; i<n; i++)
#define REPR(i, n) for(i=n; i>=0; i--)
#define FOR(i, m, n) for(i=m; i<n; i++)
#define max(a, b) ((a)>(b) ? (a):(b))
#define min(a, b) ((a)<(b) ? (a):(b))
#define INF 10000000000
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
typedef pair<double, double> doup;

int main(void) {
    ll n;
    cin >> n;
    ll a[n], i, s=0;
    
    for(i=0; i<n; i++) {
        cin >> a[i];
        a[i]--;
        s+=a[i];
    }
    cout << s << endl;
}

Measured memory_bytes: 256
/* Author : A110011 - 00:19 "CodeIn Hard Way" */

#include<bits/stdc++.h>

#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define sp(x,y)         fixed<<setprecision(y)<<x
typedef long long int ll;

using namespace std;


int find(int i,int j,int m,int n,vector<vector<char>> &res,vector<vector<int>> &dp){
        
     if(i>=m || j>=n){
        return 0;
    }
    
    if(res[i][j]=='#'){
        return 0;
    }
    
   
    
    if(i==m-1 && j==n-1){
        return 1;
    }
    
    if(dp[i][j]!=-1){
        return dp[i][j];
    }
    
    return dp[i][j]=(find(i+1,j,m,n,res,dp)+find(i,j+1,m,n,res,dp))%mod;
    
}

int main(){

	// For fast I/O.
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    
   /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif */
    
   
    int m,n;
    
    cin>>m>>n;
    
    vector<vector<char>> res(m,vector<char>(n));
    
    
    vector<vector<int>> dp(m,vector<int>(n,-1));
    
    
    for(int i=0;i<m;i++){
        for(int j=0;j<n;j++){
            cin>>res[i][j];
        }
    }
   
    int i=0,j=0;
    
    cout<<find(i,j,m,n,res,dp)<<endl;




return 0; 
}


Measured memory_bytes: 5376
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <unordered_map>
#include <climits>
#include <set>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    string S;
    cin >> S;

    int ans1 = 0;
    for (auto c: S) ans1 += (c - '0');

    int ans2 = 0;
    ans2 = (S.front() - '0' - 1) + (S.size() - 1) * 9;

    cout << max(ans1, ans2) << endl;
}
















































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


int main() {
    int N;
    cin>>N;
    int A[N];
    map<int,int>mp;
    rep(i,N){
        cin>>A[i];
        mp[A[i]]++;
    }
    int cnt =0;
    for(auto p: mp){
        if(p.second%2!=0)cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 5376
// A.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

int main(int argc, char* argv[]) {
	string w[7] = { "SUN","MON","TUE","WED","THU","FRI","SAT" };
	string s;
	cin >> s;
	int ans = 0;
	for (int i = 0; i <= 7; ++i) {
		if (w[i] == s) {
			ans = 7 - i;
			break;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define in insert
#define mp make_pair
#define F first
#define pb push_back
#define pf push_front
#define speed ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define test ll t; cin>>t; while(t--)
ll exp(ll x,ll y,ll p){ ll res=1; while(y) {if(y%2) res=(res*x%p)%p; x=(x*x)%p; y/=2; } return res;}
ll exp(ll x,ll y){ ll res=1; while(y) {if(y%2) res=(res*x); x=(x*x); y/=2; } return res;}
int main(){
    ll a,b,c; cin>>a>>b>>c;
    if(a+b+c>=22)
        cout<<"bust";
    else cout<<"win";
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long int mod = 1000000007;
 
int main() {
  long int n, k;
  cin >> n >> k;
  long int ans = 0;
  for(long int i = k; i <= n+1; i++){
    ans=(ans+i*(n-i+1)+1)%mod;
  }
  cout << ans << endl;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  vector<int> t(5);
  rep(i, 5) {
    cin >> t[i];
  }

  sort(t.begin(), t.end(),
       [](int a, int b) {
        if (a % 10 == 0) return true;
        if (b % 10 == 0) return false;
        return (a % 10) > (b % 10);
       });
  int ans = 0;
  rep(i, 4) {
    ans += ((t[i] + 9)/10 * 10);
  }
  cout << ans + t[4] << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#define ss second
#define ff first
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(a) (a).begin(),(a).end()
#define rep(i,a,b) for(int (i) = (a); (i) < (b); (i)++)
#define debug(x) cout << #x << " = " << x << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using ll = long long;
using ii = pair<int,int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<pair<int,int>>;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3fLL;
const int maxn = 1e3+10;


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

	fastio;

	int N,A;

	cin >> N >> A;

	cout << (N%500 > A ? "No" : "Yes") << '\n';

	return 0;
}

Measured memory_bytes: 256
MOD = 10**9+7


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


def read_ints():
    return list(map(int, input().strip().split(' ')))


def pow(b, p):
    ans = 1
    for _ in range(p):
        ans = (ans*b)%MOD
    return ans


def solve():
    """
    if N is odd, 
    N-1 : 2
    N-3 : 2
    0   : 1
    if N is even,
    N-1 : 2
    N-3 : 2
    1   : 1


    1 2 3 4 5 6
    1 2 3 4 5
    """
    N = read_int()
    A = read_ints()
    D = [0]*((N+1)//2)
    if N%2 == 0:
        for a in A:
            if a%2 == 0:
                return 0
            if a >= N:
                return 0
            if D[a//2] == 2:
                return 0
            D[a//2] += 1
    else:
        for a in A:
            if a%2 == 1:
                return 0
            if a >= N:
                return 0
            if D[a//2] == 2:
                return 0
            if D[0] == 2:
                return 0
            D[a//2] += 1
    return pow(2, N//2)


if __name__ == '__main__':
    print(solve())


Measured memory_bytes: 83956
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <string>
#include <iomanip>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <complex>
#include <ctime>


using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e9;

//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用
#define ret return 0

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

using Graph = vector<vector<ll>>;

#define ketasitei setprecision(15) //15桁表示

const ll MOD = 1000000007;
const double PI = 3.1415926535897932;


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n;
	cin >> n;
	int m = n % 10;
	if (m == 2 || m == 4 || m == 5 || m == 7 || m == 9)
	{
		cout << "hon" << endl;
	}
	else if (m == 3)
	{
		cout << "bon" << endl;
	}
	else
	{
		cout << "pon" << endl;
	}

	return 0;
}

Measured memory_bytes: 3612
import java.util.*;

public class Main{
    
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        int M = sc.nextInt();
        int L = sc.nextInt();
        double[][] D = new double[N][N];
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                if(i!=j)
                    D[i][j] =Double.POSITIVE_INFINITY;
            }
        }
        int[][] A = new int[3][M];
        for(int i = 0; i < M; i++){
            A[0][i] = sc.nextInt();
            A[1][i] = sc.nextInt();
            A[2][i] = sc.nextInt();
            if(A[2][i] <= L){
                D[A[0][i]-1][A[1][i]-1] = A[2][i];
                D[A[1][i]-1][A[0][i]-1] = A[2][i];
            }
        }
         
        int Q = sc.nextInt();
        int[][] s = new int[2][Q];
        for(int i = 0; i < Q; i++){
           s[0][i] = sc.nextInt();
           s[1][i] = sc.nextInt();
        }
        sc.close();

        for(int k = 0; k < N; k++){
            for(int i = 0; i < N; i++){
                for(int j = 0; j < N; j++){
                    D[i][j] = Math.min(D[i][j], D[i][k]+D[k][j]);
                }
            }
        }
        
        for(int i = 0; i < N; i++){
            for(int j = 0; j < N; j++){
                if(i == j)
                    D[i][j] = 0;
                else if(D[i][j] > L){
                    D[i][j] = Double.POSITIVE_INFINITY;
                } else
                    D[i][j] = 1;
            }
        }
        for(int k = 0; k < N; k++){
            for(int i = 0; i < N; i++){
                for(int j = 0; j < N; j++){
                    D[i][j] = Math.min(D[i][j], D[i][k]+D[k][j]);
                }
            }
        }
        
        for(int i = 0; i < Q; i++){
            if(D[s[0][i]-1][s[1][i]-1] == Double.POSITIVE_INFINITY)
                System.out.println(-1);
            else
                System.out.println((int)D[s[0][i]-1][s[1][i]-1]-1);
        }
    }
}

Measured memory_bytes: 92112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        String S = scan.next();
        
        int answer = 0;
        for(int i = 1; i < S.length(); i++) {
            if(S.charAt(i - 1) != S.charAt(i)) answer++;
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 13376
import java.util.*;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        int length = str.length();
        int cnt = 0;
        for (int i = 0; i < length; i++) {
            if (str.charAt(i) == 'x') {
                cnt++;
            }
        }
        if (cnt <= 7) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}


Measured memory_bytes: 21204
import java.io.*;
import java.util.*;
import static java.lang.Math.min;
import static java.lang.Math.max;
public class Main {

    private static void solver(InputReader sc, PrintWriter out) throws Exception {
           int n = sc.nextInt();
           int arr[] = new int[n]; int xor=0;
           for(int i=0; i<n; i++){
               arr[i] = sc.nextInt();
               xor ^= arr[i];
           }
           for(int i=0; i<n; i++){
               out.print((xor ^ arr[i])+" ");
           }

    }

    public static void main(String[] args) throws Exception {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        solver(in,out);
        out.close();
    }
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}
class Pair implements Comparable<Pair>{
    int x,y;
    Pair(int x, int y){
        this.x = x;
        this.y = y;
    }
    public int compareTo(Pair p){
        return (int)(this.x - p.x);
    }
}
class Tuple{
    String s;
    int x, y;

    public Tuple(String s, int x, int y) {
        this.s = s;
        this.x = x;
        this.y = y;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Tuple tuple = (Tuple) o;
        return x == tuple.x &&
                y == tuple.y &&
                s.equals(tuple.s);
    }

    @Override
    public int hashCode() {
        return Objects.hash(s, x, y);
    }
}

Measured memory_bytes: 58132
#include <bits/stdc++.h>
#define ll long long
using namespace std;
#define vv vector
#define ff first
#define ss second
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
typedef pair<ll,ll> pll;
typedef vv<ll> vll;
// #define dbg

int main(){
	fastio;
	ll x;
	cin>>x;
	ll ans = 1000*(x/500);
	ans +=  ((x%500 ) /5)*5;
	cout<<ans;
}

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

int main(){

  char c;
  string blood;
  int sum[4]={0,0,0,0};

  while(cin>>c){
    while(cin>>c , c!=',');
    cin >> blood;

    if(blood == "A")sum[0]++;
    else if(blood == "B")sum[1]++;
    else if(blood == "AB")sum[2]++;
    else sum[3]++;

  }

  for(int i=0; i<4; i++)cout << sum[i] << endl;

  return 0;
}

Measured memory_bytes: 1188
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

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

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

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

#define SHOP_MAX 100
#define SPOTS 10
#define INF (-(1e+9))

int main(void) {
    int shops = get_int();
    int i;
    static int map[SHOP_MAX][SPOTS];
    for(i = 0; i < shops; i++) {
        fget_array(map[i], SPOTS);
    }

    static int profits[SHOP_MAX][SPOTS+1]; // [shop_idx][cnt]
    for(i = 0; i < shops; i++) {
        fget_array(profits[i], SPOTS+1);
    }

    int pat, shop, bit;
    int ans = INF;
    // At least one of the spot should be opened.
    for(pat = 1; pat < (1<<SPOTS); pat++) {
        int res = 0;
        for(shop = 0; shop < SHOP_MAX; shop++) {
            int cnt = 0;
            for(bit = 0; bit < SPOTS; bit++) {
                if(!(pat & (1<<bit))) continue; // shutdown
                // on sale
                cnt += map[shop][bit];
            }
            res += profits[shop][cnt];
        }
        ans = max(ans, res);
    }
    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 128
x, n = map(int, input().split())
dic = {}
arr = list(map(int, input().split()))
for i in range(n):
    dic[arr[i]] = True
for i in range(1, 100):
    if x not in dic:
        print(x)
        break
    if x-i in dic:
        if x+i in dic:
            continue
        else:
            print(x+i)
            break
    else:
        print(x-i)
        break


Measured memory_bytes: 9192
import java.util.Scanner;

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

        int a = sc.nextInt();

        int result = a + (int)Math.pow(a, 2) + (int)Math.pow(a, 3);

        System.out.println(result);

    }
}

Measured memory_bytes: 35756
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect
from heapq import heappush, heappop

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

n = INT()
A = LIST()

def solve(lis):
	lis = lis.copy()
	tmp_sum = lis[0]
	lis = lis[1:]
	cnt = 0
	for x in lis:
		if (tmp_sum + x) * tmp_sum < 0:  # 異符号
			tmp_sum += x
		else:
			cnt += abs((-1)**(tmp_sum>0)*(abs(tmp_sum)+1)-x)
			tmp_sum = (-1)**(tmp_sum>0)
	return cnt

if A[0] > 0:
	ans = solve(A)
	B = A.copy()
	B[0] = -1
	ans = min(ans, solve(B)+abs(A[0]+1))
elif A[0] < 0:
	ans = solve(A)
	B = A.copy()
	B[0] = 1
	ans = min(ans, solve(B)+abs(A[0]-1))
else:
	A[0] = 1
	ans = solve(A)+1
	A[0] = -1
	ans = min(ans, solve(A)+1)
print(ans)


Measured memory_bytes: 16344
#include <bits/stdc++.h>
using namespace std;
#define vec(type) vector<type>

int main() {
    int n, k;
    cin >> n >> k;
    vec(int) h(n);
    for (int i = 0; i < n; i++) cin >> h[i];

    sort(h.begin(), h.end());
    reverse(h.begin(), h.end());
    for (int i = 0; i < min(k, n); i++) {
        h[i] = 0;
    }

    long long ans = accumulate(h.begin(), h.end(),0LL);
    cout << ans << endl;
}


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

using namespace std;

#define FAST_IO ios_base:: sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod 1000000007
#define endl "\n"
typedef long long ll;
 
int main(){ 
	
	FAST_IO;
   
	int n,m;
	cin>>n>>m;

	char g[n][m];

	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin>>g[i][j];
		}
	}

	ll dp[n][m];
	
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			dp[i][j]=0;
		}	
	}

	int t = 1;
	for(int i=1; i<n; i++){
		if(g[i][0]=='#')
			t = 0;
		dp[i][0] = t;
	}

	t=1;
	for(int j=1; j<m; j++){
		if(g[0][j]=='#')
			t = 0;
		dp[0][j] = t;
	}

	for(int i=1; i<n; i++){
		for(int j=1; j<m; j++){
			if(g[i][j]=='#')
				continue;
			if(g[i-1][j]=='.')
				dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
			if(g[i][j-1]=='.')
				dp[i][j] = (dp[i][j] + dp[i][j-1])%mod;
		}
	}
	
	/*
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
	*/
	
	
	cout<<dp[n-1][m-1]<<endl;
}
 

Measured memory_bytes: 9088
#include <iostream>

using namespace std;

int main(){
	int W;
	cin>>W;
	int a,b;
	cin>>a>>b;
	if(a > b) swap(a,b);
	if(a+W >= b){
		cout<<0<<endl;
	}
	else{
		cout<<b-a-W<<endl;
	}
}

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

int main() {
  vector<int> a (3);
  for(int i = 0; i < 3; i++){
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  cout << a.at(2)-a.at(1) + a.at(1)-a.at(0) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
long long a[100007][4];
long long mem[100007][4];
long long res = 0;

long long swim(int i,int lst)
{
    if(i == n-1)
        return a[i][lst];
    long long &r = mem[i][lst];
    if(~r)
        return mem[i][lst];
    if(lst == 0)
        r = a[i][0] + max(swim(i+1,1),swim(i+1,2));
    else if(lst == 1)
        r = a[i][1] +max(swim(i+1,0),swim(i+1,2));
    else if(lst == 2)
        r = a[i][2]+ max(swim(i+1,0),swim(i+1,1));
//    cout<<res<<" "<<i<<" "<<lst<<endl;
    return r;
}

int main()
{
    cin>>n;
    memset(mem,-1,sizeof(mem));
    for(int i=0;i<n;++i)
        cin>>a[i][0]>>a[i][1]>>a[i][2];
    long long r = max(swim(0,0),max(swim(0,1),swim(0,2)));
    cout<<r<<endl;
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);


    int n,m;
    cin>>n>>m;

    int s=0;
    loop(i,0,m)
    {
        int x;
        cin>>x;
        s+=x;
    }

    if(s>n)
    {
        cout<< "-1";
    }
    else
    {
        cout<<n-s;
    }


    return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define pb push_back
#define F first
#define S second
//#define biGinf 9e+18
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define inpv(v) for(auto &x:v) cin>>x
#define otpv(v) for(auto &x:v) cout<<x<<nwl
#define otpv2(v) for(auto &x:v) cout<<x<<" "
#define CASES int tt;cin>>tt; while(tt--)
#define for0(i,n) for(int i=0; i<n; i++)
#define for1(i,n) for(int i=1; i<n; i++)
#define sz(v) (int)(v).size()
using vi = vector < int >;
using vii = vector < vi >;
using pii = pair < int , int >;
using vpii = vector < pii >;
using int64 = long long;
//const int64 biGinf = 9e+18;
//const string yo = "YES", no = "NO";
const int inf = 2e9 + 7;
const char nwl = '\n';

string ans(vii &re, string &s, string &t, int i, int j) {
	if (!i or !j) return "";
	if (s[i - 1] == t[j - 1]) {
		return ans(re, s, t, i - 1, j - 1) + s[i - 1];
	} else if ((re[i][j] == re[i - 1][j])) {
		return ans(re, s, t, i - 1, j);
	} else if ((re[i][j] == re[i][j - 1])) {
		return ans(re, s, t, i, j - 1);
	}
}

string lcs(string s, string t) {
	int n = sz(s), m = sz(t);
	vii re(n + 1, vi(m + 1));
	for1(i, n + 1) {
		for1(j, m + 1) {
			if (s[i - 1] == t[j - 1]) {
				re[i][j] = 1 + re[i - 1][j - 1];
			} else {
				re[i][j] = max(re[i][j - 1], re[i - 1][j]);;
			}
		}
	}

	string k = ans(re, s, t, n , m );
	re.clear();
	return k;
}



int main() {
// #ifndef ONLINE_JUDGE
// 	if (fopen("input.txt", "r")) {
// 		freopen("input.txt", "r", stdin);
// 		freopen("output.txt", "w", stdout);
// 	}
// #endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	//ur code
	string s, t;
	cin >> s >> t;
	cout << lcs(s, t) << nwl;
	return 0;
}



Measured memory_bytes: 35968
#include <stdio.h>

int main()
{
    int a, b, r;
    scanf("%d%d", &a, &b);
    if (a < b) {
        int t = a;
        a = b;
        b = t;
    }
    while ((r = a % b) != 0) {
        a = b;
        b = r;
    }
    printf("%d\n", b);
    return 0;
}

Measured memory_bytes: 2712