akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;

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

    private void solveD() {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); PrintWriter pw = new PrintWriter(System.out)) {

            char[] arr = br.readLine().toCharArray();
            int[] result = new int[arr.length];

            int nl = -1;
            int nr = -1;
            for (int i = 0; i < arr.length; i++) {
                char directrion = arr[i];

                if (directrion == 'R') {
                    if (i > nl) {
                        for (int j = i; j < arr.length; j++) {
                            if (arr[j] == 'L') {
                                nl = j;
                                break;
                            }

                        }
                    }

                    boolean isOdd = (nl - i) % 2 == 0;
                    result[isOdd ? nl : nl - 1] += 1;
                    continue;
                } else {

                    if (i > nr) {
                        for (int j = i; j >= 0; j--) {
                            if (arr[j] == 'R') {
                                nr = j;
                                break;
                            }
                        }
                    }

                    boolean isOdd = (nr - i) % 2 == 0;
                    if (isOdd) {
                        result[nr] += 1;
                    } else {
                        result[nr + 1] += 1;
                    }
                }

            }

            for (int i = 0; i < result.length - 1; i++) {
                pw.print(result[i] + " ");
            }
            pw.println(result[result.length - 1]);
            pw.flush();
        } catch (IOException e) {

        }
    }
}


Measured memory_bytes: 37820
/*  -*- coding: utf-8 -*-
 *
 * b.cc: B: Contest with Drinks Easy
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100;

/* typedef */

/* global variables */

int ts[MAX_N];

/* subroutines */

/* main */

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

  int sum = 0;
  for (int i = 0; i < n; i++) (cin >> ts[i]), sum += ts[i];

  int m;
  cin >> m;

  for (int i = 0; i < m; i++) {
    int pi, xi;
    cin >> pi >> xi;
    pi--;

    printf("%d\n", sum + xi - ts[pi]);
  }
  return 0;
}


Measured memory_bytes: 256
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty ;; $n:expr) => {
        (0..$n).map(|_| get!($t ;;)).collect::<Vec<_>>()
    };
}

fn main() {
    let (N, K) = get!(i64, usize);
    let MOD = 1000000007;

    // floor(N / i) の値に応じてグループ分けし、
    // グループ単位で条件を満たす列の個数を動的計画法で求める
    let P = (N as f64).sqrt() as i64;
    let Q = N / P;
    let R = (P + Q) as i64;
    let C = (0..R).map(|i|
        if i <= P {
            1
        } else {
            N / (R - i) - N / (R - i + 1)
        }
    ).collect::<Vec<_>>();
    let mut dp = vec![vec![0; R as usize]; K as usize];
    for i in 0..R {
        dp[0][i as usize] = C[i as usize];
    }
    for j in 1..K {
        let mut acc = 0;
        for i in (1..R).rev() {
            acc = (acc + dp[j - 1][(R - i) as usize]) % MOD;
            dp[j][i as usize] = (C[i as usize] * acc) % MOD;
        }
    }
    let ans: i64 = dp[K - 1].iter().sum::<i64>() % MOD;

    println!("{}", ans);
}


Measured memory_bytes: 71932
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include <queue>
#include <math.h>
using namespace std;
int main() {
	long long int N;
	cin >> N;
	long long int num;
	int dig;
	num = N;
	for (int i = 1; i < 10000; i++) {
		if (num - pow(26, i) <= 0) {
			dig = i;
			break;
		}
		num -= pow(26, i);
	}
	string ans;
	num = N;
	for (int i = 1; i <=dig; i++) {
		for (int j = 1; j <= 26; j++) {
			long long int ptr = num - j*pow(26, i - 1);
			long long int DIG = pow(26, i);
			if ( ptr % DIG==0) {
				ans.push_back('a' + j-1 );
				num -= j * pow(26, i - 1);
				break;
			}
		}
	}
	reverse(ans.begin(), ans.end());
	cout << ans;
}

Measured memory_bytes: 4100
#include <iostream>
#include <fstream>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <algorithm>

#define MOD_BIG 1000000007
#define MOD_BIG2 998244353
using std::string;
using std::cin;
using std::cout;
using std::cerr;
using std::endl;
using ll = long long;
using std::vector;

template<typename T> void ndarray(vector<T> &vec, int len) { vec.resize(len); }
template<typename T, typename... Args> void ndarray(vector<T> &vec, int len, Args... args) {
    vec.resize(len);
    for (auto &v : vec) ndarray(v, args...);
}

//////////////////////////////////////

//////////////////////////////////////

