akhauriyash/Code-Regression huggingface dataset:
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    N, M = MI()
    ab = [None] * M

    for i in range(M):
        a, b = MI()
        ab[i] = (a, b)

    ab = sorted(ab, key=lambda x: x[1])
    # print(ab)
    bridge = [(ab[0][1]-1, ab[0][1])]

    for i in range(1, len(ab)):
        # print(ab[i], bridge[-1])
        if ab[i][0] <= bridge[-1][0] and ab[i][1] >= bridge[-1][1]:
            pass
        else:
            bridge.append((ab[i][1]-1, ab[i][1]))

    print(len(bridge))


if __name__ == '__main__':
    main()


Measured memory_bytes: 74712
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define PI acos(-1)
#define Mod (int)1000000007
#define INFTY (int)INT_MAX
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define All(vec) vec.begin(), vec.end()
#define Part(vec, b, e) vec.begin() + b, vec.begin() + e
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Count(vec, x) count(vec.begin(), vec.end(), x)
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define Find(S, s) S.find(s) != string::npos

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	Rep(i, n) cin >> A[i];
	A.erase(unique(All(A)), A.end());
	Rep(i, A.size()) {
		if (i) cout << " ";
		cout << A[i];
	}
	cout << endl;
	return 0;
}


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

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

int main() {
    int A, B;
    cin >> A >> B;

    bool one = false;
    if ((A == 1) || (B == 1)) {
       one = true;
    }

    if (one) {
        if (A == 1 && B == 1) {
            cout << "Draw" << endl;
        } else if (A == 1) {
            cout << "Alice" << endl;
        } else {
            cout << "Bob" << endl;
        }
    }

    if (!one) {
        if (A > B) {
            cout << "Alice" << endl;
        } else if (A < B) {
            cout << "Bob" << endl;
        } else {
            cout << "Draw" << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3600
// #pragma GCC target("avx2")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
using namespace std;
const long long mod=998244353;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-10;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3121000;
long long fact[C_SIZE];
long long finv[C_SIZE];
long long inv[C_SIZE];
long long Comb(int a,int b){
 	if(a<b||b<0)return 0;
 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
}
void init_C(int n){
	fact[0]=finv[0]=inv[1]=1;
	for(int i=2;i<n;i++){
		inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
	}
	for(int i=1;i<n;i++){
		fact[i]=fact[i-1]*i%mod;
		finv[i]=finv[i-1]*inv[i]%mod;
	}
}
long long pw(long long a,long long b){
	if(a<0LL)return 0;
	if(b<0LL)return 0;
	long long ret=1;
	while(b){
		if(b%2)ret=ret*a%mod;
		a=a*a%mod;
		b/=2;
	}
	return ret;
}
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
double ABS(double a){return max(a,-a);}
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
// ここから編集しろ

struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}

int X[210];
int Y[210];
Pt p[210];
int main(){
	int a;scanf("%d",&a);
	for(int i=0;i<a;i++)scanf("%d%d",X+i,Y+i);
	for(int i=0;i<a;i++)p[i]=Pt(X[i],Y[i]);
	long long ret=(pw(2,a)-1-a+mod)%mod;
	for(int i=0;i<a;i++){
		for(int j=i+1;j<a;j++){
			int has=0;
			for(int k=0;k<a;k++){
				if(k==j||k==i){has++;}
				else if(ABS(iSP(p[i],p[j],p[k]))==2||ABS(iSP(p[i],p[k],p[j]))==2){has++;}
			}
			long long tmp=pw(2,has)-1-has;
	//		printf("%d\n",has);
			ret=(ret+mod-tmp*pw(has*(has-1)/2,mod-2)%mod)%mod;
		}
	}
	printf("%lld\n",ret);
}

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

#define ll long long

#define fr(i,a,b) for (ll i = (a), _b = (b); i <= _b; i++)
#define frr(i,a,b) for (ll i = (a), _b = (b); i >= _b; i--)
#define rep(i,n) for (ll i = 0, _n = (n); i < _n; i++)
#define repr(i,n) for (ll i = n - 1; i >= 0; i--)
#define fill(ar,val) memset(ar, val, sizeof(ar))
#define fill0(ar) fill((ar), 0)
#define debug(x) cout<<#x<<": "<<x<<endl

#define ld double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second

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

#define INF 1000000000000000000

ll n,ww;
ll w[101];
ll v[101];
ll dp[101][100001];

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

    cin >> n >> ww;

    fr(i,1,100)
    {
        cin >> w[i] >> v[i];
    }

    dp[0][0] = 0;
    fill0(dp);

    fr(j,0,ww)
    {
        fr(i,1,n)
        {
            ll x = 0;
            if(w[i]<=j)
            {
                x = dp[i-1][j-w[i]];
                dp[i][j] = x+v[i];
            }
            ll y = dp[i-1][j];
            dp[i][j] = max(dp[i][j], y);
        }
    }

    cout << dp[n][ww] << endl;
}

Measured memory_bytes: 79232
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template <size_t I, class H, class... T> struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template <class H, class... T> struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template <class... T> istream& operator>>(istream&i,tuple<T...>& t) { t = TupleReaderWriter<sizeof...(T), T...>::r(i); return i; }
template <class... T> ostream& operator<<(ostream& o, tuple<T...>& t) { string delim = " "; TupleReaderWriter<sizeof...(T) - 1, T...>::w(o, t, delim); return o; }
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    int N, T;
    cin >> N >> T;
    vector<pair<int, int>> X(N);
    for(auto &x : X) {
        cin >> x.first >> x.second;
        x.second *= -1;
    }
    sort(WHOLE(X));
    for(auto &x : X) x.second *= -1;

    vector<int> dp(10000, 0);
    for(int i = 0; i < N; i++) {
        for(int t = T - 1; t >= 0; t--) {
            dp[t + X[i].first] = max(dp[t + X[i].first], dp[t] + X[i].second);
        }
    }
    cout << *max_element(WHOLE(dp)) << endl;
    return 0;
}

