akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#define N 1000

void push(int);
int pop(void);
void isEmpty(void);
void isFull(void);

int top=0,OK[N];

void push(int a){
  top++;
  OK[top] = a;
}

int pop(){
  top--;
  return OK[top+1];
}

int main(){

  int a,b,i;
  char OK[N];
  while(EOF != scanf("%s",OK)){
    if(OK[0]=='+'){
      a = pop();
      b = pop();
      push(a+b);
    }
    else if(OK[0]=='-'){
      b = pop();
      a = pop();
      push(a-b);
    } 
    else if(OK[0]=='*'){
      a= pop();
      b= pop();
      push(a*b);
    }
    else push(atoi(OK));
  }
  i=pop();
  printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 548
#! /usr/bin/env ruby
# coding: utf-8
while n = gets.to_i
  break if n == 0
  b = []
  c = []
  gets.split.map(&:to_i).each do |t|
    b << t if t % 2 == 0
    c << t if t % 2 == 1
  end
  b.sort!
  c.sort!

  e = Math.sqrt(b[0] * b[1] / c[0]).to_i
  puts e
  puts b.map{|l| l / e}.join(' ')
end

Measured memory_bytes: 9856
#include <stdio.h>
int main(){
int h,w;
while(1){
scanf("%d",&h);scanf("%d",&w);
if(h==0&&w==0)break;

for(int i=1;i<=h;i++)
{

for(int k=1;k<=w;k++)
{
    if(i%2==1){
		if(k%2==1)printf("#");
         else printf(".");
          }else{
if(k%2==1)printf(".");
else printf("#");
}
}
printf("\n");
 
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 1000
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

ll f(ll a){
  if(a<2 || a%2 == 1) return 0;
  else{
    ll b = a;
    ll cnt = 0;
    ll tencnt = 0;
    while(b>=5){
      tencnt ++;
      ll j =1;
      rep(i,tencnt) j *= 5;
      cnt += a/(j*2);
      b /= 5;
    }
    return cnt;
      
      
    
  }
}

int main(void) {
  ll n;
  cin >> n;
  cout << f(n) << endl;
         
         
  
}


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

int main(void){
    int N;
    cin >> N;
    vector<char> A(N), B(N), C(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }
    for (int i = 0; i < N; i++){
        cin >> B[i];
    }
    for (int i = 0; i < N; i++){
        cin >> C[i];
    }

     int count = N*3;
     for (int i = 0; i < N; i++){
         if (A[i] == B[i] && B[i] == C[i]) count -= 3;
         else if (A[i] == B[i] || A[i] == C[i] || B[i] == C[i]) count -= 2;
         else count--;
     }

     cout << count << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define rep1(i,n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
#define reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll H, W;
    cin>>H>>W;
    string a[100];
    bool use[100][100];
    string allwhite="";
    rep(i, H) rep(j, W) use[i][j]=true;
    rep(i, H) cin>>a[i];
    rep(i, W) allwhite+=".";
    rep(i, H){
        if(a[i]==allwhite){
            rep(j, W) use[i][j]=false;
        }
    }
    rep(i, W){
        bool rem=true;
        rep(j, H) if(a[j][i]=='#') rem=false;
        if(rem) rep(j, H) use[j][i]=false;
    }
    rep(i, H){
        bool useline=false;
        rep(j, W){
            if(use[i][j]) useline=true, cout<<a[i][j];
        }
        if(useline) cout<<endl;
    }
    return 0;
}


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

int main() {
  int a=0,b=0,ab=0,o=0,z;
  while(scanf("%d%*c",&z)==1) {
    string s;
    cin >> s;
    if(s=="A") a++;
    else if(s=="B") b++;
    else if(s=="O") o++;
    else ab++;
  }
  cout << a << endl << b << endl << ab << endl << o << endl;
  return 0;
}


Measured memory_bytes: 1236
package main
import (
  "fmt"
  "strings"
  "strconv"
  "log"
)
func main(){
  var s string
  fmt.Scan(&s)
  str := strings.Split(s, "")
  sum := 0
  for i := 0; i < len(str); i++ {
    a, err := strconv.Atoi(str[i])
    if err != nil {
      log.Fatal(err)
    }
    sum += a
  }
  if (sum % 9 == 0) {
    fmt.Println("Yes")
  } else {
    fmt.Println("No")
  }
}

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

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

    vector<ll> a(n);
    for (int i=0; i<n; i++) {
        cin >> a.at(i);
    }

    sort(a.begin(), a.end());

    ll ans = 0;

    vector<ll>::iterator low,up;

    ll ind = 0;

    for (int i=0; i<n; i++) {
        ll k = 1;
        bool findbool = false;
        while (k <= sqrt(a.at(i))) {
            if (a.at(i)%k == 0 && a.at(i)/k > 0) {
                low = lower_bound(a.begin(), a.end(), k);
                ind = low - a.begin();
                if ((ind != i && a.at(ind) == k) || (ind != n-1 && a.at(ind+1) == k)) {
                    findbool = true;
                    break;
                }
                low = lower_bound(a.begin(), a.end(), a.at(i)/k);
                ind = low - a.begin();
                if ((ind != i && a.at(ind) == a.at(i)/k) || (ind != n-1 && a.at(ind+1) == a.at(i)/k)) {
                    findbool = true;
                    break;
                }
            }
            k++;
        }
        if (!findbool) ans++;
    }

    cout << ans << endl;

}


Measured memory_bytes: 4844
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]
x,y = map(int, input().split())
if x in g1 and y in g1:
    print("Yes")
elif x in g2 and y in g2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<iostream>
#include<set>
using namespace std;
int a[200000+50],b[200000+50],c[200000+50],d[200000+50];
int main ()
{
	int i,n,m;
	while(scanf("%d",&n)!=EOF)
	{
		scanf("%d",&m);
		for(i=0;i<m;i++)
		{
			scanf("%d %d",&a[i],&b[i]);
			if(a[i]==1)
				c[b[i]]++;
			if(b[i]==1)
				c[a[i]]++;
			if(a[i]==n)
				d[b[i]]++;
			if(b[i]==n)
				d[a[i]]++;
		}	
		for(i=0;i<n;i++)
			if(c[i]!=0&&d[i]!=0)
			{
				printf("POSSIBLE\n");
				break;
			}	
		if(i==n)
			printf("IMPOSSIBLE\n");
		for(i=0;i<m;i++)
			{a[i]=0;b[i]=0;}
		for(i=0;i<n;i++)
			{
				c[i]=0;d[i]=0;
			}
	}
}

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

using namespace std;

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

#define PI acos(-1.0)
#define INF 1e9+7
#define MOD 1e9+7
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;

string s;
string table[] = { "dreameraser", "dreamerase", "dreamer", "dream", "eraser", "erase" };
string buf;

//string dp[]
//
//void check(string s){
//	if (s.size() < 5){
//		if (s.size() == 0)ans = true;
//		return;
//	}
//	string buf;
//	REP(i, 4){
//		buf = s.substr(0, table[i].size());
//		if (buf == table[i])check(s.substr(table[i].size()));
//	}
//	return;
//}

int main(){
	cin >> s;
	while (s.size() >= 5){
		bool f2 = 0;
		REP(i, 6){
			bool f = 0;
			REP(j, table[i].size()){
				if (s[j] != table[i][j])break;
				if (j == table[i].size() - 1)f = 1;
			}
			if (f){
				f2 = 1;
				s = s.substr(table[i].size());
				break;
			}
		}
		if (!f2)break;
	}
	if (s.size()==0)cout << "YES" << endl;
	else cout << "NO" << endl;
}

Measured memory_bytes: 512
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] D = new int[n];
        Arrays.setAll(D, i -> Integer.parseInt(sc.next()));
        Arrays.sort(D);
        System.out.println(D[n/2] - D[n/2-1]);
    }
}


