akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;
static const int INF (1<<30);

int main() {
  int N; cin >> N;
  string S; cin >> S;
  S = 'z' + S;

  vector<char> ans(N+2);
  bool done = false;

  // first sheep last sheep
  ans[0] = 'S';
  ans[1] = 'S';
  for (int i = 1; i <= N; i++) {
    if (ans[i] == 'S') {
      if (S[i] == 'o') {
        ans[i+1] = ans[i-1];
      } else {
        if (ans[i-1] == 'S') ans[i+1] = 'W';
        else ans[i+1] = 'S';
      }
    } else {
      if (S[i] == 'x') {
        ans[i+1] = ans[i-1];
      } else {
        if (ans[i-1] == 'S') ans[i+1] = 'W';
        else ans[i+1] = 'S';
      }
    }
  }
  if (ans[0] == ans[N] && ans[1] == ans[N+1]) done = true;


  if (!done) {
    // first sheep last wolf
    ans[0] = 'W';
    ans[1] = 'S';
    for (int i = 1; i <= N; i++) {
      if (ans[i] == 'S') {
        if (S[i] == 'o') {
          ans[i+1] = ans[i-1];
        } else {
          if (ans[i-1] == 'S') ans[i+1] = 'W';
          else ans[i+1] = 'S';
        }
      } else {
        if (S[i] == 'x') {
          ans[i+1] = ans[i-1];
        } else {
          if (ans[i-1] == 'S') ans[i+1] = 'W';
          else ans[i+1] = 'S';
        }
      }
    }
    if (ans[0] == ans[N] && ans[1] == ans[N+1]) done = true;
  }

  if (!done) {
    // first wolf last wolf
    ans[0] = 'W';
    ans[1] = 'W';
    for (int i = 1; i <= N; i++) {
      if (ans[i] == 'S') {
        if (S[i] == 'o') {
          ans[i+1] = ans[i-1];
        } else {
          if (ans[i-1] == 'S') ans[i+1] = 'W';
          else ans[i+1] = 'S';
        }
      } else {
        if (S[i] == 'x') {
          ans[i+1] = ans[i-1];
        } else {
          if (ans[i-1] == 'S') ans[i+1] = 'W';
          else ans[i+1] = 'S';
        }
      }
    }
    if (ans[0] == ans[N] && ans[1] == ans[N+1]) done = true;
  }

  if (!done) {
    // first wolf last sheep
    ans[0] = 'S';
    ans[1] = 'W';
    for (int i = 1; i <= N; i++) {
      if (ans[i] == 'S') {
        if (S[i] == 'o') {
          ans[i+1] = ans[i-1];
        } else {
          if (ans[i-1] == 'S') ans[i+1] = 'W';
          else ans[i+1] = 'S';
        }
      } else {
        if (S[i] == 'x') {
          ans[i+1] = ans[i-1];
        } else {
          if (ans[i-1] == 'S') ans[i+1] = 'W';
          else ans[i+1] = 'S';
        }
      }
    }
    if (ans[0] == ans[N] && ans[1] == ans[N+1]) done = true;
  }


  if (done) {
    ans.erase(ans.begin());
    ans.pop_back();
    for (auto x : ans) cout << x;
  } else {
    cout << -1 << endl;
  }

  return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL, LL> PII;

// chmax, chmin
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;
}

template <typename T>
function<T(T, T)> op_max = [](T a, T b) -> T { return max(a, b); };
template <typename T>
function<T(T, T)> op_min = [](T a, T b) -> T { return min(a, b); };

template <typename T>
function<T(T, T)> op_sum = [](T a, T b) -> T { return a + b; };

namespace detail {
template <typename T, std::size_t NDIMS>
struct vector_builder {
  using type = std::vector<typename vector_builder<T, NDIMS - 1>::type>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    const auto vec = std::vector<T>(dims.empty() ? 0 : dims.back(), v);
    if (!dims.empty()) dims.pop_back();
    return vector_builder<std::vector<T>, NDIMS - 1>::make(dims, vec);
  }
};

template <typename T>
struct vector_builder<T, 1> {
  using type = std::vector<T>;

  static type make(std::vector<std::size_t> dims, const T& v = {}) {
    return type(dims.empty() ? 0 : dims.back(), v);
  }
};
}  // namespace detail

template <typename T, typename... SIZE_T>
auto exvector(const T& v, SIZE_T... dims) {
  static_assert(sizeof...(dims) != 0, "invalid dimension");
  std::vector<std::size_t> vec_dims{dims...};
  return detail::vector_builder<T, sizeof...(dims)>::make(vec_dims, v);
}

using namespace std;
//********************  dumps ************************//

template <typename T>
void dump(const T& data, vector<int>& iter) {
  cout << data << " ";
}
template <typename T>
void dump(const vector<T>& data, vector<int>& iter) {
  for (auto elem : data) dump(elem, iter);
  cout << endl;
}

template <typename T>
void dump(const vector<vector<T>>& data, vector<int>& iter) {
  for (auto elem : iter) {
    cout << "[" << elem << "]";
  }
  cout << endl;
  for (int i = 0; i < data.size(); i++) {
    iter.push_back(i);
    dump(data[i], iter);
    iter.pop_back();
  }
  cout << endl;
}

template <typename T>
void dump(const vector<T>& data, int dummy) {
  for (int i = 0; i < data.size(); i++) {
    cout << "[" << i << "] " << data[i] << endl;
  }
}
template <typename T>
void dump(const T& data) {  // T : data, U = base type val.
  vector<int> iter;
  dump(data, iter);
}
///////////////////////////////////////////////

int main() {
  cout << setprecision(10);

  int N;
  cin >> N;
  vector<int> vals(N);
  for (int i = 0; i < N; i++) cin >> vals[i];

  int ret = 1000000000;
  int pos = 0;
  for (int cand = 1; cand <= 100; cand++) {
    int tmp = 0;
    for (auto val : vals) {
      tmp += (val - cand) * (val - cand);
    }
    ret = min(ret, tmp);
  }
  cout << ret << endl;

  return 0;
}


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

using namespace std;

