akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>

using namespace std;

#define debug(x) cout << #x << "==" << x << endl;

const int mod = 1000000007;;

typedef long long ll;


void prime_factor(int n, map<int, int> &mp) {

  for(int i = 2; i * i <= n; i++) {
    while(n % i == 0) {
      ++mp[i];
      n /= i;
    }
  }
  if( n != 1) mp[n] += 1;
  
}


int main() {
  ios::sync_with_stdio(false);

  int N;
  cin >> N;
  map<int, int> mp;
  for(int i = 1; i <= N; i++) {
    prime_factor(i, mp);
  }

  ll res = 1;
  for(auto x : mp) {
    res = ((res % mod) * ((x.second + 1) % mod )) % mod;
  } 

  cout << res % mod << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define INF LLONG_MAX/10
#define rep(i,n) for(int i=0;i<n;i++)
#define krep(i,k,n,m) for(int i=k;i<n;i+=m)
#define erep(i,k,n) for(int i=k;i<n;i++)
#define mod 1000000007
//最大公約数
int gcd(int s,int b){
    if(b==0)return s;
    return gcd(b,s%b);
}
signed main(){
    int n,m;
    cin>>n>>m;
    int k;
    cin>>k;
    if(n<k){
        if(m-k+n<0){
            cout<<0<<" "<<0<<endl;
        }
        else{
            cout<<0<<" "<<m-k+n<<endl;
        }
    }
    else{
        cout<<n-k<<" "<<m<<endl;
    }
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define all(x) (x).begin (),(x).end()
#define sqrt(x) sqrt(abs(x))
#define re return
#define sz(x) ((int)(x).size ())
#define prev PREV
#define next NEXT

using ll = long long;
using ii = pair<int, int>;
using ld = long double;
using D = double;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vs = vector<string>;

template<typename T> T abs (T x) { re x < 0 ? -x : x; }
template<typename T> T sgn (T x) { re x < 0 ? -1 : (x > 0 ? 1 : 0); }
template<typename T> T sqr (T x) { re x * x; }
template<typename T> T gcd (T a, T b) { re a ? gcd (b % a, a) : b; }

int n;
int m;
int g[51][51];
int a[50];
int b[50];

int can (ll mask) {
	memset (g, 0, sizeof (g));
	for (int i = 0; i <= 50; i++) g[i][i] = 1;
	for (int i = 0; i <= 50; i++)
		for (int j = 1; j <= 50; j++)
			if ((mask >> j) & 1)
				g[i][i % j] = 1;
	for (int k = 0; k <= 50; k++)
		for (int i = 0; i <= 50; i++)
			for (int j = 0; j <= 50; j++)
				g[i][j] |= g[i][k] & g[k][j];
//	cout << mask << endl;
	for (int i = 0; i < n; i++)
		if (!g[a[i]][b[i]])
			re 0;
	re 1;
}

int main () {
	scanf ("%d", &n);
	for (int i = 0; i < n; i++) scanf ("%d", &a[i]);
	for (int i = 0; i < n; i++) scanf ("%d", &b[i]);
	ll mask = 0;
	while (true) {
		int i = 0;
		while (i < 52 && !can (mask | (((ll)1 << i) - 1))) i++;
		if (i == 52) {
			cout << -1 << endl;
			re 0;
		}
		if (i == 0) break;
		i--;
//		cout << i << endl;
		mask |= (ll)1 << i;
	}
	cout << mask << endl;
	return 0;
}

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

#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

#define ll long long
#define int long long
#define double long double

#define all(a)      (a).begin(),(a).end()
#define sz(x)       (int)x.size()

#define ff first
#define ss second
#define mp make_pair

#define pb push_back
#define endl "\n"

#define bp builtin_popcountll
#define inf 1e18

const int N=1e5+5;
const int M=1e9+7;

void solve()
{
    ll n,x,mod;
    cin >> n >> x >> mod;
    if(n<=2e6)
    {
        ll ans = 0;
        while(n--)
        {
            ans = ans + x;
            x = (x*x)%mod;
        }
        cout<<ans<<"\n";
        return;
    }
    ll ans = 0;
    map<ll,ll> y;
    ll temp = x;
    vector<ll> pre;
    pre.pb(0);
    ll start = -1,end = -1,sz=-1;
    for(ll i=1;;i++)
    {
        ll rem = temp % mod;
        pre.pb(temp);
        if(y.find(rem)!=y.end())   
        {
            start = y[rem];
            end = i-1;
            sz = end - start + 1;
            break;
        } 
        y[rem] = i;
        temp = temp*temp;
        temp %= mod;
    }
    for(ll i=1;i<pre.size();i++)   pre[i] += pre[i-1];
    n -= (start - 1);
    ans += pre[start-1];
    ans += (n/sz)*(pre[end] - pre[start-1]);
    n = n % sz;
    ll i = start;
    while(n--)    ans += pre[i] - pre[i-1],i++;
    cout<<ans;
}

signed main()
{
    FAST

    int t=1;
    // cin>>t;
    for(int tc=1;tc<=t;tc++)
    {
        // cout<<"Case #"<<tc<<": ";
        solve();
    }

}

Measured memory_bytes: 6684
n = int(input())
a = list(map(int,input().split()))
for i in range(n-1):
    if a[i] > 0:
        pass
    else:
        a[i] *= -1
        a[i+1] *= -1
if a[-1] < 0:
    a[-1] *= -1
    a = sorted(a)
    ans = sum(a) - 2*a[0]
else:
    ans = sum(a)
print(ans)

Measured memory_bytes: 14412
n,*s=open(0).read().split()
a=0;b=0;ba=0;ans=0
for s_i in s:
  b+=(s_i[0]=='B')*(not s_i[-1]=='A')
  a+=(not s_i[0]=='B')*(s_i[-1]=='A')
  ba+=(s_i[0]=='B')*(s_i[-1]=='A')
  ans+=s_i.count('AB')
print(ans+ba+min(a,b)-(ba>0)*(a+b==0))

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

#define For(i,a,b) for(int (i) = (a);(i) < (b);i++)
#define Rep(i,n) For((i),0,(n))
#define All(a) (a).begin(),(a).end()
#define sp " "
#define INF 1e9

const int MAX = 402;

typedef long long ll;
const ll MOD = 1000000007;
const ll MOD_9 = 998244353;

bool seen[MAX][MAX];
char Map[MAX][MAX];
int H,W;
void bfs(int x,int y,char C,pair<ll,ll> &p){
    if(x >= H || x < 0 || y >= W || y < 0)return;
    if(seen[x][y] == true)return;
    if(Map[x][y] != C)return;
    seen[x][y] = true;
    char next_c;
    if(C == '#'){
        next_c = '.';
        p.first++;
    }else{
        next_c = '#';
        p.second++;
    }
    bfs(x+1,y,next_c,p);
    bfs(x,y+1,next_c,p);
    bfs(x-1,y,next_c,p);
    bfs(x,y-1,next_c,p);  
}


int main(){
    cin >> H >> W;
    Rep(i,H){
        Rep(j,W){
            cin >> Map[i][j];
            seen[i][j] = false;
        }
    }
    ll ans = 0;
    Rep(i,H){
        Rep(j,W){
            pair<ll,ll> p = make_pair(0,0);
            //if(map[i][j] == '#') p = make_pair(1,0);
            //else p = make_pair(0,1);
            bfs(i,j,Map[i][j],p);
            //cout << p.first << sp << p.second << endl;
            ans += (p.first)*(p.second);
        }
    }
    cout << ans << endl;
    //cin >> H;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e2 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

int mp[maxn][maxn];
int H, h, W, w;
void solve() {
    mem(mp, 0);
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < W; j++) {
            mp[i][j] = 1;
        }
    }
    for (int i = 0; i < w; i++) {
        for (int j = 0; j < H; j++) {
            mp[j][i] = 1;
        }
    }
    int ans = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (mp[i][j] == 0)
                ans++;
        }
    }
    cout << ans << endl;
}
int main() {
#ifdef LOCAL_IM0QIANQIAN
    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
    IO;
#endif // LOCAL_IM0QIANQIAN

    while (cin >> H >> W) {
        cin >> h >> w;
        solve();
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

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

	long long sum = 0;
	int tmp;
	for (int i = 0; i < n; i++) {
		cin >> tmp;
		sum += tmp;
		if (sum >= h) {
			cout << "Yes" << endl;
			return 0;
		}
	}

	cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

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

#define S second
#define F first
#define int long long  
///////
struct node
{
    int l,r;
    int v=0;
    int prsu=0;
    node* le,*ri;
    node(int a,int b)
    {
        l=a;
        r=b;
        le=NULL;
        ri=NULL;
    }
};
void up(node* seg,int in,int val)
{
    seg->v+=val;
    seg->prsu+=in;
    if(seg->l==seg->r)
    {
        return;
    }
    else
    {
        int m=(seg->l+seg->r)>>1;
        if(in<=m)
        {
            if(seg->le==NULL)
                seg->le=new node(seg->l,m);
            up(seg->le,in,val);
        }
        else{
            if(seg->ri==NULL)
                seg->ri=new node(m+1,seg->r);
            up(seg->ri,in,val); 
        }
    }
}
pair<int,int> query(node* seg,int v)
{
    if(seg==NULL||v==0)
        return {0,0};
    if(seg->l==seg->r)
    {
        return {seg->l,v*((seg->prsu)/seg->v)};
    }
    if(seg->le!=NULL&&seg->le->v>=v)
    	return query(seg->le,v);
    pair<int,int> p={0,0};
    if(seg->le!=NULL)
    {
    	p={seg->le->v,seg->le->prsu};
    }
    pair<int,int> p2=query(seg->ri,v-p.F);
    return {p2.F,p2.S+p.S};
}

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int q;
	cin>>q;
	map<int,int> m;
	int c=0;
	int t=0;
	int to=0;
	node* seg=new node(-2000000000,2000000000);
	while(q)
	{
		--q;
		int ty;
		cin>>ty;
		if(ty==1)
		{
			int a,b;
			cin>>a>>b;
			c+=b;
			up(seg,a,1);
			++t;
			to+=a;
		}
		else
		{
			if(t==0)
			cout<<c<<" 0"<<"\n";
			else
			{
				int h=(t+1)/2;
				pair<int,int> p=query(seg,h);
				int prsu=p.S;
				int x=p.F;
				// cout<<prsu<<" ";
				// cout<<c<<"\n";
				cout<<x<<" "<<(h*x-prsu)+c+(to-prsu-(t-h)*x)<<"\n";
			}
		}
	}
}

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

int main()
{
  ll a, b;
  cin >> a >> b;
  
  auto func = [](ll x)
  {
    ll ret;
    for(ll i = (x / 4) * 4; i <= x; i++)
    {
      ret ^= i;
    }
    return ret;
  };
  
  cout << (func(a - 1) ^ func(b)) << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define   ll    long long int
#define   sz    1000100
#define   pb    push_back
#define   py    printf("Yes\n")
#define   pn    printf("No\n")
#define   sc(a) scanf("%lld",&a)
const  double pi=acos(-1);

using namespace std;

ll num[sz];

int main()
{

    ll a,b;
    cin>>a>>b;

    if(b*2>=a)cout<<0<<endl;
    else
        cout<<a-(b*2)<<endl;


    return 0;
}


Measured memory_bytes: 256
l=[int(i) for i in input().split()]
chk=[0]*3
ans=0
st=100
while st:
    st-=1
    for i in range(3):
        for j in l:
            if j%2:
                print(ans)
                exit()
        if len(set(l))==1:
            print(-1)
            exit()
        chk[i]=l[(i+1)%3]//2+l[(i+2)%3]//2
    l=[i for i in chk]
    chk=[0]*3
    ans+=1


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


int main(){
  string s;
  cin>>s;
  int ans = 0 ;
  
  for(int i=0;i<3;i++){

     if( s[i] == '1'){
       ans++;
     }
    
  }

  cout<<ans<<endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IL inline
#define rep(i,j,k) for(int i=j;i<=k;++i)
#define repd(i,j,k) for(int i=j;i>=k;--i)
#define pb push_back
#define db double
#define mp make_pair
#define mp3(a,b,c) mp(mp(a,b),c)
#define pii pair<int,int>
#define piii pair<pii,int>
#define fr first
#define se second
#define ll long long
#define ull unsigned long long
#define pbc(x) __builtin_popcount(x)
#define clr(x) memset(x,0,sizeof x)
#define SIZE(x) (int)(x.size())
const int mod=1e9+7;
IL int pls(int x,int y){x+=y;return x>=mod?x-mod:x;}
IL int dec(int x,int y){x-=y;return x<0?x+mod:x;}
IL int mul(int x,int y){return 1ll*x*y%mod;}
IL int mul(int x,int y,int z){return mul(mul(x,y),z);}
IL int mul(int x,int y,int z,int p){return mul(mul(x,y),mul(z,p));}
IL void add(int &x,int y){x+=y;x=(x>=mod)?x-mod:x;}
IL int fpw(int x,int y,int r=1){for(;y;y>>=1,x=mul(x,x))if(y&1)r=mul(r,x);return r;}
IL int inv(int x){return fpw(x,mod-2);}
IL int gi(){int x;int _w=scanf("%d",&x);return x;}
IL void gi(int &x){int _w=scanf("%d",&x);}
IL void write(int x){printf("%d\n",x);}
void chkmax(int &x,int y){x=(x>y)?x:y;}
void chkmin(int &x,int y){x=(x<y)?x:y;}
const int INF=0x3f3f3f3f;
template<typename T>IL void debug(T x){cerr<<x;return;}
/* --------------------------------------------------------------------------------------------------------- */
const int maxn=1e5+10;
int n,a[maxn],b[maxn];
int main(){
	n=gi();
	rep(i,1,n)a[i]=gi(),b[i]=a[i];
	sort(b+1,b+1+n);
	int cnt=0;
	rep(i,1,n){
		if(abs(i-(lower_bound(b+1,b+1+n,a[i])-b))&1)cnt++;
	}cout<<cnt/2<<endl;
	return 0;
}

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

using namespace std;

vector<int> prefix_function(const vector<int> &s){
	int n = (int)s.size(); vector<int> b(n+1);
	b[0] = -1; int i = 0, j = -1;
	while(i < n){
		while(j >= 0 && s[i] != s[j]) j = b[j];
		b[++i] = ++j;
	}
	return b;
}
vector<bool> kmp(const vector<int> &t, const vector<int> &p){
	vector<int> b = prefix_function(p);
	int n = (int)t.size(), m = (int)p.size();
	vector<bool> occ(n);
	int j = 0;
	for(int i = 0; i < n; i++){
		while(j >= 0 && t[i] != p[j]) j = b[j];
		j++;
		if(j == m){
			occ[i - m + 1] = true;
			j = b[j];
		}
	}
	return occ;
}

const int N = 200005;

int cant[N], ans[N];

void solve(int bit, const vector<int> &a, const vector<int> &b) {
	vector<int> c(b.size());
	for(size_t i = 0; i < b.size(); i++) {
		c[i] = !b[i];
	}
	auto occ = kmp(a, b);
	auto occ_rev = kmp(a, c);
	for(int i = 0; i < (int)b.size(); i++) {
		if(!occ[i] and !occ_rev[i]) cant[i] = true;
		else if(occ_rev[i]) ans[i] |= 1 << bit;
	}
}

int main() {

	int n;
	scanf("%d", &n);
	vector<int> a(n), b(n);
	for(int &x : a) scanf("%d", &x);
	for(int &x : b) scanf("%d", &x);

	vector<int> ta(2 * n), tb(n);
	for(int bit = 0; bit < 30; bit++) {
		for(int i = 0; i < n; i++) {
			ta[i] = ta[n + i] = a[i] >> bit & 1;
			tb[i] = b[i] >> bit & 1;
		}
		solve(bit, ta, tb);
	}

	for(int i = 0; i < n; i++) {
		if(!cant[i]) {
			printf("%d %d\n", i, ans[i]);
		}
	}
}


Measured memory_bytes: 8276
#define ALL(obj) (obj).begin(), (obj).end()

#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>

using namespace std;
typedef long long ll;
const ll INF = 1e18;

ll N;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N;
    vector<ll> P(N);
    for(ll i=0; i<N; i++) {
        cin >> P[i];
    }
    
    ll count = 1;
    ll minValue = P[0];
    for(ll i=1; i<N; i++) {
        if (minValue >= P[i]) {
            minValue = P[i];
            count++;
        }
    }
    
    cout << count << endl;
    
    return 0;
}


Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cstdlib>
#include<numeric>

using namespace std;

#define INF 100000;

int n,A,B,C,l[10],ct=0,ans=100000;

void saiki(int n,int a,int b,int c,int count){
	if(n==0){
		if(a==0||b==0||c==0){
			return;
		}
		ans=min(ans,(count-3)*10+abs(a-A)+abs(b-B)+abs(c-C));
		return;
	}
	saiki(n-1,a,b,c,count);
	saiki(n-1,a+l[n-1],b,c,count+1);
	saiki(n-1,a,b+l[n-1],c,count+1);
	saiki(n-1,a,b,c+l[n-1],count+1);


}

int main(void){

	cin>>n>>A>>B>>C;
	for (int i = 0; i < n; i++) {
		cin>>l[i];
	}

	saiki(n,0,0,0,ct);
	cout<<ans<<"\n";

	return 0;
}


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

bool solve(){
    int n;
    cin >> n;
    if(n == 0) return false;
    vector<int> s(n), p(n), q(n), r(n), c(n), ls;
    for(int i=0;i<n;i++){
        cin >> s[i] >> p[i] >> q[i] >> r[i];
        c[i] = (p[i]+r[i])*4 + q[i]*9;
    }
    int P, Q, R, C;
    cin >> P >> Q >> R >> C;
    for(int i=0;i<n;i++){
        if(p[i] <= P && q[i] <= Q && r[i] <= R && c[i] <= C){
            ls.emplace_back(s[i]);
        }
    }
    if(!ls.empty()){
        for(auto i : ls){
            cout << i << endl;
        }
    }
    else{
        cout << "NA" << endl;
    }
    return true;
}

int main(){
    while(solve());
    return 0;
}



Measured memory_bytes: 3180
#include <stdio.h>
int main(){
  int x,y,r;
  scanf("%d %d",&x,&y);
  
  if(x < y){
    r = x;
    x = y;
    y = r;
  }

  while(y > 0){
    r = x % y;
    x = y;
    y = r;
  }
  printf("%d\n",x);
  
  return 0;
}


Measured memory_bytes: 2128
#include<stdio.h>

int main(void)
{
  int i,j,n,m,a[1000],S,S1;

  while(1)
    {
      scanf("%d",&n);
      scanf("%d",&m);
      if(n==0&&m==0) break;
      for(i=0;i<=n-1;i++)
	{
	  scanf("%d",&a[i]);
	}
      S1=0;
      for(i=0;i<=n-1;i++)
	{
	  for(j=i+1;j<=n-1;j++)
	    {
	      S=a[i]+a[j];
	      if(S<=m && S1<S) S1=S;
	    }
	}
      if(S1==0) printf("NONE\n");
      else printf("%d\n",S1);
    }
  return 0;
}


Measured memory_bytes: 2104
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

vector<int> a;

long long dist(int i, int j) {
	return abs(a[i] - a[j]);
}

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

	a.assign(n + 2, 0);
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}

	long long default_cost = 0;
	for (int i = 1; i < a.size(); i++) {
		default_cost += dist(i, i - 1);
	}

	vector<long long> ans(n, 0);
	for (int i = 1; i <= n; i++) {
		ans[i - 1] = default_cost - (dist(i, i - 1) + dist(i, i + 1)) + dist(i - 1, i + 1);
	}


	for (auto x: ans) {
		cout << x << endl;
	}
	return 0;
}


