akhauriyash/Code-Regression huggingface dataset:
// #includes {{{
#ifdef MY_DEBUG
#include "header/header.hpp"
#else
#include <bits/stdc++.h>
#endif

using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define RREP(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define LET(x,a) __typeof(a) x(a)
//#define IFOR(i,it,c) for(__typeof((c).begin())it=(c).begin();it!=(c).end();++it,++i)
#define ALL(c) (c).begin(), (c).end()
#define MP make_pair

#define EXIST(e,s) ((s).find(e)!=(s).end())

#define RESET(a) memset((a),0,sizeof(a))
#define SET(a) memset((a),-1,sizeof(a))
#define PB push_back
#define DEC(it,command) __typeof(command) it=command

//debug

#define whole(f,x,...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x)

typedef long long Int;
typedef unsigned long long uInt;
typedef long double rn;

template<class T>
T inf(){
	return numeric_limits<T>::has_infinity?numeric_limits<T>::infinity():(numeric_limits<T>::max()/2);
}

typedef pair<int,int> pii;

#ifdef MY_DEBUG
#include"print.hpp"
#include"debug.hpp"
#endif
// }}}

Int N;
Int g_A;
Int s_A;
Int b_A;
Int g_B;
Int s_B;
Int b_B;

Int calc(const vector<pair<Int,Int> > &v, Int N){
	if(v.size()==0)return N;
	else if(v.size()==1){
		Int q = N/v[0].first, r = N%v[0].first;
		return q * v[0].second + r;
	}else if(v.size()==2){
		Int ans = 0;
		for(Int i = 0;;i++){
			Int N0 = N - v[0].first * i;
			if(N0<0)break;
			Int q = N0/v[1].first, r = N0%v[1].first;
			ans = max(ans, i * v[0].second + q * v[1].second + r);
		}
		return ans;
	}else{
		assert(v.size()==3);
		Int ans = 0;
		for(Int i = 0;;i++){
			Int N0 = N - v[0].first * i;
			if(N0<0)break;
			for(Int j = 0;;j++){
				Int N1 = N0 - v[1].first * j;
				if(N1<0)break;
				Int q = N1/v[2].first, r = N1%v[2].first;
				ans = max(ans, i * v[0].second + j * v[1].second + q * v[2].second + r);
			}
		}
		return ans;
	}
}

void solve(){
	vector<pair<Int,Int> > p,q;
	if(g_A<g_B)p.push_back({g_A,g_B});
	else if(g_A>g_B)q.push_back({g_B,g_A});
	if(s_A<s_B)p.push_back({s_A,s_B});
	else if(s_A>s_B)q.push_back({s_B,s_A});
	if(b_A<b_B)p.push_back({b_A,b_B});
	else if(b_A>b_B)q.push_back({b_B,b_A});
	N = calc(p,N);
	N = calc(q,N);
	cout<<N<<endl;
}

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

	cin >> N;
	cin >> g_A;
	cin >> s_A;
	cin >> b_A;
	cin >> g_B;
	cin >> s_B;
	cin >> b_B;
	solve();
	return 0;
}

//}}}



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

int main(){
	int n;
	cin>>n;
	int ans={};
	int l[n]={};
	for(int i=0; i<n; i++){
		cin>>l[i];
	}
	sort(l,l+n);
	//for(int i=0; i<n; i++){
	//	cout<<l[i]<<" ";
	//}cout<<endl;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			int a=l[i]+l[j];
			//cout<<i<<" "<<j<<endl;
			//cout<<a<<endl;
			int k=distance(l,lower_bound(l,l+n,a))-1;
			//cout<<"K"<<k<<endl;
			ans+=k-j;
			
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3580
n, cap = map(int, input().split())
dp = [None] * (cap + 1)
dp[0] = 0

for _ in range(n):
    v, w = map(int, input().split())
    for k in range(cap - w, -1, -1):
        tmp_before_v = dp[k]
        if tmp_before_v == None:
            continue
        tmp_after_v, new_v = dp[k + w], tmp_before_v + v
        if tmp_after_v == None or tmp_after_v < new_v:
            dp[k + w] = new_v

print(max(filter(None, dp)))

Measured memory_bytes: 7876
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		String T = sc.next();
		sc.close();

		StringBuilder sb = new StringBuilder();
		sb.append(T);
		sb.append(S);
		System.out.println(sb.toString());

	}

}

Measured memory_bytes: 20820
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

    string s; cin >> s;

    ll cntw = 0; ll sum = 0;
    rep(i,s.size()) if(s[i] == 'W') { cntw++; sum += i;}
    ll sum2 = 0;
    
    rep(i,cntw)  sum2 += i;

    cout << sum - sum2 << endl;
}









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

