akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<vector>
#include<cstring>
#include<algorithm>
using namespace std;
const long long MAXN=300005,MOD=998244353;
long long jc[MAXN],inv[MAXN];
long long gcd(long long a,long long b)
{
	return a%b==0?b:gcd(b,a%b);
}
long long ksm(long long x,long long y)
{
	long long k=1;
	while(y)
	{
		if(y&1)
			k=(k*x)%MOD;
		x=(x*x)%MOD;
		y>>=1;
	}
	return k;
}
void Init()
{
	jc[0]=1;
	for(long long i=1;i<MAXN;i++)
		jc[i]=(jc[i-1]*i)%MOD;
	inv[MAXN-1]=ksm(jc[MAXN-1],MOD-2);
	for(long long i=MAXN-2;i>=0;i--)
		inv[i]=(inv[i+1]*(i+1))%MOD;
}
long long C(long long n,long long m)
{
	if(m<n||n<0||m<0)
		return 0ll;
	return ((jc[m]*inv[n])%MOD*inv[m-n])%MOD;
}
int main()
{
	Init();
	long long n,a1,b1,k;
	scanf("%lld%lld%lld%lld",&n,&a1,&b1,&k);
	long long e=gcd(k,gcd(a1,b1));
	if(e!=0)
	{
		k/=e;
		a1/=e;
		b1/=e;
	}
	long long a=0,b=0;
	for(long long i=0;i*a1<=k;i++)
	{
		if((k-(i*a1))%b1==0)
		{
			b=(k-(i*a1))/b1;
			b%=a1;
			a=(k-(b*b1))/a1;
			break;
		}
	}
	if(a*a1+b*b1!=k)
	{
		printf("0\n");
		return 0;
	}
	long long ans=0;
	while(a>=0)
	{
		ans=(ans+(C(a,n)*C(b,n))%MOD)%MOD;
		a-=b1;
		b+=a1;
	}
	printf("%lld\n",(ans+MOD)%MOD);
}

Measured memory_bytes: 4864
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int dp[2010];
int c[2010][2010];
#include<stack>
int BiggestRectangle(int N,int buf[]){
	buf[N]=0;
	stack<pair<int,int> >st;
	int ret=0;
	for(int i=0;i<=N;i++){
		if(st.empty())st.push(make_pair(buf[i],i));
		else if(st.top().first<buf[i])st.push(make_pair(buf[i],i));
		else if(st.top().first>buf[i]){
			int pnt=i;
			while(!st.empty()){
				int height=st.top().first;
				int index=st.top().second;
				if(height<buf[i])break;
				st.pop();
				ret=max(ret,height*(i-index+1));
				pnt=index;
			}
			st.push(make_pair(buf[i],pnt));
		}
	}
	return ret;
}
int main(){
	int h,w;
	cin>>h>>w;
	lol(i,h){
		lol(j,w){
			char z;cin>>z;
			if(z=='.')c[i][j]=0;
			if(z=='#')c[i][j]=1;
		}
	}
	for(int i=0;i<h-1;i++){
		for(int j=0;j<w-1;j++){
			int tmp=c[i][j]+c[i+1][j];
			tmp+=c[i][j+1]+c[i+1][j+1];
			c[i][j]=tmp%2;
		}
	}
	int ans=max(h,w);
	for(int j=0;j<w-1;j++)dp[j]=1;
	for(int i=0;i<h-1;i++){
		for(int j=0;j<w-1;j++){
			if(c[i][j]==true)dp[j]=1;
			else dp[j]++;
		}
		ans=max(ans,BiggestRectangle(w-1,dp));
	}
	cout<<ans<<endl;
	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

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

ll ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
	ll n,k;cin>>n>>k;
	vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	ll cnt1=0,cnt2=0;
	rep(i,n-1){
		for(int j=i+1;j<n;++j){
			if(a[i]>a[j])cnt1++;
		}
    }
	rep(i,n){
		rep(j,n){
			if(a[i]>a[j])cnt2++;
		}
	}
	ll ans=0;
	ans+=(cnt1*k)%MOD;
	ans+=(k*(k-1)/2)%MOD*cnt2%MOD;
	cout<<ans%MOD<<endl;
}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn.readLine
  import scala.io.StdIn.readInt
  
  	val n = readInt
  	val students = readLine.split(" ").map(_.toLong)
  
  	students.zip((1 to n)).sortBy(_._1).map(x => x._2.toString).foreach(println)
}


Measured memory_bytes: 76364
#include <iostream>
#include <vector>
using namespace std;
int max(vector<int>);
int min(vector<int>);

int main() {
  while(true) {
    int n;
    cin >> n;
    if(n == 0) break;
    vector<int> totals;
    for(int i = 0; i < n; ++i) {
      int total = 0;
      for(int j = 0; j < 5; ++j) {
        int p;
        cin >> p;
        total += p;
      }
      totals.push_back(total);
    }
    cout << max(totals) << " " << min(totals) << endl;
  }
  return 0;
}

int max(vector<int> v) {
  int m = v[0];
  for(int i = 0; i < v.size() - 1; ++i) {
    m = max(m, v[i + 1]);
  }
  return m;
}

int min(vector<int> v) {
  int m = v[0];
  for(int i = 0; i < v.size() - 1; ++i) {
    m = min(m, v[i + 1]);
  }
  return m;
}

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

ll solve(ll N, vector<ll> &A, bool w) {
  deque<ll> q;
  bool t = true;
  ll i = 0, j = N - 1;
  while (i <= j) {
    if (i == j) {
      if (w) {
        q.push_front(A[i]);
      } else {
        q.push_back(A[i]);
      }
      break;
    }
    if (t) {
      q.push_front(A[i++]);
      if (i <= j) q.push_back(A[j--]);
    } else {
      q.push_back(A[i++]);
      if (i <= j) q.push_front(A[j--]);
    }
    t = !t;
  }

  vector<ll> a(N);
  REP(i, 0, N) {
    a[i] = q.front();
    q.pop_front();
  }

  ll ans = 0;
  REP(i, 0, N - 1) ans += abs(a[i] - a[i + 1]);
  return ans;
}