Measured memory_bytes: 47936
from collections import Counter
import bisect
import sys
s = input()
t = input()
sb = Counter(s)
tb = Counter(t)
S = len(s)
T = len(t)

for i in range(26):
    x = chr(i+97)
    
    if sb[x] == 0 and tb[x] >= 1:
        print(-1)
        sys.exit()
        
le = [[] for i in range(26)]
for i in range(S):
    le[ord(s[i]) - 97].append(i+1)
        
loop = 0
hasu = 0

for i in range(T):
    x = ord(t[i]) - 97
    c = bisect.bisect(le[x],hasu)
    if c == len(le[x]):
        loop += 1
        hasu = le[x][0]
    else:
        hasu = le[x][c]
        
print(loop*S + hasu)

Measured memory_bytes: 80500
#include<stdio.h>
#include<string.h>
char Find(char b[][60],int H,int W,int i,int j)
{
    int t=0;
    if(b[i][j]=='#'){return '#';}
    if(i+1<H&&j<W&&b[i+1][j]=='#'){++t;}
    if(i-1<H&&j<W&&b[i-1][j]=='#'){++t;}
    if(i<H&&j+1<W&&b[i][j+1]=='#'){++t;}
    if(i<H&&j-1<W&&b[i][j-1]=='#'){++t;}
    if(i+1<H&&j+1<W&&b[i+1][j+1]=='#'){++t;}
    if(i+1<H&&j-1<W&&b[i+1][j-1]=='#'){++t;}
    if(i-1<H&&j+1<W&&b[i-1][j+1]=='#'){++t;}
    if(i-1<H&&j-1<W&&b[i-1][j-1]=='#'){++t;}
    return '0'+t;
}
int main()
{
    char a[60][60];
    int H,W,i,j;
    while(~scanf("%d %d",&H,&W))
    {
        for(i=0;i<H;++i)
        {
            scanf("%s",&a[i]);
        }
        for(i=0;i<H;++i)
        {
            for(j=0;j<W;++j)
            {
                if(a[i][j]!='#')
                {
                    printf("%c",Find(a,H,W,i,j));
                }
                else
                {
                    printf("#");
                }
            }
            printf("\n");
        }
        memset(a,0,sizeof(a));
    }
    return 0;
}


Measured memory_bytes: 128
N = int(input())
S = list(input())

accLeft = [0]
accRight = [0]

tmp = 0
for c in S:
  tmp += int(c == 'W')
  accLeft.append(tmp)
accLeft.append(0)

tmp = 0
for c in S[::-1]:
  tmp += int(c == 'E')
  accRight.append(tmp)
accRight.append(0)
accRight = accRight[::-1]

print(min([accLeft[i-1] + accRight[i+1] for i in range(1, N+1)]))

Measured memory_bytes: 94908
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <iostream>
#include <set>
using namespace std;
typedef long long ll;

int a, b;

int main(int argc, char const *argv[]) {
	cin >> a >> b;
	cout << a*b << " " << 2*(a+b) << endl;
	return 0;
}

