akhauriyash/Code-Regression huggingface dataset:
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
for(var i=0;i<Arr.length;i++){
var mfr=Arr[i].split(" ").map(Number);
var m=mfr[0];
var f=mfr[1];
var r=mfr[2];
if(m==-1 && f==-1 && r==-1)break;
if(m==-1 || f==-1){console.log("F");continue;}
if(m+f>=80){console.log("A");continue;}
if(m+f>=65){console.log("B");continue;}
if(m+f>=50){console.log("C");continue;}
if(m+f>=30 && r>=50){console.log("C");continue;}
if(m+f>=30){console.log("D");continue;}
if(m+f<30){console.log("F");continue;}
}

Measured memory_bytes: 7644
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))


int n;
lli dat[300005];
int main(void){
	scanf("%d",&n);
	rep(i,n*3){
		scanf("%lld",&dat[i]);
	}
	sort(dat,dat+n*3,greater<lli>());
	lli ans=0;
	rep(i,n){
		ans += dat[i*2+1];
	}
	printf("%lld\n",ans);
	return 0;
}



Measured memory_bytes: 2560
/* ****GT_18**** */

#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define	endl		'\n'
#define pii         pair<ll int,ll int>
#define vi          vector<ll int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll int)x.size()
#define hell        1000000007
#define rep(i,a,b)	for(ll int i=a;i<b;i++)
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define mp          make_pair
using namespace std;

#define N  105
#define K  100005

ll n,k;
ll dp[K][2];
ll a[N];

ll solve(){
	// cout<<left<<" "<<turn<<endl;
	// if(dp[left][turn]!=-1){cout<<"HI";return dp[left][turn];};
	// bool ans=0;
	// rep(i,0,n){
	// 	if(left-a[i]<0)continue;
	// 	if(solve(left-a[i],1-turn)==0){ans=1;break;}
	// }
	// return dp[left][turn]=ans;

	rep(i,0,k+1){
		rep(j,0,2){
			rep(l,0,n){
				if(i-a[l]<0)continue;
				if(dp[i-a[l]][1-j]==0){dp[i][j]=1;break;}
			}
		}
	}
	return dp[k][0];

}

int main()
{
	// ios_base::sync_with_stdio(false);
	// cin.tie(0);
	// cout.tie(0);
	int TESTS=1;
//	cin>>TESTS;
	// rep(i,0,K)dp[i][0]=dp[i][1]=-1;
	while(TESTS--)
	{
		cin>>n>>k;
		rep(i,0,n)cin>>a[i];
		bool win = solve();
		if(win){
			cout<<"First"<<endl;
		}
		else cout<<"Second"<<endl;
	}
	return 0;
}

Measured memory_bytes: 5120
import java.util.Scanner;

public class Main {

    public static void main(String[] args) { // msAC

        Scanner sc = new Scanner(System.in);
        String[] abt = sc.nextLine().split(" ");
        int X = Integer.parseInt(abt[0]);
        int A = Integer.parseInt(abt[1]);

        System.out.println(X >= A ? "10" : "0");
    }

}


Measured memory_bytes: 21844
n,m=map(int,input().split())
a=[list(input()) for i in range(n)]
b=[list(input()) for i in range(m)]
exist=False
for i in range(n-m+1):
  for j in range(n-m+1):
    match=True
    for k in range(m):
      for l in range(m):
        if a[i+k][j+l]!=b[k][l]:
          match=False
    if match:
      exist=True
print("Yes" if exist else "No")

Measured memory_bytes: 9216
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int, Z: int):
    print(Z, X, Y)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    Z = int(next(tokens))  # type: int
    solve(X, Y, Z)