int main() {
    char x, y;
    cin >> x >> y;
    if (x > y) {
        cout << '>' << endl;
    } else if ( x == y ) {
        cout << '=' << endl;
    } else {
        cout << '<' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
fn main() {
    read_line::<i32>();
    println!("{}", read_vec().iter().map(|a| a-1).sum::<i32>());
}
 
fn read_line<T: std::str::FromStr>() -> T {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().ok().unwrap()
}
 
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    buf.trim().split_whitespace().map(|e|
        e.parse().ok().unwrap()
    ).collect()
}


Measured memory_bytes: 4352
n = int(input())
a, b = map(int, input().split())
p = list(map(int, input().split()))
c1, c2, c3 = 0, 0, 0
for i in p:
  if i <= a:
    c1 += 1
  elif i <= b:
    c2 += 1
  else:
    c3 += 1
print(min(c1, c2, c3))

Measured memory_bytes: 3064
n = int(input())
 
ans = [0] * (n+1)
for x in range(1,110):
    for y in range(1,110):
        for z in range(1,110):
            tmp = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if tmp <= n:
                ans[tmp] += 1
 
for i in ans[1:]:
    print(i)

Measured memory_bytes: 69588
#include <bits/stdc++.h>
using namespace std;
#define f(i,a,n) for(i=a;i<n;i++)
#define ll long long int 
int main() {
	ll n,d,b,cnt=0,i,j,k;
     cin>>n>>d;
     ll a[n][d];
     f(i,0,n)
     f(j,0,d)
     cin>>a[i][j];
     
     f(i,0,n)
     {
         f(k,i+1,n)
         {
         ll sm=0;
         f(j,0,d)
         {
             ll dis;
             dis=abs(a[i][j]-a[k][j]);
             dis*=dis;
             sm+=dis;
         }
         ll yy=sqrt(sm);
         if((yy*yy-sm)==0)
         cnt++;
         }
     }
     cout <<cnt<<endl;
     
	return 0;
}

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    string t = s;
    reverse(t.begin(), t.end());
    int a, b;
    rep(i,n) {
        if (s[i] == 'Z') {
            a = i;
        }
        if (t[i] == 'A') {
            b = n - i;
        }
    }
    int ans = a - b + 2;
    cout << ans << endl;
}

Measured memory_bytes: 772
#include "bits/stdc++.h"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long ll;
const string s = "AKIHABARA";
string t;

void solve(){
    int si = 0 , ti = 0;
    while(si < sz(s) || ti < sz(t)){
        if(s[si]==t[ti])si++ , ti++;
        else{
            if(s[si]=='A')
                si++;
            else{
                cout << "NO\n";
                return ;
            }
        }
    }
    cout << "YES\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    solve();
    return 0;
}












Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,ans=0;
    cin>>k;
    for(int i=1;i<=k;i++)
    {

        for(int j=1;j<=k;j++)
        {
            if(i%2!=0&&j%2==0)ans++;
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
s=input()
l=len(s)
c1=0
c2=0
for i in range(l):
  if i%2==0:
    if s[i]!='0':
      c1+=1
    else:
      c2+=1
  else:
    if s[i]!='1':
      c1+=1
    else:
      c2+=1
print(min(c1,c2))

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;

string s;
long long ans = 0;

int main(){
	cin >> s;
	int numA = 0;
	for(int i = 0; i < s.size(); ++i){
		if(s[i] == 'A')
			numA++;
		else if(s[i] == 'B' && s[i+1] == 'C'){
			ans += numA;
			i++;
		}else
			numA = 0;
	}
	printf("%lld\n", ans);
}

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

using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int count=1;
    int summ=a;
    if(b==1){
        cout << 0<<endl;
        exit(0);
    }
    for(int i=1;i<=20;i++){
        if(summ<b){
            summ=summ+a-1;
            count++;
        }
        else{
            break;
        }
    }
    cout << count<<endl;
}
    



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

int main()
{
    char ch1[200001],ch2[200001];
    int count=0,len=0,i;

    scanf("%s",&ch1);
    scanf("%s",&ch2);

    len = strlen(ch1);

    for(i=0 ; i<len ; i++)
    {
        if(ch1[i]!=ch2[i])
        {
            count++;
        }
    }
    printf("%d\n",count);
    return 0;
}


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

int main(void)
{
  char buf[16];
  char outBuf[16];
  int  outIndex = 0;
  scanf("%s", buf);
  
  for (int i = 0; i < strlen(buf); i++) {
    if (buf[i] != 'B') {
      outBuf[outIndex++] = buf[i];
    } else {
      if (0 < outIndex) {
        outBuf[outIndex - 1] = '\0';
        outIndex--;
      }
    }
  }
  outBuf[outIndex++] = '\0';
  printf("%s", outBuf);
  
}

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

int main()
{
    int n,k;
    scanf("%d%d",&n,&k);
    int a[n];
    for(int i=0;i<n;i++) scanf("%d",a+i);
    sort(a,a+n);
    int ans=0;
    for(int i=0;i<k;i++) ans+=a[i];
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long C[] = new long[N];
        long S[] = new long[N];
        long F[] = new long[N];
        long ans = 0;
        for (int i = 0; i < N - 1; i++) {
            C[i] = sc.nextInt();
            S[i] = sc.nextInt();
            F[i] = sc.nextInt();
        }
        for (int i = 0; i < N; i++) {
            ans = 0;
            for (int j = i; j < N - 1; j++) {
                if (ans < S[j]) {
                    ans = S[j] + C[j];
                } else if (ans% F[j] == 0) {
                    ans = ans + C[j];
                } else {
                    ans = ans + F[j] - ans % F[j] + C[j];
                }
            }
            System.out.println(ans);
        }
    }
}


Measured memory_bytes: 26160
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back

constexpr int INF = 1LL << 60;
constexpr int MOD = 1e9 + 7;

