akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
typedef pair<P, int> PP;
const int mod = 1000000007;
const int INF = 1e12;

char c[110][110];
int d[110][110][4];
int h, w, l;
string str = "NESW";
int dy[4] = {-1, 0, 1, 0};
int dx[4] = { 0, 1, 0,-1};
bool contain(int y, int x){
   return (0 <= y && y < h && 0 <= x && x < w);
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    while(1){
        cin >> h >> w >> l;
        if(h + w + l == 0) break;
        int dr = 0, y = 0, x = 0;
        rep(i, 0, 110) rep(j, 0, 110) rep(k, 0, 4) d[i][j][k] = -1;
        rep(i, 0, h){
            rep(j, 0, w){
                cin >> c[i][j];
                if(str.find(c[i][j]) != string::npos){
                    dr = str.find(c[i][j]);
                    y = i; x = j;
                }
            }
        }
        d[y][x][dr] = 0;
        vector<PP> sv;
        sv.push_back(PP(P(y, x), dr));
        for(int i = 1;; i++){
            int ny = 0, nx = 0;
            while(1){
                ny = y + dy[dr];
                nx = x + dx[dr];
                if(contain(ny, nx) && c[ny][nx] != '#'){
                    break;
                }
                dr = (dr + 1) % 4;
            }
            y = ny; x = nx;    
            if(i == l){
                cout << y + 1 << ' ' << x + 1 << ' ' << str[dr] << endl;
                break;
            }        
            if(d[y][x][dr] != -1){
                int loop = i - d[y][x][dr];
                int step = d[y][x][dr] + (l - d[y][x][dr]) % loop;
                //cerr << loop << ' ' << step << endl;
                cout << sv[step].first.first + 1 << ' ' << sv[step].first.second + 1 << ' ' << str[sv[step].second] << endl;
                break;
            }
            d[y][x][dr] = i;
            sv.push_back(PP(P(y, x), dr));
        }
    }
}



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

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<double> b;
    for(int i=0; i<n; i++){
        double t;
        cin >> t;
        b.push(t);
    }
    for(int i=0; i<m; i++){
        double t = b.top();
        b.pop();
        b.push(t/2.0);
    }
    long long ans = 0;
    for(int i=0; i<n; i++){
        ans += floor(b.top());
        b.pop();
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1400
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using ml = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define CEIL(a, b) ((a - 1) / b + 1)

void solve() {
    int N, X, M, S = 0;
    cin >> N >> X >> M;
    vector<pair<int, int>> memo(M);
    REP(i, N) {
        // 循環した場合
        if (memo[X].first) {
            // ループ間の長さ
            int t = i - memo[X].first;
            // ループが繰り返される回数
            int c = (N - i - 1) / t;
            i += t * c;
            S += (S - memo[X].second) * c;
        } else {
            memo[X] = {i, S};
        }
        S += X;
        X = X * X % M;
    }
    cout << S << endl;
}

signed main() {
    cin.tie(nullptr)->sync_with_stdio(false);
    solve();
}


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

int main() {
	string S; cin >> S; int cnt = 0;
	for (int i = 2; i < S.size() - 1; i++) {
		if (S[i] == 'C') cnt++;
	}
	if (cnt == 1 && S[0] == 'A') {
		int rem = 0;
		for (int i = 0; i < S.size(); i++) {
			if ('A' <= S[i] && S[i] <= 'Z') rem++;
		}
		if (rem == 2) cout << "AC" << endl;
		else cout << "WA" << endl;
	}
	else cout << "WA" << endl;
	return 0;
}


Measured memory_bytes: 256
def solve():
    N = int(input())
    S = input()

    def rolling_hash(s, mod, base = 37):
        l = len(s)
        h = [0]*(l + 1)
        v = 0
        for i in range(l):
            h[i+1] = v = (v * base + ord(s[i])) % mod
        pw = [1]*(l + 1)
        v = 1
        for i in range(l):
            pw[i+1] = v = v * base % mod
        return h, pw

    def chk(S, mod, D = [0]*N):
        h, pw = rolling_hash(S, mod)
        left = 0; right = N//2+1
        while left+1 < right:
            l = mid = (left + right) >> 1
            p = pw[l]
            for i in range(min(l, N-2*l+1)):
                D[i] = (h[l+i] - h[i]*p) % mod
            s = set()
            ok = 0
            for i in range(l, N-l+1):
                s.add(D[i-l])
                D[i] = v = (h[l+i] - h[i]*p) % mod
                if v in s:
                    ok = 1
                    break
            if ok:
                left = mid
            else:
                right = mid
        return left

    print(chk(S, 10**9 + 9))
solve()

Measured memory_bytes: 3800
#include<bits/stdc++.h>
#define ll long long
#define vl vector
#define pb push_back
using namespace std;
int main()
{
    ll a,b,i,j,n,k,t,m;
    cin>>n;
    string s;
    cin>>s;
    if(n%2) cout<<"No";
    else
    {
        n/=2;
        string s1=s.substr(0,n);
        string s2=s.substr(n,n);
        if(s1==s2) cout<<"Yes";
        else cout<<"No";
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define int long long
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n;
    map<string, int> mp;
    rep(i, 0, n){
        string s;
        cin >> s;
        mp[s]++;
    }
    cin >> m;
    rep(i, 0, m){
        string s;
        cin >> s;
        mp[s]--;
    }
    int ans = 0;
    for(auto i : mp){
        if(i.second > 0) ans = max(ans, i.second);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;

class MainClass {
    static void Main() {
        Scanner cin=new Scanner();

        int a=cin.nextInt();
        int b=cin.nextInt();
        int c=cin.nextInt();

        int res=2;
        if (a==b && b==c) {
            res = 1;
        } else if (a!=b && b!=c && c!=a) {
            res = 3;
        }

        Console.WriteLine(res);
    }
}

class Scanner {
    string[] buf;
    int i;
    char[] SplitChar=new char[] {' '};
    public Scanner() {
        buf = new string[0];
        i = 0;
    }
    public string next() {
        if (i < buf.Length) return buf[i++];

        string tmp=Console.ReadLine();
        while (tmp == "")
            tmp = Console.ReadLine();

        buf = tmp.Split(SplitChar, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return buf[i++];
    }
    public int nextInt() {
        return int.Parse(next());
    }
    public long nextLong() {
        return long.Parse(next());
    }
    public double nextDouble() {
        return double.Parse(next());
    }
}


Measured memory_bytes: 2648
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e16;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)





int main() {
    int n;
    scanf("%d", &n);
    double ans = 0.0;
    for(int i = 0; i < n; i++){
        double x;
        char u[4];
        scanf("%lf %s", &x, u);
        if(u[0] == 'J') ans += x;
        else ans += 380000.0 * x;
    }
    printf("%.7lf\n", ans);
}


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

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextInt();
        long m = sc.NextInt();
        string s = sc.Next();
        string t = sc.Next();

        long answer = Lcm(n, m);

        long stepN = answer / n;
        long stepM = answer / m;
        for (long i = 0; i < n; i++)
        {
            long index = stepN * i;
            if (index % stepM == 0)
            {
                int indexS = (int)(index / stepN);
                int indexT = (int)(index / stepM);

                if (indexS >= n || indexT >= m)
                {
                    continue;
                }

                char schar = s[indexS];
                char tchar = t[indexT];

                if (schar != tchar)
                {
                    Console.WriteLine(-1);
                    return;
                }
            }
        }

        Console.WriteLine(answer);
    }

    // 最大公約数（long）
    private static long Gcd(long a, long b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            long r = a % b;
            a = b;
            b = r;
        }
        return a;
    }

    // 最小公倍数（long）
    private static long Lcm(long a, long b)
    {
        return a / Gcd(a, b) * b;
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 13192
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

using uint = unsigned;
const uint MOD = 1E9 + 7;
struct Z {
    uint v;

    Z(uint v = 0) : v(v) {}

    Z& operator += (const Z &z) {
        v += z.v;
        if (v >= MOD) v -= MOD;
        return *this;
    }

    Z& operator -= (const Z &z) {
        if (v < z.v) v += MOD;
        v -= z.v;
        return *this;
    }

    Z& operator *= (const Z &z) {
        v = static_cast<uint64_t>(v) * z.v % MOD;
        return *this;
    }
};

ostream& operator << (ostream &os, const Z &z) {
    return os << z.v;
}

Z operator + (const Z &x, const Z &y) {
    return Z(x.v + y.v >= MOD ? x.v + y.v - MOD : x.v + y.v);
}

Z operator - (const Z &x, const Z &y) {
    return Z(x.v < y.v ? x.v + MOD - y.v : x.v - y.v);
}

Z operator * (const Z &x, const Z &y) {
    return Z(static_cast<uint64_t>(x.v) * y.v % MOD);
}

Z qpow(Z base, uint e) {
    Z ret(1);
    for (; e; e >>= 1) {
        if (e & 1) {
            ret *= base;
        }
        base *= base;
    }
    return ret;
}

const size_t N = 2E5 + 5;
const size_t S = 2E3 + 2;
const size_t M = 4E3 + 5;
const size_t L = 8E3 + 5;

int n, a[N], b[N];
Z fac[L], inv[L], f[M][M];

void prep() {
    fac[0] = 1;
    for (uint i = 1; i < L; ++i) {
        fac[i] = fac[i - 1] * i;
    }
    inv[L - 1] = qpow(fac[L - 1], MOD - 2);
    for (uint i = L; --i; ) {
        inv[i - 1] = inv[i] * i;
    }
}

int main() {
    prep();
    n = read();
    for (int i = 0; i < n; ++i) {
        a[i] = read();
        b[i] = read();
        f[S - a[i]][S - b[i]] += 1;
    }
    for (uint i = 1; i < M; ++i) {
        for (uint j = 1; j < M; ++j) {
            f[i][j] += f[i - 1][j] + f[i][j - 1];
        }
    }
    Z ans = 0;
    for (int i = 0; i < n; ++i) {
        ans += f[S + a[i]][S + b[i]];
        ans -= fac[(a[i] + b[i]) << 1] * inv[a[i] << 1] * inv[b[i] << 1];
    }
    ans *= (MOD + 1) >> 1;
    cout << ans;
    return 0;
}


Measured memory_bytes: 65024
n, m = map(int, input().split())
str_1 = ""
str_2 = ""
list_1 = []
for i in range(m):
  str_1 += str(n)
list_1.append(str_1)
for i in range(n):
  str_2 += str(m)
list_1.append(str_2)
sort_list = sorted(list_1)
print(sort_list[0])

Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    string S; cin >> S;
    string T = S;
    reverse(T.begin(), T.end());
    map<char, char> mp;
    mp['b'] = 'd';
    mp['d'] = 'b';
    mp['p'] = 'q';
    mp['q'] = 'p';
    rep(i, T.length()) {
        T[i] = mp[T[i]];
    }
    if(S == T) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 512
def main():
    import sys
    input = sys.stdin.readline

    mod = 1000000007
    N, K = map(int, input().split())
    n = N//2
    dp = [[[0] * (N**2+1) for _ in range(n+1)] for _ in range(N+1)]
    dp[0][0][0] = 1

    for i in range(N):
        for j in range(n+1):
            for k in range(N**2+1):
                #print(i+1, j, k+2*j)
                if k+2*j <= N**2:
                    dp[i+1][j][k+2*j] = (dp[i+1][j][k+2*j] + dp[i][j][k])%mod
                    if j+1 <= n:
                        dp[i+1][j+1][k+2*j] = (dp[i+1][j+1][k+2*j] + dp[i][j][k])%mod
                    dp[i + 1][j][k + 2 * j] = (dp[i + 1][j][k + 2 * j] + (dp[i][j][k]*2 * j)%mod) % mod
                    dp[i+1][j-1][k+2*j] = (dp[i+1][j-1][k+2*j] + (dp[i][j][k]*j*j)%mod)%mod
    print(dp[-1][0][K])


if __name__ == '__main__':
    main()


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

int main(){
  int N, M, S;
  while(cin >> N >> M >> S, N){
    // dp[i][j]: 場所iで今の合計がjのときの組み合わせ数
    vector < vector< int > > dp( N * N + 1, vector< int >( S + 1, 0));
    dp[0][0] = 1;
    for(int i = 1; i <= M; i++){ // 選ぶ数字
      for(int j = N * N; j >= 1; j--){ // idx
        for(int k = i; k <= S; k++){ // 合計
          (dp[j][k] += dp[j - 1][k - i]) %= 100000;
        }
      }
    }
    cout << dp[N * N][S] << endl;
  }
}

Measured memory_bytes: 1796
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long
 
int main(){
  int N;
  cin >> N;
  if(N==0){
    cout << 0 << endl;
    return 0;
  }
 
  int s[100];
  int l=0;
  while(N!=0){
    if(N%2!=0){
      s[l]=1;
      --N;
    }
    else s[l]=0;
    N=-N/2;
    ++l;
  }
 
  for(int i=l-1; i>-1; --i){
    cout << s[i];
  }
 
 
  return 0;
}

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

#define N 100
#define INFTY (1<<30)
int n,m[N][N],d[N];//通过距离管理访问状态(color)

void bfs(int s) //广搜
{
    queue<int> q;
    q.push(s);
    for(int i=0;i<n;i++) d[i]=INFTY; //注意这里不能用memset
    d[s]=0; //初始化

    while(!q.empty())
    {
        int u=q.front();q.pop();
        for(int v=0;v<n;v++)
        {
            if(m[u][v]&&d[v]==INFTY) //如果有节点与u相邻且该节点没有被访问过
            {
                d[v]=d[u]+1; //距离+1
                q.push(v); //将该节点加入待访问队列中
            }
        }
    }

    for(int i=0;i<n;i++)
        cout<<i+1<<" "<<(d[i]==INFTY ? -1 : d[i])<<endl; //注意这里要用括号
}

int main()
{
    int u,k,v;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>u>>k;
        u--;
        for(int j=0;j<k;j++)
        {
            cin>>v;
            v--;
            m[u][v]=1;
        }
    }
    bfs(0);
    return 0;
}


Measured memory_bytes: 3124
while true
    n, h = gets.chomp.split.map(&:to_i)
    break if [n, h] == [0, 0]
    holes = {}
    h.times{
        c, a, b = gets.chomp.split
        a, b = a.to_i, b.to_i
        case c
        when "xy" then 1.upto(n){|i| holes[[a, b, i]] = true}
        when "xz" then 1.upto(n){|i| holes[[a, i, b]] = true}
        when "yz" then 1.upto(n){|i| holes[[i, a, b]] = true}
        end
    }
    p n ** 3 - holes.length
end


Measured memory_bytes: 17756
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

typedef tuple<ll, ll, ll> T;

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


int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<int> l(n);
  REP(i,n) cin>>l[i];
  VSORT(l);
  int sum=0;
  REP(i,n-1) sum+=l[i];
  sum > l[n-1] ? cout<<"Yes" : cout<<"No";
  cout<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <limits>
#include <algorithm>
#include <memory>
#include <climits>

constexpr long long MOD = 1000000007;

int gcd(int m, int n)
{
  return n == 0 ? m : gcd(n, m % n);
}

int main()
{
  int N;
  std::cin >> N;
  std::vector<long long> a(N);
  for (auto& val: a)
    std::cin >> val;
  std::vector<long long> dp1(N, 0);
  std::vector<long long> dp2(N, 0);
  dp1[1] = a[0] + a[1];
  dp2[1] = -a[0] -a[1];
  for (int i = 2; i < N; ++i)
  {
    dp1[i] = std::max(dp1[i-1]+a[i], dp2[i-1]+a[i]);
    dp2[i] = std::max(dp1[i-1]-a[i]-2*a[i-1], dp2[i-1]-a[i]+2*a[i-1]);
  }
  std::cout << std::max(dp1.back(), dp2.back()) << std::endl;
  return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define sort(a) sort((a).begin(),(a).end())
#define rev(a) reverse((a).begin(),(a).end())
using db = double;
using namespace std;
typedef long long ll;


int main() {
  string s;
  cin >> s;
  int cnt = 0;
  rep(i,3) {
    if (s[i] == 'o') cnt++;
  }
  cout << 700 + 100 * cnt << endl;
}
  

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main() {
    string s;
    cin >> s;
    reverse(s.begin(), s.end());

    int m = 2019;
    vector<int> count(m);

    int t = 0, x = 1;
    long long ans = 0;

    for (int i = 0; i < s.size(); i++) {
        count[t]++;
        t += (s[i] - '0') * x;
        t %= m;
        ans += count[t];
        x = x * 10 % m;
    }

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


Measured memory_bytes: 3684
# E - Dividing Chocolate
import numpy as np

H, W, K = map(int, input().split())
S = np.zeros((H, W), dtype=np.int64)

ans = H+W

for i in range(H):
    S[i] = list(str(input()))

for m in range(2**(H-1)):
    wp = np.zeros((H, W), dtype=np.int64)
    wq = np.zeros((H, ), dtype=np.int64)
    wp[0] = S[0]
    cut = 0
    for n in range(H-1):
        if m>>n&1:
            cut += 1
        wp[cut] += S[n+1]

    if cut >= ans or np.count_nonzero(wp > K):
        continue

    for j in range(W):
        wq += wp[:,j]
        if np.count_nonzero(wq > K):
            cut += 1
            wq = wp[:,j]
    ans = min(ans, cut)

print(ans)




Measured memory_bytes: 12616
#include <iostream>
#include <string>
#include <map>
#include <vector>
#define rep(i,a) for(int i=0;i<(a);++i)

using ll = long long;

std::string A;
std::map<char, ll> cnt;
std::vector<ll> vs;

int main()
{
  std::cin >> A;
  rep( i, A.size() )
    ++cnt[A[i]];

  for( auto it = cnt.begin(); it != cnt.end(); ++it )
    vs.push_back( it->second );

  ll ans = 1;
  rep( i, vs.size() ) rep( j, i )
    ans += vs[i]*vs[j];

  printf( "%lld\n", ans );

  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <utility>
#include <string>
#include <math.h>
#include <algorithm>
#include <cstring>
#include <cctype>

typedef long long int lli;

using namespace std;

int main() {
   
   int N;
   lli y=1;
   cin >> N;
   lli *A = new long long int[N]();

   for (int i=0;i<N;i++){
      cin >> A[i];
      //cout << A[i] << endl;
      if(A[i]==0){
         y=0;
         cout << 0 << endl;
         return 0;
      }
   }
   for (int i=0;i<N-1;i++){
      y*=A[i];
      if(y*A[i+1]>1000000000000000000 || y*A[i+1] <y){
         cout << -1 << endl;
         return 0;
      }
   }
   y=y*A[N-1];
   if(y>=0 && y<=1000000000000000000){  
         printf("%lld\n",y);
   }

}

Measured memory_bytes: 4376
#include<bits/stdc++.h>
using namespace std;
#define num 1000000007
//#define num 998244353
#define REP(i,a,n) for(ll i=a;i<n;i++)
#define inarr(i,a,n,A) for(ll i=a;i<n;i++) { cin>>A[i]; }
#define vll vector<long long>
#define pii pair <int,int>
#define pll pair<long long, long long>
#define vpii vector< pair <int,int>>
#define vpll vector< pair<long long, long long>>
#define max(a,b) ((a>b)?a:b)
#define min(a,b) ((a>b)?b:a)
#define max3(a,b,c) ((a>b)?(a>c)?a:c:(b>c)?b:c)
#define min3(a,b,c) ((a<b)?(a<c)?a:c:(b<c)?b:c)
#define avg(a,b) ((a)+(b))/2
#define push push_back
#define pop pop_back
#define sf int flag=0     //Remember semicolon
#define assmin(a,b) if(b<=a) { a=b; }
#define assmax(a,b) if(b>=a) { a=b; }
#define f first
#define s second
#define fix(f,n) std::fixed<<std::setprecision(n)<<f
typedef long long ll;
ll mod(ll a, ll b)
{
	if(a%b<0)
	{
		return a%b + b;
	}
	return a%b;
}
 
 
ll mod_exp(ll a, ll b, ll c)
{
	ll res=1;
	a=a%c;
	while(b>0)
	{
		if(b%2==1)
		{
			res=(res*a)%c;
		}
		b/=2;
		a=(a*a)%c;
	}
	return res;
}
ll mymod(ll a,ll b)
{
    return ((a%b)+b)%b;
}
bool prime[200001];
void SieveOfEratosthenes() 
{ 
    memset(prime, true, sizeof(prime)); 
    prime[1]=false;
    for (int p=2; p*p<=200000; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=200000; i += p) 
                prime[i] = false; 
        } 
    } 
    return;
}
ll powe[60];
void power()
{
    powe[0]=1;
    REP(i,1,15)
    {
        powe[i]=2*powe[i-1];
    }
}
ll gcdExtended(ll,ll,ll *,ll *);
ll modInverse(ll a, ll m) 
{ 
    ll x, y; 
    ll g = gcdExtended(a, m, &x, &y); 
        ll res = (x%m + m) % m;
        return res;
} 
ll gcdExtended(ll a, ll b, ll *x, ll *y) 
{ 
    if (a == 0) 
    { 
        *x = 0, *y = 1; 
        return b; 
    } 
    ll x1, y1; 
    ll gcd = gcdExtended(b%a, a, &x1, &y1); 
    *x = y1 - (b/a) * x1; 
    *y = x1; 
    return gcd; 
} 
ll facto(ll n,ll k)
{
	if(n<=k)
	return 1;
	if(k==1)
	{
		return n;
	}
	if(k==2)
	{
		return ((n)*(n-1))/2;
	}
	return ((n)*(n-1)*(n-2))/6;
}
bool my(pair<double,ll> p1, pair<double,ll> p2)
{
	if(p1.f<p2.f)
	return true;
	if(p1.f==p2.f && p2.s>p1.s)
	return true;
	return false;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,a;
    cin>>n;
    sf;
    REP(i,0,n)
    {
        cin>>a;
        if(!(a&1))
        {
            if(a%3!=0 && a%5!=0)
            {
                flag++;
            }
        }
    }
    if(!flag)
    {
        cout<<"APPROVED\n";
    }
    else
    {
        cout<<"DENIED\n";
    }
	return 0;
}

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

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }

        static void SolveA(string[] args)
        {
            long[] nx = ReadAndParseLongArr();
            long N = nx[0];
            long X = nx[1];
            long[] xarr = ReadAndParseLongArr();
            var xlist = new List<long>(xarr);
            xlist.Add(X);
            xlist.Sort();

            var distLis = new HashSet<long>();
            long distA = xlist[1] - xlist[0];
            long ans = distA;
            for(int i=2;i< xlist.Count;++i)
            {
                long preb = xlist[i - 1];
                long next = xlist[i];
                long distB = next - preb;
                ans = Math.Min(ans, gcd(distA, distB));
                distA = distB;
            }
            Console.WriteLine(ans);
        }

        static long gcd(long a, long b)
        {
            if( b == 0) { return a; }
            return gcd(b, a % b);
        }
    }
}