Measured memory_bytes: 3040
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <complex>
#include <cstring>
#include <cmath>
#include <string>
using namespace std;
#define min(a,b) a<b?a:b;
#define max(a,b) a>b?a:b;
#define LL long long
const int N = 100010;
struct  node{
	double x,y,z;
}e[30];
double map[30][30],sum,ans;
bool vis[30];
int n,m;
void dfs(int step,int pos)
{
	int i,j;
	if(step==m)
	{
		sum=0;
		for(i=1;i<=n;i++)
			for(j=1;j<=i;j++)
				if(vis[i]&&vis[j])
					sum+=map[i][j];
		if(sum>ans)
			ans=sum;
	}
	for(i=pos;i<=n;i++)
	{
		if(!vis[i])
		{
			vis[i]=1;
			dfs(step+1,i+1);
			vis[i]=0;
		}
	}
}
int main()
{
	int i,j;
	while(scanf("%d%d",&n,&m)==2)
	{
		for(i=1;i<=n;i++)
			scanf("%lf%lf%lf",&e[i].x,&e[i].y,&e[i].z);
		for(i=1;i<=n;i++)
			for(j=1;j<=i;j++)
				map[i][j]=(e[i].x-e[j].x)*(e[i].x-e[j].x)+(e[i].y-e[j].y)*(e[i].y-e[j].y)+(e[i].z-e[j].z)*(e[i].z-e[j].z);
		memset(vis,0,sizeof(vis));
		ans=0;
		dfs(0,1);
		printf("%lf\n",ans);
	}
	return 0;
}

Measured memory_bytes: 892
#include<iostream>
using namespace std;
int main(){
  int bell,P[39]={0};
  for(int i=0;i<28;i++){
    cin >> bell;
    P[bell]++;
  }
  for(int i=1;i<=30;i++){
    if(P[i]==0){
      cout << i << endl;
    }
  }
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()

int main()
{
    set<int> se;
    rep(i,3){
        int a;
        cin >> a;
        se.insert(a);
    }
    cout << se.size() << '\n';
    return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
using namespace std;
int main() {
int N, next_light = 0, count = 0;
cin >> N;
vector<int> a(N);
for (int i = 0; i < N; ++i) cin >> a[i];
for (int i = 0; i < N + 1; ++i) {
        next_light = a[next_light] - 1;
        ++count;
        if (next_light == 1) break;
}
if (count > N) cout << -1; 
else cout << count;
}

Measured memory_bytes: 640
#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 FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<vector<int> > VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}
long comb(int N,int K)
{
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

    int N;
    cin >> N;
    VI P(N), Q(N);
    REP(i,N) cin >> P[i];
    REP(i,N) cin >> Q[i];

    VI order(N);
    REP(i,N) order[i] = i+1;

    int cnt = 0, a, b;
    do {
        if (order == P) a = cnt;
        if (order == Q) b = cnt;
        cnt++;
    } while(next_permutation(ALL(order)));

    cout << abs(a-b) << endl;
}

Measured memory_bytes: 256
/**
 * Created by kaki on 2017/04/17.
 */

import java.util.Scanner;

public class Main {
    public static void main(String args[]) {
        Scanner scan = new Scanner(System.in);
        int a = Integer.parseInt(scan.next());
        int b = Integer.parseInt(scan.next());
        if (a < b) {
            System.out.println("a" + " < " + "b");
        } else if (a > b) {
            System.out.println("a" + " > " + "b");
        } else {
            System.out.println("a" + " == " + "b");
        }

    }
}

Measured memory_bytes: 26016
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int T;
int n,m;

signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  
  int a,b;
  int x = 0, p = 1;
  cin >> a >> b;
  while(b>0){
    x+=(p*(b%10));
    b/=10;
    p*=10;
  }
  while(a>0){
    x+=(p*(a%10));
    a/=10;
    p*=10;
  }
  int y = sqrt(x);
  if(y*y==x){
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }


return 0;
}
///....


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
#include <map>
#include <set>
#include <iostream>
#include <string>
#include <ctype.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;


int main(){
	int n,m;
	cin >> n >> m;
	int s[m],c[m];
	
	bool flag = false;
	REP(i,m){
		cin >> s[i] >> c[i];
	}
	
	for(int i = 0;i<(int)pow(10,n);i++){
		string a = to_string(i);
		if(a.size() < n) continue;
		REP(i,m){
			if((int)(a[s[i]-1]-'0') != c[i]){
				flag = true;
				break;
			}
		}
		if(flag){
			flag = false;
			continue;
		}
		cout << a << endl;
		return 0;
	}
	cout << "-1\n";
	
	
}

Measured memory_bytes: 256
n = input().strip()
nLen = len(n)
n = int(n)
ans = 0
if nLen == 1:
    ans = n
elif nLen == 2:
    ans = 9
elif nLen == 3:
    ans = n - 99 + 9
elif nLen == 4:
    ans = 9 + 900
elif nLen == 5:
    ans = n - 9999 + 900 + 9
elif nLen == 6:
    ans = 90909
print(ans)


Measured memory_bytes: 38384
seat = [0]*17
time = [0]*100
queue = []
t = 0
while 1:
    if t <= 5*99 and t%5 == 0:
        queue.append(t/5)
        
    sits = []
    for group in queue:
        p = (2 if group%5 != 1 else 5)
        for j in range(17-p+1):
            if seat[j:j+p].count(0) == p:
                seat[j:j+p] = [17*(group%2)+3*(group%3)+19]*p
                sits.append(group)
                break
        else:
            break
    for sit in sits:
        queue.remove(sit)
        
    seat = [max(0,i-1) for i in seat]
    for group in queue:
        time[group] += 1
    t += 1
    if t > 5*99 and not queue: break

while 1:
    try:
        n = int(raw_input())
        print time[n]
    except:
        break

Measured memory_bytes: 4260
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
	int N, A, B;
	cin >> N >> A >> B;
	if (N == 1) {
		if (A == B) {
			cout << 1 << endl;
		}
		else
			cout << 0 << endl;
	}
	else if (N == 2) {
		if (A > B) {
			cout << 0 << endl;
		}
		else cout << 1 << endl;
	}
	else {
		if (A < B) {
			cout<<(ll)(B-A)*(N-2)+1;
		}
		if (A == B) {
			cout << 1 << endl;
		}
		if (A > B) {
			cout << 0 << endl;
		}
	}
}