signed main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int n, ans = 0, minA = INF, cnt = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        int a;
        cin >> a;
        ans += abs(a);
        if (a < 0) cnt++;
        minA = min(minA, abs(a));
    }

    if (cnt % 2) {
        ans -= 2 * minA;
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin>>n>>k;
  vector<int>h(n);
  for (int i=0; i<n; i++) cin>>h[i];
  int ans = 0;
  for (int i=0; i<n; i++){
    if (h[i]>=k) ans++;
  }
  cout << ans;
}

Measured memory_bytes: 3692
from collections import deque

h, w = map(int, input().split())
tizu = [list(input()) for _ in range(h)]
check = [[False for _ in range(w)] for _ in range(h)]
queue = deque()
directions = [[0, 1], [0, -1], [1, 0], [-1, 0]]
for i in range(h):
    for j in range(w):
        if tizu[i][j] == "#":
            queue.append([i, j])
            queue.append(0)
            check[i][j] = True
            
while queue:
    pos = queue.popleft()
    ans = queue.popleft() + 1
    for dy, dx in directions:
        next_y = pos[0] + dy
        next_x = pos[1] + dx
        if next_x == -1 or next_y == -1 or next_x == w or next_y == h:
            continue
        if check[next_y][next_x]:
            continue
        check[next_y][next_x] = True
        queue.append([next_y, next_x])
        queue.append(ans)
        
print(ans - 1)
                
                

Measured memory_bytes: 220292
from _collections import deque
N = int(input())
T = [[] for _ in range(N)]
for i in range(N-1):
    u,v,w = map(int,input().split())
    T[u-1].append([v-1,w%2])
    T[v-1].append([u-1,w%2])

ans = [0]*N
used_1 = [0]*N
used_2 = [0]*N
for i in range(N):
    if used_1[i] == 0:
        used_1[i] = 1
        u = i
        P = deque([])
        for j in range(len(T[i])):
            v = T[u][j][0]
            w = T[u][j][1]
            P.append(v)
            if used_2[v] == 1:
                k = ans[v]
                if k == 1:
                    if w == 1:
                        ans[u] = 0
                    else:
                        ans[u] = 1
                else:
                    if w == 1:
                        ans[u] = 1
                    else:
                        ans[u] = 0
                used_2[u] = 1
            elif used_2[u] == 1:
                k = ans[u]
                if k == 1:
                    if w == 1:
                        ans[v] = 0
                    else:
                        ans[v] = 1
                else:
                    if w == 1:
                        ans[v] = 1
                    else:
                        ans[v] = 0
                used_2[v] = 1
            else:
                if w == 1:
                    ans[v] = 1
                else:
                    pass
                used_2[u] = 1
                used_2[v] = 1
        while(True):
            i = P.popleft()
            if used_1[i] == 0:
                used_1[i] = 1
                u = i
                for j in range(len(T[i])):
                    v = T[u][j][0]
                    w = T[u][j][1]
                    P.append(v)
                    if used_2[v] == 1:
                        k = ans[v]
                        if k == 1:
                            if w == 1:
                                ans[u] = 0
                            else:
                                ans[u] = 1
                        else:
                            if w == 1:
                                ans[u] = 1
                            else:
                                ans[u] = 0
                        used_2[u] = 1
                    elif used_2[u] == 1:
                        k = ans[u]
                        if k == 1:
                            if w == 1:
                                ans[v] = 0
                            else:
                                ans[v] = 1
                        else:
                            if w == 1:
                                ans[v] = 1
                            else:
                                ans[v] = 0
                        used_2[v] = 1
                    else:
                        if w == 1:
                            ans[v] = 1
                        else:
                            pass
                        used_2[u] = 1
                        used_2[v] = 1
            if len(P) == 0:
                break

for i in ans:
    print(i)

Measured memory_bytes: 90528
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

constexpr Int TEN(int n) { return n == 0 ? 1 : 10*TEN(n-1); }

int N;
vector<Int> A;

Int dfs(int l, int r, Int ci, Int cj) {
    if(l > r)
        return 0L;

    Int ans = TEN(18);
    for(int k = l;k <= r;k++) {
        ans = min(ans,(ci+cj)*A[k] + dfs(l,k-1,ci,ci+cj) + dfs(k+1, r, ci+cj, cj));
    }

    return ans;
}

Int solve(void) {
    if(N == 2) {
        return A[0]+A[1];
    }
    

    return A[0] + A[N-1] + dfs(1, N-2,1, 1);
}