if __name__ == '__main__':
    main()


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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define rep(i, n, m) for (int (i) = (n); (i) < (m); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debugB(x, y) cerr<<#x<<": "<<bitset<y>(x) << endl;
#define line() cerr << "---------------" << endl;

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

int n;
vec<int> v;

bool bin(int key) {
   int left = 0, right = n - 1;
   while (left <= right) {
      int mid = (left + right) / 2;
      if (key < v[mid]) {
         right = mid - 1;
      } else if (key > v[mid]) {
         left = mid + 1;
      } else {
         return true;
      }
   }
   return false;
}

int main() {
   cin >> n;
   rep (i, 0, n) {
      int x;
      cin >> x;
      v.push_back(x);
   }
   sort(all(v));

   int q;
   cin >> q;
   int cnt = 0;
   rep (i, 0, q) {
      int x;
      cin >> x;
      if (bin(x)) cnt++;
   }
   cout << cnt << endl;

   return 0;
}


Measured memory_bytes: 3500
#include <cstring>
#include <cstdint>
#include <iostream>
#include <string>
#include <memory>
#include <queue>
#include <stack>
#include <limits>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <sstream>
#include <random>
#include <functional>
#include<algorithm>
#include <array>
#include<random>
using namespace std;

int main() {
	uint64_t N;
	cin >> N;
	vector<pair<pair<int64_t, int64_t>, bool> > F(N);
	vector<pair<int64_t, int64_t> > L(N),R(N);
	for (size_t i = 0; i < N; i++)
	{
		cin >> F[i].first.first >> F[i].first.second;
		F[i].second = true;
		L[i].second = R[i].second = i;
		L[i].first = F[i].first.first;
		R[i].first = F[i].first.second;
	}
	sort(L.begin(), L.end(), greater<pair<int64_t, int64_t>>());
	sort(R.begin(), R.end());
	uint64_t ans0 = 0,ans1 = 0;
	int64_t t = 0;
	auto minMove = [&](uint64_t i)->uint64_t {
		if (t < F[i].first.first) {
			auto tt = t;
			t = F[i].first.first;
			return F[i].first.first - tt;
		}
		else if (F[i].first.second < t) {
			auto tt = t;
			t = F[i].first.second;
			return tt - F[i].first.second;
		}
		else{
			return 0;
		}
	};
	auto lptr = L.begin();
	auto rptr = R.begin();
	while (true)
	{
		while (false == F[lptr->second].second) {
			++lptr;
			if (lptr == L.end())goto SCENE1;
		}
		F[lptr->second].second = false;
		ans0 += minMove(lptr->second);
		while (false == F[rptr->second].second) {
			++rptr;
			if (rptr == R.end())goto SCENE1;
		}
		F[rptr->second].second = false;
		ans0 += minMove(rptr->second);
	}
SCENE1:
	ans0 += abs(t);
	t = 0;
	lptr = L.begin();
	rptr = R.begin();
	for (size_t i = 0; i < N; i++)
	{
		F[i].second = true;
	}
	while (true)
	{
		while (false == F[rptr->second].second) {
			++rptr;
			if (rptr == R.end())goto SCENE2;
		}
		F[rptr->second].second = false;
		ans1 += minMove(rptr->second);
		while (false == F[lptr->second].second) {
			++lptr;
			if (lptr == L.end())goto SCENE2;
		}
		F[lptr->second].second = false;
		ans1 += minMove(lptr->second);
	}
SCENE2:
	ans1 += abs(t);
	cout << max(ans0,ans1);

	return 0;
}

Measured memory_bytes: 5760
n = int(input())
l = list(map(int,input().split()))

l_dic = {}
for i in range(n):
    if l[i] not in l_dic:
        l_dic[l[i]] = 0
    l_dic[l[i]] += 1

l_item = list(l_dic.items())
l_item.sort(key = lambda x:x[0])

if len(l_dic) < 3:
    print(0)
    exit()

ans = 0
for i in range(len(l_item)):
    for j in range(i+1,len(l_item)):
        for k in range(j+1,len(l_item)):
            if l_item[i][0] + l_item[j][0] > l_item[k][0] and l_item[i][0] + l_item[k][0] > l_item[j][0] and l_item[k][0] + l_item[j][0] > l_item[i][0]:
                ans += 1*l_item[i][1]*l_item[j][1]*l_item[k][1]

print(ans)






Measured memory_bytes: 9168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;
const double p = 3.14159265;

int main(){
    double r;
    cin >> r;
    double ans = 2.0*p*r;
    
    
    
    printf("%.10f\n", ans);
    return 0;
}


Measured memory_bytes: 3788
n = int(input())

array = [0] * (10**4+1)

for i in range(1, 100+1):
  for j in range(1, 100+1):
    for k in range(1, 100+1):
      tmp = i**2 + j**2 + k**2 + i*j + j*k + k*i
      if tmp <= 10**4:
        array[tmp] += 1
        
for i in range(1, n+1):
  print(array[i])

Measured memory_bytes: 69024
import sys
input = sys.stdin.readline
 
n = int(input())
a = list(map(int,input().split()))
a.sort()
#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
#リスト l の最大公約数
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
#nの約数列挙
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    return ass #sortされていない
 
#0番目を使わない場合
res = gcdlist(a[1::])
 
#else
p = sorted(divisor(a[0]))
for i in range(len(p)-1,-1,-1):
    if p[i]<=res:
        break
    cnt = 1
    for j in range(1,n):
        if a[j]%p[i]==0:
            cnt += 1
    if cnt >= n-1:
        res = p[i]
        break
print(res)

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

using namespace std;

#define INF (1 << 30)
#define EPS 1e-10
#define MOD 1000000007

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

using ll = long long;

template<class T> void chmax(T& a, T b){ a>b?:a=b; }
template<class T> void chmin(T& a, T b){ a<b?:a=b; }

double a[200000];
int n;
ll k;

bool isok(double m) {
    ll sum = 0;
    for (int i = 0; i < n; ++i) {
        sum += (ll)max(0.0, ceil(a[i] / m)) - 1;
    }
    if (sum <= k)
        return true;
    return false;
}

int main() {
    cin >> n >> k;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }

    double l = 0, r = 1e9, m;
    for (int i = 0; i < 100; ++i) {
        m = (l + r) / 2;
        if (isok(m)) {
            r = m;
        }
        else {
            l = m;
        }
    }
    cout << (ll)ceil(l) << endl;

    return 0;
}

Measured memory_bytes: 5252
#include <stdio.h>
#define rep(i,n) for(int i=0; i<(int)(n); i++)

const int dx[]={1,0,-1,0},dy[]={0,-1,0,1};
int main(){
    int h,w;scanf("%d%d",&h,&w);
    char c[55][55];
    rep(i,h) scanf("%s",&c[i]);
    int ang=0;
    rep(i,h){
        rep(j,w){
            if(c[i][j]=='.') continue;
            int ng=1;
            rep(k,4){
                int tmpi=i+dx[k];
                int tmpj=j+dy[k];
                if(tmpi>=0&&tmpi<h&&tmpj>=0&&tmpj<w){
                    if(c[tmpi][tmpj]=='#') ng=0;
                }
            }
            if(ng) {
                ang=1;
                break;
            }
        }
        if(ang) break;
    }

    if(ang) puts("No");
    else puts("Yes");
}

Measured memory_bytes: 1636
import bisect
n = int(input())
a = [int(input()) for _ in range(n)]

b = [a[-1]]
for i in range(n - 2, -1, -1):
    if b[-1] <= a[i]:
        b.append(a[i])
    else:
        b[bisect.bisect_right(b, a[i])] = a[i]

print(len(b))

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

const int INF = 1001001001;

struct edge{
    int t;
    int w;
};

vector<edge> to[100007];
vector<int> visit(100007);
vector<int> dist(100007);

void dfs(int u, int b=-1){
    visit[u] = 1;
    rep(i, to[u].size()){
        int next = to[u][i].t;
        int nexw = to[u][i].w;
        if(next == b)continue;
        if(visit[next] == 0){
            dist[next] = dist[u] + nexw;
            dfs(next, u);
        }
    }
    return;
}

