akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define s second
#define f first
long long const mod = pow(2,32);
#define inf 1000000000000000
inline ll add(ll a, ll b){ return ((a%mod)+(b%mod)+mod)%mod;}
inline ll mul(ll a, ll b){ return (((a%mod)*(b%mod))%mod+mod)%mod;}
inline ll sub(ll a, ll b){ return ((a%mod)-(b%mod)+mod)%mod;}

ll power(ll x,ll y,ll m)
{
    if (y == 0)
        return 1;
    ll p = power(x, y/2, m) % m;
    p = (p * p) % m;
    return (y%2 == 0)? p : (x * p) % m;
}

ll modInv(ll x)
{
    return power(x,mod-2,mod)%mod;
}


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

    ll n,m;
    cin>>n>>m;
   
   ll x=(n*(n-1))/2;
    ll y=(m*(m-1))/2;
    cout<<x+y<<endl;
    return 0;
}


Measured memory_bytes: 256
use std::io;

fn main() {
    let mut buf = String::new();
    let stdin = io::stdin();
    stdin.read_line(&mut buf).unwrap();
    let K: u64 = buf.trim_end().parse().unwrap();
    let mut acc = 0;
    for i in 0..10_000_000 {
        acc *= 10;
        acc += 7;
        acc %= K;
        if acc == 0 {
            println!("{}", i + 1);
            return;
        }
    }
    println!("-1");
}


Measured memory_bytes: 2148
K = int(input())

mem = {}
def memory(k, ans):
    if k not in mem:
        mem[k] = ans
    return ans

mem2 = {}

def memory2(k, ans):
    if k not in mem2:
        mem2[k] = ans
    return ans

def gcd2(a,b):
    if a > b:
        a, b = b, a
    k = a * 1000 + b
    if k in mem2:
        return mem2[k]
    if a < b:
        if a == 0:
            return memory2(k, b)
        if a == 1:
            return memory2(k, 1)
        else:
            return memory2(k, gcd2(a, b%a))
    else:
        return memory2(k, a)

def gcd(a, b, c):
    a, b, c = sorted([a, b, c])
    k = a * 1000000 + b * 1000 + c
    if k in mem:
        return mem[k]
    else:
        return memory(k, gcd2(a, gcd2(b, c)))

s = 0
for a in range(1, K + 1):
    for b in range(a, K + 1):
        for c in range(b, K + 1):
            if a == b:
                if b == c:
                    m = 1
                else:
                    m = 3
            else:
                if b == c:
                    m = 3
                else:
                    m = 6
            s += gcd(a,b,c) * m


print(s)


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

double area(double x1, double y1, double x2, double y2,
	    double x3, double y3)
{
  return fabs((x2-x1)*(y3-y1) - (y2-y1)*(x3-x1));
}
int main()
{
  double x1, y1, x2, y2, x3, y3, xp, yp;
  double sum, sub1, sub2, sub3;

  while(scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
	      &x1, &y1, &x2, &y2, &x3, &y3, &xp, &yp) != EOF)
    {
      sum = area(x1, y1, x2, y2, x3, y3);
      sub1 = area(x1, y1, x2, y2, xp, yp);
      sub2 = area(x2, y2, x3, y3, xp, yp);
      sub3 = area(x3, y3, x1, y1, xp, yp);

      if(sum == sub1 + sub2 + sub3)
	printf("YES\n");
      else
	printf("NO\n");
    }

  return 0;
}

Measured memory_bytes: 612
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoderRegularContest069
{
    public class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(program1(new String[] { Console.ReadLine(), Console.ReadLine() }));
        }

        public static string program1(string[] args)
        {
            var n = int.Parse(args[0]);
            var s = args[1].ToCharArray();

            var animalPattern = new List<char>[] { new List<char>() { 'S', 'S' }, new List<char> { 'S', 'W' }, new List<char> { 'W', 'W' }, new List<char> { 'W', 'S' } };

            return string.Join("", animalPattern.Select(animals =>
            {
                var prevAnimal = animals.First();
                             
                foreach(var ans in s.Skip(1))
                {
                    var last = animals.Last();

                    if (last == 'S')
                    {
                        if (ans == 'x')
                        {
                            animals.Add(prevAnimal == 'S' ? 'W' : 'S');
                        }
                        else animals.Add(prevAnimal);
                    }
                    else
                    {
                        if (ans == 'o')
                        {
                            animals.Add(prevAnimal == 'S' ? 'W' : 'S');
                        }
                        else animals.Add(prevAnimal);
                    }
                    prevAnimal = last;
                }

                return animals;
            }).FirstOrDefault(animals => {
                if (animals.First() == animals.Last())
                {
                    if (s.First() == 'o' && animals.First() == 'S' || s.First() == 'x' && animals.First() == 'W')
                    {
                        return animals.ElementAt(1) == animals.ElementAt(n - 1);
                    }
                    else
                    {
                        return animals.ElementAt(1) != animals.ElementAt(n - 1);
                    }
                }
                else return false;
            })?.Take(n) ?? new List<char>() { '-', '1' }) ;
        }
    }
}