int main(void) {
  ll N;
  cin >> N;
  vector<ll> A(N);
  REP(i, 0, N) cin >> A[i];
  sort(A.begin(), A.end());

  cout << max(solve(N, A, false), solve(N, A, true)) << endl;
}

Measured memory_bytes: 2688
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int A, B, K; cin >> A >> B >> K;
	rep(x, A, B + 1) {
		if (x - A + 1 <= K || B - x + 1 <= K) {
			cout << x << endl;
		}
	}
	return 0;
}

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

bool isEqual(vector<int> &a, vector<int> &b) {
    if (a.size() != b.size()) {
        return false;
    }

    for (int i = 0; i < a.size(); i++) {
        if (a[i] != b[i]) {
            return false;
        }
    }

    return true;
}

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

    vector<int> v;
    for (int i = 1; i <= N; i++) v.push_back(i);

    vector<vector<int>> V;
    do {
        V.push_back(v);
    } while (next_permutation(v.begin(), v.end()));

    int a = 0, b = 0;
    for (int i = 0; i < V.size(); i++) {
        if (isEqual(V[i], P)) a = i;
        if (isEqual(V[i], Q)) b = i;
    }

    cout << abs(a - b) << endl;
    return 0;
}

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll N, K;
    cin >> N >> K;
    
    vector<ll> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    if (K == 0) {
        ll x = 0;
        for (int i = 0; i < N; i++) {
            x += A[i];
        }
        cout << x << endl;
        return;
    }
    int ma = 0;
    for (int i = 0; i < 63; i++) {
        if (K >> i & 1) {
            ma = i;
        }
    }
    ll ans_base = 0;
    for (int i = 0; i < N; i++) {
        ans_base += (A[i] >> (ma + 1)) << (ma + 1);
    }

    vector<vector<ll>> dp(ma + 2, vector<ll>(2, numeric_limits<ll>::min()));
    
    dp[ma + 1][0] = 0;
    for (int i = ma; i >= 0; i--) {
        ll cnt = 0;
        for(int j = 0; j < N; j++) {
            if (!(A[j] >> i & 1)) {
                cnt++;
            }
        }
        ll w1 = cnt * (1LL << i);
        ll w2 = (N - cnt) * (1LL << i);

        if (K >> i & 1) {
            // 1
            dp[i][0] = max(dp[i][0], dp[i + 1][0] + w1);
            dp[i][1] = max(dp[i][1], dp[i + 1][1] + w1);

            // 0
            dp[i][1] = max(dp[i][1], dp[i + 1][0] + w2);
            dp[i][1] = max(dp[i][1], dp[i + 1][1] + w2);

        } else {
            // 1
            dp[i][1] = max(dp[i][1], dp[i + 1][1] + w1);
            
            // 0
            dp[i][0] = max(dp[i][0], dp[i + 1][0] + w2);
            dp[i][1] = max(dp[i][1], dp[i + 1][1] + w2);
        }
    }

    cout << ans_base + max({dp[0][0], dp[0][1]}) << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 1024
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

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

    static class CStrangeBank {
        static final int[] C6 = {6, 36, 216, 1296, 7776, 46656};
        static final int[] C9 = {9, 81, 729, 6561, 59049};
        int[] m;

        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int n = in.nextInt();
            m = new int[n + 1];
            out.println(min(n));
        }

        int min(int n) {
            if (n == 0) {
                return 0;
            }
            int min = Integer.MAX_VALUE;
            for (int i = C6.length - 1; i >= 0; i--) {
                if (n >= C6[i]) {
                    min = min(n - C6[i]) + 1;
                    break;
                }
            }
            for (int i = C9.length - 1; i >= 0; i--) {
                if (n >= C9[i]) {
                    min = Math.min(min, min(n - C9[i]) + 1);
                    break;
                }
            }
            if (min == Integer.MAX_VALUE) {
                return min(n - 1) + 1;
            } else {
                return min;
            }
        }

    }
}



