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

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] p = new int[n];
		for(int i = 0; i < n; i++) p[i] = sc.nextInt();
		int cnt = 0;
		for(int i = 1; i + 1 < n; i++) {
			int max = Math.max(Math.max(p[i], p[i + 1]), p[i - 1]);
			int min = Math.min(Math.min(p[i], p[i + 1]), p[i - 1]);
			int mid = p[i] ^ p[i + 1] ^ p[i - 1] ^ max ^ min;
			if(mid == p[i]) cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 23124
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;

    vector<int> seg1, seg0;
    if(s[0] == '0'){
        seg1.push_back(0);
    }

    int now0=0, now1=0;
    for(int i=0;i<=n;i++){
        if(i < n && s[i] == '1'){
            now1++;
        }
        else{
            if(now1 > 0){
                seg1.push_back(now1);
                now1 = 0;
            }
        }
        
        if(i < n && s[i] == '0'){
            now0++;
        }
        else{
            if(now0 > 0){
                seg0.push_back(now0);
                now0 = 0;
            }
        }
    }
    if(s.back() == '0'){
        seg1.push_back(0);
    }
    if(seg0.size() <= k){
        cout << n << endl;
    }
    else{
        int maxx = 0;
        int accum = seg1[0];
        for(int i=0;i<seg0.size();i++){
            accum += seg0[i] + seg1[i+1];
            if(i >= k){
                accum -= (seg0[i - k] + seg1[i - k]);
            }
            maxx = max(maxx, accum);
        }
        cout << maxx << endl;
    }
    return 0;
}
      

Measured memory_bytes: 1020
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B;
  cin >> A >> B;
  int ans;
  ans = 0;
 
  for (int i = A; i <= B; i++){
   if (i%10 == i/10000 && (i/1000)%10 == (i/10)%10){
     ans++;
   }
  }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
#define erep(i,n) for(int i = 0;i<=n;i++)
#define rep1(i,n) for(int i = 1;i<n;i++)
#define erep1(i,n) for(int i = 1;i<=n;i++)
typedef long long ll;
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vll vector<ll>
#define vbool vector<bool>
#define INF 100000000


int main(){
  int n;
  cin >> n;
  int A[n],B[n];
  rep(i,n) cin >> A[i] >> B[i];
  ll ans = 0;
  for(int i = n-1;i>=0;i--){
    if((A[i]+ans)%B[i] != 0){
      ans += B[i] - (A[i]+ans)%B[i];
    }
  }
  cout << ans << endl;
}




Measured memory_bytes: 1024
char a[500][501];m[500][500];main(i,j,k,x,y,r,M){
for(;scanf("%d%d",&y,&x),x;printf("%d\n",r)){
	for(j=0;j<y;j++)scanf("%s",a[j]);
	for(j=0;j<y;j++)for(r=i=0;i<x;m[j][i]=r,i++)if(a[j][i]=='.')r++;else r=0;
	for(r=i=0;i<x;i++)for(j=0;j<y;j++)for(M=999,k=j;k<y;k++){
		if(M>m[k][i])M=m[k][i];
		if(r<M*(k-j+1))r=M*(k-j+1);
	}
}exit(0);}

Measured memory_bytes: 1824
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <ctype.h>
#include <algorithm>
#include <string>

using namespace std;

#define U unsigned
#define S short
#define L long
#define LL long long 
#define LLU long long unsigned

//Reading and Printing Arrays

//short int
#define rhd(arr, n) for(int aab = 0; aab < n; aab++){scanf("%hd", &arr[aab]);}
#define phd(arr, n) for(int aab = 0; aab < n; aab++){printf("%hd ", arr[aab]);}
//int
#define rd(arr, n) for(int aab = 0; aab < n; aab++){scanf("%d", &arr[aab]);}
#define pd(arr, n) for(int aab = 0; aab < n; aab++){printf("%d ", arr[aab]);}
//unsigned int
#define ru(arr, n) for(int aab = 0; aab < n; aab++){scanf("%u", &arr[aab]);}
#define pu(arr, n) for(int aab = 0; aab < n; aab++){printf("%u ", arr[aab]);}
//long int
#define rld(arr, n) for(int aab = 0; aab < n; aab++){scanf("%ld", &arr[aab]);}
#define pld(arr, n) for(int aab = 0; aab < n; aab++){printf("%ld ", arr[aab]);}
//unsigned long int
#define rlu(arr, n) for(int aab = 0; aab < n; aab++){scanf("%lu", &arr[aab]);}
#define plu(arr, n) for(int aab = 0; aab < n; aab++){printf("%lu ", arr[aab]);}
//long long int
#define rlld(arr, n) for(int aab = 0; aab < n; aab++){scanf("%lld", &arr[aab]);}
#define plld(arr, n) for(int aab = 0; aab < n; aab++){printf("%lld ", arr[aab]);}
//unsigned long long int
#define rllu(arr, n) for(int aab = 0; aab < n; aab++){scanf("%llu", &arr[aab]);}
#define pllu(arr, n) for(int aab = 0; aab < n; aab++){printf("%llu ", arr[aab]);}
//float
#define rf(arr, n) for(int aab = 0; aab < n; aab++){scanf("%f", &arr[aab]);}
#define pf(arr, n) for(int aab = 0; aab < n; aab++){printf("%f ", arr[aab]);}
//double
#define rlf(arr, n) for(int aab = 0; aab < n; aab++){scanf("%lf", &arr[aab]);}
#define plf(arr, n) for(int aab = 0; aab < n; aab++){printf("%lf ", arr[aab]);}
//char
#define rc(arr, n) for(int aab = 0; aab < n; aab++){scanf("%c", &arr[aab]);}
#define pc(arr, n) for(int aab = 0; aab < n; aab++){printf("%c", arr[aab]);}
//string
#define rs(arr) scanf("%s", arr);
#define ps(arr) puts(arr);

