akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;

#define INIT std::cin.tie(0);std::ios::sync_with_stdio(false);
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define REP(i, n) for (int i = 0; i < static_cast<int>(n); i++)
#define FOR(i, s, n) for (int i = s; i < static_cast<int>(n); i++)
#define ASC(t) [](t& x, t& y){ return x < y; }
#define DESC(t) [](t& x, t& y){ return x > y; }
#define PSORT(s,p,e) partial_sort((s), next((s), (p)), (e))
#define VIEW(v,t) for_each((v).begin(), (v).end(), [](t& a) { cout << a << " "; }); cout << endl;

#define IN(a,x,b) (a<=x && x<=b)
#define WS std::cout<<" ";
#define NL std::cout<<"\n"
#define OUT(dist) std::cout<<(dist);
template<class T> inline T CHMAX(T& x, const T y){return x=(x<y)?y:x;}
template<class T> inline T CHMIN(T& x, const T y){return x=(x>y)?y:x;}

using PII = pair<int, int>;
using PLL = pair<long long, long long>;
using LL = long long;
using ULL = unsigned long long;
template<class T> using V = vector<T>;
template<class T> using V2 = vector<vector<T>>;

int N;
V<int> z, v;

int main(){
    INIT;
    cin >> N;
    z.resize(N,0);
    v.resize(N,0);
    REP(i,N) cin >> z[i];
    std::iota(ALL(v), 0);
    std::sort(ALL(v), [](int& a, int& b) {
        return z[a] > z[b];
    });
    REP(i,N) {
        if(i == v[0]) cout << z[v[1]] << "\n";
        else cout << z[v[0]] << "\n";
    }
}

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

int main() {
    while (true) {
        int x, y;
        cin >> x >> y;
        if (x == 0 && y == 0) break;
        if (x > y) printf("%d %d\n", y, x);
        else printf("%d %d\n", x, y);
    }
    return 0;
}


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

vector<vector<int>> to(200005);
int visited[200005];
int val[200005];
ll ans[200005];

void dfs(int v) {
  if (visited[v]) return;
  visited[v] = true;
  ans[v]+= val[v];
  for (int u : to[v]) {
    if(visited[u]!=true)ans[u] += ans[v];
    dfs(u);
  }
}

int main() {
  int n, q;
  cin >> n >> q;
  rep(i,n-1) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
    to[b].push_back(a);
  }
  rep(i,q){
    int p,x;
    cin >> p >> x;
    p--;
    val[p] += x;
  }
  dfs(0);
  // for(int u : des[1]){
  //   cout << u ;
  // }
  rep(i,n)cout << ans[i] << ' ';
  cout << endl;
  return 0;
}


Measured memory_bytes: 22528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll qmul(ll a,ll b)//O(1) 二分乘法
{
    ll ret = 0, k=a, sig = 1;
    if(k<0)
    {
        sig=-1;
        k=-k;
    }
    if(b<0)
    {
        sig*=-1 ;
        b=-b;
    }
    while(b)
    {
        if(b&1)
            ret=(ret+k);
        k=(k+k);
        b>>=1;
    }
    return ret*sig;
}
int main()
{
    ll Q, H, S, D, N;
    scanf("%lld%lld%lld%lld%lld", &Q, &H, &S, &D, &N);
    ll a[] = {Q*4,H*2,S};
    ll b[] = {Q*8,H*4,S*2,D};
    sort(a,a+3);sort(b,b+4);
    //ll ans = b[0] * (N / 2);
    ll ans = qmul(b[0],N/2);
    return !printf("%lld\n",N&1?ans+a[0]:ans);
}

Measured memory_bytes: 256
import collections
A, B = map(int, input().split())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

a = set(prime_factorize(A))
b = set(prime_factorize(B))

ans = 1
for i in b:
  if i in a:
    ans += 1
    
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)

#define ll long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define pi pair<ll,ll>
#define all(X) X.begin(),X.end()

// for pair comparison function(ascending order) use return (i1.ff < i2.ff);

/* string operations :
   str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
   str.substr (x) : returns a substring str[x],... end of string
   str.find(qtr) : returns the first occurenece of qtr in str.
   builtin functions :
   __builtin_popcount(n) : no. of set bits in n.
   __builtin_parity(n) : parity of no. of set bits
   __builtin_clz(n) : no. of leading zeros before 1
   __builtin_ctz(n) : no of zeros from last to first occurrence of 1
*/

const int M = (1<<20)+5;
const int md = 1e9+7;

ll pwr(ll a,ll n,ll m)
{
	ll p=1;
	while(n>0)
	{
		if(n%2==1)
			p=(p*a)%m;
		a=(a*a)%m;
		n=n/2;
	}
	return p;
}

ll binlen(ll a)
{
	ll v = 0;
	for(ll i=0;i<61;++i)
	{
		v += (1ll<<i);
		if(a<=v) return i;
	}
}

ll cnt[M];

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

	ll n,k,i,c=0,t,d,j;

	cin >> n >> k;
	for(i=1;i<=k;++i)
	{
		cin >> d;
		for(j=1;j<=d;++j)
		{
			cin >> t;
			cnt[t]++;
		}
	}

	for(i=1;i<=n;++i)
	{
		if(cnt[i] == 0)
			c++;
	}

	cout << c << endl;
}

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