int main() {
    int n; cin >> n;
    rep(i, n-1){
        int s, t, w; cin >> s >> t >> w;
        edge E1 = {t, w};
        to[s].push_back(E1);
        edge E2 = {s, w};
        to[t].push_back(E2);
    }
    rep(i, n){
        dist[i] = INF;
    }
    dist[0] = 0; 
    dfs(0);
    int x = -1;
    int ma = -1;
    rep(i, n){
        if(dist[i] > ma){
            x = i;
            ma = dist[i];
        }
    }
    rep(i, n){
        dist[i] = INF;
        visit[i] = 0;
    }
    dist[x] = 0;
    dfs(x);
    x = -1;
    ma = -1;
    rep(i, n){
        if(dist[i] > ma){
            x = i;
            ma = dist[i];
        }
    }
    cout << ma << endl;


    return 0;
}


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

#define rep(i,l,n) for(int (i)=(l);(i)<(n);(i)++)
#define min(a,b) (a)<(b)?(a):(b)
#define max(a,b) (a)>(b)?(a):(b)
#define abs(a) (a)>0?(a):-(a)
#define llong long long

int main(){
	int N; scanf("%d",&N);
	int a[N];
	rep(i,0,N) a[i]=0;
	rep(i,1,N){
		int j; scanf("%d",&j);
		j--;
		a[j]++;
	}
	rep(i,0,N) printf("%d\n",a[i]);
	return 0;
}


Measured memory_bytes: 2508
//1 + … + 2^k < 2^(k+1)なことに注意すると、kのmaxを最小化したくなる.
#include <iostream>
#include <algorithm>
#include <vector>
#define rep(i, n) for (i = 0; i < n; i++)
#define int long long
using namespace std;

int n;
int a[50];
int b[50];

bool isFree[51];
int NONE = 114514;
int dp[51][51];
int minK(int a, int b) {
	if (a == b) return dp[a][b] = 0;
	if (dp[a][b] != -1) return dp[a][b];
	
	int k;
	int ret = NONE;
	for (k = 1; k <= a; k++) {
		if (a % k < b) continue;
		int res = minK(a % k, b);
		int eval = max(res, isFree[k] ? res : k);
		ret = min(ret, eval);
	}
	return dp[a][b] = ret;
}

bool check() {
	for (int i = 0; i < n; i++) if (a[i] != b[i]) return false;
	return true;
}

signed main() {
	int i, j;
	
	rep(i, 51) rep(j, 51) dp[i][j] = -1;
	rep(i, 51) rep(j, 51) minK(i, j);
	//rep(i, 20) { rep(j, 20) { if (dp[i][j] == NONE) cout << "- "; else cout << dp[i][j] << " "; } cout << endl; }
	
	cin >> n;
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> b[i];
	rep(i, n) if (a[i] != b[i] && b[i] * 2 + 1 > a[i]) { cout << -1 << endl; return 0; }
	
	vector<int> ans;
	while (true) {
		int maxK = 0;
		rep(i, n) {
			int res = minK(a[i], b[i]);
			maxK = max(maxK, res);
		}
		if (maxK == 0) break;
		
		ans.push_back(maxK);
		isFree[maxK] = true;

		rep(i, 51) rep(j, 51) dp[i][j] = -1;
		rep(i, 51) rep(j, 51) minK(i, j);
	}
	
	int ssum = 0;
	rep(i, ans.size()) { /*cout << ans[i] << " ";*/ ssum += (1LL << ans[i]); } //cout << endl;
	cout << ssum << endl;
	return 0;
}

Measured memory_bytes: 888
#include <stdlib.h>
#include <cmath>
#include <cstdio>
#include <cstdint>
#include <string>
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
using namespace std;
using ll = long long;

int main(){
  int N;
  cin >> N;
  int ans=N;
  for(int i=1;i<10;i++){
    if(pow(2,i)<=N) ans=pow(2,i);
    else break;
  }

  cout << ans << endl;

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  rep(i,n) {
    if(i!=n-1) {
      cout << a[n-1-i] << " ";
    }else {
      cout << a[n-1-i];
    }
    
  }
  cout << endl;
  return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int r, g;
	cin >> r >> g;
	cout << (g * 2 - r) << endl;
	return 0;
}
 

Measured memory_bytes: 256
import numpy as np
n,m = map(int,input().split())
store_ls = [0] * n
for i in range(n):
    store_ls[i] = list(map(int,input().split()))
store_ls.sort(key = lambda x: x[0])
count = 0
price = 0
for i in range(n):
    if count + store_ls[i][1] < m:
        count += store_ls[i][1]
        price += store_ls[i][0] * store_ls[i][1] 
    else:
        rest = m - count
        price += store_ls[i][0] * rest
        break
print(price)

Measured memory_bytes: 37996
use std::io::{self, Read};
use std::str::FromStr;
use std::cmp::Ord;
use std::fmt::Display;

pub struct Scanner<R: Read> {
    reader: R,
}
impl<R: Read> Scanner<R> {
    pub fn new(reader: R) -> Scanner<R> {
        Scanner { reader: reader }
    }
    pub fn read<T: FromStr>(&mut self) -> T {
        let s = self
            .reader
            .by_ref()
            .bytes()
            .map(|c| c.expect("failed to read char") as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        s.parse::<T>().ok().expect("failed to parse token")
    }
}

enum Tree<T: Ord + Display> {
    Nil,
    Node { 
        key: T, 
        left: Box<Tree<T>>, 
        right: Box<Tree<T>>,
    },
}

impl<T: Ord + Display> Tree<T> {
    fn insert_rec(&mut self, val: T) {
        match *self {
            Tree::Nil => {
                *self = Tree::Node{
                    key: val, 
                    left: Box::new(Tree::Nil), 
                    right: Box::new(Tree::Nil) };
            },
            Tree::Node{ ref key, ref mut left, ref mut right } => {
                if val < *key {
                    left.insert_rec(val);
                } else {
                    right.insert_rec(val);
                }
            },
        }
    }