Measured memory_bytes: 22880
# /usr/bin/python
# -*- coding: utf-8 -*-
#
import math


n = int(input())
csf = []
for _ in range(n-1):
  csf.append(list(map(int, input().split())))

ans = [0] * n

for i in range(n-1):
  for j in range(i+1):
    ans[j] = max(math.ceil((ans[j]-csf[i][1])/csf[i][2])*csf[i][2]+csf[i][1], csf[i][1])+csf[i][0]

for i in range(n):
  print(ans[i])

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


int ul(int x,int y,int f){
    char w[4] = {'R', 'U', 'L', 'D'};
    for (int i=0;i<x;i++) printf("%c",w[f%2*2]);
    for (int i=0;i<y;i++) printf("%c",w[f%2*2+1]);
    return 0;
}

int main(){
    int sx,sy,tx,ty;
    scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
    ul(abs(sx-tx),abs(sy-ty),0);
    ul(abs(sx-tx),abs(sy-ty),1);
    printf("D");
    ul(abs(sx-tx)+1,abs(sy-ty)+1,0);
    printf("LU");
    ul(abs(sx-tx)+1,abs(sy-ty)+1,1);
    printf("R\n");
    return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
a, b, c, d = M()
li = list()
li.append(a*c)
li.append(a*d)
li.append(b*c)
li.append(b*d)
li.sort()
print(li[-1])

Measured memory_bytes: 74668
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int e,y;
    for(int a=1;a<=4;a++){
    cin>>e>>y;
    if(e==1){cout<<6000*y<<endl;}
    else if(e==2){cout<<4000*y<<endl;}
    else if(e==3){cout<<3000*y<<endl;}
    else if(e==4){cout<<2000*y<<endl;}
}
}