void solve()
{
	int N;
	cin >> N;
	vector<int> s(12);
	int ans = 0;

	for (int i = 0; i < N; i++)
	{
		int d;
		cin >> d;
		if (d)
		{
			s[d-1]++;
			if (s[d-1]==3)
			{
				cout << 0 << endl;
				return;
			}
		}
		else
		{
			cout << 0 << endl;
			return;
		}
	}
	for (int bit = 0; bit < 1<<12; bit++)
	{
		vector<int> v;
		v.push_back(0);
		for (int i = 0; i < 12; i++)
		{
			if (!s[i]) continue;
			v.push_back((bit>>i&1)?i+1:23-i);
			if (s[i]>1) v.push_back((bit>>i&1)?23-i:i+1);
		}
		int n = v.size(), res = 12;
		for (int i = 0; i < n-1; i++)
			for (int j = i+1; j < n; j++)
			{
				int diff = abs(v[j]-v[i]);
				res = min(res, min(24-diff, diff));
			}
		ans = max(ans, res);
	}
	cout << ans << endl;
}

int main(void)
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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

int main(){
	int a,b,c,d;
	cin >> a >> b >> c;

	for(int i = a ; i <= b ;i++ ){
		if(c%i == 0)
			d += 1 ;
		}
	cout << d << endl;
	return 0;
}

Measured memory_bytes: 3088
#include <stdio.h>
#include <ctype.h>
int main(void){
    // Your code here!
    int n,k;
    scanf("%d %d",&n,&k);
    char s[n];
    scanf("%s",s);
    
    s[k-1] = tolower(s[k-1]);
    
    printf("%s",s);
    
    
    return 0;
}


Measured memory_bytes: 128
def main(n):
    a = list(map(int, input().split()))
    dp = [[0] * (n+1) for i in range(n)]
    # 区間[l,r)の最大落とせる個数
    for i in range(n - 1):
        if abs(a[i] - a[i + 1]) <= 1:
            dp[i][i + 2] = 2
            # 隣り合う達磨weightが1以内のペアをdpに記録
    for i in range(2, n): # 区間の広さ, 最大で0番目とn-1番目の差
        for l in range(n-i): # 左側のとれる値は区間の広さに依存
            r = i+l+1 # 右側は上記2変数から計
            if abs(a[l] - a[r-1]) <= 1: # 今見ている左端と右端がweight 1以内の時
                if dp[l+1][r-1] == r-l-2: # 左右1個ずつ内側の最大落とせる個数が「全部落とせる」だったとき
                    dp[l][r] = r-l # dp[l][r]は左右端を追加して記録
                    continue
            res = dp[l+1][r-1] # とりあえず現在の左右1個ずつ内側の値を記録
            for li in range(l+1, r): # lとrの間のどこかで区切って「lから区切り」「区切りからr」までの和を出す
                tmp = dp[l][li] + dp[li][r] # 区間[l, li) と 区間[li, r)のdp和
                if res < tmp: #区切った場所が最大値を更新するのであればresを更新
                    res = tmp
            dp[l][r] = res
    print(dp[0][n]) # 左端 0 から右端 n-1 までの最大値を出す

if __name__ == "__main__":
    while 1:
        n = int(input())
        if n:
            main(n)
        else:
            break


Measured memory_bytes: 6376
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "bitset"

using namespace std;

//const long long int MOD = 998244353;
//const long long int MOD = 1000000007;
const long long int MOD = 924844033;

