akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <queue>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
using namespace std;

class State{
public:
  int pos, bit, isFirst, cost;

  State(){}
  State(int pos, int bit, int isFirst, int cost) : 
    pos(pos), bit(bit), isFirst(isFirst), cost(cost) {}

  bool operator<(const State &st)const{
    return cost > st.cost;
  }
};

int n;
bool closed[16][1 << 16][2];
string a, b;

void solve(){
  int start = 0;

  for(int i = n - 1; i >= 0; i--){
    start <<= 1;
    if(a[i] != b[i]){
      start++;
    }
  }

  priority_queue<State> open;

  for(int i = 0; i < n; i++){
    if(start & (1 << i)){
      open.push(State(i, start, true, 0));
    }
  }

  memset(closed, 0, sizeof(closed));

  while(!open.empty()){
    State st = open.top();
    open.pop();

    if(closed[st.pos][st.bit][st.isFirst]){
      continue;
    }
    closed[st.pos][st.bit][st.isFirst] = true;

    if(st.bit == 0){
      cout << st.cost << endl;
      return;
    }

    if(st.isFirst){
      for(int i = 0; i < n; i++){
        if(i == st.pos || !(st.bit & (1 << i)) || a[st.pos] == a[i]) continue;
        int nbit = st.bit - (1 << i) - (1 << st.pos);
        open.push(State(i, nbit, !st.isFirst, st.cost + abs(st.pos - i)));
      }
    }
    else{
      for(int i = 0; i < n; i++){
        if(!(st.bit & (1 << i))) continue;
        open.push(State(i, st.bit, !st.isFirst, st.cost + abs(st.pos - i)));
      }
    }
  }
}

int main(){
  while(cin >> n, n){
    cin >> a >> b;
    solve();
  }
}

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

