akhauriyash/Code-Regression huggingface dataset:
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>
#include <complex>
#include <iostream>
#include <iterator>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

char field[128][128];
int memo[128][128];
int w, h;

void fillup(int y, int x, int num, char c)
{
	memo[y][x] = num;
	
	const int dy[] = {-1, 0, 0, 1};
	const int dx[] = {0, 1, -1, 0};
	
	rep(i, 4){
		int py = y + dy[i];
		int px = x + dx[i];
		if(py<0 || h<=py || px<0 || w<=px || (memo[py][px] != -2 && memo[py][px] != -1))
			continue;
		
		if(field[py][px] != c)
			memo[py][px] = -2;
		else
			fillup(py, px, num, c);
	}
}

int main()
{
	while(scanf("%d%d", &w, &h), w){
		int y, x;
		rep(i, h){
			scanf("%s", field[i+1]+1);
			rep(j, w){
				if(field[i+1][j+1] == '&'){
					y = i + 1;
					x = j + 1;
					field[y][x] = '.';
				}
			}
		}
		
		h += 2;
		w += 2;
		fill_n(field[0], w, '.');
		fill_n(field[h-1], w, '.');
		rep(i, h)
			field[i][0] = field[i][w-1] = '.';
		
		rep(i, h)
			fill_n(memo[i], w, -1);
		
		memo[y][x] = -2;
		for(int i=0;; ++i){
			const char chars[] = {'#', '.'};
			bool found = false;
			rep(l, 2){
				rep(j, h) rep(k, w){
					if(field[j][k] == chars[l] && memo[j][k] == -2){
						found = true;
						fillup(j, k, i, chars[l]);
					}
				}
			}
			if(!found)
				break;
		}
		printf("%d\n", memo[0][0]);
	}

	return 0;
}

Measured memory_bytes: 0
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#define WOULD
#define YOU
#define PLEASE
#define ACCEPT
#define MY
#define SUBMISSION
/* I REALLY HOPE MY WISH REACH YOU , ATCODER'S ONLINE JUDGE */
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const long long INF = 100100100100;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a * b / gcd(a, b);
}

int main() {
    int N;cin >> N;
    vector<int> retu(N);
    for(int i = 0;i<N;i++) cin >> retu.at(i);
    //-1が同じまたは切断直後、0が減少、1が増加
    int status = -1;
    int count = 0;
    for(int i = 0;i<N-1;i++){
        if(status == -1){
            if(retu.at(i) < retu.at(i+1)){
                status = 1;
            }
            if(retu.at(i) > retu.at(i+1)){
                status = 0;
            }
        }
        else{
            if(retu.at(i) < retu.at(i+1) && status == 0){
                count++;
                status = -1;
            }
            if(retu.at(i) > retu.at(i+1) && status == 1){
                count++;
                status = -1;
            }
        }
    }
    cout << count+1 << endl;

}

Measured memory_bytes: 640
#include<stdio.h>

int main(void){

int r=100000;
int n,a;

scanf("%d",&n);


for(int i = 0; i<n; i++){
 r = r*1.05;

if(r%1000 > 0){
a=r%1000;
r=r+1000-a;
}
}
printf("%d\n",r);

return 0;
}


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

using namespace std;

const int num_elem = 100001;

