akhauriyash/Code-Regression huggingface dataset:
using System;

public class Hello
{
    public static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        if (n <= 104) { Console.WriteLine(0); goto end; }
        if (n == 105) { Console.WriteLine(1); goto end; }
        var res = 0;
        for (int i = 10; i <= n; i++)
        {
            if (i % 2 == 1)
            {
                var count = 0;
                for (int j = 1; j <= n; j++)
                    if (i % j == 0) count++;
                if (count == 8) res++;
            }
        }
        Console.WriteLine(res);
        end:;
    }
}


Measured memory_bytes: 11092
#include <stdio.h>
#include <string.h>
int a[4];
int main(){
  int id,i;
  char blood[2];
  while(scanf("%d,%s",&id,blood)!=EOF){
    if(!strcmp(blood,"A"))a[0]++;
    if(!strcmp(blood,"B"))a[1]++;
    if(!strcmp(blood,"AB"))a[2]++;
    if(!strcmp(blood,"O"))a[3]++;
  }
  for(i=0;i<4;i++)printf("%d\n",a[i]);
  return 0;
}

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


const int Max = 5e5+10;
int num[Max << 2], mark[Max << 2];
int N, Q;
string S;


void push_up(int node)
{
    num[node] = num[node << 1] | num[node << 1 | 1];
}


void push_down(int node, int l, int r)
{
    if (mark[node]) {
        mark[node << 1] = mark[node];
        mark[node << 1 | 1] = mark[node];
        num[node << 1] = mark[node];
        num[node << 1 | 1] = mark[node];
        mark[node] = 0;
    }
}


void build(int node, int l, int r)
{
    if (l == r) {
        int c = S[l-1] - 'a';
        num[node] = 1 << c;
        mark[node] = 0;
    } else {
        int mid = (l + r) >> 1;
        build(node << 1, l, mid);
        build(node << 1 | 1, mid + 1, r);
        push_up(node);
    }
}


void update(int node, int l, int r, int cl, int cr, int c)
{
    if (cl > r || cr < l) return;
    if (cl <= l && cr >= r) {
        mark[node] = c;
        num[node] = c;
        return;
    }
    push_down(node, l, r);
    int mid = (r + l) >> 1;
    update(node << 1, l, mid, cl, cr, c);
    update(node << 1 | 1, mid + 1, r, cl, cr, c);
    push_up(node);
}