Measured memory_bytes: 22996
import java.util.Scanner;
import java.util.Arrays;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long A = sc.nextLong();
		long B = sc.nextLong();
		long[] H = new long[N];
		for (int i = 0; i < N; i++) {
			H[i] = sc.nextLong();
		}
		long l = 0;
		long r = 1000000000;
		while (r - l > 1) {
			long cnt = 0;
			long m = l + (r - l) / 2;
			for (int i = 0; i < N; i++) {
				long diff = H[i] - B * m;
				if(diff > 0){
					cnt += diff / (A - B);
					if (diff % (A - B) > 0) {
						cnt++;
					}
				}
			}
			if (cnt > m) {
				l = m;
			} else {
				r = m;
			}
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 50784
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<numeric>
#include<algorithm>
#include<tuple>
#include<cmath>
#include <iomanip>

typedef unsigned long long ull;
typedef long long ll;

ll DENOM = 1000000000LL + 7LL;
using namespace std;

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(m), b(m);
    vector<ll> r(n+1, 0);
    for(int i=0; i<m; ++i){
        cin >> a[i] >> b[i];
    }
    unordered_map<ll, vector<ll> > tun;
    for(int i=0; i<m; ++i){
        tun[a[i]].push_back(b[i]);
        tun[b[i]].push_back(a[i]);
    }
    set<ll> nxt;
    nxt.insert(1);
    for(int i=0; i<n; ++i){
        set<ll> nxt_;
        for(auto it = nxt.begin(); it != nxt.end(); ++it){
            auto v = tun[*it];
            for(auto it2 = v.begin(); it2 != v.end(); ++it2){
                if (r[*it2] != 0) continue;
                r[*it2] = *it;
                nxt_.insert(*it2);
            }
        }
        nxt = nxt_;
    }
    cout << "Yes" << endl;
    for (int i=2; i<n+1; ++i){
        cout << r[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 29048
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <istream>
#include <iterator>
#include <sstream>
#include <list>
#include <map>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <iomanip>
#define BR "\n"
#define REP(i,n) for(int (i)=0;(i)<(n);++(i))
#define ALL(cont) begin(cont),end(cont)
#define AS_MOD(a,b) ((((a) % (b) ) + (b)) % (b))
#define FEACH(it,cont) for(auto (it) = begin(cont); it!=end(cont);++it)
#define FEACHR(it,cont) for(auto (it) = rbegin(cont); it!=rend(cont);++it)
#define pb push_back
#define pob pop_back
#define fi first
#define se second
#define getll() ([](){ll s;scanf("%lld", &s);return s;})()
#define getld() ([](){ld s;scanf("%Lf", &s);return s;})()
#define prl(P) printf("%lld", P)
#define prd(P) printf("%.10Lf", P)
#define pr(P) printf(P)
#define MAX(V, T) V=max(V,T)

#define DumpArray(cont,from,to) for(int __i=from;__i<to;++__i) {cout<<"(" <<__i<<": " << cont[__i]<<")";} cout<<endl;

using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string S;
    cin >>S;
    sort(ALL(S));
    if (S[0]!=S[2] && S[0]==S[1]&&S[2]==S[3]){
        cout <<"Yes"<<endl;
    } else{
        cout <<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <time.h>
#define int long long
#define endl '\n'
#define INF 1000000000000000000
#define EPS 1e-10
#define PI 3.141592653589793238
#define all(a) a.begin(),a.end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define fi first
#define se second
#define pb push_back
#define double long double
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef complex<double> com;
template<class T, class S> bool chmax(T &a, const S &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T, class S> bool chmin(T &a, const S &b) { if (a > b) { a = b; return 1; } return 0; }
ll gcd(ll n, ll m) { return (m ? gcd(m, n%m) : n); }
ll lcm(ll n, ll m) { return n / gcd(n, m)*m; }


int grundy(int a, int k) {
	if (a < k) return 0;
	if (a%k == 0) return a / k;
	int d = a / k;
	if((a - d * k) / (d + 1) * (d + 1)) return grundy(a - (a - d * k) / (d + 1) * (d + 1), k);
	return grundy(a - (d + 1), k);
}

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

	int n;
	cin >> n;
	int ans = 0;
	rep(i, n) {
		int a, k;
		cin >> a >> k;
		ans ^= grundy(a, k);
	}
	cout << (ans ? "Takahashi" : "Aoki") << endl;
}

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

#define REP(i, n) for(decltype(n) i = 0; i < (n); i++)
#define REP2(i, x, n) for(decltype(x) i = (x); i < (n); i++)
#define RREP(i, n) for (decltype(n) i = (n) - 1;i >= 0; i--)

#define ALL(a) (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define DESCSORT(c) sort(c.begin(), c.end(), greater<int>())

#define LL long long int
#define LD long double

#define PI 3.14159265358979

#define _CRT_SECURE_NO_WARNINGS

using namespace std;

//================================================
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int N; cin >> N;
	vector<int>vec(N * 2);

	REP(i, N * 2) {
		cin >> vec[i];
	}
	SORT(vec);

	int ans = 0;
	for (int i = 0; i < N * 2; i += 2) {
		ans += min(vec[i], vec[i + 1]);
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void) {
	int c[6],sum=0;
	int mon[6] = { 1,5,10,50,100,500 };
	for (int i = 0; i < 6; i++) {
		scanf("%d", &c[i]);
		sum = sum+c[i] * mon[i];
	}
	if (sum >= 1000) printf("1\n");
	else	printf("0\n");
	return 0;
}


Measured memory_bytes: 2136
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <set>
#include <math.h>
#include <utility>
#include <stack>
using namespace std;
typedef pair<int,int> P;
const int INF = (int)((unsigned int)-1>>1);


int n;
string str;

int toint(string s){
    int n = 0;
    int p = 1;
    for(int i=s.size()-1;i>=0;i--){
        n += p*(s[i]-'0');
        p *= 10;
    }
    return n;
}

int dfs(int pos){
    //printf("in : %d\n",pos);
    vector<int> points;
    int kakko_n = 1;
    for(int i=pos+1;i<str.size();i++){
        if (kakko_n == 1){
            if(str[i]=='['){
                points.push_back(dfs(i));
                kakko_n += 1;
            }else if(str[i]==']'){
                break;
            }else{
                string num = "";
                while(str[i]!=']'){
                    num.push_back(str[i]);
                    i+=1;
                }
                points.push_back((toint(num)+1)/2);
                break;
            }
        }else{
            if(str[i]=='['){
                kakko_n += 1;
            }else if(str[i]==']'){
                kakko_n -= 1;
            }
        }
    }
    sort(points.begin(), points.end());
    int p = 0;
    for(int i=0;i<(points.size()+1)/2;i++){
        p += points[i];
    }
    /*
    printf("out : %d\n",pos);
    for(int i=0;i<points.size();i++){
        printf("%d ",points[i]);
    }
    cout << endl;
    */
    return p;
}

int main(){
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> str;
        cout << dfs(0) << endl;
    }
}

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

using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
#define ALL(x) x.begin(),x.end()
#define ll long long
const int inf=1000000007;
const int MOD=1000000007;
signed main(){
  int n;cin>>n;
  vector<string> s(n);
  rep(i,n)cin>>s[i];
  sort(ALL(s));
  s.push_back("...");
  int max=0;
  map<string,int> memo;
  int num=1;string last=s[0];
  rep1(i,n){
    if(last==s[i])num++;
    else{
      memo[last]=num;
      if(num>max)max=num;
      last=s[i];
      num=1;
    }
  }
  auto it=memo.begin();
  while(it!=memo.end()){
    if(it->second==max){
      cout<<it->first<<endl;
    }
    ++it;
  }
  return 0;
}


Measured memory_bytes: 28260
#include<stdio.h>
int main(void){
	int n,k;
	long a[200100]={0},b[200100]={0};
	long fenwick[200100]={0};
	long ok,ng,mid;
	int i,j;
	long h,flg;
	long tmp;
	scanf("%d%d",&n,&k);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++){
		a[i]+=(a[i-1]-k);
		b[i]=a[i];
	}
	h=n+1;flg=1;
	while(h>1||flg){
		if(h>1) h=h/1.3;
		if(h==10||h==9) h=11;
		flg=0;
		for(i=0;i<=n-h;i++){
			if(b[i]>b[i+h]){
				tmp=b[i];
				b[i]=b[i+h];
				b[i+h]=tmp;
				flg=1;
			}
		}
	}
	for(i=j=0;i<=n;i++){
		while(j<n&&b[j]==b[j+1]) j++;
		b[i]=b[j];
		if(j<n) j++;
	}
	h=0;
	for(i=0;i<=n;i++){
		ok=n;
		ng=-1;
		while(ok-ng>1){
			mid=(ok+ng)>>1;
			if(a[i]<=b[mid]){
				ok=mid;
			}else{
				ng=mid;
			}
		}
		ok++;
		ng=0;
		for(flg=ok;flg>0;flg-=flg&-flg) ng+=fenwick[flg];
		h+=ng;
		for(flg=ok;flg<=n+1;flg+=flg&-flg) fenwick[flg]++;
	}
	printf("%ld\n",h);
	return 0;
}


Measured memory_bytes: 6420
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int main(void){
  int X;
  scanf("%d",&X);
  if(X>=0 && X<=1000000000)
  {
    int a,b;
    a=X/500;
    a=a*1000;
    b=X%500;
    b=b/5;
    b=b*5;
    a=a+b;
    printf("%d",a);
  }
  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
# A - Honest or Dishonest
# 標準入力の取得
a,b = list(input().split())

# 全列挙
char_honest = "H"
char_dishonest = "D"
if a == char_honest:
    if b == char_honest:
        print(char_honest)
    else:
        print(char_dishonest)
else:
    if b == char_honest:
        print(char_dishonest)
    else:
        print(char_honest)

Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int a = sc.nextInt();
        int b = sc.nextInt();

        int answer = 0;
        for (int i=1; i<=n; i++){
            if (keta(i) >= a && keta(i) <= b){
                answer += i;
            }
        }

        System.out.println(answer);
    }

    private static int keta(int a){
        int man = a / 10000;
        int amari = a % 10000;
        int sen = amari / 1000;
        amari = a % 1000;
        int hyaku = amari / 100;
        amari = amari % 100;
        int zyuu = amari / 10;
        amari = amari % 10;
        return man + sen + hyaku + zyuu + amari;
    }

}


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

int main(){
	long N;
  cin>>N;
  long sum1=2;
  long sum2=1;
  
  if(N==1)
    cout<<sum2<<endl;
  else{
  	for(long i;i<N-1;i++){
      sum2+=sum1;
      sum1=sum2-sum1;
    }
    cout<<sum2<<endl;
  }
}

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

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

    int height[N];
    int dp[N];

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

    dp[0] = 0;
    
    for(int i = 0; i < N; i++){
        if(i == 1) {
            dp[i] = abs(height[1] - height[0]);
        } else if(i == 2) {
            dp[i] = min(abs(height[2] - height[0]), dp[1] + abs(height[2] - height[1]));
        } else {
            dp[i] = min(dp[i - 2] + abs(height[i] - height[i - 2]), dp[i - 1] + abs(height[i] - height[i - 1]));
        }
    }

    cout << dp[N - 1] << endl;





    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<string> ves;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)