int main()
{
    int N, v;
    cin >> N;
    vector<int> array1(num_elem, 0), array2(num_elem, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> v;
        if (i % 2 == 0)
        {
            ++array1[--v];
        }
        else
        {
            ++array2[--v];
        }
    }

    int max1 = 0, max1_i, max2 = 0, max2_i;
    for (int i = 0; i < num_elem; i++)
    {
        if (max1 < array1[i])
        {
            max1 = array1[i];
            max1_i = i;
        }
        if (max2 < array2[i])
        {
            max2 = array2[i];
            max2_i = i;
        }
    }

    if (max1_i == max2_i)
    {
        if (max1 > max2)
        {
            max2 = 0;
            array2[max2_i] = -1;
            for (int i = 0; i < num_elem; i++)
            {
                if (max2 < array2[i])
                {
                    max2 = array2[i];
                }
            }
        }
        else if(max1 < max2)
        {
            max1 = 0;
            array1[max1_i] = -1;
            for (int i = 0; i < num_elem; i++)
            {
                if (max1 < array1[i])
                {
                    max1 = array1[i];
                }
            }
        }
        else{
            int max1_2 = 0, max2_2 = 0;
            array1[max1_i] = array2[max2_i] = 0;
            for(int i=0;i<num_elem;i++){
                max1_2 = max1_2 < array1[i] ? array1[i] : max1_2;
                max2_2 = max2_2 < array2[i] ? array2[i] : max2_2;
            }
            if(max1_2 > max2_2) max1 = max1_2;
            else max2 = max2_2;
        }
    }
    cout << N - max2 - max1 << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long ll;
int main(){
	int n;
	while(cin>>n&&n){
		vector<pair<int,int> >dat;
		while(n--){
			int mem;
			cin>>mem;
			vector<int> scr;
			int a,b,c;
			for(int i=0;i<10;i++){
				cin>>a;
				scr.PB(a);
				if(a!=10||i==9){
					cin>>b;
					scr.PB(b);
				}else continue;
				if(i==9&&(a+b>=10)){
					cin>>c;
					scr.PB(c);
				}else continue;
			}
			int ans=0,k=0;
			for(int i=0;i<9;i++){
				if(scr[k]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k++;
					continue;
				}
				if(scr[k]+scr[k+1]==10){
					ans+=scr[k]+scr[k+1]+scr[k+2];
					k+=2;
					continue;
				}
				ans+=scr[k]+scr[k+1];
				k+=2;
			}
			while(k<scr.size())ans+=scr[k++];
			dat.PB(MP((-1)*ans,mem));
		}
		sort(dat.begin(),dat.end());
		for(int i=0;i<dat.size();i++){
			cout<<dat[i].second<<" "<<dat[i].first*(-1)<<endl;
		}
	}
}

Measured memory_bytes: 1220
<?php
$N=trim(fgets(STDIN));

function saiki($str){
        if(is_numeric($str)){
                return ($str+1)/2;
        }
        $array=array();
        $d=0;
        $memo;
        for ($i=0; $i < strlen($str); $i++) {
                if($str[$i]=='['){
                        if($d==0){
                                $memo=$i;
                        }
                        $d++;
                }else if($str[$i]==']'){
                        $d--;
                        if($d==0){
                                array_push($array,saiki(substr($str,$memo+1,$i-$memo-1)));
                        }
                }
        }
        sort($array);
        $size=(sizeof($array)+1)/2;
        $sum=0;
        for ($i=0; $i < $size; $i++) {
                $sum+=$array[$i];
        }
        return $sum;
}

for ($i=0; $i < $N; $i++) {
        echo saiki(trim(fgets(STDIN))).PHP_EOL;
}

Measured memory_bytes: 7160
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <string>
#include <math.h>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <stdlib.h>
#include <time.h>
#include <limits.h>
#include <assert.h>
using namespace std;
int n;
char s[100001];
stack<char> st;
int main() {
	scanf("%s", s);
	n = strlen(s);
	int ans = 0;
	for (int i = 0; i < n; i++) {
		if (!st.empty() && st.top() != s[i]) {
			st.pop();
			ans += 2;
		} else {
			st.push(s[i]);
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
int main() {
	ll h,w,a,b;
	cin >> h >> w >> a >> b;
	vector<vector<ll>>s(h,vector<ll>(w));
	for(ll i=0;i<b;i++) for(ll j=0;j<a;j++) s.at(i).at(j)=0; 
	for(ll i=b;i<h;i++) for(ll j=0;j<a;j++) s.at(i).at(j)=1; 
	for(ll i=0;i<b;i++) for(ll j=a;j<w;j++) s.at(i).at(j)=1; 
	for(ll i=b;i<h;i++) for(ll j=a;j<w;j++) s.at(i).at(j)=0; 
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++) cout << s.at(i).at(j);
		cout << endl;
	}
}


Measured memory_bytes: 9088
import heapq

N, M=map(int, input().split())
A=list(map(int, input().split()))
heapq.heapify(A)
BC=[list(map(int, input().split())) for _ in range(M)]
BC.sort(key=lambda x:(x[1], x[0]), reverse=True)

for b, c in BC:
    if len(A) and A[0]>=c:
        break
    for i in range(b):
        if len(A) and A[0]>=c:
            break
        heapq.heappop(A)
        heapq.heappush(A, c)

print(sum(A))

Measured memory_bytes: 39372
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        final Scanner sc = new Scanner(System.in);

        final double N = sc.nextDouble();
        final double K = sc.nextDouble();

        double ans = 0;
        for (int i = 1; i <= N; i++) {
            double tmp = 1.0 / N;
            int now = i;
            while (now < K) {
                now *= 2;
                tmp /= 2;
            }
            ans += tmp;
        }

        System.out.println(ans);
    }
}


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

#define ii pair<int, int>
#define lli long long int
#define ll pair<lli, lli>
#define pb push_back
#define mp make_pair
#define fi first
#define se second

using namespace std;