//swap
#define swap(a, b, tip) tip tempswap = a;a = b;b = tempswap;
//freopen
#define freopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stdout);

/*       ▄▀▄     ▄▀▄
        ▄█░░▀▀▀▀▀░░█▄
    ▄▄  █░░░░░░░░░░░█  ▄▄
   █▄▄█ █░░▀░░┬░░▀░░█ █▄▄█       */

int min(int a, int b){	return a <= b ? a : b;}
int max(int a, int b){	return a >= b ? a : b;}
int findmin(long long arr[], long long n){int min = 0;for(int i = 1; i < n;min = arr[i] < arr[min] ? i : min, i++);return min;}
int findmax(long long int arr[], long long int n){int max = 0;for(int i = 1; i < n;max = arr[i] > arr[max] ? i : max, i++);return max;}
long long int arrsum(long long arr[], long long int n){long long int sum = 0;for(int i = 0; i < n; sum += arr[i], i++);return sum;}
	
int main(){
	int k, n;
  
	scanf("%d %d", &k, &n);

	int arr[n];

	LL sum = 0, max;

	rd(arr, n);

	max = arr[0] + (k - arr[n - 1]);

	for(int i = 0; i < n - 1; i++){
		max = max < arr[i + 1] - arr[i] ? arr[i + 1] - arr[i] : max;
	}

	printf("%lld", k - max);
}


Measured memory_bytes: 896
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        try{
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            
            //String N = br.readLine();
            int N = Integer.parseInt(br.readLine());
            String strSplit[] = br.readLine().split(" ");
            int A[] = new int[N];
            for(int i=0; i<N; i++){
                A[i] = Integer.parseInt(strSplit[i]);
            }
            
            long ans = 0;
            for(int i=0; i<N-1; i++){
                int a = A[i];
                int b = A[i+1];
                
                if(a > b){
                    ans = ans + a - b;
                    A[i+1] = a;
                }
            }
            
            System.out.println(ans);
            
        }catch(Exception e){
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 61212
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}

int digits(int n) {
    int ret = 0;
    while (n) {
        n /= 10;
        ret++;
    }
    return ret;
}