int main(){
    int W,H,N; cin >> W >> H >> N;
    vei x(N),y(N),a(N);
    rep(i,N) cin >> x[i] >> y[i] >> a[i];
    ve_vei ans(W,vei(H));
    int an = 0;
    rep(i,W) rep(j,H) ans[i][j] = 1;
    rep(i,N) {
        if(a[i] == 1) rep(k,H) rep(j,x[i]) ans[j][k] = 0;
        if(a[i] == 2) rep(k,H) repk(j,x[i],W) ans[j][k] = 0;
        if(a[i] == 3) rep(k,W) rep(j,y[i]) ans[k][j] = 0;
        if(a[i] == 4) rep(k,W) repk(j,y[i],H) ans[k][j] = 0;
    } 
    rep(i,W) rep(j,H) an += ans[i][j];
    cout << an << endl;
    return 0;

}

Measured memory_bytes: 256
/**


文字列 str  に対して、与えられた命令の列を実行するプログラムを作成してください。命令は以下の操作のいずれかです：
?print a b: str  の a 文字目から b 文字目までを出力する。
?reverse a b: str  の a 文字目から b 文字目までを逆順にする。
?replace a b p: str  の a 文字目から b 文字目までを p に置き換える。

ここでは、文字列 str  の最初の文字を 0 文字目とします。

 */

//スキャナつかうため

import java.util.Scanner;