    fn print_in(&self) {
        match *self {
            Tree::Nil => {;},
            Tree::Node{ ref key, ref left, ref right } => {
                left.print_in();
                print!(" {}", key);
                right.print_in();
            },
        }
    }
    
    fn print_pre(&self) {
        match *self {
            Tree::Nil => {;},
            Tree::Node{ ref key, ref left, ref right } => {
                print!(" {}", key);
                left.print_pre();
                right.print_pre();
            },
        }
    }
} 

fn main() {
    let sin = io::stdin();
    let sin = sin.lock();
    let mut sc = Scanner::new(sin);

    let n: usize = sc.read();
    let mut tree : Tree<i64> = Tree::Nil;

    for _ in 0..n {
        let cmd: String = sc.read();
        match cmd.as_str() {
            "insert" => {
                let d: i64 = sc.read();
                tree.insert_rec(d);
            },
            "print" => {
                tree.print_in();
                println!("");
                tree.print_pre();
                println!("");
            },
            _ => { panic!("irregular command"); }
        }
    }
}



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

int main(){

  int h,w,k;
  cin >> h >> w >> k;

  vector<vector<char>> mp(w,vector<char>(h));
  vector<int> xBlack(w,0);
  vector<int> yBlack(h,0);
  int count=0;
  int ans=0;

  for(int y=0;y<h;y++){
    for(int x=0;x<w;x++){
      cin >> mp[x][y];
      if(mp[x][y]=='#'){
        xBlack[x]++;
        yBlack[y]++;
        count++;
      }
    }
  }

  int last=count-k;
  if(last<0){
    cout << 0 << endl;
    return 0;
  }

  int xtime=1,ytime=1;
  for(int i=0;i<h;i++) ytime=ytime*2;
  for(int i=0;i<w;i++) xtime=xtime*2;
  //cout << "xtime:" << xtime << endl;
  //cout << "ytime:" << ytime << endl;

  int sum;
  for(int ybit=0;ybit<ytime;ybit++){
    sum=0;
    //cout << "ybit:" << bitset<8>(ybit) << endl;
    vector<int> xBlackCP = xBlack;
    for(int i=0;i<h;i++){
      if(ybit&(1<<i)){
        sum+=yBlack[i];
        //cout << "sum:" << sum << endl;
        for(int x=0;x<w;x++){
          if(mp[x][i]=='#'){
            xBlackCP[x]--;
          }
        }
      }
    }
    int sumCP;
    for(int xbit=0;xbit<xtime;xbit++){
      sumCP=sum;
      for(int j=0;j<w;j++){
        if(xbit&(1<<j)){
          sumCP+=xBlackCP[j];
        }
        //cout << "sum:" << sum << endl;
      }
      //cout << "last-sum:" << last-sum << endl;
      if(sumCP==last){
        ans++;
      }
    }
    //cout << ans << endl << endl;
  }

  cout << ans << endl;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int x[n];
    for (int i = 0; i < n; i++) cin >> x[i];
    int sum = 0;
    for (int i = 0; i < n; i++) {
        sum += 2*min(x[i], k-x[i]);
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0; i<n; i++){
    cin >> a[i];
  }

  int ans = 0, b = 0, f = 0;

  for(int i=0; i<n; i++){
    b = a[i] - 1;
    f = f + b;
  }   
  cout << f << endl;
  
  return 0;
}

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

using ll = long long int;

int main(){
    int n;
    cin >> n;
    vector<int> cnt(n), cnt2(n+2), sum(n+1), f(n+1);
    // cnt[i]: a_j=iとなるjの個数
    for(int i=0;i<n;i++){
        int a;
        cin >> a;
        cnt[a-1]++;
    }
    // cnt2[i]: cnt[j]=iとなるjの個数
    for(int i=0;i<n;i++){
        cnt2[cnt[i]]++;
    }
    for(int i=0;i<n;i++){
        sum[i+1] = sum[i] + cnt2[i+1]*(i+1);
    }
    for(int i=n;i>0;i--){
        cnt2[i-1] += cnt2[i];
    }
    // f[i]: i回操作することが可能な最大種類数
    // 高さiのヒストグラムが何本作れるか
    // 整数jはmin(i,cnt[j])回まで使える
    // 使える個数の総和をiで割ればよい
    for(int i=1;i<=n;i++){
        f[i] = (sum[i] + cnt2[i+1]*i)/i;
    }
    for(int k=1,i=n;k<=n;k++){
        while(i > 0 && f[i] < k) i--;
        cout << i << endl;
    }
    return 0;
}

Measured memory_bytes: 5504
# from math import factorial,sqrt,ceil
from itertools import permutations as permus
# from fractions import gcd
from collections import deque,Counter
import re
# from decimal import Decimal, getcontext
# # getcontext().prec = 1000
# # eps = Decimal(10) ** (-100)

# import numpy as np
# from scipy.sparse.csgraph import shortest_path, dijkstra, floyd_warshall, bellman_ford, johnson
# from scipy.sparse import csr_matrix

# strlist = "abcdefghijklmnopqrstuvwxyz"
N = int(input())
S = input()

Sset = Counter(S)
iter = permus(list("RGB")) 

total = Sset["R"]*Sset["G"]*Sset["B"]

Slen = len(S)
hikukazu = 0
for i in range(Slen):
    for num in range(1,Slen//2+1):
        j = i+num
        k = i+num*2
        if k>Slen-1:
            break
        if S[i]!=S[j] and S[i]!=S[k] and S[k]!=S[j]:
            hikukazu += 1

ans = total - hikukazu
print(ans)
# print(*ans)   # unpackして出力。間にスペースが入る
# for row in board:
#     print(*row,sep="")    #unpackして間にスペース入れずに出力する
# print("{:.10f}".format(ans))
# print("{:0=10d}".format(ans))


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



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

  long long a;
  vector<long long> sum(N+1, 0);
  for (int i = 1; i <= N; ++i) {
    scanf("%lld", &a);
    sum[i] = sum[i-1] + a;
  }

//  for (int i = 1; i <= N; ++i) {
//    cout << sum[i] << endl;
//  }

  long long diff = LONG_LONG_MAX;
  for (int i = 1; i < N; ++i) {
    long long x = sum[i];
    long long y = sum[N] - sum[i];
    diff = min(diff, abs(x - y));
//    cout << x << " " << y << " " << diff << endl;
  }

  cout << diff << endl;

  return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <string>

using namespace std;

struct era
{
	int s;
	int t;
	string era_name;
};

int main(void)
{
	int n,q;
	string name;
	int jyear,wyear;
	int year;
	int i1,i2;

	while(1){
		cin>>n>>q;
		if(n+q==0) break;

		vector<era> v(n);

		for(i1=0;i1<n;i1++){
			cin>>name>>jyear>>wyear;
			v[i1].s=wyear-jyear+1;
			v[i1].t=wyear;
			v[i1].era_name=name;
		}
		for(i1=0;i1<q;i1++){
			cin>>year;
			for(i2=0;i2<v.size();i2++){
				if(v[i2].s<=year && year<=v[i2].t){
					cout<<v[i2].era_name<<" "<<year-v[i2].s+1<<endl;
					break;
				}
			}
			if(i2==v.size()){
				cout<<"Unknown"<<endl;
			}
		}
	}

	return 0;


}

Measured memory_bytes: 1280
import itertools

N, K = map(int, input().split())

D = set(input().split())

n = [x for x in str(N)]
num = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"} - D
judge = "no"
ans = N

for i in n:
    if i in D:
        judge = "yes"
        break

if judge == "yes":
    if ans < int(sorted(list(num))[-1] * len(n)):
        ans_list = sorted(list(itertools.product(num, repeat=len(n))))
        for i in ans_list:
            if int("".join(i)) > ans:
                ans = int("".join(i))
                break
    else:
        ans_list = sorted(list(itertools.product(num, repeat=len(n) + 1)))
        for j in ans_list:
            if int("".join(j)) > ans:
                ans = int("".join(j))
                break

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#define repeat(i,n) for (int i = 0; (i) < (n); ++(i))
using namespace std;
const int size = 7368791 + 1;
int main() {
    while (true) {
        int m, n; cin >> m >> n;
        if (m == 0 and n == 0) break;
        vector<bool> used(size);
        int j = m;
        repeat (i,n) {
            while (used[j]) ++ j;
            for (int k = j; k < used.size(); k += j) {
                used[k] = true;
            }
        }
        while (used[j]) ++ j;
        cout << j << endl;
    }
    return 0;
}



Measured memory_bytes: 4000
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    string s;
    cin >> n >> s;

    int cnt = 0;
    string ans = s;
    rep(i, n) {
        if (s[i] == '(') {
            cnt++;
        } else {
            cnt--;
        }
        if (cnt < 0) {
             ans = '(' + ans;
             cnt = 0;
        }
    }
    if (cnt > 0) ans = ans + string(cnt, ')');
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    using namespace std;
    int main(){
    	int n;cin>>n;
    	vector<pair<int,int>> vec;
    	for(int i=0;i<n;i++){
    		int a,b;cin>>a>>b;
    		vec.push_back({a,b});
    	}
    	long long int rsum=0;
    	for(int i=n-1;i>=0;i--)
    		rsum+=(vec[i].second-(vec[i].first+rsum)%vec[i].second)%vec[i].second;
    	cout<<rsum<<endl;
    	return 0;
    }

Measured memory_bytes: 1400
N=int(input())
a = list([int(input()) for _ in range(N)])

i=1
cnt=-1

for j in range(1,N+1):
    if a[i-1]==2:
        cnt=j
        break
    if a[i-1]==i:
        cnt=-1
        break
    i=a[i-1]

print(cnt)         

Measured memory_bytes: 7852
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1000000000;
const int MOD = (int)1e9 + 7;
template <class T>
inline T in()
{
    T x;
    cin >> x;
    return x;
}

signed main()
{
    int r = in<int>();
    int g = in<int>();
    int b = in<int>();
    int n = in<int>();
    int num = 0;
    for (int i = 0; i <= n / r; i++)
    {
        for (int j = 0; j <= n / g; j++)
        {
            int remain = n - r * i - g * j;
            if (remain >= 0 && remain % b == 0)
            {
                num++;
            }
        }
    }
    cout << num << "\n";
}

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

#define ll long long



void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    int cnt=3;
    if(a==b)cnt--;
    if(a==c)cnt--;
    if(b==c)cnt--;
    if(cnt==0)cnt=1;
    cout<<cnt<<endl;
}

signed main(){
    //while(1)
    solve();
}

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

int main() {

    long long int n;
    cin >> n;

    vector< long long int > v;
    long long int d = 0;

    for ( long long int i = 0; i < n; i++ ) {
        long long int in;
        cin >> in;
        v.push_back( in );
        d = in - d;
    }

    d /= 2;
    v.push_back( v[0] );

    for ( long long int i = 0; i < n; i++ ) {
        if ( i > 0 ) cout << " ";
        cout << d * 2;
        d = v[i] - d;
    }
    cout << endl;

    return 0;

}


Measured memory_bytes: 2164
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <cstdlib>
#include <cmath>
#include <string>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#define re register
#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define ms(arr) memset(arr, 0, sizeof(arr))
const int inf = 0x3f3f3f3f;
int a[100001],b;
int main() 
{
	int x,y;
	cin>>x>>y;
	int l=y-x;
	for(re int i=1;i<=l;i++)
		a[i]=a[i-1]+i;
	cout<<a[l]-y;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cassert>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
// head

const int N=101000;
int n,k,a[N];
ll s1[N],s2[N],ret;
int main() {
	scanf("%d%d",&n,&k);
	rep(i,1,n+1) {
		scanf("%d",a+i);
		s1[i]=s1[i-1]+max(0,a[i]);
		s2[i]=s2[i-1]+a[i];
	}
	rep(i,1,n+1) { // i+k-1
		if (i+k-1>n) continue;
		ret=max(ret,max(s2[i+k-1]-s2[i-1],0ll)+s1[n]-s1[i+k-1]+s1[i-1]);
	}
	printf("%lld\n",ret);
}


Measured memory_bytes: 2176
MAX = 100010

# 素数なら1となる配列
is_p =[1]*MAX
is_p[0] = 0
is_p[1] = 0

for i in range(2, MAX):
    if is_p[i] == 0:
        continue
    for j in range(i*2, MAX, i):
        is_p[j] = 0

# 2017に似た数かどうか
a = [0]*MAX
for i in range(MAX):
    if i%2 == 0:
        continue
    if is_p[i] and is_p[(i+1)//2]:
        a[i] = 1

#累積和
s = [0]*(MAX+1)
for i in range(MAX):
    s[i+1] = s[i] + a[i]

#クエリ処理
q = int(input())
for i in range(q):
    l, r = map(int, input().split())
    r += 1
    print(s[r]-s[l])

Measured memory_bytes: 7892
S = list(input())

ans = 0
for i in range(len(S)):
    for j in range(i, len(S)):
        if S[i] == 'A' or S[i] == 'C' or S[i] == 'G' or S[i] == 'T':
            if S[j] == 'A' or S[j] == 'C' or S[j] == 'G' or S[j] == 'T':
                ans = max(ans, j-i + 1)
            else:
                break
print(ans)


Measured memory_bytes: 3060
T=[[0,0] for i in range(5)]


for i in range(5):
    temp=int(input())
    if temp%10==0:
        T[i]=[10,temp]
    else:
        T[i]=[temp%10,temp]

T.sort(reverse=True)

ans=0
for i in range(4):
    ans+=((T[i][1]-1+10)//10)*10

ans+=T[4][1]

print(ans)

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define LOCAL
using namespace std;
template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
out << "(" << a.first << "," << a.second << ")";
return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
out << "["; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
return out;
}
template <typename U, typename T, class Cmp>
ostream& operator <<(ostream& out, const map<U, T, Cmp>& a) {
out << "{"; bool first = true;
for (auto& p : a) { out << (first ? "" : ", "); out << p.first << ":" << p.second; first = 0;} out << "}";
return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');
cerr.write(names, comma - names) << ": " << arg1 << " |";
__f(comma + 1, args...);
}
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
#define int long long
using P = pair<int,int>;
//#########################################
signed main(){
    int n;cin >> n;
    int a[n];
    vector<int> s(n+1);
    rep(i,n){
        cin >> a[i];
        s[i+1] = s[i] + a[i];
    }
    int ans = 1001001001001ll;
    rep(i,n+1){
        ans = min(ans,abs(s[i] - (s[n] - s[i])));
    }
    cout << ans <<endl;

    return 0;
}

Measured memory_bytes: 3328
package main

import (
	"fmt"
	"math"
	"math/cmplx"
)

func main() {
	var a, b, h, m int
	fmt.Scan(&a)
	fmt.Scan(&b)
	fmt.Scan(&h)
	fmt.Scan(&m)

	t := float64(h*60 + m)

	c := complex(float64(a)*math.Cos(math.Pi*t/360)-float64(b)*math.Cos(math.Pi*t/30),
		float64(a)*math.Sin(math.Pi*t/360)-float64(b)*math.Sin(math.Pi*t/30))

	fmt.Println(cmplx.Abs(c))
}


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

const int N=2e5+10;

int n,x;
int a[N];


int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		int y=(n-i)/2;
		if((n-i)&1)
			a[n-y]=x;
		else a[y+1]=x;
	}
	for(int i=1;i<=n;i++) printf("%d ",a[i]);
}

Measured memory_bytes: 3072
sx,sy,tx,ty = map(int,input().split())
for t in range(sy,ty):
  print("U",end="")
for t in range(sx,tx):
  print("R",end="")
for t in range(sy,ty):
  print("D",end="")
for t in range(sx,tx):
  print("L",end="")
print("L",end="")
for t in range(sy,ty+1):
  print("U",end="")
for t in range(sx,tx+1):
  print("R",end="")
print("D",end="")
print("R",end="")
for t in range(sy,ty+1):
  print("D",end="")
for t in range(sx,tx+1):
  print("L",end="")
print("U")

Measured memory_bytes: 4468
#include<cstdio>
#include<cstring>

int main(void) {
    char s[120000];
    scanf("%s",s);
    int n = strlen(s);
    int res;
    for(int i=0; i<n; i++) {
        if(i%2==0) {
            if(s[i] == 'p') res--;
        } else {
            if(s[i] == 'g') res++;
        }
    }
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 256
def main():
    import sys
    input = sys.stdin.readline
    
    n = int(input())
    arr = [0] * n
    for i in range(n):
        arr[i] = int(input())
    
    l = [0] * n
    r = [0] * n
    
    l[0] = arr[0]
    r[~0] = arr[~0]
    for i in range(1, n):
        l[i] = max(l[i - 1], arr[i])
        r[~i] = max(r[~(i - 1)], arr[~i])
    
    print(r[1])
    for i in range(1, n - 1):
        print(max(l[i - 1], r[i + 1]))
    print(l[~1])
    
    return 0

main()

Measured memory_bytes: 15676
N = int(input())
S = [input()+".", input()+","]
mod = 10**9+7

if N == 1:
    print(3)
    exit()

if S[0][0] == S[1][0]:
    i = 1
    ans = 3
else:
    i = 2
    ans = 6

while i < N:
    if S[0][i] == S[1][i]:
        if S[0][i-1] == S[1][i-1]:
            ans *= 2
        else:
            pass
        ans %= mod
        i += 1
    
    else:
        if S[0][i-1] == S[1][i-1]:
            ans *= 2
        else:
            ans *= 3
        ans %= mod
        i += 2

print(ans)

Measured memory_bytes: 9172
S = input()
i = -1
while(True):
    s = S[:i]
    if len(s)%2 != 0:
        i -= 1
        continue

    s1 = s[0:len(s)//2]
    s2 = s[len(s)//2:]
    if s1 == s2:
        print(len(s))
        exit()
    i -= 1


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>
#include <iomanip>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;


int main(){
    int v, e;
    cin >> v >> e;
    ll dp[v+1][v+1];
    for(int i = 0; i <= v; i++){
        for(int j = 0; j <= v; j++){
            if(i == j){
                dp[i][j] = 0;
            } else {
                dp[i][j] = INF;
            }
        }
    }

    for(int i = 0; i < e; i++){
        int s,t,d;
        cin >> s >> t >> d;
        dp[s][t] = d;
    }


    for(int k = 0; k < v; k++){
        for(int i = 0; i < v; i++){
            for(int j = 0; j < v; j++){
                dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j]);
            }
        }
    }

    bool negative = false;

    for(int i = 0; i < v; i++){
        if(dp[i][i] < 0){
            negative = true;
            break;
        }
    }

    if(negative){
        cout << "NEGATIVE CYCLE" << endl;
    } else {
        for(int i = 0; i < v; i++){
            for(int j = 0; j < v; j++){
                if(j != 0) cout << " ";
                if(dp[i][j] > 20000000000){
                    cout << "INF";
                } else {
                    cout << dp[i][j];
                }
            }
            cout << endl;
        }
    }
    
    return 0;
}


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

int		g_node_count = 0;

typedef	struct	s_btree
{
	char			*item;
	struct s_btree	*left;
	struct s_btree	*right;
}					t_btree;

t_btree	*btree_create_element(void *str)
{
	t_btree	*ret;

	ret = malloc(sizeof(t_btree));
	ret->item = str;
	ret->left = 0;
	ret->right = 0;
	return (ret);
}

void	btree_insert_item(t_btree **root, void *item)
{
	if (!*root)
	{
		*root = btree_create_element(item);
		return ;
	}
	if (strcmp((*root)->item, item) < 0)
	{
		if (!(*root)->left)
		{
			(*root)->left = btree_create_element(item);
			return ;
		}
		btree_insert_item(&(*root)->left, item);
	}
	else if (strcmp((*root)->item, item) > 0)
	{
		if (!(*root)->right)
		{
			(*root)->right = btree_create_element(item);
			return ;
		}
		btree_insert_item(&(*root)->right, item);
	}
}

void	btree_count_node(t_btree *root)
{
	if (root->left)
		btree_count_node(root->left);
	g_node_count++;
	if (root->right)
		btree_count_node(root->right);
}

int		main(void)
{
	int		N;
	int		i;
	char	(*S)[11];
	t_btree	*tree;

	scanf("%d", &N);
	S = malloc(sizeof(char) * N * 11);
	for (i = 0; i < N; i++)
		scanf("%s", S[i]);
	tree = 0;
	for (i = 0; i < N; i++)
		btree_insert_item(&tree, S[i]);
	btree_count_node(tree);
	printf("%d\n", g_node_count);
	return (0);
}

Measured memory_bytes: 10100
n,q = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(n-1)]
px = [list(map(int, input().split())) for i in range(q)]
parent = [0] * n
ans = [0] * n

for i in ab:
  a,b=i[0],i[1]
  parent[b-1] = a-1
  
for j in px:
  p,x = j[0], j[1]
  ans[p-1] += x

for key, i in enumerate(ans[1:]):
  key += 1
  ans[key] += ans[parent[key]]
print(*ans)

Measured memory_bytes: 124004
def main():
    n = int(input())
    d = list(map(int, input().split()))
    m = int(input())
    t = list(map(int, input().split()))
    d.sort()
    t.sort()
    x = -1
    y = -1
    while x < n and y < m-1:
        x += 1
        y += 1
        while x < n and d[x] != t[y]:
            x += 1
    if x < n:
        print("YES")
    else:
        print("NO")

if __name__ == "__main__":
    main()


Measured memory_bytes: 35420
#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(...) {}
#endif






int main(){
	string s;
	cin >> s;
	int len = SZ(s);
	
	ll op = 0;
	ll ct = 0;
	rep(i,len){
		if ( s[i] == 'W' ){
			op += i;
			ct++;
		}
	}
	
	cout << op - (ct-1)*ct/2 << endl;
	
	return 0;
}




Measured memory_bytes: 3720
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    ll s;
    cin >> s;