int query(int node, int l, int r, int cl, int cr)
{
    if (cl > r || cr < l) return 0;
    if (cl <= l && cr >= r) return num[node];
    push_down(node, l, r);
    int mid = (r + l) >> 1;
    int ret = 0;
    ret |= query(node << 1, l, mid, cl, cr);
    ret |= query(node << 1 | 1, mid + 1, r, cl, cr);
    push_up(node);
    return ret;
}


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

    cin >> N;
    cin >> S;
    build(1, 1, N);
    cin >> Q;
    int idx;
    int iq;
    char cq;
    int lq, rq;
    while (Q--) {
        cin >> idx;
        if (idx == 1) {    // 1 iq cq
            cin >> iq >> cq;
            int c = cq - 'a';
            update(1, 1, N, iq, iq, 1 << c);
        } else {    // 2 lq rq
            cin >> lq >> rq;
            int res = query(1, 1, N, lq, rq);
            cout << __builtin_popcount(res) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 12188
#include <stdio.h>

#define Mod 998244353

long long div_mod(long long x, long long y, long long z)
{
	if (x % y == 0) return x / y;
	else return (div_mod((1 + x / y) * y - x, (z % y), y) * z + x) / y;
}

long long combination(int n, int k)
{
	if (k == 0) return 1;
	
	static long long ans[600][300] = {};
	if (ans[n][k] != 0) return ans[n][k];
	
	int i;
	long long x, y;
	for (i = n, x = 1; i >= n - k + 1; i--) x = x * i % Mod;
	for (i = 2, y = 1; i <= k; i++) y = y * i % Mod;
	ans[n][k] = div_mod(x, y, Mod);
	return ans[n][k];
}

int main()
{
	int K;
	char S[301];
	scanf("%s %d", S, &K);

	int i, j, k, l, m, count[151][2] = {}, sum[2] = {};
	count[0][S[0] - '0']++;
	for (l = 1, k = 0; S[l] != 0; l++) {
		if (S[l] == S[l-1] || S[l] == '1') count[k][S[l] - '0']++;
		else count[++k][0]++;			
	}
	
	long long dp[301][301][301] = {};
	if (count[0][0] == 0) i = 1;
	else i = 0;
	dp[i][0][count[i][0]+1] = 1;
	for (j = 1; j <= count[i][1]; j++) {
		for (k = 1; k <= count[i][0]; k++) dp[i][j][k] = combination(j + count[i][0] - k - 1, j - 1);
	}
	
	for (sum[0] = count[i][0], sum[1] = count[i++][1]; count[i][1] > 0; i++) {
		for (l = 0; l <= sum[1]; l++) {
			for (k = 1; k <= sum[0] + 1; k++) dp[i][l][k+count[i][0]] = dp[i-1][l][k];
		}
		sum[0] += count[i][0];
		for (j = 1; j <= count[i][1]; j++) {
			for (l = 0; l <= sum[1]; l++) {
				for (k = 1; k <= sum[0]; k++) {
					for (m = sum[0] - count[i][0] + 1; m + count[i][0] - 1 >= k; m--) dp[i][l+j][k] = (dp[i][l+j][k] + dp[i-1][l][m] * combination(j + m + count[i][0] - k - 2, j - 1)) % Mod;
				}
			}
		}
		sum[1] += count[i][1];
	}
	
	long long ans = 0;
	for (j = 0; j <= K && j <= sum[1]; j++) {
		for (k = 1; k <= sum[0] + 1; k++) ans = (ans + dp[i-1][j][k]) % Mod;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 215452
#include<stdio.h>

#define MAX_LENGTH 32

int main(void)
{
        char line[MAX_LENGTH];
        int x,y;
        int tmp;
        int i = 0;

        while (i <= 3000) {
                i++;
                fgets(line, sizeof(line), stdin);
                sscanf(line, "%d %d", &x, &y);
                if ( (x == 0) && (y == 0) )
                        break;

                if (x > y) {
                        tmp = x;
                        x = y;
                        y = tmp;
                }
                printf("%d %d\n", x, y);
        }

        return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define FOR(i, s, e) for (ll(i) = (s); (i) < (e); (i)++)
#define FORR(i, s, e) for (ll(i) = (s); (i) > (e); (i)--)
#define debug(x) cout << #x << ": " << x << endl
#define mp make_pair
#define pb push_back
const ll MOD = 1000000007;
const int INF = 1e9;
const ll LINF = 1e16;
const double PI = acos(-1.0);
int dx[8] = { 0, 0, 1, -1, 1, 1, -1, -1 };
int dy[8] = { 1, -1, 0, 0, 1, -1, 1, -1 };

/* -----  2017/05/20  Problem: ARC 074 A / Link: http://arc074.contest.atcoder.jp/tasks/arc074_a  ----- */
/* ------問題------



-----問題ここまで----- */
/* -----解説等-----



----解説ここまで---- */

ll H, W;

ll ans = LINF;

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

	cin >> H >> W;
	ans = min(H, W);
	FOR(w, 1, W) {
		ll s = w*H;
		ll x = (W - w)*(H / 2);
		ll y = H*W - s - x;
		if (y < 1)continue;
		ll M = max(s, max(x, y));
		ll m = min(s, min(x, y));
		if (M - m < ans) {
			ans = min(ans, M - m);
		}
	}
	swap(H, W);
	FOR(w, 1, W) {
		ll s = w*H;
		ll x = (W - w)*(H / 2);
		ll y = H*W - s - x;
		ll M = max(s, max(x, y));
		ll m = min(s, min(x, y));
		ans = min(ans, M - m);
	}

	if (H % 3 == 0 || W % 3 == 0)ans = 0;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int w, a, b;
  cin >> w >> a >> b;
  if (a < b) cout << max(0, b-(a+w)) << endl;
  else cout << max(0, a-(b+w)) << endl;
  return 0;
}


Measured memory_bytes: 256
use std::cmp::max;
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("filed 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() {
    let n:usize = read();
    let w:usize = read();

    let mut value = vec![0; 110];
    let mut weight = vec![0; 110];
    for i in 0..n {
        value[i] = read();
        weight[i] = read();
    }
    let mut dp = vec![0; 10010];

    for i in 0..w+1 {
        for j in 0..n {
            if i >= weight[j] {
                dp[i] = max(dp[i], dp[i-weight[j]] + value[j]);
             }
        }
    }
    println!("{}", dp[w]);
}


Measured memory_bytes: 5036
<?php
list($n,$m)=explode(' ',trim(fgets(STDIN)));

for($i=0;$i<$n;$i++)$a[$i]=explode(' ',trim(fgets(STDIN)));

for($i=0;$i<$m;$i++)$b[$i]=trim(fgets(STDIN));
 
$o='';
for($i=0;$i<$n;$i++){
  $c=0;
  for($j=0;$j<$m;$j++) $c+=$a[$i][$j]*$b[$j];
  $o.=$c.PHP_EOL;
}
print $o;

Measured memory_bytes: 17304
#include <bits/stdc++.h>
using namespace std;
int main() {	
	int t=1;
	//cin >> t;
	while (t--) {
	   
	   string a,b;
	   cin>>a>>b;
	   int dp[3001][3001];
	    for(int i=0;i<=a.length();i++)
	    {
	    	for(int j=0;j<=b.length();j++)
	    	{
	    		if(i==0||j==0)
	    		dp[i][j]=0;
	    		else if(a[i-1]==b[j-1])
	    		{
	    			dp[i][j]=1+dp[i-1][j-1];
				}
				else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
	   
	    string ans="";
	    int i=a.length();
	    int j=b.length();
	    while(i>0&&j>0)
	    {
	    	if(a[i-1]==b[j-1])
	    	{
	    		ans+=a.substr(i-1,1);
	    		i--;
	    		j--;
			}
			else if(dp[i-1][j]>dp[i][j-1])
			  {
			  	i--;
			  }
			  else
			  {
			  	j--;
			  }
			
		}
	    
	    
	    reverse(ans.begin(),ans.end());
	    cout<<ans;
	    
      }
	} 
	
	
	

Measured memory_bytes: 38760
def check(st) : 
  
    # Compute sum of digits 
    n = len(st) 
    digitSum = 0
      
    for i in range(0,n) : 
        digitSum = digitSum + (int)(st[i]) 
  
    # Check if sum of digits 
    # is divisible by 9. 
    return (digitSum % 9 == 0) 
  
# Driver code 
x = input()
st= str(x)
  
if(check(st)) : 
    print("Yes") 
else :  
    print("No") 

Measured memory_bytes: 9232
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
ll comb[4001][4001] = {};
void init() {
	rep(i, 4001) {
		rep(j, 4001) {
			if (i == 0 || j == 0)comb[i][j] = 1;
			else comb[i][j] = (comb[i - 1][j] + comb[i][j - 1]) % mod;
		}
	}
}
ll k, n;
ll num(ll p, ll q, ll r) {
	ll res = comb[p - q][q];
	if (r - 2 * q < 0)return 0;
	res *= comb[k - 1][r - 2 * q];
	if (q % 2) {
		return ((-res)%mod + mod) % mod;
	}
	else return res % mod;
}
int main() {
	init();
	cin >> k >> n;
	Rep1(i, 2, 2 * k) {
		int p;
		if (i > k + 1) {
			p = k - (i-1) / 2;
		}
		else p = i / 2;
		ll out = 0;
		rep(j, p + 1) {
			(out += num(p, j,n)) %= mod;
		}
		cout << out << endl;
	}
	return 0;
}

Measured memory_bytes: 125312
#include<iostream>
#include<vector>
#include<string>
#include<bitset>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<set>
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

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

	vector<vector<int>> data(n + 10, vector<int>(2, 0));
	rep(i, n) {
		cin >> data[i + 1][0] >> data[i + 1][1]; //i番目の品物 data[i]
	}

	vector<vector<long long>> dp(n + 10, vector<long long>(w + 10, 0));
	
	for (int i = 0; i < n + 1; i++) {
		for (int j = 0; j < w + 1; j++) {
			if (i > 0) {
				if (dp[i][j] < dp[i - 1][j]) {
					dp[i][j] = dp[i - 1][j];
				}
			}
			if (j + data[i+1][0] <= w) {
				dp[i + 1][j + data[i + 1][0]] = dp[i][j] + data[i + 1][1];
			}
		}
	}
	/*
	rep(i, n + 1) {
		rep(j, w + 1) {
			cout << dp[i][j] << " ";
		}
		cout << endl;
	}
		*/

	cout << dp[n][w] << endl;
	return 0;
}

Measured memory_bytes: 90144
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())
cnt = 0
ans = 0
for s in S:
    if s=='R':
        cnt += 1
        ans = max(cnt, ans)
    else:
        cnt = 0
print(ans)

Measured memory_bytes: 61632
N=int(input())
h=list(map(int,input().split()))
p=h[0]
for i in range(N-1):
  if p<h[i+1]:
    p=h[i+1]
  else:
    p=p
 
q=1
r=0
if p==0:
    print(0)
else:
    while q<=p:
        if h[0]>=q:
            r=r+1
        else:
            r=r
        for i in range(N-1):
              if h[i]<q and h[i+1]>=q:
                r=r+1
              else:
                r=r
        q=q+1
    print(r)

Measured memory_bytes: 3064
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;

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

	int n, m;
	int count;

	while (cin >> n >> m){
		count = (int)log10(n + m) + 1;
		cout << count << endl;		
	}

}

Measured memory_bytes: 1236
#include<stdio.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<iostream>
#include<vector>
#include<algorithm>
#include<numeric>
#include<string.h>
#include<map>
#include<queue>

using namespace std;

typedef pair<int,int> pii;

#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<=k;i++)
#define in(i,j,k) ((i)>=(j)&&(i)<=(k))


int main(){
	int c[]={1,0,0};
	char s[9];
	while(~scanf("%s",s))swap(c[s[0]-'A'],c[s[2]-'A']);
	rep(i,3)if(c[i])printf("%c\n",'A'+i);
	return 0;
}

Measured memory_bytes: 1136
import java.util.Scanner;
public class Main {
	public static int search(String s) {
		int cnt = 0;
		for(int i = 0; i < s.length()/2;i++) {
				if(s.charAt(i)!= s.charAt(s.length()-i-1)) {
					cnt++;
					//s = s.replace(s.charAt(i), s.charAt(s.length()-i-1)) ;
				}
			}
		
		
		
		
		
		return cnt;
	}
	
	
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		String s = stdIn.next();
		System.out.println(search(s));
	}

}


Measured memory_bytes: 21716
N, M = sorted(map(int, input().split()))
if N == 1:
    if M == 1:
        print(1)
    elif M == 2:
        print(0)
    else:
        print(M - 2)
elif N == 2:
    if M == 2:
        print(0)
    else:
        print(0)
else:
    print((N - 2) * (M - 2))


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

using namespace std;
using llint = long long;

#define LOG(x) cout << "# " << #x <<" => "<< (x) <<endl


string s;
llint ans = 0;

int main() {
    // Input
    cin >> s;

    // Solve
    int id = 0, p = 0;
    while(id < s.size()-1){
        if (s.at(id)=='A') {
            ++p;
        } else if (s.at(id)=='B' && s.at(id+1)=='C') {
            ans += p;
            ++id;
        } else {
            p = 0;
        }

        ++id;
    }

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

Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int l[5];
	char c;
	while (cin >> l[0] >> c >> l[1] >> c >> l[2] >> c >> l[3] >> c >> l[4]) {
		sort(l, l + 5);
		if (l[0] == l[1] && l[1] == l[2] && l[2] == l[3])
			cout << "four card";
		else if (l[4] == l[1] && l[1] == l[2] && l[2] == l[3])
			cout << "four card";
		else if (l[0] == l[1] && l[1] == l[2] && l[4] == l[3])
			cout << "full house";
		else if (l[0] == l[1] && l[3] == l[2] && l[4] == l[3])
			cout << "full house";
		else if (l[4] == l[3] + 1 && l[3] == l[2] + 1 && l[2] == l[1] + 1 && l[1] == l[0] + 1)
			cout << "straight";
		else if (l[0] == 1 && l[1] == 10 && l[2] == 11 && l[3] == 12 && l[4] == 13)
			cout << "straight";
		else if (l[0] == l[1] && l[1] == l[2])
			cout << "three card";
		else if (l[3] == l[1] && l[1] == l[2])
			cout << "three card";
		else if (l[3] == l[4] && l[3] == l[2])
			cout << "three card";
		else if (l[0] == l[1] && l[2] == l[3])
			cout << "two pair";
		else if (l[0] == l[1] && l[4] == l[3])
			cout << "two pair";
		else if (l[2] == l[1] && l[4] == l[3])
			cout << "two pair";
		else if (l[0] == l[1] || l[1] == l[2] || l[2] == l[3] || l[3] == l[4])
			cout << "one pair";
		else cout << "null";
		cout << endl;
	}
}

Measured memory_bytes: 3040
#include <iostream>
#include <map>
#include <set>
#include <algorithm>
#include <vector>
#include <sstream>
#include <string>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <limits>
#include <unordered_map>
#include <unordered_set>
#include <math.h>
#include <fstream>
#include <iterator>
#include <random>
#include <chrono>
 
 
#define forr(i,start,count) for (int i = (start); i < (start)+(count); ++i)
#define set_map_includes(set, elt) (set.find((elt)) != set.end())
#define readint(i) int i; cin >> i
#define readll(i) ll i; cin >> i
#define readdouble(i) double i; cin >> i
#define readstring(s) string s; cin >> s
 
typedef long long ll;
 
using namespace std;

ll modd = 1000*1000*1000+7;


int main()   {

    ios_base::sync_with_stdio(false);

    cout.precision(17);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    uniform_int_distribution<int> rand_gen(0, modd);   // rand_gen(rng) gets the rand no
 
//    auto start = chrono::steady_clock::now();
  
//    readint(test_cases);
    int test_cases = 1;
    forr(t, 1, test_cases) {
        readint(a);
        cout << (a+a*a+a*a*a) << endl;
    }
 
//    auto end = chrono::steady_clock::now();
//    cout << chrono::duration_cast<chrono::milliseconds>(end - start).count() << endl;
 
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
int main()
{

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
//  #ifdef ONLINE_JUDGE
//	    freopen("input1.txt","r",stdin);
//	    freopen("output1.txt","w",stdout);
//  #endif
string s;
cin >> s;
bool flag=false;
for(int i =0 ; i <s.size()  ;i++)
{
	if(i==3)
	{
		if(s[i-1]==s[i])
		{
			if(s[i+1]==s[i+2])
			{
				flag=true;
				break;
			}
		}
	}
}
if(flag)
cout<<"Yes"<<endl;
else
cout<<"No"<<endl;

  }


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

int main(){
	int a;
	cin>>a;
	for(int i=0;i<a;i++){
		char b[100];
		cin>>b[i];
		if(b[i]=='Y'){
			cout<<"Four"<<endl;
			return 0;
		}
	}
	cout<<"Three"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
using namespace std;

int main(){
	string str;
	while(true){
		cin >> str;
		if(str == "0") break;
		int ans = 0;
		for(int i=0;i<str.size();i++){
			ans += str[i] - '0';
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 3156
S = int(input())
A = [S]
if (A[0]%2) == 0:
  A.append(int(A[0]/2))
else:
  A.append(int(3*A[0]+1))
i = 1
while i >0:
  if A[i]%2 == 0:
    X = int(A[i]/2)
    if X in A:
      A.append(X)
      break
    else:
      A.append(X)
    i += 1
  else:
    X = int(3*A[i]+1)
    if X in A:
      A.append(X)
      break
    else:
      A.append(X)
    i += 1
print(len(A))

Measured memory_bytes: 9160
import java.util.*;
public class Main{
    static int N, A, B, C;
    static int[] l;
    private final static int INF = (int)Math.pow(10, 9);

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        l = new int[N];
        for(int i = 0; i < N; i++){
            l[i] = sc.nextInt();
        }        
        System.out.println(dfs(0, 0, 0, 0)); 
    }

    public static int dfs(int cur, int a, int b, int c){
        if(cur == N){
            if(min(a, b, c) > 0){
                return Math.abs(a-A) + Math.abs(b-B) + Math.abs(c-C) - 30;
            } else{
                return INF;
            }             
        }
        int ret0 = dfs(cur + 1, a, b, c),
        ret1 = dfs(cur + 1, a + l[cur], b, c) + 10,
        ret2 = dfs(cur + 1, a, b + l[cur], c) + 10,
        ret3 = dfs(cur + 1, a, b, c + l[cur]) + 10;
        return min(ret0, ret1, ret2, ret3);
    }

    public static int min(int... value){
        int min = value[0];
        for(int i = 1; i < value.length; i++){
            if(value[i] < min){
                min = value[i];
            }
        }
        return min;
    }
}

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

int main()
{
    int N;
    cin>>N;
    long long arr[N];

    for(int i=0;i<N;i++)
    {
        cin>>arr[i];
    }
    sort(arr,arr+N);
    int count=0;
    for(int i=0;i<N-2;i++)
    {
        for(int j=i+1;j<N-1;j++)
        {
            for(int k=j+1;k<N;k++)
            {
               // cout<<i<<" "<<j<<" "<<k<<"\n";
                if(arr[i]!=arr[j] && arr[i]!=arr[k] && arr[j]!=arr[k])
                {
                    if(arr[i]+arr[j]>arr[k])
                    {
                        //cout<<"####"<<i<<" "<<j<<" "<<k<<"\n";
                        count++;
                    }
                }
            }
        }
    }
    cout<<count;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <stdio.h>
#include <math.h>
typedef long long ll;
using namespace std;

int main() {
	ll n,m;
	cin>>n>>m;
	ll a,b,ans[n+1]={0};
	for(int i=0;i<m;i++){
		cin>>a>>b;
		ans[a]++;
		ans[b]++;
	}
	for(int i=1;i<n+1;i++){
		cout << ans[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int i,j,k,num1,first[10000],num2,second[10000],same=0;
    //一つ目の数列
    scanf("%d",&num1);
    for(int i=0;i<num1;i++){
        scanf("%d",&first[i]);
    }
/*
    //デバッグ
    for(int i=0;i<num1;i++){
        printf("%d ",first[i]);
    }
    */

    //二つ目の数列
    scanf("%d",&num2);
    for(i=0;i<num2;i++){
        scanf("%d",&second[i]);
    }
    /*
     //デバッグ
    for(i=0;i<num2;i++){
        printf("%d",second[i]);
    }
    printf("\n");
    */
    if(num2<num1){
     for(j=0;j<num2;j++){
         for(k=0;k<num1;k++){
           if(first[k]==second[j]){
                   same++;
                   break;
               }
           }
         }
    }else if(num2>num1){
         for(j=0;j<num1;j++){
           for(k=0;k<num2;k++){
             if(first[j]==second[k]){
                   same++;
                   break;
               }
           }
         }
     }
    printf("%d\n",same);

    return 0;
}



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

#if __has_include(<local.h>)
#include <local.h>
#endif

using namespace std;

typedef long long int LL;
typedef long long int LLint;

//Faster Program
#define endl "\n"

//Faster Coding
#define ED return
#define GET(a) int a;cin >> a
#define DGET(a) double a;cin >> a
#define SGET(a) string a;cin >> a
#define CGET(a) char a;cin >> a
#define PRINT(a) cout << a << "\n"
#define ANS(a,b) int a;cin >> a;cout << b << "\n"
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define SORT(vec) sort(vec.begin(),vec.end())
#define REV(vec) reverse(vec.begin(),vec.end())
#define ALL(x) (x).begin(),(x).end()

//As Function
#define UP(a,b) ((a+(b-1))/b)
#define IPOW(x,y) LL(pow(x,y))

//Debug
#ifdef LOCAL_H
#define TEST cout << "OK\n"
#define DEBUG(a) a
#else
#define TEST
#define DEBUG(a)
#endif

#ifdef LOCAL_H
[[maybe_unused]]
#endif
const double PI = M_PI;
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const int INF = int(999999999);
#ifdef LOCAL_H
[[maybe_unused]]
#endif
const long long MOD = int(1000000007);

//Settings
#ifdef LOCAL_H
const bool DO_BENCHMARK = true;
#endif
const int DOUBLE_ACCURACY = 15;

#ifndef LOCAL_H
    const bool DO_BENCHMARK = false;
#endif

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(DOUBLE_ACCURACY);
    void solve();
    if(DO_BENCHMARK){
        clock_t clock_start = clock();
        solve();
        clock_t clock_end = clock();
        const double time = static_cast<double>(clock_end-clock_start)/CLOCKS_PER_SEC*1000.0;
        cout << "\n" << time << "[ms]\n";
    }
    else solve();
}

/************************************************************************************************************************************************/

void solve(){
    vector<vector<int>> vec (3,vector<int>(3));
    for(int i = 0;i < 3;i++){
        for(int j = 0;j < 3;j++){
            cin >> vec[i][j];
        }
    }

    LL N;
    cin >> N;
    for(int n = 0;n < N;n++){
        GET(dummy);
        for(int i = 0;i < 3;i++){
            for(int j = 0;j < 3;j++){
                if(dummy == vec[i][j]){
                    vec[i][j] = 0;
                }
            }
        }
    }

    if(vec[0][0]+vec[0][1]+vec[0][2]==0||vec[1][0]+vec[1][1]+vec[1][2]==0||vec[2][0]+vec[2][1]+vec[2][2]==0||vec[0][0]+vec[1][0]+vec[2][0]==0||vec[0][1]+vec[1][1]+vec[2][1]==0||vec[0][2]+vec[1][2]+vec[2][2]==0||vec[0][0]+vec[1][1]+vec[2][2]==0||vec[0][2]+vec[1][1]+vec[2][0]==0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
import itertools
import os
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

pos = [0] * (N + 1)
pos[0] = -1
for i, a in enumerate(A):
    pos[a] = i

ans = 0
lefts = [0] * N
rights = [0] * N
for i in reversed(range(1, N + 1)):
    p = pos[i]
    if p + 1 < N and A[p + 1] > i:
        # 右とつながった
        right = rights[p + 1]
    else:
        right = p
    if p - 1 >= 0 and A[p - 1] > i:
        # 左とつながった
        left = lefts[p - 1]
    else:
        left = p
    lefts[right] = left
    rights[left] = right
    ans += (p - left + 1) * (right - p + 1) * i
print(ans)


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

int main(void){
  int n; cin >>n;
  int b[n-1];
  for(int i=0; i < n-1; i++){
    scanf("%d",&b[i]);
  }
  int a[n]; a[n-1] = b[n-2];
  for(int i = n-2; i > 0; i--){
    a[i] = min(b[i],b[i-1]);
  }
  a[0] = b[0];
  int sum = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
  }
  printf("%d",sum);
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
 
using namespace std;
 
 
 
int main()
{
  int n;
  
  cin >> n;
  
  long l[n];
  for(int i=0;i<n;i++) cin >> l[i];
  
  //sort(l,l+sizeof(l)/sizeof(l[0]));
  
  int ans = 0;
  
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      for(int k=j+1;k<n;k++)
      {
        if (l[i] == l[j] || l[i] == l[k] || l[j] == l[k]) continue;
        //int i2 = l[i]*l[i];
        //int j2 = l[j]*l[j];
        //int k2 = l[k]*l[k];
        if (l[i]+l[j]>l[k] && l[k]+l[j]>l[i] && l[i]+l[k]>l[j]) ans++;
        //else if (i2+k2==j2) ans++;
        //else if (k2+j2==i2) ans++;
      }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 3664
import math

n,g=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
comp=[(100*(i+1)*arr[i][0]+arr[i][1]) for i in range(n)]
ans=10**10
for i in range(2**n):
  flag=format(i,'b')
  if len(flag)<n:
    flag='0'*(n-len(flag))+flag
  tsum=0
  tans=0
  for i in range(n):
    if flag[i]=='1':
      tsum+=comp[i]
      tans+=arr[i][0]
  if tsum>=g:
    ans=min(ans,tans)
  else:
    pos=flag[::-1].index('0')
    tq=math.ceil((g-tsum)/(100*(n-pos)))
    if tq<=arr[n-pos-1][0]:
      ans=min(ans,tans+tq)
print(ans)

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

int gcd(int x, int y){ return (x % y)? gcd(y, x % y): y; }
                      
int main(){
int K;
cin>>K;
int A[K][K];
for (int i=0; i<K; i++){
  for (int j=0; j<K; j++){
    A[i][j]=gcd(i+1,j+1);
  }
}
int B[K][K][K];
for (int i=0; i<K; i++){
  for (int j=0; j<K; j++){
    for (int k=0; k<K; k++){
      B[i][j][k]=gcd(A[i][j],k+1);
    }
  }
}
  int sum=0;
for (int i=0; i<K; i++){
  for (int j=0; j<K; j++){
    for (int k=0; k<K; k++){
      sum+=B[i][j][k];
    }}}
  cout<<sum<<endl;}


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

class WeightedUnionFind{
public:
	vector<int> Parent;
	vector<int> Rank;
	vector<long long> Weight;
	WeightedUnionFind(int n){
		++n;
		Parent.resize(n, 0);
		Rank.resize(n, 0);
		Weight.resize(n, 0);
		for(int i=0; i<n; ++i)
			Parent[i] = i;
	}

	int find(int x){
		if(Parent[x] == x) return x;
		int pastparent = Parent[x];
		Parent[x] = find(Parent[x]);
		Weight[x] += Weight[pastparent];
		return Parent[x];
	}

	bool unite(int x, int y, long long z){ // a[y] - a[x] == z
		int sx = x, sy = y;
		x = find(x);
		y = find(y);
		if(x == y) return false;
		if(Rank[x] < Rank[y]){
			Parent[x] = y;
			Weight[x] = z + Weight[sy] - Weight[sx];
		}else{
			Parent[y] = x;
			Weight[y] = - z - Weight[sy] + Weight[sx];
			if(Rank[x] == Rank[y]) ++Rank[x];
		}
		return true;
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}

	long long cost(int x, int y){ // call only if same(x, y) == true
		return Weight[x] - Weight[y];
	}
};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, q;
	cin >> n >> q;
	WeightedUnionFind wuf(n);
	for(int i=0; i<q; ++i){
		int t;
		cin >> t;
		if(t == 0){
			int x, y;
			long long z;
			cin >> x >> y >> z;
			wuf.unite(x, y, z);
		}else{
			int x, y;
			cin >> x >> y;
			if(wuf.same(x, y)) cout << wuf.cost(x, y) << "\n";
			else cout << "?\n";
		}
	}
}


Measured memory_bytes: 4428
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));

            return;
        }

        public void Solve(ConsoleInput cin)
        {

            var S = cin.ReadLine.ToCharArray();
            var T = cin.ReadLine.ToCharArray();

            int ans = 0;
            for(int i = 0; i < 3; i++)
            {
                if(S[i] == T[i])
                {
                    ans++;
                }
            }

            Console.WriteLine(ans);

        }
    }

    public static class Extensions
    {
        public static string Reverse(this string sourse)
        {
            char[] chrAry = sourse.ToCharArray();
            Array.Reverse(chrAry);
            return new string(chrAry);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}


Measured memory_bytes: 11220
// practice with Dukkha
#include <algorithm>
#include <iostream>

using namespace std;

const int N = 200000, MD = 998244353;

int ff[N], gg[N];

long long power(long long a, int k) {
	long long p = 1;
	while (k) {
		if (k & 1)
			p = p * a % MD;
		a = a * a % MD;
		k >>= 1;
	}
	return p;
}

void init(int n) {
	for (int f = 1, i = 0; i < n; i++) {
		gg[i] = power(ff[i] = f, MD - 2);
		f = (long long) f * (i + 1) % MD;
	}
}

long long ch(int n, int k) {
	return (long long) ff[n] * gg[k] % MD * gg[n - k] % MD;
}

int main() {
	int n, m, k; cin >> n >> m >> k;
	init(n);
	long long ans = 0;
	for (int h = 0; h <= k; h++)
		ans = (ans + ch(n - 1, h) * m % MD * power(m - 1, n - 1 - h)) % MD;
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define INF LLONG_MAX - 100
#define MOD 1000000007
#define fcout cout << fixed << setprecision(15)
#define int long long
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
#define lower_bound lowb
#define upper_bound upb
typedef long long ll;
typedef pair<char, int> P;
typedef priority_queue<int> pque;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a*b/gcd(a,b);};
int mod(int a,int b){return (a+b-1)/b;};
int month[12] = {31,28,31,30,31,30,31,31,30,31,30,31};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



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

	string s;
	cin >> s;
	int n = s.size();

	vector<P> v;
	int t = 1;
	REP(i, 1, n) {
		if(s[i] != s[i - 1]) {
			v.push_back(P(s[i - 1], t));
			t = 1;
		} else {
			t++;
		}
	}
	v.push_back(P(s[n - 1], t));

	int ans = 0;

	rep(i, v.size()) {
		if(v[i].first == 'O') {
			int now_size = v[i].second;
			if(v[i - 1].first == 'J' && v[i - 1].second >= now_size) {
				if(v[i + 1].first == 'I' && v[i + 1].second >= now_size) {
					chmax(ans, now_size);
				}
			}
		}
	}

	// rep(i, v.size()) {
	// 	cout << v[i].first << " " << v[i].second << endl;
	// }

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



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

using namespace std;

int main(){
    int h,w;
    char a[100][100];
    cin>>h>>w;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin>>a[i][j];
        }
    }
    int b;
    for(int i=0;i<h;i++){
        b=0;
        for(int j=0;j<w;j++){
            if(a[i][j]=='#'){
                b=1;
                break;
            }
        }
        if(b==0){
            for(int j=i+1;j<h;j++){
                for(int k=0;k<w;k++){
                    a[j-1][k]=a[j][k];
                }
            }
            h--;
            i--;
        }
    }
    for(int i=0;i<w;i++){
        b=0;
        for(int j=0;j<h;j++){
            if(a[j][i]=='#'){
                b=1;
                break;
            }
        }
        if(b==0){
            for(int j=i+1;j<w;j++){
                for(int k=0;k<h;k++){
                    a[k][j-1]=a[k][j];
                }
            }
            w--;
            i--;
        }
    }
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cout<<a[i][j];
        }
        cout<<"\n";
    }
}

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

int main() {
  int n, t, l, r, m, c;
  int a[100];
  while (1) {
    cin >> n;
    if (!n) break;
    for (int i=0; i<n; i++) {
      cin >> a[i];
    }
    cin >> t;
    l = 0;
    r = n-1;
    c = 0;
    while (l <= r) {
      m = (l + r) >> 1;
      ++c;
      if (a[m] > t) {
        r = m - 1;
      } else if (a[m] < t) {
        l = m + 1;
      } else {
        break;
      }
    }
    cout << c << endl;
  }
  return 0;
}

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

int main(){
   int N;
   int64_t K;
   cin>>N>>K;
   vector<int> A(N),F(N);
   for(int i=0;i<N;i++){
      cin>>A.at(i);
   }
   for(int i=0;i<N;i++){
      cin>>F.at(i);
   }

   sort(F.begin(),F.end());
   sort(A.begin(),A.end(),greater<int>());

   int64_t right=1000000000000;
   int64_t left=-1;
   int64_t x;
   int64_t count;
   while(left<right-1){
      x=(right+left)/2;
      count=0;
      for(int i=0;i<N;i++){
         count+=max(int64_t(0),A.at(i)-x/F.at(i));
      }
      if(count>K)
         left=x;
      else
         right=x;
   }
   cout<<right<<endl;
}

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};

int main(){
    string s;
    string key = "keyence";
    
    cin>>s;

    int befcnt=0,aftcnt=0;
    
    for(int i = 0; i < 7; i++)
    {
        if(s[i]==key[i])
        {
            befcnt++;
        }
        else
        {
            break;
        }
    }
    
    for(int i = 0; i < 7; i++)
    {
        if(s[s.length()-i-1]==key[6-i])
        {
            aftcnt++;
        }
        else
        {
            break;
        }
    }
    
    

    if(befcnt+aftcnt>=7)
    {
        cout<<"YES"<<endl;
    }
    else 
    {
        cout<<"NO"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = gets.chomp.to_i

jewelrys = gets.chomp.split.map(&:to_i)
costs = gets.chomp.split.map(&:to_i)

profits = 0
for i in 0..(n-1) do
  temp = jewelrys[i] - costs[i]
  if temp > 0
    profits = profits + jewelrys[i] - costs[i]
  end
end

print("#{profits}\n")

Measured memory_bytes: 1788
import java.util.*;

public class Main{

    int w,h;
    char[][] map;
    boolean B,W;
    int[] dx = {0,0,1,-1};
    int[] dy = {1,-1,0,0};
    int cnt;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            w = sc.nextInt();
            h = sc.nextInt();
            if(w==0 && h==0) break;

            map = new char[h][w];
            for(int i=0; i<h; i++){
                String line = sc.next();
                map[i] = line.toCharArray();
            }

            int bsum = 0, wsum = 0;
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    if(map[i][j]=='.'){
                        cnt = 0;
                        B = false;
                        W = false;
                        bfs(j,i);
                        if(B && !W) bsum += cnt;
                        if(!B && W) wsum += cnt;
                    }
                }
            }

            System.out.println(bsum+" "+wsum);
        }
    }

    void bfs(int sx, int sy){
        LinkedList<int[]> list = new LinkedList<int[]>();
        list.add(new int[]{sx,sy});
        boolean[][] v = new boolean[h][w];

        while(list.size()>0){
            int[] xy = list.poll();
            int x = xy[0], y = xy[1];

            if(v[y][x]) continue;
            v[y][x] = true;

            cnt++;
            map[y][x] = 'x';

            for(int i=0; i<4; i++){
                int nx = x+dx[i], ny = y+dy[i];
                if(nx<0 || nx>=w || ny<0 || ny>=h) continue;
                if(map[ny][nx]=='.') list.add(new int[]{nx,ny});
                else if(map[ny][nx]=='B') B = true;
                else if(map[ny][nx]=='W') W = true;
            }
        }
    }

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

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int n, w;
ll dp[100100];

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

    cin >> n >> w;
    for (int i = 1; i <= n; i++){
        int a, b;
        cin >> a >> b;
        for (int j = w-a; j >= 0; j--)
            dp[j+a] = max(dp[j+a], dp[j]+b);
    }
    ll ans = 0;
    for (int i = 0; i <= w; i++)
        ans = max(ans, dp[i]);
    cout << ans;

}


