akhauriyash/Code-Regression huggingface dataset:
/*
 * Copyright (c) 2019 ... All rights reserved.
 * ...
 */
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

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

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {

    // source code
    int R, G, B, N;
    cin >> R >> G >> B >> N;
    int cnt = 0;

    for (int r = 0; r <= 3000; r++){
        for (int g = 0; g <= 3000; g++){
            int tmp_b = N - g*G - r*R;
            if ((tmp_b%B == 0) and (tmp_b >= 0)){
                cnt++;
            }
        }
    }
    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>

using namespace std;

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

	int n;
	cin >> n;

	int c[n-1],s[n-1],f[n-1];

	for(int i=0;i<n-1;i++){
		cin >> c[i] >> s[i] >> f[i];
	}

	for(int i=0;i<n-1;i++){
		int time=0;
		for(int j=i;j<n-1;j++){
			if(time < s[j]) time = s[j] + c[j];
			else if(time % f[j] == 0) time += c[j];
			else		time += (f[j] - time % f[j]) + c[j];
		}
		cout << time << "\n";
	}
	cout << "0\n";
	
	return 0;
}

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

using namespace std;

using ll = int64_t;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = 2147483647;
constexpr ll L_INF = 9223372036854775807LL;

//===




int main()
{
	string S;
	cin >> S;
	ll K;
	cin >> K;

	int lenS = (int)S.size();

	vector<char> cv;
	Vl nv;

	char now;

	now = S[0];
	ll cnt = 1;
	for (int i = 1; i < lenS; ++i) {
		if (S[i] == now) {
			++cnt;
		}
		else {
			cv.push_back(now);
			nv.push_back(cnt);
			now = S[i];
			cnt = 1;
		}
	}

	cv.push_back(now);
	nv.push_back(cnt);


	ll ans = 0;

	int lencv = (int)cv.size();

	if (lencv == 1) {
		ans = nv[0] * K / 2;
	}
	else if (cv[0] == cv[lencv - 1] && lencv > 1) {
		for (int i = 1; i < lencv - 1; ++i) {
			ans += nv[i] / 2;
		}
		ans *= K;
		ans += (nv[0] + nv[lencv - 1]) / 2 * (K - 1);
		ans += nv[0] / 2;
		ans += nv[lencv - 1] / 2;
	}
	else {
		for (int i = 0; i < lencv; ++i) {
			ans += nv[i] / 2;
		}
		ans *= K;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#define ll long long
using namespace std;
const int maxn=110;

ll n;



int main() {
    //freopen("a.out", "w", stdout);
    while(scanf("%lld",&n)&&n) {
        ll a=0;
        string s;
        cin>>s;
        for(int i=0;i<s.size();++i) {
            a<<=1;
            a+=s[i]-'0';
        }
        a+=1ll<<52;
        ll e=0,ans=a;
        while(n) {
            ll t=((1ll<<53)-1-ans)/a+1;
            if(t>n) {
                ans+=n*a;
                break;
            }
            else {
                ans+=t*a;
                ++e;
                ans>>=1;
                a>>=1;
                if(!a) break;
                n-=t;
            }
        }
        for(int i=11;i>=0;--i) {
            cout<<(((1ll<<i)&e)?1:0);
        }
        for(int i=51;i>=0;--i) {
            cout<<(((1ll<<i)&ans)?1:0);
        }
        cout<<'\n';
    }
}


/*
100 1100101


*/


Measured memory_bytes: 3260
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int ans=0;
    vector<char>W(3);
    for(int i=0;i<3;i++){
        cin>>W[i];
    }
    if(W[0]=='R'){
        ans++;
        if(W[1]=='S'){
            cout<<ans<<endl;
            return 0;
        }
        else{
            ans++;
            if(W[2]=='S'){
                cout<<ans<<endl;
                return 0;
            }
            else{
                ans++;
            }
        }
    }
    else{
        if(W[1]=='R'){
            ans++;
            if(W[2]=='R'){
                ans++;
            }
            else{
                cout<<ans<<endl;
                return 0;
            }
        }
        else{
            if(W[2]=='R'){
                ans++;
            }
        }
    }
    cout<< ans << endl;
    return 0;
}


Measured memory_bytes: 3592
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int maxx=1e8+10;
int a[maxx];
int main() {
	ll n,t;
	cin>>n;
	ll len=0;
	while(n){
		if(n%26==0){
			a[len++]=26;
			n--;
		}else{
			a[len++]=n%26;
		}
		n/=26;
	} 
	per(i,0,len){
		printf("%c",a[i]+'a'-1);
	}
} 

Measured memory_bytes: 3608
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



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

using namespace std;
char ban[75][75];
char ans[75][75];
int a[8] = {-1,-1,-1,0,0,1,1,1};
int b[8] = {-1,0,1,1,-1,-1,0,1};

int h,w;
int main(){
  cin >> h >> w;
  FOR(i,h){
    FOR(j,w){
      cin >> ban[i][j];
    }
  }
  FOR(i,h){
    FOR(j,w){
      if(ban[i][j]=='#') ans[i][j]=ban[i][j];
      else{
        int k = 0;
        REP(t1,8){
          if(ban[i+a[t1]][j+b[t1]]=='#') k++;
        }
        ans[i][j] = '0'+k;
      }
    }
  }
  FOR(i,h){
    FOR(j,w){
      cout << ans[i][j];
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//20:32~
import java.util.*;

public class Main{
    public static void main(String args[]){

        Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
        String s = sc.next();

        char c = ' ';
        int count = 0;
        for(int i = 0; i < n; i++){
            if(c == s.charAt(i)){

            }else{
                c = s.charAt(i);
                count++;
            }
        }

        System.out.println(count);

    }

}


Measured memory_bytes: 24020
#include <bits/stdc++.h>
#define NMAX 1001

using namespace std;
struct pnt{int x,y,d;};
queue<pnt> q;
int dl[]={0,1,0,-1},dc[]={1,0,-1,0};
char b[NMAX][NMAX];
int dmax=0,n,m;
void bfs(){
    while(q.size()){
        dmax=max(dmax,q.front().d);
        for(int i=0;i<4;i++){
            int X=q.front().x+dc[i],Y=q.front().y+dl[i];
            if(X>=0 && X<n && Y>=0 && Y<m & b[X][Y]=='.'){
                b[X][Y]='#';
                q.push({X,Y,q.front().d+1});
            }
        }
        q.pop();
    }
}
int main(){
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    cin>>n>>m;
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>b[i][j];
            if(b[i][j]=='#')
                q.push({i,j,0});
        }
    }
    bfs();
    cout<<dmax;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    string a[n];
    int acnt, bcnt, ccnt, dcnt;
    acnt = 0;
    bcnt = 0;
    ccnt = 0;
    dcnt = 0;
    rep(i,n){
        cin >> a[i];
        if(a[i] == "AC"){
            acnt++;
        }
        else if(a[i]=="WA"){
            bcnt++;
        }
        else if(a[i]=="TLE"){
            ccnt++;
        }
        else{
            dcnt++;
        }
        
    }
    cout << "AC";
    cout << ' ';
    cout << 'x';
    cout << ' ';
    cout << acnt << endl;
    cout << "WA";
    cout << ' ';
    cout << 'x';
    cout << ' ';
    cout << bcnt << endl;
    cout << "TLE";
    cout << ' ';
    cout << 'x';
    cout << ' ';
    cout << ccnt << endl;
    cout << "RE";
    cout << ' ';
    cout << 'x';
    cout << ' ';
    cout << dcnt << endl;

        /*cout << "WA x" + ' '+bcnt << endl;
        cout << "TLE" + ' '+ccnt << endl;
        cout << "RE"+ ' '+dcnt << endl;*/
}

Measured memory_bytes: 6744
s = input()
if 1 <= int(s[2:]) <= 12:
    if 1 <= int(s[0:2]) <= 12:
        print('AMBIGUOUS')
    else:
        print('YYMM')
else:
    if 1 <= int(s[0:2]) <= 12:
        print('MMYY')
    else:
        print('NA')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    vector<int> b(n);
    for (int i = 0; i < n; i++) {
        cin >> b.at(i);
        b.at(i)--;
    }

    vector<int> ans;
    for (int i = 0; i < n; i++) {
        int ind;
        for (int j = 0; j < n - i; j++) {
            if (b.at(j) > j) {
                cout << -1 << endl;
                return 0;
            }
            if (b.at(j) == j) ind = j;
        }
        ans.push_back(ind);
        b.erase(b.begin() + ind);
    }

    reverse(ans.begin(), ans.end());
    for (int i = 0; i < n; i++) {
        cout << ans.at(i) + 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> vi;
#define endl '\n'
#define fo(i,a,b) for(int i=a;i<=b;i++)
#define rf(i,a,b) for(int i=a;i>=b;i--) 
#define fast_io ios_base::sync_with_stdio(0);
#define show(x) cout<<x<<endl;
#define pret(x) cout<<x<<endl; return 0;
#define disp(x) cout<<x<<" ";
#define let(x,y) cout<<x<<" "<<y<<endl;
ll MOD=1e9+7;
const int maxn=2e5+5;

int32_t main(){
    fast_io;
    int n,x,t;
    cin >> n >> x >> t;
    int ans = 0;
    while (n > 0){
    	n -= x;
    	ans += t;
    }
    show(ans);
    return 0;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll n;cin >>n;
    int ans=INF;
    for (int i = 0; i < 1000; ++i) {
        if(i>=n){
            ll c=i;
            set<ll>s;
            while(c>0){
                s.insert(c%10);
                c/=10;
            }
            if(s.size()==1)ans=min(ans,i);
        }
    }
    cout <<ans <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <string>
#include <utility>
#include <map>
#include <deque>

using namespace std;
#define rep(i,n) for(int i=1;i<=(int)(n);i++)
#define Rep(i,n) for(int i=0;i<=(int)(n-1);i++)
typedef long long ll;
typedef map<int,int> mint;
typedef pair<int,int> pint;
typedef pair<ll,ll> pll;
typedef deque<pair<ll,ll>> dep;
int dx[]={-1,0,1,0};
int dy[]={0,-1,0,1};
int inf=1e9+1000;
const int mod=1e9+7;
ll infi=1e18+100;

//x=10111;
//x<<2 = 1011100 (右シフト),x>>2 = 101 (左シフト)
//(x>>2)&1 = 101 & 001 = 1
//iビット目は、(x>>i) & 1 でわかる(x>>i)%2 でもよい

int H,W;
char c[60][60];
string s[60];

int main(){
	cin>>H>>W;
	Rep(i,H) Rep(j,W) cin>>c[i][j];
	bool f=true;
	
	Rep(i,H){
		Rep(j,W){
			if(c[i][j]=='#'){
				int cnt=0;
				Rep(k,4){
					int ni=i+dx[k];
					int nj=j+dy[k];
					if(c[ni][nj]=='#'&&ni>=0&&ni<=(H-1)&&nj>=0&&nj<=(W-1)){
						cnt++;
					}
				}
				if(cnt==0){f=false; break;}
			}
		}
	}
	if(f) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 200001

int N,K;
ll L;
int minimum,maximum;
int input_array[NUM],table[NUM];

bool isOK(int number){

	for(int i = minimum; i <= maximum; i++)table[i] = 0;

	int count = 0,loc;
	for(loc = 0; loc < N; loc++){
		if(input_array[loc] <= number){
			count++;
			if(count == K){
				break;
			}
		}
	}

	if(loc == N)return false;

	ll sum = (N-1)-loc+1;

	for(int left = 1; left+(K-1) <= N-1; left++){
		if(input_array[left-1] <= number)count--;
		while(loc < N && count < K){
			loc++;
			if(input_array[loc] <= number)count++;
		}
		if(loc == N)break;
		sum += (N-1)-loc+1;
	}

	return sum >= L;
}

int main(){

	scanf("%d %d %lld",&N,&K,&L);
	minimum = BIG_NUM;
	maximum = -1;

	for(int i = 0; i < N;i++){
		scanf("%d",&input_array[i]);
		minimum = min(minimum,input_array[i]);
		maximum = max(maximum,input_array[i]);
	}

	int left = minimum,right = maximum,m = (left+right)/2;
	int ans = maximum;

	while(left <= right){

		if(isOK(m)){
			ans = m;
			right = m-1;
		}else{
			left = m+1;
		}
		m = (left+right)/2;
	}

	printf("%d\n",ans);

	return 0;
}



Measured memory_bytes: 4716
n = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

import itertools
A = itertools.permutations([i+1 for i in range(n)], n)
B=list(A)

B.sort()

# print(B)

p=-1
q=-1
for i in range(len(B)):
    # print(P,[j for j in B[i]])
    if P == [j for j in B[i]]:
        
        p=i
    if Q== [j for j in B[i]]:
        q=i
print(abs(p-q))

Measured memory_bytes: 47708
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <climits>

#define rep(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 0
//#ifdef LOCAL
//#define DEBUG(s) cout << (s) << endl
//#define dump(x)  cerr << #x << " = " << (x) << endl
//#define BR cout << endl;
//#else
//#define DEBUG(s) do{}while(0)
//#define dump(x) do{}while(0)
//#define BR
//#endif


//改造
typedef long long int ll;
using namespace std;
#define INF (1 << 20)
#define INFl (ll)5e15
#define DEBUG 0 //デバッグする時1にしてね
#define dump(x)  cerr << #x << " = " << (x) << endl
#define MOD 1000000007
//ここから編集する


int main() {
    int N;
    cin >> N;
    int x = 0;
    bool div[32] = {};

    rep(i,0,N){
        int tmp;
        cin >> tmp;
        x ^= tmp;
        for(int j = 0; ;j++){
            if(tmp >> j & 1){
                div[j] = true;
                break;
            }
        }
    }
    int cnt = 0;
    while(x != 0){
        int j;
        for(j = 0; x >> j > 0; j++){

        }
        x ^= ((1 << j) - 1);
        cnt++;
        if(!div[j-1]){
            cnt = -1;
            break;
        }

    }
    cout << cnt << endl;





    return 0;
}


Measured memory_bytes: 256
// E - Multiplication 4
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int N, K; cin>>N>>K;
	vector<int> P, M;
	vector<ll> A(N);
	rep(i, N){
		cin>>A[i];
		if(A[i] < 0) M.push_back(A[i]);
		else P.push_back(A[i]);
	}

	bool can_minus = true;
	if(P.size() > 0) can_minus = K<N? false: M.size()%2;
	else can_minus = K%2;

	ll ans = 1, mod = 1'000'000'007;

	if(can_minus){
		sort(A.begin(), A.end(), [](ll x, ll y){ return abs(x) < abs(y); });
	}

	else{
		A.clear();
		sort(P.begin(), P.end());
		sort(M.rbegin(), M.rend());
		if(K % 2){ ans = P.back(); P.pop_back(); }
		while(P.size() > 1){
			ll x = P.back(); P.pop_back();
			x *= P.back(); P.pop_back();
			A.push_back(x);
		}
		while(M.size() > 1){
			ll x = M.back(); M.pop_back();
			x *= M.back(); M.pop_back();
			A.push_back(x);
		}
		sort(A.rbegin(), A.rend());
	}

	if(!can_minus) K /= 2;
	rep(i, K) ans = (ans * (A[i] % mod)) % mod;
	cout<< (ans+mod)%mod <<endl;
}


Measured memory_bytes: 5824
//(????????°, ?????¨????????????????????°)??§??´?????????????????¨, ???????????¢????????????????????????????????????????????§??????
//????????¨, ????????????????????????3?§???¢??¨4?§???¢????????????????????????
//A * B ??? 25000^2 ??? min(A, B) ??? 25000???????????¢???????°??????????????????????????????¨??£?§£???????????¨?????????????????????

#include <iostream>
#include <vector>
#define int long long
using namespace std;

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

//ax + by = gcd(a, b)??¨????????´??°???(x, y)??????????±?????????????.
void extgcd(int a, int b, int &x, int &y) {
	int r[100];
	int q[100];
	int cnt;
	
	r[0] = a;
	r[1] = b;
	cnt = 2;
	while (r[cnt - 2] % r[cnt - 1] != 0) {
		q[cnt - 1] = r[cnt - 2] / r[cnt - 1];
		r[cnt] = r[cnt - 2] - q[cnt - 1] * r[cnt - 1];
		cnt++;
	}
	q[cnt - 1] =r[cnt - 2] /  r[cnt - 1];
	
	x = 0;
	y = 1;
	for (int i = 0; i < cnt - 2; i++) {
		int nx = y;
		int ny = x - y * q[cnt - 2 - i];
		x = nx;
		y = ny;
	}
}

signed main() {
	int n, w, h;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> w >> h;
		int g = gcd(w, h);
		if (g < (w + h) / (2 * g)) {
			int x, y;
			extgcd(w, -h, y, x);
			if (x < 0) { x *= -1; y *= -1; }
			cout << 3 << endl;
			cout << 0 << " " << 0 << endl;
			cout << w << " " << h << endl;
			cout << x << " " << y << endl;
		}
		else {
			cout << 4 << endl;
			cout << 0 << " " << 0 << endl;
			cout << w << " " << h - 1 << endl;
			cout << w / g << " " << h / g << endl;
			cout << w - 1 << " " << h << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3104
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()
A.sort()

max = max(A)
index = bisect_left(A, max / 2)
if abs((max / 2) - A[index]) < abs((max / 2) - A[index - 1]):
    ans = [max, A[index]]
else:
    ans = [max, A[index - 1]]
print(*ans)


Measured memory_bytes: 60400
from collections import deque
from collections import Counter

H,W=map(int,input().split())
S=[]
c = []
for i in range(H):
  s = input()
  S.append(s)
  c.extend(list(s))
c = Counter(c)

def bfs(s):
  seen = [[0 for i in range(W)] for j in range(H)]
  total = [[0 for i in range(W)] for j in range(H)]
  todo = deque([])
  now = s
  if S[now[0]][now[1]]=='#':return 0
  seen[now[0]][now[1]],total[now[0]][now[1]] = 1,0
  todo.append(now)
  while 1:
    if len(todo)==0:break
    now = todo.popleft()
    for d in [(1,0),(-1,0),(0,1),(0,-1)]:
      new = (now[0]+d[0], now[1]+d[1])
      if new[0]<0 or new[0]>=H:continue
      if new[1]<0 or new[1]>=W:continue
      if seen[new[0]][new[1]]==1:continue
      if S[new[0]][new[1]]=='#':continue
      seen[new[0]][new[1]] = 1
      todo.append(new)
      total[new[0]][new[1]] = total[now[0]][now[1]] + 1
  return total

d = bfs((0,0))[-1][-1]
if d == 0:
  print(-1)
  exit()
print(c['.']-d-1)

Measured memory_bytes: 9460
N = int(input())
blist = list(map(int,input().split()))

isExist = False
olist = []
while (True):
  if len(blist) == 0:
    isExist = True
    break
    
  changed = False
  for i in reversed(range(len(blist))):
    if blist[i] == i+1:
      olist.insert(0,blist.pop(i))
      changed = True
      break
      
  if not changed:
    break
    
if isExist:
  for index in olist:
    print(index)
else:
  print(-1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }
int main(int argc, char* argv[]) {
    int n;
    cin >> n;
    vector<string> s(n);
    rep(i,n) cin >> s[i];
    vector<int> count(n,0);
    count[0]=0;
    int index=0;
    sort(ALL(s));
    rep(i,n-1) {
        if(s[i]==s[i+1]) count[index]++;
        else index++;
    }
    int max =0;
    rep(i,n) {
        if(max < count[i]) max = count[i];
    }
    unique(ALL(s));
    rep(i,n){
        if(count[i]==max) cout << s[i] << endl;
    }
    return 0;
}


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

using namespace std;

int n;
string s;

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

    cin >> s;

    int n = s.size();
    int c0 = 0, c1 = 0;
    for(int i = 0; i < n; i++)
    {
        if(s[i] == '0')
            c0++;
        else
            c1++;
    }

    cout << 2 * min(c0, c1);

    return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int MAXN=2005,MOD=1000000007;

int PowMod(int a,int b)
{
    int ret=1;
    while(b)
    {
        if(b&1)
            ret=1LL*ret*a%MOD;
        a=1LL*a*a%MOD;
        b>>=1;
    }
    return ret;
}

int fac[MAXN*MAXN],ifac[MAXN*MAXN];

void Init()
{
    fac[0]=1;
    for(int i=1;i<MAXN*MAXN;i++)
        fac[i]=1LL*fac[i-1]*i%MOD;
    ifac[MAXN*MAXN-1]=PowMod(fac[MAXN*MAXN-1],MOD-2);
    for(int i=MAXN*MAXN-2;i>=0;i--)
        ifac[i]=1LL*ifac[i+1]*(i+1)%MOD;
}
int C(int n,int r)
{return 1LL*fac[n]*ifac[n-r]%MOD*ifac[r]%MOD;}

int N,K,dp[MAXN][MAXN];

int main()
{
    Init();
    scanf("%d%d",&N,&K);
    if(K==1)
    {
        puts("1");
        return 0;
    }
    dp[0][0]=1;
    for(int i=0;i<=N;i++)
        for(int j=0;j<=i;j++)
        {
            if(i)
                dp[i][j]=(dp[i][j]+dp[i-1][j])%MOD;
            if(j)
                dp[i][j]=(dp[i][j]+1LL*dp[i][j-1]*C(N*K-i-(K-1)*(j-1)-1,K-2)%MOD)%MOD;
        }
    int ans=1LL*dp[N][N]*fac[N]%MOD;
    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 46336
s=input()
t=input()
n=len(s)
m=len(t)
ans='UNRESTORABLE'
a=[]
for i in range(n-m+1):
  if s[i]==t[0] or s[i]=='?':
    for j in range(m):
      if s[i+j]!=t[j] and s[i+j]!='?':
        break
    else:
      an=list(s[:i]+t+s[i+j+1:])
      for k in range(n):
        if an[k]=='?':
          an[k]='a'
      an=''.join(an)
      a.append(an)
if len(a):
  print(min(a))
else:print(ans)

Measured memory_bytes: 38512
from collections import deque

n = int(input())

g = [[] for _ in range(n)]
for _ in range(n):
    u, k, *V = list(map(int, input().split()))
    V.sort()
    for v in V:
        g[u-1].append(v-1)
        # g[v-1].append(u-1)
d = [-1] * n
d[0] = 0

que = deque([])
que.append(0)
while que:
    v = que.popleft()
    for i in g[v]:
        if d[i] == -1:
            d[i] = d[v] + 1
            que.append(i)

for i in range(n):
    print(f'{i+1} {d[i]}')


Measured memory_bytes: 6020
#include <bits/stdc++.h>   
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll mod = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
     
ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}
using Graph = vector<vector<int>>;
Graph G;

int main(){
    int n; cin >> n;
    int ans = 0;
    rep(i, n){
        int x; cin >> x;
        if((i + 1) % 2 == 1 and x % 2 == 1) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3632
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <bits/stdc++.h>

using namespace std;

long long int max( long long int a, long long int b )
{
    if( a >= b )    return a;
    
    return b;
}

int main()
{
    long long int a, b, c, d;
    cin>>a;
    cin>>b;
    cin>>c;
    cin>>d;
    
    long long int prod = a*c;
    
    prod = max(prod, a*d);
    prod = max( prod, b*c );
    prod = max( prod, b*d );
    
    cout<<prod<<endl;
    
    return 0;
}


Measured memory_bytes: 3632
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn count_digit(n: usize) -> usize {
    let mut ret = 0;
    let mut rem = n;
    while rem != 0 {
        rem /= 10;
        ret += 1;
    }
    ret
}

fn F(a: usize, b: usize) -> usize {
    max(count_digit(a), count_digit(b))
}

const INF: usize = 1 << 60;

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut ans = INF;
    for i in (1..).take_while(|k| k * k <= N) {
        if N % i == 0 {
            ans = min(ans, F(i, N/i));
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
 
 
 
 
int main() {
   
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
   
    long int n,cnt=0;
    cin>>n;
    long int a[n],i,j;
    int flag=0;
    for(i=0;i<n;++i)
      { cin>>a[i];
       
      }
         
    
    
    
    sort(a,a+n);
    
    for(i=0;i<n;++i)
     {
         flag=0;
        for(j=1;j<=sqrt(a[i]);++j)
         {
             if(a[i]%j==0)
              {
                  if(binary_search(a,a+n,j))
                    {
                        if(j==a[i])
                          {
                              if(upper_bound(a,a+n,j)-lower_bound(a,a+n,j)>1)
                                {
                                    flag=1;
                                    break;
                                }
                          }
                        else
                        {
                        flag=1;
                        break;
                        }
                    }
                   
                   if(binary_search(a,a+n,a[i]/j)==1)
                    {
                        if(j==1)
                         {
                             if(upper_bound(a,a+n,a[i])-lower_bound(a,a+n,a[i])>1)
                                {
                                    flag=1;
                                    break;
                                }
                         }
                         
                        else
                        {
                        flag=1;
                        break;
                        }
                    }
                      
                      
              }
         }
         
         if(flag==0)
           cnt++;
     }
     
     cout<<cnt;
    
   
 
	return 0;
}

Measured memory_bytes: 5236
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll h;
  cin >> h;

  ll buf = 1,cnt = 0;
  while(buf * 2 <= h)
  {
    buf = buf * 2;
    cnt++;
  }
  ll c = pow(2,cnt) - 1;
  cout << buf + c << endl;

  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Threading.Tasks;
using static System.Console;
using static System.Math;
class Z { static void Main() => new KK(); }
class KK
{
	int F => int.Parse(Str);
	long FL => long.Parse(Str);
	int[] G => Strs.Select(int.Parse).ToArray();
	long[] GL => Strs.Select(long.Parse).ToArray();
	double[] GR => Strs.Select(double.Parse).ToArray();
	string Str => ReadLine();
	string[] Strs => Str.Split(new char[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries);
	public const int MOD = 1000000007;
	public const long INFL = 4011686018427387913L;
	public KK()
	{
		SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
		Solve();
		Out.Flush();
	}
	int N;
	long[,] a;
	void Solve()
	{
		N = F;
		a = new long[N, N];
		for (var i = 0; i < N; i++)
		{
			var I = G;
			for (var j = 0; j < N; j++) a[i, j] = I[j];
		}
		dp = new long[1 << N];
		done = new bool[1 << N];
		pair = new long[1 << N];
		for (var s = 1u; s < (1 << N); s++)
		{
			var t = MSB(s);
			for (var i = 0; i < N; i++) if ((s & (1 << i)) != 0) pair[s] += a[t, i];
			pair[s] += pair[s ^ (1 << t)];
		}
		WriteLine(Calc((1u << N) - 1));
	}
	long[] pair;
	long[] dp;
	bool[] done;
	long Calc(uint s)
	{
		if (s == 0) return 0;
		if (!done[s])
		{
			done[s] = true;
			var t = MSB(s);
			var s2 = s ^ (1u << t);
			dp[s] = Calc(s2);
			//var left = new List<int> { t };
			for (var U = (1u << N) - 1; ; --U)
			{
				U &= s2;
				if (U == 0) break;
				//var p = 0L;
				//for (var i = 0; i < N; i++) if ((U & (1 << i)) != 0) left.Add(i);
				//for (var i = 0; i < left.Count; i++) for (var j = i + 1; j < left.Count; j++) p += a[left[i], left[j]];
				dp[s] = Max(dp[s], Calc(s2 ^ U) + pair[U | (1u << t)]);
				//left.Clear();
				//left.Add(t);
			}
		}
		return dp[s];
	}
	public static int MSB(uint n)
	{
		n |= n >> 1;
		n |= n >> 2;
		n |= n >> 4;
		n |= n >> 8;
		n |= n >> 16;
		return BitCount(n) - 1;
	}
	public static int BitCount(uint n)
	{
		n = (n & 0x55555555) + ((n >> 1) & 0x55555555);
		n = (n & 0x33333333) + ((n >> 2) & 0x33333333);
		n = (n & 0x0f0f0f0f) + ((n >> 4) & 0x0f0f0f0f);
		n = (n & 0x00ff00ff) + ((n >> 8) & 0x00ff00ff);
		return (int)((n & 0x0000ffff) + ((n >> 16) & 0x0000ffff));
	}
}


Measured memory_bytes: 14176
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong

signed main(){
	int s;
	cin >> s;
	int tmp,old;
	tmp = s;
	set<int> num_set;
	int m = 1; 
	num_set.insert(s);
	while(1){
		m += 1;
		if(tmp%2==0){
			tmp /= 2;
		}
		else{
			tmp *= 3;
			tmp += 1;
		}
		if(num_set.find(tmp) != num_set.end()){
			break;
		}
		num_set.insert(tmp);
	}
	cout << m << endl;
	


}

Measured memory_bytes: 764
s1 = gets.chomp
s2 = gets.chomp
# s1???????????°???[0..s1.size]?????£?????´???
# s2???????????°???[0..s2.size]?????£?????´???
# ??¨???????????????
res = Array.new(s1.size.succ).map{Array.new(s2.size.succ, 0)}

# ????????????????????????0???????????¨????????¢?????????????????????
for i in (0..s1.size) do
  res[i][0] = i
end
for i in (0..s2.size) do
  res[0][i] = i
end

# ??¨????????????????????????????????°??¨????????¢???1????????¨??????
# ????????§???????????°??¨????????¢???1?¢???????
# ???????????????s??¨dp???????????????1????????????
for i in (1..s1.size) do
  for j in (1..s2.size) do
    if s1[i - 1] == s2[j - 1]
      res[i][j] = res[i - 1][j - 1]
    else
      res[i][j] = [res[i - 1][j - 1], res[i - 1][j], res[i][j - 1]].min + 1
    end
  end
end
p res[s1.size][s2.size]

Measured memory_bytes: 16700
#include <stdio.h>
#include <string.h>
 
int main(void)
{
    char str[1001],p[1001],t[8],tmp;
    int q,a,b,i,j,k;
    scanf("%s%d",str,&q);
    for(i=0;i<q;i++){
        scanf("%s%d%d",t,&a,&b);
        if(strcmp(t,"print")==0){
            for(j=a;j<=b;j++)printf("%c",str[j]);
            puts("");
        }
        else if(strcmp(t,"reverse")==0){
            for(j=a;j<b;j++){
                for(k=b;k>j;k--){
                    tmp=str[k-1];
                    str[k-1]=str[k];
                    str[k]=tmp;
                }
            }
        }
        else{
            scanf("%s",p);
            j=a;
            k=0;
            while(j<=b){
                str[j]=p[k];
                j++;
                k++;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 2112
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    N = II()
    B = LMIIS()
    suma = B[0] + B[-1]
    #Ai :max(Bi,Bi-1)
    for i in range(1,N-1):
        suma += min(B[i],B[i-1])
    print(suma)

if __name__ == '__main__':
    main()

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

void operate(int *s, int size) {
    map<int, int> ns;
    for (int i = 0; i < size; i++) {
        ns[s[i]]++;
    }
    for (int i = 0; i < size; i++) {
        s[i] = ns[s[i]];
    }
}

bool finish(int *s, int size) {
    int ns[size];
    for (int i = 0; i < size; i++) {
        ns[i] = s[i];
    }
    operate(ns, size);
    for (int i = 0; i < size; i++) {
        if (ns[i] != s[i]) {
            return false;
        }
    }
    return true;
}

int main() {
    int n;
    while (cin >> n, n != 0) {
        int s[n];
        for (int i = 0; i < n; i++) {
            cin >> s[i];
        }
        int count = 0;
        while (!finish(s, n)) {
            operate(s, n);
            count++;
        }
        cout << count << endl;
        cout << s[0];
        for (int i = 1; i < n; i++) {
            cout << ' ' << s[i];
        }
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int P = scan.nextInt();
        int[] A = new int[N];
        long[] dp = new long[5001];
        for (int i = 0; i < N; i++) {
            A[i] = scan.nextInt();
        }
        int sum = Arrays.stream(A).sum();
        dp[0] = 1;
        for (int i = 0; i < N; i++) {
            long[] next_dp = new long[5001];
            for (int j = 0; j <= 5000; j++) {
                if (dp[j] == 0) {
                    continue;
                }
                next_dp[j] += dp[j];
                next_dp[j + A[i]] += dp[j];
            }
            dp = next_dp;
        }
        long ans = 0;
        for (int i = 0; i <= sum; i++) {
            if (i % 2 != P) {
                continue;
            }
            ans += dp[i];
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 29524
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;

int main(){
  string s; cin >> s;
  int n = s.size();
  
  ll ans = 0;
  for(int bit = 0; bit < (1<<n-1);bit++){
    ll tmp = 0;
    tmp += s[0] - '0';
    rep(i,n-1){
      if(bit & (1<<i)){
        ans += tmp;
        tmp = s[i+1] - '0';
      }else{
        tmp *= 10;
        tmp += s[i+1] - '0';
      }
    }
    ans += tmp;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <algorithm>

#define rep(i, N) for(int (i) = 0; (i) < (N); (i) ++)
typedef long long ll;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int>  as(N, 0);
    rep(i, N){
        cin >> as[i];
    }
    sort(as.begin(), as.end());
    int ans = 0;
    for(int i = 0; i < N;){
        int j = i;
        int tmp = 0;
        for(; j < N && as[j] == as[i]; j++){
            tmp ++;
        }
        ans += tmp % 2;
        i = j;
    }
    cout << ans << endl;

    return 0;
}


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

using namespace std;

long long n, b, w[110], v[110], memo[110][100010];

long long dp(long long idx, long long weight) {
	if(idx > n) {
		return 0;
	}
	if(memo[idx][weight] != -1) {
		return memo[idx][weight];
	}
	if(weight + w[idx] <= b) {
		memo[idx][weight] = max(dp(idx + 1, weight + w[idx]) + v[idx], dp(idx + 1, weight));
		return memo[idx][weight];
	}
	else {
		memo[idx][weight] = dp(idx + 1, weight);
		return memo[idx][weight];
	}
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	memset(memo, -1, sizeof(memo));
	cin >> n >> b;
	for(long long i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	cout << dp(1, 0) << endl;
}


Measured memory_bytes: 86272
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
 
int main() {
  int N; cin >> N;
  int acnt = 0, uncnt = 0;
  rep(i, N) {
    string s; cin >> s;
    if(s=="A") acnt++;
    if(s=="Un")uncnt++;
    if(acnt<uncnt) {
      cout << "NO" << endl;
      return 0;
    }
  }
  cout << (acnt == uncnt ? "YES" : "NO") << endl;
  return 0;
}

Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007


int main() {
	int N; cin >> N;
	vector<int> a(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(), greater<int>());
	int A = 0, B = 0;
	for (int i = 0; i < N; i++) {
		if (i % 2 == 0)A += a[i];
		else B += a[i];
	}
	cout << A - B << endl;



	return 0;
}


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

//答えが合わない場合はlong long型を疑うこと！

int main(){
    int a,b,c,d,ans=0;
    cin >> a >> b >> c >> d;
    if(a>=b) ans+=b;
    else ans+=a;
    if(c>=d) ans+=d;
    else ans+=c;
    cout << ans <<endl;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split(" ");
	var max = parseInt(line[0]);
	var sum = parseInt(line[1]);
	var ans = 0;
	var maxover3 = Math.ceil(sum/3);
	var remain = 0;
	for(var i = 0; i <= maxover3;i++){
		remain = sum - i;
		for(var j = i;j<=max;j++){
			var k = remain - j;
			if(k>=j&&k<=max){
				if(i===j&&i===k){
					ans++;
					 	      //console.log(String(i)+" "+String(j)+" "+String(k));
				} else if(i===j||i===k||k===j){
					ans+=3;
					 	      //console.log(String(i)+" "+String(j)+" "+String(k));
				} else {
					ans+=6;
					 	     //console.log(String(i)+" "+String(j)+" "+String(k));
				}
			}
 
		}
	}
	console.log(ans);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <bitset>

#define PB push_back
#define MP make_pair
#define YES cout<<"YES"<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define No cout<<"No"<<endl
#define INF (1<<30)
#define LLINF (1<<60)
#define MOD 1000000007
#define REP(i, n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;

int N;
pair<int, int>r[111], b[111];
bool c[222];

int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        r[i] = MP(x, y);
    }
    for (int i = 0; i < N; i++) {
        int x, y;
        cin >> x >> y;
        b[i] = MP(x, y);
    }

    sort(r, r + N), sort(b, b + N);
    int ans = 0;
    int pr = 0, pb = 0;
    r[N] = b[N] = MP(INF, INF);
    while (pr < N || pb < N) {
        if (r[pr].first < b[pb].first) {
            c[r[pr].second] = 1;
            ++pr;
        }
        else {
            for (int i = b[pb].second - 1; i > -1; i--) {
                if (c[i]) {
                    c[i] = 0;
                    ++ans;
                    break;
                }
            }
            ++pb;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb(x) push_back(x)
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;

const int MX = 1005;
int n;
vi a;

bool valid (vi &a) {
	for (int i = 1; i <= n; i++) {
		int x, y;

		forn (j, 2 * n) {
			if (a[j] == i) x = j;
			if (a[j] == i + n) y = j;
		}

		if (x > y) swap(x, y);
		
		int acu = 0;
		for (int k = x; k <= y; k++)
			acu ^= a[k] > n ? a[k] - n : a[k];
		
		if (acu != i)
			return 0;
	}

	return 1;
}

int main () {
	ios_base::sync_with_stdio(0); cin.tie(0);
	
	cin >> n;

	if (__builtin_popcount(n) == 1) {
		cout << "No" << endl;
		return 0;
	}

	cout << "Yes" << endl;

	int x = 0;
	for (int i = 0; x + (1 << i) <= n; i++)
		x += 1 << i;

	for (int i = 1; i < x; i++)
		cout << i << " " << i + 1 << endl;

	cout << x << " " << n + 1 << endl;
	
	for (int i = 1; i < x; i++)
		cout << n + i << " " << n + i + 1 << endl;

	for (int i = x + 1; i + 1 <= n; i += 2) {
		cout << i << " " << i + 1 << endl;
		cout << i + 1 << " " << 1 << endl;
		cout << 1 << " " << n + i << endl;
		cout << n + i << " " << n + i + 1 << endl;
	}

	if (n % 2 == 0) {
		int mx = 0, acu = 0;

		for (int i = 1;; i++) {
			acu ^= i;
			if (__builtin_popcount(i) != 1) continue;
			if (n & i) {
				mx = i;
				break;
			}
		}

		int y = n ^ acu;
		if (y % 2)
			cout << n << " " << y << endl;
		else
			cout << n << " " << n + y << endl;
		cout << mx << " " << 2 * n << endl;
	}

	return 0;
	a.resize(2 * n);
	iota(all(a), 1);

	do {
		if (valid(a)) {
			for (int x : a) cout << x << " ";
			cout << endl;
		}
	} while (next_permutation(all(a)));

	return 0;
}


Measured memory_bytes: 2688
/**
 *    author:  math2do
 *    created: 20.04.2020 15:10:00 IST
**/

#include <bits/stdc++.h>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector <int> arr(n - 1);
  for (int &v : arr) {
    cin >> v;
  } 
  vector <int> ans(n + 1, 0);
  for (int v : arr) {
    ans[v]++;
  } 
  for (int i = 1; i <= n; i++) {
    cout << ans[i] << '\n';
  } 
  return 0;
}


Measured memory_bytes: 4788