int main() {
    long long N, K;
    scanf("%lld %lld", &N, &K);

    long long x = N / K;
    N -= K * x;
    if (llabs(N - K) < N) {
        N = llabs(N - K);
    }
    
    printf("%lld\n", N);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int bingo[3][3];
    rep(i,3){
        rep(j,3){
            cin >> bingo[i][j];
        }
    }
    int n;
    cin >> n;
    rep(ai,n){
        int b;
        cin >> b;
        rep(i,3){
            rep(j,3){
                if(bingo[i][j] == b) bingo[i][j] = -1;
            }
        }
    }
    
    rep(i,3){
        bool flag = true;
        rep(j,3){
            if(bingo[i][j] != -1){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
        flag = true;
        rep(j,3){
            if(bingo[j][i] != -1){
                flag = false;
                break;
            }
        }
        if(flag){
            cout << "Yes" << endl;
            return 0;
        }
        
    }
    bool flag = true;
    rep(i,3){
        if(bingo[i][i] != -1){
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
        return 0;
    }
    flag = true;
    rep(i,3){
        if(bingo[i][2-i] != -1){
            flag = false;
            break;
        }
    }
    if(flag){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include <bitset>
#include <cmath>
#include <stack>
#include <iomanip>
#include <map>
#include <math.h>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const ll INF = 1LL << 60;

ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }




int N,W;
ll v[110];
ll w[110];
ll dp[110][100010];
int main()
{
	cin >> N >> W;
	for(int i = 0; i < N; i++) cin >> w[i] >> v[i];

	for(int i = 0; i < 110; i++)
	{
		for(int j = 0; j < 100010; j++)
		{
			dp[i][j] = INF;
		}
	}
	dp[0][0] = 0;

	 for (int i = 0; i < N; ++i) {
        for (int sum_v = 0; sum_v < 100010; ++sum_v) {

            // i 番目の品物を選ぶ場合
            if (sum_v - v[i] >= 0) chmin(dp[i+1][sum_v], dp[i][sum_v - v[i]] + w[i]);

            // i 番目の品物を選ばない場合
            chmin(dp[i+1][sum_v], dp[i][sum_v]);
        }
    }
	ll res = 0;
	for (int sum_v = 0; sum_v < 100010; ++sum_v) {
        if (dp[N][sum_v] <= W) res = sum_v;
    }
    cout << res << endl;

}

Measured memory_bytes: 86272
#include<iostream>
using namespace std;
main(){
	int data[5],tmp;
	for(int i=0;i<5;++i)cin>>data[i];
	for(int i=0;i<5;++i){
		for(int j=i;j<5;++j){
			if(data[i]<data[j]){
				tmp=data[i];
				data[i]=data[j];
				data[j]=tmp;
			}
		}
	}
	for(int i=0;i<5;++i){
		if(i<4)cout<<data[i]<<" ";
		else cout<<data[i]<<endl;
	}
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define REP(i,a,b) for(int i=(a); i<=(b); i++)
#define f first
#define s second
#define mp make_pair
#define pb push_back
using namespace std;

typedef long long ll;

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    cout << (n>=30?"Yes":"No");
    return 0;
}

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


int main() {
    string S;
    cin >> S;
    Int K, N;
    cin >> K;
    N = S.size();

    set<char> X;
    rep(i,N) X.insert(S[i]);
    if (X.size() == 1) {
        cout << (K * N) / 2 << endl;
        return 0;
    }

    vector<bool> changed(N,false);

    Int m = 0;
    if (N > 1) {
        rep(i,N-1) {
            if (S[i] == S[i+1] && !changed[i]) {
                m++;
                changed[i+1] = true;
            }
        }
    }

    Int ans = 0;
    ans = m * K;

    if (S[0] == S[N-1]) {
        Int y, z;
        rep1(i,N-1) {
            if (S[i] != S[0]) {
                y = i;
                break;
            }
        }
        for (int j = N-2; j>=0; j--) {
            if (S[j] != S[N-1]) {
                z = N-1-j;
                break;
            }
        }
        if (y % 2 == 1 && z % 2 == 1) ans += K-1;
    }

    cout << ans << endl;
}

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

#define INF 100100100
#define MOD 1000000007

using namespace std;
using ll = long long;
using ull = unsigned long long ;

int main(int argc, char const* argv[]){
   ios::sync_with_stdio(false);
   cin.tie(0);
   int N;
   cin>>N;
   vector<ll>A(N),B(N);
   ll ans=0;
   for(int i=0;i<N;i++)cin>>A[i]>>B[i];
   for(int i=N-1;i>=0;i--){
      if((A[i]+ans)%B[i])ans+=(B[i]-(A[i]+ans)%B[i]);
   }
   cout<<ans<<endl;
   return 0;
}


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

int n;

int main() {
    cin >> n;
    int a[n], b[n];
    for (int i=0; i<n; i++) cin >> a[i];
    for (int i=0; i<n; i++) b[i]=a[n-i-1];
    for (int i=0; i<(n-1); i++) cout << b[i] << " ";
    cout << b[n-1] << endl;
}


Measured memory_bytes: 3092
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char **argv)
{
    int h, w;
    scanf("%d %d", &h, &w);

    int nh = h + 2;
    int nw = w + 2;
    int size = nh * nw;
    char *out = (char *) malloc(size);
    for (int i = 0; i < size; ++i) {
        out[i] = '#';
    }

    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            int idx = (i+1)*nw + (j+1);
            scanf(" %c ", &out[idx]);
        }
    }

    for (int i = 0; i < nh; ++i) {
        for (int j = 0; j < nw; ++j) {
            printf("%c", out[i*nw + j]);
        }
        putchar('\n');
    }
    return 0;
}


Measured memory_bytes: 128
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
#include <cassert>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 2e5 + 10;

int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int pt, px, py;
	int n;
	cin >> n;
	pt = px = py = 0;
	while (n--)
	{
		int t, x, y;
		cin >> t >> x >> y;
		int need = abs(x - px) + abs(y - py);
		int tot = t - pt;
		if (tot < need || (tot - need) % 2 == 1) puts("No"), exit(0);
		pt = t, px = x, py = y;
	}
	puts("Yes");
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <algorithm>
#include <set>
#include <vector>
#include <queue>
#define pb push_back
using namespace std;
typedef pair<int,int> pii;

int main(){

  int n,m;
  cin>>n>>m;
  vector<int> x;

  int t;
  for(int i=0;i<m;i++){
    cin>>t;
    x.pb(t+1e5);
  }
  if(n>=m){
    cout<<0<<endl;
    return 0;
  }
  
  sort(x.begin(),x.end());
  vector<int> y;
  for(int i=0;i<m-1;i++){
    y.pb(x[i+1]-x[i]);
  }
  sort(y.begin(),y.end());

  int res=x[x.size()-1]-x[0];
  for(int i=0;i<n-1;i++){
    res-=y[y.size()-1-i];
  }
  cout<<res<<endl;
  
  return 0;
}



Measured memory_bytes: 1400
N = int(input())
B = list(map(lambda x: int(x) - 1, input().split()))
res = []
for i in range(N):
    for j in range(len(B) - 1, -1, -1):
        if B[j] == j:
            res.append(B.pop(j))
            break
if len(B) == 0:
    for r in res[::-1]:
        print(r + 1)
else:
    print(-1)


Measured memory_bytes: 9136
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
#define REP(var, a, b) for (int var = (a); var < (b); var++)
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()
#define rALL(c) (c).rbegin(), (c).rend()
ll MOD = 1000000007;
const ll INF = 1LL << 62;

struct mint {
  ll x;
  mint(ll x = 0) : x(x % MOD) {}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += MOD - a.x) >= MOD) x -= MOD;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= MOD;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime MOD
  mint inv() const { return pow(MOD - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

int main() {
  //
  ll n, m;
  cin >> n >> m;
  vl x(n), y(m);
  rep(i, n) { cin >> x[i]; }
  rep(i, m) { cin >> y[i]; }
  sort(ALL(x));
  sort(ALL(y));

  mint xsum(0);
  rep(i, n - 1) {
    mint len(x[i + 1] - x[i]);
    xsum = xsum + len * mint(i + 1) * mint(n - (i + 1));
  }
  // cerr << xsum.x << endl;

  mint ysum(0);
  rep(i, m - 1) {
    mint len(y[i + 1] - y[i]);
    ysum = ysum + len * mint(i + 1) * mint(m - (i + 1));
  }

  mint ans = xsum * ysum;
  cout << ans.x << endl;
  return 0;
}


Measured memory_bytes: 1792
/* Search III */
#include<stdio.h>
#include<string.h>

#define M 1000003
#define L 14

char H[M][L]; /* Hash Table */

int getChar(char ch){
  if ( ch == 'A') return 1;
  else if ( ch == 'C') return 2;
  else if ( ch == 'G') return 3;
  else if ( ch == 'T') return 4;
}

/* convert a string into an integer value */
long long getKey(char str[]){
  long long sum = 0, p = 1, i;
  for ( i = 0; i < strlen(str); i++ ){
    sum += p*(getChar(str[i]));
    p *= 5;
  }
  return sum;
}

int h1(int key){ return key%M; }
int h2(int key){ return 1+key%(M-1); }

int find(char str[]){
  int key,i,h_1,h_2;
  key=getKey(str);
  h_1=h1(key);
  //printf("h_1:%d\n",h_1);
  if(strcmp(H[h_1],str)==0){
    return 1;  /*true*/
  }else{
    h_2=h2(key);
    //printf("h_2:%d\n",h_2);
    for(i=h_1;;/*i+=h_2*/){
      //printf("key:%d\n",key);
      //printf("i:%d\n",i);
      if(strcmp(H[i],str)==0)return 1; /*true*/
      else if(H[i][0]=='\0')return 0; /*false*/
      else if((M-i)<=h_2){
	i=h_2-(M-i);
	//printf("i:%d\n",i);
      }else{
	i+=h_2;
	//printf("i:%d\n",i);
      }
    }
  }
}

int insert(char str[]){
  int key, h_1, h_2, h, i;
  key=getKey(str);
  h_1=h1(key);
  if(H[h_1][0]=='\0'){
    strcpy(H[h_1],str);
  }else{
    h_2=h2(key);
    for(i=0;;i++){
      h=(h_1+i*h_2)%M;
      if(H[h][0]=='\0')break;
      }
    strcpy(H[h],str);
  }
  return 0;
}

int main(){
  int i, n, h;
  char str[L], com[9];
  for ( i = 0; i < M; i++ ) H[i][0] = '\0';
    
  scanf("%d", &n);
    
  for ( i = 0; i < n; i++ ){
    scanf("%s %s", com, str);
    
    if ( com[0] == 'i' ){
      insert(str);
    } else {
      if (find(str)){
	printf("yes\n");
      } else {
	printf("no\n");
      }
    }
  }
  return 0;
}

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

long GCD(long x,long y){
  if(max(x,y)%min(x,y) == 0){
    return min(x,y);
  }
  else{
    GCD(min(x,y),max(x,y)%min(x,y));
  }
}

int main() {
  long n,x,ans;
  cin >> n >> x;
  vector<long>data(n+1);
  vector<long>sa(n);
  for(long i = 0;i < n;i++){
    cin >> data[i];
  }
  data[n] = x;
  sort(data.begin(),data.end());
  for(int i = 0;i < n;i++){
    sa[i] = data[i+1]-data[i];
    if(i != 0){
      ans = GCD(ans,sa[i]);
    }
    else{
      ans = sa[i];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
n,a,b,c=map(int,input().split())
s=[]
for i in range(n):
    s.append(input())
s.append('EOF')

ans=[]
 
flag=True
 
for i in range(n):
    if s[i]=='AB':
        if a==0 and b==0:
            flag=False
            break
        if a==0 or (b!=0 and a==1 and s[i+1]=='AC'):
            ans.append('A')
            a+=1
            b-=1
        else:
            ans.append('B')
            a-=1
            b+=1
    elif s[i]=='AC':
        if a==0 and c==0:
            flag=False
            break
        if a==0 or (c!=0 and a==1 and s[i+1]=='AB'):
            ans.append('A')
            a+=1
            c-=1
        else:
            ans.append('C')
            a-=1
            c+=1
    else:
        if c==0 and b==0:
            flag=False
            break
        if c==0 or (b!=0 and c==1 and s[i+1]=='AC'):
            ans.append('C')
            c+=1
            b-=1
        else:
            ans.append('B')
            c-=1
            b+=1

if flag:
    print("Yes")
    for i in ans:
        print(i)
else:
    print("No")

Measured memory_bytes: 85384
abclist = list('abcdefghijklmnopqrstuvwxyz')

N = int(input())


vals = []
strs = []
while(N != 0):
    N = N - 1

    mod = N % 26

    N = N // 26

    vals.append(mod)

    strs.append(abclist[mod])

strs.reverse()
s = "".join(strs)
print(s)


Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
inline int read(){
    int x = 0; char c = getchar();
    while (!isdigit(c)) c = getchar();
    while (isdigit(c)) x = x * 10 + c - '0',c = getchar();
    return x;
}
template <typename T> void read(T &x){
	x = 0; int f = 1; char ch = getchar();
	while (!isdigit(ch)) {if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) {x = x * 10 + ch - '0'; ch = getchar();}
	x *= f;
}
inline void write(int x){if (x > 9) write(x/10); putchar(x%10+'0'); }

int main(){
	int n,m;read(n); read(m);
	int ans= n/m; if (n%m>0) ++ans;
	cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
use proconio::{fastout, input};

use proconio::marker::Usize1;
use std::cmp::max;

#[fastout]
fn main() {
    input! {
        n: usize, k: i64,
        pp: [Usize1; n],
        cc: [i64; n],
    }
    let mut ans = std::i64::MIN;
    for s in 0..n {
        let mut i = s;
        let mut t = 0;
        let mut c = 0;
        let mut m = std::i64::MIN;
        loop {
            c += 1;
            i = pp[i];
            t += cc[i];
            m = max(m, t);
            if c == k {
                ans = max(ans, m);
                break;
            }
            if i == s {
                if t <= 0 {
                    ans = max(ans, m);
                } else {
                    t = t * (k / c - 1);
                    m = max(m, t);
                    for _ in 0..(c + k % c) {
                        i = pp[i];
                        t += cc[i];
                        m = max(m, t);
                    }
                    ans = max(ans, m);
                }
                break;
            }
        }
    }
    println!("{}", ans);
}


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

int main(void){
  int h, w;
  vector<string> a(100);

  cin >> h >> w;
  for(int i = 0; i < h; i ++)
    cin >> a.at(i);

  for(int i = 0; i < w+2; i ++)
    cout << "#";
  cout << endl;
  for(int i = 0; i < h; i ++){
    cout << "#" << a.at(i) << "#" << endl;
  }
  for(int i = 0; i < w+2; i ++)
    cout << "#";
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

class Program
{
    static void Main(string[] args)
    {
        var nk = Console.ReadLine().Split(' ');
        var n = int.Parse(nk[0]);
        var k = int.Parse(nk[1]);

        var s = Console.ReadLine().Split(' ');
        var d = new int[n];
        for (int i = 0; i < n; i++)
        {
            d[i] = int.Parse(s[i]);
        }

        var min = int.MaxValue;
        for (int i = 0; i + k - 1 < n; i++)
        {
            min = Math.Min(Math.Min(min,
                d[i + k - 1] - d[i] + Math.Abs(d[i])),
                d[i + k - 1] - d[i] + Math.Abs(d[i + k - 1]));
        }

        Console.WriteLine(min);
    }
}

Measured memory_bytes: 21856
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  vector<ppiii> v;
  int n;
  int unused;
  cin >> n >> unused;
  while(n--) {
    int a, b, c;
    cin >> a >> b >> c;
    v.push_back({{a, b}, c});
  }
  sort(v.begin(), v.end());
  vector<pii> dp;
  for(ppiii out: v) {
    bool need = true;
    for(pii& out2: dp) {
      if(out.second == out2.second) {
        out2.first = out.first.second;
        need = false;
        break;
      }
      if(out2.first < out.first.first) {
        out2.first = out.first.second;
        out2.second = out.second;
        need = false;
        break;
      }
    }
    if(need) {
      dp.push_back({out.first.second, out.second});
    }
  }
  cout << dp.size() << "\n";
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 1912
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		bool flag[201];
		for(int i = 0; i <= 2 * n; ++i)
		{
			flag[i] = false;
		}
		vector<int> taro(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> taro[i];
			flag[taro[i]] = true;
		}
		vector<int> hanako;
		for(int i = 1; i <= 2 * n; ++i)
		{
			if(!flag[i])
			{
				hanako.push_back(i);
			}
		}
		sort(taro.begin(), taro.end(), greater<int>());
		sort(hanako.begin(), hanako.end(), greater<int>());
		int stage = taro[taro.size() - 1];
		taro.pop_back();
		int p_taro = 0;
		int p_hanako = 0;
		bool turn = false;
		while(!taro.empty() && !hanako.empty())
		{
			if(!turn)
			{
				bool ok_flag = false;
				for(int i = hanako.size() - 1; i >= 0; --i)
				{
					if(hanako[i] >= stage)
					{
						ok_flag = true;
						stage = hanako[i];
						vector<int> buf = hanako;
						hanako.clear();
						for(int j = 0; j < buf.size(); ++j)
						{
							if(buf[j] != stage)
							{
								hanako.push_back(buf[j]);
							}
						}
						break;
					}
				}
				if(!ok_flag)
				{
					stage = 0;
				}
				turn = !turn;
			}
			else
			{
				bool ok_flag = false;
				for(int i = taro.size() - 1; i >= 0; --i)
				{
					if(taro[i] >= stage)
					{
						ok_flag = true;
						stage = taro[i];
						vector<int> buf = taro;
						taro.clear();
						for(int j = 0; j < buf.size(); ++j)
						{
							if(buf[j] != stage)
							{
								taro.push_back(buf[j]);
							}
						}
						break;
					}
				}
				if(!ok_flag)
				{
					stage = 0;
				}
				turn = !turn;
			}
		}
		cout << hanako.size() << endl;
		cout << taro.size() << endl;
	}
}

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

Measured memory_bytes: 1216
#include <cstdio>
#include <stack>
using namespace std;

int main()
{
	stack<int> stk;
	int n,out;

	while(scanf("%d",&n) != EOF){
		if(n == 0){
			out = stk.top();
			stk.pop();
			printf("%d\n",out);
		}
		else
			stk.push(n);
	}

	return 0;
}

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

#define MAXN 100003

int main(void)
{
    int N,i,j;
    int h[MAXN], p[MAXN];
    scanf("%d",&N);
    for (i=0;i<N;i++)
    {
        scanf("%d",&h[i]);
    }
    p[N-1]=0;
    p[N-2]=abs(h[N-2]-h[N-1]);
    for(i=N-3;i>=0;i--)
    {
        p[i]=min(p[i+1]+abs(h[i]-h[i+1]),p[i+2]+abs(h[i]-h[i+2]));
    }
    printf("%d\n",p[0]);

    return 0;
}

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

if Y > N*10000 or Y < N*1000:
    print("-1 -1 -1")
else:
    for i in range(N+1):
        for j in range(N+1-i):
            k = N-i-j
            m = 10000*i+5000*j+1000*k
            if m == Y:
                print("%s %s %s" % (i, j, k))
                break
        else:
            continue
        break
    else:
        print("-1 -1 -1")


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
#define ALL(A) (A).begin(),(A).end()
#define ll long long
const ll mod = 1e9+7;
const ll INF = 2*1e18;
const int inf = 1e9+7;

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N;
	cin >> N;
	string S1,S2;
	cin >> S1 >> S2;
	vector<int> v;
	for(int i=0;i<N;i++){
		if(S1[i]==S2[i]){
			v.push_back(0);
		}else{
			v.push_back(1);
			i++;
		}
	}
	ll ans = 1;
	if(v[0]==0)ans = 3;
	else ans = 6;
	for(int i=1;i<v.size();i++){
		if(v[i]==1){
			if(v[i-1]==1){
				ans *= 3;
			}else{
				ans *= 2;
			}
		}else{
			if(v[i-1]==1){
				ans *= 1;
			}else{
				ans *= 2;
			}
		}
		ans %= 1000000007;
	}
	cout << ans%1000000007 << endl;
}

Measured memory_bytes: 256
#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;
#ifdef ENABLE_DEBUG
#define dump(a) cerr<<#a<<"="<<a<<endl
#define dumparr(a,n) cerr<<#a<<"["<<n<<"]="<<a[n]<<endl
#else
#define dump(a) 
#define dumparr(a,n) 
#endif
#define FOR(i, a, b) for(ll i = a;i < b;i++)
#define For(i, a) FOR(i, 0, a)
#define REV(i, a, b) for(ll i = b-1;i >= a;i--)
#define Rev(i, a) REV(i, 0, a)
#define REP(a) For(i, a)
#define SIGN(a) (a==0?0:(a>0?1:-1))

typedef long long int ll;
typedef unsigned long long ull;
typedef unsigned int uint;
typedef pair<ll, ll> pll;
typedef pair<ll,pll> ppll;
typedef vector<ll> vll;

const ll INF=(1LL<<50);
#if __cplusplus>=201700L
ll gcd(ll a, ll b) {
  if(a < b) return gcd(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
#endif

template<class S,class T>
std::ostream& operator<<(std::ostream& os,pair<S,T> a){
  os << "(" << a.first << "," << a.second << ")";
  return os;
}
template<class T>
std::ostream& operator<<(std::ostream& os,vector<T> a){
  os << "[ ";
  REP(a.size()){
    os<< a[i] << " ";
  }
  os<< " ]";
  return os;
}


void solve(std::vector<long long> A){
  if(A[0]+A[1]+A[2]<22){
    cout<<"win"<<endl;
  }else{
    cout<<"bust"<<endl;
  }
}

int main(){
    std::vector<long long> A(3);
    for(int i = 0 ; i < 3 ; i++){
        scanf("%lld",&A[i]);
    }
    solve(std::move(A));
    return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) throws IOException {
		Main mainObj = new Main();
		mainObj.solve();
	}

	public void solve() throws IOException {
		FastScanner fs = new FastScanner();
		String str = fs.next();
		char beforeChar = '\0';
		for(int i = 0; i < str.length(); i++) {
			char nowChar = str.charAt(i);
			if(nowChar == beforeChar) {
				System.out.println("Bad");
				return;
			}
			beforeChar = nowChar;
		}
		System.out.println("Good");
	}

	

	public class FastScanner {

		BufferedReader reader;
		private StringTokenizer st;

		public FastScanner() {
			st = null;
			reader = new BufferedReader(new InputStreamReader(System.in));
		}

		public String next() throws IOException {
			if (st == null || !st.hasMoreElements()) {
				st = new StringTokenizer(reader.readLine());
			}
			return st.nextToken();
		}

		public String nextLine() throws IOException {
			st = null;
			String readLine = null;
			readLine = reader.readLine();
			return readLine;
		}

		public int nextInt() throws NumberFormatException, IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws NumberFormatException, IOException {
			return Long.parseLong(next());
		}

		public int[] nextIntArr(int n) throws NumberFormatException, IOException {
			int[] retArr = new int[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextInt();
			}
			return retArr;
		}

		public long[] nextLongArr(int n) throws NumberFormatException, IOException {
			long[] retArr = new long[n];
			for (int i = 0; i < n; i++) {
				retArr[i] = nextLong();
			}
			return retArr;
		}

		public void close() throws IOException {
			reader.close();
		}
	}

}


Measured memory_bytes: 22612
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)

int main(){
    string s;
    cin>>s;
    
    int p[26]={};
    rep(i,s.size()){
        p[s[i]-'a']++;
    }
    
    if(s.size()%2==0){
        int odd = 0;
        rep(i,26)if(p[i]%2)odd++;
        cout<<odd/2+odd%2<<endl;
    }
    else{
        int ans = INF;
        rep(i,s.size()){
            p[s[i]-'a']--;
            
            int odd = 0;
            rep(i,26)if(p[i]%2)odd++;
            ans = min(ans,odd/2+odd%2);
            
            p[s[i]-'a']++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3136
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

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

int main() {
  int n;
  cin >> n;
  n %= 10;
  if(n == 3) cout << "bon" << endl;
  else if(n == 0 || n == 1 || n == 6 || n == 8) cout << "pon" << endl;
  else cout << "hon" << endl;

  return 0;
}

Measured memory_bytes: 3588
class Surface:
    def __init__(self, mp):
        self.mp = mp

    def mirror(self):
        for y in range(5):
            self.mp[y] = self.mp[y][::-1]

    def mirror_ud(self):
        for y in range(2):
            self.mp[y], self.mp[4 - y] = self.mp[4 - y], self.mp[y]

    def spin90(self):
        new_mp = [[None] * 5 for _ in range(5)]
        for y in range(5):
            for x in range(5):
                new_mp[x][4 - y] = self.mp[y][x]
        self.mp = new_mp

    def spin270(self):
        new_mp = [[None] * 5 for _ in range(5)]
        for y in range(5):
            for x in range(5):
                new_mp[4 - x][y] = self.mp[y][x]
        self.mp = new_mp

    def to_hash(self):
        ret = 0
        for y in range(5):
            for x in range(5):
                if self.mp[y][x] != ".":
                    ret += 2 ** (y * 5 + x)
        return ret


def calc(lst):
    return sum([2 ** i for i in lst])


hash_dic = {
    calc([8, 18, 22]):1,
    calc([2, 8, 12, 16, 22]):2,
    calc([2, 8, 12, 18, 22]):3,
    calc([6, 8, 12, 18]):4,
    calc([2, 6, 12, 18, 22]):5,
    calc([2, 6, 12, 16, 18, 22]):6,
    calc([2, 8, 18]):7,
    calc([2, 6, 8, 12, 16, 18, 22]):8,
    calc([2, 6, 8, 12, 18, 22]):9
}


def make_dice(drawing):
    dice = []
    s1 = Surface([line[8:13] for line in drawing[1:6]])
    s1.mirror()
    dice.append(hash_dic[s1.to_hash()])

    s2 = Surface([line[1:6] for line in drawing[8:13]])
    s2.spin90()
    s2.mirror()
    dice.append(hash_dic[s2.to_hash()])

    s3 = Surface([line[8:13] for line in drawing[8:13]])
    s3.mirror()
    dice.append(hash_dic[s3.to_hash()])

    s4 = Surface([line[15:20] for line in drawing[8:13]])
    s4.spin270()
    s4.mirror()
    dice.append(hash_dic[s4.to_hash()])

    s5 = Surface([line[22:27] for line in drawing[8:13]])
    s5.mirror()
    dice.append(hash_dic[s5.to_hash()])

    s6 = Surface([line[8:13] for line in drawing[15:20]])
    s6.mirror()
    s6.mirror_ud()
    dice.append(hash_dic[s6.to_hash()])

    return dice


def result(dice1, dice2):
    cnt1 = cnt2 = 0
    for num1 in dice1:
        for num2 in dice2:
            if num1 > num2:
                cnt1 += 1
            if num1 < num2:
                cnt2 += 1
    print("HIGH" if cnt1 >= cnt2 else "LOW")


while True:
    s = input()
    if s == "0":
        break
    drawing1, drawing2 = [s[:28]], [s[29:]]
    for _ in range(20):
        s = input()
        drawing1.append(s[:28])
        drawing2.append(s[29:])
    dice1 = make_dice(drawing1)
    dice2 = make_dice(drawing2)
    result(dice1, dice2)




Measured memory_bytes: 5740
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n;
int a[200010];
int XOR;
int main() {
	cin >> n;
	for (int i = 1; i <= n; i++) cin >> a[i], XOR ^= a[i];
	for (int i = 1; i <= n; i++) cout << (a[i] ^ XOR) << " ";
	return 0;
}

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

#define rep(X,N) for(int X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    string s;
    cin >> s;

    rep(i, s.size()){
        if(s[i] == '?'){
            s[i] = 'D';
        }
    }

    cout << s << endl;
    return 0;
}


Measured memory_bytes: 3724
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int h, w;
string s[109];
long long dp[109][109];

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> h >> w;
	for (int i = 0; i < h; i++) cin >> s[i];
	if (s[0][0] == '#') dp[0][0]++;
	for (int j = 1; j < w; j++) {
		dp[0][j] = dp[0][j - 1];
		if (s[0][j] == '#') {
			if (s[0][j - 1] == '.') dp[0][j]++;
		}
	}
	for (int i = 1; i < h; i++) {
		dp[i][0] = dp[i - 1][0];
		if (s[i][0] == '#') {
			if (s[i - 1][0] == '.') dp[i][0]++;
		}
	}
	for (int i = 1; i < h; i++) {
		for (int j = 1; j < w; j++) {
			long long t0 = dp[i][j - 1], t1 = dp[i - 1][j];
			if (s[i][j] == '#') {
				if (s[i][j - 1] == '.') t0++;
				if (s[i - 1][j] == '.') t1++;
			}
			dp[i][j] = min(t0, t1);
		}
	}
	cout << dp[h - 1][w - 1] << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 384
a, b = map(int, input().split())
c = [int(input())for _ in range(a)]
c.sort()
d = b - sum(c)
e = len(c)
while True:
    if d - c[0] < 0:
        break
    else:
        d = d - c[0]
        e += 1
print(e)


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;


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

    string str1,str2;
    cin>>str1>>str2;
    int ans=0;
    for(int i=0;i<3;i++)
    {
        if(str2[i]==str1[i])
        {
            ans++;    
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,n,a,b,c,flag=0;
    cin>>n;
    cin>>a>>b;
    for(i=a; i<=b; i++)
    {
        c=i%n;
        if(c==0)
        {
            flag=1;
            break;

        }
    }
    if(flag==1)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;
        
return 0;

}


Measured memory_bytes: 3676
#include<bits/stdc++.h>
#define del(a,i) memset(a,i,sizeof(a))
#define ll long long
#define inl inline
#define il inl void
#define it inl int
#define ill inl ll
#define re register
#define ri re int
#define rl re ll
#define mid ((l+r)>>1)
#define lowbit(x) (x&(-x))
#define INF 0x3f3f3f3f
using namespace std;
template<class T>il read(T &x){
	int f=1;char k=getchar();x=0;
	for(;k>'9'||k<'0';k=getchar()) if(k=='-') f=-1;
	for(;k>='0'&&k<='9';k=getchar()) x=(x<<3)+(x<<1)+k-'0';
	x*=f;
}
template<class T>il _print(T x){
	if(x/10) _print(x/10);
	putchar(x%10+'0');
}
template<class T>il print(T x){
	if(x<0) putchar('-'),x=-x;
	_print(x);
}
ll mul(ll a,ll b,ll mod){long double c=1.;return (a*b-(ll)(c*a*b/mod)*mod)%mod;}
it qpow(int x,int m,int mod){
	int res=1,bas=x;
	while(m){
		if(m&1) res=(1ll*res*bas)%mod;
		bas=(1ll*bas*bas)%mod,m>>=1;
	}
	return res;
}
const int N = 3e5+5,mod = 1e9+7;
it add(int x,int y){ return x+y>=mod?x+y-mod:x+y; }
it mul(int x,int y){ return 1ll*x*y%mod; }
il inc(int &x,int y){ x=add(x,y); }
int n,f[N][3][3];
char s[N];
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	scanf("%s",s+1),n=strlen(s+1);
	f[0][0][0]=1;
	for(ri i=1;i<=n;++i) for(ri j=0;j<3;++j)
		for(ri k=0;k<3;++k){
			if(s[i]!='0'){
				if(k) inc(f[i][j][k-1],f[i-1][j][k]);
				else inc(f[i][min(j+1,2)][k],f[i-1][j][k]);
			}
			if(s[i]!='1'){
				if(k==2) inc(f[i][j][1],f[i-1][j][k]);
				else inc(f[i][j][k+1],f[i-1][j][k]);
			}
		}
	int ans=0;
	assert(f[n][0][0]==0&&f[n][0][2]==0&&f[n][1][1]==0);
	for(ri i=0;i<3;++i) for(ri j=0;j<=i;++j) inc(ans,f[n][i][j]);
	print(ans);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n;
	string s[125252];
	cin>>n;
	REP(i, n){
		cin>>s[i];
		sort(ALL(s[i]));
	}
	sort(s, s+n);
	// REP(i, n){
	// 	cout<<s[i]<<'\n';
	// }
	int i=0;
	ll ans=0;
	while(i<n){
		ll cnt=1;
		while(i<n && s[i]==s[i+1]){
			++i;
			++cnt;
			// DEBUG(i);
		}
		// DEBUG(cnt);
		// DEBUG(s[i]);
		ans+=cnt*(cnt-1)/2;
		++i;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 5888
import fractions as math
a,b,c,d = map(int,input().split())
"""
aからbまでの倍数を求めるのではなく、
0からa-1,0からbまでの２つに分けてそれぞれ出して差で求める。
"""

a = a-1 #0からb迄を求めるときにaはもう使わないので変えちゃっていい
lcm = (c*d//math.gcd(c,d))
c = b//c - a//c
d = b//d - a//d
cd = b//lcm - a//lcm

#求めるのは割り切れる数ではなく割り切れない数
print(b-a-(c+d-cd))

Measured memory_bytes: 5048
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;

int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p;   
                 
  
    while (y > 0)  
    {  
        
        if (y & 1)  
            res = (res*x) % p;  
  
        
        y = y>>1;   
        x = (x*x) % p;  
    }  
    return res;  
}  

int main()
{




  int t;
  //cin>>t;
 t=1;

  while(t--)
{
    int n;
     cin>>n;

    long ans= (long)(n/500)*1000;
     n=n%500;

     ans+= (long)(n/5)*5;

    cout<<ans;
}

return 0;
}


Measured memory_bytes: 256
// B.

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

using namespace std;

typedef long long LL;
typedef pair<LL, LL> II;

int main(int argc, char *argv[]) {
	map<II, vector<int>> m;
	int n;
	cin >> n;
	vector<II> xy(n);
	map<II, int> xyi;
	for (int i = 0; i < n; ++i) {
		cin >> xy[i].first >> xy[i].second;
		xyi[xy[i]] = i;
	}
	int ans = n;
	sort(xy.begin(), xy.end());
	for (int i = 0; i < n; ++i) {
		for (int j = i + 1; j < n; ++j) {
			int cost = n;
			for (int k = 0; k < n; ++k) {
				II temp(xy[k].first - xy[j].first + xy[i].first, xy[k].second - xy[j].second + xy[i].second);
				auto x = xyi.find(temp);
				if (x != xyi.end()) {
					--cost;
				}
			}
			ans = min(ans, cost);
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.awt.geom.Point2D;
import java.util.*;
 
public class Main {
    Scanner sc = new Scanner(System.in);
 
    public static void main(String[] args) {
    	new Main(); 
    }
 
    public Main() {
    	while(sc.hasNext()){
    		new aoj0054().doIt();
    	}
    }
    class aoj0054{
    	void doIt(){
    		int a = sc.nextInt();
    		int b = sc.nextInt();
    		if(a >= b)a = a % b;
    		int n = sc.nextInt();
    		int sum = 0;
    		for(int i = 0;i < n;i++){
    			a = a * 10;
    			sum += a / b;
    			a = a % b;
    		}
    		System.out.println(sum);
    	}
    }
}

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

using namespace std;
long long change_num(long long p[], int N) {
  long long res = 0;
  long long next_sum;
  long long sum = p[0];
  for (int i = 1; i < N; i++) {
    next_sum = sum + p[i];
    if((sum < 0 && next_sum > 0) || (sum > 0 && next_sum < 0)) {
      sum = next_sum;
      continue;
    } 
    if(sum > 0 && next_sum >= 0) {
      res += next_sum + 1;
      sum = -1;
      continue;
    }
    if (sum < 0 && next_sum <= 0) {
      res += 1 - next_sum;
      sum = 1;
      continue;
    }
  }
  return res;
}


int main() {
  int N;
  cin >> N;
  
  long long a[N];
  for (int i = 0; i < N; i++)
    cin >> a[i];
    
  long long ans = 0;
  long long sum = a[0];
  
  long long plus_ans = 0;
  long long minus_ans = 0;
  if (a[0] == 0) {
    plus_ans = 1; 
    a[0] = 1;
    plus_ans += change_num(a, N); 
 
    minus_ans = 1;
    a[0] = -1;
    minus_ans += change_num(a, N);
  } else if (a[0] > 0) {
    plus_ans = 0; 
    plus_ans += change_num(a, N); 
 
    minus_ans = 1 + a[0];
    a[0] = -1;
    minus_ans += change_num(a, N);
    
  } else {
    minus_ans = 0;
    minus_ans += change_num(a, N);
    
    plus_ans = 1 - a[0]; 
    a[0] = 1;
    plus_ans += change_num(a, N); 
 
  }

    
  if(plus_ans < minus_ans) {
    ans = plus_ans;
  } else {
    ans = minus_ans;
  }  
  cout << ans << endl;

}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
// statics
using namespace std;
using int64 = int_fast64_t;
using PAIR = pair<int64, int64>;
constexpr int INF = 1 << 30;
constexpr int64 LINF = 1LL << 60;
constexpr int MOD = 1e9 + 7;
constexpr int MAX_N = 3e5 + 1;

// init/input
#define int int64
#define INIT ios::sync_with_stdio(false);cin.tie(0);
#define VAR(type, ...) type __VA_ARGS__;MACRO_VAR_Scan(__VA_ARGS__);
template<typename T> void MACRO_VAR_Scan(T &t) {cin>>t;}
template<typename First, typename...Rest> void MACRO_VAR_Scan(First &first, Rest&...rest) {cin>>first;MACRO_VAR_Scan(rest...);}
#define VEC(type, c, n) vector<type> c(n);for(auto &&i:c)cin>>i;

// out
#define OUT(dist) cout<<(dist);
#define FOUT(n, dist) cout<<fixed<<setprecision(n)<<(dist);
#define SP cout<<" ";
#define BR cout<<endl;
#define zero(n) cout<<setfill('0')<<right<<setw(n)
#define debug(x) cerr<<#x<<":"<< (x);BR;

// utility
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, a) for(auto &&i:(a))
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define RFOR(i, a, b) for(int i=(b)-1;i>=0;--i)
#define REP(i, n) for(int i=0;i<(n);++i)
#define RREP(i, n) for(int i=(n)-1;i>=0;--i)

int gcd(int a,int b){
	return a%b==0?b:gcd(b,a%b);
}

signed main() {
  INIT;
	VAR(int,n);
	VEC(int,a,n);
	int ans=a.back();
	REP(i,n){
		ans=min(ans,gcd(ans,a[i]));
	}
	OUT(ans)BR;
  
  return 0;
}


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

int main() {
    int n;
    map< string, int> s_map;
    string s;
    int i;
    int max_s = 0;

    cin >> n;

    for(i = 0; i < n; i++) {
        cin >> s;
        s_map[s] = s_map[s] + 1;
        if(s_map[s] > max_s) {
            max_s = s_map[s];
        }
    }

    for(auto itr = s_map.begin(); itr != s_map.end(); ++itr) {
        if(itr->second == max_s) {
            cout << itr->first << endl;
        }
    }
}

Measured memory_bytes: 25216
using System;
using System.Collections.Generic;
using System.Linq;
using static AtCoder.Io;

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            Console.WriteLine("auieo".Contains(ReadString()) ? "vowel" : "consonant");
        }
    }

    public static class Io
    {
        public static string ReadString() => Console.ReadLine();
        public static string[] ReadStringArray() => ReadString().Split(' ');
        public static int ReadInt() => int.Parse(ReadString());
        public static long ReadLong() => long.Parse(ReadString());
        public static int[] ReadIntArray() => ReadStringArray().ParseInt().ToArray();
        public static long[] ReadLongArray() => ReadStringArray().ParseLong().ToArray();
        public static IEnumerable<int> ParseInt(this IEnumerable<string> source) => source.Select(int.Parse);
        public static IEnumerable<long> ParseLong(this IEnumerable<string> source) => source.Select(long.Parse);
    }
}


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

typedef long long ll;

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

    ll n,x;
    cin >> n >> x;
    vector<ll> a(n);
    for(ll i=0;i<n;i++) cin >> a[i];
    ll ans = 0;
    for(ll i=0;i<n-1;i++){
        if(a[i]+a[i+1]>x){
            if(x-a[i]>=0){
                ans += a[i+1]-(x-a[i]);
                a[i+1] = x - a[i];
            }else{
                ans += a[i+1] + a[i] - x;
                a[i+1] -= a[i+1];
                a[i] = x;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;
using ll = long long;

int main() {
    ll a[2], b[2];
    cin >> a[0] >> a[1] >> b[0] >> b[1];

    ll m = -1e18;
    for(int i=0; i<2; i++) {
        for(int j=0; j<2; j++) {
            m = max(m, a[i]*b[j]);
        }
    }
    cout << m;
    return 0;

}


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

#define rep(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
#define SZ(x) ((int) (x).size())
typedef long long ll;

int main(){
	string str;
	cin >> str;
	int len = SZ(str);
	int first;
	rep(i,0,26) {
		char c = 'a' + i;
		first=-1;
		rep(j,0,len) {
			if(str[j]!=c) continue;
			if(first==-1) first=j;
			else {
				if(j-first<=2) {
					cout<< first+1 << " "<< j+1 <<endl;
					return 0;
				}
				first = j;
			}
		}
	}
	cout<<-1<<" "<<-1<<endl;
	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<functional>
#include<queue>
#include<map>
using namespace std;
long long n, a[100009];
int main() {
	cin >> n;
	for (int i = 0; i < n; i++) { cin >> a[i]; }
	sort(a, a + n, greater<int>());
	vector<long long>E;
	for (int i = 0; i < n - 1; i++) {
		if (a[i] == a[i + 1]) { E.push_back(a[i]); i++; }
	}
	if (E.size() <= 1)cout << "0" << endl;
	else cout << E[0] * E[1] << endl;
	return 0;
}

Measured memory_bytes: 1660
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
#include <vector>

using namespace std;

int main() {
	int N, Y;
	cin >> N >> Y;
	int res10000 = -1, res5000 = -1, res1000 = -1;
	for (int i = 0; i <= N; i++) {
		for (int j = 0; j + i <= N; j++) {
			int c = N - i - j;
			int total = i * 10000 + j * 5000 + c * 1000;
			if (total == Y) {
				res10000 = i;
				res5000 = j;
				res1000 = c;
			}
		}
	}
	cout << res10000 << ' ' << res5000 << ' ' << res1000 << endl;
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<29)

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int n, m, s, g1, g2;
	while (cin >> n >> m >> s >> g1 >> g2) {
		if (n == 0 && m == 0 && s == 0 && g1 == 0 && g2 == 0) break;
		n; m; s--; g1--; g2--;
		vector<vector<int>> dist(n, vector<int>(n, INF));
		for (int i = 0; i < m;i++) {
			int b1, b2, c; cin >> b1 >> b2 >> c;
			b1--; b2--;
			dist[b1][b2] = c;
		}

		//WarshallFloyd
		for (int i = 0; i < n;i++) dist[i][i] = 0;
		for (int i = 0;i < n;i++)for (int j = 0; j < n;j++)for (int k = 0;k < n;k++) {
			dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
		}

		int ans = INF;
		for (int i = 0; i < n;i++) {
			ans = min(ans, dist[s][i] + dist[i][g1] + dist[i][g2]);
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 3180
#include <cstdio>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;

const int INF=1<<30;

template <class RandomIt>
size_t msort(RandomIt first, RandomIt last) {
    if (first+1 >= last) return 0;

    using T=typename RandomIt::value_type;
    ptrdiff_t lhalf=(last-first)>>1;
    RandomIt mid=first+lhalf;

    size_t count_=0;
    count_ += msort(first, mid);
    count_ += msort(mid, last);

    ptrdiff_t rhalf=last-mid;
    vector<T> L(lhalf+1), R(rhalf+1); L[lhalf]=R[rhalf]=INF;

    for (RandomIt in=first, out=L.begin(); in<mid; (++in, ++out))
        *out = *in;

    for (RandomIt in=mid, out=R.begin(); in<last; (++in, ++out))
        *out = *in;

    for (RandomIt it=first, l=L.begin(), r=R.begin(); it<last; ++it) {
        if (*l <= *r) {
            *it = *l++;
        } else {
            *it = *r++;
            count_ += lhalf-(l-L.begin());
        }
    }

    return count_;
}

int main() {
    size_t n;
    scanf("%zu", &n);

    vector<int> a(n);
    for (size_t i=0; i<n; ++i)
        scanf("%d", &a[i]);

    printf("%lld\n", msort(a.begin(), a.end()));
    return 0;
}

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

int main() {

  string s;
  cin >> s;

  if(s[s.size()-1]  == 's'){
  // 条件分岐　どう設定したらいいものか…
    std::cout << s << "es" << "\n";
   }else{
      std::cout << s << "s" << "\n";
  }

  return 0;
}

Measured memory_bytes: 3136