Measured memory_bytes: 256
#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
#include<utility>
#include<algorithm>
#include<vector>
#include<queue>
#include<iostream>
#include<math.h>
#include<stack>
#include<set>
#define INF 2147483647
#define loop(i, a, b) for(int i=a; i<=b; i++)
#define mem(arr) memset(arr, 0, sizeof(arr));
using namespace std;
typedef long long lli;
typedef double llf;
typedef pair<int, int> P;
typedef vector<int> vec;
typedef priority_queue<int, vector<int>, greater<int> > pQ;
typedef queue<int> Q;
typedef set<int> S;
struct edge{
	int to, value;
};
void solve();
int main()
{
	int times = 1;
//	cin >> times;
	loop(i, 1, times)
	{
		solve();
		cout << '\n';
	}
	return 0;
}
const int n = 2e5;
vector<edge> tree[n + 50];
int a, b, c, d, e, f;
int arr[n + 50], arr1[n + 50], arr2[n + 50];
string str, str1, str2;

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

Measured memory_bytes: 5248
import bisect

n=int(input())
l=list(map(int,input().split()))
l.sort()
cnt=0

# print(l)

# print()

for i in range(n-1,1,-1):
    for j in range(i-1, 0, -1):
        kagen=l[i]-l[j]
        if l[j]>kagen:
            idx_jogen=j
            idx_kagen=bisect.bisect_right(l,kagen)
            cnt+=idx_jogen-idx_kagen
            # print(l[i], l[j], kagen, idx_jogen,idx_kagen,cnt)

print(cnt)