Measured memory_bytes: 256
def i1():
 return int(input())
def i2():
 return [int(i) for i in input().split()]
#pakuri
[n,k]=i2()
 
if k>(n-1)*(n-2)/2:
 print(-1)
else:
 c=(n-1)*(n-2)//2-k
 print(n-1+c)
 for i in range(n-1):
  print(1,i+2)
 
 for i in range(2,n+1):
  if c<=0:
     break
  for j in range(2,n+1):
    if i<j and c>0:
      print(i,j)
      c-=1
    if c<=0:
       break

Measured memory_bytes: 42988
#include <iostream>
#include <map>
#include <string>
using namespace std;
int main(void){
    // Here your code !
    map<char,int> ascii;
    string str;
    cin >> str;
    for(int i = 0; i < str.length(); i++)
        ascii[str[i]]++;
    
    bool flag = true;
    for(auto itr = ascii.begin() ; ascii.end() != itr; itr++)
        if((*itr).second % 2 == 1) flag = false;
    
    
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
    
}


Measured memory_bytes: 256
cnt = 0
def merge(A,left,mid,right):
    global cnt
    n1 = mid - left
    n2 = right - mid

    L = [A[i] for i in range(left, mid)]
    R = [A[i] for i in range(mid, right)]
    L.append(float("inf"))
    R.append(float("inf"))
    i = 0
    j = 0
    for k in range(left, right):
        if L[i] <= R[j]:
            A[k] = L[i]
            i += 1
        else:
            cnt += n1 - i
            A[k] = R[j]
            j += 1

def mergeSort(A,left,right):
        if left + 1 < right:
            mid = (left+right) // 2
            mergeSort(A,left,mid)
            mergeSort(A,mid,right)
            merge(A,left,mid,right)

input()
a = list(map(int, input().split()))
mergeSort(a, 0, len(a))
print(cnt)



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

using namespace std;

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

	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for(int i = 0; i < n; i++)
	{
		int cnt = 0;
		bool use[26] = {false};
		for(int j = 0; j < i; j++)use[s[j] - 'a'] = true;
		for(int j = i; j < n; j++)
		{
			if(use[s[j] - 'a'])
			{
				use[s[j] - 'a'] = false;
				cnt++;
			}
		}
		ans = max(ans, cnt);
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  while(1){
    int m, f, r;
    scanf("%d%d%d", &m, &f, &r);
    if(m == -1 && f == -1 && r == -1) break;
    else if(m == -1 || f == -1) printf("F\n");
    else if(m + f >= 80) printf("A\n");
    else if(m + f >= 65) printf("B\n");
    else if(m + f >= 50 || (m + f >= 30 && r >= 50)) printf("C\n");
    else if(m + f >= 30) printf("D\n");
    else printf("F\n");
  }
}



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