public class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成

		Scanner sc = new Scanner(System.in);

		// 文字列str,命令の数を受け取る
		String str = sc.nextLine();
		int intMeirei = sc.nextInt();
		String strMeirei;
		int intSaisyo;
		int intSaigo;
		String strKekka ;
		//intMeireiの数だけ処理を繰り返す
		for (int i = 0; i < intMeirei; i++) {
			//命令の内容を受け取る
			strMeirei = sc.next();
			//命令の最初の文字と最後の文字設定
			intSaisyo = sc.nextInt();
			intSaigo = sc.nextInt();
			//受け取った文字がreplace
			if (strMeirei.equals("replace")) {
				//指定された場所の文字と受け取った文字列を入れ替え
				String strOkikae = sc.next();
				//文字列０?最初の数字、最後の数字と文字列の長さまでの文字列をa,bに保持
				String a = str.substring(0,intSaisyo);
				String b =  str.substring(intSaigo+1,str.length());
				str = a + strOkikae + b ;

				//System.out.println(str);
			//受け取った文字がreverse
			} else if (strMeirei.equals("reverse")) {

				//指定された場所の文字列を変換、reverseで逆順にする。
				StringBuffer b = new StringBuffer(str.substring(intSaisyo,intSaigo + 1));
		        String strGyaku = b.reverse().toString();
		        //文字列０?最初の数字、最後の数字と文字列の長さまでの文字列をｃ、ｄに保持
		        String c = str.substring(0,intSaisyo);
		        String d = str.substring(intSaigo+1,str.length());
		        //保持した文字列と逆順にした文字列の結合
		        str =  c + strGyaku + d;


		        //System.out.println(str);

			//受け取った文字がprint
			} else if (strMeirei.equals("print")) {
				//最初の数字と最後の数字の位置の文字列表示
				strKekka= str.substring(intSaisyo,intSaigo+1);
				System.out.println(strKekka);

			}

		}
	}
}

Measured memory_bytes: 22564
#include<stdio.h> 
int main()
{
	char ch[52];
	int k=0,i=0,s=0,n;
	scanf("%d",&n);
	for(k=0;k<=n;k++)
		scanf("%c",&ch[k]);
	for(i=1;i<=n-2;i++)
	{
		if(ch[i]=='A'&&ch[i+1]=='B'&&ch[i+2]=='C')
			s++;
	}
	printf("%d",s);
	return 0;
}

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



typedef unsigned long ul;
typedef unsigned long long ull;
typedef long long ll;
typedef vector<ll> vint;
typedef vector< vector<ll> > vvint;
typedef vector< vector< vector<ll> > > vvvint;
typedef vector<string> vstring;
typedef vector< vector<string> > vvstring;
typedef vector<char> vchar;
typedef vector< vector<char> > vvchar;
typedef vector<long double> vdouble;
typedef vector< vector<long double> > vvdouble;
typedef vector< vector< vector<long double> > > vvvdouble;
typedef pair<ll,ll> pint;
typedef vector<pint> vpint;
typedef vector<bool> vbool;

#define rep(i,n) for(ll i=0;i<n;i++)
#define repf(i,f,n) for(ll i=f;i<n;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define ALL(obj) (obj).begin(), (obj).end()
#define vmax(vec) *max_element(vec.begin(), vec.end())
#define vmin(vec) *min_element(vec.begin(), vec.end())
#define vsort(vec) sort(vec.begin(), vec.end())
#define vsortgr(vec) sort(vec.begin(), vec.end(), greater<ll>())
#define MOD 1000000007
const double PI=3.14159265358979323846;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int msb(ll n){
  int ret = -1;

  while(n > 0){
    n>>=1;
    ret++;
  }


  return ret;
}


int main() {


  cout<<fixed<<setprecision(10);
  ll n;
  cin>>n;
  vint a(n);
  rep(i,n) cin>>a[i];
  sort(ALL(a));
  map<ll,ll> cnt;
  rep(i,n) cnt[a[i]]++;
  set<ll> used; // used indices
  ll ans = 0;


  for(ll i=n-1; i>=0; i--){
    // if(used.count(i)) continue;
    if(cnt[a[i]] == 0) continue;
    // cout<<a[i]<<endl;
    cnt[a[i]]--;
    if(a[i]&(a[i]-1) == 0){// 2べき
      if(cnt[a[i]] > 0){
        ans++;
        cnt[a[i]]--;
      }
    }else{
      ll t = (1<<(1+msb(a[i]))) - a[i];
      if(cnt[t]>0){
        ans++;
        cnt[t]--;
      }
    }

  }

  cout<<ans<<endl;



}
//


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

int main(void)
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    int N;
    cin >> N;

    string tmp;
    set<string> s;
    for(int i=0; i<N; i++){
        cin >> tmp;
        s.insert(tmp);
    }

    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19276
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;

