akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <bitset>
#include <cmath>
#include <ctime>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <stdio.h>
#include <string>
#include <vector>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(),a.end()
using namespace std;
// using ll = long long;
// using P = pair<int,int>;
// using vi = vector<int>;
// using vvi = vector<vi>;







template <typename T>
T gcd(T a, T b) {
  if(b == 0) return a;
  else return gcd(b,a%b);
}



int main() {
  int N;
  cin >> N;
  if(N%10 == 2 || N%10 == 4 ||N%10 == 5 || N%10 == 7 || N%10 == 9){
    cout << " hon " << endl;
  }
  else if(N%10 == 0 || N%10 == 1 ||N%10 == 6 || N%10 == 8){
    cout  << " pon " << endl;
  }
  else cout << " bon " << endl;
    


  
  return 0;
}





Measured memory_bytes: 3000
#include <iostream>

using namespace std;

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    
    while (K > 0) {
        if (B <= A)
            B *= 2;
        else
            break;
        K--;
    }

    while (K > 0) {
        if (C <= B)
            C *= 2;
        else
            break;
        K--;
    }

    if (C > B && B > A)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

Measured memory_bytes: 3588
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
n,m = map(int,input().split())
wa_cnt = [0]*n
pena = 0
solve = 0
for i in range(m):
  p,s = map(str,input().split())
  if s == "WA":
    wa_cnt[int(p)-1] += 1
  else:
    if wa_cnt[int(p)-1] >= 0:
      pena += wa_cnt[int(p)-1]
      solve += 1
      wa_cnt[int(p)-1] = -100010
print(solve,pena)

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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

bool DEBUG = 0;

template<class T> void dprint(T s){
  if(DEBUG){ cout << s << "\n"; }
}


int main(int argc,char* argv[]){
  if(argc>1 && argv[1][0]=='D'){ DEBUG=1;}
  dprint("start");

  int N; cin>>N;
  ll x[N],y[N],p[N];
  REP(i,N){
    cin >> x[i] >> y[i] >> p[i];
  }
  dprint("input");

  //　前処理
  ll xc[1<<N][N];
  ll yc[1<<N][N];
  for(ll bits=0LL; bits<(1<<N);++bits){
    REP(i,N){
      xc[bits][i] = abs(x[i]);
      yc[bits][i] = abs(y[i]);
      REP(j,N){
        if( (bits>>j) & 1){
          chmin(xc[bits][i],abs(x[i]-x[j]));
          chmin(yc[bits][i],abs(y[i]-y[j]));
        }
      }
    }
  }
  for(ll bits=0LL; bits<(1<<N);++bits){
    REP(i,N){
      xc[bits][i] *= p[i];
      yc[bits][i] *= p[i];
    }
  }

  ll ans[N+1];
  FILL(ans,N+1,-1);
  // 道を通す集落にビットを立てる
  for(ll bits=0LL; bits<(1<<N);++bits){
    int num = 0;
    REP(i,N){
      if((bits>>i)&1){
        ++num;
      }
    }
    // 部分集合を取る
    for(int cits = bits; ;cits=(cits-1)&bits){
      ll temp = 0LL;
      REP(j,N){
        if( !( (cits>>j)&1) ){
          temp += min( xc[cits][j],yc[bits-cits][j] );
        }
      }
      if(ans[num]>=0){
        chmin(ans[num],temp);
      }else{
        ans[num] = temp;
      }
      if(!cits){break;}
    }
  }
  REP(i,N+1){
    cout << ans[i] << "\n";
  }
}

Measured memory_bytes: 11324
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

A = INT()
B = INT()
C = INT()
D = INT()
E = INT()

tmp1 = [A, B, C, D, E]
tmp2 = [x%10 for x in tmp1]
min_=10 # 最後に頼む料理
index = None
for i in range(len(tmp2)):
	if tmp2[i] != 0:
		if tmp2[i] < min_:
			min_ = tmp2[i]
			index = i
for i in range(len(tmp1)):
	if i == index:
		continue
	if tmp1[i]%10 != 0:
		tmp1[i] = (tmp1[i] - tmp1[i]%10) + 10
print(sum(tmp1))