// ******************************************************************
// Segment Tree with Lazy Propagation
// Increment modification on range, queries for sum on range.
// ******************************************************************
template<typename T>
class SegTree{
    size_t n;
    int h;
    const T identity_element = 0;
    vector<T> data;
    vector<T> lazy;
    void apply(size_t i, T v, size_t k){
        data[i] = data[i] + v * k;
        if (i < n) lazy[i] = lazy[i] + v;
    }
    void build(size_t i){      // update all the parents of node i.
        for (size_t k = 2; i > 1; k <<= 1, i >>= 1){
            data[i/2] = data[i] + data[i^1] + lazy[i/2] * k;
        }
    }
    void push(size_t p){       // propagates the changes from the root to node p.
        for (int s = h, k = 1 << (h - 1); s > 0; --s, k >>= 1){
            size_t i = p >> s;
            if (lazy[i] != 0){
                apply(i*2, lazy[i], k);
                apply(i*2+1, lazy[i], k);
                lazy[i] = 0;
            }
        }
    }
    int calc_h(size_t nn){
        int hh = 1;
        for (; nn > 1; ++hh, nn >>= 1);
        return hh;
    }
public:
    SegTree(size_t _n): n(_n), h(calc_h(n)), data(2 * n, 0), lazy(n, 0){}
    SegTree(const vector<T> &src): n(src.size()), h(calc_h(n)), data(2 * n, 0), lazy(n, 0){
        for (int i = 0; i != n; ++i) data[n + i] = src[i];
        for (int i = n - 1; i != 0; --i) data[i] = data[i*2] + data[i*2+1];
    }
    void add(size_t L, size_t R, T v){  // add v to range [L, R)
        L += n;
        R += n;
        size_t L0 = L;
        size_t R0 = R;
        for (size_t k = 1; L < R; L >>= 1, R >>= 1, k <<= 1){
            if (L & 1) apply(L++, v, k);
            if (R & 1) apply(--R, v, k);
        }
        build(L0);
        build(R0 - 1);
    }
    T query(size_t L, size_t R){
        L += n;
        R += n;
        push(L);
        push(R - 1);
        T ret = identity_element;
        for (; L < R; L >>= 1, R >>= 1){
            if (L & 1) ret += data[L++];
            if (R & 1) ret += data[--R];
        }
        return ret;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, q;
    cin >> n >> q;
    SegTree<long long> seg(n);
    while (q--){
        int c;
        cin >> c;
        if (c == 0){
            int s, t, x;
            cin >> s >> t >> x;
            seg.add(s - 1, t, x);
        }else{
            int s, t;
            cin >> s >> t;
            cout << seg.query(s - 1, t) << '\n';
        }
    }
    return 0;
}

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

int main()
{
  string a, b;
  int hit, blow;

  while( cin >> a >> b, a != "0" ) {
    hit = blow = 0;
    for(int i=0; i<4; i++) {
      if( a[i] == b[i] ) hit++;
    }

    for(int i=0; i<4; i++) {
      for(int j=0; j<4; j++) {
	if( i != j && a[i] == b[j] ) blow++;
      }
    }

    cout << hit << " " << blow << endl;
  }
}

Measured memory_bytes: 1180
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
            cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 3892
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define M 1000000007
#define ll long long
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define REPI(i,a,b) for(ll i=b-1;i>=a;i--)
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define G(a,b) get<a>(b)
#define VI vector<int>
#define VLL vector<long long>
 
#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set
 
ll modI(ll a, ll m);
ll gcd(ll a, ll b);
ll powM(ll x, unsigned ll y, unsigned ll m);
void pairsort(int a[], int b[], int n);
void pairsortll(ll a[],ll b[],ll n);
ll logint(ll x,ll y);
 
 
ll gcd(ll x,ll y)
{
    if(x==0) return y;
    return gcd(y%x,x);
}
 
ll powM(ll x,ll y,ll m)
{
    if(y==0) return 1;
    ll p=powM(x,y/2,m)%m;
    p=(p*p)%m;
    return (y%2==0)?p:(x*p)%m;
}
 
ll modI(ll a, ll m)
{
    ll m0=m,y=0,x=1;
    if(m==1) return 0;
    while(a>1)
    {
        ll q=a/m;
        ll t=m;
        m=a%m;
        a=t;
        t=y;
        y=x-q*y;
        x=t;
    }
    if(x<0) x+=m0;
    return x;
}
 
void pairsort(int a[],int b[],int n)
{
    pair<int,int> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
void pairsortll(ll a[],ll b[],ll n)
{
    pair<ll,ll> v[n];
    REP(i,0,n)
    {
        v[i].F=a[i];
        v[i].S=b[i];
    }
    sort(v,v+n);
    REP(i,0,n)
    {
        a[i]=v[i].F;
        b[i]=v[i].S;
    }
}
 
ll logint(ll x,ll y)
{
    ll ans=0;
    ll a=1;
    for(ll i=0;i<=x;i++)
    {
        if(x<a)
        {
            return ans;
        }
        ans++;
        a*=y;
    }
    return -1;
}
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
 
    /*
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    */
 
    ll q=1;
    //cin>>q;
    while(q--)
    {
        ll n,w;
        cin>>n>>w;
        ll dp[100001];
        dp[0]=0;
        REP(i,1,100001) dp[i]=1e18;
        REP(j,0,n)
        {
            ll t1,t2;
            cin>>t1>>t2;
            REPI(i,0,100001)
            {
                if(i+t2<100001) dp[i+t2]=min(dp[i+t2],dp[i]+t1);
            }
        }
        REPI(i,0,100001)
        {
            if(dp[i]<=w)
            {
                cout<<i;
                break;
            }
        }
    }
 
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<string>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<bitset>
#include<map>
#include<vector>
#include<string.h>
#include<algorithm>
#include<iostream>
#include<queue>
#include<deque>
#include<stack>
#include<cmath>
#include<ctime>
#include<complex>
#include<list>
using namespace std;

string s;
int num;

int main(){
	cin>>s;
	int num=s[0]-'0';
	for(int i=1;i<s.size();i++) if(s[i]<='8'){
		cout<<num+(s.size()-i)*9-1<<endl;
		return 0;
	}else num+=s[i]-'0';
	cout<<num<<endl;
	return 0;
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
#define FO(i, a, b) for (int i = a; i <= b; i++)
#define FE(i, a, b) for (int i = a; i < b; i++)
#define FR(i, a, b) for (int i = a; i >= b; i--)
#define R(i) i = read()

using namespace std;

int read() {
	int x = 0; char c = getchar();
	while((c != '-') && (c < 48 || c > 57)) x = x * 10 + c - 48, c = getchar();
	if(c == '-') {c = getchar(); while(c >= 48 && c<= 57) x = x * 10 - c + 48, c = getchar();}
	else while(c >= 48 && c<= 57) x = x * 10 + c - 48, c = getchar();
	return x;
}

int n, a, b;

char c[10000];

int main() {
	scanf("%s", c);
	int l = strlen(c);
	FE(i, 0, l - 8) {
		cout << c[i];
	}
	return 0;
}

Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::collections::HashMap;
fn main() {
    input! {
        n: usize,
        s: [String; n],
        m: usize,
        t: [String; m],
    }
    let mut d = s.iter().map(|c| (c, 0)).collect::<HashMap<_, _>>();
    for i in 0..s.len() {
        //d[&s[i]]+=1;
        if let Some(x) = d.get_mut(&s[i]) {
            *x += 1;
        }
    }
    for j in 0..t.len() {
        if d.contains_key(&t[j]) {
            //d[&t[i]]-=1;
            if let Some(x) = d.get_mut(&t[j]) {
                *x -= 1;
            }
        }
    }
    let mut max = 0;
    for (_, &v) in d.iter() {
        if max <= v {
            max = v;
        }
    }
    println!("{}", max);
}

Measured memory_bytes: 4352
import re

n = input()
n = int(n)

sum = 0.

for i in range(1,n+1):
	line =input()
	li = line.split(" ")
	
	u = li[1]
	
	if u == 'JPY':
		sum += int(li[0])
	elif u == 'BTC':
		sum += float(li[0]) * 380000.0

print(sum)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
using namespace std;

typedef long long ll;

vector<pair<int,int> > lst;
const int MAXN = 1e9;

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n, k, s;
	cin>>n>>k>>s;
	for(int i = 1;i <= k;i++) cout<<s<<" ";
	for(int i = k + 1;i <= n;i++) {
		if(s != MAXN) cout<<MAXN<<" ";
		else cout<<MAXN - 1<<" ";
	}
	cout<<endl;
}

Measured memory_bytes: 1280
N = gets.to_i
h = gets.split.map(&:to_i)
h.unshift(0)
h.push(0)
count = 0
now = false
count_b = 0


while true do
  for i in 1..N do
    if !now && h[i] > 0 && h[i-1] == 0
      h[i] -= 1
      if h[i+1] == 0
        count += 1
      else
        now = true
      end
    elsif now && h[i] > 0
      h[i] -= 1
      if h[i+1] == 0
        now = false
        count += 1
      end
    end
  end

  break if count == count_b
  count_b = count
end

puts count


Measured memory_bytes: 1788
#include <bits/stdc++.h>
typedef unsigned long long ll;
using namespace std;
 
 
 
int main() {
    ll n ; cin>>n; ll a=0 ;
 
    for(int i = 1 ; i <=sqrtl(n) ; i++){
        ll k = n/i;
        if(n%i==0){
            int x=0;
            if(i>=k){
                x=k;
            }
            else{
                x=i;
            }
            if(a<x){
                a=x;
            }
        }
    }
   
    cout<<a+n/a-2;
    
}

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

int p[35][35];
int memo[33][33][33][33];
int M = 1000000007;

//[l, r), [u, d)
// max bunkatu
int dfs(int l, int r, int u, int d, int mi) {
    if (memo[l][r][u][d] != -1) return memo[l][r][u][d];
    int sum = 0;
    for (int i = l; i < r; ++i) {
        for (int j = u; j < d; ++j) {
            sum += p[i][j];
        }
    }
    if (sum < mi) {
        return memo[l][r][u][d] = -M;
    }
    int ret = 1;
    for (int i = l + 1; i < r; ++i) {
        ret = max(ret, dfs(l, i, u, d, mi) + dfs(i, r, u, d, mi));
    }
    for (int i = u + 1; i < d; ++i) {
        ret = max(ret, dfs(l, r, u, i, mi) + dfs(l, r, i, d, mi));
    }
    return memo[l][r][u][d] = ret;
}
int main() {
    while (1) {
        int h, w, s;
        cin >> h >> w >> s;
        if (!h) return 0;
        int sum = 0;
        for (int i = 0; i < h; ++i) {
            for (int j = 0; j < w; ++j) {
                cin >> p[i][j];
                sum += p[i][j];
            }
        }
        for (int i = 0; i < 33; ++i) {
            for (int j = 0; j < 33; ++j) {
                for (int k = 0; k < 33; ++k) {
                    for (int l = 0; l < 33; ++l) {
                        memo[i][j][k][l] = -1;
                    }
                }
            }
        }
        int ma = dfs(0, h, 0, w, sum - s);
        int ok = sum - s, ng = sum + 1;
        while (ok + 1 < ng) {
            int m = (ok + ng) / 2;
            for (int i = 0; i < 33; ++i) {
                for (int j = 0; j < 33; ++j) {
                    for (int k = 0; k < 33; ++k) {
                        for (int l = 0; l < 33; ++l) {
                            memo[i][j][k][l] = -1;
                        }
                    }
                }
            }
            if (dfs(0, h, 0, w, m) == ma) {
                ok = m;
            }
            else {
                ng = m;
            }
        }
        cout << ma << " " << (s- sum + ok) << "\n";
    }
}

Measured memory_bytes: 7708
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <limits>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<int,int>
#define x first
#define y second
#define sf scanf
#define pf printf
#define vec vector
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(a) a.begin(),a.end()
#define clr(a,b) memset(a,b,sizeof(a))
#define bin_cnt(x) __builtin_popcount(x)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define srep(sub,s) for(int sub=s&(s-1);sub;sub=(sub-1)&s)
#define irep(i,a) for(__typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define irrep(i,a) for(__typeof(a.rbegin()) i=a.rbegin();i!=a.rend();i++)
#define inf numeric_limits<int>::max()
#define finf numeric_limits<double>::infinity()
#define eps 1e-8
#pragma GCC optimize ("O3")
#define o3 __attribute__((optimize("O3")))
#pragma comment(linker, "/STACK:32505856")

template<class T> inline T sqr(T a) {return a*a;}
template<class T> inline int gmin(T&a,T b) {if(a>b){a=b;return 1;}return 0;}
template<class T> inline int gmax(T&a,T b) {if(a<b){a=b;return 1;}return 0;}
inline int dcmp(const double &a) {return a>eps?1:(a<-eps?-1:0);}
struct Initializer{Initializer(){ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);}}initializer;

char st[1024];
int main() {
  while (~sf("%s",st)) {
    int len = strlen(st);
    rep(i,0,3) pf("%c",st[i]);
    putchar(' ');
    rep(i,4,len-1) pf("%c",st[i]);
    putchar('\n');
  }
  return 0;
}


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

using namespace std;
using ll = long long;
ll mod = 1000003;
ll fact[1111111];

ll po(ll a, ll b)
{
  if (b == 0)return 1;
  ll z = po(a, b / 2);
  z = z*z%mod;
  if (b % 2 == 1)z = z*a%mod;
  return z;
}
ll inv(ll a)
{
  return po(a, mod - 2);
}

int main() {
  ll Q;
  cin >> Q;
  fact[0] = 1;
  for (int i = 0; i < mod + 10; i++)
    fact[i + 1] = fact[i] * (i + 1) % mod;
  ll x[Q], d[Q], n[Q];
  for (int i = 0; i < Q; ++i) {
    cin >> x[i] >> d[i] >> n[i];
  }
  for (int i = 0; i < Q; ++i) {
    if (d[i]==0)
      cout << po(x[i], n[i]) << endl;
    else{
      ll first=x[i]*inv(d[i])%mod;
      ll end=first+n[i]-1;
      if(first<=mod && mod <= end)
        cout << 0 << endl;
      else{
        ll a = fact[end]*inv(fact[first-1]) % mod;
        cout << a*po(d[i],n[i]) %mod << endl;
      }
    }
  }

}


Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pp;

int main() {
    int N;
    cin >> N;
    vector<int> X(N);
    for(int i=0; i<N; ++i) cin >> X[i];

    vector<pp> Y(N);
    for(int i=1; i<=N; ++i) Y[i-1] = pp(X[i-1], i);
    sort(Y.begin(), Y.end());
    map<int, int> Z;
    for(int i=1; i<=N; ++i) Z[Y[i-1].second] = i;

    for(int i=1; i<=N; ++i) {
        if(Z[i] <= N/2) cout << Y[N / 2].first << endl;
        else cout << Y[N / 2 - 1].first << endl;
    } 
    return 0;
}

Measured memory_bytes: 13952
import java.util.*;
public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long x = sc.nextLong();
    long aa = a/x;
    long bb = b/x;
    
    
    if(a%x==0) System.out.println(bb-aa+1);
    else  System.out.println(bb-aa);

  }
}

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