int main() {
    
    int X, Y;
    cin >> X >> Y;
    
    int ans = 0;
    
    if (X == 1) {
        ans += 300000;
    } else if (X == 2) {
        ans += 200000;
    } else if (X == 3) {
        ans += 100000;
    }
    
    if (Y == 1) {
        ans += 300000;
    } else if (Y == 2) {
        ans += 200000;
    } else if (Y == 3) {
        ans += 100000;
    }
    
    if (X == 1 && Y == 1) {
        ans += 400000;
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    //ALDS1_1_D_Maximum Profit

    let number_of_data = read();

    let mut max_profit = -2000000000;
    let mut min_price = 2000000000;
    for _i in 0..number_of_data {
        let now_price = read();
        let profit = now_price - min_price;
        if now_price < min_price {
            min_price = now_price;
        }
        if profit > max_profit {
            max_profit = profit
        }
    }
    println!("{}", max_profit);
}


Measured memory_bytes: 5044
#include<iostream>
#include<cstdio>
#include<queue>
#include<vector>
#include<string.h>
#include<algorithm>
#include <cmath>

using namespace std;

long long N,i,j,k,memo[3002][3002],all,ans,M,S,A[3002],MOD;

int dp(int n,int m)
{
  if(memo[n][m]!=-1)
  {
    return memo[n][m];
  }
  
  int u,v;
  
  u=dp(n-1,m);
  u%=MOD;
  if(m>A[n])
  {
    u+=dp(n-1,m-A[n]);
  }
  else if(m==A[n])
  {
    u+=dp(n-1,0)+1;
  }
  u%=MOD;
  memo[n][m]=u;
  return u;
  
}

int main()
{
  MOD=998244353;
  
  cin>> N>>S;
  
  for(i=0;i<N;i++)
  {
    cin>>A[i];
  }
  
  for(i=0;i<N;i++)
  {
    for(j=0;j<S+1;j++)
    {
      memo[i][j]=-1;
    }
  }
  
  for(i=0;i<N;i++)
  {
    memo[i][0]=i+1;
  }
  for(j=1;j<S+1;j++)
  {
    memo[0][j]=0;
  }
  memo[0][A[0]]=1;
  
  ans=0;
  
  for(i=0;i<N;i++)
  {
    ans+=dp(i,S);
    ans%=MOD;
  }

  cout <<ans;
  

  
}

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

#define ll long long
#define pb push_back
#define F first
#define S second

using namespace std;

const int N = 100005;

int n;
vector <pair <int, int>> g[N];

int res[N];
void dfs(int v, int par = -1, long long dis = 0) {
    res[v] = dis % 2;
    for (auto i : g[v]) {
        if (i.F != par) {
            dfs(i.F, v, dis + i.S);
        }
    }
}

int main() {
    ios_base :: sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    cin >> n;
    int a, b, c;
    for (int i = 1; i < n; i++) {
        cin >> a >> b >> c;
        g[a].pb({b, c});
        g[b].pb({a, c});
    }
    dfs(1);
    for (int i = 1; i <= n; i++) {
        cout << res[i] << '\n';
    }
    return 0;
}


Measured memory_bytes: 8448
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 = new int[n];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}

		int ans = 0;
		outer:
		while (true) {
			for (int i = 0; i < a.length; i++) {
				if (a[i] % 2 == 1) {
					break outer;
				}
				a[i] /= 2;
			}
			ans++;
		}
		System.out.println(ans);

		sc.close();
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <bitset>
#include <functional>
#include <queue>
#include <utility>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define dump(x)  cerr << #x << " = " << (x) << endl;
typedef long long LL;

using namespace std;