int main(void){
    /*
    Al + Ar = r-l
    Al + l = r - Ar
    b[i] = Ai + i;
    cnt[i - A[i]]++;
    */
    int n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    map<ll, ll> cnt;
    rep(i,n) {
        cin >> a[i];
        b[i] = a[i] + i;
        c[i] = i - a[i];
        cnt[c[i]]++;
    }
    ll res = 0;
    rep(i,n){
        res += cnt[b[i]];
        if (b[i] == c[i]) res--;
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 30584
#include<bits/stdc++.h>
#include<boost/variant.hpp>
using namespace std;
typedef long long ll;
typedef vector<boost::variant<bool, ll, int, string, double, char*, const char*>> any;
template<typename T> inline void pr(const vector<T> &xs){
	for(int i=0; i<xs.size()-1; i++) cout<<xs[i]<<" ";
	(xs.empty()?cout:(cout<<xs[xs.size()-1]))<<endl;
}
#ifdef DEBUG
#define debug(...) pr(any{__VA_ARGS__})
#define debugv(x) pr((x))
#else
#define debug(...)
#define debugv(x)
#endif

struct rational {
	ll d, n;
	rational(ll denominator=0, ll nominator=1): d(denominator), n(nominator) {}
	bool operator< (const rational &o) const { return d*o.n<o.d*n; }
	bool operator== (const rational &o) const { return d*o.n==o.d*n; }
	double operator()() const { return (double)d/n; }
};

int main(){
	int N, A, B;
	cin >> N >> A >> B;
	vector<ll> V(N);
	for(int i=0; i<N; i++) cin >> V[i];

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

	ll sum = 0;
	vector<ll> cnt(N+1);
	vector<rational> mmax(N+1);
	for(int i=0; i<N; i++){
		sum += V[N-i-1];
		int m = i+1;

		if(m<A||B<m) continue;
		auto ub = upper_bound(V.begin(), V.end(), V[N-i-1]);
		auto lb = lower_bound(V.begin(), V.end(), V[N-i-1]);
		int n = ub-lb;
		int k = m - (V.end()-ub);
		k = min(k, n-k);
		ll count = 1;
		for(int j=0; j<k; j++){
			count *= n-j;
			count /= j+1;
		}
		mmax[m] = rational(sum, m);
		cnt[m] = count;
		debug(m, n, k, mmax[m](), cnt[m]);
	}


	rational mans = mmax[A];
	ll cans = cnt[A];
	for(int m=A+1; m<=B; m++){
		if(mans < mmax[m]){
			mans = mmax[m];
			cans = cnt[m];
		} else if(mmax[m] == mans){
			cans += cnt[m];
		}
	}
	cout << setprecision(20) << mans() << endl;
	cout << cans << endl;

	return 0;
}


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

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
int inf=1000000007;
char map[30][30];
struct Point{
    int x;
    int y;
    vector<Point> next;
    void get_next(){
        int px=x+1;int py=y;
        if(map[py][px]=='.'){
            Point buf;
            buf.x=px;
            buf.y=py;
            next.push_back(buf);
        }
        px--;py++;
        if(map[py][px]=='.'){
            Point buf;
            buf.x=px;
            buf.y=py;
            next.push_back(buf);
        }
        py--;px--;
        if(map[py][px]=='.'){
            Point buf;
            buf.x=px;
            buf.y=py;
            next.push_back(buf);
        }
        px++;py--;
        if(map[py][px]=='.'){
            Point buf;
            buf.x=px;
            buf.y=py;
            next.push_back(buf);
        }
     }
};

signed main(){
  int h,w;cin>>h>>w;
  rep(i,30){
      rep(j,30){
          map[i][j]='#';
      }
  }
  vector<string> a(h);
  queue<Point> start;
  int max=0;
  rep(i,h)cin>>a[i];
  rep1(i,h){
      rep1(j,w){
          map[i][j]=a[i-1][j-1];
          if(a[i-1][j-1]=='.'){
              Point buf;
              buf.x=j;
              buf.y=i;
              start.push(buf);
          }
      }
  }
  while(!start.empty()){
      vector<vector<int>> memo(30,vector<int> (30,inf));
      int buf_max=0;
      queue<Point> q;
      Point buf=start.front();
      memo[buf.y][buf.x]=0;
      start.pop();
      q.push(buf);
      while(!q.empty()){
          Point p=q.front();
          q.pop();
          p.get_next();
          int num=p.next.size();
          for(int i=0;i<num;i++){
              //if(memo[p.next[i].y][p.next[i].x]==inf)
              if(memo[p.next[i].y][p.next[i].x]>memo[p.y][p.x]+1){
                  memo[p.next[i].y][p.next[i].x]=memo[p.y][p.x]+1;
                  q.push(p.next[i]);
              }
          }
        }
        rep1(i,h){
            rep1(j,h){
                if(memo[i][j]!=inf&&memo[i][j]>buf_max){
                    buf_max=memo[i][j];
                }
            }
        }
        if(max<buf_max)max=buf_max;
  }
cout<<max<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF 1000000007
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int col[100005];

struct diameter{
	static const int MAX=200000;
	vector<int> G[MAX];
	int n;
	int d[MAX];
	bool vis[MAX];
	int d2[2][MAX];

	void bfs(int s){
		fill(d,d+n,INF);
		priority_queue<P,vector<P>,greater<P> > que;
		d[s]=0;
		int co=col[s]+G[s].size();
		que.push(P(d[s],s));
		int v;
		while(que.size()){
			P p=que.top();
			que.pop();
			if(p.first>d[p.second])continue;
			for(int i=0;i<G[p.second].size();i++){
				int e=G[p.second][i];
				int co=col[e]+G[e].size();
				int cos=0;
				if(co%2==0)cos+=2;
				if(d[e]>d[p.second]+cos){
					d[e]=d[p.second]+cos;
					que.push(P(d[e],e));
				}
			}
		}
	}

	int diameter_points(int s=0){
		bfs(s);
		int maxv=-1145140;
		int tgt=0;
		for(int i=0;i<n;i++){
			if(d[i]==INF)continue;
			if(G[i].size()!=1)continue;
			int co=col[i]+G[i].size();
			if(maxv<d[i]){
				maxv=d[i];
				tgt=i;
			}
		}
		bfs(tgt);
		maxv=-1145140;
		int v=0;
		for(int i=0;i<n;i++){
			if(d[i]==INF)continue;
			if(G[i].size()!=1)continue;
			//printf("%d->%d %d\n",tgt,i,d[i]);
			int co=col[i]+G[i].size();
			if(maxv<d[i]){
				maxv=d[i];
				v=i;
			}
		}
		return maxv;
	}
};

int n;
vector<int> iG[100005];
string str;

bool flag[100005];
vector<int> G[100005];
int cnt[100005];
int ans=0;
diameter dia;

void dfs(int v,int p){
	//printf("%d\n",v);
	int co=col[v]+G[v].size();
	if(co%2==0){
		ans++;
	}
	for(int i=0;i<G[v].size();i++){
		if(G[v][i]!=p){
			dfs(G[v][i],v);
			ans+=2;
		}
	}
}

void solve(int s){
	dfs(s,-1);
	if(ans<=1){
		printf("%d\n",1);
		return;
	}
	dia.n=n;
	printf("%d\n",ans-dia.diameter_points(s));
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n-1;i++){
		int a,b;
		scanf("%d%d",&a,&b);
		a--;
		b--;
		iG[a].push_back(b);
		iG[b].push_back(a);
	}
	cin >> str;
	for(int i=0;i<n;i++){
		if(str[i]=='W'){
			col[i]=0;
		}else{
			col[i]=1;
		}
	}
	queue<int> que;
	for(int i=0;i<n;i++){
		cnt[i]=iG[i].size();
		if(iG[i].size()<=1){
			que.push(i);
		}
	}
	while(que.size()){
		int v=que.front();
		que.pop();
		if(col[v]==1){
			flag[v]=true;
			for(int j=0;j<iG[v].size();j++){
				cnt[iG[v][j]]--;
				if(cnt[iG[v][j]]==1){
					que.push(iG[v][j]);
				}
			}
		}
	}
	for(int i=0;i<n;i++){
		for(int j=0;j<iG[i].size();j++){
			if(!flag[iG[i][j]]){
				G[i].push_back(iG[i][j]);
				dia.G[i].push_back(iG[i][j]);
			}
		}
	}
	for(int i=0;i<n;i++){
		if(!flag[i] && cnt[i]<=1){
			solve(i);
			return 0;
		}
	}
	printf("%d\n",0);
	return 0;
}

Measured memory_bytes: 27136
#include <bits/stdc++.h>
#define REP(i,n) for(int64_t i=0;i<(n);i++)
#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REV(c) reverse((c).begin(),(c).end())
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define Yes cout << "Yes" << endl;
#define No cout << "No" << endl;
#define COUTDOUBLE(d,i) cout << setprecision((i)) << (d) << endl;
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}
#define MREP(i,m) for(auto i=(m).begin(); i != (m).end(); ++i) // auto key = i->first;auto value = i->second;

using namespace std;
typedef int64_t I;
typedef pair<I,I> P;
typedef vector<I> V;

I MOD = pow(10,9)+7;
I MAX = LONG_MAX;
I MIN = LONG_MIN;

// 最大公約数
I gcd(I a, I b) {
  return b != 0 ? gcd(b, a % b) : a;
}

// 最小公倍数
I lcm(I a, I b) {
  return a * b / gcd(a, b);
}

int ctoi(char c){
  return c - '0';
}

int main(){
  I n,k;
  cin >> n >> k;
  V v(n);
  VIN(v);
  I t=0;
  REP(i,min(n,k)+1){
    I iL,iR,b;
    b = k - i;
    REP(j,i+1){
      V tmp;
      iL = j;
      iR = i - j;
      REP(l,iL){
        tmp.push_back(v.at(l));
      }
      REP(l,iR){
        tmp.push_back(v.at(n-1-l));
      }
      SORT(tmp);
      I c=0;
      while (c < b && tmp.size() > 0){
        if (tmp.at(0) < 0){
          tmp.erase(tmp.begin()+0);
          c++;
        }else{
          break;
        }
      }
      I an = 0;
      REP(l,tmp.size()){
        an += tmp.at(l);
      }
      t = max(t,an);
    }
  }
  cout << t << endl;
  return 0;
}



Measured memory_bytes: 256
H, W = map(int, input().split())
c = [list(map(int, input().split())) for _ in range(10)]
grid = [list(map(int, input().split())) for _ in range(H)]

def warshall_floyd(d):
    #d[i][j]: iからjへの最短距離
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j],d[i][k] + d[k][j])
    return d