Measured memory_bytes: 3120
/*
 * Author       : YangDavid
 * Created Time : 2019年07月14日 星期日 22时36分08秒
 */

#include<bits/stdc++.h>
#define rep(i, n) for(int i = 1; i <= n; ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 111111;
int n;
vector<pii> e;

set<int> adj1;
void add(int x, int y) { e.emplace_back(x, y); }

int main() {
    scanf("%d", &n);
    if(__builtin_popcount(n) == 1) {
        puts("No");
        return 0;
    }
    puts("Yes");
    add(3, 2);
    add(2, 1);
    add(1, n + 3);
    add(n + 3, n + 2);
    add(n + 2, n + 1);
    int c = 3;
    while(c + 2 <= n) {
        add(1, c + 1);
        add(c + 1, c + 2);
        add(1, n + c + 2);
        add(n + c + 2, n + c + 1);
        c += 2;
    }
    if(c < n) {
        int k = 1;
        while(k <= n) k <<= 1;
        k >>= 1;
        add(n, k);
        int to = n ^ 1 ^ k;
        if(to & 1) to += n;
        add(n * 2, to);
    }

    for(auto g : e)
        printf("%d %d\n", g.first, g.second);
    
    return 0;
}


Measured memory_bytes: 3952
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int T = sc.nextInt();
        //String S = sc.next();

        
        
        int res = T/A*B;
        System.out.println(res);
        
        
                
            

        }
        
        

        
        
        }
    

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