int main(void)
{
	int A, B, K;

	cin >> A >> B >> K;

	int minNum = min(A, B);

	for (int count = 0; minNum >= 1; minNum--) {
		if ((A%minNum == 0) && (B%minNum == 0)) {
			count++;
			if (count == K) {
				break;
			}
		}
	}

	cout << minNum << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>

#include <algorithm>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;
const ll INF = 1ll << 60;

ll MOD = 1e9 + 7;

int main()
{

    int n;
    cin >> n;

    cout << n * n * n << endl;

    return 0;
}

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

#define vi vector<int>
#define vii vector<int, int>
#define ll long long
#define pb push_back
#define mp make_pair
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

const int MOD = 1000000007;

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

    sort(a, a+n);

    int x = n / 2;

    cout << a[x] - a[x-1] << endl;


    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
 
int main() {
    ll n; cin >> n;
    vl a(n + 1);
    for (ll i = 1; i <= n; i++)
        cin >> a[i];
 
    ll cnt = 0;
    ll b = 1;
    while(1) {
        if (b == 2) {
            cout << cnt << endl;
            return 0;
        }
        b = a[b];
        cnt ++;
        if (cnt >= n+1) break;
    }
    cout << -1 << endl;
    return 0;
}

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

int main() {
  int n;
  cin >> n;
  int n2 = 1<<n;
  vector<int> a(n2);
  rep(i,n2) cin >> a[i];
  sort(a.begin(), a.end());
  vector<int> s;
  s.push_back(a.back());
  a.back() = -1;
  rep(i,n) {
    vector<int> p = s;
    sort(p.begin(),p.end());
    int ai = n2-1;
    while (p.size() > 0 && ai >= 0) {
      if (a[ai] == -1) {
        --ai;
        continue;
      }
      if (a[ai] < p.back()) {
        s.push_back(a[ai]);
        p.pop_back();
        a[ai] = -1;
      }
      --ai;
    }
    if (p.size() > 0) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}

Measured memory_bytes: 3060
THP, TAT, AHP, AAT = map(int, input().split())

turn = 0
while True:
  if turn % 2 == 0:
    AHP -= TAT
    if AHP <= 0:
      print("Yes")
      break
  else:
    THP -= AAT
    if THP <= 0:
      print("No")
      break
  turn += 1

Measured memory_bytes: 9076
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long,long long> pll;
const int maxn=100005;
int n,m,f[maxn];
struct point {
    int x,y,id;
} p[maxn];
bool cmp1(point p1,point p2) {
    return p1.x<p2.x;
}
bool cmp2(point p1,point p2) {
    return p1.y<p2.y;
}
inline void init() {
    for (int i=0;i<n;++i)
        f[i]=i;
}
int F(int x) {
    return x==f[x]?x:f[x]=F(f[x]);
}
inline void U(int a,int b) {
    f[F(a)]=F(b);
}
struct edge {
    int u,v,w;
    edge(){}
    edge(int u,int v,int w):u(u),v(v),w(w){}
    bool operator<(const edge &rhs)const{
        return w<rhs.w;
    }
} e[maxn<<1];
int main()
{
    scanf("%d",&n);
    init();
    for (int i=0;i<n;++i) {
        scanf("%d%d",&p[i].x,&p[i].y);
        p[i].id=i;
    }
    sort(p,p+n,cmp1);
    for (int i=0;i<n-1;++i)
        e[i]=edge(p[i].id,p[i+1].id,abs(p[i].x-p[i+1].x));
    sort(p,p+n,cmp2);
    for (int i=0;i<n-1;++i)
        e[i+n-1]=edge(p[i].id,p[i+1].id,abs(p[i].y-p[i+1].y));
    m=2*n-2;
    sort(e,e+m);
    long long res=0;
    for (int i=0;i<m;++i)
        if (F(e[i].u)!=F(e[i].v)) {
            U(e[i].u,e[i].v);
            res+=1LL*e[i].w;
        }
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 4224
///Nahid Hasan Raju
#include <bits/stdc++.h>
#define ll long long
#define MS(ARRAY,VALUE) memset(ARRAY,VALUE,sizeof(ARRAY))
#define Fin freopen("input.txt","r",stdin)

#define P(XX) cout<<XX<<endl
#define P1(XX) cerr<<"db1: "<<XX<<endl
#define P2(XX,YY) cerr<<"db2: "<<XX<<" "<<YY<<endl
#define P3(XX,YY,ZZ) cerr<<"db3: "<<XX<<" "<<YY<<" "<<ZZ<<endl
using namespace std;
ll m, n;
ll a[205],b[205],c[205],B[205];//o[205][205];

bool f(ll p, ll q, ll r)
{
    if(p+q>r && p+r>q && r+q>p && p!=q && q!=r && p!=r){
        //P3(p,q,r);
        return 1;
    }
    return 0;
}


int main()
{
    int test=1, tc=0;
    int  i, j;
    #ifndef ONLINE_JUDGE
    Fin;
    test=1;
    #endif
    ll k, ans,x,y;
    //scanf("%d", &test);
    while(test--)
    {
        j=0;
        ans=0;
        k=0;
        ll p;
        cin>>n;

        for(i=0;i<n;i++){
            cin>>a[i];
        }
        //sort(a,a+n);
        for(i=0;i<n;i++){for(j=i+1;j<n;j++){for(k=j+1;k<n;k++)
        {
            if(f(a[i],a[j],a[k]))ans++;
        }
        }}
        P(ans);
    }
    return 0;
}



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

int main() {
  int N, K; cin >> N >> K;
  int P[N]; for (int i = 0; i < N; i++) cin >> P[i];
  sort(P, P+N);
  int sum = 0;
  for (int i = 0; i < K; i++) {
    sum += P[i];
  }
  cout << sum << endl;
}

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

int A,B,C;

int main()
{
    cin >> A >> B >> C;

    for (int i = 0; i < A*B; i+=A)
    {
        if(i%B == C){
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
S1 = input()
S2 = input()
dp = [0 for i in range(N)]
if S1[0] == S2[0]:
    dp[0] = 3
else:
    dp[0] = 6
# i - 1個目、i個目が
# 横ドミノ１個目→横ドミノ２個目
# 横ドミノ→横ドミノ
# 横ドミノ→縦ドミノ
# 縦ドミノ→縦ドミノ
# 縦ドミノ→横ドミノそれぞれについて場合分け
# 各回について
for i in range(1, N):
    # 横ドミノ２つ目だった場合
    if S1[i] == S1[i - 1]:
        dp[i] = dp[i - 1]
    # 横ドミノ１つめor縦ドミノ１つ目の場合
    else:
        # 縦ドミノ１つ目
        if S1[i] == S2[i]:
            # 一つ前も縦ドミノ
            if S1[i - 1] == S2[i - 1]:
                dp[i] = (dp[i - 1] * 2) % mod
            # 横ドミノ
            else:
                dp[i] = dp[i - 1]
        # 横ドミノ1つ目
        else:
            # 一つ前が縦ドミノ
            if S1[i - 1] == S2[i - 1]:
                dp[i] = (dp[i - 1] * 2) % mod
            # 一つ前が２つ目横ドミノ
            else:
                dp[i] = (dp[i - 1] * 3) % mod
print(dp[-1])

Measured memory_bytes: 38384
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
n = gets.chomp.to_i
a = gets.chomp.split.map(&:to_i)
a.sort!
ans = a.shift
lim = 10 ** 18
a.each do |e|
  ans *= e
  if ans > lim
    puts -1
    exit
  end
end
puts ans


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

using namespace std;
typedef long long ll;
const int MAXN = 1010;

int H, W, K;
char board[MAXN][MAXN];

vector <int> gogo (int x, int y)
{
    vector <int> v;
    for (int i = 0; i < W; i++)
    {
        int cv = 0;
        for (int j = x; j < y; j++)
            if (board[j][i] == '1')
                cv++;
        v.push_back(cv);
    }
    return v;
}

int main()
{
    ios_base::sync_with_stdio(0);

    cin >> H >> W >> K;
    for (int i = 0; i < H; i++)
        for (int j = 0; j < W; j++)
            cin >> board[i][j];

    int res = 1e9;
    for (int i = 0; i < (1 << (H - 1)); i++)
    {
        bool bad = false;
        vector <int> v;
        v.push_back(0);
        for (int j = 0; j < (H - 1); j++)
            if (i & (1 << j))
                v.push_back(j + 1);
        v.push_back(H);


        vector <vector <int> > vv;
        for (int j = 0; j + 1 < v.size(); j++)
        {
            vv.push_back(gogo (v[j], v[j+1]));
            for (int x : vv.back())
                if (x > K)
                {
                    bad = true;
                }
        }
        if (bad) continue;
        vector <int> csum;
        for (int j = 0; j < vv.size(); j++)
            csum.push_back(0);

        int cans = 0;
        for (int j = 0; j < vv[0].size(); j++)
        {
            bool need = false;
            for (int k = 0; k < vv.size(); k++)
                if (csum[k] + vv[k][j] > K)
                    need = true;

            if (need)
            {
                //cout << i << " " << j << "\n";
                cans++;
                for (int k = 0; k < vv.size(); k++)
                    csum[k] = 0;
            }
            for (int k = 0; k < vv.size(); k++)
                csum[k] += vv[k][j];
        }

        cans += __builtin_popcount(i);
        //cout << i << " " << cans << "\n";
        res = min (res, cans);
    }
    cout << res << "\n";
}

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

int main(){
	int m1, d1, m2, d2;
	cin>>m1>>d1>>m2>>d2;
	int days[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
	
	if(d1 == days[m1-1]){ cout<<1;return 0;}
	cout<<0;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
template <class T>
bool find(vector<T> v, T key) {
	for (size_t i = 0; i < v.size(); i++)
		if (v[i] == key)return true;
	return false;
}
int main() {
	int n;
	while (cin >> n, n) {
		string code[60];
		for (int i = 0; i < n; i++) {
			string s; cin >> s;
			for (size_t j = 0; j < s.size(); j++) {
				if (j == 0)code[i] += s[j];
				else if (s[j - 1] == 'a')code[i] += s[j];
				else if (s[j - 1] == 'e')code[i] += s[j];
				else if (s[j - 1] == 'i')code[i] += s[j];
				else if (s[j - 1] == 'o')code[i] += s[j];
				else if (s[j - 1] == 'u')code[i] += s[j];
			}
		}
		for (int k = 1; k < 60; k++) {
			vector<string>v;
			for (int j = 0; j < n; j++) {
				if (find(v, code[j].substr(0, k)))goto cont;
				v.push_back(code[j].substr(0, k));
			}
			cout << k << endl;
			goto end;
		cont:;
		}
		cout << "-1\n";
	end:;
	}
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, m, n) for (int i = m; i < n; ++i)
const int MOD = 1000000007;
ll add(ll &a, ll b) {
  a = (a + b) % MOD;
}

ll dp[101010];
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> a(N+1);
  rep(i, 0, M) {
    int v; cin >> v;
    a[v] = 1;
  }
  dp[0] = 1;
  rep(i, 0, N) {
    if(a[i]) continue;
    if(!a[i+1]) add(dp[i+1], dp[i]);
    if(!a[i+2]) add(dp[i+2], dp[i]);
  }
  cout << dp[N] << endl;
  return 0;
}


Measured memory_bytes: 1408
import java.util.Scanner;
import java.lang.Math;

public class Main {
  public static int suit_int(String suit)
  {
    switch(suit)
    {
      case "S":
        return 0;
      case "H":
        return 1;
      case "C":
        return 2;
      case "D":
        return 3;
      default:
        System.out.print("ERROR");
        return -1;
    }
  }

  public static String suit_str(int suit)
  {
    switch (suit) {
      case 0:
        return "S";
      case 1:
        return "H";
      case 2:
        return "C";
      case 3:
        return "D";
      default:
        System.out.println("ERROR");
        return "ERROR";
    }
  }

  public static void main(String[] args)
  {
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    boolean a[][] = new boolean[4][13];
    for (int i = 0; i < n; i++) {
      int suit = suit_int(scan.next());
      int num = scan.nextInt()-1;
      a[suit][num] = true;
    }
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 13; j++) {
        if(a[i][j]) continue;
        System.out.printf("%s %d\n",suit_str(i),j+1);  
      }
    }
    scan.close();
  }
}



Measured memory_bytes: 26552
#include<bits/stdc++.h>
#define IOS ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define pb push_back
#define mp make_pair
#define ll long long
#define int long long
#define mod 1000000007
#define DEBUG cout<<"Hello1\n";
#define all(v) (v).begin(),(v).end()
#define clr(x) memset(x,0,sizeof(x))
#define deb(...) debug(#__VA_ARGS__, __VA_ARGS__);
const int N = 1e6 + 5;
const ll inf = LLONG_MAX;
using namespace std;

template<typename T> void debug(string s, T x) {cout << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cout << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}
template<class T>
void print_container(T &container) {
	for (auto &t : container) {
		cout << t << " ";
	}
	cout << endl;
}

int n;
int a[N];
void solve() {
	cin >> n;

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

	sort(a, a + n, greater<int>());

	int ans = 0;
	ans += a[0];
	int k = n - 2;

	int i;
	for ( i = 1; i <= k / 2; i++) {
		// deb(ans);
		ans += (2 * a[i]);
	}
	if (k % 2) {
		ans += a[i];
	}

	cout << ans << endl;

}

int32_t main() {
	IOS;

	solve();
}



Measured memory_bytes: 5176
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 c = sc.nextInt();
        int d = sc.nextInt();

        if (Math.abs(c - a) <= d) {
            System.out.println("Yes");
        } else if (Math.abs(b - c) <= d && Math.abs(b - a) <= d) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23252
import sys
input = sys.stdin.readline

n = int(input())

#ss = [sorted(list(input())) for _ in range(n)]
ss = []
checked = {}
count = 0
for i in range(n):
    tmp = list(input())
    tmp.sort()
    tmp = str(tmp)
    if not(tmp in checked):
        checked[tmp] = 1
    else:
        count += checked[tmp]
        checked[tmp] += 1

print(count)

Measured memory_bytes: 21988
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int k = sc.nextInt();
        int s = sc.nextInt();
        long ans = 0;
        for(int i = 0; i <= k; i++){
            for(int j = 0; j <= k; j++){
                int z = s-i-j;
                if(z >= 0 && z <= k){
                    ans++;
                }
            }
        }
        System.out.println(ans);
    }
    
    public static int beamSearch(long[] arr, long target){
        int left = 0;
        int right = arr.length;
        while(right-left > 1){
            int mid = (left+right)/2;
            if(arr[mid] > target){
                right = mid;
            }else{
                left = mid;
            }
        }
        return left;
    }
}

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

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

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

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

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

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


Measured memory_bytes: 23252
#include <stdio.h>
#define P(s) printf(s "\n");

int main(void) {
	int m, f, r, sum;
	
	while (1) {
		scanf("%d %d %d", &m, &f, &r);
		if (m + f + r == -3) {
			break;
		}
		if ((m == -1) || (f == -1)) {
			P("F");
		} else {
			sum = m + f;
			if (sum >= 80) {
				P("A")
			} else if (sum >= 65) {
				P("B")
			} else if (sum >= 50) {
				P("C")
			} else if (sum >= 30) {
				if (r >= 50) {
					P("C")
				} else {
					P("D")
				}
			} else {
				P("F")
			}
		}
	}

	return 0;
}

Measured memory_bytes: 584
import java.util.*;
public class Main { 
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt(); 
		String s = sc.next();
		String ans = "No";
		
		if(n % 2 == 0) {
			if(s.substring(0,s.length()/2).equals(s.substring(s.length()/2))) {
				ans = "Yes";
			}
		}
		System.out.println(ans);
	}	
}

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



class A
{
    static int n;
    public static void Main() {
        n = int.Parse(Console.ReadLine());
        int[] nodes = new int[n+1];
        int[] data = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        data.CopyTo(nodes, 1);
        for (int i = n / 2; i > 0; i--) {
            Maxheapify(nodes, i);
        }
        for(int i=1;i<=n;i++) {
            Console.Write(" " +nodes[i]);
        }
        Console.WriteLine();
    }
    public static void Maxheapify(int[] nodes, int i) {
        int left = i * 2;
        int right = i * 2 + 1;
        int largest = (left <= n && nodes[left] > nodes[i]) ? left : i;
        if (right <= n && nodes[right] > nodes[largest]) {
            largest = right;
        }
        if (largest != i) {
            int temp = nodes[i];
            nodes[i] = nodes[largest];
            nodes[largest] = temp;
            Maxheapify(nodes, largest);
        }
    }
}


Measured memory_bytes: 48600
A =[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(A[int(input()) - 1])

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

const int MN = 500005;

char s[MN];
int N, A[MN];

int main() {
	scanf("%s", s + 1), N = strlen(s + 1);
	for (int i = 0; i < N; ++i) A[i] = s[N - i] & 15;
	int carry = 0;
	for (int i = 0; i < N; ++i) (A[i] *= 9) += carry, carry = A[i] / 10, A[i] %= 10;
	if (carry) A[N++] = carry;
	int Sum = 0;
	for (int i = 0; i < N; ++i) Sum += A[i];
	for (int L = 1; ; ++L) {
		A[0] += 9, Sum += 9;
		for (int i = 0; i < N && A[i] >= 10; ++i) ++A[i + 1], A[i] -= 10, Sum -= 9;
		if (A[N - 1] >= 10) A[N - 1] -= 10, A[N++] = 1, Sum -= 9;
		if (Sum <= 9 * L) return printf("%d\n", L), 0;
	}
	return 0;
}

Measured memory_bytes: 4152
#include <iostream>

int main(void)
{
	int h, w;
	char cell[50][50];
	int ans[50][50];

	std::cin >> h >> w;

	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			std::cin >> cell[i][j];
		}
	}
	int cnt = 0;
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			//std::cout << cnt++;
			if (cell[i][j] == '#'){
				ans[i][j] = '#';
			}
			else{
				int cnt = 0;
				for (int k = -1; k <= 1; k++){
					for (int l = -1; l <= 1; l++){
						if (i + k < 0 || i + k >= h || j + l < 0 || j + l >= w)
							continue;

						if (cell[i + k][j + l] == '#') {
							cnt++;
						}
					}
				}
				ans[i][j] = cnt;
			}
		}
	}
	
	for (int i = 0; i < h; i++){
		for (int j = 0; j < w; j++){
			if (ans[i][j] == '#')
				std::cout << (char)ans[i][j];
			else
				std::cout << ans[i][j];
		}
		std::cout << std::endl;
	}
	
}