##############################
n = 10
d = [[float("inf")]*n for i in range(n)] 
#d[u][v] : 辺uvのコスト(存在しないときはinf)
for x in range(n):
    for y in range(n):
        d[x][y] = c[x][y]
        d[y][x] = c[y][x]
for i in range(n):
    d[i][i] = 0 #自身のところに行くコストは０
cost = warshall_floyd(d)
ans = 0
for h in range(H):
    for w in range(W):
        if grid[h][w] != -1:
            ans += cost[grid[h][w]][1]
print(ans)

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

int main() {
  string s;
  cin >> s;
  
  if(s == "Sunny"){
    cout << "Cloudy" << endl;
  }
  
  else if(s == "Cloudy"){
    cout << "Rainy" << endl;
  }
  
  else{
    cout << "Sunny" << endl;
  }
}

Measured memory_bytes: 256
import sys

a1 = list(map(int, input().split()))
a2 = list(map(int, input().split()))
a3 = list(map(int, input().split()))
n = int(input())
b = [int(input()) for i in range(n)]

a1.extend(a2)
a1.extend(a3)
result = []

for target_list in b:
    try:
        result.append(a1.index(target_list)+1)
    except:
        continue        

ans = [[1, 2, 3], [4, 5, 6], [7, 8, 9], [1, 4, 7],[2, 5, 8], [3, 6, 9], [1, 5, 9], [3, 5, 7]]


for target_list in ans:
    tmp = set(target_list) & set(result)
    if len(tmp)>=3:
        print("Yes")
        sys.exit()

print("No")    


Measured memory_bytes: 3064
n,m,l=map(int,raw_input().split())
A=[]
B=[]
for i in range(n):
    A.append(map(int,raw_input().split()))
for i in range(m):
    B.append(map(int,raw_input().split()))
for i in range(n):
    print(' '.join(map(str,[sum([A[i][j]*B[j][k] for j in range(m)]) for k in range(l)])))

Measured memory_bytes: 6840
A, B, C, D = map(int, input().split())

while A > 0 and C > 0:
    C = C - B
    A = A - D
    #print(C, A)

if A <= 0 and C <= 0:
    ans = 'Yes'
elif C <= 0:
    ans = 'Yes'
else:
    ans = 'No'
print(ans)


Measured memory_bytes: 9172
n,m = map(int,input().split())

if n % 2 == 0:
    if n % 4 == 0:
        flag = True
        for i in range(m):
            if i == n//4:
                flag = False
            if flag == True:
                print(i+1,n-i)
            else:
                print(i+1,n-i-1)
    else:
        flag = True
        for i in range(m):
            if n-i - (i+1) == n//2:
                flag = False
            if flag == True:
                print(i+1,n-i)
            else:
                print(i+1,n-i-1)
else:
    for i in range(m):
        print(i+1,n-i)

Measured memory_bytes: 9276
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>

#define lpsbd(i, s, b, d) for(size_t i = (s); i < (b); i+=(d))
#define lpsb(i, s, b) for(size_t i = (s); i < (b); i++)
#define lpn(i, n) for(size_t i = 0; i < (n); i++)
#define fa(i, x) for(auto &i: x)
#define vcd(t, n, d) vector<t>(n, d)
#define vc(t, n) vector<t>(n)
#define all(x) (x).begin(), (x).end()

using namespace std;
using ll = long long;

const ll MOD = 1000000007;