int main(void) {
    cin>>N;

    for(int i = 0;i < N;i++) {
        Int a;
        cin>>a;
        A.push_back(a);
    }

    cout<<solve()<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <sstream>
#include <set>
#include <iomanip>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <functional>

#include <cstdio>
#include <cmath>
#include <climits>
#include <cstring>
#include <cctype>
#include <cstdlib>


using namespace std;

#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(w, x, y, z) cout << w << " " << x << " " << y << " " << z << endl;
#define tr6(a, b, w, x, y, z) cout << a << " " << b << " " << w << " " << x << " " << y << " " << z << endl;

#define ll long long
#define fastIO  ios::sync_with_stdio(false); cin.tie(0);
inline int in() { int x; scanf("%d", &x); return x; }
inline ll inL() {ll x; scanf("%lld", &x); return x; }
string toString(long long n) { stringstream ss; ss << n; return ss.str(); }
long long toNumber(string s){ stringstream ss; long long n; ss << s; ss >> n; return n; }


int main(){
#ifdef __APPLE__
    const clock_t begin_time = clock();
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    
    int n = in();
    
    vector <ll> a(2 * n);
    
    for (int i = 0; i < 2*n; i++) {
        a[i] = inL();
    }
    
    sort(a.begin(), a.end());
    
    ll ans = 0;
    for (int i = 0; i < 2 * n; i += 2) {
        ans += a[i];
    }
    
    cout << ans << endl;
    
    
#ifdef __APPLE__
    cout << endl;
    cout << "Time : ";
    cout << float( clock () - begin_time ) / CLOCKS_PER_SEC << endl;
#endif
    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (H, W) = readLine()!!.split(" ").map(String::toInt)
    repeat(W + 2) { print("#") }
    println()
    repeat(H) {
        print("#")
        readLine()!!.let(::print)
        print("#")
        println()
    }
    repeat(W + 2) { print("#") }
    println()
}

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

//template
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>(b);i--)
#define ALL(v) (v).begin(),(v).end()
typedef long long int ll; typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename A,size_t N,typename T>void Fill(A(&array)[N],const T &val){fill((T*)array, (T*)(array+N), val);}
const int inf = 0x3fffffff; const ll INF = 0x3fffffffffffffff;
//template end

bitset<4000010> dp;

int main(){
    int n; scanf("%d",&n);
    vector<int> a(n);
    rep(i,0,n)scanf("%d",&a[i]);
    int sum=0; rep(i,0,n)sum+=a[i];
    dp[0]=1;
    rep(i,0,n)dp|=(dp<<a[i]);
    rep(i,(sum+1)/2,4000010)if(dp[i]){
        printf("%d\n",i); break;
    }
    return 0;
}

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

F = []

for i in range(N):

    f = list(map(int,input().split()))

    F.append( [f[0],f[1] ,f[2],f[3] , f[4],f[5] , f[6],f[7] , f[8],f[9] ] )

P = []

for i in range(N):

    p = list(map(int,input().split()))

    P.append(p)

ans = -N * (10 ** 7)

for i in range(2 ** 10):
    
    nt = format(i,"b")
    nt = nt.zfill(10)

    #print (nt)

    now = 0

    for j in range(N):

        both = 0
        for k in range(10):

            if F[j][k] == 1 and nt[k] == "1":
                both += 1

        now += P[j][both]
        #print (j,both,now)

    if i != 0:
        ans = max(now,ans)

print (ans)

        


Measured memory_bytes: 3188
#include<iostream>
#include<cstdio>

using namespace std;

int n;

int main(void){
	while(1){
		int ans=0;
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n/4;i++){
			int a;
			scanf("%d",&a);
			ans+=a;
		}
		printf("%d\n",ans);
	}
    return 0;
}

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

int main(void)
{
   int a, b, i=10;

   scanf("%d%d",&a,&b);

   while(i<=b)
      i=i*10;

   a=(a*i)+b;
   b=sqrt(a);
   if(b*b==a)
      printf("Yes\n");
   else
      printf("No\n");
   return 0;
}

Measured memory_bytes: 128
S = list(input())
S_l = len(S)
n=0
l = []
r = []
f_l, f_r = 0,0
for n in range(S.index('*')):
    if S[n]== '(':
        f_l += 1
    elif S[n]== ')':
        f_l -= 1
for n in range(S_l - S.index('*')):
    if S[S_l-n-1] == ')':
        f_r += 1
    elif S[S_l-n-1]== '(':
        f_r -= 1
print(min(f_r, f_l))


Measured memory_bytes: 5564
#include <bits/stdc++.h>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
#define endl "\n"
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
const ll INF = 2e+9 + 10;
typedef pair<ll, ll> P;


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

  int K,S; cin >> K >> S;
  int res = 0;
  rep(x, K+1) {
    rep(y, K+1) {
      if(S-x-y>=0 && S-x-y<=K) ++res;
    }
  }
  cout << res << endl;

  return 0;
}


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

#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) do{}while(0)
#endif







ll h, w, n;
vector<vector<ll>> v;

int main(){
	cin >> h >> w >> n;
	
	v.resize(w);
	rep(i,n){
		ll x, y;
		cin >> x >> y;
		x--;
		y--;
		v[y].push_back(x);
	}
	
	rep(i,w)
		sort(ALL(v[i]));
	
	
	// 下方向の障害物のxを返す
	auto xblock = [&](ll px, ll py){
		auto it = lower_bound(v[py].begin(),v[py].end(),px);
		if ( it == v[py].end() )
			return h;
		return *it;
	};
	
	
	ll x = 0;
	ll y = 0;
	ll minx = h;
	while ( true ){
		ll bx = xblock(x,y);
		chmin( minx, bx );
		
		//eprintf( "%lld %lld bx=%lld \n", x+1, y+1, bx );
		// 高橋君は、移動できるなら常に移動する
		if ( bx == x+1 )
			break;
		x++;
		
		if ( y == w-1 || xblock(x,y+1) == x ){ // 右に移動できない
			;
		}
		else {
			y++;
		}
	}
	
	cout << minx << endl;
	
	
	return 0;
}