Measured memory_bytes: 256
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

using namespace std;
#define REP(i, n) for (int i = 0; i < n; i++)
#define ALL(obj) obj.begin(), obj.end()

const int iINF = 1e9;
const long long llINF = 1e18;
const int MOD = 1e9 + 7;
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;
}

template <std::uint_fast64_t Modulus>
class modint {
    using u64 = std::uint_fast64_t;

   public:
    u64 a;

    constexpr modint(const u64 x = 0) noexcept : a(x % Modulus) {}
    constexpr u64 &value() noexcept { return a; }
    constexpr const u64 &value() const noexcept { return a; }
    constexpr modint operator+(const modint rhs) const noexcept { return modint(*this) += rhs; }
    constexpr modint operator-(const modint rhs) const noexcept { return modint(*this) -= rhs; }
    constexpr modint operator*(const modint rhs) const noexcept { return modint(*this) *= rhs; }
    constexpr modint operator/(const modint rhs) const noexcept { return modint(*this) /= rhs; }
    constexpr modint &operator+=(const modint rhs) noexcept {
        a += rhs.a;
        if (a >= Modulus) {
            a -= Modulus;
        }
        return *this;
    }
    constexpr modint &operator-=(const modint rhs) noexcept {
        if (a < rhs.a) {
            a += Modulus;
        }
        a -= rhs.a;
        return *this;
    }
    constexpr modint &operator*=(const modint rhs) noexcept {
        a = a * rhs.a % Modulus;
        return *this;
    }
    constexpr modint &operator/=(modint rhs) noexcept {
        u64 exp = Modulus - 2;
        while (exp) {
            if (exp % 2) {
                *this *= rhs;
            }
            rhs *= rhs;
            exp /= 2;
        }
        return *this;
    }
};

