akhauriyash/Code-Regression huggingface dataset:
#include<cstdio>
#include<utility>
#include<algorithm>

using namespace std;

int A[2000];
int N;
int K;
int Q;

pair<int,int> Ap[2000];
int B[2000];
int C[2000];
int D[2000];

int main() {
    scanf("%d%d%d", &N, &K, &Q);
    for(int i = 0; i < N; ++i) {
        scanf("%d", A+i);
        Ap[i] = pair<int,int>(A[i],i);
    }

    sort(Ap, Ap+N);
    int min = Ap[Q-1].first-Ap[0].first;
    for(int p = 1; p < N-Q; ++p) {
        int t = 0;
        if(Ap[p].first == Ap[p-1].first) continue;
        int last = 0;
        int num = 0;
        for(int i = 0; i < N; ++i) {
            B[i] = A[i];
            C[i] = 1;
        }
        for(int i = 0; i < p; ++i) {
            C[Ap[i].second] = 0;
        }
        for(int i = 0; i < N; ++i) {
            if(C[i]) continue;
            if(i-last < K) {
                last = i+1;
                continue;
            }
            sort(B+last, B+i);
            for(int j = 0; j < i-last-K+1; ++j) {
                D[num++] = B[last+j];
            }
            last = i+1;
        }
        if(N-last >= K) {
            sort(B+last, B+N);
            for(int j = 0; j < N-last-K+1; ++j) {
                D[num++] = B[last+j];
            }
        }
        if(num < Q) continue;
        sort(D, D+num);
        if(min > D[Q-1]-D[0]) min = D[Q-1]-D[0];
    }

    printf("%d", min);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint a;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a;
	cout << a+a*a+a*a*a << endl;
	
	return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for (long long i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll MOD = 1000000007;
const ll INF = 10000000000000;
#define all(v) v.begin(), v.end()
 
int main(){
  string S;
  cin >> S;
  if(S=="RRR"){
    cout << 3 << endl;
  }else if(S=="RRS"||S=="SRR"){
    cout << 2 << endl;
  }else if(S=="SSS"){
    cout << 0 << endl;
  }else{
    cout << 1 << endl;
  }
}
  
  

Measured memory_bytes: 3624
def f;gets.split.map &:to_i;end
while(n=f.inject:+)>0
m=[2]*(n+1)
t=[]
(1..f[0]).map{i,j,k,r=f;r>0?(m[i]=m[j]=m[k]=1;t.push i,j,k;nil):[i,j,k]}.map{|l|l&&((a=l-t).size>1||m[a[0]]=0)}
puts m[1,n]end

Measured memory_bytes: 6144
g1 = [1, 3, 5, 7, 8, 10, 12]
g2 = [4, 6, 9, 11]
g3 = [2]
x, y = map(int, input().split())
if x in g1 and y in g1:
    print('Yes')
elif x in g2 and y in g2:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i ->
        let s1 = String.sub s 0 i in
        doit s1 (String.sub s (i + 1) (String.length s - String.length s1 - 1) :: acc)
  in doit str []

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; k] -> begin
      let a = Array.make n 0 in
      let rec read i =
        if i < n then (a.(i) <- (read_int ()); read (i + 1))
      in read 0;
      let rec check p =
        let rec doit i j s =
          if i = n then n
          else if j >= k then i
          else
            let x = s + a.(i) in
            if x > p then doit i (j + 1) 0
            else doit (i + 1) j x
        in doit 0 0 0
      and bin_search l r =
        if r < l then l
        else
          let m = (l + r) / 2 in
          if check m >= n then bin_search l (m - 1)
          else bin_search (m + 1) r
      in Printf.printf "%d\n" (bin_search 0 (100000 * 10000))
    end
  | _ -> exit 1

Measured memory_bytes: 5236
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>
#include<queue>
#include<stack>
#include<set>
#include<map>
using namespace std;
typedef long long LL;
const int maxn = 100000+5;
const LL mod = 1000000007;
const int MAXN = 20000+5;
const int MAXM = 50000+5;
const int INF = 0x3f3f3f3f;
struct Edge
{
    int to,next,cap,flow;
} edge[MAXM];
int tol;
int head[MAXN];
void init()
{
    tol = 0;
    memset(head,-1,sizeof(head));
}
void addedge(int u,int v,int w,int rw = 0)
{
    edge[tol].to = v;
    edge[tol].cap = w;
    edge[tol].flow = 0;
    edge[tol].next = head[u];
    head[u] = tol++;
    edge[tol].to = u;
    edge[tol].cap = rw;
    edge[tol].flow = 0;
    edge[tol].next = head[v];
    head[v] = tol++;
}
int Q[MAXN];
int dep[MAXN],cur[MAXN],sta[MAXN];
bool bfs(int s,int t,int n)
{
    int fr = 0,tail = 0;
    memset(dep,-1,sizeof(dep[0])*(n+1));
    dep[s] = 0;
    Q[tail++] = s;
    while(fr < tail)
    {
        int u = Q[fr++];
        for(int i = head[u]; i != -1; i = edge[i].next)
        {
            int v = edge[i].to;
            if(edge[i].cap > edge[i].flow && dep[v] == -1)
            {
                dep[v] = dep[u] + 1;
                if(v == t)return true;
                Q[tail++] = v;
            }
        }
    }
    return false;
}
LL dinic(int s,int t,int n)
{
    LL maxflow = 0;
    while(bfs(s,t,n))
    {
        for(int i = 0; i < n; i++)cur[i] = head[i];
        int u = s, tail = 0;
        while(cur[s] != -1)
        {
            if(u == t)
            {
                int tp = INF;
                for(int i = tail-1; i >= 0; i--)
                    tp = min(tp,edge[sta[i]].cap-edge[sta[i]].flow);
                maxflow += (LL)tp;
                for(int i = tail-1; i >= 0; i--)
                {
                    edge[sta[i]].flow += tp;
                    edge[sta[i]^1].flow -= tp;
                    if(edge[sta[i]].cap-edge[sta[i]].flow == 0)
                        tail = i;
                }
                u = edge[sta[tail]^1].to;
            }
            else if(cur[u] != -1 && edge[cur[u]].cap > edge[cur[u]].flow && dep[u] + 1 == dep[edge[cur[u]].to])
            {
                sta[tail++] = cur[u];
                u = edge[cur[u]].to;
            }
            else
            {
                while(u != s && cur[u] == -1)
                    u = edge[sta[--tail]^1].to;
                cur[u] = edge[cur[u]].next;
            }
        }
    }
    return maxflow;
}
int a[MAXN];
int main()
{

    init();
    int n;
    scanf("%d",&n);
    LL res=0;
    for (int i=1; i<=n; ++i) {
        scanf("%d",&a[i]);
        if(a[i]>0) {
            res+=(LL)a[i];
        }
    }
    int st=0;
    int ed=n+1;
    for(int i=1; i<=n; i++) {
        if(a[i]>0) {
            addedge(i,ed,a[i]);
        }
        if(a[i]<0) {
            addedge(st,i,-a[i]);
        }
        for (int j=i<<1; j<=n; j+=i) {
            addedge(i,j,INF);
        }
    }
    printf("%lld\n",res-dinic(st,ed,n+2));
    return 0;
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<climits>
using namespace std;
int main(){
  int n;
  int array[100005];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>array[i];
  }
  sort(array,array+n);
  
  int p=array[0];
  int minimum=INT_MAX;
  while(p<=array[n-1]){
    int sum=0;
    for(int i=0;i<n;i++){
      sum+=(array[i]-p)*(array[i]-p);
    }
    minimum=min(minimum,sum);
    p++;
  }
  cout<<minimum<<endl;
  return(0);
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc= new Scanner(System.in);

		while(true) {
			int H=sc.nextInt();
			int W=sc.nextInt();
			if(H==0&&W==0) break;
				for (int i=0;i<H;i++) {
					for(int j=0;j<W;j++) {
						System.out.print("#");
					}
					System.out.println();
				}					System.out.println();

			}
	}

}