    ll x1, y1, x2, y2;
    x1 = 1000000000LL;
    y1 = 1LL;
    y2 = (s+x1-1)/x1;
    x2 = (x1-s%x1)%x1;
    cout << "0 0" << ' ' << x1 << ' ' << y1 << ' ' << x2 << ' ' << y2 << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define min(x,y) ((x<y)?x:y)
int amount[6] = { 2, 3, 5, 10, 12, 15};
int value[6] = { 380, 550, 850, 1520, 1870, 2244};

int dp[7][51];

void calcMinVal(void){
	int c_shop;
	int c_amount;
	int tmp1;
	int tmp2;
	
	for( c_shop = 0; c_shop < 7; c_shop++){
		for( c_amount = 0; c_amount < 51; c_amount++){
		dp[c_shop][c_amount] = 10000000;
		}
	}

	for(c_shop = 0; c_shop < 7; c_shop++){
		dp[c_shop][0] = 0;
	}
	
	for( c_shop = 0; c_shop < 6; c_shop++){
		for( c_amount = 1; c_amount < 51; c_amount++){
			if( c_amount - amount[c_shop] >= 0){
				tmp1 = dp[c_shop][c_amount - amount[c_shop]] + value[c_shop];
				tmp2 = dp[c_shop+1][c_amount - amount[c_shop]] + value[c_shop];
				dp[c_shop+1][c_amount] = min(dp[c_shop][c_amount],min(tmp1,tmp2));				
			}else{
				dp[c_shop+1][c_amount] = dp[c_shop][c_amount];
			}
		}
	}
}

int main(void){
	int input;
	calcMinVal();
	while(1){
		scanf("%d",&input);
		if(input == 0){
			break;
		}
		printf("%d\n",dp[6][input/100]);
	}
}

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


int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int H, W, h, w;
	cin >> H >> W;
	cin >> h >> w;