Measured memory_bytes: 11844
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int l , r, d; cin >> l >> r >> d;
    int ans = 0;
    for(int i = l; i <= r;  i++) {
        if(i%d == 0) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 3608
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC087B
{
    class Program
    {
        static void Main(string[] args)
        {
            var A = int.Parse(Console.ReadLine());
            var B = int.Parse(Console.ReadLine());
            var C = int.Parse(Console.ReadLine());
            var X = int.Parse(Console.ReadLine());

            int count = 0;
            for(int i = 0; i <= A; i++)
            {
                int remain = X;
                remain -= 500 * i;
                for(int j = 0; j <= B; j++)
                {
                    int remain2 = remain - 100 * j;
                    for (int k = 0; k <= C; k++)
                    {
                        int remain3 = remain2 - 50 * k;
                        if (remain3 == 0) count++;
                    }
                }
            }

            Console.WriteLine(count);
            Console.ReadKey();
        }
    }
}


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

int main() {
    int N, H;
    cin >> N >> H;
    vector<int> A(N), B(N);

    rep(i, N) cin >> A[i] >> B[i];
    sort(B.rbegin(), B.rend());
    int amax = 0;
    rep(i, N) amax = max(amax, A[i]);

    int ans = 0;
    rep(i,N){
        if(amax<=B[i]){
            ans++;
            H -= B[i];
        }
        else
            break;
        if(H<=0)
            break;
    }

    ans += max(0, (H + amax - 1) / amax);
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>

int n;
class data{
public:
	std::string l;
	int p,a,b,c,d,e,f,s,m;
	data(){}
	bool operator<(const data &d1)const{
		long long gm1=d1.f*d1.s*d1.m-d1.p,gm=f*s*m-p;
		long long t1=d1.a+d1.b+d1.c+(d1.d+d1.e)*d1.m;
		long long t=a+b+c+(d+e)*m;
		if(gm1*t==gm*t1)return l<d1.l;
		return gm*t1>gm1*t;
	}
};

std::vector<data> dat;

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		dat.clear();
		for(int i=0;i<n;i++){
			data id;
			std::cin >> id.l >> id.p >> id.a >> id.b >> id.c >> id.d >> id.e >> id.f >> id.s  >> id.m;
			dat.push_back(id);
		}
		sort(dat.begin(),dat.end());
		for(int i=0;i<n;i++){
			std::cout << dat[i].l << std::endl;
		}
		std::cout << "#" << std::endl;
	}
	return 0;
}

Measured memory_bytes: 1276
#include<bits/stdc++.h>
using namespace std;
int main ()
{
	int n;
	cin>>n;
	if(n%10==2||n%10==4||n%10==5||n%10==7||n%10==9)
	{
		cout<<"hon";
	}
	else if(n%10!=3)
	{
		cout<<"pon";
	}
	else
	{
		cout<<"bon";
	}
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

int dp[100005];

int main(){
	int n,k;
	cin>>n>>k;
	vector<int> a(n);
	for(int& x:a){
		cin>>x;
	}
	
	dp[0] = 0;
	for(int i = 1; i <= k; i++){
		dp[i] = 0;
		for(int x:a){
			if(i >= x && dp[i-x] == 0){
				dp[i] = 1;
			}
		}
	}
	
	if(dp[k] == 1)
		cout<<"First";
	else
		cout<<"Second";
	
}

Measured memory_bytes: 3984
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;

#define INX(x) (cin >> x)
#define OUTX(x) (cout << x << endl)

#define ADD emplace_back
#define MP make_pair
#define VVEC(type) vector<vector<type>>


int main()
{
    ll N, D;
    cin >> N >> D;

    ll result = 0;
    for (ll i = 0; i < N; i++)
    {
        ll X, Y;
        cin >> X >> Y;
        if(sqrt(X * X + Y * Y)  <= D)
        {
            result++;
        }
    }
    cout << result << endl;
    


    return 0;
}


Measured memory_bytes: 3676
##======================================python3
import sys
import collections
sys.setrecursionlimit(10**6)
input = sys.stdin.readline

class Run:
    def build(gv):
        gv.s = input().strip()
    
    def string_reverse_chk(gv, s:str):
        rev_s = "".join(list(reversed(s))[0:len(s)])
        if s == rev_s:
            return True
        return False
    
    def solve(gv):
        
        ans = "No"
        
        while True:
            slen = len(gv.s)
            reversed_s = "".join(list(reversed(gv.s))[0:slen])
            
            if gv.string_reverse_chk(gv.s) is False : break
            if gv.string_reverse_chk(gv.s[0:int((slen -1)/2)]) is False : break
            if gv.string_reverse_chk(reversed_s[0:int((slen -1)/2)]) is False : break
            
            if gv.string_reverse_chk(gv.s[int((slen +3)/2 -1):slen]) is False : break
            if gv.string_reverse_chk(reversed_s[int((slen +3)/2 -1):slen]) is False : break
            
            
            ans = "Yes"
            break
        
        print(ans)
        
if __name__ == '__main__':
    run = Run()
    run.build()
    run.solve()


Measured memory_bytes: 3316
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <numeric>
typedef long long ll;
using namespace std;
const int MOD = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
#define int long long
#define vint vector<int>
#define pint pair<int,int>
#define pb(a) push_back(a)
#define all(v) v.begin(),v.end()
#define dbg(x) cerr << #x << " = " << (x) << endl
#define yn(b) cout << ((b) ? "Yes" : "No") << endl
#define YN(b) cout << ((b) ? "YES" : "NO") << endl

int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

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

	char S;
	cin >> S;

	if(S=='A'){
		cout << 'T' << endl;
	}
	if(S=='T'){
		cout << 'A' << endl;
	}
	if(S=='C'){
		cout << 'G' << endl;
	}
	if(S=='G'){
		cout << 'C' << endl;
	}
	

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please


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


	int N, W;
	cin >> N >> W;
	map<ll, ll> MAP;

	MAP[0] = 0;
	rep(i, N) {
		int w, v;
		cin >> w >> v;
		map<ll, ll> MAP2;
		for (auto itr : MAP) {
			MAP2[itr.first + w] = itr.second + v;
		}
		for (auto itr : MAP2) {
			if (MAP[itr.first] < itr.second) MAP[itr.first] = itr.second;
		}
	}

	ll saidai = 0;
	for (auto itr : MAP) {
		if (itr.first <= W) saidai = max(saidai, itr.second);
	}
	co(saidai);

	Would you please return 0;
}

Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 7)
rl = sys.stdin.readline