int main() {
	int N;
	cin >> N;
	long double T, A;
	cin >> T >> A;
	long double ans = 10000000, place = 0;
	vector<long double>H(N);
	for (int i = 0; i < N; i++) {
		cin >> H.at(i);
		long double C = T - (H.at(i) * 0.006);
		if (abs(A - C) < ans) {
			ans = abs(A - C);
			place = i + 1;
		}
	}
	cout << place << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  sort(s.begin(),s.end());
  if(s.at(0)==s.at(1)&&s.at(1)!=s.at(2)&&s.at(2)==s.at(3)){
    cout<<"Yes"<<endl;
  }else
    cout<<"No"<<endl;
}

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

int main()
{
    int n,t;
    int f = 1001;
    cin >> n >> t;
    int c[100],s[100];
    memset(c,0,sizeof(c));
    memset(s,0,sizeof(s));
    
    for(int i = 0;i < n;i++)
    {
        int j,k;
        cin >> j >> k;
        c[i] = j;
        s[i] = k;
     }
     
     for(int j= 0;j < n;j++)
     {
        if(s[j] <= t)
        {
            if(c[j] <= f && c[j] > 0)
            {
                f = c[j];
            }
        }
     }
    if(f == 1001)
    {
        cout << "TLE";
    }else
    {
        cout << f;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <map>
#include <vector>
#include <math.h>
using namespace std;

#define debug(x) cout<<#x<<": "<<x<<endl
#define rep(i,a,b) for(int i=a;i<b;i++)
#define PB push_back
#define putn(x,n) cout<< fixed<< setprecision(n)<< x << endl;
typedef long long ll;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int c[3][3];
	int x;
	rep(i,0,3){
		rep(j,0,3){
			cin>>x;
			c[i][j]=x;
		}
	}
	rep(a_1,0,101){
		rep(a_2,0,101){
			rep(a_3,0,101){
				if(c[0][0]-a_1 == c[1][0]-a_2 && c[1][0]-a_2 == c[2][0]-a_3
				&& c[0][1]-a_1 == c[1][1]-a_2 && c[1][1]-a_2 == c[2][1]-a_3
				&& c[0][2]-a_1 == c[1][2]-a_2 && c[1][2]-a_2== c[2][2]-a_3){
					cout << "Yes"<<endl;
					return 0;
				}
			}
		}
	}
	cout<<"No"<<endl;

	return 0;
}


Measured memory_bytes: 256
from sys import stdin


def main():
    input = lambda: stdin.readline()[:-1]
    N, M = map(int, input().split())
    PS = [(int(p), s) for p, s in (input().split() for _ in [0] * M)]

    taka = [['WA', 0] for _ in [0] * (N + 1)]
    for p, s in PS:
        if taka[p][0] == 'AC':
            continue
        taka[p][0] = s
        if s == 'WA':
            taka[p][1] += 1
    ac, wa = 0, 0
    for a, b in taka:
        if a == 'AC':
            ac += 1
            wa += b
    print(ac, wa)


main()


Measured memory_bytes: 30136
abc = 'abcdefghijklmnopqrstuvwxyz'
n=int(input())
l = [30]*len(abc)
for _ in [0]*n:
  s = input()
  for i in range(len(abc)):
    l[i] = min([l[i],s.count(abc[i])])
ans = ''
for i in range(len(abc)):
  ans+=abc[i]*l[i]
print(ans)

Measured memory_bytes: 3060
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <queue>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define MP make_pair
#define MT make_tuple
#define EACH(i,c) for(auto i: c)
#define SORT(c) sort((c).begin(),(c).end())

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

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

	LL N;
	cin >> N;

	FOR(h, 1, 3501){
		FOR(n, h, 3501){
			if(4 * h * n <= N * (n + h)) continue;
			FOR(w, h, n + 1){
				LL tmp = 4 * h * n * w - N * (n * w + h * w + h * n);
				if(tmp == 0){
					cout << h << " " << n << " " << w << endl;
					return 0;
				}
				if(0 < tmp) continue;
			}
		}
	}
	cout << "non" << endl;


	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int n;
	string s;
	int ans=0;
	cin >>n;
	map<string ,int>res;
	rep(i,n){
		cin>>s;
		res[s]+=0;
		res[s]++;
	}
	printf("AC x %d\n",res["AC"]);
	printf("WA x %d\n", res["WA"]);
	printf("TLE x %d\n", res["TLE"]);
	printf("RE x %d\n", res["RE"]);

}