int main() {
    int n, k;
    cin >> n >> k;
    vi d(k);
    for (int i = 0; i < k; ++i) {
        cin >> d[i];
    }
    sort(d.begin(), d.end());
    int ret = n;
    while (true) {
        int temp = ret;
        bool ok = true;
        while (temp > 9) {
            int dig = temp % 10;
            if (find(d.begin(), d.end(), dig) != d.end())
                ok = false;
            temp /= 10;
        }
        if (find(d.begin(), d.end(), temp) != d.end())
            ok = false;
        if (ok)
            break;
        else
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  int cnt = 0;
  cin >> S >> T;
  
  for(int i = 0;i < S.size(); i++){
    if(S.at(i) != T.at(i))
    	cnt++;
  }
  cout << cnt << endl;
  
}

Measured memory_bytes: 3896
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <cmath>
#include <utility>
using namespace std;
typedef long long int ll;

int main() {
  int N;
  cin>>N;
  
  vector<ll> h(N);
  for(int i=0;i<N;++i){
    cin>>h[i];
  }
  
  bool flag=true;
  
  for(int i=N-2;i>=0;--i){
    if(h[i]-h[i+1]>1){
      flag=false;
      break;
    }
    if(h[i]-h[i+1]==1)
      --h[i];
  }
  
  if(flag)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
}


Measured memory_bytes: 1024
#include<stdio.h>

int main(){
    int N;
    scanf("%d",&N);
    N = N%26;
    
    int s=10001;
    
    char S[s];
    scanf("%s",S);
    for(int i=0;i<s;i++){
        if('\0' == S[i]){
            s = i;
            break;
        }
    }
    
    for(int i=0;i<s;i++){
        S[i] += N;
        if(91 <= S[i]){
            S[i] -= 26;
        }
        printf("%c",S[i]);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a, b, c, d; cin >> a >> b >> c >> d;
	int N; cin >> N;
	N *= 4;
	vector<vector<int>> t(4, vector<int>(4, INF));
	t[0][0] = a * 4; t[1][1] = b * 4; t[2][2] = c * 4; t[3][3] = d * 4;
	rep(i, 0, 4)rep(j, 0, 3) {
		chmin(t[i][j + 1], t[i][j] * 2);
	}
	dump(t);
	int e[4] = { 1,2,4,8 };
	int ans = 0;
	rrep(j, 0, 4) {
		int mini = INF;
		int idx = -1;
		rep(i, 0, 4) {
			if (chmin(mini, t[i][j]))
				idx = i;
		}
		dump(mini, idx);
		ans += mini*(N / e[j]) / 4;
		N %= e[j];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <queue>
using namespace std;
bool visited[100005];
map<int,int> mp;
int main(){
    for(int i = 0; i < 100005; i++) visited[i] = false;
    int n,m;
    cin >> n >> m ;
    vector<vector<int>> g(n);
    for(int i = 0; i < m; i++){
        int a,b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    visited[0] = true;
    queue<int> q;
    q.push(0);
    while(!q.empty()){
        int v = q.front(); q.pop();
        for(int nv:g[v]){
            if(visited[nv]) continue;
            visited[nv] = true;
            mp[nv] = v+1;
            q.push(nv);
        }
    }
    puts("Yes");
    for(int i = 1; i < n; i++) cout << mp[i] << endl;
    return 0;
}

Measured memory_bytes: 14340
#include <stdio.h>

int main(void){
	int num1, num2;

	for (num1 = 1; num1 <= 9; num1++){
		for (num2 = 1; num2 <= 9; num2++){
			printf("%dx%d=%d\n", num1, num2, num1*num2);
		}
	}
	return 0;
}

Measured memory_bytes: 520
#include<stdio.h>
typedef long long LL;

LL f(LL x)
{
    if(x%2)return 11*(x/2)+6;
    return 11*(x/2);
}

int main()
{
    LL s=0,e=1e15,X,mid,mem;
    scanf("%lld", &X);
    while(s<=e){
        mid=(s+e)/2;
        if(f(mid)>=X)mem=mid,e=mid-1;
        else s=mid+1;
    }
    printf("%lld", mem);
    return 0;
}


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

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

  string alp = "abcdefghijklmnopqrstuvwxyz";

  for (int i = 0; i < alp.size(); i++) {
    
    char alpChar = alp.at(i); int count = 0;
    
    for (int j = 0; j < w.size(); j++) {
      char wChar = w.at(j);
      if (alpChar == wChar) count++;
    }
    
    if (count % 2 == 1) {
      cout << "No" << endl;
      return 0;
    }
    
  }

  cout << "Yes" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - 48;}
char myitoc(int N) {return '0' + N;}
 
signed main()
{
  int N, W;
  cin >> N >> W;
  int w0, v0;
  cin >> w0 >> v0;
  vector<vector<int>> V(4);
  V.at(0).push_back(v0);
  for (int i = 1; i < N; i++)
  {
    int w, v;
    cin >> w >> v;
    V.at(w - w0).push_back(v);
  }
  
  vector<vector<int>> S(4);
  for (int i = 0; i < 4; i++)
  {
    sort(V.at(i).begin(), V.at(i).end(), greater<int>());
    S.at(i).push_back(0);
    for (int j = 0; j < V.at(i).size(); j++)
    {
      S.at(i).push_back(S.at(i).at(j) + V.at(i).at(j));
    }
  }
  
  int ans = 0;
  for (int i0 = 0; i0 < S.at(0).size(); i0++)
  {
    for (int i1 = 0; i1 < S.at(1).size(); i1++)
    {
      for (int i2 = 0; i2 < S.at(2).size(); i2++)
      {
        for (int i3 = 0; i3 < S.at(3).size(); i3++)
        {
          int tmp = 0;
          tmp += S.at(0).at(i0);
          tmp += S.at(1).at(i1);
          tmp += S.at(2).at(i2);
          tmp += S.at(3).at(i3);
          cerr << tmp << endl;
          if (w0 * i0 + (w0 + 1) * i1
             + (w0 + 2) * i2 + (w0 + 3) * i3 <= W)
            chmax(ans, tmp);
        }
      }
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

int n;
vector<P> ab, cd;

void solve() {
    sort(ab.begin(), ab.end(), [](P a, P b) { return a.second > b.second; });
    sort(cd.begin(), cd.end());
    int ans = 0;
    bool used[n];
    fill(used, used + n, false);
    rep(i, n) {
        P _xy = cd[i];
        rep(j, n) {
            P xy = ab[j];
            if (!used[j] && xy.first < _xy.first && xy.second < _xy.second) {
                used[j] = true;
                ans++;
                break;
            }
        }
    }
    cout << ans << endl;
}

int main() {
    cin >> n;
    ab.resize(n);
    cd.resize(n);
    int x, y;
    rep(i, n) {
        cin >> x >> y;
        ab[i] = make_pair(x, y);
    }
    rep(i, n) {
        cin >> x >> y;
        cd[i] = make_pair(x, y);
    }
    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect
#define no {cout << -1; return;}
#define yes {cout << "Yes"; return;}
#define mkp make_pair
#define mkt make_tuple
#define cerr if(0) cerr

void solve() {
    int a, b;
    cin >> a >> b;
    cout << max(0ll, a - 2 * b);
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}


Measured memory_bytes: 3628
#include <stdio.h>

int Adj[101][101],n,discover[101];
char color[101];
int Que[100],element_en,element_de;


void Bfs_initialization(){
  int i;
  for(i=1;i<=n;i++){
    discover[i]=-1;
    color[i]='w';
  }
  color[1]='g';
  discover[1]=0;
  
  element_en=0;
  element_de=0;
}

void Bfs_print(){
  int i;
  for(i=1;i<=n;i++)
    printf("%d %d\n",i,discover[i]);
}

int Empty(){
  if(element_en-element_de==0)
    return 1;
  return 0;
}

void Enqueue(int key){
  Que[element_en]=key;
  element_en++;
}

int Dequeue(){
  return Que[element_de++];
}

void Bfs_function(){
  int now,i;
  Bfs_initialization();

  Enqueue(1);
  while(Empty()!=1){
    now=Dequeue();

    i=1;
    while(i<=n){
      if(Adj[now][i]==0 || discover[i]!=-1){
	i++;
	continue;
      }
      discover[i]=discover[now]+1;
      Enqueue(i);
      color[i]='g';
      i++;
    }

    color[now]='b';
  }

  Bfs_print();
}

void Initialization(){
  int i,j;
  for(i=1;i<=n;i++)
    for(j=1;j<=n;j++)
      Adj[i][j]=0;
}

int main(){
  int i,j,element,number,key;
  scanf("%d",&n);
  Initialization();

  for(i=0;i<n;i++){
    scanf("%d%d",&element,&number);
    for(j=0;j<number;j++){
      scanf("%d",&key);
      Adj[element][key]=1;
    }
  }

  Bfs_function();
  return 0;
}


Measured memory_bytes: 2048
import java.util.Scanner;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		int N = S.length();
		int hantei1=((N-1)/2);
		int hantei2=((N+3)/2)-1;
		String a1 = S.substring(0, hantei1);
		String a2 = S.substring(hantei2, N);
		
		if(a1.equals(a2)) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 25172
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int SIZ = 100;
int r, c;
char maz[SIZ + 5][SIZ + 5];
bool pri[SIZ + 5];
int main()
{
  scanf("%d%d", &r, &c);
  int cnt = 0;
  for (int i = 0; i < r; i++)
  {
    bool flag = false;
    scanf("%s", maz[cnt]);
    for (int j = 0; j < c;j++)
      if (maz[cnt][j] == '#')
        flag = true, pri[j] = true;
    if(flag)
      cnt++;
  }

  for (int i = 0; i < cnt;i++)
  {
    for (int j = 0; j < c;j++)
      if (pri[j])
        printf("%c", maz[i][j]);
    printf("\n");
  }
  return 0;
}


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

int main(){
    int x, y, z;
    cin >> x >> y >> z;
    
    int count = 0, sum = z;
    while (sum < x) {
        sum += y + z;
        if (sum <= x) {
            count++;
        }
    }
    
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int MOD = 1e9 + 7;

int main(){
    int n;
    cin >> n;
    int B[n] = {};
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        B[a]++;
    }

    /*
    2の(中央までの個数分)累乗
    奇数の場合でも中央の数は固定なので偶奇関係なし
    */
    long long ans = 1;
    for(int i = 0; i < n / 2; i++){
        ans  = ans * 2 % MOD;
    }

    /*
    奇数：0が1つ
    偶数：0無し
    */
    if(n & 1){
        if(B[0] == 1);
        else ans = 0;
    }else{
        if(B[0]) ans = 0;
    }

    /*
    奇数：奇数番目に2か確認
    偶数：偶数番目に2か確認
    */
    for(int i = 1; i < n; i++){
        if(n & 1){
            if(i & 1){
                if(B[i]){
                    ans = 0;
                    break;
                }
            }else{
                if(B[i] == 2);
                else{
                    ans = 0;
                    break;
                }
            }
        }else{
            if(i & 1){
                if(B[i] == 2);
                else{
                    ans = 0;
                    break;
                }
            }else{
                if(B[i]){
                    ans = 0;
                    break;
                }
            }
        }
    }
    cout << ans << endl; 

    return 0;
}

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

using namespace std;

int main(){
  int N;
  cin >> N;
  if (N % 2 != 0){
    cout << "No" << endl;
  }
  else{
	string S;
    cin >> S;
    bool flag = true;
    for (int i=0; i<S.size() / 2; i++){
      if (S[i] != S[i + S.size() / 2]){
        flag = false;
        break;
      }
    }
    cout << (flag ? "Yes" : "No") << endl;
  }
  return 0;
}
      


Measured memory_bytes: 256
#![allow(non_snake_case, unused_imports)]

// Input
macro_rules! input { (source = $s:expr, $($r:tt)*) => { let mut iter = $s.split_whitespace(); let mut next = || { iter.next().unwrap() }; input_inner!{next, $($r)*} }; ($($r:tt)*) => { let stdin = std::io::stdin(); let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next = move || -> String{ bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect() }; input_inner!{next, $($r)*} }; }
macro_rules! input_inner { ($next:expr) => {}; ($next:expr, ) => {}; ($next:expr, $var:ident : $t:tt $($r:tt)*) => { let $var = read_value!($next, $t); input_inner!{$next $($r)*} }; ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => { let mut $var = read_value!($next, $t); input_inner!{$next $($r)*} }; }
macro_rules! read_value { ($next:expr, ( $($t:tt),* )) => { ( $(read_value!($next, $t)),* ) }; ($next:expr, [ $t:tt ; $len:expr ]) => { (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() }; ($next:expr, [ $t:tt ]) => { { let len = read_value!($next, usize); (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>() } }; ($next:expr, chars) => { read_value!($next, String).chars().collect::<Vec<char>>() }; ($next:expr, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

// Module
use std::cmp::{min,max};
use std::collections::{HashSet,HashMap,BTreeMap,VecDeque};

// Functions

// Main
fn main(){
    input!{
        D: usize,
    }
    print!("Christmas");
    for _ in 0..(25-D){
        print!(" Eve");
    }
}

Measured memory_bytes: 4352
/*
sonu_verma1
*/
#include <bits/stdc++.h>
// For policy based data structure
/*#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> */
using namespace std;
/*using namespace __gnu_pbds; 
typedef tree<int, null_type, less<int>, rb_tree_tag, 
             tree_order_statistics_node_update> 
    new_data_set;*/
 
#define MD 1000000007
#define X first
#define Y second
#define pb push_back
#define debug(val, ch) cout <<val <<ch
#define FOR(i, st, en, ch) for(register int i = (st); i <= (en) ; i += (ch))
#define RFOR(i, st, en, ch) for(register int i = (st); i >= (en) ; i -= (ch))
#define REP(i, j) FOR(i, 0, j, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
 
typedef long long int ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<int, bool> pib;
typedef pair<bool, int> pbi;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL)
/*********************************************************************/
void test(int r1)
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    vector<int>cn(n+1,0);
    ll r=0,w=0;
    int i;
    for(i=0;i<n;i++)
    {
        if(s[i]=='R')
            r++;
        else
            w++;
    }
    if(s[n-1]=='R')
        cn[n-1]=1;
    for(i=n-2;i>=0;i--)
    {
        if(s[i]=='R')
        {
            cn[i]=cn[i+1]+1;
        }
        else
            cn[i]=cn[i+1];
    }
    ll ans=0;
    for(i=0;i<n;i++)
    {
        if(s[i]=='W')
            ans+=cn[i];
    }
    ans=min(ans,min(r,w));
    ll ans1=cn[n-w];
    ans=min(ans,ans1);
    cout<<ans<<endl;


}
/***********************************************************************/
int main()
{
    fast();
    int t=1,r;
    // cin>>t;
    for(r=1;r<=t;r++)
        test(r);
    return 0;
}

Measured memory_bytes: 4348
N = int(input())
a = list(map(int, input().split()))


a = sorted(a, reverse = True)
ans = 0

index_val = int(N//2)
ans += a[0]
for i in range(1, index_val):
    ans += (2 * a[i])
if N % 2 != 0:
    index_val = N//2
    ans += a[index_val]

print(ans)

Measured memory_bytes: 31392
#include <iostream>

#include <iomanip>
using namespace std;
int main(){

   int a,b,c;
    cin>>a>>b>>c;
    if(a>=b && a>=c){
        cout<<((a*10)+c+b);
    }
    else if(b>=a && b>=c){
        cout<<((b*10)+a+c);
    }
     else if(c>=a && c>=b){
        cout<<((c*10)+a+b);
    }






    return 0;
}


Measured memory_bytes: 256
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <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 <bits/stdc++.h>
#include<queue>
#include <numeric>
using namespace std;
 
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
 
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
 template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
 
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define fore(i,a) for(auto &i:a)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
 
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
 
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
 

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

LL lcm(LL a, LL b){
    LL g = gcd(a,b);
    return a/g *b;
}

int main(){
    long long N,A,B;
    cin >> N >> A >> B;
    long long kyori=B-A;
    long long ans=0;
    if(kyori%2==0){
    ans=kyori/2;
    }
    else{
    ans=min(A-1,N-B)+1+(B-A-1)/2;
    }
    cout << ans;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>
#include<sstream>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;


int main()
{
	cin >> t; s = "keyence";
	int sa = sz(t) - 7;
	rep(i, sz(t)) {
		if (s[i] != t[i]) {
			bool flag = false;
			t.erase(i, sa);
			if (s == t) {
				cout << "YES" << endl; return 0;
			}
			else { cout << "NO" << endl; return 0; }
		}
	}
	cout << "YES" << endl;

	return 0;
}


Measured memory_bytes: 3604
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

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

		String p = "peach";
		String a = "apple";
		
		Pattern pp = Pattern.compile(p);
		Pattern pa = Pattern.compile(a);
		
		String[] nico = sc.nextLine().split(" ");
		for (int i = 0; i < nico.length; i++) {
			if (nico[i].contains(p)) {
				Matcher mp = pp.matcher(nico[i]);
				nico[i] = mp.replaceFirst(a);
			} else if (nico[i].contains(a)) {
				Matcher ma = pa.matcher(nico[i]);
				nico[i] = ma.replaceFirst(p);
			}
			
			if (i != (nico.length - 1)) System.out.print(nico[i] + " ");
			else System.out.println(nico[i]);
		}
	}
}

Measured memory_bytes: 25984
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out=0,fh=1;
	char jp=getchar();
	while ((jp>'9'||jp<'0')&&jp!='-')
		jp=getchar();
	if (jp=='-')
		fh=-1,jp=getchar();
	while (jp>='0'&&jp<='9')
		out=out*10+jp-'0',jp=getchar();
	return out*fh;
}
const int MAXN=21;
int n,A[MAXN],B[MAXN],C[MAXN];
int main()
{
	n=read();
	for(int i=1;i<=n;++i)
		A[i]=read();
	for(int i=1;i<=n;++i)
		B[i]=read();
	for(int i=1;i<n;++i)
		C[i]=read();
	int ans=0,lst=-1;
	for(int i=1;i<=n;++i)
	{
		int x=A[i];
		ans+=B[x];
		if(x==lst+1)
			ans+=C[lst];
		lst=x;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

int main() {
	const int64_t MAX = 1e18;
	int64_t s; cin >> s;

	int64_t x3 = 1e9, y2 = 1e9;
	for(int64_t i = 10; i <= 1e9; i *= 10) {
		if(s / i + 1 <= 1e9) {
			x3 = i;
			y2 = s / i + 1;
			break;
		}
	}
	s = x3 * y2 - s;
	int64_t x2 = 0, y3 = 0;
	for(int64_t i = 1; i * i <= s; ++i) {
		if(s % i == 0) {
			if(s / i > 1e9) continue;
			x2 = i;
			y3 = s / i;
			break;
		}
	}
	cout<<0<<" "<<0<<" "<<x2<<" "<<y2<<" "<<x3<<" "<<y3<<endl;
	return 0;
}

Measured memory_bytes: 256
n = str(input())
list_n = list(n)
if list_n[0] == list_n[1] and list_n[1] == list_n[2]:
    print("Yes")
elif list_n[1] == list_n[2] and list_n[2] == list_n[3]:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3060
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}

int main(){

    int x,y;
    cin>>x>>y;
    
    int k=(y-2*x)/2;
    int y2 = (y-2*x);

    if((y2%2==1)||(y2<0)){
        cout<<"No"<<endl;
        return 0;
    }

    int t = x-k;

    if(t<0){
        cout<<"No"<<endl;

    }else{

        cout<<"Yes"<<endl;
    }

return 0;
}


Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	int r, D;
	vector< int > x(2020);
	cin >> r >> D >> x[2000];
	for (int i = 2001; i <= 2010; i++) {
		x[i] = r * x[i - 1] - D;
		cout << x[i] << endl;
	}
	//cout << endl;

	return 0;
}

Measured memory_bytes: 256
bingo = [0] * 9

A = input().split()
A += input().split()
A += input().split()

n = int(input())

for i in range(n):
    b = input()
    if b in A:
        bingo[A.index(b)] = 1        
    
ans = 'No'

for i in range(3):
    if bingo[i] == bingo[i + 3] == bingo[i + 6] == 1:
        ans = 'Yes'

for i in range(3):
    if bingo[3 * i] == bingo[3 * i + 1] == bingo[3 * i + 2] == 1:
        ans = 'Yes'
        
if bingo[0] == bingo[4] == bingo[8] == 1:
        ans = 'Yes'

if bingo[2] == bingo[4] == bingo[6] == 1:
        ans = 'Yes'

print(ans)

Measured memory_bytes: 3188
import sys


def input(): return sys.stdin.readline().strip()


def resolve():
    n = int(input())
    l = list(map(int, input().split()))
    lsort = sorted(l)
    left = lsort[n // 2 - 1]
    right = lsort[n // 2]
    for i in l:
        if i <= left:
            print(right)
        else:
            print(left)
resolve()

Measured memory_bytes: 86100
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  long long int n,i,count,answer,len;
  string str;
  char c;
  char e = 's';
  cin >> str;
  len = str.size();
  c = str.at(len-1);
  if( e == c)
  {
    cout << str << "es";
  }
  else
  {
    cout << str << "s";
  }
  return 0;
}

Measured memory_bytes: 3628
import sys
def sieve(m):
    N=range(1,m+2,2)
    r=int(m**.5)
    h=len(N)
    N[0]=0
    for i in range(h):
        x=N[i]
        if x>r: break
        if x and i+x<h: N[i+x:h:x]=[0]*((h-1-i-x)/x+1)
    return N
def f0056(n):
    x=0
    if n<4:x=0
    elif n==4:x=1
    elif n%2==1:
        if S[(n-2)/2]: x=1
    else:
        a=n/2
        for e in PRIMES:
            if e>a: break
            if S[(n-e)/2]: x+=1
    return x

S=sieve(50000)
PRIMES=filter(None,S)
for n in sys.stdin:
    n=int(n)
    if n==0: break
    print f0056(n)

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

using namespace std;

const int N=1e6+3;

const double eps=0.000000001;

#define pb push_back
#define all(x) (x).begin(),(x).end()
typedef long long ll;

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

const int inf=1e9,mod=1e9+7;

int n,m,a[N],b[N],k,q,u,v,x,y,tc,c,l,r,ans,cnt[100005];

char s[N];

void IO(){
	ios::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("test.txt","r",stdin);
	#endif
}

int main(){
	//IO();
	int n,a,b;
	scanf("%d%d",&a,&b);
	for(int i=1;i<10*N;i++){
		x=i*(0.08);
		y=i*(0.1);
		if (x==a && y==b)
			return !printf("%d\n",i);
	}
	printf("-1\n");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define RFOR(i,a,b) for(int i=(b-1); i>=(a); i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define pb push_back
using ll = long long;
using D = double;
using LD = long double;
using P = pair<int, int>;
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; }
int gcd(int a, int b){ return b ? gcd(b, a%b) : a;}
int lcm(int a, int b){ return a / gcd(a, b) * b;}
int main(){
    int k; cin >> k;
    ll ans = 0;
    FOR(i,1,k+1){
        FOR(j,1,k+1){
            FOR(l,1,k+1){
                ll tmp = (ll)gcd(i,j);
                tmp = (ll)gcd(tmp, l);
                ans += tmp;
            }
        }
    }
    cout << ans << endl;
}


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

int main() {
  int K,S;
  cin >> K>>S;
  int c=0;
  for (int i=0;i<=K;i++){
    for (int j=0;j<=K;j++){
      int z = S-i-j;
      if(z>=0 && z<=K) c++;
    }
  }
cout << c << endl;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define INF 2e9
#define IMAX 1000000007
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long llong;

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

	int max = 0;
	int counting = 0;
	int prev = 0;
	int now = 0;
	bool init = true;
	REP(idx, N) {
		cin >> now;
		if (init) {
			init = false;
		} else {
			if (prev >= now) {
				++counting;
			} else {
				if (max < counting) {
					max = counting;
				}
				counting = 0;
			}
		}
		prev = now;
	}
	if (max < counting) {
		max = counting;
	}

	cout << max << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int a, b, c, d;

int get_score(int i, int y){
    return i * a + y * b + i / 10 * c + y / 20 * d;
}

int main(){
    int h1, h2;
    cin >> h1 >> h2;
    int k1, k2;
    cin >> k1 >> k2;
    cin >> a >> b >> c >> d;
    int hiroshi = get_score(h1, h2);
    int kenjiro = get_score(k1, k2);
    if(hiroshi < kenjiro){
        cout << "kenjiro\n";
    }else if(kenjiro < hiroshi){
        cout << "hiroshi\n";
    }else{
        cout << "even\n";
    }
}


Measured memory_bytes: 3068
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

n = I()
a = LI()

def calc(flag):
    ans = 0
    now = 0
    for i in range(n):
        now += a[i]
        if flag == '+':
            if now <= 0:
                ans += 1-now
                now = 1
            flag = '-'
        else:
            if now >= 0:
                ans += now+1
                now = -1
            flag = '+'
    return ans

print(min(calc('+'),calc('-')))

Measured memory_bytes: 63216
from sys import stdin
import sys
# import itertools
# import math

S = input()
if S == 'zyxwvutsrqponmlkjihgfedcba':
    print(-1)
    sys.exit()
a = [chr(i) for i in range(97, 97+26)]
b = [0 for i in range(26)]
d = dict(zip(a, b))
d1 = d
for i, v in enumerate(S):
    d[v] = d.get(v, 0)+1
for i, v in enumerate(a):
    if d[v] != 1:
        print(S+v)
        sys.exit()
temp = []
temp1 = []

for i in range(25):
    temp1 = []
    temp.append(S[-1-i])
    # print(S[-1-i], S[-1-i-1])
    for k, v in enumerate(temp):
        # print("v="+v)
        # print(S[-1-i-1], ord(S[-1-i-1]), ord(v))
        if S[-1-i-1] < v:
            temp1.append(v)
    # print(temp, temp1)
    if len(temp1) > 0:
        temp1.sort()
        print(S[:-1-i-1]+temp1[0])
        sys.exit()

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] s = sc.next().split("");
        for (int i = 0; i < s.length; i++) {
            if (s[i].equals("U")
                    || s[i].equals("D")
                    || (i % 2 == 0 && s[i].equals("R"))
                    || (i % 2 == 1 && s[i].equals("L"))) {
                continue;
            }
            System.out.println("No");
            return;
        }
        System.out.println("Yes");
    }
}



Measured memory_bytes: 21844
#define _USE_MATH_DEFINES
#include <iostream>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fore(i,a,b) for(int i = (int)a; i < (int)b; i++)
#define fr(i,a,b) for(int i = (int)a - 1; i >= (int)b; i--)
#define inf INT32_MAX
#define N 200005
#define mod 1000000000 + 7

using namespace std;

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

inline void solve()
{
    int x, k;
    cin >> k >> x;
    fore(i,max(-1000000, x - k + 1),min(x + k, 1000001))
    {
        cout << i << ' ';
    }
}


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

Measured memory_bytes: 256
T = input()
count = 0
point = 0
for t in T:
    if count % 2 == 0:
        a = 'g'
    else:
        a = 'p'
    if a=='p' and t=='g':
        point += 1
    elif a=='g' and t=='p':
        point -= 1
    else:
        point += 0
    count += 1
print(point)

Measured memory_bytes: 3316
use proconio::input;

fn main() {
    input!{
        a: i32,
        b: i32,
        c: i32,
        k: i32,
    }
    let ans = if k <= a {
        k
    } else if k <= a + b {
        a
    } else if k <= a + b + c {
        a -1*(k - a - b)
    } else {
        0
    };
    println!("{}", ans);
}

Measured memory_bytes: 2176
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String args[]) throws IOException {
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(isr);
					
		String str, str2;
		
		char l;
		char s;
		
		int sum[] = new int[26];
		
		l = 'A';
		s = 'a';
			
		str = br.readLine();
		str2 = br.readLine();
		
		boolean flag = false;
		
		char ch[] = str.toCharArray();
		char ch2[] = str2.toCharArray();
		for(int i = 0; i < ch.length; i++){
			if(flag == true)break;
			for(int j = 0; j < ch2.length; j++){
				if(ch.length > i + j){
					if(ch2[j] != ch[i + j]){
						break;
					}
				}else{
					if(ch2[j] != ch[i + j - ch.length])break;
				}
				if(j == ch2.length - 1){
					flag = true;
				}
			}
		}
		if(flag == true){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 24340
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>

#define rep(i,n) for(int i = 0;i < n;i++)
#define Rep(i,m,M) for(int i = m;i < M;i++)
#define print(var) cout<<#var" = "<<var<<endl;

typedef long long ll;

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;

ll C = 0,x;

void solve(vector<ll> A)
{
	int len;
	while (1)
	{
		len = A.size();
//			print(len)
		if (A[0] > x)
		{
			C += A[0] - x;
			A[0] = x;
		}
		if (len == 2)
		{
			if (A[0] + A[1] > x)
			{
				C += A[0] + A[1] - x;
			}
			return;
		}
		if (len == 1)
		{
			
			return;
		}
		if (A[0] + A[1] > x)
		{
			C += A[0] + A[1] - x;
			A[1] = x - A[0];

		}
		if (A[len - 2] + A[len - 1] > x)
		{
			C += A[len - 2] + A[len - 1] - x;
			A[len - 2] = x - A[len - 1];
		}
		A.erase(A.begin());
		A.erase(A.end() - 1);
	}
}

void solve2(vector<ll> A)
{
	int len;

		len = A.size();
		//			print(len)
		rep(i, len)
		{
			//	print(A[i])
	//			cout << "A[" << i << "] = " << A[i] << endl;
		}
		rep(i, len - 1)
		{
			if (A[i] + A[i + 1] > x)
			{
				C += A[i] + A[i + 1] - x;
				A[i + 1] = x - A[i];
			}
		}
}

int main()
{
	int N;
	cin >> N >> x;
	vector<ll> a(N);
	rep(i, N)
	{
		cin >> a[i];
	}
	solve(a);
	cout << C;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define FORD(i, a, b) for (ll i = a ; i > b ; i--)
#define hahashad ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
typedef long long ll;
#define VL vector<ll> 
#define what(A) cout<<#A<<" is "<<A<<endl;
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    FOR(i,0,n)
    {
		cin>>a[i];
    }
    sort(a,a+n);
    ll ans=a[n-1],k=n-2,flag=1;
    FOR(i,0,(n-2))
    {
        ans+=a[k];
        if(flag==0)
        {
            flag=1;
            k--;
        }
        else
            flag=0;
    }
    cout<<ans;
}

Measured memory_bytes: 5188
#include <bits/stdc++.h>
#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++)
using namespace std;
using P = pair<int, int>; 
using ll = long long;

int main()
{
  int a[3];
  rep(i, 3){
    cin >> a[i];
  }
  swap(a[0],a[1]);
  swap(a[0],a[2]);
  cout << a[0] << " " << a[1] << " " << a[2] << endl;
  return 0;
}

Measured memory_bytes: 3584
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <unordered_map>
using namespace std;

#define FOR(i,f,t) for(int i=(int)f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=(int)f; i>(int)t; i--)
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define pb push_back
#define SYNC ios_base::sync_with_stdio(false)
#define inf 2248012
#define mp make_pair
#define F first
#define S second
#define ri(x) scanf("%d",&x)
#define rii(x,y) scanf("%d %d",&x,&y)
#define riii(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define lri(x) scanf("%lld",&x)
#define lrii(x,y) scanf("%lld %lld",&x,&y)
#define lriii(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)

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

const int MAXN = 1e5+3; //AREGLAAAAAAAAR!!!!
string s;
int main(){
	SYNC;
	cin>>s;
	int good=1;
	int n= s.size();
	if(s[0]!='A') good=0;
	int cnt =0;
	FOR(i,2,n-1){
		if(s[i]=='C'){
			cnt++;
			s[i]='a';
		}
	}
	if(cnt!=1) good=0;

	FOR(i,1,n) if(s[i]>='A' && s[i]<='Z') good=0;
	if(good) printf("AC\n");
	else printf("WA\n");
}
	

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

int main(){

    int N;
    cin >> N;
    vector <int> x(N+1);  //list and number

    int ii;
    for(int i=2; i<=N; i++){
        ii=i;
        for(int j=2; j<=N; j++){
            while(ii%j==0){
                x.at(j)++;
                ii=ii/j;
            }
        }
    }

    long ans;
    ans=1;
    for(int i=2; i<=N; i++){
        ans=ans*( (long) x.at(i)+1);
        if(ans > (long) 1e9 + 7 ){
            ans=ans%( (long) 1e9 + 7 );
        } 
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256