int main() {
int ans=0;
int kari=0;
string s;
cin>>s;
char ss[4]={'A','T','G','C'};
rep(i,s.size()){
    char u=s[i];
    bool flag=0;
    rep(j,4){
        if(u==ss[j]){
            flag=1;
            break;
        }
    }
    if(flag==1){kari++;}else{kari=0;}
    ans=max(kari,ans);
    
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using std::cerr;using std::cin;using std::cout;using std::abs;using std::min;using std::max;using std::swap;using std::map;using std::unordered_map;using std::unordered_set;using std::bitset;using std::pair;using std::set;using std::string;using std::vector;using std::sort;using ll=long long;using uint=unsigned int;using pii=pair<int,int>;using pll=pair<ll,ll>;using ull = unsigned long long;using ld=long double;template<typename T>void _(const char*s,T h){cerr<<s<<" = "<<h<<"\n";}template<typename T,typename...Ts>void _(const char*s,T h,Ts...t){int b=0;while(((b+=*s=='(')-=*s==')')!=0||*s!=',')cerr<<*s++;cerr<<" = "<<h<<",";_(s+1,t...);}// break continue pop_back 998244353
#define int ll
#define pii pll
#define f first
#define s second
#define pb emplace_back
#define forn(i,n) for(int i=0;i<(n);++i)
#define sqr(x) ((x)*(x))
struct init{init(){cin.tie(0);std::iostream::sync_with_stdio(0);cout<<std::fixed<<std::setprecision(10);cerr<<std::fixed<<std::setprecision(5);}~init(){
#ifdef LOCAL
#define dbg(...) _(#__VA_ARGS__,__VA_ARGS__)
cerr<<"Time elapsed: "<<(double)clock()/CLOCKS_PER_SEC<<"s.\n";
#else
#define dbg(...) 
#endif
}}init;template<typename T,typename U>void upx(T&x,U y){if(x<y)x=y;}template<typename T,typename U>void upn(T&x,U y){if(x>y)x=y;}


const int N=2e5+5,OO=1e9;
pii es[N];
int ans[N];
int a[N];
char c[N];
vector<pii> g[N];
int par[N],rank[N];
int get(int x){return x==par[x]?x:(par[x]=get(par[x]));}
bool un(int x,int y){
    if((x=get(x))==(y=get(y)))return 0;
    if(rank[x]<rank[y])swap(x,y);
    return rank[x]+=(rank[x]==rank[y]),par[y]=x;
}
struct e{
    int x,y,c,i;
}rs[N];
int u[N];
void dfs(int v,char col){
    u[v]=1;
    c[v]=col;
    for(pii p:g[v]){
        if(!u[p.f]&&ans[p.s]!=-1){
            dfs(p.f,'B'^'W'^col);
        }
    }
}

int32_t main(){
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;++i){
        cin>>a[i];
        par[i]=i;
        rank[i]=0;
    }
    forn(i,m){
        int x,y;
        cin>>x>>y;
        g[x].pb(y,i);
        g[y].pb(x,i);
        ans[i]=-1;
        es[i]={x,y};
        rs[i]={x,y,max(a[x],a[y]),i};
    }
    for(int i=1;i<=n;++i){
        int ex=0;
        for(pii p:g[i]){
            if(a[p.f]<=a[i])ex=1;
        }
        if(!ex){
            cout<<"-1\n";
            return 0;
        }
    }
    sort(rs,rs+m,[](const e&p1,const e&p2){return p1.c<p2.c;});
    forn(i,m){
        e e=rs[i];
        if(un(e.x,e.y)){
            ans[e.i]=e.c;
        }else{
            ans[e.i]=-1;
        }
    }
    dfs(1,'B');
    for(int i=1;i<=n;++i)cout<<c[i];
        cout<<'\n';
    forn(i,m){
        if(ans[i]==-1)ans[i]=OO;
        cout<<ans[i]<<'\n';
    }

    return 0;
}


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

#define int long long

#define rep(i, n) for (signed i = 0; i < signed(n); i++)
#define REP(i, s, n) for (signed i = signed(s); i < signed(n); i++)
#define rrep(i, n) for (signed i = signed(s) - 1; i >= 0; i--)

#define all(c) begin(c), end(c)
template<typename T>bool maxup(T& a, const T&& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool maxup(T& a, const T& b) { if (a < b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T&& b) { if (a > b) { a = b; return true; }; }
template<typename T>bool minup(T& a, const T& b) { if (a > b) { a = b; return true; }; }

#define X first
#define Y second

using VV = vector<vector<int>>;
using V = vector<int>;
using P = pair<int, int>;
using IP = pair<int, P>;

template<typename T>
inline void input(vector<T>& v) { for (auto& x : v) cin >> x; }


void calc() {
	string s;
	cin >> s;
	rep(i, s.size() - 1) {
		if (s[i] == 'A' && s[i + 1] == 'C') {
			cout << "Yes" << endl;
			return;
		}
	}
	cout << "No" << endl;
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	calc();
#ifdef _MSC_VER
	system("pause");
#endif
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <numeric>
using namespace std;

int abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  A = A + B;
  C = C + D;
  if(A > C){
    cout << "Left" << endl;
  }
  else if(A == C){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Right" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
int A,B,C,X,Y;
int main(){
    cin >> A >> B >> C >> X >> Y;
    int num;
    if(X >= Y) num = Y*2*C + (X-Y)*A;
    else num =  X*2*C + (Y-X)*B;
    
    cout << min(C*2*max(X,Y),min(num ,A*X + B*Y)) << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
 
ll gcd(ll a, ll b){
  if(b == 0){
    return a;
  }
  else{
    return gcd(b,(a%b));
  }
}
ll lcm(ll a,ll b){
  return a/gcd(a,b)*b;
}
ll mpower(ll a,ll b,ll c){
    int z;
    if(b==0){
        z=1;
        z%=c;
        return z;
    }
    if(b==1){
        z=a;
        z%=c;
        return z;
    }
    else{
        return (((mpower(a,b/2,c))*(mpower(a,b/2,c))%c)*mpower(a,b%2,c)%c);
    }
}

int main(){
  int a,b,m;
  cin>>a>>b>>m;
  int vec[a];
  int vecb[b];
  int x=1999999,y=1999999;
  for(int i=0;i<a;i++){
    cin>>vec[i];
    x=min(x,vec[i]);
  }
  for(int i=0;i<b;i++){
    cin>>vecb[i];
    y=min(y,vecb[i]);
  }
  int ans=x+y;
  int p,q,r;
  for(int i=0;i<m;i++){
    cin>>p>>q>>r;
    ans=min(ans,vec[p-1]+vecb[q-1]-r);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
using System;

namespace aoj9b
{
    class Program
    {
        static void Main(string[] args)
        {
            for (;;)
            {
                /*???????????????????????????????????????*/
                string line = Console.ReadLine();
                if (line == "-")
                {
                    return;
                }

                int m = int.Parse(Console.ReadLine());
                int n = 0 ;

                for(int i = 0; i < m; i++)
                {
                    n += int.Parse(Console.ReadLine());
                }
                
                line = shuffleN(line, n);
                Console.WriteLine(line);
            }
        }

        /*n????????£???????????????????????????*/
        private static string shuffleN(string line, int n)
        {
            for( int i = 0; i < n; i++)
            {
                line = shuffle(line);
            }
            return line;
        }

        /*1????????£???????????????????????????*/
        private static string shuffle(string line)
        {
            string str = line.Substring(0, 1);      //line????????????????????????str??????????????????
            line = line.Remove(0, 1);               //line?????????????????????????¶????
            line += str;                            //?¶????????????????????°???????????¶????

            return line;
        }
    }
}

Measured memory_bytes: 9048
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<cctype>
#include<vector>
using namespace std;
typedef int mmp;
#define vd void
#define rg register
#define il inline
#define sta static
il int gi(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return x*f;
}
const int maxn=1e5+1,maxm=maxn<<1;
int fir[maxn],dis[maxm],nxt[maxm],w[maxm],id;
il vd link(int a,int b,int c){nxt[++id]=fir[a],fir[a]=id,dis[id]=b,w[id]=c;}
vector<int>S;
int col[maxn],faq[maxn],tot,yes[maxm];
il int fuck(int x){
	while(x<1)x+=3;
	while(x>3)x-=3;
	return x;
}
il vd dfs(int x,int c){
	if(col[x]){
		if(c!=col[x])faq[x]=1;
		return;
	}
	S.push_back(x);col[x]=c;
	for(rg int i=fir[x];i;i=nxt[i]){
		if(!yes[i])++tot,yes[i]=1;
		dfs(dis[i],fuck(c+w[i]));
	}
}
mmp main(){
	int n=gi(),m=gi(),x,y;
	while(m--){
		x=gi(),y=gi();
		link(x,y,1);
		link(y,x,-1);
	}
	long long ans=0;
	for(rg int i=1;i<=n;++i)
		if(!col[i]){
			tot=0;S.clear();
			dfs(i,1);
			int a[4]={0},d=0;
			for(rg int i=0;i<S.size();++i){
				if(faq[S[i]]){d=1;break;}
				++a[col[S[i]]];
			}
			if(d)ans+=S.size()*S.size();
			else if(a[1]==0||a[2]==0||a[3]==0)ans+=tot/2;
			else ans+=1ll*a[1]*a[2]+1ll*a[2]*a[3]+1ll*a[3]*a[1];
		}
	printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 6520
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
int main() {
    string s; cin >> s;
    int n = s.size();
    string ans;
    rep(i, n) {
        if(s[i] == 'B') {
            if(!ans.empty()) ans.pop_back();
        } else {
            ans.push_back(s[i]);
        }
    }
    cout << ans;
}


Measured memory_bytes: 256
from collections import Counter

n = int(input())
A = list(map(int, input().split()))
q = int(input())
B = list()
C = list()

for i in range(q):
    b, c = map(int, input().split())
    B.append(b)
    C.append(c)

sum_a = sum(A)
c = Counter(A)
for i in range(q):
    b_num = c[B[i]]
    diff = (C[i] - B[i]) * b_num
    c[C[i]] = c[C[i]] + c[B[i]]
    c[B[i]] = 0
    sum_a = sum_a + diff
    print(sum_a)


Measured memory_bytes: 30240
#include<bits/stdc++.h>
#define ll long long
#define MAX 1000005
#define evn(x) (!((x)&1))
#define MOD (ll)(1e9+7)
#define INF INT32_MAX
#define INFL INT64_MAX
using namespace std;

void solve()	{
	string s;
	cin >> s;
	ll w=0;
	ll ans=0;
	for(int i=0; i<s.size(); i++)	{
		if(s[i]=='W')	{
			ans+=w;
		}
		else w++;
	}
	cout << ans << endl;
}

int main()	
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	//cin >> t;
	for(int i=1; i<=t; i++)	{
		solve();
	}
	return 0;
}

Measured memory_bytes: 3764
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

char a,b;

int main(){
    cin>>a>>b;
    if(a=='H'){
        out(b);
    }
    else{
        if(b=='H'){
            out('D');
        }
        else{
            out('H');
        }
    }
}


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

double COS60 = cos(M_PI / 3.0), SIN60 = sin(M_PI / 3.0);

void print(double p[2]) {
  printf("%f %f\n", p[0], p[1]);
}

void add(double ret[2], double p1[2], double p2[2]) {
  ret[0] = p1[0] + p2[0];
  ret[1] = p1[1] + p2[1];
}

void subtract(double ret[2], double p1[2], double p2[2]) {
  ret[0] = p1[0] - p2[0];
  ret[1] = p1[1] - p2[1];
}

void multiply(double ret[2], double p[2], double a) {
  ret[0] = p[0] * a;
  ret[1] = p[1] * a;
}

void devide(double ret[2], double p[2], double a) {
  ret[0] = p[0] / a;
  ret[1] = p[1] / a;
}

double norm(double x[2]) {
  return sqrt(x[0] * x[0] + x[1] * x[1]);
}

void rot60(double ret[2], double x[2]) {
  double tmp[2] = {x[0], x[1]};
  ret[0] = COS60 * tmp[0] - SIN60 * tmp[1];
  ret[1] = SIN60 * tmp[0] + COS60 * tmp[1];
}

void coch(int n, double p1[2], double p2[2]) {
  if(n == 0) {
    return;
  }
  double s[2], t[2], u[2], d[2];

  // d = ( p2 - p1 ) / 3
  subtract(d, p2, p1);
  devide(d, d, 3.0);

  // calc s
  add(s, d, p1);
  // calc u
  multiply(u, d, 2);
  add(u, u, p1);
  // calc t
  rot60(t, d);
  add(t, t, s);

  coch(n - 1, p1, s);
  print(s);
  coch(n - 1, s, t);
  print(t);
  coch(n - 1, t, u);
  print(u);
  coch(n - 1, u, p2);
}

int main(void) {
  int n;
  scanf("%d", &n);

  double p1[2] = {0.0, 0.0};
  double p2[2] = {100.0, 0.0};
  print(p1);
  coch(n, p1, p2);
  print(p2);
  return 0;
}

Measured memory_bytes: 2752
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c=0;cin>>a>>b;
  for(int i=0;i<2;i++){
    if(a>=b)c+=a, a-=1;
    else c+=b,b-=1;
  }
  cout<<c<<endl;
}

Measured memory_bytes: 256
import sys

def get_array(): return list(map(int, sys.stdin.readline().strip().split()))
def get_ints(): return map(int, sys.stdin.readline().strip().split())
def input(): return sys.stdin.readline().strip()

a,b = get_ints()
if a<=9 and b<=9:
    print(a*b)
else:
    print(-1)

Measured memory_bytes: 38384
#include <cstdio>
#include <algorithm>
using namespace std;
int n,i,a[100050];
int main()
{
	scanf("%d",&n);
	for (i=1;i<=n;i++){
		int x;scanf("%d",&x);a[x+1]++;
	}int ans=0;
	for (i=1;i<=100000;i++) ans=max(ans,a[i]+a[i-1]+a[i+1]);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 512
n,m = map(int,input().split())
if n >= m:
  print(0)
  exit()

xm = [int(i) for i in input().split()]
xm.sort()
dist = [xm[i+1] - xm[i] for i in range(m - 1)]
dist.sort()
print(sum(dist[:m-n]))

Measured memory_bytes: 13840
S = list(input())
n = len(S)
dp = [[0] * 13 for _ in range(n + 1)]

MOD = 10 ** 9 + 7

def solve():
    res = 0
    dp[0][0] = 1
    for i in range(n): #n文字順番に確かめる
        if S[i] == '?': #i文字目が自由のとき
            c = -1
        else:
            c = int(S[i])
        
        for j in range(10):
            if c != -1 and c != j:
                continue
            for k in range(13):
                dp[i + 1][(k * 10 + j) % 13] += dp[i][k]
        
        for j in range(13):
            dp[i + 1][j] %= MOD
    # print (dp)
    res = dp[n][5]
    return res

print (solve())



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

int n, m,q;
int ans=0;
vector<int> a(50),b(50),c(50),d(50),e(10);

void dfs(int dep, int curr){
  if(dep==n){
    int tmp=0;
    for(int i=0;i<q;i++){
      if( e.at(b.at(i)-1) -e.at(a.at(i)-1) == c.at(i) )
        tmp +=d.at(i);
    }
    ans =max(ans,tmp);
    return;
  }
  for(int i=curr;i<=m;i++){
    e.at(dep) =i;
    dfs(dep+1, i);
  }
}

int main(){
  cin >> n >> m >> q;
  for(int i=0;i<q; i++){
    cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);
  }
  
  dfs(0,1);
  cout <<ans << endl;
}


Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
 
int main() {
	int N,K,B=0;
	cin>>N>>K;
	for(int i=0; i<N; i++){
		int A;
		cin>>A;
		if(A*2<=K){
			B+=A*2;
		}
		else{
			B+=((K-A)*2);
		}
	}
	cout<<B<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(){
  char s[11],r[21],t[11];
  int n,c=0,i;
  scanf("%s %d",s,&n);
  for(i=0;i<n;i++){
    scanf("%s",r);
    strcpy(t,r);
    strcat(r,t);
    if(strstr(r,s))c++;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 624
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
int main(){
  ll n ;cin>>n;
  vector<ll> A(n) ;
  vector<ll> B(n) ;
  rep(i,n){
    cin>>A[i]>>B[i] ;
  }
  sort(A.begin(),A.end()) ;
  sort(B.begin(),B.end()) ;
  if(n%2==1){
    cout<<B[(n-1)/2]-A[(n-1)/2]+1<<endl ;
  }
  else{
    cout<<(B[(n/2)-1]+B[(n/2)])
    -(A[(n/2)-1]+A[(n/2)])+1<<endl ;
  }
    return 0;
  }

Measured memory_bytes: 6428
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner num = new Scanner(System.in);
        int a = num.nextInt();
        int b = num.nextInt();

        if(a < b) {
            System.out.println("a < b");
        } else if(a > b) {
            System.out.println("a > b");
        } else {
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26408
import java.io.*;
 
class Main{
    public static void main(String[] args) throws IOException{
     
        int x,y;
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str[] = br.readLine().split(" ");
        x = Integer.parseInt(str[0]);
        y = Integer.parseInt(str[1]);

	if(x>y){
        	System.out.println("a > b");
	}else if(x<y){
		System.out.println("a < b");
	}else{
		System.out.println("a == b");
	}
    }
}

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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll INF = 1e17 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 2e5 + 5;

vector<pair<ll, pii> > ee;

int a[MAXN];
int par[MAXN];
ll d;

int get_par(int v) {
	return v == par[v] ? v : par[v] = get_par(par[v]);
}

void rec_sol(int l, int r) {
	if (l == r) {
		return;
	}
	int mid = (l + r) >> 1;
	rec_sol(l, mid);
	rec_sol(mid + 1, r);
	ll mn_l = INF, mn_r = INF;
	int minl = l, minr = r;
	REPN(i, l, mid) {
		ll val = (ll)a[i] + d * (mid - i);
		if (val < mn_l) {
			mn_l = val;
			minl = i;
		}
	}
	REPN(i, mid + 1, r) {
		ll val = (ll)a[i] + d * (i - mid - 1);
		if (val < mn_r) {
			mn_r = val;
			minr = i;
		}
	}
	REPN(i, l, mid) {
		ee.pb(mp(mn_r + d * (mid + 1 - i) + a[i], mp(i, minr)));
	}
	REPN(i, mid + 1, r) {
		ee.pb(mp(mn_l + d * (i - mid) + a[i], mp(minl, i)));
	}
}

void solve(){
	int n;
	scanf("%d%lld", &n, &d);
	REP(i, 0, n) {
		scanf("%d", &a[i]);
	}
	rec_sol(0, n - 1);
	SORT(ee);
	REP(i, 0, n) {
		par[i] = i;
	}
	ll ans = 0ll;
	REP(i, 0, SZ(ee)) {
		int a = ee[i]._2._1, b = ee[i]._2._2;
		//printf("%lld %d %d %d %d\n", ee[i]._1, a, b, get_par(a), get_par(b));
		a = get_par(a);
		b = get_par(b);
		if (a != b) {
			ans += ee[i]._1;
			par[a] = b;
		}
	}
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 68704