Measured memory_bytes: 3724
#include        <map>
#include      <queue>
#include     <string>
#include     <cstdio>
#include     <vector>
#include    <cstring>
#include   <iostream>
#include  <algorithm>
using namespace std;
#define ll long long
const ll inf = 1000000000000000000ll;
const int maxn = 1e5+5;
const ll mod = 1e9+7;
int vis[maxn]={0};
bool vis2[maxn]={0};
int to[maxn*2],nx[maxn*2],head[maxn],tot=0;
int n;
int cnt1=0,cnt2=0;

void add(int u,int v){
    to[tot] = v;
    nx[tot] = head[u];
    head[u] = tot++;

    to[tot] = u;
    nx[tot] = head[v];
    head[v] = tot++;
}
int fl=0;
bool dfs(int u,int d){
    if(u==n){
        fl = (d-1)/2;
        return true;
    }
    for(int i=head[u];i!=-1;i=nx[i]){
        int v = to[i];
        if(vis2[v]==0){
            vis2[v] = 1;
            if(dfs(v,d+1)){
                if(d<=fl)vis[v] = 1;
                else vis[v] = -1;
                return true;
            }
        }
    }
    return false;
}
void bfs1(int u){
    queue<int>q;q.push(u);
    while(!q.empty()){
        int t= q.front();q.pop();
        for(int i=head[t];i!=-1;i=nx[i]){
            int v = to[i];
            if(vis[v]==0){
                vis[v] = 2;
                cnt1++;
                q.push(v);
            }
        }
    }
}
void bfs2(int u){
    queue<int>q;q.push(u);
    while(!q.empty()){
        int t = q.front();q.pop();
        for(int i=head[t];i!=-1;i=nx[i]){
            int v = to[i];
            if(vis[v]==0){
                vis[v] = -2;
                cnt2++;
                q.push(v);
            }
        }
    }
}
int main(){
    int u, v;
    memset(head,-1,sizeof(head));
    scanf("%d",&n);
    for(int i=1;i<n;i++){
        scanf("%d%d",&u,&v);
        add(u,v);
    }
    vis2[1]=1;
    dfs(1,1);
    vis[1]=1;vis[n]=-1;


    for(int i=1;i<=n;i++){
        if(vis[i]==1){
            bfs1(i);cnt1++;
        }else if(vis[i]==-1){
            bfs2(i);cnt2++;
        }
    }

    if(cnt1>cnt2)
        puts("Fennec");
    else
        puts("Snuke");
    return 0;
}
/*

6
1 2
2 3
3 5
3 6
1 4


5
1 5
5 2
2 3
3 4


*/