Measured memory_bytes: 2432
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a,b;
		while(true){
			a = sc.nextInt();
			b = sc.nextInt();
			if(a==0&&b==0)break;
			for(int i=0;i<a;i++){
				for(int j=0;j<b;j++){
					System.out.print("#");
				}
				System.out.print("\n");
			}
			System.out.print("\n");
		}
	}
}



Measured memory_bytes: 38220
n = int(input())
a = list(map(int, input().split()))

a.sort()

good_val = 0
total_cnt = 0
tmp_cnt = 0
over = 0
for i in range(n):
  if good_val == 0:
    good_val = a[i]

  if a[i] == good_val:
    tmp_cnt += 1
    if over == 0 and tmp_cnt == good_val:
      tmp_cnt = 0
      over = 1
    if i == n - 1:
      total_cnt += tmp_cnt
  else:
    total_cnt += tmp_cnt
    good_val = a[i]
    tmp_cnt = 1
    over = 0
    if i == n - 1:
      total_cnt += tmp_cnt

print(total_cnt)

Measured memory_bytes: 15260
import sys

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = [0] * N
    for i in range(N-1):
        ans[A[i]-1] += 1

    print(*ans, sep="\n")


if __name__ == "__main__":
    main()


Measured memory_bytes: 31092
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define DEBUG fprintf(stderr, "Passing [%s] line %d\n", __FUNCTION__, __LINE__)
#define File(x) freopen(x".in","r",stdin); freopen(x".out","w",stdout)