Measured memory_bytes: 43484
#include <iostream>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
using namespace std;

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    int res = -1;

    int types = 1 << n;
    vector<vector<int>> v;
    vector<int> p;
    for (int i = 0; i < n; i++) {
        int price;
        cin >> price;
        p.push_back(price);
        vector<int> vv;
        for (int j = 0; j < m; j++) {
            int t;
            cin >> t;
            vv.push_back(t);
        }
        v.push_back(vv);
    }
    for (int i = 0; i < types; i++) {
        int price = 0;
        vector<int> state(m, 0);
        int index = i;
        for (int j = 0; j < n; j++) {
            if (index % 2 == 1) {
                for (int k = 0; k < m; k++) {
                    state[k] += v[j][k];
                }
                price += p[j];
            }
            index /= 2;
        }
        int flag = 1;
        for (int j = 0; j < m; j++) {
            if (state[j] < x) {
                flag = 0;
                break;
            }
        }
        if (flag == 1) {
            if (res == -1 || res > price) {
                res = price;
            }
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3636
package main

import "fmt"

func main() {
	var a, b, c int
	fmt.Scanf("%d %d %d", &a, &b, &c)
	if a == b {
		fmt.Printf("%d", c)
		return
	}
	if a == c {
		fmt.Printf("%d", b)
		return
	}
	if b == c {
		fmt.Printf("%d", a)
		return
	}
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define mp make_pair
#define fst first
#define snd second
#define fr(i, a, b) for(int i=a; i<b; i++)


int main() {
    int n; cin >> n;
    vector<int> res(n+1);
    for(int i=1; i<=n; i++) {
        int t; cin >> t;
        res[t] = i;
    }
    for(int i=1; i<=n; i++) {
        cout << res[i] << " ";
    }
}


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

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    int a,b; cin>>a>>b;
    if(a<b)rep(i,b)cout<<a;
    else rep(i,a)cout<<b;
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

typedef long long LL;

const int INF = 0x3f3f3f3f;


int main(void) {
    std::ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int a, b;
    string s, t, str;
    cin >> s >> t;
    cin >> a >> b;
    cin >> str;

    if (str == s) {
        cout << a-1 << " " << b << endl;
    } else {
        cout << a << " " << b-1 << endl;
    }

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		double n = scan.nextDouble();
		long a = (long)n-1;
		double d =Math.sqrt(n);
		for(long i=2; i<d+1; i++){
			double b = n/i;
			if(b == (long)b){
				a=(long)b+(long)i-2;
			}
		}
		System.out.println(a);   

	}
}

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

using namespace std;

int main()
{
	string str;
	int cnt = 0;
	while(cin >> str)
	{
		int len = str.size();
		if(len == 1) {
			cnt++;
			continue;
		}
		int len_half = len / 2, last = len - 1;
		bool hit = true;
		for(int i=0; i < len_half && hit; i++)
		{
			if(str[i] != str[last-i]) hit = false;
		}
		if(hit) cnt++;
	}
	cout << cnt << endl;

	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstdlib>
#include <map>
#include <queue>
#include <vector>
#define mem(i,a) memset(i,a,sizeof(i))
#define PI acos(-1.0)
#define DMAX 200000+5
#define MOD 20190823
#define eps 1e-8
#define mp make_pair
#define INF 1000000000+9
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
inline void read(int &f){
	f=0;
    ll x=1;
    char ch=getchar();
    while(ch<48 || ch>57) {
        if(ch=='-') {
            x=-1;
        }
        ch=getchar();
    }
    while(ch<=57 && ch>=48) {
        f=f*10+ch-'0';
        ch=getchar();
    }
    f*=x;
} 
int n;
int tr[DMAX];
int a[DMAX];
int ans=1;
int minn=INF;
int lowbit(int p){
    return p&(-p);
}
void add(int pos,int val){
    for(;pos<=n;pos+=lowbit(pos)){
        tr[pos]+=val;
    }
}
int query(int pos){
    int add=0;
    for(;pos;pos-=lowbit(pos)){
        add+=tr[pos];
    }
    return add;
}
int main(){
    read(n);
    for(int i=1;i<=n;i++){
        read(a[i]);
    }
    minn=a[1];
    for(int i=2;i<=n;i++){
        if(a[i]<minn){
            ans++;
            minn=a[i];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    vector<int> G[N], c(N, 0);
    for(int i = 0; i < M; i++){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        c[a]++;
        c[b]++;
    }
    for(int i = 0; i < N; i++){
        if(c[i] % 2 == 1){
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
}

Measured memory_bytes: 5948
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>
#include <functional>
#include <cassert>
#include <fstream>
#include <ctime>

using namespace std;
using ll = long long;

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).sizeT()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())
#define ASSERT(cond,mes) assert(cond && mes)

constexpr int MOD = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u / GCD(u, v) * v;
}

template <class T>
std::vector<T> enum_div(T n) {
    std::vector<T> ret;
    for (T i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i * i != n) {
                ret.push_back(n / i);
            }
        }
    }
    return ret;
}

bool isPrime(ll num) {
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;


    for (ll i = 3; i * i <= num; i += 2) {
        if (num % i == 0) {
            return false;
        }
    }

    return true;
};


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

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

template<class T>
bool is_integer(T x) {
    return std::floor(x) == x;
}

struct ToUpper {
    char operator()(char c) { return toupper(c); }
};

struct ToLower {
    char operator()(char c) { return tolower(c); }
};

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

    ll N;
    cin >> N;

    cout << (N * (N - 1)) / 2 << endl;

    return 0;
}


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

int main(){
	int N; cin>>N;
	vector<int>a;
	vector<int>b;
	for(int i=0;i<N;i++){
		int x; cin>>x;
		a.push_back(x);
		b.push_back(x);
	}
	sort(b.begin(),b.end());
	for(int i=0;i<N;i++){
		if(a[i]<=b[N/2-1])cout<<b[N/2];
		else cout<<b[N/2-1];
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3948
# vim: fileencoding=utf-8


def main():
    n, a, b = map(int, input().split())
    ans = 0
    for i in range(1, n + 1):
        s = str(i)
        c = 0
        for j in range(len(s)):
            c += int(s[j])
        if c >= a and c <= b:
            ans += i
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 73116
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> vec={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int n;
  cin>>n;
  cout<<vec.at(n-1)<<endl;
}

Measured memory_bytes: 256
typedef long long ll;

#include <iostream>
#include <map>
#include <algorithm>
#include <queue>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }
inline ll getLL(){ ll s; scanf("%lld", &s); return s; }

#include <set>
using namespace std;

vector<pair<int, int> > g[100000];

vector<ll> dijkstra(int pos, int n){
  vector<ll> ret(n, -1);

  typedef pair<ll, int> data;
  priority_queue<data, vector<data>, greater<data> > pq;

  pq.push(data(0, pos));

  while(pq.size()){
    const data d = pq.top(); pq.pop();
    const int now = d.second;
    const ll cost = d.first;

    if(ret[now] != -1) continue;
    ret[now] = cost;

    REP(i,g[now].size()){
      const int next = g[now][i].first;
      const ll cc = cost + g[now][i].second;

      if(ret[next] == -1){
	pq.push(data(cc, next));
      }
    }
  }

  return ret;
}

const int MAX_N = 1 << 20;
int n, dat[2 * MAX_N - 1];
void init(int n_){
  n = 1;
  while(n < n_) n *= 2;
  REP(i, 2 * n - 1) dat[i] = 0;
}

void update(int k, int a){
  k += n - 1;
  dat[k] = a;

  while(k > 0){
    k = (k - 1) / 2;
    dat[k] = dat[k * 2 + 1] + dat[k * 2 + 2];
  }
}

int query(int a, int b, int k, int l, int r){
  if(r <= a || b <= l) return 0;

  if(a <= l && r <= b) return dat[k];

  int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
  int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);

  return vl + vr;
}

int main(){
  const int n = getInt();
  const int m = getInt();

  init(n);

  REP(i,m){
    const int a = getInt();
    const int b = getInt();
    const int c = getInt();

    g[a].push_back(make_pair(b, c));
    g[b].push_back(make_pair(a, c));
  }

  vector<ll> sd = dijkstra(0, n);
  vector<ll> gd = dijkstra(n - 1, n);
  vector<ll> gds = gd; sort(gds.begin(), gds.end());
  map<ll, vector<int> > gdm;

  vector<pair<ll, ll> > d(n);

  REP(i,n){
    d[i].first  = sd[i];
    d[i].second = gd[i];
  }
  sort(d.begin(), d.end());

  REP(i,n){
    gdm[d[i].second].push_back(i);
  }

  const int q = getInt();
  vector<pair<pair<ll, ll>, int> > que(q);

  REP(i,q){
    que[i].first.second = getLL();
    que[i].first.first = getLL();
    que[i].second = i;
  }

  sort(que.begin(), que.end());
  int gpos = 0;

  vector<int> ans(q);

  REP(i,q){
    const ll fs = que[i].first.second;
    const ll fg = que[i].first.first;

    while(gpos != n && fg > gds[gpos]){
      const vector<int> &v = gdm[gds[gpos]];

      REP(j,v.size()){
	update(v[j], 1);
      }

      gpos++;
    }

    const int lim = lower_bound(d.begin(), d.end(), pair<ll, ll>(fs + 1, -1)) - d.begin();

    ans[que[i].second] = lim - query(0, lim, 0, 0, ::n);
    // printf("%d %d : lim = %d, ans = %d  (gpos = %d)\n", fs, fg, lim, ans[que[i].second], gpos);
  }

  REP(i,q){
    printf("%d\n", ans[i]);
  }

  return 0;
}

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

const int MAX_N=1e5+10;
const int INF=1e9+10;

deque <pair<int,int> > Q;
int K;
vector <pair<int,int> > g[MAX_N];
int dist[MAX_N];

void get_dist(){
	for(int i=0;i<MAX_N;i++) dist[i]=INF;
	dist[1]=1;
	Q.push_back(make_pair(dist[1],1));
	while(Q.size()){
		int val=Q.front().first,x=Q.front().second;
		Q.pop_front();
		if(val>dist[x]) continue;
		for(int i=0;i<g[x].size();i++){
			int cost=g[x][i].first,to=g[x][i].second;
			if(dist[to]>dist[x]+cost){
				dist[to]=dist[x]+cost;
				if(cost==0)
					Q.push_front(make_pair(dist[to],to));
				else
					Q.push_back(make_pair(dist[to],to));
			}
		}
	}
}

int main(){
	scanf("%d",&K);
	for(int i=1;i<K;i++){
		g[i].push_back(make_pair(0,i*10%K));
		g[i].push_back(make_pair(1,(i+1)%K));
	}
	get_dist();
	printf("%d\n",dist[0]);
	return 0;
}

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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool flag = false;
  for(int i = 1; i < 10000; i++){
    if((i * A) % B == C){
      flag = true;
      break;
    }
  }
  if(flag){
    cout << "YES" <<endl;
  }else{
    cout << "NO" <<endl;
  }
}

Measured memory_bytes: 256
N,Y = map(int,input().split())

import sys
for i in range(N+1):
    for j in range(N+1-i):
        k = N-(i+j)
        if k>=0 and 10000*i+5000*j+1000*k == Y:
            print(i,j,k)
            sys.exit()

print(-1,-1,-1)

Measured memory_bytes: 3060
#include <tuple>
#include <queue>
#include <vector>
#include <iostream>
using namespace std;

int main() {
    int n, m; cin >> n >> m;
    vector<vector<pair<int, int> > > adj(n);
    for (int i = 0; i < m; i++) {
        int a, b, c; cin >> a >> b >> c;
        a--;  b--;
        adj[a].push_back({b, c});
        adj[b].push_back({a, c});
    }
    long long sum = 0;
    // MST
    vector<vector<pair<int, int> > > temp(n);
    bool visited[n] = {};
    visited[0] = true;
    priority_queue<tuple<int, int, int> > pq; // cost, src, dst
    int depth[n] = {};
    for (auto e : adj[0]) pq.push(make_tuple(-e.second, 0, e.first));
    while (!pq.empty()) {
        auto e = pq.top(); pq.pop();
        int cost = -get<0>(e), src = get<1>(e), dst = get<2>(e);
        if (visited[dst]) continue;
        visited[dst] = true;
        depth[dst] = depth[src] + 1;
        temp[src].push_back({dst, cost});
        sum += cost;
        for (auto e : adj[dst])
            if (!visited[e.first]) pq.push(make_tuple(-e.second, dst, e.first));
    }
    temp.swap(adj);

    pair<int, int> par[12][n] = {};
    for (int k = 0; 1<<k < n; k++)
        for (int i = 0; i < n; i++)
            if (k == 0) 
                for (auto e : adj[i])
                    par[0][e.first] = {i, e.second};
            else if (depth[i] >= 1<<k) {
                int a1 = par[k-1][i].first,
                    a2 = par[k-1][a1].first,
                    cost1 = par[k-1][i].second,
                    cost2 = par[k-1][a1].second;
                par[k][i] = {a2, max(cost1, cost2)};
            } else
                par[k][i] = {-1, -1};

    // for (int k = 0; 1<<k < n; k++)
    //     for (int i = 0; i < n; i++)
    //         cout << i << ' ' << k << ' ' << par[k][i].second << endl;

    int q; cin >> q;
    while (q--) {
        int s, t; cin >> s >> t;
        s--; t--;
        if (depth[s] < depth[t]) swap(s, t);
        int mx = 0;
        for (int d = depth[s] - depth[t], k = 0; d > 0; k++) {
            if (d & 1<<k) {
                mx = max(mx, par[k][s].second);
                s = par[k][s].first;
                d ^= (1<<k);
            }
            // cout << k << ' ' << mx << endl;
        }
        if (s != t) {
            for (int k = 11; k >= 0; k--) {
                if (1<<k <= depth[s] && par[k][s].first != par[k][t].first) {
                    mx = max(mx, max(par[k][s].second, par[k][t].second));
                    s = par[k][s].first;
                    t = par[k][t].first;
                }
            }
            mx = max(mx, max(par[0][s].second, par[0][t].second));
        }
        cout << sum - mx << endl;
    }
}


Measured memory_bytes: 17520
#include <bits/stdc++.h>
using namespace std;
int main() {
int X,Y,Z;
cin >> X >> Y >> Z;
int cnt = Z,ans = 0;;
while (ans <= X) {
  cnt += Y+Z;
  if (cnt > X) break;
  ans++;
}
cout << ans << endl;

return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>

int main()
{
    int n;
    int ans = 1;
    scanf("%d", &n);
    while (ans*2 <= n)
    {
        ans *= 2;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
	int N, L;
	vector<string> S;
	cin >> N >> L;
	for(int i = 0; i < N; i++){
		string input;
		cin >> input;
		S.push_back(input);
	}
	bool flag = 1;
	for(int i = 0; flag; i++){
		flag = 0;
		for(int j = N - 1; j >= i + 1; j--){
			if(S[j] < S[j - 1]){
				swap(S[j], S[j - 1]);
				flag = 1;
			}
		}
	}
	for(int i = 0; i < N; i++){
		cout << S[i];
	}
	cout << endl;
	return 0;
}


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

int main()
{
    int N, K, cost=0;
    cin >> N >> K;
    vector<int> x(N);
    for(int i=0; i<N; i++) cin >> x[i];
    for(int i=0; i<N; i++) cost += 2 * std::min(x[i], abs(x[i]-K));
    cout << cost << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a;i < b;i++)
#define rrep(i,a,b) for(int i = a;i >= b;i--)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cerr << #x << ": " << x << endl;
typedef long long ll;
using namespace std;

//---------------------------------------------------------------------------------------------------

//---------------------------------------------------------------------------------------------------

int main(){
   cin.tie(0);
   ios::sync_with_stdio(false);
   
   int a[3],ans = 0;
   cin >> a[0] >> a[1] >> a[2];
   sort(a,a+3);

   ans += a[1] - a[0];
   ans += a[2] - a[1];

   cout << ans << endl;

   return 0;
}


Measured memory_bytes: 256
N, Q = map(int, input().split())
S = list(input())

arr = [0 for j in range(N)]
A_tmp = 0
S_tmp = 0

for i in range(N):
    if S[i] == "A":
        A_tmp = 1
        arr[i] = S_tmp
    elif A_tmp == 1 and S[i] == "C":
        S_tmp += 1
        arr[i] = S_tmp
        A_tmp = 0
    else:
        arr[i] = S_tmp
        A_tmp = 0

ans_arr = []
for i in range(Q):
    l, r = map(int, input().split())
    
    ans_arr.append(arr[r-1]-arr[l-1])

for i in range(Q):
    print(ans_arr[i])

Measured memory_bytes: 10992
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    long int x, y, z, k;
    cin >> x >> y >> z >> k;
    long int a[x], b[y], c[z];
    rep(i, x) cin >> a[i];
    rep(i, y) cin >> b[i];
    rep(i, z) cin >> c[i];
    long int a2[x*y];
    long int idx = 0;
    rep(i, x){
        rep(j, y){
            a2[idx] = a[i] + b[j];
            idx++;
        }
    }
    sort(a2, a2 + x * y, greater<long int>());
    long int num = min(k, x * y);
    long int a3[num*z];
    idx = 0;
    rep(i, num){
        rep(j, z){
            a3[idx] = a2[i] + c[j];
            idx++;
        }
    }
    sort(a3, a3 + num * z, greater<long int>());
    long int ans = 0;
    rep(i, k){
        cout << a3[i] << endl;
    }
}


Measured memory_bytes: 31488
package main

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

func abs(n int) int {
  if n >= 0 {
    return n
  } else {
    return -n
  }
}

func main()  {
  sc := bufio.NewScanner(os.Stdin)
  sc.Buffer(make([]byte, 64*1024*1024), 64*1024*1024)
  sc.Scan()
  n, _ := strconv.Atoi(sc.Text())
  sc.Scan()
  aArr := strings.Split(sc.Text(), " ")
  a := make([]int, n)
  for i := 0; i < n; i++ {
    a[i], _ = strconv.Atoi(aArr[i])
  }
  cnt := make([]int, 2)
  sum := make([]int, 2)
  for i := 0; i < 2; i++ {
    for j:= 0; j < n; j++ {
      sum[i] += a[j]
      if (i+j)%2 == 0 {
        if sum[i] >= 0 {
          cnt[i] += abs(sum[i]+1)
          sum[i] = -1
        }
      } else {
        if sum[i] <= 0 {
          cnt[i] += abs(sum[i]-1)
          sum[i] = 1
        }
      }
    }
  }
  if cnt[0] < cnt[1] {
    fmt.Println(cnt[0])
  } else {
    fmt.Println(cnt[1])
  }
}


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

int main() {
  int n;
  cin >> n;
  int x[n], y[n];

  for (int i = 0; i < n; i++) {
    cin >> x[i];
  }
  
  for (int i = 0; i < n; i++) {
    cin >> y[i];
  }

  double d1 = 0;

  for (int i = 0; i < n; i++) {
    d1 += fabs((double)(x[i] - y[i]));
  }
  
  double d2 = 0;

  for (int i = 0; i < n; i++) {
    d2 += pow(fabs((double)(x[i] - y[i])),2);
  }

  d2 = sqrt(d2);
  
  double d3 = 0;

  for (int i = 0; i < n; i++) {
    d3 += pow(fabs((double)(x[i] - y[i])),3);
  }

  d3 = pow(d3, 1 / 3.0);
  
  double dinf = 0;
  double max = 0;
  for (int i = 0; i < n; i++) {
    if (max < fabs(x[i] - y[i])) max = fabs(x[i] - y[i]);
  }
  
  dinf = max;

  printf("%.6f\n%.6f\n%.6f\n%.6f\n" , d1, d2, d3, dinf);
  
  return 0;
}



Measured memory_bytes: 3340
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

#define rep(i,n) for (int i=0; i<n; i++)
#define pll pair<ll, ll>
#define F first
#define S second

class UnionFind{
public:
  vector<ll> par; //各元の親を表す配列
  vector<ll> siz; //素集合のサイズを表す配列

  UnionFind(ll sz_): par(sz_), siz(sz_,1){
    for (int i=0; i<sz_; ++i) par[i] = i;
  }
  void init(ll sz_){
    par.resize(sz_);
    siz.assign(sz_,1);
    for (int i=0; i<sz_; ++i) par[i] = i;
  }

  // Find
  ll root(ll x){ //根の検索
    if (par[x] == x){
      return x;
    }else{
      return par[x] = root(par[x]);
    }
  }

  // Union(Unite, Merge)
  bool merge(ll x, ll y){
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x,y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool issame(ll x, ll y){
    return root(x) == root(y);
  }
  ll size(ll x){
    return siz[root(x)];
  }
};

int main(){
  int N, M, a, b;
  cin >> N >> M;
  vector<pll> vec(M);
  rep(i, M){
    cin >> a >> b; --a; --b;
    vec[i].F = a;
    vec[i].S = b;
  }

  UnionFind uf(N);
  ll res = 0;
  rep(i, M){ //繋がない辺
    uf.init(N);
    rep(j, M){
      if (j == i) continue;
      uf.merge(vec[j].F, vec[j].S);
    }
    if (uf.size(0) < N) res++;
  }

  cout << res << "\n";
  return 0;

}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	
		int n = sc.nextInt();
		int ac = 0;
		int wa = 0;
		int tle = 0;
		int re = 0;
		
		for(int i=0;i<n;i++){
			String s = sc.next();

			if(s.equals("AC")){
				ac++;
			} else if(s.equals("WA")){
				wa++;
			} else if(s.equals("TLE")){
				tle++;
			} else if(s.equals("RE")){
				re++;
			}
		}
		System.out.println("AC" + " " + "x" + " " + ac);
		System.out.println("WA" + " " + "x" + " " + wa);
		System.out.println("TLE" + " " + "x" + " " + tle);
		System.out.println("RE" + " " + "x" + " " + re);
	}
}

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

#define rep(i,m,n) for(int i = (m); i < (n); i++)
#define rrep(i,m,n) for(int i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]); if(i!=n-1) cout << " ";} cout << endl;
#define printp(x,n) for(int i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    ll A[100010], B[100010];
    cin >> N;
    rep(i,0,N){
        cin >> A[i];
    }
    rep(i,0,N){
        cin >> B[i];
    }
    ll val = 0;
    ll diff[100010] = {};
    rep(i,0,N){
        val += (B[i] - A[i]);
        diff[i] = (B[i] - A[i]);
    }
    if(val > 0){
        print(-1);
        return 0;
    }
    vector<lpair> lp;
    rep(i,0,N){
        lp.push_back(make_pair(diff[i], i));
    }
    sort(lp.begin(), lp.end());
    // printp(lp,N);
    ll plus_cnt = 0;
    ll ans1 = 0;
    rep(i,0,N){
        if(diff[i] > 0){
            plus_cnt += diff[i];
            ans1++;
        }
    }
    if(ans1 == 0){
        print(0);
        return 0;
    }
    // print(ans1);
    ll idx = 0;
    while(1){
        ll pp = lp[idx].second;
        ll diffs = lp[idx].first;
        ll v1 = abs(diffs);
        plus_cnt -= v1;
        if(plus_cnt <= 0) break;
        idx++;
    }
    print(ans1 + idx + 1);


}


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