	cout << H*W-(h*W+(H-h)*w) << endl;
	return 0;
}

Measured memory_bytes: 256
/**
                  ▄█▀ ▀█▀ ▄▀▄ █▀ █▄█▄█ ▄▀▄ █▀ ▄█▀
                  <⇋⇋⇋⋛∰≓⊂(⌒,_ゝ⌒)⊃≓∰⋛⇋⇋⇋>

            ♔♕♖♗♘♙ ☜❷☞✪ ィℋ६ ≈ ᗫẵℜℵĬŊĞ ✪☜❷☞ ♚♛♜♝♞♟
            ♔♕♖♗♘♙                             ♚♛♜♝♞♟
                      ˙·٠•●♥ Ƹ̵̡Ӝ̵̨̄Ʒ ♥●•٠·˙

**/

#include <bits/stdc++.h>

#define sz(s) s.size()
#define pb emplace_back
#define fr first
#define sc second
#define mk make_pair
#define int long long
#define all(s) s.begin(), s.end()

using namespace std;

const int N = 2e5 + 5;
const int inf = 1e9 + 7;

int n, sum, a[N];
vector < int > b;
main()
{
   cin >> n;
   b.pb(-1);
   for( int i = 1; i <= n; i++ )
      cin >> a[i], b.pb( a[i] );

   sort( all( b ) );
   int m = n / 2;

   for( int i = 1; i <= n; i++ )
   {
      if( a[i] > b[ m ] )
         cout << b[ m ] << endl;
      else
         cout << b[ m + 1 ] << endl;
   }
}