int main(void)
{
    int N;
    cin >> N;
    int ans;
    for (int i =1; i <= N; i++)
    {
        if (i < 10 || (100 <= i && i < 1000) || (10000 <= i && i < 100000)) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
  
using namespace std;
  
template<class T> void ckmin(T &a, T b) { a = min(a, b); }
template<class T> void ckmax(T &a, T b) { a = max(a, b); }
  
#define pb push_back
#define mp make_pair
#define cotu cout
#define itn int
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
  
#define ordered_set tree<int , null_type,less<int >, rb_tree_tag,tree_order_statistics_node_update> 
  
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
  
const int inf = int(1e9);
const int mod = inf + 7;
const int N = 1e6 + 555; // TL MB
const double PI = acos(-1.0);
 
void mul(ll &x, ll y){
	x *= y;
	if(x >= mod) x %= mod;
}
 
void add(ll &x, ll y){
	x += y;
	if(x >= mod) x -= mod;
	if(x < 0) x += mod;
}
ll bp(ll a, ll n){
	ll r = 1;
	while(n){
		if(n & 1) mul(r, a);
		mul(a, a);
		n >>= 1;
	}
	return r;
}

void solve(){
	string s;
	cin >> s;
	string t = "";
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'B') {
			if(!t.empty()) t.pop_back();
		}
		else{
			t += s[i];
		}
	}
	
	cout << t;
}


 
 