def solve():
    N, K = map(int, rl().split())
    A = list(map(int, rl().split()))
    
    l_i = 0
    ans = []
    for ai in A[K:]:
        ans.append('Yes' if A[l_i] < ai else 'No')
        l_i += 1
    print(*ans, sep='\n')


if __name__ == '__main__':
    solve()


Measured memory_bytes: 110608
import sys
read = sys.stdin.buffer.read
input = sys.stdin.buffer.readline
inputs= sys.stdin.buffer.readlines
#rstrip().decode('utf-8')

#import math
#import numpy as np
#import operator
#from heapq import heapify,heappop,heappush
#from math import gcd
#from fractions import gcd
#from collections import deque
#from collections import defaultdict
#from collections import Counter
#from itertools import accumulate
#from itertools import groupby
#from itertools import permutations
#from itertools import combinations
#from scipy.sparse import csr_matrix
#from scipy.sparse.csgraph import floyd_warshall
#from scipy.sparse.csgraph import csgraph_from_dense
#from scipy.sparse.csgraph import dijkstra
#sys.setrecursionlimit(10**7)

#map(int,input().split())

def main():
	s=input().rstrip().decode('utf-8')
	a,b,c=s.count("a"),s.count("b"),s.count("c")
	if max(a,b,c)-min(a,b,c)<=1:
		print("YES")
	else:
		print("NO")
	



if __name__ == '__main__':
	main()

Measured memory_bytes: 3316
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String ans = "No";

        int x = sc.nextInt();
        int y = sc.nextInt();
        for(int i = 0; i <= x; i++){
            int j = x - i ;
            if( y == i*2 + j*4) ans = "Yes";
        }
        out.println(ans);

        out.flush();

    }

    static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

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

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

            return tokenizer.nextToken("\n");
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

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

    }
}

Measured memory_bytes: 32744
#include <iostream>
#include <map>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <math.h>
#include <string>
using namespace std;
typedef long long ll;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n , a , b , h[100005] = {} , l = 0 , r = 1000000000;
    cin >> n >> a >> b;
    for ( int i = 0 ; i < n ; i++ ) cin >> h[i];
    while ( l + 1 < r ) {
        ll m = ( l + r ) / 2 , c[100005] = {} , d = 0;
        for ( int i = 0 ; i < n ; i++ ) c[i] = max( 0ll , h[i] - m * b );
        for ( int i = 0 ; i < n ; i++ ) if( c[i] > 0 ) d += ( c[i] - 1 ) / ( a - b ) + 1;
        if ( d <= m ) {
            r = m;
        } else {
            l = m;
        }
    }
    cout << r;
}


Measured memory_bytes: 1792
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
int m,n;
bool t[22][11000];
int dp[3000][11000];
int main(){
while(cin>>m>>n,n||m){
rep(i,2000)rep(j,10000)dp[i][j]=0;
rep(i,22)rep(j,10000)t[i][j]=0;
rep(i,m){
	rep(j,n)cin>>t[i][j];
}

int ans=0,cnt=0;
rep(i,(1<<m)){

	cnt=0;
	rep(j,n){
		rep(k,m){
			if(i&(1<<k)&&t[k][j])dp[i][j]++;
			if((!(i&(1<<k)))&&!t[k][j])dp[i][j]++;
			
		}
	}
	rep(j,n)cnt+=max(dp[i][j],m-dp[i][j]);
	ans=max(cnt,ans);
}

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


Measured memory_bytes: 89260
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		int totalFlower = scanner.nextInt();
		int flowersHeight[] = new int[totalFlower];
		int maxFlowerHeight = 0;

		for(int i = 0; i < totalFlower; ++i) {
			flowersHeight[i] = scanner.nextInt();
			maxFlowerHeight = Math.max(maxFlowerHeight, flowersHeight[i]);
		}

		int wateringTimes = 0;

		loop:while(true) {

			boolean  start = false;

			for(int i = 0, j = 0; i < totalFlower; ++i) {

				if(!start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
					start = true;
				}
				else if(start && (flowersHeight[i] != 0)) {
					--flowersHeight[i];
				}
				else if(start && (flowersHeight[i] == 0)) {
					break;
				}
				else {
					if(++j == totalFlower) break loop;
				}

			}
			++wateringTimes;
		}

		System.out.print(wateringTimes);
	}

}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

ll n, k;

int main() {
    cin >> n >> k;
    ll x = n % k;
    ll y = k - (n % k);
    cout << min(x, y) << endl;
}


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