Measured memory_bytes: 33776
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  n=pI(readline())
  """n<=x*108<n+1"""
  """n/108<=x<(n+1)/108"""
  x=cld(n,1.08)
  c=cld(n+1,1.08)
  if x==c
    println(":(")
  else
    println(Int(x))
  end
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

int main()
{
    char c;
    cin >> c;
    string ans[2] = {"vowel", "consonant"};
    cout << ans[!(c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o')] << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>){
	val cin = Scanner(System.`in`)
    val n = cin.nextInt()
    
    val arr = Array<Int>(n, { 0 })

    for (i in 2..n) {
        arr[cin.nextInt() - 1] += 1
    }

    for (i in 0..n-1) {
        println(arr[i])
    }
}

Measured memory_bytes: 61048
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int main(){
	int n,m;
	cin>>n>>m;
	unordered_map<int,int>arr;
	for(int i=0;i<m;i++){
		int temp;
		cin>>temp;
		arr[temp]++;
	}
	vector<int>dp(n+1,0);
	dp[0]=1;
	if(arr.find(1)==arr.end())
		dp[1]=1;
	for(int i=2;i<=n;i++){
		if(arr.find(i)==arr.end()){
			dp[i]=(dp[i-1]+dp[i-2])%mod;
		}
	}
	cout<<dp[n];
	return 0;
}

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

int ctoi(char c) {
    int n = c - '0';
    return n;
}

int pow_int(int x, int n) {
    if (n == 0) {
        return 1;
    }else {
        int y = x;
        for (int i = 0; i < n-1; i++) {
            x *= y;
        }
        return x;
    }
}


int main() {
    string n;
    cin >> n;
    bool flag = false;
    rep(i, 3) {
        if (n[i] == '7') flag = true;
    }
    if (flag) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
using namespace std;

long long s[100000];
long long t[100000];
long long x[100000];
int main(){
    int A;
    int B;
    int Q;
    cin >> A >> B >> Q;
    for(int i = 0; i < A; i++){
        cin >> s[i];
    }
    for(int i = 0; i < B; i++){
        cin >> t[i];
    }
    for(int i = 0; i < Q; i++){
        cin >> x[i];
    }

    for(int i = 0; i < Q; i++){
        auto it_s = lower_bound(s, s + A, x[i]);
        auto it_t = lower_bound(t, t + B, x[i]);
        long long s_prev_dist = (it_s == s ? LLONG_MAX / 4 : x[i] - *(it_s - 1));
        long long s_cur_dist = (it_s == s + A ? LLONG_MAX / 4 : *it_s - x[i]);
        long long t_prev_dist = (it_t == t ? LLONG_MAX / 4: x[i] - *(it_t - 1));
        long long t_cur_dist = (it_t == t + B ? LLONG_MAX / 4: *(it_t) - x[i]);
        //cout << s_prev_dist << " " << s_cur_dist << " " << t_prev_dist << " " << t_cur_dist << endl;

        cout << min(2 * s_prev_dist + t_cur_dist,
            min(s_prev_dist + 2 * t_cur_dist,
            min(2 * s_cur_dist + t_prev_dist,
            min(s_cur_dist + 2 * t_prev_dist, 
            min(max(s_prev_dist, t_prev_dist), max(s_cur_dist, t_cur_dist)))))) << endl;
    }
    return 0;
}


Measured memory_bytes: 3712
import math
import numpy as np
import itertools
import sys
N = int(input())

#Nをリストにした（int）
Nl = list(map(int, list(str(N))))

#Nの桁数
size = int(math.log10(N) + 1)

#答え
ans = 0

#3〜m-1桁まで
size_l = list(np.arange(3, size))
for m in size_l:
	c = 3**m - 3 * 2**m + 3 * 1**m
	ans += c
#ここまででm-1桁目まで数え上げてる

A = ['3','5','7']
l = list(itertools.product(A, repeat=size))
def tyo(x):
	if '3' in x and '5' in x and '7' in x:
		return x
	else:
		return ''
def aaa(x):
	ans = ''.join(x)
	if not ans == '':
		return ans
l = list(map(tyo, l))
l = list(map(aaa, l))
l = [item for item in l if item]
l = list(map(int, l))
l.sort()
l = [item for item in l if item <= N]
ans += len(l)
print(ans)


Measured memory_bytes: 15856
import java.io.*;
import java.util.*;

public class Main {

    public static void main(final String[] args) throws Exception {
        final Scanner sc = new Scanner(System.in);
        long L;
        L = sc.nextLong();

        final Solver solver = new Solver();
        solver.solve(L);
    }
}

class Solver {
    public void solve(long L) {
        double s = L / 3.0;
        System.out.println(String.format("%f", s * s * s));
    }
}



Measured memory_bytes: 21204
N,K = map(int,input().split())
series = list(map(int,input().split()))
onepoint=series.index(1)
start = max(0,onepoint-K+1)
end = min(len(series),onepoint+K)
#print("start=",start,"end=",end)
ans = 10**9
for p in range(start,end):
	tmp = 0
	back = p
	front = p + K
	#print("back=",-(-back // (K-1)))
	#print("front=",-(-(len(series)-front) // (K-1)))
	tmp += -(-back // (K-1)) #Round Up
	tmp += -(-(len(series)-front) // (K-1))
	#print("tmp=",tmp)
	if ans > tmp:
		ans = tmp

print(ans+1)

Measured memory_bytes: 13880
N = int(input())
done = [0] * N
button = [int(input()) for _ in range(N)]
done[0] = 1
i = 0
ans = 1
for _ in range(N):
  i = button[i] - 1
  if i == 1:
    print(ans)
    exit()
  if done[i] == 1:
    print(-1)
    exit()
  else:
    done[i] = 1
    ans += 1

Measured memory_bytes: 7852
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int a, b, c, d, k;

signed main() {
	cin >> a >> b >> c >> d >> k;
	int ans = max((int)0, (c - a) * 60 + (d - b) - k);
	cout << ans << endl;
}


Measured memory_bytes: 3632
import Control.Monad
import Data.Maybe
import qualified Data.ByteString.Char8 as BS
import Data.List
import qualified Data.Vector.Unboxed as VU
import qualified Data.Vector.Unboxed.Mutable as VUM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine

main = do
    n <- getInt
    cs <- VU.replicateM n $ do
            c <- getInt
            return $ c - 1
    let result = VU.create $ do
            vec <- VUM.replicate n (1 :: Int)
            color <- VUM.replicate 200001 (-1 :: Int)

            forM_ [0,1] $ \i -> do
                VUM.write color (cs VU.! i) i

            forM_ [2..n-1] $ \i -> do
                let ci = cs VU.! i
                j <- VUM.read color ci
                xj <- if j == -1 || j == i-1
                      then return 0
                      else VUM.read vec j
                xp <- VUM.read vec (i-1)
                VUM.write vec i $ (xj + xp) `mod` 1000000007
                VUM.write color ci i
            
            return vec
    print $ if n == 1 then 1 else result VU.! (n-1)

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

using namespace std;

void solve()
{
	int n;
	while(cin >> n, n)
	{
		vector<int> Vec(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		int ohajiki = 32;
		bool endFlag = false;
		int pos = 0;
		while(!endFlag)
		{
			ohajiki -= (ohajiki - 1) % 5;
			cout << ohajiki << endl;
			ohajiki -= Vec[pos];
			++pos;
			if(pos >= n)
			{
				pos = 0;
			}
			if(ohajiki <= 0)
			{
				endFlag = true;
				cout << 0 << endl;
				continue;
			}
			else
			{
				cout << ohajiki << endl;
			}
		}
	}
}

int main()
{
	solve();
	return(0);
}

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

int main()
{
    string s;
    cin >> s;

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

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

int main() {
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin>>a[i];

  int cnt = 0;
  int ans = 0;
  sort(a.begin(),a.end());
  while (cnt<n) {
    int cc = a[cnt];
    int f = 0;
    while (cnt<n&&a[cnt]==cc) f++, cnt++;
    ans += f%2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int p[100005],re[100005];
main()
{
    int t,r;
    scanf("%d%d",&t,&r);
    p[1]=1;
    for(int i = 1;i <= t;i++)
    {
        re[i]=1;
    }
    int s,e;
    for(int i = 0;i < r;i++)
    {
        scanf("%d%d",&s,&e);
        p[e]=max(p[e],p[s]);
        if(re[s]==1)
        {
            p[s]=0;
        }
        re[s]--;
        re[e]++;
    }
    int co=0;
    for(int i = 1;i <= t;i++)
    co+=p[i];
    printf("%d",co);
}


Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main() {
  int N;
  long long K;
  cin >> N >> K;
  vector<int> A(N+1);
  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  int p=1;
  long long time = 0;
  map<int, int> numset;//町番号, 最近通った時間
  numset[1] = 0;
  while(1){
    p = A[p];
    time++;
    if(time==K){
      break;
    }
    if(numset.count(p)){
      break;
    }else{
      numset[p] = time;
    }
    numset.at(p) = time;
  }
  if(time == K){
    cout << p << endl;
    return 0;
  }
  int loop = time - numset.at(p);
  K -= numset.at(p);
  K %= loop;
  if(K == 0){
    cout << p << endl;
    return 0;
  }
  time = 0;
  while(1){
    p = A[p];
    time++;
    if(time==K) break;
  }
  cout << p << endl;
  return 0;
}

Measured memory_bytes: 10952
r, c = gets.split.map(&:to_i)
m = []
r.times {m << gets.split.map(&:to_i)}
tate = Array.new(c, 0)
putout = ->(ar) {
  st = ""
  sum = 0
  ar.each_with_index do |x, i|
    st += x.to_s + " "
    sum += x
    tate[i] += x
  end
  st += sum.to_s
  puts st
}
m.each {|x| putout.(x)}
putout.(tate)


Measured memory_bytes: 7352
#include <bits/stdc++.h>
#include <cmath>
using namespace std;
#define _GLIBCXX_DEBUG
#define ll long long
#define rep(i,n) for (ll i = 0; i < n; i++)
#define vl vector<ll>
#define vpl vector<pair<ll,ll>>
#define vvl vector<vector<ll>> //a(縦行,vector<ll>(横列));
#include<algorithm>//__gcd(a,b)
#include <iostream>
#include <vector>
#include <cstdlib>
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const long long INF = 1LL << 60;

int main(){
ll n;cin>>n;
vl a(n);rep(i,n)cin>>a[i];
ll ans=0;

for(ll i=1;i<n;i++){
    if(a[i]<a[i-1]){
ans+=a[i-1]-a[i];
a[i]=a[i-1];
    }
}


cout<<ans<<endl;
}

Measured memory_bytes: 4764
object Main {
  val dir = List((-1, 0), (0, 1), (1, 0), (0, -1))

  def inCheck(w: Int, h: Int, y: Int, x: Int) = {
    0 <= y && y < h && 0 <= x && x < w
  }

  def solve(w: Int, h: Int, tiles: List[String]): Int = {
    var sx, sy = 0
    tiles.zipWithIndex.foreach(t => 
      for(x <- 0 until w) {
        if(t._1(x) == '@') {
          sx = x; sy = t._2
        }
      })
    val used = Array.fill[Boolean](h, w)(false)
    val queue = new scala.collection.mutable.Queue[List[Int]]
    queue += List(sy, sx)
    var count = 1
    while(queue.size != 0) {
      val pos = queue.dequeue
      for(d <- dir) {
        val my = pos(0) + d._1
        val mx = pos(1) + d._2
        if(inCheck(w, h, my, mx) && tiles(my)(mx) == '.' && !used(my)(mx)) {
          used(my)(mx) = true
          count += 1
          queue += List(my, mx)
        }
      }
    }
    count
  }

  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    var w, h = sc.nextInt
    while(h != 0 || w != 0) {
      val tiles = for(_ <- 1 to h) yield sc.next
      println(solve(w, h, tiles.toList))
      w = sc.nextInt; h = sc.nextInt
    }
  }
}

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

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

  if(b == 100){
    for(int i = 1; i < 317; i++){
      if(a * 1000 + b == i * i){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  else if(0 < b && b < 10){
    for(int i = 1; i < 317; i++){
      if(a * 10 + b == i * i){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  else if(9 < b && b < 100){
    for(int i = 1; i < 317; i++){
      if(a * 100 + b == i * i){
        cout << "Yes" << endl;
        return 0;
      }
    }
  }

  cout << "No" << endl;

}


Measured memory_bytes: 256
// In the name of Allah the Lord of the Worlds.

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

typedef long long ll;

bool cmp(pair<ll , ll > A , pair<ll , ll > B)
{
    return A.second > B.second;
}
int main(void)
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);

    int n , m;
    cin >> n >> m;
    vector<pair<ll , ll > > v;

    for(int i=0;i<n;i++){
        ll in1 , in2;
        cin >> in1 >> in2;
        v.push_back({in1 , in2});
    }
    sort(v.begin() , v.end() , cmp);
    set<int>st;
    for(int i=1;i<=m;i++){
        st.insert(i);
    }
    ll now = 0 , ans = 0;
    for(int i=0;i<v.size();i++){
        auto it = st.upper_bound(v[i].first-1);
        if(it==st.end())continue;
        ans+=v[i].second;
        st.erase(it);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6512
#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<vector>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define li long long
#define gc getchar()
#define pc putchar
li read(){
	li x = 0,y = 0,c = gc;
	while(!isdigit(c)){y = c;c = gc;}
	while(isdigit(c)){x = (x << 1) + (x << 3) + (c ^ '0');c = gc;}
	return y == '-' ? -x : x;
}
void print(li x){
	if(x < 0){pc('-');x = -x;}
	if(x >= 10) print(x / 10);
	pc(x % 10 + '0');
}
void file(){freopen(".in","r",stdin);freopen(".out","w",stdout);}
int n,m,a[300010],b[300010],c[300010],d[300010],e[300010];
int bt[300010];

int main(){
	//file();
	int i,j,k;
	n = read(); m = 1 << n;
	for(i = 0;i < m;++i) a[i] = read(),c[i] = i,d[i] = a[i];
	for(i = 1;i < m;++i) bt[i] = bt[i >> 1] + (i & 1);
	for(i = 1;i < m;i <<= 1){
		for(j = 0;j < m;++j) if(!(i & j)){
			if(d[i ^ j] < d[j]){
				d[i ^ j] = d[j];
				c[i ^ j] = c[j];
			}	
		} 
	}
	for(i = 0;i < m;++i) if(i != c[i]) e[i] = a[i];
	for(i = 1;i < m;i <<= 1){
		for(j = 0;j < m;++j) if(!(i & j)){
			e[i ^ j] = max(e[i ^ j],e[j]);
			if(c[i ^ j] != c[j]) e[i ^ j] = max(e[i ^ j],a[c[j]]);
		}
	}
	for(i = 0;i < m;++i) b[i] = d[i] + e[i];
	//for(i = 0;i < m;++i) cerr<<d[i]<<" ";cerr<<endl;
	//for(i = 0;i < m;++i) cerr<<c[i]<<" ";cerr<<endl;
	//for(i = 0;i < m;++i) cerr<<e[i]<<" ";cerr<<endl;
	/*for(i = 0;i < m;++i){
		for(j = i;j;j = j - 1 & i){
			//cerr<<i<<" "<<j<<" "<<(i ^ j)<<endl;
			b[i] = max(b[i],a[j] + d[i ^ j]);
		}
	}*/
	for(i = 1;i < m;++i){
		b[i] = max(b[i],b[i - 1]);
		print(b[i]);pc('\n');
	}
	return 0;
}


Measured memory_bytes: 9856
#A
"""
n, a, b = map(int, input().split())
ab = n / 2
ansa = min(a, b)
ansb = max((a+b)-n, 0)
print(ansa,ansb)
"""

#B
n = int(input())
a = input()
b = input()
c = input()
ans = 0
for i in range(n):
    bf = [a[i], b[i], c[i]]
    bf = set(bf)
    ans += len(bf) - 1
print(ans)

Measured memory_bytes: 38384
package main

import "fmt"

func main() {
	easy := true
	var S string
	fmt.Scan(&S)
	for i := 0; i < len(S); i++ {
		if i%2 == 0 {
			if S[i:i+1] == "L" {
				easy = false
				break
			}
		} else {
			if S[i:i+1] == "R" {
				easy = false
				break
			}
		}
	}
	if easy {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  string a, b, c;
  cin >> a >> b >> c;

  if (a.back() == b[0] && b.back() == c[0]) {
    COUT("YES");
  } else {
    COUT("NO");
  }
  return 0;
}

Measured memory_bytes: 3644
N, K = map(int, input().split())
p = list(map(int, input().split()))

p_K = []
p_K.append(sum(p[0:K]))

for i in range(N-K):
    p_K.append(p_K[i] - p[i] + p[i+K])

print((max(p_K) + (K)) / 2)

Measured memory_bytes: 25060
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <numeric>
#include <algorithm>
#include <functional>

using namespace std;

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

	int X, Y;
	cin >> X >> Y;

	if (X % Y == 0)
	{
		cout << -1;
	}
	else
	{
		cout << X;
	}

	return 0;
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
int main()
{
	int a[3]={0},b,c;
	cin>>b>>c;
	a[b-1]++;
	a[c-1]++;
	for(int i=0;i<3;i++)
	if(a[i]==0)
	cout<<i+1;
} 

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

int main() {
    int N, M; cin >> N >> M;
    int mul = 1;
    for (int i = 0; i < M; i++) mul *= 2;
    int X = 100 * (N - M) * mul + 1900 * M *  mul;
    cout << X << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;
typedef long long  ll;

const int N = 100010;
int a[N], b[N];
map<pair<int, int> , int> myhash;
int ans;


int main() {
	char ch;
	for (int i = 1; i <= 12; i++) {
		cin>>ch;
		cout<<ch;
		if (i == 4) cout<<' ';
	}
	cout<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define sqr(x) ((x)*(x))
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define ld long double
#define vi vector<int>
#define all(a) a.begin(),a.end()
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > > 
#define pii pair<int,int> 
#define pb push_back
#define mp make_pair
#define debuge cerr<<"isok"<<endl
#define debug(x) cerr<<#x<<"="<<x<<endl
#define dprintf(...) fprintf(stderr,__VA_ARGS__)
#define SS second
#define FF first
#define ls (k<<1)
#define rs (k<<1|1)
#define clr(a,x) memset(a,x,sizeof(a))
#define cpy(a,x) memcpy(a,x,sizeof(a))
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#define SZ(x) ((int)x.size())
using namespace std;
template<class T> inline void gmin(T &x,const T &y){x=x>y?y:x;}
template<class T> inline void gmax(T &x,const T &y){x=x<y?y:x;}
template<class T> inline bool Gmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T> inline bool Gmax(T &x,const T &y){return x<y?x=y,1:0;}
const int BufferSize=1<<16;
char buffer[BufferSize],*Bufferhead,*Buffertail;
bool Terminal;
inline char Getchar(){
	if(Bufferhead==Buffertail){
		int l=fread(buffer,1,BufferSize,stdin);
		if(!l){Terminal=1;return 0;}
		Buffertail=(Bufferhead=buffer)+l;
	}
	return *Bufferhead++;
}
template<class T>inline bool read(T &x){
	x=0;char c=Getchar(),rev=0;
	while(c<'0'||c>'9'){rev|=c=='-';c=Getchar();if(Terminal)return 0;}
	while(c>='0'&&c<='9') x=x*10+c-'0',c=Getchar();
	if(c=='.'){
		c=Getchar();double t=0.1;
		while(c>='0'&&c<='9') x=x+(c-'0')*t,c=Getchar(),t=t/10;
	}
	x=rev?-x:x;
	return 1;
}
template<class T1,class T2> inline bool read(T1 &x,T2 &y){return read(x)&read(y);}
template<class T1,class T2,class T3> inline bool read(T1 &x,T2 &y,T3 &z){return read(x)&read(y)&read(z);}
template<class T1,class T2,class T3,class T4> inline bool read(T1 &x,T2 &y,T3 &z,T4 &w){return read(x)&read(y)&read(z)&read(w);}
inline bool reads(char *x){
	char c=Getchar();
	while(c<33||c>126){c=Getchar();if(Terminal)return 0;}
	while(c>=33&&c<=126) (*x++)=c,c=Getchar();
	*x=0;return 1;
}
template<class T>inline void print(T x,const char c='\n'){
	if(!x){putchar('0');putchar(c);return;}
	if(x<0) putchar('-'),x=-x;
	int m=0,a[20];
	while(x) a[m++]=x%10,x/=10;
	while(m--) putchar(a[m]+'0');
	putchar(c);
}
//--------------------------------head---------------------------------------------

const int inf=0x3f3f3f3f;
const int N=200005,M=100005,mod=1e9+7;
template<class T,class S> inline void ch(T &x,const S y){x=(x+y)%mod;}
inline int exp(int x,int y,const int mod=::mod){
	int ans=1;
	while(y){
		if(y&1) ans=(ll)ans*x%mod;
		x=(ll)x*x%mod;y>>=1;
	}return ans;
}

int k,a[N];

int main(){
#ifdef rqgao2014
	assert(freopen("input.txt","r",stdin));
#endif
	scanf("%d",&k);
	for(int i=1;i<=k;i++)
		scanf("%d",&a[i]);
	ll l=2,r=2;
	for(int i=k;i;i--){
		ll L=(l+a[i]-1)/a[i]*a[i],R=r/a[i]*a[i];
		if(L>r||R<l){puts("-1");return 0;}
		if(L>R){puts("-1");return 0;}
		l=L;r=R+a[i]-1;
	}
	cout<<l<<" "<<r<<endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
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; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k; cin >> n >> k;
    vll a(n), f(n);
    for (ll i = 0; i < n; i++) cin >> a[i];
    for (ll i = 0; i < n; i++) cin >> f[i];
    sort(ALL(a));
    sort(ALL(f));
    reverse(ALL(f));
    ll low = 0, high = HIGHINF;
    while (low < high) {
        ll mid = (low + high) >> 1;
        ll tmpk = 0;
        for (ll i = 0; i < n; i++) {
            ll cost = a[i] * f[i];
            if (cost <= mid) continue;
            else tmpk += (cost - mid + f[i] - 1) / f[i];
        }

        if (tmpk > k) low = mid + 1;
        else high = mid;
    }

    cout << low << '\n';
    return 0;
}


Measured memory_bytes: 3328
#include <cstdio>

using namespace std;

int main() {
  long long N, M;
  scanf("%lld %lld", &N, &M);
  if (N >= M/2) {
    printf("%lld", M/2);
  } else {
    long long ans = N;
    M -= 2*N;
    ans += M/4;
    printf("%lld", ans);
  }
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n, k;
    cin >> n >> k;
    vint c(n, 0);
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int a;
            cin >> a;
            --a;
            c[a]++;
        }
    }

    int ans = 0;
    rep(i, n) if (c[i]==0) ans++;

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

Measured memory_bytes: 3588
using System;

namespace AOJ.Volume0
{
    public class SquareSearching
    {
        public static void Main()
        {
            while (true)
            {
                int size = int.Parse(Console.ReadLine());
                if (size == 0) { break; }

                var map = new int[size, size];
                for (int i = 0; i < size; i++)
                {
                    string line = Console.ReadLine();
                    for (int j = 0; j < size; j++) { map[i, j] = line.Substring(j, 1) == "." ? 1 : 0; }
                }

                int answer = 0;
                for (int i = 1; i < size; i++)
                {
                    for (int j = 1; j < size; j++)
                    {
                        if (map[i, j] != 0)
                        {
                            map[i, j] = Math.Min(map[i - 1, j - 1], Math.Min(map[i - 1, j], map[i, j - 1])) + 1;
                            answer = Math.Max(answer, map[i, j]);
                        }
                    }
                }
                Console.WriteLine(answer);
            }
        }
    }
}

Measured memory_bytes: 22536
import sys
sys.setrecursionlimit(500*500) # default 1000

class neighborList():
    def __init__(self,N):
        self.to=[[] for j in range(N)] # N points

def calcDist(v_,p=-1,dist=0): # vertices & parent idx
    distList[v_]=dist
    lst=neighborList.to[v_] # children list
    for child in lst:
        if child==p:
            continue
        calcDist(child,v_,dist+1)
    return distList

# input
N, u, v = map(int, input().strip().split()) # t,a
u-=1
v-=1
neighborList = neighborList(N)
for i in range(N-1):
    A, B = map(int, input().strip().split())
    A-=1 # start from 0
    B-=1
    neighborList.to[A].append(B)
    neighborList.to[B].append(A)

distList=[0]*N
distT = calcDist(u)
distList=[0]*N
distA = calcDist(v)

mx=0
for i in range(N):
    if distT[i] < distA[i]:
        mx=max(mx,distA[i])
print(mx-1)

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

using namespace std;

typedef long long ll;

int N;
string s;

int main(){
    cin >> N;
    cin >> s;
    int ans = 1;
    char c = s[0];
    for(int i=1;i<N;i++){
        if(c == s[i]) continue;
        c = s[i];
        ans++;
    }
    cout << ans << endl;
    return 0;
}

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

typedef unsigned long long int LL;

int n;
vector<int> a;

LL solve() {
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int t;
	while (cin >> n) {
		a = vector<int>(n + 1, 0);
		for (int i = 0; i < n - 1; i++) {
			cin >> t;
			a[t]++;
		}
		for (int i = 1; i <= n; i++)
			cout << a[i] << endl;
		a.clear();
	}
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b) {
  if(a%b==0) {
    return(b);}
  else {
    return(gcd(b,a%b));}
  }
int main() {
  int k;
  cin >> k;
  int sum=0;
  for(int h=0;h<k;h++){
    for(int i=0;i<k;i++){
      for(int j=0;j<k;j++){
        sum+=gcd(gcd(h+1,i+1),j+1);
        }}}
  cout << sum << endl;
  return 0;
  }
    
    

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define int long long
using namespace std;

//typedef
//------------------------------------------
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VP;


//REPEAT
//------------------------------------------
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define RFOR(i, m, n) for(int i = m;i > n;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,m)  RFOR(i,m,0)

//container util
//------------------------------------------
#define pb(a) push_back(a)
#define fst first
#define snd second
#define SORT(V) sort((V).begin(),(V).end())
#define REV(V) reverse((V).begin(),(V).end())

//constant
//------------------------------------------
const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

//grobal variable
//------------------------------------------

//def function, class
//------------------------------------------

//main
//------------------------------------------
signed main(){
  int N;
  cin >> N;
  VI W(N);
  REP(i, N) cin >> W.at(i);

  int ans=INF;

  REP(T, N){
    int S1=0, S2=0;
    REP(i, T) S1+=W.at(i);
    FOR(i, T, N) S2+=W.at(i);
    ans = min(ans, abs(S1-S2));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ITP1_11_A
{
    class Dice
    {
        int[] surface;
        

        public Dice(int[] x) { surface = x; }

        public void turn(char vct)
        {
            int[] sub = new int[6];

            for (int i = 0; i < 6; i++)
                sub[i] = surface[i];

            switch (vct)
            {
                case 'S':
                    surface[0] = sub[4];
                    surface[1] = sub[0];
                    surface[5] = sub[1];
                    surface[4] = sub[5];
                    break;
                case 'N':
                    surface[0] = sub[1];
                    surface[1] = sub[5];
                    surface[5] = sub[4];
                    surface[4] = sub[0];
                    break;
                case 'W':
                    surface[0] = sub[2];
                    surface[2] = sub[5];
                    surface[5] = sub[3];
                    surface[3] = sub[0];
                    break;
                case 'E':
                    surface[0] = sub[3];
                    surface[2] = sub[0];
                    surface[5] = sub[2];
                    surface[3] = sub[5];
                    break;
                default:
                    break;                    
            }
          /*foreach (var s in surface)
                Console.Write(" " + s);
            Console.WriteLine();*/            
        }
        public void showTop() { Console.WriteLine(surface[0]); }
    }


    class Program
    {
        static void Main(string[] args)
        {
            string input = Console.ReadLine();
            string order = Console.ReadLine();

            Dice d = new Dice(input.Split(' ').Select(x => Convert.ToInt32(x)).ToArray());

            foreach (var o in order)
                d.turn(o);

            d.showTop();
        }
    }
}

Measured memory_bytes: 9628
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

const int MAX = 2e5 + 1;

int dpl[MAX];
int dpr[MAX];

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

	int N, K, C;
	cin >> N >> K >> C;

	string str;
	cin >> str;

	dpl[0] = 0;
	int last_l = -1e6;
	for (int i = 1; i <= N; i++)
	{
		if (str[i - 1] == 'o' && last_l + C < i)
		{
			last_l = i;
			dpl[i] = dpl[i - 1] + 1;
		}
		else
		{
			dpl[i] = dpl[i - 1];
		}
	}

	dpr[N] = 0;
	int last_r = 1e6;
	for (int i = N; i >= 1; i--)
	{
		if (str[i - 1] == 'o' && last_r - C > i)
		{
			last_r = i;
			dpr[i - 1] = dpr[i] + 1;
		}
		else
		{
			dpr[i - 1] = dpr[i];
		}
	}

	for (int i = 0; i < N; i++)
	{
		if (str[i] == 'o' && dpl[i] + dpr[i + 1] == K - 1)
		{
			cout << i + 1 << "\n";
		}
	}

	return 0;
}


Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
const int INF = 1e9;
typedef long long ll;

int r,g,b,n,t;
int main(){
    cin >> r >> g >> b >> n;
    ll ans = 0;
    REP(i,n+1) REP(j,n+1){
        t = n - r*i - g*j;
        if(t >= 0 && t % b == 0) ++ans;
    }

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)

int main() {
    // your code goes here
    ll a,b,c;
    cin >> a >> b >> c;
    if(a+b>=c) cout << "No" << endl;
    else if((c-b-a)*(c-b-a)>4*a*b) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

int main(){
    ll X, Y, Z, K, A[1000], B[1000], C[1000];
    cin >> X >> Y >> Z >> K;
    for(int i=0;i<X;i++)
        cin >> A[i];
    for(int i=0;i<Y;i++)
        cin >> B[i];
    for(int i=0;i<Z;i++)
        cin >> C[i];
    
    // 降順ソート
    sort(A, A + X, greater<ll>());
    sort(B, B + Y, greater<ll>());
    sort(C, C + Z, greater<ll>());
    vector<ll> ans;
    for(int i=0;i<X;i++){
        for(int j=0;j<Y;j++){
            for(int k=0;k<Z;k++){
                if((i+1)*(j+1)*(k+1) <= K)
                    ans.push_back(A[i] + B[j] + C[k]);
                else
                    break;                
            }
        }
    }

    // 降順ソート
    sort(ans.begin(), ans.end(), greater<ll>());
    for(int i=0;i<K;i++)
        cout << ans[i] << endl;

}

Measured memory_bytes: 1400
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <queue>
typedef long long ll;
#define rep(i,n) for(int i = 0;i<n;++i)
#define repc(bit,k,n) for (int bit = (1<<k)-1;bit < (1<<n); bit = next_combination(bit))
#define repi(itr,vec) for(auto itr = vec.begin();itr!=vec.end();++itr)
using namespace std;
using Graph = vector<vector<int> >;

/* next combination
 * usage:repc(bit,k,n)
 * */
int next_combination(int sub) {
  int x = sub & -sub, y = sub + x;
  return (((sub & ~y) / x) >> 1) | y;
}

/* uniq
 * usage:uniq(vec)
 * */
void uniq(vector<int> &vec){
  sort(vec.begin(), vec.end());
  vec.erase(unique(vec.begin(), vec.end()), vec.end());
  return;
}

/* BinaryIndexedTree
 * usage:update and sum of 1~N
 * */
int N;
int bit[1000010];
void add(int a, int w) {
  for (int x = a; x <= N; x += x & -x) bit[x] += w;
}
int sum(int a) {
  int ret = 0;
  for (int x = a; x > 0; x -= x & -x) ret += bit[x];
  return ret;
}

int main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
  int n;cin>>n;
  vector<vector<vector<int> > >point;
  rep(i,n){
    int a,b;cin>>a>>b;
    point.push_back({{0},{a,b}});
  }
  rep(i,n){
    int a,b;cin>>a>>b;
    point.push_back({{1},{a,b}});
  }
  sort(point.begin(),point.end(),[](const vector<vector<int> >& a,const vector<vector<int> >& b){return a[1][0]<b[1][0];});
  int ans = 0;
  for(int i = 1;i<point.size();i++){
    if(point[i][0][0]!=1)continue;
    int cur = point[i][1][1];
    vector<vector<int> > temp;
    for(int j = i-1;j>=0;j--){
      if(point[j][0][0]!=0)continue;
      if(cur <= point[j][1][1])continue;
      temp.push_back({point[j][1][1],j});
    }
    if(!temp.empty()){
      sort(temp.begin(),temp.end());
      point[temp.back()[1]][0] = {2};
      ans++;
    }
  }

  cout << ans<<'\n';

        return 0;
}

Measured memory_bytes: 3588
#include<stdio.h>
#define n 8
void move(int);
void print();
int col[8],row[8],left[15],right[15],A[n][n];

int main(){
    int i,j,k,r,c;
    for(i=0;i<n;i++){
        row[i]=-1;
        col[i]=-1;
    }
    for(i=0;i<2*n-1;i++){
        left[i]=-1;
        right[i]=-1;
    }

    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            A[i][j]=-1;
        }
    }

    scanf("%d",&k);
    for(i=0;i<k;i++){
        scanf("%d%d",&r ,&c);
        A[r][c]=1;
    }
    move(0);
    return 0;
}
void move(int i){
    int j;
    if(i==n){
        print();
        return;
    }

    for(j=0; j<n;j++){
        if( left[i-j+n-1]==1 || right[i+j]==1 || col[j]==1)continue;
        row[i]=j;
        col[j]=right[i+j]=left[i-j+n-1]=1;
        move(i+1);
        row[i]=col[j]=right[i+j]=left[i-j+n-1]=-1;


    }
}
void print(){
    int i,j;
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(A[i][j]==1){
                if(row[i]!=j)return;
            }
        }
    }
    for(i=0;i<n;i++){
        for(j=0;j<n;j++){
            if(row[i]==j)printf("Q");
            else printf(".");
        }
        printf("\n");

    }

}


Measured memory_bytes: 2148