int main() {
    string S, T;
    cin >> S >> T;

    int Slen = S.size(), Tlen = T.size();
    string ans = "";

    for (int i = Slen - Tlen; i >= 0; i--) {
        string Scopy = S;
        bool restorable = true;

        for (int j = 0; j < Tlen; j++) {
            if (Scopy[i+j] == T[j] || Scopy[i+j] == '?') {
                Scopy[i+j] = T[j];
            } else {
                restorable = false;
                break;
            }
        }

        if (restorable) {
            for (int j = 0; j < Slen; j++) {
                if (Scopy[j] == '?') {
                    Scopy[j] = 'a';
                }
            }

            if (ans == "") {
                ans = Scopy;
            } else {
                ans = min(ans, Scopy);
            }
        }
    }

    if (ans == "") {
        cout << "UNRESTORABLE" << endl;
    } else {
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    int n, m;
    cin >> n >> m;
    vector<pair<int,int>> v;
    rep(i,m){
        int a,b;
        cin >> a >> b;
        v.push_back({b,a});
    }
    int cnt = 1;
    int right = 0;
    sort(v.begin(), v.end());
    rep(i,m){
        if(i == 0) right = v[i].first;
        else{
            if(right <= v[i].second){
                cnt++;
                right = v[i].first;
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

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

    ll n, a, b, c;
    cin>>n>>a>>b>>c;
    vl ls(n);
    cin>>ls;

    ll ans = LINF;
    rep(i, 1<<(2 * n)) {
        ll res = 0;
        ll temp = i;
        vl g(4);
        rep(j, n) {
            if (temp % 4 != 3 && g[temp % 4] != 0) res += 10;
            g[temp % 4] += ls[j];
            temp /= 4;
        }
        if (g[0] == 0 || g[1] == 0 || g[2] == 0) continue;
        res += abs(g[0] - a) + abs(g[1] - b) + abs(g[2] - c);
        chmin(ans, res);
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
import fractions
from functools import reduce

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

N=int(input())
A = list(map(int,input().split()))
MOD = 1000000007

lcm = lcm_list(A)
ans = 0
for i in range(N):
  ans = (ans + (lcm // A[i]))
print(ans % MOD)


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

int main() {
    int n, a[3000], f_m = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        f_m += a[i] - 1;
    }

    cout << f_m << endl;
}

Measured memory_bytes: 504
using System;

namespace AtCoderProblems
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int ans = 0;

            for(int i = 0; i < str.Length; i++)
            {
                int a = int.Parse(str[i]);
                if(a == 0)
                {
                    ans = i + 1;
                }
            }

            Console.WriteLine(ans);

        }
    }

}

Measured memory_bytes: 27476
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(A, B):
    if A <= 5:
        return 0
    elif A <= 12:
        return B//2
    return B


def main():
    # N = read_int()
    A, B = read_int_n()
    # A = [read_int_n() for _ in range(N)]
    print(slv(A, B))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7264
using System;
using System.Collections.Generic;//list用
using System.Text;//StringBuilder用
using System.Collections;//ハッシュテーブル用
using System.Linq;

class Program
{
    //Hashtable ht = new Hashtable();
    static List<int> s = new List<int>();
      static List<int> a = new List<int>();
      static List<int> b = new List<int>();
      static List<int> c = new List<int>();
    static decimal result;
    static int N,K;
    //StringBuilder strresult= new StringBuilder("");//Append(str ○○)関数で文字を追加していく


    static void Main()
    {
        //Modular mo = new Modular(0);//素数で割った余りを出せで使う。()内が初期値。★使い方：Modular型で宣言すると、その時点でのその素数で割った余りを保持する変数になる（powべき乗、Fac累乗、nCr組み合わせも関数として存在）
        //Node<> no = new Node<>();//UnionFind★Find関数で根っこの値を返す（根っこの値が一緒なら同グループ）、Unite関数で二つの木をくっつける
        //Permutation<> pe = new Permutation<>();//配列＆リストを並べ替えた場合の全ケースを出力★All関数でリスト形式で返す。
        //Treap<> tr = new Treap<>();//平衡二分木★Insert()関数で挿入、FindIndex()関数で該当する大きさの物が入るべき配列番号を返す。
        //PriorityQueue<int,int> pr = new PriorityQueue<int,int>();//優先度付キュー★Add(key,value)で格納、Dequeue()で取りだし。keyが小さいものから取り出す。
Read3();
      result=-1;
      N=s[0];
      K=s[1];
if(N>=10 || K>=10){Console.WriteLine(result.ToString());return;}
result=N*K;
        Console.WriteLine(result.ToString());

    }

  
  
  
    static void Read1()//1項
    {
        string tmp = Console.ReadLine();
        N = int.Parse(tmp);
    }

    static void Read2()//複数項（項目数Ｎ）
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < N; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read3()//1行複数項
    {
        string[] tmp = Console.ReadLine().Split(' ');
        for (int i = 0; i < tmp.Length; i++) { s.Add(int.Parse(tmp[i])); }
    }
    static void Read4()//NK１行
    {
        string[] tmp = Console.ReadLine().Split(' ');
        N = int.Parse(tmp[0]);
        K = int.Parse(tmp[1]);
    }
    static void Read5()//N行K項
    {
      for(int i=0;i<K;i++)
      {
        string[] tmp = Console.ReadLine().Split(' ');
        a.Add(int.Parse(tmp[0]));
        b.Add(int.Parse(tmp[1]));
        c.Add(0);
        string[] tmp2 = Console.ReadLine().Split(' ');
        for(int j=0;j<b[i];j++){c[i]+=(int)Math.Pow(2,int.Parse(tmp2[j])-1);}
      }
    }
}


Measured memory_bytes: 13140
#include <iostream>

using namespace std;

int main()
{
    string s[7]={"SUN","MON","TUE","WED","THU","FRI","SAT"};
    string word;
    getline(cin,word);
    for(int i=7,k=0;i>=1;i--,k++){
        if(word==s[k])
            cout<<i;
    }
 return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll A;
    string B;
    cin >> A >> B;
    ll C = 0;
    REP(i, B.size()) {
        if (B[i] == '.')
            continue;
        C = C * 10 + (B[i] - '0');
    }

    ll X = (A * C) / 100LL;
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long n, ans[101001]={0}, x, y, z;
    cin >> n;
    for(x=1;x<=1000;x++){
        for(y=1;y<=1000;y++){
            for(z=1;z<=1000;z++){
                long long tmp;
                tmp=x*x+y*y+z*z+x*y+y*z+z*x;
                if(tmp<=10000){
                    ans[tmp]++;
                }
            }
        }
    }
    for(int i=1;i<=n;i++){
        cout << ans[i] <<endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin>>N;
  vector<char>C(N);
  int w=0;
  int r=0;
  int migi=0;
  int M=0;
  for(int i=0;i<N;i++){
    cin>>C[i];
    if(C[i]=='W'){
      w++;
    }
    else{
      r++;
    }
  }
  if(C[0]=='R'){
    migi++;
    for(int i=0;i<N;i++){
      if(C[i+1]=='R'){
        migi++;
      }
      else{
        break;
      }
    }
  }
  for(int i=0;i<r;i++){
    if(C[i]=='W'){
      M++;
    }
  }
  int ans=0;
  cout<<min(M,r)<<endl;
}

Measured memory_bytes: 3640
#include<iostream>
#include<queue>
#include<cstdint>
using namespace std;

const int MAX = 100000;
typedef struct {
	queue<pair<int, int> > branch;
	int64_t distance;
} Tree;
int main() {
	int N, Q, K, a, b, c, z, x, y;
	static Tree node[MAX];
	cin >> N;
	for (int i = 1;i < N;i ++) {
		cin >> a >> b >> c;
		node[a - 1].branch.push(make_pair(b - 1, c));
		node[a - 1].distance = -1;
		node[b - 1].branch.push(make_pair(a - 1, c));
		node[b - 1].distance = -1;
	}
	cin >> Q >> K;
	node[K - 1].distance = 0;
	queue<int> que;
	que.push(K - 1);
	pair<int, int> branch;
	while(!que.empty()) {
		z = que.front();
		que.pop();
		while(!node[z].branch.empty()) {
			branch = node[z].branch.front();
			node[z].branch.pop();
			if (node[branch.first].distance == -1) {
			node[branch.first].distance = node[z].distance + branch.second;
			que.push(branch.first);
			}
		}
	}
	/*for (int i = 0;i < N;i ++) {
		cout << node[i].distance << " ";
	}*/
	
	cin >> x >> y;
	cout << node[x - 1].distance + node[y - 1].distance;
	for (int i = 1;i < Q;i ++) {
		cin >> x >> y;
		cout << endl << node[x - 1].distance + node[y - 1].distance;
	}
	return 0;
}

Measured memory_bytes: 70144
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.stream.Collectors;

public class Main {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner(System.in);
		final String S = scan.next();
		final int l = S.length();

		int numberL = 0;
		int numberR = 0;
		char previous = 'R';
		Integer[] ans = new Integer[l];
		for (int i = 0; i < l; i++) {
			ans[i] = 0;
		}
		for (int i = 0; i < l - 1; i++) {
			if (S.charAt(i) == 'R') {
				if (previous == 'R') {
					numberR++;
				} else {
					ans[i - numberL - 1] += (numberL - (numberL % 2)) / 2;
					ans[i - numberL] += (numberL + (numberL % 2)) / 2;
					numberL = 0;
					numberR++;
					previous = 'R';
				}
			} else {
				if (previous == 'L') {
					ans[i] = 0;
					numberL++;
				} else {
					ans[i - 1] += (numberR + (numberR % 2)) / 2;
					ans[i] += (numberR - (numberR % 2)) / 2;
					numberR = 0;
					numberL++;
					previous = 'L';
				}
			}
		}
		if (previous == 'L') {
			numberL++;
			ans[l - 1] = 0;
			ans[(l - 1) - numberL] += (numberL - (numberL % 2)) / 2;
			ans[(l - 1) - numberL + 1] += (numberL + (numberL % 2)) / 2;
		} else {
			ans[l - 2] += (numberR + (numberR % 2)) / 2;
			ans[l - 1] = (numberR - (numberR % 2)) / 2 + 1;
		}

		String output = Arrays.asList(ans).stream()
				.map(n -> String.valueOf(n))
				.collect(Collectors.joining(" "));
		System.out.println(output);

	}

	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());
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}
	}

}


Measured memory_bytes: 34828
N=int(input())
if N&(N-1)==0:
    print("No")
else:
    print("Yes")
    if N%2==1:
        k=N//2
        for i in range(1,k+1):
            print(2*i,2*i+1)
            print(2*i+1,1)
            print(1,2*i+N)
            print(2*i+N,2*i+1+N)
        print(1+N,2)
    else:
        k=N//2-1
        for i in range(1,k+1):
            print(2*i,2*i+1)
            print(2*i+1,1)
            print(1,2*i+N)
            print(2*i+N,2*i+1+N)
        print(1+N,2)
        n=N.bit_length()-1
        a=2**n
        b=N+1-a
        print(N,a+N)
        print(2*N,b)


Measured memory_bytes: 77484
#include<iostream>
#include<string.h>
using namespace std;

int main(){
  int n,i,p1=0,p2=0;
  string str1,str2;

  cin >> n;

  for (i = 0 ; i < n; i++){
    cin >> str1 >> str2;
    string in1 = str1.substr(0) ;
    string in2 = str2.substr(0) ;
    
    if ( in1 < in2)p2 += 3;
    if ( in1 == in2 ) {
      p1++;
      p2++;
    }
    if ( in1 > in2 ) p1 += 3;
  }

  cout << p1 << " " <<p2 <<endl;

  return 0;
}

Measured memory_bytes: 1216
import sys
import re
import math
import collections
import decimal
import bisect

# import copy
# import heapq
# from collections import deque
# import decimal

# sys.setrecursionlimit(100001)
INF = sys.maxsize
# MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    x = ni()

    for a in range(-200,200):
        for b in range(-200,200):
            if a**5-b**5 == x:
                print(a,b)
                exit(0)




if __name__ == '__main__':
    main()


Measured memory_bytes: 10192
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

// Poor Computer
// 2012/12/29
public class Main{
	Scanner sc=new Scanner(System.in);

	int n;
	int[] a;
	int max=42;

	void run(){
		n=sc.nextInt();
		a=new int[n];
		for(int i=0; i<n; i++){
			a[i]=sc.nextInt();
		}
		solve();
	}

	long end;
	int ub;

	void solve(){
		end=0;
		for(int i=0; i<n; i++){
			end|=1L<<a[i];
		}
		for(int t=n-1; t<max; t++){
			ub=t;
			if(dfs(1L<<1, 0)){
				println(ub+"");
				break;
			}
		}
	}

	boolean dfs(long s, int step){
		if(step+Long.bitCount(end&~s)>ub){
			return false;
		}
		if((end&s)==end){
			return true;
		}
		for(long s1=s; s1!=0; s1&=s1-1){
			int i=Long.numberOfTrailingZeros(s1);
			for(long s2=s; s2!=0; s2&=s2-1){
				int j=Long.numberOfTrailingZeros(s2);
				if(i+j<=max&&(s>>(i+j)&1)==0){
					if(dfs(s|(1L<<(i+j)), step+1)){
						return true;
					}
				}
				if(abs(i-j)>0&&(s>>abs(i-j)&1)==0){
					if(dfs(s|(1L<<abs(i-j)), step+1)){
						return true;
					}
				}
			}
			for(; i<=max; i<<=1){
				if((s>>i&1)==0){
					if(dfs(s|(1L<<i), step+1)){
						return true;
					}
				}
			}
		}
		return false;
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#define mem(a,n) memset(a,n,sizeof(a))
#define rep(i,a,b) for(int i=a;i<b;i++)
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
const double eps=1e-6;
const int MOD=1e5+3;
const int INF=0x3f3f3f3f;
const int N=1e5+5;
int main()
{
    int n,a,b;
    while(~scanf("%d%d%d",&n,&a,&b))
    {
        int d1=b-a-1;
        if(d1%2==1) puts("Alice");
        else puts("Borys");
    }
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N = int(input())
hn = list(map(int, input().split()))

def f(hn):
    cnt = min(hn)
    hn2 = [h - cnt for h in hn]
    sub_hn = []
    tmp = []
    for h in hn2:
        if h == 0:
            if len(tmp) > 0:
                sub_hn.append(tmp)
                tmp = []
        else:
            tmp.append(h)

    if len(tmp) > 0:
        sub_hn.append(tmp)

    return cnt + sum(map(f, sub_hn))

print(f(hn))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
/*
string S_str[H];
cins(S_str, S_str + H);
S_str[i][j];
*/
inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i, n) for(ll i = 0; i < n; i++)


int main(){
  ll n;
  cin >>n;
  ll sum=0;
  rep(i,n)
  if((i+1)%3!=0 && (i+1)%5!=0){

    sum += i+1;
  }
  cout << sum<< endl;

}


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

// #define int long long
#define rep(i, n) for (long long i = (long long)(0); i < (long long)(n); ++i)
#define reps(i, n) for (long long i = (long long)(1); i <= (long long)(n); ++i)
#define rrep(i, n) for (long long i = ((long long)(n)-1); i >= 0; i--)
#define rreps(i, n) for (long long i = ((long long)(n)); i > 0; i--)
#define irep(i, m, n) for (long long i = (long long)(m); i < (long long)(n); ++i)
#define ireps(i, m, n) for (long long i = (long long)(m); i <= (long long)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) long long(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll,ll,ll>>;
using vb = vector<bool>;

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; }

const ll INF = 1e9;
const ll MOD = 1e9+7;
const ll LINF = 1e18;




signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  string s; cin>>s;
  ll n=s.size();
  ll ans=0;
  ll b=0;
  rep(i,n){
    if(s[i]=='W') ans+=b;
    else b++;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 720
#include <bits/stdc++.h>
#define fast_io() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define PI 3.14159265
#define MOD 1000000007
#define PSET(x,y) fixed<<setprecision(y)<<x
#define ll long long
#define ld long double
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define lop(i,a,b) for(ll i=a;i<b;i++)
#define lopr(i,a,b) for(ll i=a;i>=b;i--)
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define eb emplace_back
#define fi first
#define se second
#define pi pair<int,int>
#define pll pair<ll, ll>
#define si set<int>
#define sll set<ll>
#define maxheap priority_queue<int>
#define minheap priority_queue<int,vector<int>,greater<int>>
#define state tuple<int,int,int>
#define graph map<ll,list<ll>>

inline int sbt(int x){return __builtin_popcount(x);} //returns number of set bits

using namespace std;

#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

graph g;

bool func(int i, set<int> s){

	s.insert(i);

	if(s.size()==4)
		return true;

	for(auto ele: g[i])
		if(s.find(ele)==s.end())
			if(func(ele,s))
				return true;

	return false;
}

int main(){
    // #ifndef ONLINE_JUDGE
    //     freopen("input.txt", "r", stdin);
    //     freopen("output.txt", "w", stdout);
    // #endif
    
    fast_io()
    
    lop(i,0,3){
    	int a,b;
    	cin>>a>>b;

    	g[a].pb(b);
    	g[b].pb(a);
    }

    bool flag=false;
    lop(i,1,5){
    	set<int> s;
    	flag = func(i,s);
    	if(flag){
    		cout<<"YES";
    		return 0;
		}
    }

    cout<<"NO";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF 1e9
#define dump(x) cerr<<#x<<"="<<x<<endl
#define all(a) (a).begin(),(a).end()
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<vii> viii;
typedef pair<int,int> P;
template <class T> void chmin(T & a, T const & b) { if (b < a) a = b; }
#define int long long
using ll = long long;
const ll mod = LLONG_MAX;

int N,H;
P a[100010];
P c[100010];
signed main(){
  cin>>N>>H;
  int temp=-INF;
  rep(i,N){
    cin>>a[i].second>>a[i].first;
   if(temp<a[i].second)temp=a[i].second;

  }


  sort(a,a+N);
  reverse(a,a+N);

  rep(i,N){
    dump(a[i].first);
  }
  dump(temp);

  int idx=0;
  while(1){
    if(H<=0 || idx==N || temp>a[idx].first)break;
    H-=a[idx].first;
    idx++;
  }
  dump(H);

  if(H<=0)cout<<idx<<endl;
  else if(H%temp==0)cout<<idx+((H)/temp)<<endl;
  else cout<<idx+((H)/temp)+1<<endl;



}


Measured memory_bytes: 1024
# import math
# import statistics
#a=input()
#b,c=int(input()),int(input())
# c=[]
# for i in a:
#    c.append(i)
e1,e2,e3 ,e4= map(int,input().split())
#K = input()
# f = list(map(int,input().split()))
#g = [input() for _ in range(a)]

if e4%2==0 or e4==0:
    print(e1-e2)
elif e4%2==1 :
    print(-(e1-e2))
elif abs(e1-e2)>=10**18:
    print("Unfair")

Measured memory_bytes: 8888
#include <deque>
#include <cstdio>
#include <algorithm>

using namespace std;

typedef long long LL;

deque<int> a, b;

int Solve(LL n)
{
	if (n == 1)
	{
		a.push_front(1);
		b.push_front(1);
		return 1;
	}
	if (n & 1)
	{
		int p = Solve(n >> 1) + 1;
		a.push_back(p);
		b.push_back(p);
		return p;
	}
	else
	{
		int p = Solve(n - 1) + 1;
		a.push_front(p);
		b.push_back(p);
		return p;
	}
}

int main()
{
	LL n;
	scanf("%lld", &n);
	Solve(n);
	printf("%d\n", a.size() + b.size());
	for (; !a.empty(); a.pop_front()) printf("%d ", a.front());
	for (; !b.empty(); b.pop_front()) printf("%d ", b.front());
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
using namespace std;
bool C(double a,double b,double c,double d){return a*d-b*c>=0;}
main()
{
	double a,b,c,d,e,f,g,h;
	while(~scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a,&b,&c,&d,&e,&f,&g,&h))
	{
		int cnt=C(e-c,f-d,a-c,b-d)+C(g-e,h-f,c-e,d-f)+C(a-g,b-h,e-g,f-h)+C(c-a,d-b,g-a,h-b);
		cout<<(cnt==0||cnt==4?"YES":"NO")<<endl;
	}
}


Measured memory_bytes: 3224