int main()
{
	int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    
    long long maxi = a[0], ans = 0;
    for (int i = 0; i < n; i++)
    {
        if(maxi <= a[i])
        {
            maxi = a[i];
        }
        else
        {
            ans += maxi - a[i];
        }
    }
    cout << ans << endl;
    
}

Measured memory_bytes: 3968
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i <= (n); i++)
#define show(a, n) rep(i,n) {cout<<a[i]<<' ';} cout<<endl;

using namespace std;
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<long long, long long> pll;

const int INF = 1 << 30;
const long long INFL = 1LL << 62;
const int MOD = 1000000007;
const int MAX = 100000;
const int N = 100010;

int main() {
	ll n, x;
	cin >> n >> x;
	ll a[N];
	rep(i, n) cin >> a[i];
	ll ans = 0;
	if(a[0] > x) {
		ans += a[0] - x;
		a[0] = x;
	}
	for(int i = 1; i < n; i++) {
		if(a[i] + a[i-1] > x) {
			ans += a[i] + a[i-1] - x;
			a[i] -= a[i] + a[i-1] - x;;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        char[] S = scanner.next().toCharArray();
        if (S.length < 3 || S.length > 99) {
            System.out.println("No");
            return;
        }
        if (!isKaibun(S)) {
            System.out.println("No");
            return;
        }

        char[] left = Arrays.copyOfRange(S, 0, (S.length - 1) / 2);
        if (!isKaibun(left)) {
            System.out.println("No");
            return;
        }
        char[] right = Arrays.copyOfRange(S, (S.length + 3) / 2 - 1, S.length);
        if (!isKaibun(right)) {
            System.out.println("No");
            return;
        }

        System.out.println("Yes");
    }

    private static boolean isKaibun(char[] chars) {
        if (chars.length == 1) {
            return true;
        }
        if (chars.length < 3) {
            return false;
        }
        for (int i = 0; i< (chars.length-1)/2; i++) {
            if (chars[i] != chars[chars.length - i - 1]) {
                return false;
            }
        }
        return true;
    }
}


Measured memory_bytes: 21716