Measured memory_bytes: 1152
N = int(input())
Ws = [int(i) for i in input().split()]


ans = 100000000
for idx in range(1, N):
    si = sum(Ws[:idx])
    sj = sum(Ws[idx:])
    min_w = abs(si-sj)
    ans = min(ans, min_w)

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<math.h>
#include<vector>
#include<algorithm>
using namespace std;

/*class Dice
{
public:
	int men[7];

	void in(int i)
	{
		for (i; i < 7; i++)
		{
			cin >> men[i];
		}
	}

	void out(int i)
	{
		cout << men[1] << endl;

	}


};*/

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

	string EWSN;

	int men[7];
	/*Dice a, b, c;

	Dice *info;

	info = new Dice;

	info->in(1);*/

	int j = 0;

	for (int i = 1; i < 7; i++)
	{
		cin >> men[i];
	}

	cin >> EWSN;

	
	for (j = 0; j < EWSN.size();j++){

		if (EWSN[j] == 'E')
		{
			a = men[1];

			men[1] = men[4];

			men[4] = men[6];

			men[6] = men[3];

			men[3] = a;

		}
		else if (EWSN[j] == 'W')
		{
			a = men[1];

			men[1] = men[3];

			men[3] = men[6];

			men[6] = men[4];

			men[4] = a;
		}
		else if (EWSN[j] == 'S')
		{
			a = men[1];

			men[1] = men[5];

			men[5] = men[6];

			men[6] = men[2];

			men[2] = a;
		}
		else if (EWSN[j] == 'N')
		{
			a = men[1];

			men[1] = men[2];

			men[2] = men[6];

			men[6] = men[5];

			men[5] = a;
		}

	}


	/*info->out(1);

	delete info;*/

	cout << men[1] << endl;

	return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