Measured memory_bytes: 5488
#include <stdio.h>

int main(int argc, char const *argv[]) {
  int a,b,c;
  scanf("%d", &a);
  scanf("%d", &b);
  scanf("%d", &c);
  int ans = 0;
  if(a >= b){
    if(a >= c){
      ans = 10*a + b + c;
    }else{
      ans = 10 * c + a + b;
    }
  }else{
    if(b >= c){
      ans = 10*b + a + c;
    }else{
      ans = 10 * c + a + b;
    }
  }
  printf("%d",ans);
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int t = sc.nextInt();
    
    int stack1 = 0;
    int stack2 = sc.nextInt();
    int ans = t;
    
    for(int i = 1; i < n; i++) {
      stack1 = sc.nextInt();
      if(stack1 < stack2 + t) ans += (stack1 -stack2);
      else ans += t;
      stack2 = stack1;
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 58008
import math
import sys
import itertools
import queue
from fractions import gcd

def lcm(a, b):
    return a * b // gcd(a, b)

def combination(n, r):
    return factorial(n) // (factorial(n - r) * factorial(r))

sys.setrecursionlimit(10000)

mod = 1000000007

"""
# 0埋め, 小数点出力桁指定時のときの出力
a = 100
b = 0.987654321
print("{0:06d}-{1:6f}".format(a,b))
000100-0.987654

# 文字列をリストに格納
char_list = list("abcd") # ["a","b","c","d"]

# 標準入力取得
## 文字列
    = sys.stdin.readline().rstrip()
    = list(sys.stdin.readline().rstrip())

## 数値
    = int(sys.stdin.readline())
    = map(int, sys.stdin.readline().split())
    = list(map(int, sys.stdin.readline().split()))
    = [list(map(int,list(sys.stdin.readline().split()))) for i in range(h)]  # 二次元配列入力　二次元マップみたいな入力のとき
"""

if __name__ == "__main__":
    D = int(sys.stdin.readline())

    if D == 22:
        print("Christmas Eve Eve Eve")
    elif D == 23:
        print("Christmas Eve Eve")
    elif D==24:
        print("Christmas Eve")
    else:
        print("Christmas")

Measured memory_bytes: 5328
from collections import deque
n = int(input())
A = deque(map(str, input().split()))
B = deque()
cycle = n % 2
for a in A:
    if cycle % 2 == 1:
        B.appendleft(a)
    else:
        B.append(a)
    cycle += 1
print(' '.join(B))


Measured memory_bytes: 30564
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <map>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

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

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

ll choose2(ll n){
    return n*(n-1)/2;
}

int main(){
    ll r;
    cin>>r;
    cout<<3*r*r<<endl;
    return 0;
}

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

string s;
 
int main(void){
    
    cin >> s;
    int ans = 0;
    for(int i = 0; i < s.size(); ++i){
        if(s[i] == '+') ++ans;
        else --ans;
    }
    printf("%d\n", ans);
    
    return 0;
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {

            List<int> list = new List<int>();
            int n = int.Parse(Console.ReadLine());
            //a = int.Parse(Console.ReadLine()); //標準入力
            string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得

            for(int i = 0;i<n;i++)
            {
                list.Add(int.Parse(str[i]));
            }
            bool check = false;
            int tmp = -1;
            int count = 0;
            for(int i = 0;i<list.Count;i++)
            {
                if (tmp == list[i])
                {
                    count++;
                    tmp = -1;
                }
                else
                tmp = list[i];
            }
            Console.WriteLine(count);
            //Console.Write("改行なし a = {0} b = {1} c = {2}", a, b, c)//改行なし出力
            //Console.WriteLine("改行あり a = {0} b = {1} c = {2}", a, b, c);//改行付き出力
        }
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    if(n>=65 && n<=90){
        cout << 1 << endl;
    }
    else if(n>=97 && n<=122){
        cout << 2 << endl;
    }
    else{
        cout << 0  << endl;
    }
    return(0);
}


Measured memory_bytes: 3092