int main() {
	int n;
	char s[105], t[105];
	scanf("%d %s %s", &n, s, t);
	for (int i = 0; i < n; i++)
		printf("%c%c", s[i], t[i]);
	puts("");
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,a,b) for(int i =(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
#define REPm(i,n) for(int i=(n)-1;i>=0;i--)
#define REP1(i,n) for(int i=1;i<=(n);i++)
typedef long long ll;
#define inf 1e9
int main(){
    int N,M;
    int a[51],b[51],c[51],d[51];
    cin >> N >> M;
    REP1(i,N) cin >> a[i] >> b[i];
    REP1(i,M) cin >> c[i] >> d[i];
    REP1(i,N){
        int mind = inf;
        int mini = 0;
        REP1(j,M){
            int dis = abs(a[i]-c[j])+abs(b[i]-d[j]);
            if(dis < mind){
                mind = dis;
                mini = j;
            }
        }
        cout << mini << endl;
    }
    return 0;
}


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

TD=[]
for i in range(Q):
    t, d = input().split()
    if d=='L':
        TD.append([t,-1])
    else:
        TD.append([t,1])

def check(place):
    for td in TD:
        if td[0]==S[place]:
            place+=td[1]
            if place<0:
                return -1
            elif place>=N:
                return 1
    return 0

l,r=-1,N
L,R=-1,N

while abs(r-l)>1:
    m=(l+r)//2
    if check(m)<0:
        l=m
    else:
        r=m
L=l
l,r=-1,N

while abs(r-l)>1:
    m=(l+r)//2
    if check(m)>0:
        r=m
    else:
        l=m

R=r

print(max(R-L-1,0))


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

using namespace std; 

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
typedef long long LL;

#define SORT_ASC(c) sort((c).begin(), (c).end())
#define SORT_DESC(c) sort((c).begin(), (c).end(), greater<typeof((c).begin())>())

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

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INT_LARGE = 1000000100;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

void Main()
{
	int l,r;
	cin >> l >> r;

	if(r-l >= 2019){
		cout << 0 << endl;
		return;
	}

	l %= 2019;
	r %= 2019;
	
	if(r<=l){
		cout << 0 << endl;
		return;
	}

	int m = INT_LARGE;
	FOR(i,l,r+1){
		FOR(j,i+1,r+1){
			m = min(m,(i*j)%2019);
		}
	}
	cout << m <<endl;
	


	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
    return 0;
}

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

using namespace std;
#define ll long long
#define sz(a) (int)(a).size()
#define rep(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define frep(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)

typedef vector<int> vi;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<ii> vii;

const int inf = 5000000 + 7;
const ll linf  = 1ll * inf * inf;
const int N = 100000 + 7;
const int M = 10000 + 7;
const int multipleTest = 0;
const double pi = acos(-1);

int n;
int a[N];
int b[N];
vector<int> uniq;

class FenWickTree{
public:
	static const int MAXN = 200000 + 7;
	static const int MID = MAXN / 2;
	int L[MAXN];
	
	void update(int x, int val) {
		x += MID;
		for (int t = x; t < MAXN; t += t & -t) L[t] += val;
	}
	
	int get(int x) {
		x += MID;
		int res = 0;
		for (int t = x; t > 0; t -= t & -t) {
			res += L[t];
		}
		return res;
	}
} fenwickTree;


ll check(int x) {
	for (int i = 0; i < n; ++i) b[i] = (a[i] >= x) ? 1 : -1;
	for (int i = 1; i < n; ++i) b[i] += b[i - 1];
	
	fenwickTree.update(0, 1);
	ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		cnt += fenwickTree.get(-b[i] - 1);
		fenwickTree.update(-b[i], 1);
	}
	
	fenwickTree.update(0, -1);
	for (int i = 0; i < n; ++i) fenwickTree.update(-b[i], -1);
	
	return cnt;
}

void solve() {
	cin >> n;
	uniq.resize(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", a + i);
		uniq[i] = a[i];
	}
	sort(uniq.begin(), uniq.end());
	auto it = unique(uniq.begin(), uniq.end());
	
	int lo = 0, hi = it - uniq.begin() - 1, res = uniq[0];
	const ll M = 1ll * n * (n + 1) / 2;
	const ll cnt = M / 2 + 1;
	
	while (lo <= hi) {
		int mid = (lo + hi) >> 1;
		if (check(uniq[mid]) < cnt) {
			res = uniq[mid];
			lo = mid + 1;
		} else hi = mid - 1;
	}
	
	cout << res << '\n';
}

int main() {
#ifdef _LOCAL_
	freopen("in.txt", "r", stdin);
	//	freopen("out.txt", "w", stdout);
#endif
	int Test = 1;
	if (multipleTest) {
		cin >> Test;
	}
	
	for(int i = 0; i < Test; ++i) {
		//		printf("Case #%d: ", i + 1);
		solve();
	}
#ifdef _LOCAL_
	cerr << "\n" << 1.0 * clock() / CLOCKS_PER_SEC << "\n";
#endif
}


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

int main() {
    ll a,b,c;
    cin >> a >> b >> c;
    if(a+b-c>0){
      cout << "No" << endl;
    }
  else if(4*a*b<(a+b-c)*(a+b-c))cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll gcd(ll m,ll n);
ll lcm(ll m,ll n);
int gcd(const vector<int> &v);
int lcm(const vector<int> &v);
int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll ans=1;
	for(int i=0;i<n;i++){
		ll a;
		cin >> a;
		ans=lcm(ans,a);
	}
	cout << ans << endl;
	return 0;
}
ll gcd(ll a,ll b){
	return (b==0?a:gcd(b,a%b));
}
ll lcm(ll a,ll b){
	return a/gcd(a,b)*b;
}


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define FORR2(x,y,arr) for(auto& [x,y]:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>x;
	cout<<(1-x)<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3644
#include <iostream>
using namespace std;
int main(void){
	int n,asum,bsum,a,b;
	while(1){
		asum=0;bsum=0;
		cin>>n;
		if(!n) return 0;
		while(n--){
		cin>>a;
		cin>>b;
			if(a >= b) asum+=a;
			else bsum+=a;
			if(a <= b) bsum+=b;
			else asum+=b;
		}
		cout<<asum<<" "<<bsum<<endl;
		}
}

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

#define F first
#define S second

using namespace std;

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

const int N = 110, M = 110;

LL a, b, n;

int main()
{
	cin >> a >> b >> n;
	
	LL x = min(b - 1LL, n);
	LL res = (a * x) / b - a * (x / b);
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 3600
def submit():
    n = int(input())
    alist = list(map(int, input().split()))
    blist = list(map(int, input().split()))


    # 順番にグリーディ
    a = alist.copy()
    b = blist.copy()
    score_a = 0
    for i in range(0, n):
        if a[i] < b[i]:
            score_a += a[i]
            b[i] -= a[i]
            a[i] = 0
        else:
            score_a += b[i]
            a[i] -= b[i]
            b[i] = 0

        if a[i + 1] < b[i]:
            score_a += a[i + 1]
            b[i] -= a[i + 1]
            a[i + 1] = 0
        else:
            score_a += b[i]
            a[i + 1] -= b[i]
            b[i] = 0


    print(score_a)


if __name__ == '__main__':
    submit()


Measured memory_bytes: 18396
L = input()
MOD = 10**9+7

pow_3=[1]
for _ in range(2*10**5):
  pow_3.append((pow_3[-1]*3)%MOD)
  
pow_2=[1]
for _ in range(2*10**5):
  pow_2.append((pow_2[-1]*2)%MOD)
  
count = L.count('1')
ans = pow_2[count]

for i in range(len(L)-1,-1,-1):
  if L[i]=='1':
    count -= 1
    m = pow_3[len(L)-i-1]*pow_2[count]
    ans += m
    ans %= MOD
print(ans)

Measured memory_bytes: 19060
#include<stdio.h>
int main(void)
{
	int n,m,vector[100],matrix[100][100],i,j,k,matrix_vector[100]={0},c;

	{
		scanf("%d %d",&n,&m);
		
		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{
				scanf("%d",&matrix[i][j]);
				
			}
		}

		for(k=0;k<m;k++)
		{
			scanf("%d",&vector[k]);
			
		}

		for(i=0;i<n;i++)
		{
			for(j=0;j<m;j++)
			{	
				c=matrix[i][j] * vector[j];
				matrix_vector[i]+=c;
				
			}
			printf("%d\n",matrix_vector[i]);
		}
	}

	return 0;
}


Measured memory_bytes: 2104
function main(input){
  input = input.split('\n');
  const [n, m, k] = input[0].split(' ').map(Number);
  const a = input[1].split(' ').map(Number).reduce((a, x)=>{
    if(a.length === 0){
      return [x];
    } else{
      a.push(x+a[a.length-1])
      return a;
    }
  },[]);
  const b = input[2].split(' ').map(Number).reduce((a, x)=>{
    if(a.length === 0){
      return [x];
    } else{
      a.push(x+a[a.length-1]);
      return a;
    }
  },[]);

  const aMax = searchIndex(a, k);

  let max = 0;
  for(let i=0; i<=aMax; i++){
    const ak = i===0? 0 : a[i-1];
    const bMax = searchIndex(b, k-ak);
    if(bMax + i > max){
      max = bMax + i;
    }
  }

  console.log(max);
}

function searchIndex(arr, k){
  let st = 0;
  let ed = arr.length;
  while(st != ed){
    i = ((st + ed)/2) >> 0;
    if(k < arr[i]) {
       ed = i;
    }else{
      st = i+1;
    }
  }

  return st;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').trim());

Measured memory_bytes: 66848
def check_alive(n):
    p = n
    for spell in spells:
        if spell[0] == s[p]:
            p += 1 if spell[1] == 'R' else -1
        if p == -1:
            return 'L'
        elif p == N:
            return 'R'
    return 'OK'

N, Q = list(map(int, input().split()))
s = [x for x in input()]
spells = [input().split() for i in range(Q)]

def __main__():
    if check_alive(0) == 'R':
        print(0)
        return
    elif check_alive(0) == 'OK':
        left_alive = 0
    else:
        a, b = 0, N-1
        while b - a > 1:
            m = round((b+a)/2)
            if check_alive(m) == 'L':
                a = m
            else:
                b = m
        left_alive = b
    if check_alive(N-1) == 'L':
        print(0)
        return
    elif check_alive(N-1) == 'OK':
        right_alive = N-1
    else:
        a, b = 0, N-1
        while b - a > 1:
            m = round((b+a)/2)
            if check_alive(m) == 'R':
                b = m
            else:
                a = m
        right_alive = a
    
    print(right_alive - left_alive + 1)

if __name__ == "__main__":
    __main__()


Measured memory_bytes: 42656
package main

import (
	"fmt"
	"math"
)

func main() {
	var N, L, n, sum int
	fmt.Scan(&N, &L)
	min := math.MaxInt64
	for i := 1; i <= N; i++ {
		w := Abs(L + i - 1)
		if w < min {
			min = w
			n = i
		}
	}
	for i := 1; i <= N; i++ {
		if i == n {
			continue
		}
		sum += L + i - 1
	}
	fmt.Println(sum)
}

func Abs(a int) int {
	return int(math.Abs(float64(a)))
}


Measured memory_bytes: 512
function main(input) {
    var a = input[0];
    var b = input[1];
    var ans = false;
    if(a.length != b.length) ans = false;
    else{
        start: for(var i=0;i<a.length;i++){
            for(var j=0;j<b.length;j++){
                if(a[(i+j)%a.length] != b[j])continue start;
            }
            ans = true;
            break;
        }
    }
    
    console.log(ans?"Yes":"No");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8').trim().split("\n"))


Measured memory_bytes: 7372
def kyoto():
    for ball in ball_lis:
        if B[-1] <= C[-1] < ball:
            C.append(ball)
        elif C[-1] < B[-1] < ball:
            B.append(ball)
        elif B[-1] < ball < C[-1]:
            B.append(ball)
        elif C[-1] < ball < B[-1]:
            C.append(ball)
        else:
            print 'NO'
            break
    else:
        print 'YES'
            
for i in range(int(raw_input())):
    ball_lis = [int(char) for char in raw_input().split()]
    B = [0]
    C = [0]
    kyoto()

Measured memory_bytes: 4228
#include <bits/stdc++.h>
using ll = long long;
#define FOR(i, k, n) for(ll i = (k); i < (n); i++)
#define FORe(i, k, n) for(ll i = (k); i <= (n); i++)
#define FORr(i, k, n) for(ll i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(ll i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;

const int INF = 1001001001;

int main(void){
  ll n, m;
  cin >> n >> m;
  if(n == 1 && m == 1){
    cout << 1 << endl;
    return 0;
  }

  //外周以外のマスは9回参照される->裏
  ll ans = max(0ll, n-2) * max(0ll, m-2);
  //角:4 or 2 ->表;
  //辺:6 or 3
  if(n == 1 || m == 1){
    ans += max(n-2, m-2);
  }
  cout << ans << endl;
  return 0;
}

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

using namespace std;

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

typedef long long ll;

void Main()
{
    int r; cin >> r;
    cout << 3 * r * r << endl;
}

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


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
  ll n = 0;
  cin >> n;
  vector<ll> a(n);
  for(int i = 0;i < n;i++)cin >> a[i];
  ll res = 0;
  for(int i = 0;i < n;i++){
    if(a[i] == i + 1 && i != n - 1){
      res++;
      swap(a[i],a[i + 1]);
    }
  }
  if(a[n - 1] == n)res++;
  cout << res << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>
#include<unordered_map>

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

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

typedef long long ll;
using namespace std;






class UnionFind
{
public:
  UnionFind(int num)
  {
      parent=vector<int>(num,-1);
  }
  int root(int a)
  {
    if(parent[a]<0)return a;
    return parent[a]=root(parent[a]);
  }
  int size(int a)
  {
    return -parent[root(a)];
  }
  bool connect(int a,int b)
  {
    int pa=root(a),pb=root(b);
    if(pa==pb)return false;
    if(size(pa)>size(pb))swap(pa,pb);
    parent[pb]+=parent[pa];
    parent[pa]=pb;
    return true;

  }
  void print()
  {
    rep(i,10)cout<<parent[i]<<" ";
    cout<<endl;
  }
private:
  vector<int>parent;

};
UnionFind uni1(200001),uni2(200001),uni(200001);
vector<int> f(200001,0);
int n;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k,l;
  cin>>n>>k>>l;
  rep(i,k){int a,b;cin>>a>>b;uni1.connect(a,b);}
  rep(i,l){int a,b;cin>>a>>b;uni2.connect(a,b);}
  map<pair<int,int>,int>ma;
  repi(i,1,n+1)ma[{uni1.root(i),uni2.root(i)}]++;
  repi(i,1,n+1)cout<<ma[{uni1.root(i),uni2.root(i)}]<<"\n";
  cout<<flush;

  return 0;

}


Measured memory_bytes: 15232
N = int(input())
flag = 0
for i in range(1, 3501):
    for j in range(1, 3501):
        if 4*i*j - i*N - j*N > 0:
            if (N*i*j) % (4*i*j - i*N - j*N) == 0:
                print(i, j, (N*i*j) // (4*i*j - i*N - j*N))
                flag = 1
                break
    if flag == 1:
        break


Measured memory_bytes: 40556
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 2147483647;
const ll LINF = 9223372036854775807;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int n, m, q;
VI a(50),b(50),c(50),d(50);
ll ans=0;
void dfs(VI p,int k){
	if(p.size()==n){
		ll sum=0;
		REP(i,q){
			if(p[b[i]-1]-p[a[i]-1]==c[i])
				sum+=d[i];
		}
		ans=max(ans,sum);
		return;
	}
	int l=p.size();
	p.push_back(k);
	while(p[l]<=m){
		dfs(p,p[l]);
		p[l]++;
	}
}

int main() {
	cin >> n >> m >> q;
	REP(i,q)
		cin >> a[i] >> b[i] >> c[i] >> d[i];
	VI s(0);
	dfs(s,1);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3636
#pragma region
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define repc(i, m, n) for (int i = m; i < n; i++)
#define reprc(i, m, n) for (int i = m; i > n; i--)
#define all(v) v.begin(), v.end()
#define INF 1e9
#define EPS 1e-10
using namespace std;
typedef long long ll;
#pragma endregion

int main()
{
    double L;
    cin >> L;

    cout << fixed << setprecision(12);
    cout << L * L * L / 27 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int linearSearch(int*, int, int);

int main(){
  int N[10000]; int Q[500];
  int nnum, qnum;
  int i, j, search, count = 0;

  scanf("%d", &nnum);
  for(i = 0; i < nnum; i++){
  scanf("%d", &N[i]);
  }
  scanf("%d", &qnum);
  for(i = 0; i < qnum; i++){
  scanf("%d", &Q[i]);
  }
  
  for(i = 0; i < qnum; i++){
    if(linearSearch(N, nnum, Q[i]) == 1){
      count++;
    }
  }
  
  /*
  for(i = 0;i < qnum; i++){
    search = Q[i];
    left = 0;
    right = nnum-1;
    
    while(left < right){
      mid = (left + right)/2;
      if(search == N[mid]){
	printf("%d found\n", search);
	count++;
	break;
      }
      if(search > N[mid]){
	left = mid+1;
      }
      else if(search < N[mid]){
	right = mid;
      }
    }
  }
  */

printf("%d\n", count);
  return 0;
}

int linearSearch(int *A,int length, int key){
  int i = 0;
  
  A[length] = key;
  while( A[i] != key){
    i++;
  }
  if(i == length){
    return 0;
  }
  return 1;
}



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

int main() {
	int n, k, a[100];
	bool state[100001];
	cin >> n >> k;
	int mn = 1e9;
	for (int i=0; i<n; i++) {
		cin >> a[i];
		mn = min(mn, a[i]);	
	}
	for (int i=0; i<mn; i++)
		state[i] = 0;
	for (int i=mn; i<=k; i++) {
		state[i] = 1;
		for (int j=0; j<n; j++) {
			if (i>=a[j]) 
				state[i] = state[i] && state[i-a[j]];		
		}
		state[i] = !state[i];	
	}
	if (state[k]) 
		cout << "First" << "\n";
	else cout << "Second" << "\n";
}

Measured memory_bytes: 384
h,w=map(int,input().split())
state=[]
for i in range(h):
    state.append(input())
count=0
for i in range(h):
    for j in range(w):
        if state[i][j]=='.':
            count+=1
def bfs():
    dist=[[-1]*w for i in range(h)]
    dist[0][0]=0
    stack=[]
    stack.append([0,0])

    while(stack):
        #print(dist)
        node=stack.pop(0)
        for i,j in zip([1,-1,0,0],[0,0,1,-1]):
            if 0<=node[0]+i<h and 0<= node[1]+j<w:
                if dist[node[0]+i][node[1]+j]==-1 and state[node[0]+i][node[1]+j]=='.':
                    dist[node[0]+i][node[1]+j]=dist[node[0]][node[1]]+1
                    if [node[0]+i,node[1]+j]==[h-1,w-1]:
                        break
                    stack.append([node[0]+i,node[1]+j])
    if dist[h-1][w-1]==-1:
        print(-1)
    else:
        print(count-1-dist[h-1][w-1])

bfs()

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

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

template<class T> using v = std::vector<T>;
template<class T> using vv = v<v<T>>;

const int mod = 1000000007;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
//const int mod = 998244353;

struct mint {
    ll x; // typedef long long ll;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint operator-() const { return mint(-x);}
    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 { return mint(*this) += a;}
    mint operator-(const mint a) const { return mint(*this) -= a;}
    mint operator*(const mint a) const { return mint(*this) *= 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 { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}


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

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

// combination mod prime
// https://www.youtube.com/watch?v=8uowVvQ_-Mo&feature=youtu.be&t=1619
struct combination {
    vector<mint> fact, ifact;
    combination(int n):fact(n+1),ifact(n+1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
    }
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n]*ifact[k]*ifact[n-k];
    }
};

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

    int n, m, v; cin >> n >> m;
    priority_queue<double> q;

    rep(i,n) {
        cin >> v;
        q.push(v);
    }

    rep(i,m) {
        v = q.top(); q.pop();
        v /= 2;
        q.push(v);
    }

    ll ans = 0;
    rep(i,n) {
        ans += floor(q.top()); q.pop();
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

int ask(int t)
{
	char str[11];
	
	printf("%d\n", t);
	fflush(stdout);
	
	scanf("%s", str);
	if(*str == 'V') exit(0);
	else if(*str == 'M') return 0;
	else return 1;
}

void f(int s, int t1, int e, int t2)
{
	int mid = s + e >> 1;
	int t3 = ask(mid);
	
	if((t1 ^ t3 ^ s ^ mid) & 1) f(s, t1, mid, t3);
	else f(mid, t3, e, t2); 
}

int main()
{
	int n, t1, t2;
	
	scanf("%d", &n);
	
	t1 = ask(0);
	t2 = ask(n/2);
	
	if((t1 ^ t2 ^ 0 ^ (n/2)) & 1) f(0, t1, n/2, t2);
	else f(n/2, t2, n, t1);
	
	return 0;
}

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

const int mod = 1000000007;


int main() {
  int n;
  cin >> n;
  vector<string> co;
  map<string, int> mp;
  rep(i, n) {
    string s;
    cin >> s;
    mp[s]++;
    co.push_back(s);
  }
  int max = 0;
  vector<string> mx;
  rep(i, co.size()) {
      if(max<mp[co[i]]){
        max = mp[co[i]];
      }
  }
  rep(i, co.size()) {
    if (max == mp[co[i]]) {
      mx.push_back(co[i]);
    }
  }
  //cout << 3 << endl;
  sort(mx.begin(), mx.end());
  mx.erase(unique(mx.begin(), mx.end()),mx.end());
  rep(i, mx.size()) cout << mx[i] << endl;
}


Measured memory_bytes: 28400
#include <iostream>/*{{{*/
#include <bits/stdc++.h>
#define rep(i, x) for(int i = 0; i < (int)(x); i++)
#define REPS(i,x) for(int i = 1; i <= (int)(x); i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i >= n;i--)
#define ALL(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define FILL(x,y) memset(x,y,sizeof(x))
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define PB(a) push_back(a)
#define debug(x) cerr << __LINE__ << ": " << #x << " -> " << x << '\n'
#define INF 999999999
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};/*}}}*/

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

  int n, m;
  cin >> n >> m;
  int d[n] = {};
  rep(i, m){
    int tmp;
    cin>>tmp;
    d[tmp-1] += 1;
    cin>>tmp;
    d[tmp-1] += 1;
  }
  rep(i,n){
    cout << d[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <numeric>
#include <time.h>
#include <map>
#include <unordered_map>
#include <stack>
#include <queue>

using namespace std;
typedef long long ll;

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

int main()
{
  string s;
  cin >> s;
  int sz = s.size();
  int a = 0, b = 0;
  for (int i = 0; i < sz; i++)
  {
    if (i % 2 == s[i] - '0')
    {
      a++;
    }
    else
    {
      b++;
    }
  }

  cout << min(a, b) << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a),i##_end=(b);i<=i##_end;++i)
#define For(i,a,b) for(int i=(a),i##_end=(b);i<i##_end;++i)
#define per(i,a,b) for(int i=(b),i##_st=(a);i>=i##_st;--i)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define dbg(x) cerr<<#x" = "<<x<<endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define Es(x,i) for(Edge*i=G[x];i;i=i->nxt)
typedef long long ll;
typedef pair<int,int> pii;
const int inf=~0u>>1,MOD=1e9+7;
inline int rd() {
    int x,c,f=1;while(!isdigit(c=getchar()))f=c!='-';x=c-'0';
    while(isdigit(c=getchar()))x=x*10+c-'0';return f?x:-x;
}
const int N=100011;
int n,m;
int fa[N],s[N];
int find(int x){
	if(x!=fa[x]){
		int tmp=find(fa[x]);
		s[x]+=s[fa[x]];
		fa[x]=tmp;
	}
	return fa[x];
}
int main(){
	n=rd(),m=rd();
	rep(i,1,n)fa[i]=i;
	rep(_,1,m){
		int l=rd(),r=rd(),w=rd();
		if(find(l)!=find(r)){
			s[fa[r]]=s[l]-s[r]-w;
			fa[fa[r]]=fa[l];
		} else if(s[r]-s[l]!=-w){
			puts("No");
			return 0;
		}
	}
	puts("Yes");
}

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

int main() {
int64_t n;
cin>>n;
  vector<int> a(n);
for(int i=0;i<n;i++){
  cin>>a.at(i);
}
map<int, int> ans;
for(int i=0;i<n;i++){
  ans[a.at(i)]=i+1;
}
for(int i=1;i<=n;i++){
  cout<<ans[i]<<endl;
}


}

Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define iter(it,a) for(auto it=a.begin();it!=a.end();it++)
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define preturn(X) cout<<X<<endl; return 0
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//cout.setf(ios::fixed); cout.precision(18)

bool check(string x){
    int i = 0;
    int j = x.size()-1;
    while(i<j){
        if(x[i]!=x[j]){
            return 0;
        }
        i++;
        j--;
    }
    return 1;
}

vector<int> val;

int main(){
    cin.tie(0);ios_base::sync_with_stdio(0);
    string s,a="";
    cin>>s;
    s = "a"+s;
    s = s+"a";
    rep(i,0,s.size()){
        if(s[i]!='x'){
            a+=s[i];
        }
    }
    if(check(a)==0){
        preturn(-1);
    }
    int temp = 0;
    rep(i,1,s.size()){
        if(s[i]!='x'){
            val.pb(temp);
            temp = 0;
        }
        else{
            temp++;
        }
    }
    int i = 0;
    int j = val.size()-1;
    ll ans = 0;
    while(i<j){
        ans+=(abs(val[i]-val[j]));
        i++;
        j--;
    }
    preturn(ans);
}

Measured memory_bytes: 1260
#include<cstdio>
int main()
{
    int K,S;
    int count=0;
    scanf("%d%d",&K,&S);
    for(int x=0;x<=K;x++)
    {
        for(int y=0;y<=S-x&&y<=K;y++)
        {
            if(S-x-y<=K)
                count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


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

#define MAX_N 19

long long K, m;
int dig[MAX_N], cut[MAX_N], sum;
vector<pair<long long, string>>vec;
char T[11] = "0123456789";

void _memset() {
	sum = 0;
	for (int i = 0; i < MAX_N; i++) {
		dig[i] = 0;
		cut[i] = 0;
	}
	vec.clear();
}

long long power(long long n, long long v) {
	long long res = 1;
	for (int i = 0; i < v; i++) {
		res *= n;
	}
	return res;
}

int digits(long long n) {
	for (int i = 0; i < MAX_N; i++) {
		if (power(10, i) >= n) { return i + 1; }
	}
}

long long STOI(string U) {
	long long res = 0;
	for (int i = 0; i < U.size(); i++) {
		for (int j = 0; j < 10; j++) {
			if (U[i] == T[j]) {
				res += power(10, U.size() - 1 - i)*j;
			}
		}
	}
	return res;
}

string TOSTR(long long n) {
	string S = ""; bool ok = false;
	for (int i = MAX_N - 1; i >= 0; i--) {
		long long b = power(10, i);
		long long c = (n / b) % 10;
		if (c >= 1) {
			ok = true;
		}
		if (ok == true) {
			S += T[c];
		}
	}
	return S;
}

string make(vector<long long>vect) {
	string W = "";
	for (int i = 0; i < vect.size(); i++) {
		if (i >= 1) { W += ','; }
		W += TOSTR(vect[i]);
	}
	return W;
}

vector<long long>kaiseki(string W) {
	vector<long long>vec4;
	string X = "";
	W += ',';
	for (int i = 0; i < W.size(); i++) {
		if (W[i] == ',') {
			vec4.push_back(STOI(X));
			X = "";
		}
		else {
			X += W[i];
		}
	}
	return vec4;
}

int main() {
	while (true) {
		_memset();
		cin >> K >> m;
		if (K == 0 && m == 0) {
			break;
		}

		int digit = digits(m);
		string S = "";
		vector<long long>vec2;
		vec2.clear();

		for (int i = 0; i < MAX_N; i++) {
			dig[i] = (m / power(10, i)) % 10;
		}
		for (int i = 0; i < power(2, digit - 1); i++) {
			S = "";
			sum = 0;
			vec2.clear();
			for (int j = 0; j < MAX_N; j++) {
				cut[j] = 0;
			}
			for (int j = 0; j < digit - 1; j++)
			{
				int a = power(2, j);
				cut[j] = (i / a) % 2;
			}

			for (int j = digit - 1; j >= 1; j--) {
				S += T[dig[j]];
				if (cut[j - 1] == 1) {
					vec2.push_back(STOI(S));
					sum += vec2[vec2.size() - 1];
					S = "";
				}
			}
			S += T[dig[0]];
			vec2.push_back(STOI(S));
			sum += vec2[vec2.size() - 1];
			S = "";

			if (sum <= K && vec2[0] != 0) {
				vec.push_back(make_pair(sum, make(vec2)));
			}
		}
		sort(vec.begin(), vec.end(),greater<pair<long long, string>>());

		long long target;
		int sum2 = 0;

		if (vec.size() >= 1) {
			sum2 = 0;
			target = vec[0].first;
			for (int i = 0; i < vec.size(); i++) {
				if (vec[i].first == target) {
					sum2++;
				}
				else {
					break;
				}
			}
		}
		if (sum2 == 0) {
			cout << "error" << endl;
		}
		if (sum2 >= 2) {
			cout << "rejected" << endl;
		}
		if (sum2 == 1) {
			cout << vec[0].first << ' ';
			vector<long long>vec3 = kaiseki(vec[0].second);
			for (int i = 0; i < vec3.size(); i++) {
				if (i >= 1) { cout << ' '; }
				cout << vec3[i];
			}
			cout << endl;
		}

	}
	return 0;
}

Measured memory_bytes: 3060
S=input()

A="01"*(len(S)//2)+"0"*(len(S)%2)
count_A=0

B="10"*(len(S)//2)+"1"*(len(S)%2)
count_B=0

for i in range(len(S)):
    if S[i]!=A[i]:
        count_A+=1
    if S[i]!=B[i]:
        count_B+=1

print(min(count_A,count_B))



Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int n, m, q;
std::vector<int> a, b, c, d;
std::vector<int> v;

int func() {
    if (v.size() == n) {
        int ret = 0;
        for (int i = 0; i < q; i++) {
            if (v[b[i] - 1] - v[a[i] - 1] == c[i]) {
                ret += d[i];
            }
        }
        return ret;
    }

    int ret = 0;
    for (int i = v.size() == 0 ? 1 : v.back(); i <= m; i++) {
        v.push_back(i);
        ret = std::max(ret, func());
        v.pop_back();
    }
    return ret;
}


int main() {
    std::cin >> n >> m >> q;
    for (int i = 0; i < q; i++) {
        int a_, b_, c_, d_;
        std::cin >> a_ >> b_ >> c_ >> d_;
        a.push_back(a_);
        b.push_back(b_);
        c.push_back(c_);
        d.push_back(d_);
    }
    std::cout << func() << std::endl;
    return 0;
}


Measured memory_bytes: 3680
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define REP(i, a, b) for ( int i = a; i < b; i++ )
#define rep(i, n) REP(i, 0, n)
#define INFTY (1<<21)
int m, n, k, d, C[7], G[110][110], N, D[110][64];
int getID(string str){
if ( str == "H" ) return 0;
if ( str == "D" ) return N - 1;
string num = str.substr(1, str.size()-1);
if ( str[0] == 'C' ) return atoi(num.c_str());
return atoi(num.c_str()) + m;
}
bool isC(int x){ return 1 <= x && x <= m; }
int bellman(){
rep(i, N) rep(j, (1<<m)) D[i][j] = INFTY;
D[0][0] = 0;
rep(o, N*(1<<m)){bool change = false;
rep(u, N) rep(v, N){
if ( u == v || G[u][v] == INFTY ) continue;
rep(b, (1<<m)){
if (isC(v) && (b&(1<<(v-1))) != 0 ) continue;
if ( isC(v) ) {
if ( D[u][b] + G[u][v] - C[v] < D[v][b|(1<<(v-1))] ) {
D[v][b|(1<<(v-1))] = D[u][b] + G[u][v] - C[v];
change = true;
}
} else {
if ( D[u][b] + G[u][v] < D[v][b] ){
D[v][b] = D[u][b] + G[u][v];
change = true;
}
}
}
}
if ( !change ) break;
}
int minv = INFTY;
rep(i, (1<<m)) minv = min(minv, D[N-1][i]);
return minv;
}
int main(){
string source, target;
int cost;
while(cin >> m >> n >> k >> d && m ){
N = 2 + n + m;
REP(i, 1, m+1) cin >> C[i];
rep(i, N) rep(j, N) G[i][j] = INFTY;
rep(i, d){
cin >> source >> target >> cost;
int s = getID(source);
int t = getID(target);
G[t][s] = G[s][t] = min(G[s][t], cost * k);
}
cout << bellman() << endl;
}
return 0;
}

Measured memory_bytes: 1300
#include<bits/stdc++.h>
#define exi return puts("-1"),0
const int N=100005;
using namespace std;
typedef long long ll;
int n,no[N],sz[N],f[N],de[N];
pair<ll,int>d[N];
ll tp,ans;
map<ll,int>mp;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	scanf("%lld",&d[i].first),
	d[i].second=i,sz[i]=1;
	sort(d+1,d+n+1);
	for(int i=1;i<=n;i++)
	mp[d[i].first]=i;
	for(int i=n;i>1;i--){
		tp=d[i].first+2*sz[i]-n;
		//cerr<<d[i].first<<":"<<tp<<endl;
		if(sz[i]*2>=n||!mp[tp])exi;
		f[i]=mp[tp],sz[mp[tp]]+=sz[i];
	}
	//cerr<<"??\n";
	for(int i=2;i<=n;i++)
	de[i]=de[f[i]]+1,ans+=de[i];
	if(ans^d[1].first)exi;
	for(int i=2;i<=n;i++)
	printf("%d %d\n",d[i].second,d[f[i]].second);
}

Measured memory_bytes: 10496
n = int(input())
t,a = (input().split())
t,a = int(t),int(a)
ans = 0
i = 1000000
j = 0

for h in input().split():
    j = j + 1
    h = int(h)
    tmp = t - h*0.006
    if i > abs(a-tmp):
        i = abs(a-tmp)
        ans = j
        
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
#include <math.h>

int main(void){
  float x1,x2=0;
  int n;
  
  scanf("%d", &n);
  /*
  x1 = n/1.08;
  x2 = (n+1)/1.08;
  for(int i=ceil(x1);i<=ceil(x2);i++){
    if(ceil(i) ==floor(i)){
      printf("%d", i);
      return 0;
    }
  }
  */
  
  for(int i=1;i<=n;i++){
    if((floor)(i*1.08)==n){
         printf("%d", i);
      return 0;
    }
  }
  

      
       
       
        printf(":(\n");

  /*
  if(ceil(ceil(x1)) != floor(ceil(x))){
  }
  else          printf("%.0f",x);

*/


  return 0;
}
  

Measured memory_bytes: 1708
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

template <typename T = ll>
class SegmentTree
{
public:
  using Fn = function<T(T, T)>;
  int N;
  vector<T> dat;
  const T unit = 0; //単位元 a * e = a
  Fn func = [](ll a, ll b) { return max(a, b); };

  void init(ll n)
  {
    N = 1;
    while (N < n)
      N *= 2;
    dat.assign(2 * N - 1, unit);
  }

  void update(int k, T a)
  {
    k += N - 1;
    dat[k] = a;
    while (k > 0)
    {
      k = (k - 1) / 2;
      dat[k] = func(dat[k * 2 + 1], dat[k * 2 + 2]); //
    }
  }

  T query(int a, int b, int k = 0, int l = 0, int r = -1)
  {
    if (r < 0)
      r = N;
    if (r <= a || b <= l)
      return unit;
    if (a <= l && r <= b)
      return dat[k];
    else
    {
      T vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
      T vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
      return func(vl, vr);
    }
  }
};

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

  int n;
  cin >> n;
  auto my_max = [](ll a, ll b) { return max(a, b); };
  SegmentTree<> sg[26];
  rep(i, 26)
  {
    sg[i].init(n);
  }
  string s;
  cin >> s;
  rep(i, s.length())
  {
    sg[s[i] - 'a'].update(i, 1);
  }
  int q;
  cin >> q;
  rep(qi, q)
  {
    int type;
    cin >> type;
    if (type == 1)
    {
      int i;
      char c;
      cin >> i >> c;
      i--;
      rep(j, 26) sg[j].update(i, 0);
      sg[c - 'a'].update(i, 1);
    }
    else
    {
      int l, r;
      cin >> l >> r;
      l--, r--;
      int sum = 0;
      rep(i, 26) sum += sg[i].query(l, r + 1);
      cout << sum << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 214292