using namespace std;
#define ll long long
#define rep(i, s, n) for(int i = s; i < n; i++)
//typedef pair<T, T> P;

int main() {
    int n;
    cin >> n;
    vector<int> a(n+1);
    rep(i, 1, n+1) cin >> a[i];
    vector<int> b(n+1, 0);
    int c = 0;
    for(int i = n; i > 0; i--) {
        int tmp = 0; // = a[i];
        int k = 1;
        while(i*k <= n) {
            tmp += b[i*k];
            //tmp %= 2;
            k++;
        }
        if(a[i] != tmp%2) {
            c++;
            b[i] = 1;
        }
    }

    cout << c << endl;
    rep(i, 1, n+1) {
        if(b[i] == 1) {
            cout << i << " ";
            //c++;
        }
    }
    //if(c == b.size()) cout << 0;
    cout << endl;
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second
#define setpre(x) cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , ";
    logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */


const lint mod = MOD9;
class mint{
    public:
        long long x;

    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint& operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};

mint dp[3005][3005][2];

int main(){
    int n, s; cin >> n >> s;
    rep(i, n){
        dp[i][0][0] = (i+1)*(i+2)/2 - i - 1;
        dp[i][0][1] = i+2;
    }

    rep(i, n){
        int a; cin >> a;
        if(i == 0){
            dp[0][a][0] = 1;
            dp[0][a][1] = 1;
        }
        else{
            repn(w, s){
                dp[i][w][0] = dp[i-1][w][0] + dp[i-1][w][1];
                dp[i][w][1] = dp[i-1][w][1];
                if(w >= a) dp[i][w][1] += dp[i-1][w-a][1];
            }
        }
    }

    out(dp[n-1][s][0] + dp[n-1][s][1]);
}

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

using namespace std;

#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template<class T>
void print(vector<T>& V, bool spaced = true) {
    string space;
    spaced ? space = " " : space = "";
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << space;
    }cout<< '\n';
}