using mint = modint<MOD>;

int main() {
    using P = pair<long long, int>;
    int N, M;
    cin >> N >> M;
    vector<long long> Q[100010];
    REP(i, N) {
        int a, b;
        cin >> a >> b;
        Q[a].push_back(b);
    }

    long long ans = 0;
    priority_queue<int> que;
    for (int i = 1; i < M + 1; i++) {
        for (auto x : Q[i]) {
            que.push(x);
        }
        if (!que.empty()) {
            ans += que.top();
            que.pop();
        }
    }

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

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

int main(){

  vector<vector<int>> A(3, vector<int>(3));
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
     cin >> A.at(i).at(j);
    }
  }

  int N;
  cin >> N;

  vector<int> b(N);
  for (int i = 0; i < N; i++) {
   cin >> b.at(i);
  }

  vector<vector<int>> count(3, vector<int>(3));
  for (int i = 0; i < N; i++) {
    int X=b.at(i);
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < 3; j++) {
       if (A.at(i).at(j)==X) count.at(i).at(j)=1;
      }
    }
  }

  bool ans = false;

  for (int i = 0; i < 3; i++) {
     if (count.at(i).at(0)==1 && count.at(i).at(1)==1 && count.at(i).at(2)==1) ans=true;
  }

  for (int j = 0; j < 3; j++) {
     if (count.at(0).at(j)==1 && count.at(1).at(j)==1 && count.at(2).at(j)==1) ans=true;
  }

  if (count.at(0).at(0)==1 && count.at(1).at(1)==1 && count.at(2).at(2)==1) ans=true;
  if (count.at(0).at(2)==1 && count.at(1).at(1)==1 && count.at(2).at(0)==1) ans=true;
  
  if (ans) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
  
}

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

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;