Measured memory_bytes: 4136
A, B, C, D, E, F = map(int,input().split())
answer_number = [0,0,0,0]
answer_max = 0
for i in range((F//(100*A))+1):
  for j in range(((F-100*A*i)//(100*B))+1):
    if i==0 and j ==0: continue
    for k in range(((F-100*A*i-100*B*j)//C)+1):
      for l in range(((F-100*A*i-100*B*j-C*k)//D)+1):
        if (C*k+D*l)/(A*i+B*j) <= E:
          if (C*k+D*l)/(A*i+B*j) > answer_max:
            answer_max = (C*k+D*l)/(A*i+B*j)      #### k
            answer_number = [i,j,k,l]
if answer_max == 0: print(100*A,0)
else:
  print(C*answer_number[2]+D*answer_number[3]+100*(A*answer_number[0]+B*answer_number[1]), C*answer_number[2]+D*answer_number[3])
  


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

int main() {
  // Toll Gates
  int n, m, x; cin >> n >> m >> x;
  int lc=0, rc=0;
  rep(i,m) {
     int ai; cin >> ai;
     if (ai < x) lc++;
     else rc++;
  }
  cout << min(lc,rc) << endl;
  return 0;
}

Measured memory_bytes: 3628
using System;
using System.Collections.Generic;

namespace c
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			// ????????????????????????
			int N = int.Parse (Console.ReadLine());
			int[] input = new int[N];
			// ????????????????????????????????????
			for (int i = 0; i < N; i++) {
				input[i] = int.Parse (Console.ReadLine ());
			}
			// ?????§??????????????§???????????£?????°??????
			ShellSort shellSort = new ShellSort();
			shellSort.sort (input);			
		}
	}

	public class ShellSort	
	{
		private int cnt = 0;

		// ?????§????????????
		public void sort(int[] array) {

			List<int> G = new List<int>();
			int m = 0;

			this.cnt = 0;

			// G??¢??°????¨???? G: (G_n+1 = 3 * G_n + 1)
			for (int i = 0; i < array.Length; i++) {
				if (i == 0) {
					G.Add (1); // G[0] = 1 ??¨????????????
					continue;
				}
				// ?????¨???g??????????¨????
				int g_now = (3 * G [i - 1]) + 1;
				// ??????????????????????°?????????´??????G??¢??°?????????
				if (array.Length < g_now) {
					break;
				}
				G.Add (g_now);
			}

			// G???????????????????????????????????¨?????? before: 1,4,13,40... => ... 40,13,4,1
			G.Reverse();

			// G???????´???°
			m = G.Count;

			for (int i = 0; i < m; i++) {
				// ?????\?????????
				this.insertionSort(array, array.Length, G[i]);
			}

			// ????????????
			// 1: m?????? 2: G??¢??°???????????????????????? 3: cnt?????? 4: ??´??????????????????1???????????????????????????

			// 1.
			Console.WriteLine (m);

			// 2.
			for (int i = 0; i < G.Count; i++) {
				if (i == G.Count - 1) {
					Console.WriteLine (G [i]);
					continue;
				}
				Console.Write(G[i] + " ");
			}

			// 3.
			Console.WriteLine(this.cnt);

			// 4.
			for (int i = 0; i < array.Length; i++) {
				Console.WriteLine(array[i]);				
			}
		}

		// ?????\?????????
		private void insertionSort(int[] array, int n, int g) {
			for (int i = g; i < n; i++) {
				int v = array [i];
				int j = i - g;
				while (j >= 0 && array [j] > v) {
					array [j + g] = array [j];
					j = j - g;
					this.cnt++;
				}
				array [j + g] = v;
			}
		}
	}
}

Measured memory_bytes: 16528
#include <iostream>

using namespace std;

int main() {
    long long a, b, k;
    cin >> a >> b >> k;

    if (a >= k) {
        cout << a - k << " " << b << endl;
    } else if (a + b >= k) {
        cout << 0 << " " << (a + b) - k << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#define rep(i,l,r) for(ll i=l;i<r;i++)
typedef long long ll;
int main() {
	ll h,w,k;
	scanf("%lld%lld%lld", &h, &w,&k);
	char map[7][7];
	rep(i, 0, h) {
		scanf("%s", map[i]);
	}
	ll ans = 0;
	rep(i, 0, 1<<h) {
		rep(j, 0, 1<<w) {
			ll sum = 0;
			rep(k, 0, h) {
				rep(l, 0, w) {
					if (!(i & (1 << k)) && !(j & (1 << l)) && map[k][l] == '#') sum++;
				}
			}
			if (sum == k) ans++;
		}
	}
	printf("%lld", ans);
	return 0;
}

Measured memory_bytes: 1708
import std.stdio;
import std.array;

void main(){

    int N,num,res;
    bool flag;

    res = 0;
    readf("%d\n",&N);
    for(int i=0;i<N;i++){

	readf("%d\n",&num);
	flag = true;
	for(int j=2;j*j<=num;j++){
	    if(num % j == 0) {
		flag = false;
		break;
	    }
	}
	if(flag) res++;
    }
    writeln(res);
}

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

public class Main {
    public static void main(String[] args) {
        final Scanner in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        final int n = in.nextInt();
        System.out.println(n * n * n);
    }
}


Measured memory_bytes: 21588
#include <iostream>
#include <vector>
#include <cmath>
// #include <string>
// #include <set>
// #include <algorithm>

using namespace std;
// typedef unsigned long long ull;

template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    for (const auto i : v) {
        os << i << " ";
    }
    os << "]";
    return os;
}

int main(int argc, char const *argv[]) {
    int N, M;
    cin >> N >> M;

    vector<int> k(M);
    vector<vector<int>> s(M);
    for (int i = 0; i < M; i++) {
        cin >> k[i];
        s[i].resize(k[i]);
        for (int j = 0; j < k[i]; j++) {
            cin >> s[i][j];
        }
    }

    vector<int> p(M);
    for (int i = 0; i < M; i++) {
        cin >> p[i];
    }

    int ans = 0;
    for (int state = 0; state < (1 << N); state++) {
        vector<int> switch_on(N);
        for (int j = 0; j < N; j++) {
            switch_on[j] = (state >> j) & 1;
        }
        // cout << state << " : " << switch_on << endl;

        bool all_on = true;
        for (int i = 0; i < M; i++) {
            int count = 0;
            for (int j = 0; j < k[i]; j++) {
                count += switch_on[s[i][j]-1];
            }
            // cout << i << "," << p[i] << "," << count << endl;
            if (count % 2 != p[i]) {
                // cout << "off" << endl;
                all_on = false;
                break;
            }
            // cout << "on" << endl;
        }
        if (all_on) {
            ans += 1;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, m, d;

    cin >> n >> m >> d;

    if(d == 0){
        printf("%.10Lf", (m - 1) * 1 / ld(n));
    }else{
        printf("%.10Lf", (m - 1) * 2 * (n - d) / ld(pow(n, 2)));
    }
}


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

double dist(int N, int K, double x[], double y[], double tx,double ty){
	vector<double> dis;
	for(int i=0;i<N;i++)dis.push_back( sqrt( (tx-x[i])*(tx-x[i]) + (ty-y[i])*(ty-y[i]) ) );
	sort(dis.rbegin(), dis.rend());
	double a = 0.0f;
	for(int i=0;i<K;i++)a+=dis[i];
	return a;
}

int main(){
	int N,K;
	scanf("%d%d", &N, &K);
	double x[N], y[N];
	for(int i=0;i<N;i++){
		int a,b;
		scanf("%d%d", &a, &b);
		x[i]=(double)a;
		y[i]=(double)b;
	}
	double lx=-2000.0f, rx = 2000.0f;
	for(int i1=0;i1<100;i1++){
		double tlx = (lx+lx+rx)/3.0f;
		double trx = (lx+rx+rx)/3.0f;
		double ly=-2000.0f, ry=2000.0f;
		for(int i2=0;i2<1000;i2++){
			double tly = (ly+ly+ry)/3.0f;
			double trY = (ly+ry+ry)/3.0f;
			if(dist(N,K,x,y,tlx,tly) < dist(N,K,x,y,tlx,trY)){
				ry = trY;
			}
			else{
				ly = tly;
			}
		}
		double a1 = dist(N,K,x,y,tlx, ly);
		//printf("%.10f %.10f\n", ly, tlx);

		ly=-2000.0f; ry=2000.0f;
		for(int i2=0;i2<100;i2++){
			double tly = (ly+ly+ry)/3.0f;
			double trY = (ly+ry+ry)/3.0f;
			if(dist(N,K,x,y,trx,tly) < dist(N,K,x,y,trx,trY)){
				ry = trY;
			}
			else{
				ly = tly;
			}
		}
		double a2 = dist(N,K,x,y,trx, ly);

		if(a1>a2)lx=tlx;
		else rx=trx;
		if(i1==99)printf("%.10f\n", min(a1, a2));
	}
	return 0;
}


Measured memory_bytes: 3264
#include<bits/stdc++.h>
using namespace std;
const int N=110;
char s[N];
int a[N];
int k,l,ans;
int c(int x,int y){
	if(y==0) return 1;
	else if(y==1) return x;
	else if(y==2) return (x*(x-1))/2;
	else if(y==3) return (x*(x-1)*(x-2))/6;
}
int find(int len,int x[],int t){
	if(t==0||len==0||t>len) return 0;
	if(t==1){
		if(x[len-1]==0) return find(len-1,x,t);
		else return x[len-1]+(len-1)*9;
	}
	if(t==2){
		if(x[len-1]==0) return find(len-1,x,t);
		else return (x[len-1]-1)*c(len-1,1)*9+find(len-1,x,t-1)+c(len-1,2)*81;
	}
	if(t==3){
		if(x[len-1]==0) return find(len-1,x,t);
		else return (x[len-1]-1)*c(len-1,2)*81+find(len-1,x,t-1)+c(len-1,3)*729;
	}
}
int main()
{
	scanf("%s",s);
	scanf("%d",&k);
	l=strlen(s);
	for(int i=0,j=l-1;j>=0;++i,--j) a[i]=s[j]-'0';
	if(k>l)printf("0");
	else{
		ans=find(l,a,k);
		printf("%d\n",ans);
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define forn(i, n) for (ll i = 0; i < (n); i++)
#define fori(i, b, e) for (ll i = (b); i < (e); i++)
#define forr(i, b, e) for (ll i = (b); i >= (e); i--)
#define allele(v) v.begin(), v.end()
#define fi first
#define se second
#define Mat vector<vector<ll>>
#define Arr vector<ll>
#define Matd vector<vector<ld>>
#define Arrd vector<ld>

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b) << endl;
    return 0;
}

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

int p(int x,int y);

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

    vector<int>keta;

    int a=n;
    while(a != 0){
        keta.push_back(a%10);
        a/=10;
    }

    int ans=0;
    if(keta.size()==1)ans+=n;
    else{
        ans+=9;
        if(keta.size()==2);
        else if(keta.size()==3)ans+=n-99;
        else{
            ans+=900;
            if(keta.size()==5)ans+=n-9999;
            else if(keta.size()==6)ans+=90000;
        }
    }

    cout << ans << endl;

    return 0;
}


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

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i <=n;i++){
    num*=yakusu[i];
  }
  return num;
}

//vc alp(26) ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  int N;string S;cin>>N>>S;

  int ans=0;
  
  rep(i, S.size()-1){
    int cnt =0;
    map<char,int > ap,bp;
 

    string mae=S.substr(0,i+1);
    string ato =S.substr(i+1);
    rep(j,mae.size()){
      
      ap[mae[j]]=1;
      
      
    }
    rep(k,ato.size()){
      bp[ato[k]]=1;
    }
    for(auto x:bp){
     
      ap[x.first]++;    
      
    }
    for(auto x :ap){
      if(x.second>=2) cnt++;
    }
    ap.clear();
    bp.clear();
    
    ans =max(ans,cnt);
  
    
  }
  cout<<ans <<endl;
}





Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
#define int long
#define ll long long
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class t> using vc=vector<t>;
template<class t> using vvc=vc<vc<t>>;

using pi=pair<int,int>;
using vi=vc<int>;

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(20);

    int A,B,K; cin >> A >> B >> K;
    if(A>=K){
        cout << A-K <<" "<< B << endl; 
    } else if(A+B>=K){
        cout << 0 << " " << A+B-K << endl;
    } else cout << 0 << " " << 0 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl '\n'

using namespace std;
template<class T, class T2> inline void chkmax(T &x, const T2 &y) { if(x < y) x = y; }
template<class T, class T2> inline void chkmin(T &x, const T2 &y) { if(x > y) x = y; }
const int MAXN = (1 << 20);
const int mod = (int)1e9 + 7;

int pw(int x, int b)
{
	int ret = 1;
	while(b)
	{
		if(b & 1) ret = (ret * 1ll * x) % mod;
		x = (x * 1ll * x) % mod;
		b >>= 1;
	}

	return ret;
}

int h, w, a, b;

void read()
{
	cin >> h >> w >> a >> b;
}

int fact[MAXN], inv_fact[MAXN];
inline int C(int n, int k) { if(n < 0 || k < 0 || n < k) return 0; return (((fact[n] * 1ll * inv_fact[k]) % mod) * 1ll * inv_fact[n - k]) % mod; }
inline int f(int x, int y) { return C(x + y - 2, y - 1); }

/*

   1 1 1 1 1 1 1 1
   1 2 3 4 5 
   1 3 6 10
   1 4
   1 5
   1
   1
   1

*/

void solve()
{
	fact[0] = 1; for(int i = 1; i < MAXN; i++) fact[i] = (fact[i - 1] * 1ll * i) % mod;
	inv_fact[MAXN - 1] = pw(fact[MAXN - 1], mod - 2); for(int i = MAXN - 2; i >= 0; i--) inv_fact[i] = (inv_fact[i + 1] * 1ll * (i + 1)) % mod;	

	int answer = f(h, w);
	for(int i = 1; i <= b; i++)
		answer = (answer - (f(h - a, i) * 1ll * f(a, w - i + 1)) % mod + mod) % mod;
	
	cout << answer << endl;
}

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

	read();
	solve();
	return 0;
}



Measured memory_bytes: 8448
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	char a[n][n], b[m][m];
	for(int i = 0; i < n; i++){
		for(int j = 0; j < n; j++){
			cin >> a[i][j];
		}
	}
	for(int i = 0; i < m; i++){
		for(int j = 0; j < m; j++){
			cin >> b[i][j];
		}
	}

	for(int i = 0; i <= n - m; i++){
		for(int j = 0; j <= n - m; j++){
			bool exist = true;
			for(int k = 0; k < m; k++){
				for(int l = 0; l < m; l++){
					if(a[i + k][j + l] != b[k][l]){
						exist = false;
					}
				}
			}
			if(exist){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
	return 0;
}

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

int main() {
  int n,q;
  string s;
  cin >> n >> q >> s;
  vector<pair<int,int>> l(q,pair<int,int>());
  vector<int> a(n+1);
  a[0]=0;
  a[1]=0;
  for(int i=0;i<q;i++) cin >> l[i].first >> l[i].second;

  for(int i=2;i<n+1;i++) {
    if(s.at(i-1)=='C'&&s.at(i-2)=='A') a[i]=a[i-1]+1;
    else a[i]=a[i-1];
  };

  for(int i=0;i<q;i++) {
    int ans=0;
    if(l[i].first>1) {
      if(s.at(l[i].first-1)=='C'&&s.at(l[i].first-2)=='A') ans=-1;
    };
    ans+=a[l[i].second]-a[l[i].first-1];
    cout << ans << endl;
  };
}

Measured memory_bytes: 2176
#include<iostream>
#include<cstring>

using namespace std;

int main(){
	int N;
	cin >> N;
	string str1, str2;
	cin >> str1 >> str2;
	string str3;
	for(int i = 0; i < N; i++){
		str3 += str1[i];
		str3 += str2[i];
	}
	cout << str3 << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep_lr(i,l,r) for(int i=(l);i<(r);i++)
#define all(x) (x).begin(),(x).end()
#define V vector
typedef V<int> vi;
typedef V<vi> vvi;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<int, int, int> T;
constexpr int INF = INT_MAX >> 1;
constexpr ll LINF = 5000000000000000LL;
constexpr int MOD = 1000000007;

int main() {
	
	int n;
	cin >> n;
	vi a(n + 1, INF);
	a[0] = 0;

	queue<int> q;
	q.push(0);

	while (!q.empty()) {
		
		int v = q.front();
		q.pop();

		if (v + 1 <= n)if (a[v + 1] == INF) {
			a[v + 1] = a[v] + 1;
			q.push(v + 1);
		}

		int mon = 6;
		while (v + mon <= n) {
			if (a[v + mon] == INF) {
				a[v + mon] = a[v] + 1;
				q.push(v + mon);
			}
			mon *= 6;
		}
		mon = 9;
		while (v + mon <= n) {
			if (a[v + mon] == INF) {
				a[v + mon] = a[v] + 1;
				q.push(v + mon);
			}
			mon *= 9;
		}
	}
	
	cout << a[n] << endl;

}

Measured memory_bytes: 3696
# r * g * bを計算する
# その中からj-i = k-j を満たすものを引く
# 2j = i + k
n = gets.chomp.to_i
s = gets.chomp.chars

h = Hash.new(0)

c_map = {
    'R' => 0,
    'G' => 1,
    'B' => 2
}


s.each do |c|
  h[c_map[c]] += 1
end

ans = h[0] * h[1] * h[2]

0.upto(n-2) do |i|
  i.upto(n-1) do |j|
    k = 2 * j - i
    next if k >= n

    ans -= 1 if s[i] != s[j] && s[j] != s[k] && s[k] != s[i]
  end
end

p ans

Measured memory_bytes: 14432
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
typedef pair<vector<int>, int> P;
const int INF = 1<<30; 
const int MOD = 1e9 + 7;
const int d[] = {-1, -4, 1, 4};
map<vector<int>, int> bfs(vector<int> goal)
{
    queue<P> que;
    map<vector<int>, int> res;
    que.push(P(goal, 0));
    res[goal] = 0;
    while(que.size())
    {
        vector<int> now = que.front().first;
        int cnt = que.front().second;
        que.pop();
        int zero = -1;
        for(int i = 0; i < now.size(); i++) if(now[i] == 0) zero = i;
        for(int i = 0; i < 4; i++)
        {
            int u = zero + d[i];
            if(u > 7 || u < 0) continue;
            if(zero == 3 && u == 4) continue;
            if(zero == 4 && u == 3) continue;
            swap(now[zero], now[u]);
            if(res.count(now) == 0 || res[now] > cnt + 1)
            {
                que.push(P(now, cnt + 1));
                res[now] = cnt + 1;
            }
            swap(now[u], now[zero]);
        }
    }
    return res;
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    vector<int> goal;
    for(int i = 0; i <= 7; i++) goal.push_back(i);
    map<vector<int>, int> mp = bfs(goal);
    string s;
    while(getline(cin, s))
    {
        vector<int> v;
        for(int i = 0; i < s.size(); i++)
        {
            if(s[i] == ' ') continue;
            v.push_back(s[i] - '0');
        }
        cout << mp[v] << endl;
    }
    return 0;
}




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

int main(void) {
	for (;;) {
		int x, y, s;
		cin >> x >> y >> s;
		if (x == 0 && y == 0 && s == 0) {
			break;
		}

		int s_1, s_2, t_1, t_2, t=1;
		for (int i = 1; i < s; i++) {
			for (int j = 1; j < s; j++) {
				s_1 = i * (100 + x) / 100;
				s_2 = j * (100 + x) / 100;
				if (s_1 + s_2 == s) {
					t_1 = i * (100 + y) / 100;
					t_2 = j * (100 + y) / 100;
					if (t_1 + t_2 > t) {
						t = t_1 + t_2;
					}
				}
			}
		}

		printf("%d\n", t);
	}
	return 0;
}

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

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);

        int n = sc.nextInt();
        Integer[] a = new Integer[n];
        for(int i=0;i<n;i++) a[i] = sc.nextInt();
        Arrays.sort(a);

        pw.println(a[n/2] - a[(n-1)/2]);

        pw.close();
    }
}

Measured memory_bytes: 39656
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define frw(i, a, b) for(int i = a; i < b; i++)
#define fi first
#define se second
#define pb push_back
#define in insert
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define sz(a) int(a.size())
#define pii pair<int, int>
#define piii pair<int, pii>
#define pll pair<ll, ll>
#define plll pair<ll, pll>
#define vpii vector<pii>
#define vpiii vector<piii>
#define vpll vector<pll>
#define vplll vector<plll>
#define mod 1000000007

int modInverse(ll a, ll m) 
{ 
    ll m0 = m; 
    ll 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; 
} 
 ll dp[200000];

int po(ll x,ll y)
{
	ll res=1;
	while(y>0)
	{
		if(y&1)
			res=(res*x)%mod;
		y=y>>1;
		x=(x*x)%mod;
	}
	return res;
}

ll nck(ll n, ll k) {
	ll ans=1;
	for(int i=1; i<=k; ++i)
		ans=ans*(n-i+1)%mod*dp[i]%mod;
	return ans;
}
int main()
{
	int n,k;
	cin>>n>>k;
	ll a[n];
	ll ms=0;
	for(int i=0;i<n;i++)
		cin>>a[i];
	for(int i=0;i<k;i++)
		ms+=a[i];
	double ans=(double)ms;
	for(int i=k;i<n;i++)
	{
		ms+=a[i]-a[i-k];
		ans=max((double)ms,ans);
	}
	ans=(ans+k)/2;
	cout << fixed << setprecision(8) <<ans<<endl; 
}

Measured memory_bytes: 1792
import sys
import math
import collections
import itertools
import array
import inspect

# Set max recursion limit
sys.setrecursionlimit(1000000)


# Debug output
def chkprint(*args):
    names = {
        id(v): k
        for k, v in inspect.currentframe().f_back.f_locals.items()
    }
    print(', '.join(
        names.get(id(arg), '???') + ' = ' + repr(arg) for arg in args))


# Binary converter
def to_bin(x):
    return bin(x)[2:]


def li_input():
    return [int(_) for _ in input().split()]


def gcd(n, m):
    if n % m == 0:
        return m
    else:
        return gcd(m, n % m)


def gcd_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = gcd(v, L[i])

    return v


def lcm(n, m):
    return (n * m) // gcd(n, m)


def lcm_list(L):
    v = L[0]

    for i in range(1, len(L)):
        v = lcm(v, L[i])

    return v


# Width First Search (+ Distance)
def wfs_d(D, N, K):
    """
    D: 隣接行列(距離付き)
    N: ノード数
    K: 始点ノード
    """

    dfk = [-1] * (N + 1)
    dfk[K] = 0

    cps = [(K, 0)]
    r = [False] * (N + 1)
    r[K] = True
    while len(cps) != 0:
        n_cps = []
        for cp, cd in cps:
            for i, dfcp in enumerate(D[cp]):
                if dfcp != -1 and not r[i]:
                    dfk[i] = cd + dfcp
                    n_cps.append((i, cd + dfcp))
                    r[i] = True

        cps = n_cps[:]

    return dfk


# Depth First Search (+Distance)
def dfs_d(v, pre, dist):
    """
    v:  現在のノード
    pre: １つ前のノード
    dist: 現在の距離

    以下は別途用意する
    D: 隣接リスト(行列ではない)
    D_dfs_d: dfs_d関数で用いる，始点ノードから見た距離リスト
    """

    global D
    global D_dfs_d

    D_dfs_d[v] = dist

    for next_v, d in D[v]:
        if next_v != pre:
            dfs_d(next_v, v, dist + d)

    return


def sigma(N):
    ans = 0
    for i in range(1, N + 1):
        ans += i
    return ans


class Combination:
    def __init__(self, n, mod):

        g1 = [1, 1]
        g2 = [1, 1]
        inverse = [0, 1]
        for i in range(2, n + 1):
            g1.append((g1[-1] * i) % mod)
            inverse.append((-inverse[mod % i] * (mod // i)) % mod)
            g2.append((g2[-1] * inverse[-1]) % mod)
        self.MOD = mod
        self.N = n
        self.g1 = g1
        self.g2 = g2
        self.inverse = inverse

    def __call__(self, n, r):
        if (r < 0 or r > n):
            return 0
        r = min(r, n - r)
        return self.g1[n] * self.g2[r] * self.g2[n - r] % self.MOD


# --------------------------------------------

dp = None


def main():
    N = int(input())
    S = [int(input()) for _ in range(N)]

    total = sum(S)

    if total % 10 != 0:
        print(total)
    else:
        min10x = 999

        for s in S:
            if s % 10 != 0 and s < min10x:
                min10x = s

        if min10x == 999:
            print(0)
        else:
            print(total - min10x)


main()


Measured memory_bytes: 4724
H, W = map(int,input().split())
ans = 0

if H == 1:
    print(1)
elif W == 1:
    print(1)
else:
    if H % 2 == 0:
        ans = H // 2 * W
    else:
        if W % 2 == 0:
            ans = H * W // 2
        else:
            ans = H * (W//2) + H//2 + 1

    print(ans)

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

int main() {
    int n; cin >> n;
    vector<int> a(n);
    int m = 0;
    for(int i = 0; i < n; i ++) {
        cin >> a[i];
        if(a[i]<0) {
            m ++;
            a[i] *= -1;
        }
    }
    long long sum;
    if(m%2==0) sum = accumulate(a.begin(), a.end(),0LL);
    else sum = accumulate(a.begin(), a.end(),0LL) - (*min_element(a.begin(), a.end()) * 2);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 640
/* https://codeforces.com/contest/1360/problem/H */
#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using vs = vector<string>;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vpi = vector<pair<int, int>>;
using vpl = vector<pair<ll, ll>>;
using ld = double;

#define f first
#define s second 
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define pb push_back
#define	lb lower_bound
#define	ub upper_bound
#define	sz(x) (int)(x).size()
#define all(x) x.begin(), x.end()
#define ins insert
#define	mp make_pair

const int MAX = INT_MAX;

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

	sort(all(a), greater<ll>());
	auto cmp = [&] (pair<ll, pair<ll, ll>>& lhs, pair<ll, pair<ll, ll>>& rhs) {
		return lhs.s.f < rhs.s.f;
	};

	priority_queue<pair<ll, pair<ll, ll>>, vector<pair<ll, pair<ll, ll>>>, decltype(cmp)> pq(cmp);
	ll ans = 0;
	ll id = 0;
	for (int i = 0;i < N;++i) {
		if (pq.size() == 0) {
			pq.push(mp(id++, mp(a[i], a[i])));
		}
		else {
			auto temp = pq.top();
			//cout<<temp.s.f<<" "<<temp.s.s<<endl;
			pq.pop();
			ans += temp.s.f, temp.s.s;
			pq.push(mp(id++, mp(min(a[i], temp.s.s), max(a[i], temp.s.s))));
			pq.push(mp(id++, mp(min(a[i], temp.s.f), max(a[i], temp.s.f))));
		}
	}

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


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

data = dict()

for i in range(1, n + 1):
    city, score = input().split()
    if city not in data:
        data[city] = []
    data[city].append([int(score), i])

for key in sorted(data.keys()):
    for _, num in sorted(data[key], key=lambda x: -x[0]):
        print(num)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll mod=1000000007;
ll MOD=INF;


int main() {
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans=b*d;
    ans=max(ans,b*c);
    ans=max(ans,a*c);
    ans=max(ans,a*d);
    cout << ans << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <set>
#include <utility>
#include <cstdio>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n, m) for (int i = n; i >= m; i--)

#include <iostream>
#include <string>
#include <sstream>
#include <cstring>
#include <cstdio>
using namespace std;

int main() {
  int a, p;
  cin >> a >> p;
  cout << (a*3 + p)/2 <<endl;
}


Measured memory_bytes: 256
xyh = []
n = int(input())
for i in range(n):
	x, y, h = map(int, input().split())
	xyh.append([x, y, h])

for cx in range(101):
	for cy in range(101):
		h = 0
		judge = 1
		for k in range(n):
			if xyh[k][2] > 0:
				h = xyh[k][2] + abs(cx-xyh[k][0]) + abs(cy-xyh[k][1])
				break
		for k in range(n):
			if max(h - abs(cx-xyh[k][0]) - abs(cy-xyh[k][1]), 0) != xyh[k][2]:
				judge = 0
				break
		if judge:
			print(cx, cy, h)
			exit(0)


Measured memory_bytes: 3064
while True:

  n = int(raw_input())

  if n == 0:
   break

  A_p = B_p = 0

  for i in range(n):

    A, B = map(int, raw_input().split())

    if A > B:
      A_p += (A + B)

    elif A == B:
      A_p += A
      B_p += B

    else:
      B_p += (A + B)

  print A_p, B_p

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

int isprime(int x){
  if(x==2) return 1;
  if(x<2||x%2==0) return 0;
  int i;
  for(i=3;i<=sqrt(x);i+=2) //????????????????????????????????????
    if(x%i==0)
      return 0;
  return 1;
}

int main(void){
  int n,x,i,num=0;

  scanf("%d",&n);// ??´??°????????°

  for (i = 0;i < n;i++) 
    {
      scanf("%d",&x);
      if(isprime(x))num++;//return 1?????´??????num???????????????
    }
    printf("%d\n",num);
  return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
int main(void)
{
	int i,j;
	
	for(i=1;i<=9;i++)
	{
		for(j=1;j<=9;j++)
		{
			printf("%dx%d=%d\n",i,j,i*j);
		}
	}
	return 0;
}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
using vb = vector<bool>;
using vb2 = vector<vector<bool>>;
using vc = vector<char>;
using vc2 = vector<vector<char>>;
using vs = vector<string>;
using si = set<int>;
using vs2 = vector<vector<string>>;
using pii = pair<int, int>;
using mii = map<int, int>;
const int INF = 1e9;
const ll LINF = 1e18;
const long double PI = acos(-1.0);

#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)
#define sz(x) (int)(x).size()
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
 
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define SORT(v) sort(ALL(v));
#define RSORT(v) sort(RALL(v));
#define IN(type,a) type a;cin >> a;
#define VIN(type,a,n) vector<type> a(n);cin >> a;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;
#define COUT(x) cout << (x) << endl;
#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;
#define ENDL cout << endl;
#define DB(s,x) cout << (s) << " : " << x << endl;
 
#define HOGE COUT("HOGE")
 
template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}
 
template<typename T> bool chmax(T& a, const T& b){if(a<b){a=b;return true;}return false;}
template<typename T> bool chmin(T& a, const T& b){if(a>b){a=b;return true;}return false;}
template<typename T> T gcd(T a,T b){if(b==0){return a;}else{return gcd(b, a%b);}}



const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
 
int main() {
    IN(string, s);
    vector<int> w;
    REP(i, s.length()){
        if (s[i]=='W') {
            w.emplace_back(i);
        }
    }
    ll ans = 0;
    REP(i, w.size()){
        ans += w[i]-i;
    }
    COUT(ans);
}


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}


typedef long long ll;

#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1000000007;
//const ll MOD = 998244353;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { -1,0, 1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
// #define mp make_pair
//#define endl '\n'


vii a(500, vi(500, -1));

void solve(int l, int r, int c) {
  if (r - l == 1) return;
  int m = (l + r) / 2;
  for (int u = l; u < m; u++) {
    for (int v = m; v < r; v++) {
      a[u][v] = a[v][u] = c;
    }
  }

  solve(l, m, c + 1);
  solve(m, r, c + 1);
}

int main() {
  int n;
  cin >> n;
  solve(0, n, 1);

  rep (i, n - 1) {
    for (int j = i + 1; j < n; j++) {
      cout << a[i][j] << " ";
    }
    cout << endl;
  }
    
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007

int main(){
    int64_t n;
    cin>>n;
    vector<int> x(n);
    vector<int> y(n);
    vector<int> h(n);
    rep(i,n){
        cin >> x[i]>>y[i]>>h[i];
    }
    int H;
    rep(cx,101){
        rep(cy,101){
            set<int> s;
            rep(i,n){
                //ここでHがn点のデータに対して等しければそこがcx,cy;
                if(h[i]>0){
                H = h[i]+abs(x[i]-cx)+abs(y[i]-cy);
                s.insert(H);
                }
                else{
                    //h[i]==0ならこの条件を満たしてないといけない
                    //H<=abs(x[i]-cx)+abs(y[i]-cy)
                }
            }
            if(s.size()==1){
                bool ok=true;
                rep(i,n){
                    if(h[i]==0 && H>abs(x[i]-cx)+abs(y[i]-cy)){
                        ok=false;
                    }
                }
                if(ok)cout<<cx<<" "<<cy<<" "<<H<<endl;
            }
        }
    }
    
}

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

vector<int> val;
vector<int> cnt;
vector< vector<int> > t;
vector<bool> seen;
int p = 0;

void dfs(int u) {
    p += val[u];
    cnt[u] = p;
    for (int i = 0; i < (int)t[u].size(); i++) {
        int v = t[u][i];
        if (seen[v]) continue;
        seen[v] = 1;
        dfs(v);
    }
    p -= val[u];
}

int main() {
    int N, Q;
    cin >> N >> Q;
    val.assign(N, 0);
    cnt.assign(N, 0);
    seen.assign(N, false);
    t.resize(N);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        t[a].push_back(b);
        t[b].push_back(a);
    }
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        --p;
        val[p] += x;
    }
    seen[0] = true;
    dfs(0);
    for (int i = 0; i < N; i++) {
        cout << cnt[i] << ' ';
    }
    cout << endl;
}

Measured memory_bytes: 24320
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma once
#include<bits/stdc++.h>
#define q register
typedef long long ll;
using namespace std;
string s;
ll tag1,tag2,ans,tot;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>s;
    for(q ll i=0;i<s.length();i++){
        if((s[i]=='C')&&(!ans)){
            tag1=i,ans++;
               tot=tag1;    
        }
        if(s[i]=='F'){
            tag2=i;   
            if(ans)   {
                puts("Yes");
                return 0;
            }
        }
    }
    puts("No");
    return 0;
}

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

namespace Sample101
{

    class Program
    {
        static int[] stack = new int[1000];
        static int top = 0;

        static void Push(int n)
        {
            top++;
            stack[top] = n;
        }

        static int Pop()
        {
            top--;
            return stack[top + 1];
        }

        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split(' ');
            foreach (string s in line)
            {
                if (s == "+")
                {
                    var b = Pop();
                    var a = Pop();
                    Push(a + b);
                } else if (s == "-")
                {
                    var b = Pop();
                    var a = Pop();
                    Push(a - b);
                } else if (s == "*")
                {
                    var b = Pop();
                    var a = Pop();
                    Push(a * b);
                } else
                {
                    Push(int.Parse(s));
                }
            }

            Console.WriteLine(Pop());
        }
    }
}


Measured memory_bytes: 17924
//============================================================================
// Name        : abc143_b.cpp
// Author      : abb
// Version     :
// Copyright   : [My copyright notice]
// Description : test program
//============================================================================

/*
B - TAKOYAKI FESTIVAL 2019

実行時間制限: 2 sec / メモリ制限: 1024 MB

配点 : 200 点

問題文
たこ焼きフェスティバル (たこフェス) の季節がやってきました！
今年のたこフェスでは N 個のたこ焼きがふるまわれる予定です。このうち i 個目のたこ焼きのおいしさは d_i です。
ところで、おいしさが x と y であるたこ焼きを一緒に食べると、体力が x × y 回復することが一般に知られています。
たこフェスでふるまわれる N 個のたこ焼きから、2 個を選ぶ方法は \frac{N × (N - 1)}{2} 通り考えられます。そのそれぞれについて、一緒に食べたときの体力の回復量を求めて、その総和を出力してください。

制約

・入力は全て整数である。
・2 <= N <= 50
・0 <= d_i <= 100


 */

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ull = unsigned long long;

#define REP(i, m, n) for (ll i = (m); i < (ll)(n); ++(i))
#define REPM(i, m, n) for (ll i = (m); i <= (ll)(n); ++(i))
#define REPR(i, m, n) for (ll i = (m); i >= (ll)(n); --(i))
#define REPD(i, m, n, d) for (ll i = (m); i < (ll)(n); i += (d))
#define REPMD(i, m, n, d) for (ll i = (m); i <= (ll)(n); i += (d))
#define ALL(x) begin(x), end(x)

/**
 * エントリポイント．
 * @return 0.
 */
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n;
    cin >> n;
    vector<ll> d(n);
    REP(i, 0, n)
    {
        cin >> d[i];
    }
    ll sum = 0;
    REP(i, 0, n - 1)
    {
        REP(j, i + 1, n)
        {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256