int main()
{
    Red;
  	// int T; cin >> T; while(T--)
    solve();
    return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll h,w;

int main(){
	cin.sync_with_stdio(false);
  cin>>h>>w;
  if(h%3==0||w%3==0){
    cout<<0<<endl;
    return 0;
  }
  ll res=INF;
  rep(i,h+1){
    ll a=w*i,b=((w+1)/2)*(h-i),c=(w/2)*(h-i);
    minch(res,max(a,max(b,c))-min(a,min(b,c)));

    a=w*i,b=w*((h-i+1)/2),c=w*((h-i)/2);
    minch(res,max(a,max(b,c))-min(a,min(b,c)));
  }
  rep(i,w+1){
    ll a=h*i,b=((h+1)/2)*(w-i),c=(h/2)*(w-i);
    minch(res,max(a,max(b,c))-min(a,min(b,c)));

    a=h*i,b=h*((w-i+1)/2),c=h*((w-i)/2);
    minch(res,max(a,max(b,c))-min(a,min(b,c)));
  }

  cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python

import random

class Dice:
    def __init__(self, top, s, e, w, n, bottom):
        self.top    = top
        self.s      = s
        self.e      = e
        self.w      = w
        self.n      = n
        self.bottom = bottom

    def rotate(self, dist):
        if dist == 'N':
            self.top, self.s, self.n, self.bottom = self.s, self.bottom, self.top, self.n 
        elif dist == 'S':
            self.s, self.bottom, self.top, self.n = self.top, self.s, self.n, self.bottom 
        elif dist == 'E':
            self.top, self.e, self.w, self.bottom = self.w, self.top, self.bottom, self.e 
        elif dist == 'W':
            self.w, self.top, self.bottom, self.e = self.top, self.e, self.w, self.bottom 

if __name__ == '__main__':
    dice1 = Dice(*map(int, raw_input().split()))
    dice2 = Dice(*map(int, raw_input().split()))

    ref1 = set()
    ref2 = set()
    for _ in range(1000):
        if len(ref1) > 23:
            break

        ref1.add((dice1.top, dice1.s, dice1.e))
        ref2.add((dice2.top, dice2.s, dice2.e))

        dist = 'NSEW'[random.randint(0,3)]
        dice1.rotate(dist)
        dice2.rotate(dist)

    print 'Yes' if ref1==ref2 else 'No'



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

int main() {
    ll N, M, H[100010], tmp[100010]; 
    
    cin >> N >> M;
    for (int i = 1; i <= N; i++) {
        cin >> H[i];
        tmp[i] = 0;
    }

    for (int i = 0; i < M; i++) {
        ll A, B; cin >> A >> B; 
        tmp[A] = max(tmp[A], H[B]);
        tmp[B] = max(tmp[B], H[A]);
    }

    ll ans = 0;
    for (int i = 1; i <= N; i++) {
        if (H[i] > tmp[i]) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5156
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
ABC = list(map(int,input().split()))

d = max(ABC)*3 - sum(ABC)

if d%2==0:
    print(d//2)
else:
    print((d+3)//2)

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

using ull = unsigned long long;
class Way;
class Tower
{
public:
	Tower(ull height) :
		height(height)
	{}
	vector<Tower*> next;
	ull height;

	static void MakeNext(Tower*t1, Tower* t2)
	{
		t1->next.emplace_back(t2);
		t2->next.emplace_back(t1);
	}

	bool IsGreat()
	{
		
		for (auto& t : next)
		{
			if (t->height >= height)
			{
				return false;

			}
		}
		return true;
	}

};
int main()
{
	ull towers_cnt, ways_cnt;
	cin >> towers_cnt >> ways_cnt;

	vector<Tower*> towers;
	towers.resize(towers_cnt);

	for (ull i = 0; i < towers_cnt; i++)
	{
		ull height;
		cin >> height;
		towers[i] = new Tower(height);
	}

	for (ull i = 0; i < ways_cnt; i++)
	{
		ull t1, t2;
		cin >> t1 >> t2;
		Tower::MakeNext(towers[t1 - 1], towers[t2 - 1]);
	}

	ull cnt = 0;
	for (ull i = 0; i < towers_cnt; i++)
	{
		if (towers[i]->IsGreat())
			cnt++;
	}

	cout << cnt;
	
	for (ull i = 0; i < towers_cnt; i++)
	{
		delete towers[i];
	}
	return 0;
}

Measured memory_bytes: 12224
N = int(input())
b = list(map(int,input().split()))
for i in range(1,N):b[i] = b[i] + b[i-1]

cost = sub = 0
if b[0] > 0:pass
elif b[0] == 0:cost,sub = 1,1
else:cost,sub = 1 - b[0], 1-b[0]

for i in range(1,N):
    if i % 2 == 0:
        if b[i] + sub <= 0:
            newsub = -1 * (b[i] + sub) + 1
            cost += abs(newsub)
            sub += newsub
    else:
        if b[i] + sub >= 0:
            newsub = -1 * (b[i] + sub + 1)
            cost += abs(newsub)
            sub += newsub

cost2 = sub2 = 0
if b[0] < 0:pass
elif b[0] == 0:cost2,sub2 = 1,-1
else:cost2,sub2 = 1 + b[0], -1 *(1+b[0])

for i in range(1,N):
    if i % 2 == 1:
        if b[i] + sub2 <= 0:
            newsub2 = -1 * (b[i] + sub2) + 1
            cost2 += abs(newsub2)
            sub2 += newsub2
    else:
        if b[i] + sub2 >= 0:
            newsub2 = -1 * (b[i] + sub2 + 1)
            cost2 += abs(newsub2)
            sub2 += newsub2

print(min(cost,cost2))

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

#define REP(i, n) for(int64_t i = 0; i < n; i++)
#define REPR(i, n) for(int64_t i = n; i >= 0; i--)
#define FOR(i, m, n) for(int64_t i = m; i < n; i++)
#define FORR(i, m, n) for(int64_t i = m; i >= n; i--)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}
template<class T>
inline bool chmax(T &a, T b) {if(a < b) {a = b;return true;}return false;}
template<class T>
inline bool chmin(T &a, T b) {if(a > b) {a = b;return true;}return false;}
const ll INF= 1ll << 60;
const ll MOD = 1000000007;
double EPS = 1e-10;
//----------------------------------------------------------

ll n, a, b;

//累乗のmod
ll modpow(ll a, ll n) {
    int64_t res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return res;
}

int main(){
    cin >> n >> a >> b;
    ll t = modpow(2,n); //全組み合わせの合計
    t--; //nC0を引く
    ll fn=1;
    ll fab=1;
    //フェルマーの小定理を用いてnCaとnCbを計算する
    FOR(i,1,((a>b)?a+1:b+1))
    {
        fn=fn*(n-(i-1))%MOD;
        fab=fab*modpow(i,MOD-2)%MOD;
        if(a>b)
        {
            if(i==b)
            {
                t =(t - fn*fab%MOD)%MOD;
                if(t<0)t+=MOD;
            }
        }
        else
        {
            if(i==a)
            {
                t =(t - fn*fab%MOD)%MOD;
                if(t<0)t+=MOD;
            }
        }
    }
    t=(t-fn*fab%MOD)%MOD;
    if(t<0)t+=MOD;
    cout << t << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter

N = int(input())
a = list(input().split())
seq = [int(a[i]) for i in range(N)]
Cons = Counter(seq)

num = list(Cons.items())
count = 0

for i in range(len(num)):
    dif = int(num[i][1]) - int(num[i][0])
    count += (dif if dif >= 0 else int(num[i][1]))

print(count)

Measured memory_bytes: 28140
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll arr[n+5];
    ll arr1[n+5];

    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
        arr1[i]=arr[i];
    }
    sort(arr1,arr1+n);

    ll cnt=0;
    for(int i=0;i<n;i++)
    {
        if(arr[i]!=arr1[i])
            cnt++;
    }
   

    if(cnt<=2)
        cout<<"YES"<<endl;
    else
        cout<<"NO"<<endl;
        return 0;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <stdio.h>
using namespace std;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second
typedef long long ll;
typedef vector< ll > vi;
typedef vector<pair<ll,ll> > vpii;
#define all(c) c.begin(),c.end()
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define INF 1000000007
#define N 100005
#define PI 3.14159265
bool compare(pair<ll,ll> i, pair<ll,ll> j) 
{
  return i.S < j.S;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b); 
}
int main()
{
	ll n,a;
	cin>>n;
	vi v;
	rep(i,0,n)
	{
		cin>>a;
		v.pb(a);
	}
	vi v2;
	v2.pb(0);
	v2.pb(abs(v[0]-v[1]));
	rep(i,2,n)
	{
		v2.pb(min(v2[i-2]+abs(v[i-2]-v[i]),v2[i-1]+abs(v[i-1]-v[i])));
	}
	cout<<v2[n-1];
	return 0;
}

Measured memory_bytes: 2548
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str  = sc.nextLine();
        String[] astr = str.split(" "); //状況に合わせて
        Boolean flag  = true;
        int[] in_data = Stream.of(astr).mapToInt(x->{
            try{
                return Integer.parseInt(x);
            }
            catch(Exception e){
                e.printStackTrace();
            }
            return 0;
        }).toArray();
        sc.close();
        int a = in_data[0];
        int p = in_data[1];

        int tmp = a * 3 + p;
        System.out.println(tmp/2);
    }
}

Measured memory_bytes: 28756
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<queue>
#include<cmath>
#include<cstdio>
#include<tuple>
#include<bitset>
#include<map>

using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
typedef pair<int,int> P;
const int inf=100000000000000007;
const int MOD=998244353;

signed main(){
  int n,s;cin>>n>>s;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  vector<vector<int>> dp(n+1,vector<int>(s+1,0));
  dp[0][0]=1;
  rep1(i,n){
    rep(j,s+1){
      dp[i][j]=dp[i-1][j]*2;
      dp[i][j]%=MOD;
      if(j>=a[i-1]){
        dp[i][j]+=dp[i-1][j-a[i-1]];
        dp[i][j]%=MOD;
      }
    }
  }
  cout<<dp[n][s]<<"\n";
  return 0;
}


Measured memory_bytes: 73708
#pragma GCC compiler("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N,K;
ll tot=1;
ll mod=1e9+7;
vector<int> v[100010];
bool vis[100010];
int figli[100010];
int parent[100010];
void dfs(int pos){
  for(int i=0;i<v[pos].size();i++){
    if(v[pos][i]==parent[pos])continue;
    parent[v[pos][i]]=pos;
    dfs(v[pos][i]);
  }
}
int main(){
  //freopen("input.txt","r",stdin);
  //freopen("output.txt","w",stdout);
  ios_base::sync_with_stdio(0);
  cin>>N>>K;
  for(int i=0;i<N-1;i++){
    int a,b;
    cin>>a>>b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  parent[1]=-1;
  dfs(1);
  queue<int>q;
  q.push(1);
  while(!q.empty()){
    int pos=q.front();
    q.pop();
    if(vis[pos])continue;
    vis[pos]=1;
    ll per=K;
    if(parent[pos]!=-1){
      per--;
      per-=figli[parent[pos]];
      figli[parent[pos]]++;
      if(parent[parent[pos]]!=-1)per--;
    }
    tot*=per;
    tot%=mod;
    for(int i=0;i<v[pos].size();i++){
      q.push(v[pos][i]);
    }
  }
  cout<<tot<<endl;
  return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<double> a(n);
  double b;
  for(int i=0;i<n;i++){
  	cin >> a[i];
  }
  sort(a.begin(),a.end());
  
  while(a.size()>1){
  	b=(a[0]+a[1])/2;
    a.erase(a.begin(),a.begin()+2);
    a.insert(a.begin(),b);
  }
  cout << a[0];
  
  return 0;
}

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

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Tarek
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ASheepAndWolves solver = new ASheepAndWolves();
        solver.solve(1, in, out);
        out.close();
    }

    static class ASheepAndWolves {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int s = in.nextInt();
            int w = in.nextInt();
            if (w >= s) out.println("unsafe");
            else out.println("safe");
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  for (int i = 0; i < n; ++i)
    cin >> p[i];
  int ans = 0;
  for (int i = 0; i < n - 2; ++i)
    if ((p[i] < p[i + 1] && p[i + 1] < p[i + 2]) ||
        (p[i + 2] < p[i + 1] && p[i + 1] < p[i]))
      ++ans;
  cout << ans << endl;
}

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

using namespace std;

int min(int a, int b)
{
	if (a > b)
		return b;
	else
		return a;
}

int main()
{
	int N;
	cin >> N;
	vector<int> B;
	for (int i = 0; i < N - 1; i++)
	{
		int x;
		cin >> x;
		B.push_back(x);
	}
	int ans = B[0];
	for (int i = 1; i < N - 1; i++)
	{
		ans += min(B[i - 1], B[i]);
	}
	ans += B[N - 2];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
s = raw_input()

St1, St2 = [], []
sumv = 0

for i in range(len(s)):
    if s[i] == '\\':
        St1.append(i)
    elif s[i] == '/' and len(St1) > 0:
        j = St1.pop()
        a = i-j
        sumv += a
        while len(St2) > 0 and St2[-1][0] > j:
            a += St2.pop()[1]

        St2.append([j, a])

St2.insert(0, [0, len(St2)])

print sumv
print ' '.join(map(lambda x: str(x[1]), St2))

Measured memory_bytes: 7160
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i < b; i++)
#define rrep(i, a, b) for(int i = b - 1; i >= a; i--)
typedef long long ll;
typedef pair<int,int> pii;

int main(){
    int N; cin >> N;
    vector<int> A(N);
    vector<vector<pii>> Z(N, vector<pii>());
    rep(i, 0, N){
        cin >> A[i];
        rep(j, 0, A[i]){
            pii tmp; cin >> tmp.first >> tmp.second;
            tmp.first--;
            Z[i].push_back(tmp);
        }
    }
    int ans = 0;

    rep(i, 0, 1 << N){
        int cnt = 0;
        bool flag = 1;
        vector<int> T(N, -1); 
        rep(j, 0, N){
            if(i & (1 << j)) T[j] = 1;
            else T[j] = 0;
        }
        rep(j, 0, N){
            if(i & (1 << j)){
                cnt++;
                for(auto e: Z[j]){
                    if(T[e.first] != e.second){
                        flag = 0;
                        break;
                    }
                }
            }
            if(flag == 0) break;
        }
        if(flag == 0) continue;
        //cout << i << " " << cnt << endl;

        ans = max(ans, cnt);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl

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

    auto cnt = [](int a){
        int res = 0;
        for(int i=1; i<=sqrt(a); i++){
            int tmp = sqrt(a);
            tmp *= sqrt(a);
            //dump(tmp);
            if(tmp == a){
                res++;
                break;
            }
            if(a%i==0) res+=2;
        }

        return res;
    };

    dump(cnt(135));

    int count = 0;
    for(int i=1; i<=n; i++){
        if(i%2==0) continue;
        if(cnt(i)==8) {
            dump(i);
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        int n = sc.NextInt();
        int m = sc.NextInt();
        int x = sc.NextInt();

        int[] c = new int[n];
        int[,] a = new int[n, m];

        for (int i = 0; i < n; i++)
        {
            c[i] = sc.NextInt();
            for (int j = 0; j < m; j++)
            {
                a[i, j] = sc.NextInt();
            }
        }

        int answer = int.MaxValue;

        for (int i = 0; i < Math.Pow(2, n); i++)
        {
            int tmpAnswer = 0;
            int[] tmpA = new int[m];
            for (int j = 0; j < n; j++)
            {
                if ((1 & (i >> j)) == 1)
                {
                    tmpAnswer += c[j];
                    for (int k = 0; k < m; k++)
                    {
                        tmpA[k] += a[j, k];
                    }
                }
            }
            if (tmpA.Where(num => num < x).Count() == 0)
            {
                answer = Math.Min(answer, tmpAnswer);
            }
        }

        if (answer == int.MaxValue)
        {
            Console.WriteLine(-1);
            return;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

Measured memory_bytes: 28976
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int N;
  cin >> N;
  
  if(1 <= (N % 100)&& N % 100 <= 12 && N / 100 >= 1 && N / 100 <= 12){
    cout << "AMBIGUOUS" << endl;
  }else if(1 <= (N % 100) && N % 100 <= 12){
    cout << "YYMM" << endl;
  }else if(N / 100 >= 1 && N / 100 <= 12){
    cout << "MMYY" << endl;
  }else{
    cout << "NA" << endl;
  }
  
 
     
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
#include <stdlib.h>
using namespace std;

int main(void) {
	// your code goes here
	long long int n,i,j,x[1001],y[1001],a[2001],b[1001],d,h[41]={0},one=0,zero=0,max=0;
	cin >> n;
	for(i=1;i<=n;i++) {
		cin >> x[i] >> y[i];
		if(abs(x[i]+y[i])%2==0) zero=1;
		else one=1;
		a[i]=x[i]+y[i];
		b[i]=x[i]-y[i];
	}
	if(zero==one) {
		cout << -1 <<endl;
		return 0;
	}
	if(zero==1){
		printf("34\n");
		for(i=0;i<=30;i++){
			d=pow(2.0,i);
			printf("%lld ",d);
		}
		printf("1 1 1\n");
		for(i=1;i<=n;i++){
			int f[41]={0};
			int g[41]={0};
			if(abs(x[i])%2==0&&abs(y[i])%2==0){
				a[i]=a[i]+2147483647-1;
				j=0;
				while(a[i]>0){
					f[j]=a[i]%2;
					a[i]=(a[i]-a[i]%2)/2;
					j++;
				}
				b[i]=b[i]+2147483647-1;
				j=0;
				while(b[i]>0){
					g[j]=b[i]%2;
					b[i]=(b[i]-b[i]%2)/2;
					j++;
				}
				for(j=1;j<=31;j++){
					if(f[j]==1&&g[j]==1) printf("R");
					if(f[j]==1&&g[j]==0) printf("U");
					if(f[j]==0&&g[j]==1) printf("D");
					if(f[j]==0&&g[j]==0) printf("L");
				}
				printf("RDU\n");
			}
			if(abs(x[i])%2==1&&abs(y[i])%2==1){
				a[i]=a[i]+2147483647-3;
				j=0;
				while(a[i]>0){
					f[j]=a[i]%2;
					a[i]=(a[i]-a[i]%2)/2;
					j++;
				}
				b[i]=b[i]+2147483647-1;
				j=0;
				while(b[i]>0){
					g[j]=b[i]%2;
					b[i]=(b[i]-b[i]%2)/2;
					j++;
				}
				for(j=1;j<=31;j++){
					if(f[j]==1&&g[j]==1) printf("R");
					if(f[j]==1&&g[j]==0) printf("U");
					if(f[j]==0&&g[j]==1) printf("D");
					if(f[j]==0&&g[j]==0) printf("L");
				}
				printf("RRU\n");
			}
		}
	}
	if(one==1){
		printf("33\n");
		for(i=0;i<=30;i++) {
			d=pow(2.0,i);
			printf("%lld ",d);
		}
		printf("1 1\n");
		for(i=1;i<=n;i++){
			int f[41]={0};
			int g[41]={0};
			if(abs(x[i])%2==1&&abs(y[i])%2==0){
				a[i]=a[i]+2147483647-2;
				j=0;
				while(a[i]>0){
					f[j]=a[i]%2;
					a[i]=(a[i]-a[i]%2)/2;
					j++;
				}
				b[i]=b[i]+2147483647-2;
				j=0;
				while(b[i]>0){
					g[j]=b[i]%2;
					b[i]=(b[i]-b[i]%2)/2;
					j++;
				}
				for(j=1;j<=31;j++){
					if(f[j]==1&&g[j]==1) printf("R");
					if(f[j]==1&&g[j]==0) printf("U");
					if(f[j]==0&&g[j]==1) printf("D");
					if(f[j]==0&&g[j]==0) printf("L");
				}
				printf("RR\n");
			}
			if(abs(x[i])%2==0&&abs(y[i])%2==1){
				a[i]=a[i]+2147483647-2;
				j=0;
				while(a[i]>0){
					f[j]=a[i]%2;
					a[i]=(a[i]-a[i]%2)/2;
					j++;
				}
				b[i]=b[i]+2147483647;
				j=0;
				while(b[i]>0){
					g[j]=b[i]%2;
					b[i]=(b[i]-b[i]%2)/2;
					j++;
				}
				for(j=1;j<=31;j++){
					if(f[j]==1&&g[j]==1) printf("R");
					if(f[j]==1&&g[j]==0) printf("U");
					if(f[j]==0&&g[j]==1) printf("D");
					if(f[j]==0&&g[j]==0) printf("L");
				}
				printf("RU\n");
			}
		}
	}
	return 0;
}


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

int main(){
  
  long long N, K, Q; // K 開始点 Q 問題数
  cin >> N >> K >> Q;
  vector<int> ans(Q);
  rep(i,Q) cin >> ans[i];
  
  // まずは実直に
  
  vector<int> players(N);
  rep(i,N){
    players[i] = K - Q;
  }
  
  // 
  rep(i, Q){
    players[ans[i]-1]++;
  }
  
  rep(i,N) {
    if (players[i] > 0) cout << "Yes" << endl;
    else cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 1408