int main() {
    string s, t;
    cin >> s >> t;
    
    vector<vector<short> > vec(t.size() + 1, vector<short>(26));
    for (int i = 1; i <= t.size(); i++) {
        vec[i][t[i-1] - 'a']++;

        for (int j = 0; j < 26; j++) {
            vec[i][j] += vec[i-1][j];
        }
    }

    vector<vector<short> > v(s.size() + 1, vector<short>(26));
    for (int i = 1; i <= s.size(); i++) {
        v[i][s[i-1] - 'a']++;

        for (int j = 0; j < 26; j++) {
            v[i][j] += v[i-1][j];
        }
    }


    for (int i = s.size(); i > 0; i--) {
        set<vector<short>> sv;
        for (int j = 0; j + i < vec.size(); j++) {
            vector<short> sub(26);
            for (int k = 0; k < 26; k++) {
                sub[k] += vec[i + j][k] - vec[j][k];
            }

            sv.insert(sub);
        }
        
        for (int j = 0; j + i < v.size(); j++) {
            vector<short> sub(26);
            for (int k = 0; k < 26; k++) {
                sub[k] = v[i + j][k] - v[j][k];
            }

            if (sv.find(sub) != sv.end()) {
                cout << i << endl;
                return 0;
            }
        }
    }

    cout << 0 << endl;

    return 0;
}