long long int N, M, K, H, W, L, R;


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

	cin >> N >> K;
	long long int ans = 1;
	for (int i = 2; i <= N; i++) {
		ans *= i;
		ans %= MOD;
	}
	vector<int>num(2 * K);
	for (int i = 0; i < N; i++) {
		num[i % (2 * K)]++;
		if (i + K < N)num[i % (2 * K)]++;
		if (i / (2 * K))continue;
		if (i - K >= 0)num[i % (2 * K)]++;
	}
	int bag = 0;
	for (auto i : num)bag = max(bag, i);
	vector<vector<long long int>>dp(bag + 1, vector<long long int>(N + 1));
	dp[0][0] = 1;
	dp[1][0] = 1;
	for (int i = 2; i <= bag; i++) {
		for (int j = 0; j <= N; j++) {
			dp[i][j] = dp[i - 1][j];
			if (j)dp[i][j] += dp[i - 2][j - 1];
			dp[i][j] %= MOD;
//			cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	vector<long long int>by(N + 1, 1);
	for (int i = 1; i <= N; i++) {
		by[i] = by[i - 1] * i;
		by[i] %= MOD;
	}
	vector<long long int>ndp(N + 1);
	ndp[0] = 1;
	for (int i = 0; i < 2 * K; i++) {
		for (int j = N; j >= 1; j--) {
			for (int k = min(num[i] / 2, j); k >= 1; k--) {
				ndp[j] += ndp[j - k] * dp[num[i]][k];
				ndp[j] %= MOD;
			}
		}
		//for (auto j : ndp)cout << j << endl;
	}
	for (int i = 1; i <= N; i++) {
		ans += MOD*MOD;
		if(i%2)ans -= ndp[i] * by[N - i];
		else ans += ndp[i] * by[N - i];
		ans %= MOD;
	//	cout << ans << endl;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;
const int mod=1e9+7;
typedef long long ll;
const int inf=0x3f3f3f3f;
const int maxn=1e3+100;

ll a[maxn];
int main()
{
    ll n,k;
    scanf("%lld%lld",&n,&k);
    int tot=0;
    while(n){
        tot++;
        n/=k;
    }
    cout<<tot<<endl;
    return 0;
}
/*

ll qpow(ll x,ll y){
    ll sum=1;
    while(y){
        if(y&1)
            sum=sum*x%mod;
        y/=2;
        x=x*x%mod;
    }
    return sum;
}
ll C(ll n,ll m){
    ll low=min(m,n-m);
    ll H=1,L=1;
    for(int i=n-low+1;i<=n;i++)
        H=H*i%mod;
    for(int i=1;i<=low;i++)
        L=L*i%mod;
    return H*qpow(L,mod-2)%mod;
}
*/



Measured memory_bytes: 256
def cvtTime(s):
    h, m, s = map(int, s.split(":"))
    return h * 60 * 60 + m * 60 + s


while True:
    n = int(input())
    if n == 0:
        break

    cnt = [0] * (60 * 60 * 24 + 2)

    for i in range(n):
        begin, end = input().split()
        begin_time = cvtTime(begin)
        end_time = cvtTime(end)

        cnt[begin_time] += 1
        cnt[end_time] -= 1

    for i in range(1, len(cnt)):
        cnt[i] += cnt[i - 1]

    print(max(cnt))


Measured memory_bytes: 9548
#include<bits/stdc++.h>
using namespace std;
 
using lli = long long int;
using ll = long long ;
using ld=long double;
using d= double;

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

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <map>
#include <set>
#include <queue>
#include <list>
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define crep(i) for(char i='a';i<='z';i++)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define psortfirst(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.first<b.first;});
#define ALL(x) (x).begin(),(x).end()
int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}
using namespace std;
using pii  = pair<int,int>;
long long gcd(long long a, long long b){return (b == 0 ? a : gcd(b, a%b));}
long long lcm(long long a, long long b){return a*b/gcd(a,b);}
typedef long long ll;
#define MOD 1000000007
#define EPS 10e-8


int main(){
  int i,j,k;
  int sx,tx,sy,ty;
  cin>>sx >> sy>>tx>>ty;

  string ans = "";
  int dx,dy;
  dx = tx - sx; dy = ty - sy;
  cout << string(dx,'R') << string(dy,'U');
  cout << string(dx,'L') << string(dy,'D');
  cout << 'D' << string(dx+1,'R') << string(dy+1,'U') << 'L';
  cout << 'U' << string(dx+1,'L') << string(dy+1,'D') << 'R';
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000007;

int main()
{
	ll x;
	cin >> x;
	ll a, b;

	if (x % 11 == 0) a = (x / 11) * 2;
	else a = (x / 11 + 1) * 2;
	if ((x + 5) % 11 == 0) b = ((x + 5) / 11) * 2 - 1;
	else b = ((x + 5) / 11 + 1) * 2 - 1;
	cout << min(a, b) << endl;
}

Measured memory_bytes: 256
x, k, d=map(int,input().split())
x=abs(x)
#k回すべて戻っても0に達せない場合  k-x//d
if x//d>=k:
  print(x-k*d)
elif (k-x//d)%2==0:
  print(x%d)
else:
  print(abs(x-x//d*d-d))

Measured memory_bytes: 8960
#include<stdio.h>

int main(void){
	int m[20][20],i,l,n,x,y;
	
	while(scanf("%d",&n)!=0){
		if(n==0)break;
		for(i=0;i<20;i++){
			for(l=0;l<20;l++){
				m[i][l]=0;
			}
		}
		
		x=(n-1)/2;
		y=x+1;
		
		m[x][y]=1;
		
		for(i=2;i<=n*n;i++){
			x+=1;
			y+=1;
			while(1){
				if(x>=n){
					x=0;
					continue;
				}
				if(x<0){
					x=n-1;
					continue;
				}
				if(y>=n){
					y=0;
					continue;
				}
				if(y<0){
					y=n-1;
					continue;
				}
				if(m[x][y]>0){
					x-=1;
					y+=1;
					continue;
				}
				break;
			}
			m[x][y]=i;
		}
		
		for(i=0;i<n;i++){
			for(l=0;l<n;l++){
				printf("%4d",m[l][i]);
			}
			printf("\n");
		}
	}
	return 0;
}

		
		

Measured memory_bytes: 620
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010LL;
const int MAX=310;
const double EPS=1e-9;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n;cin>>n;
    if(n<=999){
        cout<<"ABC"<<endl;
    }else{
        cout<<"ABD"<<endl;
    }
}

Measured memory_bytes: 256
N, M = map(int, input().split())
sc = list(list(map(int, input().split())) for _ in range(M))

for i in range(1000):
    str_num = str(i)
    num_len = len(str_num)
    if num_len != N:
        continue
    for s, c in sc:
        if num_len < s:
            break
        if int(str_num[s - 1]) != c:
            break
    else:
        print(i)
        exit()

print("-1")


Measured memory_bytes: 3064
N = int(input())
from math import ceil, sqrt, factorial
from itertools import permutations
def eratosthenes(n):
    l = [1 for i in range(n+1)]
    l[0] = l[1] = 0
    for i in range(2, ceil(sqrt(n))):
        if l[i] == 0: continue
        for j in range(i*2, n+1, i):
            l[j] = 0
    return l

m = factorial(N)
ans = set()

p = eratosthenes(530)

p = [i for i,v in enumerate(p) if v ]

for i in p:
    a = i**74
    if not m % a:
        ans.add(a)
        break

for a,b in permutations(p,2):
    c = a**2*b**24
    if not m % c:
        ans.add(c)
    c = a**4*b**14
    if not m % c:
        ans.add(c)

for a,b,c in permutations(p, 3):
    d = a**2 * b**4 * c ** 4
    if not m % d:
        ans.add(d)

print(len(ans))

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

const int MAX = 5100000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  	COMinit();
   int X,Y;
  	cin >>X>>Y;
  	int a,b,flag=0;
  	a=2*Y-X;
  	b=2*X-Y;
  	if(a%3!=0||b%3!=0||a<0||b<0||(a==0&&b==0)){flag=1;}
  	a/=3;
  	b/=3;
  	if(flag==0){
  	cout<<COM(a+b,b)<<endl;
    }
  	else{cout<<0<<endl;}
}

Measured memory_bytes: 119808
#include<bits/stdc++.h>    
using namespace std;
#define ll long long 
#define pi pair<int,int>
#define pb push_back
#define inf 1e16
#define mod 1000000007
#define en '\n'
int pw(int a, int b){
	int ans = 1;
	while(b){
		if(b&1)ans = (ans*a)%mod;
		a = (a*a)%mod;
		b>>=1;
	}
	return ans;
}
int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll n;cin>>n;
	string s,t;cin>>s>>t;
	string ans = "";
	for(int i = 0 ; i < n ; i ++ ){
		ans.pb(s[i]);
		ans.pb(t[i]);
	}
	cout<<ans<<en;
	return 0 ; 
}



Measured memory_bytes: 256
a, b, c, x, y = map(int,input().split())

#cのみが最安
# a より2cが安い場合
# b より2cが安い場合
# 共通部をcで買って
# a+b より2cが安い場合

# 2まいずついる共通部
bose = min(x,y)

bose_cost = 0
if a+b > 2*c:
    bose_cost = 2*c
else:
    bose_cost = a+b


remain = max(x,y) - min(x,y)
remain_cost = 0


remain_one_cost = 0
if x> y:
    remain_one_cost = a
else:
    remain_one_cost = b

remain_cost = 0
if remain_one_cost > 2*c:
    remain_cost = 2*c
else:
    remain_cost = remain_one_cost

result = bose * bose_cost + remain_cost * remain
print(result)



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

using namespace std;
using ll = long long;

int main()
{
  ios_base::sync_with_stdio (0);
  cin.tie (0);
  int k, x;
  cin >> k >> x;
  for (int i = x - k + 1; i <= x + k - 1; i++) {
    cout << i <<  ' ';
  }
  return 0;
}


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

int main(void){
	char str[1001];		// input; input string , 1<=length<=1000
	int n=0;			// input; command times, 1<=n<=100
	int a=0, b=0;
	char* p_str=str;	// string pointer
	char cpy[1001];
	int i=0, j=0;		// loop index

	scanf("%s", str);
	scanf("%d", &n);
	for(i=0;i<n;i++){
		scanf("%s", cpy);
		if(strcmp(cpy, "print") == 0){
			scanf("%d %d", &a, &b);
			p_str = str + a;
			strncpy(cpy, p_str, b-a+1);
			cpy[b-a+1] = '\0';
			printf("%s\n", cpy);

		}else if(strcmp(cpy, "reverse") == 0){
			scanf("%d %d", &a, &b);
			p_str = str + b;
			for(j=0;j<b-a+1;j++){
				cpy[j] = *(p_str);
				p_str--;
			}
			p_str = str + a;		// ?????¶???????????????
			for(j=0;j<b-a+1;j++) *(p_str + j) = cpy[j];

		}else if(strcmp(cpy, "replace") == 0){
			scanf("%d %d %s", &a, &b, cpy);
			p_str = str + a;
			for(j=0;j<b-a+1;j++) *(p_str + j) = cpy[j];
		
		}else{
		
		}
	}
	return 0;
}

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

#define ll long long int
#define MOD ((int)(1e9) + 7)

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int a, b;
  cin >> a >> b;
  cout << (a-1 + b-1 -1) / (a-1) << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;
import java.util.function.Function;

/**
 * Created by btk on 2017/10/13.
 */
public class Main {
   public static void main(String[] args){
       Scanner sc=new Scanner(System.in);
       int n=sc.nextInt();
       int m=sc.nextInt();
       int[] a=new int[m];
       int[] b=new int[m];
       for (int i = 0; i < m; i++) {
           a[i] = sc.nextInt()-1;
           b[i] = sc.nextInt()-1;
       }
       int ret=m;
       for (int i = 0; i < m; i++) {
           int[][] d=new int[n][n];
           for (int j = 0; j < m; j++) {
               d[a[j]][b[j]]=1;
               d[b[j]][a[j]]=1;
           }
           for (int j = 0; j < n; j++) {
               d[j][j]=1;
           }
           d[a[i]][b[i]]=0;
           d[b[i]][a[i]]=0;

           for (int k = 0; k < n; k++) {
               for (int x = 0; x < n; x++) {
                   for (int y = 0; y < n; y++) {
                       d[x][y]|=d[x][k]&d[k][y];
                   }
               }
           }

           ret-=d[a[i]][b[i]];
       }
       System.out.println(ret);
       sc.close();
   }
}


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

int main()
{
  int a,b;cin>>a>>b;
  if ((a+b)%2==0)
  {
    cout << (a+b)/2 << endl;
  }
  else
  {
    cout << "IMPOSSIBLE" << endl;
  }
  
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>

using namespace std;

#define sz(a) static_cast<int>((a).size())
#define f first
#define s second
#define els(v) for (auto &el : (v))


#ifdef KIRYA
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define dbg(...)
#endif

template<typename T>
void _dbg(const char* _s, T _h) {
    cerr << _s << " = " << _h << "\n";
}

template<typename T, typename... Ts>
void _dbg(const char*_s, T _h, Ts... _t) {
    int _b = 0;

    while (((_b += *_s == '(') -= *_s == ')') != 0 || *_s != ',')
        cerr << *_s++;

    cerr << " = " << _h << ",";
    _dbg(_s + 1, _t...);
}

const int64_t INF = static_cast<int64_t>(1e9) + 7;
const int64_t LINF = INF * INF;
const int MAXN = static_cast<int>(1e6) + 17;

void solve() {
    int64_t a, b;
    cin >> a >> b;
    int64_t gcd = __gcd(a, b);
    int64_t bnd = pow(gcd, 0.5);
    int ans = 1;
    for (int i = 2; i <= bnd; ++i) {
        if (gcd % i == 0) {
            ++ans;
            while (gcd % i == 0) {
                gcd /= i;
            }
        }
    }
    ans += gcd != 1;
    cout << ans << '\n';
}

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

    int q = 1;

    for (int i = 0; i < q; ++i) {
        solve();
    }
}


Measured memory_bytes: 256
N = int(input())

# dp[i]を合計i円引き出すための最小の引き出し回数とする
# 再帰関数で求めようとするとsys.setrecursionlimit(100000)でも再帰関数上限を突破する

square_6_list = []
x = 1
while 6**x <= 10**5:
    square_6_list.append(6**x)
    x += 1

square_9_list = []
x = 1
while 9**x <= 10**5:
    square_9_list.append(9**x)
    x += 1

min_withdrow = [float("inf")]*(N+1)
min_withdrow[0] = 0
min_withdrow[1] = 1

for i in range(2, len(min_withdrow)):
    tmp_list = []
    for x in [1, 2, 3, 4, 5]:
        if i-x >= 0:
            tmp_list.append(min_withdrow[i-x] + x)
        else:
            break
    for x in square_6_list:
        if i-x >= 0:
            tmp_list.append(min_withdrow[i-x] + 1)
        else:
            break
    for x in square_9_list:
        if i-x >= 0:
            tmp_list.append(min_withdrow[i-x] + 1)
        else:
            break
    min_withdrow[i] = min(tmp_list)

print(min_withdrow[-1])

Measured memory_bytes: 3828
x = int(input())
if x==1:
  print(1)
  exit()
ans = 1
for i in range(x, 0, -1):
  m = i
  div = []
  for j in range(2,int(m**0.5)+2):
    if m%j==0:
      count = 0
      while m%j ==0:
        m //= j
        count += 1
      div.append(count)
  if m!= 1:
    div.append(1)
  count = div[0]
  for c in div:
    if c!= count or count ==1:
      break
  else:
    print(i)
    exit()
print(ans)



Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello{
    public Hello(){}
    public static void Main(){
        new Hello().Calc();
    }
    void Calc(){
        var inputs = InputValues;
        foreach(var i in inputs){
            Console.WriteLine(i);
        }
    }
    List<int> InputValues{
        get{
            var inputs = new List<int>();
            while(true){
                var s = Console.ReadLine().Split(' ');
                var a = int.Parse(s[0]);
                var b = int.Parse(s[2]);
                var op = s[1];
                if(op == "?"){
                    break;
                }
                switch(op){
                    case "+":
                        inputs.Add(a + b);
                        break;
                    case "-":
                        inputs.Add(a - b);
                        break;
                    case "*":
                        inputs.Add(a * b);
                        break;
                    case "/":
                        inputs.Add(a / b);
                        break;
                    default:
                        break;
                }
                
            }
            return inputs;
        }
    }
}



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

char X[1001];
char Y[1001];

int LCS(int, int);

int main(){
  int n, i, commonlength;
  int len1, len2;
  
  scanf("%d",&n);
  
  for(i = 0 ; i < n ; i++){
    scanf("%s",X);
    scanf("%s",Y);
    len1 = strlen(X);
    len2 = strlen(Y);

    commonlength = LCS(len1,len2);
    printf("%d\n",commonlength);
  }

  return 0;
}
    
int LCS(int x, int y){
  int i, j;
  int Z[1001][1001];

  for(i = 0 ; i <= x ; i++) Z[i][0] = 0;
  for(i = 0 ; i <= y ; i++) Z[0][i] = 0;

  for(i = 1 ; i <= x ; i++){
    for(j = 1 ; j <= y ; j++){
      if(X[i-1] == Y[j-1]){
	Z[i][j] = Z[i-1][j-1]+1;
      }
      else if(Z[i-1][j-1] >= Z[i][j-1]){
	Z[i][j] = Z[i-1][j];
      }
      else{
	Z[i][j] = Z[i][j-1];
      }
    }
  }

  if(i == 0 || j == 0) return 0;
  else if(i > 0 && j > 0 && x == y) return Z[i-1][j-1];
  else if(i > 0 && j > 0 && x != y) return Z[x][y];
}



Measured memory_bytes: 5652
#include <iostream>
#include <vector>
#include <algorithm>
#include <limits.h>
using namespace std;

struct UnionFind{
    vector<int> par;
    vector<int> rank;
    UnionFind(int x){
        par=vector<int> (x);
        rank=vector<int> (x,1);
        for (int i=0;i<x;i++){
            par[i]=i;
        }
    }
    int root(int x){
        if(par[x]==x){
            return x;
        }
        else{
            return par[x]=root(par[x]);
        }
    }
    void unite(int x,int y){
        x=root(x);y=root(y);
        if(x==y){
            return;
        }
        if(rank[x]<rank[y]){
            par[x]=y;
        }
        else{
            par[y]=x;
        }
        if(rank[x]==rank[y]){
            rank[x]++;
        }
    }
    bool check(int x,int y){
        return root(x)==root(y);
    }
};

int main(){
    int n,m;
    cin >> n >> m;
    vector<int> da(n);
    for(int i=0;i<n;i++){
        cin >> da[i];
    }
    UnionFind UN(n);
    for(int i=0;i<m;i++){
        int x,y;
        cin >> x >> y;
        UN.unite(x-1,y-1);
    }
    int ans=0;
    for(int i=0;i<n;i++){
        if(UN.check(i,da[i]-1)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 1408
N, M = map(int, input().split(" "))
prohibit = {i: set() for i in range(N)}

for _ in range(M):
    a, b = map(int, input().split(" "))
    prohibit[b - 1].add(a - 1)
    prohibit[a - 1].add(b - 1)

now = set([0])
ans = 0
for i in range(1, N):
    if len(now & prohibit[i]) > 0:
        now = set([i])
        ans += 1
    else:
        now.add(i)
print(ans)

Measured memory_bytes: 83428
def main():
    n = int(input())
    h = list(map(int, input().split()))

    dp = [0] * n
    dp[1] = abs(h[1] - h[0])
    for i in range(2, n):
        dp[i] = min(dp[i-2]+abs(h[i] - h[i-2]), dp[i-1]+abs(h[i] - h[i-1]))

    print(dp[n-1])

main()

Measured memory_bytes: 84776
n = gets.to_i
values = gets.to_s.split(' ').map(&:to_f).sort!

prev_value = (values[0] + values[1]) / 2

if n > 2
  (2...n).each do |idx|
    prev_value = (prev_value + values[idx]) / 2
  end
end

puts prev_value


Measured memory_bytes: 3836
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll INF = 3000000000000000000; //10^18
const int inINF = 1000000000; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;

int main(){
    int N;
    cin >> N;
    vector<int> P(N);
    for (int i = 0; i < N; i++) {
        cin >> P[i];
    }
    int ans = 0;
    int m = inINF;

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

}

Measured memory_bytes: 4000
lst=[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]
print(lst[int(input())-1])

Measured memory_bytes: 2940
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<climits>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iomanip>
using namespace std;

#define rep(i,j,n) for(int i=(j);i<(n);i++)
#define rep2(i,j,n) for(int i=(j);i<=(n);i++)
#define all(i) i.begin(),i.end()
#define INF 1e9

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef pair<int, int> pi;
typedef long long i64;

int main() {
	double n;
	cin >> n;
	int ans = (n / 2)*(n + 1);
	cout << ans << endl;
}

Measured memory_bytes: 256
// </> : towhid1zaman

#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair< int, int > pii;
typedef pair< pii, int > ppi;
#define fill(a,b) memset(a,b,sizeof(a))
#define all(v) (v).begin(),(v).end()
#define sp(k) cout<<setprecision(k)<<fixed;
#define rep(i,a) for(int i=0;i<a;i++)
#define rep1(i,a,b) for(int i=(a);i<=(b);++i)
#define irep(i,b,a) for(int i=(b);i>=(a);--i)
#define minv(v) *min_element(all(v))
#define maxv(v) *max_element(all(v))
#define unq(v) sort(all(v)),(v).erase(unique(all(v)),(v).end())
#define _ ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
#define sqr(a) ((a)*(a))
#define sz(a) int(a.size())
#define ff first
#define ss second
#define pb push_back

const double pi = acos(-1.0);
const int mod = 1000000007; // (int)1e9+7
const int inf = 0x3f3f3f3f;// (int)3e18;
const int maxn = 2000100;



int main(){
        _
        map<int,bool>mp;
        mp[100]=1;
        mp[101]=1;
        mp[102]=1;
        mp[103]=1;
        mp[104]=1;
        mp[105]=1;
        int tot = 615;
        int x; cin >> x;
        for(int i = 106; i<=x; i++){
            mp[i]|=mp[i-100];
            mp[i]|=mp[i-101];
            mp[i]|=mp[i-102];
            mp[i]|=mp[i-103];
            mp[i]|=mp[i-104];
            mp[i]|=mp[i-105];
        }
        cout<<mp[x]<<endl;

return 0;
}




Measured memory_bytes: 4992
#include<algorithm>
#include<iostream>
#include<climits>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<queue>
#include<set>
#include<map>
#define ll long long
using namespace std;
//{{{ read()
inline int read(){
	register int x=0,f=1;
	register char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-')	f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')	x=x*10+(ch^48),ch=getchar();
	return x*f;
}
//}}}
const int N=1005;
char s[N][N];
int n,m,a[N][N];
struct P{
	int x,y,z;
	P (int xx=0,int yy=0,int zz=0){
		x=xx,y=yy,z=zz;
	}
	bool operator < (const P k) const{
		return z>k.z;
	}
};
priority_queue<P> que;
int main(){
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)	scanf("%s",s[i]+1);
	memset(a,27,sizeof(a));
	a[1][1]=(s[1][1]=='#');
	que.push(P(1,1,a[1][1]));
	while(!que.empty()){
		P k=que.top();	que.pop();
		int x=k.x,y=k.y,z=k.z;
		if(z!=a[x][y])	continue;
		if(x<n){
			int k=z+(s[x+1][y]=='#'&&s[x][y]=='.');
			if(k<a[x+1][y])	a[x+1][y]=k,que.push(P(x+1,y,k));
		}
		if(y<m){
			int k=z+(s[x][y+1]=='#'&&s[x][y]=='.');
			if(k<a[x][y+1])	a[x][y+1]=k,que.push(P(x,y+1,k));
		}
	}
	cout<<a[n][m]<<endl;
	return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;
const double PI=acos(-1);
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	ll k; cin >> k;
	ll ans = 1;
	bool ok = false;

	// あまりを10倍してたす
	ll cnt = 1;
	ll now = 7;
	for(;;){
		if(now % k == 0){
			ok = true;
		}else{
			ans++;
			now %= k;
			now *= 10;
			now += 7;
		}
		if(ok) break;
		cnt++;
		if(cnt >= 1000000) break;
	}

	if(ok){
		cout<<ans<<endl;
	}else{
		cout<<-1<<endl;
	}
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>

using namespace std;

template<typename T>
bool linear_search(vector<T> S, T t) {
    for (T s : S) if (s == t) return true;
    return false;
}

int main() {
    uint32_t n, q, count = 0;

    cin >> n;
    vector<uint32_t> S(n);
    for (uint32_t &s : S) cin >> s;

    cin >> q;
    while (q--) {
        uint32_t t;
        cin >> t;
        if (linear_search(S, t)) count++;
    }

    cout << count << endl;

    return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

int main(){
    int N;
    cin >> N;
    vector<int> cnt(N+1,0);
    for(int i=0; i<N; i++){
        int a;
        cin >> a;
        cnt[a]++;
    }

    vector<int> memo(N+1,0);
    for(int i=0; i<=N; i++){
        memo[cnt[i]]++;
    }

    //cout_vec(memo);

    for(int i=N; i>0; i--){
        memo[i-1]+=memo[i];
    }

    //cout_vec(memo);

    for(int i=1; i<N; i++){
        memo[i+1]+=memo[i];
    }

    //cout_vec(memo);

    int k=1;
    for(int i=N; i>=0 && k<=N;){
        if(k*i<=memo[i]){
            cout << i << '\n';
            k++;
        }else{
            i--;
        }
    }
}

Measured memory_bytes: 5636
#include <vector>
#include <stdio.h>
#include <iostream>
#include <algorithm>

using namespace std;
class DSU {
  int n;  
  vector<int> p;
  vector<int> rank;
public:
  DSU(int _n): n(_n), p(n), rank(n, 0) {
    for (int i = 0; i < n; ++i) p[i] = i;
  }
  void unite(int x, int y) {
    int par_x = findRep(x);
    int par_y = findRep(y);
    if (rank[par_x] > rank[par_y]) {
      p[par_y] = par_x;
    } else {
      p[par_x] = par_y;
      if (rank[par_x] == rank[par_y]) rank[par_y]++;
    }
  }

  int findRep(int x) {
    if (x != p[x]) {
      p[x] = findRep(p[x]);
    }
    return p[x];
  }
};

template <typename T>
struct Edge {
  int from, to;
  T cost;
  Edge(int f, int t, T c): from(f), to(t), cost(c){};
  bool operator < (const Edge &e) const {
    return cost < e.cost;
  }
};

template <typename T>
T kruskal(vector< Edge<T> > &G, int n) {
  T total = 0;
  sort(G.begin(), G.end());
  DSU d = DSU(n);
  for (size_t i = 0; i < G.size(); ++i) {
    Edge<T> e = G[i];
    if (d.findRep(e.to) != d.findRep(e.from)) {
      d.unite(e.to, e.from);
      total += e.cost;
    }
  }
  return total;
}

int main () {
  int v, e;
  scanf("%d %d", &v, &e);

  vector< Edge<int> > G;
  for (int i = 0; i < e; ++i) {
    int s, t, w;
    scanf("%d %d %d", &s, &t, &w);
    G.emplace_back(s, t, w);
  }

  int ans = kruskal<int>(G, v);
  printf("%d\n", ans);
  return 0;
}



Measured memory_bytes: 4504
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return a.second < b.second;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> ab;
  for (int i = 0; i < M; ++i) {
    int ai, bi;
    cin >> ai >> bi;
    ab.push_back(make_pair(ai, bi));
  }
  sort(ab.begin(), ab.end(), cmp);

  int ans = 0, end = 0;
  for (int i = 0; i < M; ++i) {
    if (end <= ab[i].first) {
      end = ab[i].second;
      ++ans;
    }
  }

  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define int long long int
using namespace std;
int vis[100000+1]={0};
vector<int>g[100000+1];
int dis[100000+1]={0};
int ind[100000+1]={0};
void dfs(int u)
{
	stack<int>s;
	
	s.push(u);
	
	while(!s.empty())
	{
		
		int a=s.top();
	
		vis[a]=1;
		s.pop();
		for(auto i:g[a])
		{
			dis[i]=max(dis[i],dis[a]+1);
			ind[i]--;
		   if(vis[i]==0&&ind[i]==0)
			s.push(i);
		}
	}

}
	
int32_t main() {
  int n,m,ma=0,a,b;
  
  cin >> n >> m;
 
  while(m--)
  {
	 cin >> a >> b;
	 g[a].push_back(b);
	 ind[b]++;
 }
 for(int i=1;i<=n;i++)
 {
	 if(vis[i]==0&&ind[i]==0)
	 {
		dfs(i);
	 }
 }
 for(int i=1;i<=n;i++)
 {
	 ma=max(ma,dis[i]);
 }
 cout << ma <<"\n";
 
  
}



Measured memory_bytes: 11360
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <deque>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <utility>
#include <algorithm>
#include <numeric>
#include <typeinfo>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <ctime>

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

int main()
{
	for(vi p(8);cin>>p[0];){
		repi(i,1,8)
			cin>>p[i];
		
		int _c[]={1,4,1,4,1,2,1,2};
		vi c(_c,_c+8),res(c);
		int max=0;
		rep(i,8){
			int temp=0;
			rep(j,8)
				temp+=min(p[j],c[j]);
			if(max<temp || max==temp && res>c){
				res=c;
				max=temp;
			}
			rotate(c.begin(),1+allof(c));
		}
		rep(i,8)
			printf("%d%c",res[i],i==7?'\n':' ');
	}

	return 0;
}

Measured memory_bytes: 0
s = input()
n = len(s)
arr = [1] * n

index = 0
bal = 0
while index < n-1:
    # print("index is: ", index)
    if(s[index] == 'R'):
        if s[index + 1] == 'L':
            #distribute
            ni = index + 2
            fbal = 0
            lfc = 0
            while ni < n:
                # print("ni is: ", ni)
                if s[ni] == 'L':
                    fbal += 1
                    arr[ni] = 0
                    ni += 1
                    lfc += 1
                else:
                    break

            # print("lfc is: ", lfc)
            totalbal = bal + 2 + fbal


            if(totalbal % 2 == 0):
                arr[index] = totalbal // 2
                arr[index + 1] = totalbal // 2
            else:
                if(bal % 2 == 0):
                    arr[index] = totalbal // 2 + 1
                    arr[index + 1] = totalbal // 2
                else:
                    arr[index] = totalbal // 2
                    arr[index + 1] = totalbal // 2 + 1
            # print("previous index is: ", index)
            bal = 0
            index = index + 1 + lfc + 1
            # print("new index is: ", index)
        else:
            bal += 1
            arr[index] = 0
            index += 1

ans = ""
for v in arr:
    ans += str(v) + " "
print(ans)





Measured memory_bytes: 4468
#include<bits/stdc++.h>
using namespace std;
int main(){
long long  i,n,d;
  cin >> n >> d;
  long long yotaro=0;
  for(i=0;i<n;i++){
    long long x,y;
    cin >> x >> y;
    if(x*x+y*y<=d*d){
      yotaro++;
    }
  }
  cout << yotaro << endl;
}
    


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;

int main(){
    int tmp;
    int ans = 0;
    vector<int> rems;
    
    for(int i = 0; i < 5; i++){
        cin >> tmp;
        if(tmp%10 == 0) ans += tmp;
        else{
            ans += ((tmp/10)+1)*10;
            rems.push_back(10 - tmp%10);
        }
    }

    if(rems.empty()) cout << ans << '\n';
    else{
        int maxi = *max_element(rems.begin(), rems.end());
        cout << ans - maxi << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int n = input.nextInt();
        double[] p = new double[n+1];
        double[] q = new double[n+1];
        for(int i = 1; i <= n; i++) {
            p[i] = input.nextDouble();
        }
        for(int i = 0; i <= n; i++) {
            q[i] = input.nextDouble();
        }
        System.out.println(getMinCost(n, p, q));
    }
    private static double getMinCost(int n, double[] p, double[] q) {
        double[][] e = new double[n+2][n+1];
        double[][] w = new double[n+2][n+1];
        for(int i = 0; i <=n; i++) {
            e[i+1][i] = q[i];
            w[i+1][i] = q[i];
        }
        for(int l = 1; l <= n; l++) {
            for(int i = 1; i <= n-l+1; i++) {
                int j = i + l - 1;
                e[i][j] = Double.MAX_VALUE;
                w[i][j] = w[i][j-1] + p[j] + q[j];
                for (int k = i; k <= j; k++) {
                    e[i][j] = Math.min(e[i][j], e[i][k-1] + e[k+1][j] + w[i][j]);
                }
            }
        }
        return e[1][n];
    }
}



Measured memory_bytes: 44284
#include <bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;

#define INF (i64)1e18
#define MOD (i64)(1e9+7)
#define REP(i, n) for(i64 i = 0; i < n; i++)
#define RANGE(i, a, b) for(i64 i = a; i < b; i++)

int main() {
  int n;
  cin >> n;
  vector<i64> a(n);
  for(auto& e : a) cin >> e;
  sort(a.begin(), a.end(), greater<i64>());

  list<i64> c = {0};
  i64 ans = 0;
  bool flag = false;
  for (auto& e : a) {
    ans += c.front();
    c.pop_front();
    c.push_back(e);
    if (flag) c.push_back(e);
    flag = true;
  }
  std::cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11040
use proconio::input;
use proconio::marker::Bytes;

fn main() {
    input! { s: Bytes };
    let m = 2019;
    // ある桁の数値は 10^i * s[i] と表現できる。
    // 10^i 部分も mod 2019 を取ることで扱える桁数になる。
    // rs[i] 右から i 桁目までの mod ((s[0] + s[1] + ... s[i]) % 2019)
    let rs = std::iter::once(0_usize).chain(s.iter().rev().map(|b| (b - b'0') as usize).scan(
        (1_usize, 0_usize),
        |acc, d| {
            let (b, r) = *acc;
            acc.0 = (b * 10) % m;
            acc.1 = ((d * b) % m + r) % m;
            Some(acc.1)
        },
    ));
    // [i, j] において mod 2019 が 0 になるためには
    // rs[j] - rs[i - 1] = 0 にすれば良い
    // rs[i] = rs[j - 1] になる個数を求めれば良い
    //
    // cs[r] 余り r ごとの rs における出現回数
    let mut cs = vec![0_usize; m];
    for r in rs {
        cs[r] += 1;
    }
    let ans = cs
        .iter()
        .map(|&c| c * c.saturating_sub(1) / 2)
        .sum::<usize>();
    println!("{}", ans);
}


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

bool dfs(int x,int y,int cou);
int sx,sy;
int n;
int a,b;
int dx[]={-1,0,1,-2,-2,-2,-1,0,1,2,2,2};
int dy[]={-2,-2,-2,-1,0,1,2,2,2,1,0,-1};
int dsx[]={0,0,-1,-1,-1,0,1,1,1};
int dsy[]={0,-1,-1,0,1,1,1,0,-1};
pair<int,int> data[10];
int main(){
  while(1){
    cin >> sx >> sy;
    if(sx==0 && sy==0) break;
    cin >> n;
    for(int i=0;i<n;i++){
      cin >> a >> b;
      data[i].second=a;
      data[i].first=b;
    }
    if(dfs(sx,sy,0)==true) cout << "OK" << endl;
    else cout << "NA" << endl;
  }
}

bool dfs(int x,int y,int cou){
  if(cou==n) return true;
  for(int i=0;i<12;i++){
    int nx=x+dx[i];
    int ny=y+dy[i];
    if(nx>=0 && nx<=9 && ny>=0 && ny<=9){
      for(int j=0;j<9;j++){
	int nsx=data[cou].second+dsx[j];
	int nsy=data[cou].first+dsy[j];
	if(nx==nsx && ny==nsy){
	  if(dfs(nx,ny,cou+1)==true) return true;
	}
      }
    }
  }
  return false;
}

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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair

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

const int MAXN = 300005;
int a[MAXN];

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

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n;
    ll ans;
    cin>>n;
    for (int i=0;i<3*n;i++) cin>>a[i];
    sort(a,a+3*n);
    ans = 0;
    for (int i=n;i<3*n;i+=2)
    {
        ans+=a[i];
    }
    cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=100005,M=200005,Mod=1e9+7;
int n,m,S,T,edgenum,X[M],Y[M],Z[M],head[N],Next[M*2],vet[M*2],val[M*2];
ll ans,d1[N],d2[N],g1[N],g2[N];
bool vis[N];
priority_queue<pair<ll,int>,vector<pair<ll,int> >,greater<pair<ll,int> > >que;
void add(int u,int v,int w){
	edgenum++;
	Next[edgenum]=head[u];
	vet[edgenum]=v;
	val[edgenum]=w;
	head[u]=edgenum;
}
void dij(ll*d,ll*g,int s){
	d[s]=0,g[s]=1;
	que.push(make_pair(0,s));
	while(!que.empty()){
		int u=que.top().second;
		ll w=que.top().first;
		que.pop();
		if(vis[u]||d[u]<w)continue;
		vis[u]=1;
		for(int i=head[u];i;i=Next[i]){
			int v=vet[i];
			if(d[v]==w+val[i])g[v]=(g[v]+g[u])%Mod;
			if(d[v]>w+val[i]){
				g[v]=g[u];
				d[v]=w+val[i];
				que.push(make_pair(d[v],v));
			}
		}
	}
}

int main(){
	scanf("%d%d%d%d",&n,&m,&S,&T);
	for(int i=1;i<=m;i++){
		int x,y,z;
		scanf("%d%d%d",&x,&y,&z);
		add(x,y,z);
		add(y,x,z);
		X[i]=x,Y[i]=y,Z[i]=z;
	} 
	memset(d1,0x3f,sizeof d1);
	memset(d2,0x3f,sizeof d2);
	dij(d1,g1,S);
	memset(vis,0,sizeof(vis));
	dij(d2,g2,T);
	ll dis=d1[T];
	ans=g1[T]*g1[T]%Mod;
	for(int i=1;i<=n;i++)
		if(d1[i]+d2[i]==dis&&d1[i]==d2[i])
			ans=(ans-g1[i]*g1[i]%Mod*g2[i]%Mod*g2[i]%Mod)%Mod;
	for(int i=1;i<=m;i++){
		int u=X[i],v=Y[i],d=Z[i];
		if(d1[u]+d+d2[v]==dis&&d1[u]+d>d2[v]&&d2[v]+d>d1[u])
			ans=(ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
		u=Y[i],v=X[i],d=Z[i];
		if(d1[u]+d+d2[v]==dis&&d1[u]+d>d2[v]&&d2[v]+d>d1[u])
			ans=(ans-g1[u]*g2[v]%Mod*g1[u]%Mod*g2[v]%Mod)%Mod;
	}
	printf("%lld",(ans%Mod+Mod)%Mod);
	return 0;
}

Measured memory_bytes: 15384
// C - Switches
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;

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

	vi S(M);
	for(int m=0; m<M; ++m){
		int K; cin>>K;
		for(int k=0; k<K; ++k){ int s; cin>>s; S[m] |= 1<<(s-1); }
	}

	vi P(M); for(int p=0; p<M; ++p) cin>>P[p];

	int all = 1<<N, unmatch_count = 0;
	for(int s=0; s<all; ++s){//s: sw all pattern
		int b,m;
		for(m=0; m<M; ++m){//S[m]: sw data matching
			int sw = s & S[m];
			b = 0; while(sw){ if(sw&1) ++b; sw/=2; }//count bit '1'
			if(b%2 != P[m]) break;
		}
		if(m<M && b%2 != P[m]) ++unmatch_count;
	}
	cout<< all - unmatch_count <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <cstdio>

using namespace std;

typedef long long ll;

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

int main(int argc, char **argv)
{
    string S;
    cin >> S;
    if (S[2] == S[3] && S[4] == S[5]) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256