const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;
const double PI=3.1415926535897932;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}

ll minll(ll a, ll b){
    if(a >= b)  return b;
    else    return a;
}

ll maxll(ll a, ll b){
    if(a >= b)  return a;
    else    return b;
}

ll n;

int main(){
    cin >> n;
    ll ans = 1;

    for(int i = 0; i < 3; i++){
        ans *= n; 
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
/************************************
 TEMPLATE FOR PROGRAM COMPETITION
 ***********************************/
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
#include <cstring>

int main(){
  
  char S[4], T[4];
  
  scanf("%s", S);
  scanf("%s", T);
  
  int ans = 0;
  for(int i = 0; i < 3; i++){
    if(S[i] == T[i]) ans++;
  }
  
  std::cout << ans << std::endl;
  
  return 0;
}


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

using namespace std;

int main(void){
    string s;

    cin >> s;

    if(s[0]!=s[1]&&s[1]!=s[2]&&s[2]!=s[0])cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <tuple>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i, n) for (int i = 0; i < n; i++)

int main()
{
    int r,d,x;
    cin >> r>>d>>x;
    REP(i,10){
        x = r*x-d;
        cout << x << endl;
    }
}

Measured memory_bytes: 256
import java.io.*
import java.util.*
import java.lang.*
import java.lang.Math.*


class CumSum(val A: LongArray) {
    private var csum: LongArray = LongArray(A.size + 1){0L}
    init {
        for (i in 1..A.size) {
            this.csum[i] = this.csum[i-1] + A[i-1]
        }
    }
    fun sum(L: Int, R: Int): Long {
        val r = min(R, A.size)
        val l = max(L, 0)
        if (l >= r) return 0
        return this.csum[r] - this.csum[l]
    }
}

fun solve() {
    val N = rd.readInt()
    val A = rd.readLongArray().sorted()

    val cs = CumSum(A.toLongArray())

    var cnt = 1
    for (i in N-1 downTo 0) {
        if (cs.sum(0, i) * 2 >= A[i]) cnt++
        else break
    }

    val ans = cnt
    println(ans)
}


//val rd = debug.Reader("agc", "011", "b", "sample-1")
val rd = Reader()


fun main(args: Array<String>) {
    try {
        var exception: Throwable? = null
        val sth = Thread(null, SolveThread(), "solveThread", 128 * 1024 * 1024)
        sth.setUncaughtExceptionHandler { _, e -> exception = e }
        sth.start(); sth.join()
        if (exception != null) throw exception!!
    } catch (e: Exception) { throw e }
}
const val MOD = 1_000_000_007L; const val INF = Int.MAX_VALUE/2; const val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int); data class LongPair(val first: Long, val second: Long)
val errPrintln: (Any) -> Unit = { msg -> System.err.println(msg) }
fun rAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("EAssert Error: $msg"); throw Error(msg) }
}
fun tAssert(exp: Boolean, lazyMsg: () -> String = {""}) {
    if (!exp) { val msg = lazyMsg(); errPrintln("TAssert Error: $msg"); Thread.sleep(3000) }
}
class SolveThread : Runnable {
    override fun run() { solve() }
}
class Reader {
    private val br = BufferedReader(InputStreamReader(System.`in`))
    val readString: () -> String = { br.readLine() }
    val readInt: () -> Int = { br.readLine().toInt() }
    val readLong: () -> Long = { br.readLine().toLong() }
    val readIntArray: () -> IntArray = { br.readLine().split(' ').map { it.toInt() }.toIntArray() }
    val readLongArray: () -> LongArray = { br.readLine().split(' ').map { it.toLong() }.toLongArray() }
    val readListInt: () -> List<Int> = { br.readLine().split(' ').map { it.toInt() } }
    val readListLong: () -> List<Long> = { br.readLine().split(' ').map { it.toLong() } }
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define revrepeat(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
const int MOD = 1e9 + 7;
const int INF = __INT_MAX__;               // 2^31 - 1
const long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
const int MAX_N = 1e5 + 5;
const double PI = acos(-1);

struct mint {
    // Preparation: MOD is already defined.
    ll value;

    mint(ll value = 0) : value((value % MOD + MOD) % MOD) {}

    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint pow(mint m) const {
        return pow(m.value);
    }

    mint inv() const {
        ll a = value, b = MOD, u = 1, v = 0;
        while (b) {
            ll t = a / b;
            a -= t * b;
            swap(a, b);
            u -= t * v;
            swap(u, v);
        }
        u %= MOD;
        return u;
    }

    mint &operator+=(const mint a) {
        if ((value += a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator-=(const mint a) {
        if ((value += MOD - a.value) >= MOD) value -= MOD;
        return *this;
    }
    mint &operator*=(const mint a) {
        (value *= a.value) %= MOD;
        return *this;
    }
    mint &operator/=(const mint a) {
        return (*this) *= a.inv();
    }

    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

int main() {
    ll n, a, b;
    cin >> n >> a >> b;
    vl x(n);
    rep(i, n) {
        cin >> x[i];
    }
    vl dist;
    adjacent_difference(all(x), back_inserter(dist));
    dist.erase(dist.begin());

    ll ans = 0;
    foreach (d, dist) {
        if (d * a > b) {
            ans += b;
        } else {
            ans += d * a;
        }
    }
    out(ans);
}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/










int  N, H, W;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> N >> H >> W;

    int ans = (N-H+1) * (N - W+1);
    cout << ans << endl;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

signed main() {
    string str;
    cin >> str;
    int ret = 0;
    int wcnt = 0;

    for (int i = str.size() - 1; i >= 0; i--) {
        if (str[i] == 'W') {
            wcnt++;
        } else {
            ret += wcnt;
        }
    }

    cout << ret << endl;

    return 0;
}

Measured memory_bytes: 640
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int dy[8] = { 1, 1, 1, 0, 0, -1, -1, -1 };
const int lr[4] = { 0, 1, 0, -1 };
const int ud[4] = { 1, 0, -1, 0 };



//LOVE Ayane Sakura



using namespace std;



int main() {
	string S;
	int Q;
	cin >> S >> Q;
	vector<int>T(Q), F(Q);
	vector<string>C(Q);
	int EoO = 0;
	for (int i = 0; i < Q; i++) {
		cin >> T[i];
		if (T[i] == 1) {
			EoO++;
		}
		else {
			cin >> F[i] >> C[i];
		}
	}
	priority_queue<pair<int, string>, vector<pair<int, string>>, greater<pair<int, string>>>q;
	if (EoO % 2 == 1) {
		reverse(S.begin(), S.end());
	}
	q.push(make_pair(0, S));
	int check = 0;
	for (int i = 0; i < Q; i++) {
		if (T[i] == 1) {
			check++;
		}
		else {
			if (F[i] == 1) {
				q.push(make_pair(-(i + 1) * (int)pow(-1, (EoO - check)), C[i]));
			}
			else {
				q.push(make_pair((i + 1) * (int)pow(-1, (EoO - check)), C[i]));
			}
		}
	}
	while (!q.empty()) {
		cout << q.top().second;
		q.pop();
	}
	cout << endl;
}



Measured memory_bytes: 18160
N = input()
if N[0] == "M":
    print(6)
elif N[0] == "F":
    print(2)
elif N[0] == "W":
    print(4)
elif N[0] == "T":
    if N == "THU" :
        print(3)
    else:
        print(5)
else:
    if N == "SUN" :
        print(7)
    else:
        print(1)

Measured memory_bytes: 38384