Measured memory_bytes: 4188
#include<bits/stdc++.h>
using namespace std;
int main(){
	int x,y,ans=2e9+7;
	scanf("%d%d",&x,&y);
	if(x<=y&&y-x<ans) ans=y-x;
	if(-x<=y&&y+x+1<ans) ans=y+x+1;
	if(x<=-y&&-y-x+1<ans) ans=-y-x+1;
	if(-x<=-y&&x-y+2<ans) ans=x-y+2;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i
edge = Array.new(n+1).map{Array.new}
(n-1).times do
    a, b, c  = gets.chomp.split(" ").map(&:to_i)
    edge[a] << [b, c]
    edge[b] << [a, c]
end

q, k = gets.chomp.split.map(&:to_i)

cost = Array.new(n+1,0)
done = Array.new(n+1,false)

queue = [k]
done[k] = true
cost[k] = 0
while(queue.size > 0)
    v = queue.pop
    
    edge[v].each do |i, j|
        if done[i] == false
            done[i] = true
            cost[i] = cost[v] + j
            queue.push(i)
        else
        end
    end
end

q.times do
    x, y = gets.chomp.split.map(&:to_i)
    puts cost[x] + cost[y]
end


Measured memory_bytes: 29820
#include<stdio.h>

int main(){
  int i,j,v,n,m,k;
  int V[150][150];

  scanf("%d",&n);

  for(i = 0; i < n; i++){
    scanf("%d%d",&v,&m);
    if(m != 0){
      for(j = 0; j < m; j++){
	scanf("%d",&k);
	V[v-1][k-1] = 1;
      }
    }
  }

  for(i = 0; i < n; i++){
    j = 0;
    printf("%d",V[i][j]);
    for(j = 1; j < n; j++){
      printf(" %d",V[i][j]);
    }
    printf("\n");
  }
  return 0;
}

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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

#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++)

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

ll dp[51][51][2501];
int main()
{
    int N, A;
    vector<int> X;
    cin >> N >> A;
    X.resize(N);
    rep(i, N) cin >> X[i];

    dp[0][0][0] = 1;

    for (int i=0; i<N; i++) {
        for (int j=0; j<N; j++) {
            for (int s=0; s<=2500; s++) {
                if (s + X[i] <= 2500) {
                    dp[i+1][j+1][s + X[i]] += dp[i][j][s];
                }
                dp[i+1][j][s] += dp[i][j][s];
            }
        }
    }
    
    ll ans = 0;
    // for (int i=1; i<=N; i++) {
        for (int j=1; j<=N; j++) {
            ans += dp[N][j][A*j];
            // cerr << "(" << A*j << ", " << j << ") = " << dp[N][j][A*j] << endl;
        }
    // }
    cout << ans << endl;

}



Measured memory_bytes: 50048
#include <stdio.h>

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

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

int main(void)
{
    int n, s;
    int i;
    int min_, max_, t;
    
    while (1){
        scanf("%d", &n);
        
        if (n == 0){
            break;
        }
        
        s = 0;
        for (i = 0; i < n; i++){
            scanf("%d", &t);
            if (i == 0){
                min_ = max_ = t;
            }
            min_ = min(min_, t);
            max_ = max(max_, t);
            s += t;
        }
        
        printf("%d\n", (s - min_ - max_) / (n - 2));
    }
    
    return (0);
}

Measured memory_bytes: 0
import heapq 
h = []

N,M = list(map(int,input().split()))
A = list(map(int,input().split()))
for a in A:
  heapq.heappush(h, -a)

start = heapq.heappop(h)
for i in range(M):
  start = heapq.heappushpop(h, -((-start)//2))

print(-(sum(h)+start))

Measured memory_bytes: 64612
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout<< (x) << " "

int main(){
    string s;cin>>s;
    int cnt=0;
    int bcnt=0;
    vector<int>w;
    rep(i,s.size()){
        if(s[i]=='B')bcnt++;
        else{w.push_back(bcnt);}
    }
    ll ans = 0;
    for(auto i=w.begin();i!=w.end();i++){
        ans += (*i);
    }
    co(ans);
}

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

int n,m,t,x,y;

int cnt1[4],cnt2[4];
int main(){
    string a,b;
    cin>>n>>m>>t;
    cin>>x>>y;
    cin>>a>>b;
    bool yes=true;
    for(int i=0;i<t;i++){
        if(a[i]=='R'){//出的
            cnt1[0]++;
        }else if(a[i]=='L'){
            cnt1[1]++;
        }else if(a[i]=='U'){
            cnt1[2]++;
        }else{
            cnt1[3]++;
        }
        if(y+cnt1[0]>m||y-cnt1[1]<1||x-cnt1[2]<1||x+cnt1[3]>n)yes=false;
        if(b[i]=='R'){//不出的
            cnt2[0]++;
        }else if(b[i]=='L'){
            cnt2[1]++;
        }else if(b[i]=='U'){
            cnt2[2]++;
        }else{
            cnt2[3]++;
        }
        if(a[i]!=b[i]){
        cnt2[0]=min(cnt2[0],m-y);
        cnt2[1]=min(cnt2[1],y-1);
        cnt2[2]=min(cnt2[2],x-1);
        cnt2[3]=min(cnt2[3],n-x);
        }
        if(cnt2[0]>cnt1[1])cnt2[0]-=cnt1[1],cnt1[1]=0;
        else cnt1[1]-=cnt2[0],cnt2[0]=0;
        if(cnt2[1]>cnt1[0])cnt2[1]-=cnt1[0],cnt1[0]=0;
        else cnt1[0]-=cnt2[1],cnt2[1]=0;
        if(cnt2[2]>cnt1[3])cnt2[2]-=cnt1[3],cnt1[3]=0;
        else cnt1[3]-=cnt2[2],cnt2[2]=0;
        if(cnt2[3]>cnt1[2])cnt2[3]-=cnt1[2],cnt1[2]=0;
        else cnt1[2]-=cnt2[3],cnt2[3]=0;
        if(a[i]==b[i]){
            cnt2[0]=min(cnt2[0],m-y);
        cnt2[1]=min(cnt2[1],y-1);
        cnt2[2]=min(cnt2[2],x-1);
        cnt2[3]=min(cnt2[3],n-x);
        }
    }
    if(yes)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

//ref : https://www.hamayanhamayan.com/entry/2017/07/30/030601

int main(){
    ll k; 
    cin >> k;
    ll d = k % 50;
    vector<ll> ans;
    for(int i = 0; i < 50 - d; i++) ans.pb(49 - d);
    for(int i = 0; i < d; i++) ans.pb(50);
    ll a = k / 50;
    for(int i = 0; i < 50; i++) ans[i] += a;
    cout << 50 << endl;
    rep(i,50){
        cout << ans[i];
        if(i != 49) cout << " ";
    }
    cout << endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define MOD 1000000007
typedef unsigned long long ull;

int main() {
  int n;
  string s;
  cin >> n >> s;
  int count = 0;
  rep(i, n - 2) {
      if (s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C') {
          count++;
      }
  }

  cout << count;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main() {
	int n, k;
	int x, y, z;
	int s, ans;
	bool v = true;
	ans = 0;
	scanf("%d %d", &n,&k);
	ans = 1;
	s = 0;
	f(i, n) {
		scanf("%d", &x);
		s += x;
		if (s <= k)ans++;
	}
	printf("%d\n", ans);


	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=4999999996000000001;



int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b && b!=c) || (b==c && c!=a) || (c==a && a!=b)){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll; 
int main() {
  ll n; cin>>n;
  bool ans=false;
  if(n<=81) {
    for(int i=1; i<=9; i++) {
      for(int j=1; j<=9; j++) {
        if(n==j*i) ans=true;
      }
    }
  }
  if(ans==true) cout << "Yes";
  else cout << "No";
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
Created on Sat Oct 13 12:14:21 2018
ABC075C
@author: maezawa
"""

def dfs(now, visited):
    visited.add(now)
    if len(visited) == n:
        return True
    ans = False
    for nextnode in adj[now]:
        if nextnode in visited:
            continue
        if dfs(nextnode, visited):
            ans = True
    return ans
        

def is_bridge(cur_edge):
    start = cur_edge[0]
    visited = set([])
    adj[cur_edge[1]].remove(start)
    adj[start].remove(cur_edge[1])
    if dfs(start,visited):
        ans = False
    else:
        ans = True
    adj[cur_edge[1]].append(start)
    adj[start].append(cur_edge[1])
    return ans
    
    
n, m = list(map(int, input().split()))
adj = [[] for _ in range(n+1)]
edges = []
for _ in range(m):
    ai, bi = list(map(int, input().split()))
    adj[ai].append(bi)
    adj[bi].append(ai)
    edges.append([ai, bi])

#print(adj)

cnt = 0
for edge in edges:
    if is_bridge(edge):
        #print(edge)
        cnt += 1

print(cnt)

Measured memory_bytes: 3064
fun main(args: Array<String>) {
    val s = readLine()!!
    var res = 0

    s.forEach {
        if (it == 'R') {
            res++
        }
    }

    if (s[1] == 'S') {
        if (res > 0) {
            res = 1
        }
    }

    println(res.toString())
}


Measured memory_bytes: 34416