template<class T>
void printendl(vector<T>& V) {
    for(int i = 0; i < V.size(); i++) {
        cout<< V[i] << '\n';
    }
}

template<class T>
T gcd(T a, T b) {
    T r;
    while (b != 0) {
        r = a % b;
        a = b;
        b = r;
    }
    return a;
}

template <class T>
T lcm (T a, T b) {
    return a / gcd(a, b) * b;
}

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

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

//str

bool isPalindrome(string str){
    
    int length = str.length();
 
    for (int i = 0; i < (length / 2); i++)
        if (str[i] != str[length - 1 - i])
            return false;
 
    return true;    
}

void reverseStr(string& str) 
{ 
    int n = str.length(); 
    for (int i = 0; i < n / 2; i++) 
        swap(str[i], str[n - i - 1]); 
}
 

//Read through the messages at the end when you're done

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);


    string s; cin>> s;
    int n = s.length();
    if(s[n-1] == '3') {
        cout << "bon" << '\n';
    }else if(s[n-1] == '0' || s[n-1] == '1' || s[n-1] == '6' || s[n-1] == '8') {
        cout << "pon" << '\n';
    }else {
        cout << "hon" << '\n';
    }

    
    

    return 0;
}

    //Use long long da5eel rabbak!
    //Dont use endl;
    //DONT SUBMIT IZA UR NOT SURE WALLAHI BTENDAM
    //Dear Amine, just because it worked for the test cases doesnt necessarily mean it is correct.
    //Dear Amine, try it on ur own test cases iza ur not SURE
    //In case u didnt use long long, CHECK FOR POTENTIAL OVERFLOWS
    //DONT FORGET TO MOD EVERYTHING IZA U NEED TO MOD



Measured memory_bytes: 3552