using namespace std;

typedef long long LL;
typedef pair <int, int> PII;
typedef pair <int, PII> PIII;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

inline LL gl()
{
	LL f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

const int INF = 0x3f3f3f3f;

string x, y, s;
struct Node
{
    int id, ty;
    char c;
} a[200003];

int main()
{
    getline(cin, s);
	int q = gi();
	for (int i = 1; i <= q; i+=1)
	{
	    a[i].id = gi();
	    if (a[i].id == 2)
	    {
	        a[i].ty = gi();
	        scanf("%c", &a[i].c);
	    }
	}
	int tot = 0;
	for (int i = 1; i <= q; i+=1)
	{
	    if (a[i].id == 1) 
	    {
	        ++tot;
	    }
	    else 
	    {
	        if (tot & 1)
	        {
	            if (a[i].ty == 1) y = y + a[i].c;
	            else x = a[i].c + x;
	        }
	        else
	        {
    	        if (a[i].ty == 1) x = a[i].c + x;
    	        else y = y + a[i].c;
	        }
	    }
	}
	if (tot & 1) 
	{
	    reverse(s.begin(), s.end());
	    reverse(x.begin(), x.end());
	    reverse(y.begin(), y.end());
	    swap(x, y);
	}
	cout << x << s << y << endl;
	return 0;
}


Measured memory_bytes: 3560
lr = list(map(int, input().split()))
 
l = lr[0]
r = lr[1]
 
ans=2018
tr=min(2019, r-l)
for i in range(l, l+tr):
    for j in range(l+1, l+tr+1):
        ans = min(ans, (i*j)%2019)
        
        
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<string> com(n),str(n);
    set<string> dic;
    for(int i=0;i<n;i++){
        string com,str;
        cin >> com >> str;
        if(com[0] == 'i')dic.insert(str);
        else {
            auto res = dic.find(str);
            cout << ((res != dic.end())?"yes":"no") << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 47512
# coding: utf-8

N = int(input())

H = list(map(int, input().split()))

res = 0
move = 0
for i in range(N-1):
    if H[i] >= H[i+1]:
        move += 1
    else:
        res = max(res, move)
        move = 0

print(max(res, move))


Measured memory_bytes: 14224
//#define _GLIBCXX_DEBUG
//#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
//using namespace atcoder;
#define rep(i,n) for (int i = 0;i < (int)(n);i++)
using ll = long long;
const ll MOD=1000000007;
//const ll MOD=998244353;
const long long INF = 1LL << 60;
const double pi=acos(-1.0);
int dx[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};
int dy[9] = {0, 1, 0, -1, 1, -1, -1, 1, 0};

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



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

  ll N; cin>>N;
  vector<vector<int>> D(N,vector<int>(2)); rep(i,N) rep(j,2) cin>>D[i][j];
  
  for(int i=0;i<=N-3;i++){
    int judge=1;
    for(int j=i;j<i+3;j++){
      if(D[j][0]!=D[j][1]) judge=0;
    }
    if(judge) {cout<<"Yes"<<'\n'; return 0;}
  }
  
  cout<<"No"<<'\n';
  
  return 0;
}


Measured memory_bytes: 3612
#include<stdio.h>

int main(void) {

	int n, i, j;
	char symbol;
	int snum;
	int number;
	int ALL[52];
	int cards[52];
	int a;

	for (i = 0; i < 52; i++) {
		ALL[i] = 1;
	}

	scanf("%d\n", &n);

	for (j = 0; j < n; j++) {
		scanf("%c %d\n", &symbol, &number);
		
		switch (symbol) {
		case 'S':
			snum = 0;
			break;
		case 'H':
			snum = 1;
			break;
		case 'C':
			snum = 2;
			break;
		case 'D':
			snum = 3;
			break;
		}

		cards[j] = snum * 13 + number - 1;

	}

	for (j = 0; j < n; j++) {

		a = cards[j];

		
			ALL[a] = 0;
		

	}

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

		if (ALL[a] == 1) {
			
			if ((a + 1) % 13 == 0) {
				
				number = 13;
				snum = (a + 1 - number) / 13;
			}
			else {
				snum = (a + 1) / 13;
				number = (a + 1) % 13;
			}
			
			switch (snum) {
			case 0:
				symbol = 'S';
				break;
			case 1:
				symbol = 'H';
				break;
			case 2:
				symbol = 'C';
				break;
			case 3:
				symbol = 'D';
				break;
			}

			printf("%c %d\n", symbol, number);

		}
		
	}
	

	return(0);
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

bool odd(string s) {
    for(int i = 0; i < s.size();i+=2) {
        if(s[i] == 'L') return false;
    }
    return true;
}
bool even(string s) {
    for(int i = 1; i < s.size(); i+=2) {
        if(s[i] == 'R') return false;
    }
    return true;
}
int main() {
    string s;
    cin >> s;
    if(odd(s) && even(s)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void debug(String str) {
        boolean debug = false;
        if (debug != false) {
            return;
        }
        System.out.println(str);
    }

    public static void main(String[] args) {

        int N;
        int P[];

        try (Scanner sc = new Scanner(System.in)) {
            N = sc.nextInt();
            P = new int[N];
            for(int i =0;i < N;i++){
                P[i] = sc.nextInt();
            }
        }
        int cnt = 0;;
        for(int i =0;i < P.length;i++){
            if(i+1 != P[i]){
                cnt++;
            }
        }

        if(cnt ==2 ||cnt ==0){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }
        return;
    }
}


Measured memory_bytes: 23892
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>
using namespace std;

typedef long long ll;

#define INF 10e10
#define rep(i,n) for(int i=0; i<n; i++)
#define rep_r(i,n,m) for(int i=m; i<n; i++)
#define END cout << endl
#define MOD 1000000007
#define pb push_back
// 昇順sort
#define sorti(x) sort(x.begin(), x.end())
// 降順sort
#define sortd(x) sort(x.begin(), x.end(), std::greater<int>())

int main() {
  int n; cin >> n;
  ll h,w; cin >> h >> w;
  ll res = 0;
  rep(i,n) {
    ll x,y; cin >> x >> y;
    if (x >= h and y >= w) res++;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <assert.h>
#include <stdlib.h>
#include <time.h>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <string.h>
#include <cmath>
#include <memory.h>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#define ll long long
using namespace std;

void solve() {
    int n;
    cin >> n;
    vector<int> p(n, 0);
    int e;
    for (int i = 0; i < n - 1; ++i) {
        cin >> e;
        p[e - 1]++;
    }
    for (int i = 0; i < n; ++i)
        cout << p[i] << endl;
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int t = 1;
    while(t--)
        solve();
    return 0;
}


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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) (r).begin(),(r).end()
#define gsort(st,en) sort((st),(en),greater<int>())
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using dict = map<string,int>;
using pii = pair<int,int> ;
using pll = pair<ll,ll> ;

const int mod = 1000000007;
constexpr int imax = ((1<<30)-1)*2+1 ;
constexpr int inf = 100000000;
constexpr double PI = acos(-1.0) ;
double eps = 1e-10 ;
const int dy[] = {-1,0,1,0};
const int dx[] = {0,-1,0,1};

inline bool value(int x,int y,int w,int h){
  return (x >= 0 && x < w && y >= 0 && y < h);
}

template<typename T>
void Unique(vector<T> &v){
  sort(all(v));
  v.erase(unique(all(v)),v.end());
}

template<typename T>
T ston(string& str, T n){
  istringstream sin(str) ;
  T num ;
  sin >> num ;
  return num ;
}

void Ans(bool f){
  if(f) cout << "YES"<<endl;
  else cout << "NO"<<endl;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s,s2;
  while(cin >> s >> s2){
    ll ans = 0;
    vector<vector<ll>> dp(s.size()+1,vector<ll>(s2.size()+1,0));
    rep(i,s.size()){
      rep(j,s2.size()){
        if(s[i] == s2[j]){
          dp[i+1][j+1] += dp[i][j]+1;
          ans = max(ans,dp[i+1][j+1]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 128208
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

map<ll, ll> prime_factor(ll n){
    map<ll,ll> com;
    for(ll i = 2LL; i*i<=n; ++i){
        while(n%i==0LL){
            com[i]++;
            n /= i;
        }
    }
    if(n != 1LL)com[n]++;
    return com;
}

int main(){
	ll N; cin>>N;
	// if(N==2){cout<<}
	ll ans = 1LL;
	// map<ll,ll> e1 = prime_factor(N-1LL);
	// ll t = 1LL;
	// for(auto x : e1){
	// 	t *= (x.second+1);
	// }
	ll M = N-1LL;
	for(ll div = 1LL; div*div<=M; ++div){
		if(M%div == 0){
			if(div*div == M)ans++;
			else ans += 2LL;
		}
	}
	ans--;
	// cout<<ans<<endl;
	for(ll k = 2LL; k*k <= N; ++k){
		if(N%k!=0)continue;
		ll tmp1 = N; ll tmp2 = N;
		ll l = N/k;
		while(tmp1%k==0)tmp1/=k; 
		if(tmp1%k == 1)ans++; 
		if(k==l)continue;
		while(tmp2%l==0)tmp2 /=l;
		if(tmp2%l == 1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

// int main(){
// 	ll N;
// 	cin>>N;
// 	if(N==2LL){cout<<1<<endl; return 0;}
// 	if(N==3LL){cout<<2<<endl; return 0;}
// 	ll ans = 3LL;
// 	map<ll, ll> minus1 = prime_factor(N-1LL);
// 	if(minus1.size()!=1){
// 		ll addi = 1LL;
// 		for(auto x : minus1)addi *= (x.second+1);
// 		addi -= 2LL;
// 		if(minus1.count(2) != 0)addi--;
// 		ans += addi;
// 	}
// 	map<ll, ll> me = prime_factor(N);
// 	set<ll> t;
// 	ll cnt = 0LL;
// 	for(auto x : me){
// 		ll radi = x.first;
// 		REP(i,x.second){
// 			t.insert(pow(radi,i));
// 		}
// 		if(x.first != 2 &&x.second >=2LL)cnt+=x.second/2;
// 	}
	
// 	for(auto x: t){
// 		if(x == 2)continue;
// 		if(t.count(x+1))cnt++;
// 	}
// 	ans += cnt;
// 	cout<<ans<<endl;
// 	return 0;
// }

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<algorithm>
//#include<ctime>
//#include<cmath>
//#include<queue>

using namespace std;
#define LL long long

inline int read(){
	int x=0,f=1; char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;
	for(;isdigit(c);c=getchar()) x=x*10+c-'0';
	return x*f;
}
const int INF = 2147483600;
const int MAXN = 100010;

int N; int a[MAXN+1];
int cnt[2][MAXN+10];

int main(){
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	N=read();
	for(int i=1;i<=N;i++) a[i]=read(),cnt[i&1][a[i]]++;
	int ans1=0,ans2=0,ans11=0,ans22=0;
	int pos1,pos2;
	for(int i=1;i<=MAXN;i++){
		if(cnt[1][i]>ans1){
			ans11=ans1;
			ans1=cnt[1][i]; pos1=i;
		} else ans11=max(ans11,cnt[1][i]);
	}
	for(int i=1;i<=MAXN;i++){
		if(cnt[0][i]>ans2){
			ans22=ans2;
			ans2=cnt[0][i]; pos2=i;
		} else ans22=max(ans22,cnt[0][i]);
	}
	if(pos2!=pos1) printf("%d\n",N-ans1-ans2);
	else printf("%d\n",min(N-ans22-ans1,N-ans11-ans2));
	return 0;
}



Measured memory_bytes: 1408
#include <iostream>
#include <cstdio>
#include <sstream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <cctype>
#include <stack>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <cmath>
//#include <bits/stdc++.h>

using namespace std;
typedef long long lolo;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef unsigned long long ulolo;

const int maxn = (int)3e5 + 5;
const int INF = 0x3f3f3f3f;
const lolo inf = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-6;
const int MOD = 1000000007;

template<class T>
inline void read(T &x) {
    x = 0; T flag = 1;char c;
    do { c = (char) getchar(); if (c == '-') break; } while (c < '0' || c > '9');
    if (c == '-') { c = '0', flag = -1;}
    do { x = x * 10 + c - '0';c = (char) getchar();} while (c >= '0' && c <= '9');
    x *= flag;
}
template<class T>
inline void out(T x) {
    if (x > 9) out(x / 10);
    x = x % 10;
    putchar('0' + x);
}

int a[83][83], b[83][83];
bool dp[83][83][80*161];
int main() {
//    freopen("../in.txt", "r", stdin);
    int h, w;
    read(h); read(w);
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            read(a[i][j]);
        }
    }
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            read(b[i][j]);
        }
    }
    int ans=INF;
    dp[0][0][abs(a[0][0]-b[0][0])]=true;
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            for (int k = 0; k <= 80*(i+j); ++k) {
                if (i > 0 && dp[i-1][j][k]) {
                    dp[i][j][abs(k+a[i][j]-b[i][j])] = true;
                    dp[i][j][abs(k-a[i][j]+b[i][j])] = true;
                }
                if (j > 0 && dp[i][j-1][k]) {
                    dp[i][j][abs(k+a[i][j]-b[i][j])] = true;
                    dp[i][j][abs(k-a[i][j]+b[i][j])] = true;
                }
            }
        }
    }
    for (int i = 0; i <= 80*(h+w-1); ++i) {
        if (dp[h-1][w-1][i]) {
            ans = i;
            break;
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 83328
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>

int gcd(int a,int b);

int main()
{
    long int N,X;
    scanf("%ld%ld",&N,&X);

    int y[N],d[N];

    for( int i=0;i<N;i++ ){
        scanf("%d",&y[i]);
        d[i] = abs(X-y[i]);
    }

    int ans;
    int D1 = d[0],D2;

    for( int i=1;i<N;i++ ){
        D2 = gcd(D1,d[i]);
        D1 = D2;
    }
    
    printf("%d\n",D1);

    return 0;
}

int gcd(int a, int b)
{
    int c;

    if (a < b) {
        a+=b; b=a-b; a-=b;
    }

    while (b != 0) {
        c = a % b;
        a = b;
        b = c;
    }

    return a;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
 
int main() {
  
  int n,k=0,i;
  string s,r="Three";
  
  cin >> n;
  
  for(i=0;i<n;i++){
    
    cin >> s;
    if(s=="Y")r="Four";
    
  }
  
  cout << r << endl;
      
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		long H = sc.nextLong();
		long W = sc.nextLong();
		if (H == 1 || W == 1) {
			System.out.println(1);
			System.exit(0);
		}
		if (H * W % 2 == 1) {
			System.out.println(H * W / 2 + 1);
		} else {
			System.out.println(H * W / 2);
		}
	}
}

Measured memory_bytes: 35572
import itertools
n,m,x=map(int,input().split())
lis=tuple(tuple(map(int,input().split())) for _ in range(n)) #再代入しないので二次元tupleでよい
ans=float("inf")

def dfs(progress,skills,nowcost):#実行前においておけば参照できる
    global ans
    if progress==n:
        if all(v>=x for v in skills):
            ans=min(ans,nowcost)
        return 0
    dfs(progress+1,skills,nowcost)
    dfs(progress+1,[a+b for a,b in zip(skills,lis[progress][1:])],nowcost+lis[progress][0])

dfs(0,[0]*m,0)
if ans==float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 9220
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
 
int main(){
    int n;
    cin >> n;
    vector<long long> cities(n+1);
    vector<long long> heros(n+1);
 
    for (int i=0;i<n+1;i++){
        cin >> cities[i];
    }
    for (int i=0;i<n;i++){
        cin >> heros[i];
    }
    heros[n] = 0;
 
    long long acc = 0;
    long long prev_hero = 0;
    long long prev_hero_min = 0;
    for (int i=0;i<n+1;i++){
        acc += min((prev_hero + heros[i]), cities[i]);
        prev_hero = max(heros[i] - max((cities[i] - prev_hero), prev_hero_min), prev_hero_min);
    }
 
    cout << acc << endl;
    return 0;
}

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

using namespace std;

priority_queue<int> q;

int main(){
    int n, m, x;
    long long  s=0;
    cin>>n>>m;
    for(int i=0; i<n; ++i){
        cin>>x;
        q.push(x);
    }
    while(m--){
        x=q.top();
        q.pop();
        x/=2;
        q.push(x);
    }
    while(!q.empty()){
        s+=q.top();
        q.pop();
    }
    cout<<s;
    return 0;
}


Measured memory_bytes: 892
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using ld = long double;
using P = pair<int, int>;
using vs = vector<string>;
using vi = vector<int>;
using vvi = vector<vi>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQG = priority_queue<T, vector<T>, greater<T> >;
const int INF = 100010001;
const ll LINF = (ll)INF*INF*10;
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) {return a < b && (a = b, true);}
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) {return a > b && (a = b, true);}
template<typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) { return is >> p.first >> p.second;}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) { return os << p.first << ' ' << p.second;}



//head



int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vi x(n);
	rep(i, n) cin >> x[i];
	int m;
	ll k;
	cin >> m >> k;
	vi a(m);
	rep(i, m) {
		cin >> a[i];
		a[i] -= 2;
	}

	int lo = log2(double(k))+1.01;
	vvi vec(lo, vi(n-1));
	rep(i, n-1) {
		vec[0][i] = i;
	}
	rep(i, m) {
		swap(vec[0][a[i]], vec[0][a[i]+1]);
	}
	rep(i, lo-1) {
		rep(j, n-1) {
			vec[i+1][j] = vec[i][vec[i][j]];
		}
	}

	vi vv(n-1), vj(n-1);
	rep(i, n-1) vv[i] = i;
	vi::iterator now, pre;
	now = vj.begin();
	pre = vv.begin();
	rep(i, lo) if(k>>i&1) {
		rep(j, n-1) {
			*(now+j) = vec[i][*(pre+j)];
		}
		swap(now, pre);
	}

	vector<ll> len(n-1);
	rep(i, n-1) len[i] = ll(x[i+1])-x[i];

	ll nn = x[0];
	cout << x[0] << '\n';
	rep(i, n-1) {
		nn += len[*(pre+i)] ;
		cout << nn << '\n';
	}
}

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

#define vi vector<int>
#define ll long long int

int main() {

    int N;
    cin >> N;

    ll sum_0 = 0;
    ll sum_1 = 0;
    ll count_0 = 0;
    ll count_1 = 0;

    ll a;
    cin >> a;
    if (a > 0) {
        sum_0 = a;
    }
    else {
        sum_0 = 1;
        count_0 = abs(a-1);
    }

    if (a < 0) {
        sum_1 = a;
    }
    else {
        sum_1 = -1;
        count_1 = abs(a+1);
    }

    for (int i = 1; i < N; i++) {
        cin >> a;

        if (sum_0 * (sum_0 + a) >= 0) {
            if (sum_0 > 0) {
                count_0 += abs(sum_0 + a - (-1));
                sum_0 = -1;
            }
            else {
                count_0 += abs(sum_0 + a - 1);
                sum_0 = 1;
            }
        }
        else {
            sum_0 += a;
        }

        if (sum_1 * (sum_1 + a) >= 0) {
            if (sum_1 > 0) {
                count_1 += abs(sum_1 + a - (-1));
                sum_1 = -1;
            }
            else {
                count_1 += abs(sum_1 + a - 1);
                sum_1 = 1;
            }
        }
        else {
            sum_1 += a;
        }

    }

    cout << min(count_0, count_1) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
const int INF = 1000000001;

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

int main() {
  char s;
  cin >> s;
  cout << (char)(s+1) << endl; 
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(final String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] x = new int[5];
		x[0] = sc.nextInt();
		x[1] = sc.nextInt();
		x[2] = sc.nextInt();
		x[3] = sc.nextInt();
		x[4] = sc.nextInt();
		sc.close();
		int answer = 0;
		for(int i = 0; i < 5; i++) {
			if(x[i] == 0) {
				answer = i + 1;
			}
		}
		prtln(answer);
	}

	public static <T> void prtln(T t) { System.out.println(t); }
}


Measured memory_bytes: 27040
sx,sy,tx,ty = map(int,input().split())

ans = ""
ans += "R" * (tx - sx)
ans += "U" * (ty - sy)
ans += "R"
ans += "D" * (ty - sy + 1)
ans += "L" * (tx - sx + 1)
ans += "U" * (ty - sy + 1)
ans += "R" * (tx - sx)
ans += "U"
ans += "L" * (tx - sx + 1)
ans += "D" * (ty - sy + 1)
ans += "R"

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using pii=pair<int,int>;
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((ll)x.size())
#define MOD (ll)(998244353)
#define INF (2e9)
#define EPS (1e-6)
#ifdef LOCAL_TEST
#define debug(...) do{\
	cerr<<__PRETTY_FUNCTION__<<" - "<<__LINE__<<\
	" : ("#__VA_ARGS__<<") = ";\
	_OUT(__VA_ARGS__);\
}while(0)
template<typename T>void _OUT(T x){cerr<<x<<endl;}
template<typename T,typename...I>void _OUT(T x,I ...tail){cerr<<x<<", ";_OUT(tail...);}
#else
#define debug(...)
#endif

void INIT(){
#ifdef LOCAL_TEST
	freopen("D:\\input.in","r",stdin);
	freopen("D:\\output.out","w",stdout);
	freopen("D:\\error.out","w",stderr);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0);
}

ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }
ll lcm(ll a,ll b) { return a/gcd(a,b)*b; }
ll fpow(ll b,ll p){
	b%=MOD;
	ll ans=1;
	while(p>0){
		if(p&1) ans=(ans*b)%MOD;
		p/=2;
		b=(b*b)%MOD;
	}
	return ans;
}

int dp[10010];

int32_t main() {
	INIT();
	//code...
	int h,n; cin>>h>>n;
	vector<pii> v(n); //pair(weight,cost)
	for(auto &i:v) cin>>i.F>>i.S;
	For(i,1,h) dp[i]=INF;
	dp[0]=0;
	For(i,0,n-1) For(j,1,h){
		if(j<=v[i].F) dp[j]=min(dp[j],v[i].S);
		else dp[j]=min(dp[j],dp[j-v[i].F]+v[i].S);
	}
	cout<<dp[h]<<"\n";
	return 0;
}


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

int main(){
    double x, q;
    while(cin >> q, q != -1.0){
        x = q / 2.0;
        while(abs(x*x*x-q) >= 0.00001*q){
            x = x-(x*x*x-q)/(3*x*x);
        }
        printf("%.6f\n", x);
    }
    return 0;
}

Measured memory_bytes: 0
void main() {
	auto ip = readAs!(int[]), a = ip[0], b = ip[1];
	int[] arr = new int[](999);
	arr[0] = 1;
	foreach(i; 1..999) arr[i] = arr[i-1] + i+1;
	int c;
	int d = b - a;
	foreach(i; 0..998) {
		if(arr[i+1] - arr[i] == d) {
			writeln(arr[i] - a);
		}
	}
}

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.container;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	N := getStdinInt()

	if N%2 == 0 {
		fmt.Printf("0.5\n")
	} else {
		var o float64 = 0
		var n float64 = 0
		o = float64(N/2 + 1)
		n = float64(N)
		fmt.Printf("%f\n", o/n)
	}
}

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func getStdin() string {
	return readLine()
}
func getStdinInt() int {
	str := getStdin()
	rtn, _ := strconv.Atoi(str)
	return rtn
}
func getStdinInt2() (int, int) {
	list := getStdinIntArr()
	return list[0], list[1]
}
func getStdinInt3() (int, int, int) {
	list := getStdinIntArr()
	return list[0], list[1], list[2]
}
func getStdinInt64() int64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return rtn
}
func getStdinIntU64() uint64 {
	str := getStdin()
	rtn, _ := strconv.ParseInt(str, 10, 64)
	return uint64(rtn)
}
func getStdinInt64_2() (int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1]
}
func getStdinInt64_3() (int64, int64, int64) {
	list := getStdinIntArr64()
	return list[0], list[1], list[2]
}
func getStdinIntArr() []int {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.Atoi(val)
	}
	return rtn
}
func getStdinIntArr64() []int64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]int64, len(list))
	for idx, val := range list {
		rtn[idx], _ = strconv.ParseInt(val, 10, 64)
	}
	return rtn
}
func getStdinIntArrU64() []uint64 {
	str := getStdin()
	list := strings.Split(str, " ")
	rtn := make([]uint64, len(list))
	for idx, val := range list {
		r, _ := strconv.ParseInt(val, 10, 64)
		rtn[idx] = uint64(r)
	}
	return rtn
}
func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}
func min64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}
func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}
func max64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}
func abs(n int) int {
	if n < 0 {
		return -n
	}
	return n
}
func abs64(n int64) int64 {
	if n < 0 {
		return -n
	}
	return n
}
func readLine() string {
	buf := make([]byte, 0, 0)
	for {
		l, p, _ := sc.ReadLine()
		buf = append(buf, l...)
		if !p {
			break
		}
	}
	return string(buf)
}


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

int main()
{
    string s;
    cin >> s;

    if(s == "Sunny"){
        cout << "Cloudy";
    }
    else if(s == "Cloudy"){
        cout << "Rainy";
    }
    else{
        cout << "Sunny";
    }
    
    return 0;
}

Measured memory_bytes: 256
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b){
  ll r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return b;
}


ll LCM(ll a,ll b){
  ll c=a,d=b,r,tmp;
/*自然数 a > b を確認・入替*/
  if(a<b){
    tmp=a,a=b,b=tmp;
  }
/*ユークリッドの互除法*/
  r=a%b;
  while(r!=0){
    a=b,b=r,r=a%b;
  }
  return c/b*d;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

vector<pair<char,ll>> runlength(string s,vector<pair<char,ll>> p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
    return p;
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
  return p;
}


ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  string a,b;
  cin>>a>>b;
  rep(i,n){
    cout<<a[i]<<b[i];
  }
  
  cout<<endl;
}

Measured memory_bytes: 256