Measured memory_bytes: 7424
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.BufferedReader;
class Main {
    public static void main(String args[] ) throws Exception {
//        int testCases = Integer.parseInt(br.readLine());
//        while(testCases-- >0){
//
//        }
//        double in = GetInput.getInt();
//        System.out.println(Math.PI*2*in);

        int []ins = GetInput.getArrayInt();
        int n = ins[0]; int m = ins [1];

        int []days = GetInput.getArrayInt();
        int daysSum = 0;
        for (int i = 0 ; i < m; i++){
            daysSum+=days[i];
        }
        if (n-daysSum>=0){
            System.out.println(n-daysSum);
            return;
        }
        else System.out.println(-1);
    }
}

class GetInput {
    static BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));

    static char[] getCharArray() {
        char[] charArray;
        try {
            StringBuilder string = getInputString();
            charArray = new char[string.length()];
            for (int i = 0; i < string.length(); i++) {
                charArray[i] = string.charAt(i);
            }
            return charArray;
        } catch (Exception e) {
            e.printStackTrace();
        }
        charArray = new char[0];
        return charArray;
    }

    static int[] getArrayInt() {
        String[] string;
        int[] array;
        try {
            string = bufferedReader.readLine().split("\\s+");
            array = new int[string.length];
            for (int i = 0; i < string.length; i++) {
                array[i] = Integer.parseInt(string[i]);
            }
            return array;
        } catch (IOException e) {
            e.printStackTrace();
        }

        int[] arra = new int[2];
        return arra;
    }

    static int getInt() {
        try {
            String string = bufferedReader.readLine();
            return Integer.parseInt(string);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return 0;
    }

    static StringBuilder getInputString() {
        try {
            StringBuilder string = new StringBuilder();
            string.append(bufferedReader.readLine());
            return string;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return new StringBuilder();
    }

    static long getLongInput() {
        try {
            String string = bufferedReader.readLine();
            return Long.parseLong(string);
        } catch (IOException e) {
            e.printStackTrace();
        }

        return 0;
    }

    static long[] getLongArrayInput() {
        String[] string;
        long[] array;
        try {
            string = bufferedReader.readLine().split("\\s+");
            array = new long[string.length];
            for (int i = 0; i < string.length; i++) {
                array[i] = Long.parseLong(string[i]);
            }
            return array;
        } catch (IOException e) {
            e.printStackTrace();
        }

        long[] arra = new long[2];
        return arra;
    }
}



Measured memory_bytes: 35744
#include<iostream>
#include<stack>
#define _w_ true
using namespace std;

const int Ebit[8] = {0,1,2,3,5,7,8,9};

//特別な8進数に変換する
//８進数に変換する方法だが、コンピュータシステム概論で１０進数を２進数になおした時の様に
//８で割ったときのあまりが８より小さくなるまでわっていく
//８でわれなくなったとき、そののこったのから上にもどしていく
//うまくかけないので、コンピュータシステム概論のハンドアウトを読んでたも

int main(){
  int n;
  stack<int> st;
  while(_w_){
    cin >> n;
    if(n == 0)break;
    while(_w_){
      if(n<8){
	st.push(Ebit[n]);
	break;
      }
      int amari = n%8;
      n = n/8;
      st.push(Ebit[amari]);
    }
    while(st.size()){
      cout << st.top();
      st.pop();
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(void)
{
    int n;
    int i, x;
    
    scanf("%d", &n);
    
    for(i=3; i<=n; i++){
        if(i%3==0){
            printf(" %d", i);
        }
        else{
            x=i;
            while(x){
                if(x%10==3){
                    printf(" %d", i);
                    break;
                }
                x/=10;
            }
        }
    }
    printf("\n");
    
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <limits>
#include <cmath>
#include <iomanip>
#include <functional>
#include <random>
#include <boost/multiprecision/cpp_int.hpp>

using namespace std;
using ll = long long;
namespace mp = boost::multiprecision;



int main()
{
  // 整数の入力
  ll N;
  cin >> N;
  string S;
  cin >> S;
  deque<pair<char,ll>> A;
  for (size_t i = 0; i < N; i++)
  {
      if (A.empty()){
        A.push_back({S[i],1});
      }else if (A.back().first == S[i]){
        A.back().second++;
      }else{
        A.push_back({S[i],1});
      }
  }
  ll ans = 0;
  while(!A.empty()){
    if (A.back().first == 'W'){
      A.pop_back();
    }else if (A.front().first == 'R'){
      A.pop_front();
    }else{
      ll utikeshi = min(A.front().second,A.back().second);
      A.front().second -= utikeshi;
      A.back().second -= utikeshi;
      ans += utikeshi;
      if (A.front().second == 0){
        A.pop_front();
      }
      if (A.back().second == 0){
        A.pop_back();
      }
    }
  }
  cout << ans << endl;
 return 0;
}


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

int main() {
    int r, g, b;
    cin >> r >> g >> b;

    int num;
    num = r * 100 + g * 10 + b;
    if (num % 4 == 0) {
        cout << "YES" << endl;
    }
    else {
        cout << "NO" << endl;
    }

    return 0;
}


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

using namespace std;

typedef long long ll;

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

	string s;
	cin >> s;
	cout << "ABC" << s << endl;
}


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

using namespace std;

int main(){

long long int a[5];
long long int n;
long long int minn=1000000000000001;
cin>>n;
for (int i=0;i<5;i++){
cin>>a[i];
minn=min(minn,a[i]);
}
long long int ans=(n-1)/minn+1;
cout<<ans+4<<endl;

return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
using namespace std;
static int const NUM_MAX = 100;
static int const VAL_MAX = 100;

void show_argv(int argc, int argv[]) {
	for (int i = 0; i < argc; i++) {
		if (i != 0) cout << " ";
		cout << argv[i];
	}
	cout << endl;
}

void selectionSort(int argc, int argv[]) {
	int minj, sw_count = 0;
	for (int i = 0; i < argc; i++) {
		minj = i;
		for (int j = i + 1; j < argc; j++) {
			if (argv[j] < argv[minj]) minj = j;
		}
		if (minj != i) {
			swap(argv[i], argv[minj]);
			sw_count++;
		}
	}
	show_argv(argc, argv);
	cout << sw_count << endl;
}

int main() {
	int argc, argv[NUM_MAX];
	
	cin >> argc;
	for (int i = 0; i < argc; i++) cin >> argv[i];

	selectionSort(argc, argv);
}

Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>


using namespace std;

const int INF = 1000000;

int main(){
    int a,b,c;
    cin >> a >> b >> c ;

    if(a+b >=c)cout << "Yes" << endl;
    else cout << "No" << endl;


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    vector<char> S(N);
    REP(i, N) { cin >> S[i]; }
    sort(S.begin(), S.end());
    S.erase(unique(S.begin(), S.end()), S.end());
    if(S.size() == 4) {
        cout << "Four" << endl;
        return 0;
    }
    cout << "Three" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10, MAXN = 4e5 + 10;
int a[N], n, mid, tp[N], b[N];
bool isval(int x) {
	for (int i = 0; i < n; i++)
		if (a[i] >= x)
			b[i] = 1;
		else
			b[i] = 0;
	for (int i = 0; i < n; i++) {
		tp[i] = b[i];
		if (i != 0 && b[i - 1] % 2 == b[i] % 2)
			tp[i] = b[i] + 2;
		else if (i != n - 1 && b[i + 1] % 2 == b[i] % 2)
			tp[i] = b[i] + 2;
	}
	int fr[6] = {MAXN, MAXN, MAXN, MAXN};
	for (int i = 0; i < n; i++) {
		fr[tp[i]] = min(fr[tp[i]], abs(i - mid));
	}
	if (fr[2] == fr[3] && fr[2] == MAXN)
		return (bool) ((b[mid] + mid) % 2);
	else 
		return (fr[3] < fr[2]);
}
int getAns() {
	int up = n, dw = 0;
	while (up - dw > 1) {
		int md = (up + dw) / 2;
		if (isval(md))
			dw = md;
		else
			up = md;
	}
	return dw;
}
int main() {
	cin >> n;
	mid = n - 1, n = 2 * n - 1;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	cout << getAns();
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD 1000000007

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

signed main() {
	int X, Y;
	cin >> X >> Y;

	cout << (abs(X - Y) < 2 ? "Brown" : "Alice") << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long x = sc.nextLong();
		long[] nums = new long[n];
		for(int i = 0; i < n; i++){
			nums[i] = sc.nextLong();
		}
		long result = 0;
		for(int i = 1; i < n; i++){
			if(nums[i - 1] + nums[i] > x){
				if(nums[i - 1] <= x){
					result += (nums[i - 1] + nums[i] - x);
					nums[i] -= (nums[i - 1] + nums[i] - x);
				}
				else{
					result += (nums[i - 1] + nums[i] - x);
					nums[i] = 0;
					nums[i - 1] = x;
				}
			}
		}
		System.out.println(result);
		sc.close();
	}
}

Measured memory_bytes: 60372