Measured memory_bytes: 18272
fun main(args: Array<String>) {
    val (N, C) = listOfInt()
    val D = Array(C) { listOfInt().toIntArray() }
    val t = Array(3) { IntArray(C) }
    repeat(N) { i ->
        listOfInt().forEachIndexed { j, x ->
            t[(i + j) % 3][x - 1] += 1
        }
    }
    var ans = Int.MAX_VALUE
    for (i in 0 until C) {
        for (j in 0 until C) {
            if (i == j) continue
            for (k in 0 until C) {
                if (i == k || j == k) continue
                var x = 0
                x += (0 until C).map { D[it][i] * t[0][it] }.sum()
                x += (0 until C).map { D[it][j] * t[1][it] }.sum()
                x += (0 until C).map { D[it][k] * t[2][it] }.sum()
                ans = Math.min(x, ans)
            }
        }
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { it.toInt() }

Measured memory_bytes: 72064
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>

using namespace std;

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

using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

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

    int s_len = s.length();

    int res = 0;
    if (s_len % 2 == 0) {
        for (int i = 0; i < s_len / 2; i++)
        {
            if (s[i] != s[s_len - i - 1]) res++;
        } 
        
    }
    else {
        for (int i = 0; i < s_len / 2; i++)
        {
            if (s[i] != s[s_len - i - 1]) res++;
        }   
    }
    cout << res << "\n";
}

Measured memory_bytes: 256
import sys

def bit_add(iii,x):
    while iii<len(bit):
        bit[iii]+=x
        iii+=iii&(-iii)
def bit_sum(jjj):
    s=0
    while jjj>0:
        s+=bit[jjj]
        jjj-=jjj&(-jjj)
    return s

n=int(input())
a=list(map(int,input().split()))
num=n*(n+1)//2
high=max(a)
low=min(a)
while high-low>1:
    mid=(high+low)//2
    ans=0
    b=[]
    for i in range(n):
        if a[i]>=mid:
            b.append(1)
        else:
            b.append(-1)
    for i in range(1,n):
        b[i]+=b[i-1]
    for i in range(n):
        b[i]+=n
    bit=[0]*(2*n+3)
    bit_add(n,1)
    for i in range(n):
        ans+=bit_sum(b[i])
        bit_add(b[i],1)
    if num%2==1:
        if ans>=num//2+1:
            low=mid
        else:
            high=mid
    else:
        if ans>=num//2:
            low=mid
        else:
            high=mid

            
            
if not high in a:
    print(low)
    sys.exit()
else:
    mid=high
    ans=0
    b=[]
    for i in range(n):
        if a[i]>=mid:
            b.append(1)
        else:
            b.append(-1)
    for i in range(1,n):
        b[i]+=b[i-1]
    for i in range(n):
        b[i]+=n
    bit=[0]*(2*n+3)
    bit_add(n,1)
    for i in range(n):
        ans+=bit_sum(b[i])
        bit_add(b[i],1)
    if num%2==1:
        if ans>=num//2+1:
            print(high)
        else:
            print(low)
    else:
        if ans>=num//2:
            print(high)
        else:
            print(low)

Measured memory_bytes: 121032
#include <iostream>

using namespace std;

int main(){
  
  int a , b ,c ;
  
  cin >> a >> b >> c;
  
  if(a > b){
    
    swap (a , b);
  }
    
  if(b > c){
    
    swap (b , c);
  }
  
  if(a > b){
    
    swap (a , b);
  }
  
  cout << a << ' '<< b << ' '<< c << endl;
}


Measured memory_bytes: 3100
import java.util.*;

public class Main {
	Scanner sc = new Scanner(System.in);
	void doIt() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int temp;
		int max = x;
		for(int i = 0; i < n; i++) {
			temp = sc.nextInt();
			//System.out.println(temp);
			if(max < temp) max = temp;
		}

		//System.out.println(max);
		for(int i = 0; i < m; i++) {
			temp = sc.nextInt();
			if(max >= temp) {
				System.out.println("War");
				return;
			}
		}
		if(max >= y) {
			System.out.println("War");
			return;
		}
		System.out.println("No War");

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

}


Measured memory_bytes: 23252
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
typedef long long integer;
//////////////////////////////////////////////////
struct Vertex {
	// edge information
	vector<int> edges_to; //to vertex number
	vector<integer> edges_cost; // edge cost
	
	//for dijkstra
	bool done; //conform or not
	integer cost; // now cost
	int from;
	
	bool operator<(const Vertex& another) const { // priority --> min
        return another.cost < cost; // order(cost)
    }
	
	bool operator==(const Vertex& another) const {
        return another.cost == cost; // order(cost)
    }
};

Vertex V[100002];

int main(){
    int N,M;
    SCD2(N,M);

    REP(i,M){
        int L,R;
        integer D;
        SCD2(L,R);
        SCLLD(D);
        
/*         if (L>R){
            swap(L,R);
            D = -D;
        } */

        V[L].edges_to.PB(R);
        V[L].edges_cost.PB(D);
        V[R].edges_to.PB(L);
        V[R].edges_cost.PB(-D);
    }

    bool ans = true;


    FORq(s,1,N){
        if (V[s].done) continue;
        queue<int> Q;
        Q.push(s);
        V[s].cost = 0;
        V[s].done = true;

        int nowpos = s;
        integer nowcost = 0;
        while(!Q.empty()){
            nowpos = Q.front();
            nowcost = V[nowpos].cost;
            Q.pop();

            REP(i,V[nowpos].edges_to.size()){
                int nextpos = V[nowpos].edges_to[i];
                integer nextcost = V[nowpos].edges_cost[i];

                if ((V[nextpos].done) and (nowcost + nextcost != V[nextpos].cost)){
                    printf("No\n");
                    return 0;
                }else if(!V[nextpos].done){
                    Q.push(nextpos);
                }
                
                V[nextpos].done = true;
                V[nextpos].cost = nowcost + nextcost;
            }
        }
    }

    printf("Yes\n");


}


Measured memory_bytes: 17792
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

#include <iostream>

struct mint{
    static const long long MOD = 1000000007;

    long long v;

    mint() : v(0) {}
    mint(long long x){
        x = x % MOD;
        if(x < 0){ x += MOD; }
        v = x;
    }
    mint& operator+=(mint a){
        v += a.v;
        if(v >= MOD){ v -= MOD; }
        return *this;
    }
    mint& operator*=(mint a){
        v *= a.v;
        v %= MOD;
        return *this;
    }
    mint& operator-=(mint a){
        v -= a.v;
        if(v < 0){ v += MOD; }
        return *this;
    }
    mint& operator/=(mint a){
        return (*this) *= a.inv();
    }

    mint operator*(mint a) const{
        return mint(v) *= a;
    }

    mint operator+(mint a) const {
        return mint(v) += a;
    }

    mint operator-(mint a) const {
        return mint(v) -= a;
    }

    mint operator/(mint a) const {
        return mint(v) /= a;
    }

    mint pow(long long k) const {
        mint res(1),tmp(v);
        while(k){
            if(k&1) res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }
    mint inv(){return pow(MOD - 2); }

    static mint comb(long long n, int k){
        mint res(1);
        for(int i = 0; i < k; ++i){
            res *= mint(n - i);
            res /= mint(i + 1);
        }
        return res;
    }

    static mint factorial(long long n){
        mint res(1);
        for(int i = n; i > 1; --i){
            res *= mint(i);
        }
        return res;
    }

    bool operator<(const mint &a) const {
        return v < a.v;
    };
};

mint operator*(long long l, mint r){ return r * l; }

std::ostream& operator<<(std::ostream& stream, const mint& m){
    stream << m.v;
    return stream;
}

int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> x(n), y(m);
    for(int i = 0; i < n; ++i){
        cin >> x.at(i);
    }
    for(int i = 0; i < m; ++i){
        cin >> y.at(i);
    }

    mint ytotal = 0;
    for(int i = 0; i < m - 1; ++i){
        ytotal += mint(y.at(i + 1) - y.at(i)) * (i + 1) * (m - i - 1);
    }

    mint ans = 0;
    for(int i = 0; i < n - 1; ++i){
        ans += mint(x.at(i + 1) - x.at(i)) * (i + 1) * (n - i - 1) * ytotal;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std; 
#define int int64_t
#define itn int
#define fi first
#define se second
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  int ans=0,sum;
  cin>>s;
  for(int i=0;i<(1<<s.size());i++){
    sum=0;
    for(int j=0;j<s.size();j++){
      //sum+=(s[j]-'0');
      if(i&(1<<j)) ans+=sum,sum=0;
      else sum*=10,sum+=(s[j]-'0');
    }
    ans+=sum;
  }
  cout<<ans<<"\n";
}


Measured memory_bytes: 3636
#include <iostream>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
#include<array>
#include<functional>
#include<iomanip>
#include<ios>
using namespace std;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)

typedef int value_type; /* ソートするキーの型 */

value_type med3(value_type x, value_type y, value_type z)
/* x, y, z の中間値を返す */
{
    if (x < y)
        if (y < z) return y; else if (z < x) return x; else return z; else
        if (z < y) return y; else if (x < z) return x; else return z;
}

void quicksort(value_type a[], int left, int right,value_type index[])
/* クイックソート
 * a     : ソートする配列 
 * left  : ソートするデータの開始位置
 * right : ソートするデータの終了位置
 * index: index配列
 */
{
    if (left < right) {
        int i = left, j = right;
        value_type tmp, pivot = med3(a[i], a[i + (j - i) / 2], a[j]); /* (i+j)/2ではオーバーフローしてしまう */
        while (1) { /* a[] を pivot 以上と以下の集まりに分割する */
            while (a[i] < pivot) i++; /* a[i] >= pivot となる位置を検索 */
            while (pivot < a[j]) j--; /* a[j] <= pivot となる位置を検索 */
            if (i >= j) break;
            tmp = a[i]; a[i] = a[j]; a[j] = tmp; /* a[i],a[j] を交換 */
            tmp = index[i]; index[i] = index[j]; index[j] = tmp;
            i++; j--;
        }
        quicksort(a, left, i - 1,index);  /* 分割した左を再帰的にソート */
        quicksort(a, j + 1, right,index); /* 分割した右を再帰的にソート */
    }
}


int dfs(int n,int N){
    if (n>N){
        return 0;
    }
    

    int ret;
    
    return ret;
}
double logfact(int n){
    long long dp[n+1];
    dp[0]=1;
    //dp[1]=1;
    double sum=0;
    for(int i=1;i<=n;i++){
        sum+=log(i);
    }
    return sum;
}
int main(){
    int N;
    cin >>N;

    long p[N];

    FOR(i,N){
        cin>>p[i];
    }
    sort(p,p+N);

    p[N-1]/=2;

    int tmp=0;

    FOR(i,N){
        tmp+=p[i];
    }

    cout<<tmp<<endl;


    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int n,m;
	cin>>n>>m;
	int md = (n-1)/2;
	int l1 = 1,l2 = md+1,l3 = md+2, l4 = l3+md-1;
	while(l1<l2&&m){
		cout<<l1<<' '<<l2<<endl;
		l1++;
		l2--;
		m--;
	}
	while(l3<l4&&m){
		cout<<l3<<' '<<l4<<endl;
		l3++;
		l4--;
		m--;
	}
	
	return 0;
}

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

typedef long long int ll;
typedef string str;

int main ()
{
	ll t,n,m,k,i,a,b;
	cin >> t;
	a=t/500;
	b=t%500;
	n=b/5;
	m=a*1000+n*5;
	cout << m << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

	Scanner sca = new Scanner(System.in);
	long h = sca.nextLong();
	long w = sca.nextLong();

	long ans = 0L;

	if(h == 1) {
		ans = 1;
	}
	else if(w == 1) {
		ans = 1;
	}
	else if(h % 2 == 0 && w % 2 == 0) {
		ans = (w / 2) * h;
	}
	else if(h % 2 == 0 && w % 2 == 1) {
		ans = (h / 2) * (w / 2) + (h / 2) * (w / 2 + 1);
	}
	else if(h % 2 == 1 && w % 2 == 0) {
		ans = (w / 2) * h;
	}
	else {
		ans = (h / 2) * (w / 2) + (h / 2 + 1) * (w / 2 + 1);
	}
	System.out.println(ans);

	// 後始末
	sca.close();
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
#include <stdlib.h>

int down(const void *a, const void *b) {
  return *(int *)b - *(int *)a;
}

int main(){
  int n;
  scanf("%d", &n);
  int v[n];
  for(int i = 0; i < n; i++){
    scanf("%d", &v[i]);
  }
  qsort(v, n, sizeof(int), down);
  double ans = 0.0;
  long long int x = 1;
  for(int i = 0; i < n - 1; i++){
    x *= 2;
    ans += (v[i] + 0.0) / (x + 0.0);
  }
  ans += (v[n - 1] + 0.0) / (x + 0.0);
  printf("%.12f\n", ans);
  return 0;
}


Measured memory_bytes: 128
import sys, bisect, math, itertools, heapq, collections
from operator import itemgetter
# a.sort(key=itemgetter(i)) # i番目要素でsort
from functools import lru_cache
# @lru_cache(maxsize=None)
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
INF = float('inf')
mod = 10**9 + 7
eps = 10**-7


def inp():
    '''
    一つの整数
    '''
    return int(input())


def inpl():
    '''
    一行に複数の整数
    '''
    return list(map(int, input().split()))


class combination():
    def __init__(self, mod):
        '''
        modを指定して初期化
        '''
        self.mod = mod
        self.fac = [1, 1]  # 階乗テーブル
        self.ifac = [1, 1]  # 階乗の逆元テーブル
        self.inv = [0, 1]  # 逆元計算用

    def calc(self, n, k):
        '''
        nCk%modを計算する
        '''
        if k < 0 or n < k:
            return 0
        self.make_tables(n)  # テーブル作成
        k = min(k, n - k)
        return self.fac[n] * (self.ifac[k] * self.ifac[n - k] %
                              self.mod) % self.mod

    def make_tables(self, n):
        '''
        階乗テーブル・階乗の逆元テーブルを作成
        '''
        for i in range(len(self.fac), n + 1):
            self.fac.append((self.fac[-1] * i) % self.mod)
            self.inv.append(
                (-self.inv[self.mod % i] * (self.mod // i)) % self.mod)
            self.ifac.append((self.ifac[-1] * self.inv[-1]) % self.mod)


comb = combination(mod)

n, k = inpl()
ans = 0
# m個の0人の部屋を作る
for m in range(min(n, k + 1)):
    # n個の部屋からm個の0人の部屋を選ぶ
    a = comb.calc(n, m) % mod
    # n個の部屋にm人を自由に割り当てる
    b = comb.calc(n - 1, n - m - 1) % mod
    ans += a * b % mod
print(ans % mod)


Measured memory_bytes: 82544
N,M = map(int,input().split())
L = []
for i in range(N):
    a,b = map(int,input().split())
    s = (a,b)
    L.append(s)
L.sort()
ans = 0
cnt = 0
for i,j in L:
    if(M> (cnt+ j)):
        ans += i * j
        cnt += j
    elif (M <= (cnt + j)):
        ans += i * (M - cnt)
        break
print(ans)

Measured memory_bytes: 53464
a = int(input())
b = input()
c = input()
e = -1
for i in range(a):
    if b[-i-1:] == c[:i+1]:
        e = max(e,i)
if e == -1:
    print(len(b + c))
else:
    print(len(b + c[e+1:]))


Measured memory_bytes: 2940
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

while True:
    N = int(input())
    if N == 0:
        break
    p = []
    for l in range(N):
        p.append(int(input()))
    p.sort()
    S = 0
    s = 0
    for l in range(N-1):
        s += p[l]
        S += s
    print(S)



Measured memory_bytes: 5728
#include <stdio.h>

int main(){

    int result = 1; 
    int power = 3; //cubic
    int x;

    scanf("%d", &x);

    //loop
    int i;
    for(i = 0; i < power; i++){
        result = result * x;
    }

    printf("%d\n",result);

    return 0;
}

Measured memory_bytes: 1804
#include <iostream>
#include <string>
#include <algorithm>

#include <stdio.h>
using namespace std;

int main(void) {
	int face[6];
	string simu;
	for (int i = 0; i < 6; i++) {
		cin >> face[i];
	}
	cin >> simu;
	int top   = 1;
	int up    = 5;
	int down  = 2;
	int left  = 4;
	int right = 3;
	for (int i = 0; i < simu.length(); i++) {
		switch (simu[i]) {
			case 'E':
				right = top;
				top = left;
				left = 7 - right;
				break;
			case 'W':
				left = top;
				top = right;
				right = 7 - left;
				break;
			case 'S':
				down = top;
				top = up;
				up = 7 - down;
				break;
			case 'N':
				up = top;
				top = down;
				down = 7 - up;
				break;
			default:
				break;
		}
	}
	cout << face[top - 1] << endl;

	return 0;
}



Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define RI(X) scanf("%d", &(X))
#define RII(X, Y) scanf("%d%d", &(X), &(Y))
#define RIII(X, Y, Z) scanf("%d%d%d", &(X), &(Y), &(Z))
#define DRI(X) int (X); scanf("%d", &X)
#define DRII(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define DRIII(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define RS(X) scanf("%s", (X))
#define CASET int ___T, case_n = 1; scanf("%d ", &___T); while (___T-- > 0)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define PII pair<int,int>
#define VI vector<int>
#define VPII vector<pair<int,int> >
#define PLL pair<long long,long long>
#define VPLL vector<pair<long long,long long> >
#define F first
#define S second
typedef long long LL;
using namespace std;
const int MOD = 1e9+7;
const int SIZE = 1e6+10;
string s="CODEFESTIVAL2016";
int main(){
    string t;
    cin>>t;
    int an=0;
    REP(i,16)an+=s[i]!=t[i];
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 256
N, L = (int(x) for x in input().split())
#リンゴiの味はL+i-1で与えられる。（i=1~N）
#作る予定のアップルパイの味の総和はN*(L-1) + 1/2*(N+1)*N
#出力はN-1個からアップルパイを作るとき、元の味との差が最小になる味
#味が0に最も近いものを探して、引けばよい。
aji = [L+i for i in range(N)]
#i=1~Nなので注意
#print(aji)
#0に一番近いものを探索
left = 0
while (aji[left] < 0):
    if left < N-1:
        left += 1
    else:
        break
#print(left)
ans = sum(aji) - aji[left]
print(ans)

Measured memory_bytes: 3060
<?php
class MyTest {

    public function run() {
        // スペース区切りの整数の入力
        fscanf(STDIN, "%d %d %d", $a, $b, $c);
        if (($c >  $a && $c < $b) || $c < $a && $c > $b ) {
            echo "Yes\n";
        } else {
            echo "No";
        }
        
    }
    
}

$test = new MyTest();
$test->run();

Measured memory_bytes: 4728
#include <bits/stdc++.h>
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define int long long
using namespace std;
using cd = complex <double>;

typedef pair <int, int> pii;
const int N = 3e3 + 5;
const long long INF = 1e18;
const int mod = 998244353;//786433;//998244353;
const double Pi = acos(-1);

 
void Fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

int n;
int a[400005], L[400005];
int Ans[400005][25];
long long res;

int Min(int x, int y)
{
	if(a[x] < a[y])
	{
		return x;
	}
	else
	{
		return y;
	}
}

int M(int l, int r)
{
	int temp = L[r - l + 1];
	int re = (1 << temp);
	re = r + 1 - re;
	return Min(Ans[l][temp], Ans[re][temp]);
}

void DNC(int l, int r)
{
	if(l > r)
	{
		return;
	}
	if(l == r)
	{
		res += a[l];
		return;
	}
	long long temp = M(l, r);
	res += (temp - l + 1) * (r - temp + 1) * a[temp];
	DNC(l, temp - 1);
	DNC(temp + 1, r); 
}

signed main()
{
	cin >> n;
	L[1] = 0;
	for(int i = 2; i <= 400000; i++)
	{
		L[i] = L[i >> 1] + 1;
	}
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		Ans[i][0] = i;
	}
	for(int i = 1; i <= 20; i++)
	{
		for(int j = 0; j + (1 << (i - 1)) <= n; j++)
		{
			int temp = 1 << (i - 1);
			Ans[j][i] = Min(Ans[j][i - 1], Ans[j + temp][i - 1]);
		}
	}
	DNC(0, n - 1);
	cout << res;
}

Measured memory_bytes: 56704
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double D;
#define F first
#define S second
const ll MOD=1000000007;
const ll E=1e18;

set<vector<ll>> ans;
multiset<ll> cost;
set<ll> point;
ll n;
ll l,r;

void dfs(ll d){
  if(d==n){
    ll L=l;
    auto I=point.begin(); ++I;
    vector<ll> ret;
    for(;I!=point.end();++I){
      ret.push_back((*I)-L);
      L=*I;
    }
    ans.insert(ret);
    return;
  }
  auto I=cost.end(); I--;
  ll dist=*I;
  ll w=dist+l;
  vector<ll> used;
  bool j=true;
  for(auto I=point.begin();I!=point.end();++I){
    auto T=cost.find(abs(*I-w));
    if(T!=cost.end()){
      used.push_back(abs(*I-w));
      cost.erase(T);
    }
    else{
      j=false;
      break;
    }
  }
  if(j && point.count(w)==0){
    point.insert(w);
    dfs(d+1);
    point.erase(w);
  }
  for(auto &I:used){cost.insert(I);}
  used.clear();
  
  w=r-dist;
  j=true;
  for(auto I=point.begin();I!=point.end();++I){
    auto T=cost.find(abs(*I-w));
    if(T!=cost.end()){
      used.push_back(abs(*I-w));
      cost.erase(T);
    }
    else{
      j=false;
      break;
    }
  }
  if(j && point.count(w)==0){
    point.insert(w);
    dfs(d+1);
    point.erase(w);
  }
  for(auto &I:used){cost.insert(I);}
}




int main(){
  while(cin>>n){
    if(n==0){break;}
    //for(auto &I:ans){I.clear();}
    ans.clear();
    cost.clear();
    point.clear();
    l=0; cin>>r;
    for(int i=1;i<n*(n-1)/2;i++){
      ll d;
      cin>>d;
      cost.insert(d);
    }
    point.insert(l);
    point.insert(r);
    dfs(2);
    for(auto &I:ans){
      for(int i=0;i+1<n;i++){cout<<I[i]<<(i+2==n?"\n":" ");}
    }
    cout<<"-----"<<endl;
  }

  return 0;
}



Measured memory_bytes: 3152
H, W, N = map(int, input().split())
ab = set(tuple(map(int, input().split())) for i in range(N))

dxy = {0:[0, 1, 2], 1:[-1, 0, 1], 2:[-2, -1, 0]}
num_all = (H - 2) * (W - 2)
num = [0] * 10
for a, b in ab:
  for i in range(3):
    Da = dxy[i]
    for j in range(3):
      n = 0
      flag = False
      Db = dxy[j]
      for da in Da:
        aa = a + da
        for db in Db:
          bb = b + db
          if aa < 1 or H < aa or bb < 1 or W < bb:
            flag = True
            break
          if (aa, bb) in ab:
            n += 1
        if flag:
          break
      if flag:
        continue
      num[n] += 1

for i in range(2, 10):
  num[i] //= i

num[0] = num_all - sum(num[1:])
print(*num, sep='\n')

Measured memory_bytes: 70488
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

typedef long long ll;

string S;
ll K;

int main() {
	cin >> S >> K;

	ll ans = 0;
	if (S[S.size() - 1] != S[0]) {
		ll base = 0;
		int renzoku = 1;
		for (int i = 1; i < S.size(); i++) {
			if (S[i] == S[i - 1])renzoku++;
			else {
				base += renzoku / 2;
				renzoku = 1;
			}
		}
		base += renzoku / 2;
		renzoku = 1;
		cout << base * K << endl;
	}
	else if (count(S.begin(), S.end(), S[0]) == S.size()) {
		cout << S.size() * K / 2LL << endl;
	}
	else {
		ll ans = 0;
		ll renzoku = 1;
		ll s, e;//[s, e]が最初と最後の文字列とつながってないもの
		//1周期目の最初の部分での必要な操作回数
		for (int i = 1; i < S.size(); i++) {
			if (S[i] == S[i - 1])renzoku++;
			else {
				ans += renzoku / 2;
				s = i;
				break;
			}
		}
		renzoku = 1;
		//最後の周目の最後の部分での必要な操作回数
		for (int i = S.size() - 2; i >= 0; i--) {
			if (S[i] == S[i + 1])renzoku++;
			else {
				ans += renzoku / 2;
				e = i;
				break;
			}
		}

		renzoku = 1;
		ll base = 0;
		for (int i = s + 1; i <= e; i++) {
			if (S[i] == S[i - 1])renzoku++;
			else {
				base += (renzoku / 2) * K;
				renzoku = 1;
			}
		}
		base += (renzoku / 2) * K;
		ans += base;
		renzoku = 1;

		ans += ((s + (S.size() - 1 - e)) / 2) * (K - 1);
		cout << ans << endl;
	}
	return 0;
}

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>bool chmin(T&a,const T&b){return a>b?(a=b,1):0;}
template<class T>bool chmax(T&a,const T&b){return a<b?(a=b,1):0;}


int nextInt() { int x; scanf("%d", &x); return x;}

const int INF = 1001001001;
const int SZ = 200000 + 10;
int dp[SZ];

int f(ll x) {
  int res = 0;
  while (x > 0) {
    res += x % 10;
    x /= 10;
  }
  return res;
}

int main2() {
  REP(j, SZ) dp[j] = INF;

  ll K = nextInt();
  while (K % 2 == 0) K /= 2;
  while (K % 5 == 0) K /= 5;
  
  int ans = f(K);
  dp[0] = 0;
  queue<int> q;
  q.push(0);
  while (!q.empty()) {
    int i = q.front(); q.pop();
    {
      for (int a = 0; a <= 9; a++) {
        int ni = i + (K * a);
        if (chmin(dp[(ni/10)], dp[i] + ni % 10)) {
          q.push(ni/10);
        }
      }
    }
  }
  for (int i = 1; i < SZ; i++) {
    chmin(ans, dp[i] + f(i));
  }  
  cout << ans << endl;
  return 0;
}


pair<int, int> ex(ll K) {
  int mi = 999999999;
  int aa = 1;
  for (int a = 1; a <= 10000; a++) {
    string s = to_string(K * a);
    int p = 0;
    REP(i, s.size()) p += s[i]-'0';
    if (chmin(mi, p)) {
      aa = a;
    }
  }
  return make_pair(mi, aa);
}

int main() {
  /*
  for (int k = 1; k <= 1000; k++) if (k % 2 != 0 && k % 5 != 0) {
    pair<int,int> p = ex(k);
    cout << k << "  " << p <<  "  " << (p.second * k) << endl;
  }
  for (int k = 79992; k <= 79992; k++) {
    pair<int,int> p = ex(k);
    cout << k << "  " << p <<  "  " << (p.second * k) << endl;
  }
  */
  for (;!cin.eof();cin>>ws) main2();
  return 0;
}



Measured memory_bytes: 1920
//解説AC
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    string s;
    cin >> s;
    
    long long ans = 0;
    bool flag = false;
    int n, count_b = 0;
    n = s.length();
    rep(i, n){
        if(s.at(i)=='B'&&!flag) flag = true;
        if(flag){
            if(s.at(i)=='B') count_b++;
            if(s.at(i)=='W'){
                ans += count_b;
            }
        }
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<queue>
#include<climits>
#include<set>
#include<map>
#define ll long long
using namespace std;

int main() {
	string s;
	cin >> s;
	for (ll i = 0; i < s.size(); i++) {
		if (s[i] == ',') {
			s[i] = ' ';
		}
	}
	cout << s << endl;


}

Measured memory_bytes: 256
char = str(input())
length = len(char)
char_len = ((length-1)/2)
char_list = list(char)
cnt = 0
list1 = []
list2 = []
newlist = []

while cnt != char_len:
    list1.append(char_list[cnt])
    cnt += 1

cnt2 = ((char_len * -1)-1)
cnt3 = -1
while cnt3 != cnt2:
    list2.append(char_list[cnt3])
    cnt3 -= 1

if list1 != list2:
    print('No')
else:
    for i in (reversed(list1)):
        newlist.append(i)
    if newlist == list1:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
 
int n, x, y, w[101000], ans;
vector<int> g[100100];
 
int Dfs(int x, int fa) {
	if(g[x].size() == 1) return 1;
	int res = 0, cnt = 0;
	for(int i = 0; i < g[x].size(); i++) {
		int v = g[x][i];
		if(v == fa) continue;
		int t = Dfs(v, x);
		if(t == 1) cnt++;
		res += t;
	}
//	printf("%d %d\n", x, cnt);
	if(cnt > 0) ans += cnt - 1;
	return res;
}
 
int main(void) {
	scanf("%d", &n);
	for(int i = 1; i < n; i++) {
		scanf("%d%d", &x, &y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int root = -1;
	for(int i = 0; i < n; i++) 
		if(g[i].size() > 2) {
			root = i;
			break;
		}
	if(!(~root)) return 0 * puts("1");
	Dfs(root, -1);
	printf("%d\n", ans);
}

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

int main() {
	// your code goes here
	int a,b,i,j;
	cin>>a>>b;
	int f=1;
	for(i=1;i<=15;i+=2)
	{
	    a--;
	}
	for(i=2;i<=16;i+=2)
	{
	    b--;
	}
	if(a<=0&&b<=0)
	cout<<"Yay!"<<endl;
	else
	cout<<":("<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <map>
#include <algorithm>
#include <cmath>
#include <vector>
#include <fstream>
#include <string>
#include <random>
#include <queue>
#include <iomanip>
#include <functional>
#include <climits>
#include <tuple>
#include <unordered_map>
#include <limits>
#include <functional>
#include <cassert>
#include <numeric>
#include <bitset>
#include <set>

#define FOR(x,n) for(int x = 0; x < n; x++)
#define INPUT(x) scanf("%d",&x)
#define PUT(x) printf("%d\n",x)
#define DPUT(x) printf("%.15lf\n",x)
#define GET(x,y) std::get<x>(y)
#define CHMAX(x,y) x = std::max(x,y)
#define CHMIN(x,y) x = std::min(x,y)
#define SP_END (i != n - 1 ? ' ' : '\n') ;

using namespace std;

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vll = std::vector<ll>;
using vpll = std::vector<pll>;
using vpii = std::vector<pii>;
using vi = std::vector<int>;
using vvi = std::vector<vi>;
using vvpii = std::vector<vpii>;
using vch = std::vector<char>;
using vvch = std::vector<vch>;
using tiii = std::tuple<int, int, int>;

const ll mod197 = 1000000007LL;
const ll INF = 10000000000LL;

const double PI11 = 3.14159265359;

const int dis[5] = { 0,1,0,-1,0 };

const int disD[4] = { 0,1,1,0 };
const int disLD[3] = { 0,1,0 };

const char disC[4] = { 'U','D','R','L' };
const char disY[4] = { -1,1,0,0 };
const char disX[4] = { 0,0,1,-1 };

//最大公約数
ll gcd(ll a, ll b) {
	if (a%b == 0)
		return b;
	return gcd(b, a%b);
}

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

	cout << min(a, b) + min(c, d) << endl;

	return 0;
}


Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
chk = [0]*(n-1)
for i in range(n-1):
    if A[i + 1] > A[i]:
        chk[i] = 2
    elif A[i + 1] < A[i]:
        chk[i] = 0
    else:
        chk[i] = 1
c = 0
money = 1000
stock = 0
for i in range(n-1):
    if chk[i] == 2 and c == 0:
        stock = money//A[i]
        money -= stock*A[i]
        c = 1
    elif chk[i] == 0 and c == 1:
        money += stock*A[i]
        stock = 0
        c = 0
    if 2 not in chk[i:]:
        money += stock*A[i]
        stock = 0
        break
money += stock*A[n-1]
print(money)

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

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int MAX { 200010 };
const ll MOD { 1000000007 }, oo { 1LL << 62 };

int solve(int N, const vector<int>& xs)
{
    return 0;
}

int main()
{
    ios::sync_with_stdio(false);

    int A, B, C, D;
    cin >> A >> B >> C >> D;

    int next = 0;

    while (A > 0 and C > 0)
    {
        switch (next) {
        case 0:
            C -= B;
            break;

        default:
            A -= D;
            break;
        }

        next = 1 - next;
    }

    cout << (next ? "Yes" : "No") << '\n';

    return 0;
}


Measured memory_bytes: 3636
N,K=map(int,input().split())
A=list(map(int,input().split()))
for i in range(K):
    d=[0]*(N+1)
    for j,a in enumerate(A):
        d[max(0,j-a)]+=1
        d[min(N,j+a+1)]-=1
    b=1
    for j in range(N):
        if d[j]!=N:
            b=0
        d[j+1]+=d[j]
    A=d[:-1]
    if b>0:
        break
print(*A)

Measured memory_bytes: 169304
#include <bits/stdc++.h>
 
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n) for(int i=1;i<=(n);i++)
#define lol long long
#define SUM(n) ((n)+1)*(n)/2　//1〜nまでの総和を求める式
#define mp make_pair
#define fi first
#define se second
#define pu push_back
#define SYOU(x) setprecision(x+1) //小数点桁数を指定する
#define abs(x,y) (max(x,y)-min(x,y))
#define all(v) v.begin(),v.end()
#define UPDight(a,b) (a+b-1)/b //小数点切り上げ 
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MOD=int(1e9)+7; 
using namespace std;
using pii = pair<int,int>;
typedef vector<int> vit;

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

    int n;
    bool in = false, de = false;
    cin >> n;
    int a[n + 5];
    reps(i, n){
      cin >> a[i];
    }
    int ans = 0;
    for(int i = 2;i <= n;i ++){
      if(in){//増加
	if(a[i - 1] > a[i]){
	  ans ++;
	  in = false;
	}
      } else if(de) {//減少
	if(a[i - 1] < a[i]){
	  ans ++;
	  de = false;
	}
      } else {
	if(a[i - 1] < a[i]){
	  in = true;
	} else if(a[i - 1] > a[i]){
	  de = true;
	} 
      }
    }
    cout << ans + 1 << '\n';
    return 0;
} 


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <map>
#include <deque>
#include <iomanip>
#include <cstdio>

using namespace std;
typedef  long long ll;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
#define  MP make_pair
#define  PB push_back
#define inf  1000000007
#define rep(i,n) for(int i=0;i<(int)(n);++i)


int main(){
    int n;
    cin >> n;
    int ans = 0;
    for(int i=1;i<=n;i+=2){
        int cnt = 0;
        for(int j=1;j<=i;j++){
            if(i%j==0)cnt++;
        }
        if(cnt==8){
            ans++;
        }
    }   
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 500;
;

int in[N][N], f[N][N], s[N][N];
signed main()
{
#ifdef home
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#else
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    int h, w;
    cin >> h >> w;
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
        {
            char c;
            cin >> c;
            in[i][j] = c == '#';
        }
    for (int i = 0; i < h; i++)
        f[i][0] = f[i][w - 1] = 1;
    for (int i = 0; i < w; i++)
        f[h - 1][i] = 1;
    for (int i = h - 3, r = 1; i >= 0; i -= 2)
    {
        if (r)
        {
            for (int j = 0; j < w - 2; j++)
                f[i][j] = 1;
        }
        else
        {
            for (int j = w - 1; j > 1; j--)
                f[i][j] = 1;
        }
        r = 1 - r;
    }
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
        {
            if (!f[i][j])
                s[i][j] = 1;
        }
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
        {
            if (in[i][j])
            {
                f[i][j] = s[i][j] = 1;
            }
        }
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++)
        {
            if (in[i][j] && (!f[i][j] || !s[i][j]))
            {
                cout << "kek";
                return 0;
            }
            if (f[i][j] && s[i][j] && !in[i][j])
            {
                cout << "kek";
                return 0;
            }
        }
    for (int i = 0; i < h; i++, cout << '\n')
        for (int j = 0; j < w; j++)
        {
            if (f[i][j])
                cout << '#';
            else
                cout << '.';
        }
    cout << '\n';
    for (int i = 0; i < h; i++, cout << '\n')
        for (int j = 0; j < w; j++)
        {
            if (s[i][j])
                cout << '#';
            else
                cout << '.';
        }
}

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

#define INF 1e9 + 5

// for using in pairs
#define F first
#define S second

// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;


void solve(int tc)
{
	int x;
	cin >> x;
	if (x >= 30)
	{
		cout << "Yes\n";
	}else
	{
		cout << "No\n";
	}
}

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;

	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}
	return 0;
}


Measured memory_bytes: 3604
/*input
5
WWWWWWWWWW
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
#define version 20190814
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

int n;
string s;
string t;
vector<int> v;
int main(){
	IOS;
	cin>>n>>s;
	REP(i,n){
		t.pb('W');
		t.pb('B');
	}
	REP(i,n+n){
		if(s[i]!=t[i]) v.pb(i);
	}
	if(SZ(v)!=n||v[0]!=0){
		cout<<"0\n";
		return 0;
	}
	ll ans=1;
	REP(i,n){
		ans=ans*(i+1)%MOD;
	}
	for(int i=n-1;i>=0;i--){
		ans=ans*(n+n-v[i]-1-(n-i-1)*2)%MOD;
	}
	cout<<ans<<'\n';
	return 0;
}


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

int main() {
  string S, T;
  int A, B;
  cin >> S >> T;
  cin >> A >> B;
  string U;
  cin >> U;
  if (U == S) {
    A--;
  } else {
    B--;
  }
  cout << A << " " << B << endl;
}

Measured memory_bytes: 256
/*
* * * * * * * * * * * * * * * * * * *
*       Author : Ganzaki            *
*                                   *
*       language : c++              *
*                                   *
* * * * * * * * * * * * * * * * * * *
*/
#include <bits/stdc++.h>


#define FOR(i,j,k) for(ll i=j;i<k;i++)
#define FOR1(i,j,k) for(ll i=j;i<=k;i++)
#define FOR2(i,j,k) for(ll i=j;i>=k;i--)
#define FILL(a,i) memset(a,i,sizeof(a))
#define db(i) printf("lol %d \n",i)
#define el '\n'
#define dbg(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
#define MOD 1000000007


using namespace std;


typedef long long ll;
typedef unsigned long ul;
typedef std::string str;
typedef long double ld;
typedef pair<ll,ll> ii;
typedef std::vector<str> vs;
typedef std::vector<int> vi;
typedef std::vector<ll> vll;
typedef std::vector<char> vc;
typedef map<int,int> mii;
typedef map<string,int> msi;
void desperate_optimization(int precision){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.setf(ios::fixed);
    cout.setf(ios::showpoint);
    cout.precision(precision);
}




void solve()
{
    str s;
    cin>>s;
    if(s.compare("Sunny")==0)
    {
        cout<<"Cloudy"<<el;
    }
    else if(s.compare("Cloudy")==0)
    {
        cout<<"Rainy"<<el;
    }
    else
    {
        cout<<"Sunny"<<el;
    }
}





int main()
{
    desperate_optimization(10);

    solve();
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  int a,b;
  cin>>a>>b;
  if(a>=13)
    {
    cout<<b;
    }
  else if(a>=6 && a<=12)
    {
    cout<<b/2;
    }
  else if(a<=5)
    { 
    cout<<"0";
    }
  return 0;
  }
    

Measured memory_bytes: 256
import numpy as np
n, k = map(int, input().split())
hhh = np.array(list(map(int, input().split())))
dp = np.zeros(n, dtype=int)
for i in range(1, n):
    start = max(0, i - k)
    dp[i] = min(dp[start:i] + np.abs(hhh[i] - hhh[start:i]))
print(dp[n - 1])

Measured memory_bytes: 22748
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <boost/range/algorithm.hpp>
#include <boost/integer/common_factor_rt.hpp>
#define MAX 100000000

using namespace std;

int N;

int main()
{
    while (cin >> N)
    {
        int p, cnt = 0;
        for (int i = 1; i <= N; i++)
        {
            cin >> p;
            if (p != i)
            {
                cnt++;
            }
        }
        if (cnt == 0 || cnt == 2)
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}


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

using namespace std;

int main()
{
    string s;
    cin >> s;
    bitset<10> b;
    int len = s.length();
    int loop = 1;
    long long ans = 0;
    for (int i=0; i<len-1; ++i){
        loop *= 2;
    }
    for (int i=0; i<loop; ++i){
        b = static_cast<bitset<10>>(i);
        long long num = 0;
        for (int j=0; j<len; ++j){
            if(b[j] == 1){
                ans += num * 10 + (s[j] - '0');
                num = 0;
            }
            else {
                num = num * 10 + (s[j] - '0');
            }
        }
        ans += num;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256