akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define REP(i, a, b) for (int i = (a), i##_end_ = (b); i < i##_end_; ++i)
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define mp make_pair
#define x first
#define y second
#define pb push_back
#define SZ(x) (int((x).size()))
#define ALL(x) (x).begin(), (x).end()

template<typename T> inline bool chkmin(T &a, const T &b) { return b < a ? a = b, 1 : 0; }
template<typename T> inline bool chkmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }

typedef long long LL;

const int oo = 0x3f3f3f3f;

const int maxn = 200100;

int n;
char s[maxn + 5];

map<int, int> Min;

int main()
{
#ifdef matthew99
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	scanf("%s", s);
	n = strlen(s);
	int tmp = 0;
	Min[0] = 0;
	REP(i, 0, n)
	{
		tmp ^= 1 << (s[i] - 'a');
		int ans = oo;
		if (Min.count(tmp)) ans = Min[tmp];
		REP(j, 0, 26) if (Min.count(tmp ^ (1 << j))) chkmin(ans, Min[tmp ^ (1 << j)]);
		if (!Min.count(tmp)) Min[tmp] = ans + 1;
		else chkmin(Min[tmp], ans + 1);
		if (i == n - 1) printf("%d\n", ans + 1);
	}
	return 0;
}


Measured memory_bytes: 9856
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 99999999999ll
#define MIN -99999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(a) cout<<a<<endl
#define putout2(a,b) putout(a);putout(b)
#define putout3(a,b,c) putout(a);putout(b);putout(c)
#define putout4(a,b,c,d) putout(a);putout(b);putout(c);putout(d)
#define putout5(a,b,c,d,e) putout(a);putout(b);putout(c);putout(d);putout(e)
#define Gput(a,b) G[a].push_back(b)
#define cin1(a) cin>>a
#define cin2(a,b) cin>>a>>b
#define cin3(a,b,c) cin>>a>>b>>c
#define cin4(a,b,c,d) cin>>a>>b>>c>>d
#define cin5(a,b,c,d,e) cin>>a>>b>>c>>d>>e
#define sum(v) accumulate(all(v), 0ll)
#define gcd(x,y) __gcd(x,y)
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*y/z;
}
int main() {
cout << fixed << setprecision(30);
  ll a,b,c,d;
  cin4(a,b,c,d);
  if(d==1)putout(1);
  else putout(0);
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#define N (1000000000+7)
using namespace std;
typedef long long ll;
typedef pair<int,ll> P;

ll to[200010];
bool visited[200010];

int main(void){
    ll n,k;
    cin>>n>>k;
    for(ll i=1;i<=n;i++){
        ll a;
        cin>>a;
        to[i]=a;
    }
    ll now = 1;
    vector<ll>vis;
    ll rops = -1;
    while(true){
        if(visited[now]){
            rops = now;
            break;
        }
        visited[now] = true;
        vis.push_back(now);
        now = to[now];
    }
    int index = 0;
    for(index=0;index<vis.size();++index){
        if(k==0){
            cout<<vis[index]<<endl;
            return 0;
        }
        if(rops == vis[index])break;
        else {
            k--;
        }
    }
    map<ll,ll>m;
    ll in = 0;
    for(;index<vis.size();++index){
        //cout<<in<<" "<<vis[index]<<endl;
        m[in]=vis[index];
        in++;
    }
    cout<<m[k%in]<<endl;
    return 0;
}

Measured memory_bytes: 16184
#include<iostream>
#include<fstream>
#include<iomanip>
#include<cstdio>
#include<string>
#include<cstring>
#include<climits>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#include<list>
#include<unordered_map>
#include<random>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define vii vector<int>
#define vll vector<ll>
#define lb lower_bound
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) v.erase(unique(v.begin(),v.end()),v.end())
// #define int ll
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
const ll mod = 998244353;
const ll MAX = 1100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1};


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    ll a[10],cnt=0;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    cnt+=(a[2]-a[0])/2;
    cnt+=(a[2]-a[1])/2;
    a[0]+=(a[2]-a[0])/2*2;
    a[1]+=(a[2]-a[1])/2*2;
    sort(a,a+3);
    if(a[0]==a[1]&&a[1]==a[2]) cout<<cnt<<endl;
    else if(a[0]==a[1]) cout<<cnt+1<<endl;
    else cout<<cnt+2<<endl;
    return 0;
}


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

using namespace std;

int main(){
    string s;
    bool flag = true,flag1 = true,flag2= true;

    cin>>s;
    for (int i = 0; i < (int)s.size()/2; i++)
    {
        if(s[i] == s[s.size()-i-1]) continue;
        else{
            flag = false;
            break;
        }
    }
    for (int i = 0, j = (int) s.size()/2 -1; i < (int)s.size()/2 && j >= 0; i++, j--)
    {
        if(s[i] == s[j]) continue;
        else{
            flag1 = false;
            break;
        }
    }
    for (int i = (int)(s.size()+1)/2, j = s.size()-1; i < (int)s.size() && j >=(int)(s.size()+1)/2; i++,j--)
    {
        if(s[i] == s[j]) continue;
        else{
            flag2 = false;
            break;
        }
    }
    
    if(flag && flag1 && flag2){
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    
    return 0;

}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#include <unordered_map>
//#include"testlib.h"
#define endl "\n"
#define all(v) v.begin(),v.end()
#define allr(s) s.rbegin(),s.rend()
#define RT(s) return cout<<s,0
#define watch(x) cout << (#x)<<" = "<<x<<endl
#define sz(s)    (int)(s.size())
#define PI acos(-1)
#define EPS 1e-100
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
int dy[] = { 1, -1, 0, 0, -1, 1, 1, -1 };
int dx[] = { 0, 0, 1, -1, 1, -1, 1, -1 };
void file() {
#ifndef ONLINE_JUDGE
	freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
#else
	//freopen("street.in", "r", stdin);
	//freopen("out.txt", "w", stdout);
#endif
}
void fast() {
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
}
ll gcd(ll x, ll y) {
	if (!y)return abs(x);
	return gcd(abs(y), abs(x % y));
}
const  int N = 2e5 + 9;
ll mem[N][5];
int n, mx;
vi v1;
ll solve(int idx, int rem) {
	if (idx >= n) {
		if (rem) return 0;
		return -1e16;
	}
	ll& ret = mem[idx][rem];
	if (ret != -1) return ret;
	ret = v1[idx];
	if (n - idx - 1 == rem)
		return ret;
	ret += solve(idx + 2, rem);
	if (rem)
		ret = max(ret, v1[idx] + solve(idx + 3, rem - 1));
	if (rem == 2)
		ret = max(ret, v1[idx] + solve(idx + 4, 0));
	return ret;
}
int main() {
//	file();
	fast();
	memset(mem, -1, sizeof mem);
	cin >> n;
	v1 = vi(n);
	for (auto& it : v1) cin >> it;
	if (n & 1) mx = 2;
	else mx = 1;
	//watch(solve(0, mx));
	ll ans = max(solve(0, mx), solve(1, mx - 1));
	if (n & 1)
		ans = max(ans, solve(2, mx - 2));
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 19528
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+2;
string s[105];
int main()
{
    ft
    int t,i,j,n,m,l,r,z;
    cin>>n>>m;
    for(i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(i=0;i<=n+1;i++)
    {
        if(i==0 || i==n+1)
        {
            for(j=0;j<=m+1;j++)
            {
                cout<<"#";
            }
        }
        else
        {
            cout<<"#"<<s[i]<<"#";
        }
        cout<<"\n";
    }
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
int main()
{
    ll n, k, r, s, p;
    cin >> n >> k >> r >> s >> p;
    string t;
    cin >> t;
    map<char, ll> mp;
    mp['r'] = p;
    mp['s'] = r;
    mp['p'] = s;
    ll ans = 0;
    if (k == 1)
    {
        ll tt = 1;
        rp(i, 0, n - 1)
        {
            if (t[i] == t[i + 1])
            {
                tt++;
            }
            else
            {
                ans += mp[t[i]] * ll((tt + 1) / 2);
                tt = 1;
            }
            if (i == n - 2)
            {
                ans += mp[t[i + 1]] * ll((tt + 1) / 2);
            }
        }
    }
    else
    {
        rp(j, 0, k)
        {
            ll tt = 1;
            if (j + k < n)
            {
                for (ll i = j; i < n - k; i += k)
                {
                    if (t[i] == t[i + k])
                    {
                        tt++;
                    }
                    else
                    {

                        ans += mp[t[i]] * ll((tt + 1) / 2);
                        tt = 1;
                    }
                    if (i + 2 * k >= n)
                    {
                        ans += mp[t[i + k]] * ll((tt + 1) / 2);
                        tt = 1;
                    }
                }
            }
            else
            {
                ans += mp[t[j]];
            }
            // cout << ans << endl;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.Scanner;

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

	int[][] c_ = new int[3][3];
	for(int i = 0; i < 3; i++){
	    for(int j = 0; j < 3; j++){
		c_[i][j] = scan.nextInt();
	    }
	}
	int one_max = Integer.MIN_VALUE;
	int two_max = Integer.MIN_VALUE;
	int three_max = Integer.MIN_VALUE;
	for(int i = 0; i < 3; i++){
	    for(int j = 0; j < 3; j++){
		if(i == 0){
		    if(c_[j][i] > one_max)
			one_max = c_[j][i];
		}else if(i == 1){
		    if(c_[j][i] > two_max)
			two_max = c_[j][i];
		}else{
		    if(c_[j][i] > three_max)
			three_max = c_[j][i];
		}
	    }
	}
	
	int[][] a_ = new int[3][3];
	int[][] b_ = new int[3][3];
	boolean[] flag_ = {false, false, false};
	for(int one = 0; one <= one_max; one++){
	    for(int two = 0; two <= two_max; two++){
		for(int three = 0; three <= three_max; three++){
		    flag_[0] = false;
		    flag_[1] = false;
		    flag_[2] = false;
		    for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
			    switch(j){
			    case 0 :
				b_[i][j] = one;
				break;
			    case 1:
				b_[i][j] = two;
				break;
			    case 2:
				b_[i][j] = three;
				break;
			    }
			    a_[i][j] = c_[i][j] - b_[i][j];
			}
			if(a_[i][0] == a_[i][1] &&
			   a_[i][0] == a_[i][2]){
			    flag_[i] = true;
			}else{
			}
		    }
		}
	    }
	}

	if(flag_[0] == true &&
	   flag_[1] == true &&
	   flag_[2] == true){
	    System.out.println("Yes");
	}else{
	    System.out.println("No");
	}
    }
}


Measured memory_bytes: 23168
io = STDIN
n,q=io.gets.split.map(&:to_i)
str=io.gets.chomp +" "
ar=Array.new(n,0)
cnt=0
n.times do |i|
  cnt+=1 if str[i..i+1]=='AC'
  ar[i]=cnt
end
ar.unshift(0)
q.times.each do
  l,r=io.gets.split.map(&:to_i)
  p ar[r-1]-ar[l-1]
end


Measured memory_bytes: 3708
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

# nCk
## 0!~n!をmodしつつ求める
def fact_all(n,M=mod):
    f = [1]*(n+1)
    ans = 1
    for i in range(1,n+1):
        ans = (ans*i)%M
        f[i] = ans
    return f

## inv(0!)~inv(n!)をmodしつつ求める
def fact_inv_all(fact_all,M=mod):
    N = len(fact_all)
    finv = [0]*N
    finv[-1] = pow(fact_all[-1],M-2,M)
    for i in range(N-1)[::-1]:
        finv[i] = finv[i+1]*(i+1)%M
    return finv

## nCkをmodしつつ返す
def nCk(n,k,fact_list,inv_list,M=mod):
    return (((fact_list[n]*inv_list[k])%M)*inv_list[n-k])%M

def edges_to_pt(s,t,n,directed=False):
    pt = [[] for _ in range(n)]
    for i in range(len(s)):
        pt[s[i]-1].append(t[i]-1)
        if not directed:
            pt[t[i]-1].append(s[i]-1)
    return pt

def order_dfs(pt,N):
    s = 0
    parent = [-1]*N
    order = [s]
    visited = [False]*N
    visited[s] = True
    S = [s]
    while S:
        v = S.pop()
        for u in pt[v]:
            if not visited[u]:
                visited[u] = True
                order.append(u)
                parent[u] = v
                S.append(u)
    return order,parent

N = I()
a,b = LIR(N-1,2)
pt = edges_to_pt(a,b,N)

fl = fact_all(N)
il = fact_inv_all(fl)

order,parent = order_dfs(pt,N)
order = order[::-1]

# 順方向の部分木について数え上げ（葉側から順に行う）
visited = [False]*N
size = [0]*N
dp = [1]*N
for v in order:
    # 葉の処理
    if len(pt[v]) == 1 and not visited[pt[v][0]]:
        dp[v] = 1
        size[v] = 1
    # 葉以外での処理
    else:
        size_v = 0
        for u in pt[v]:
            size_v += size[u]
            dp[v] *= dp[u]*il[size[u]]
            dp[v] %= mod
        dp[v] *= fl[size_v]
        dp[v] %= mod
        size[v] = size_v + 1
    visited[v] = True

# 逆側の部分木について数え上げ（根側から順に行う）
dp2 = [1]*N
for v in order[::-1]:
    p = parent[v]
    # 根の処理
    if p == -1:
        dp2[v] = 1
    # 根以外での処理
    else:
        dp2[v] = (((dp[p]*dp2[p]*pow(dp[v],mod-2,mod))%mod
                    *fl[N-1-size[v]]*il[size[p]-1])%mod
                    *fl[size[v]]*il[N-size[p]])%mod

# 部分木の情報を統合
for v in range(N):
    ans = (fl[N-1]*il[size[v]-1]*il[N-size[v]]*dp[v]*dp2[v])%mod
    print(ans)

Measured memory_bytes: 121152
#include"stdio.h"
#include"iostream"
#include"string.h"
#include"string"
using namespace std;
int main(){
	int A,B;
	while(scanf("%d%d",&A,&B)!=EOF){
		if((A+B)%3==0||A%3==0||B%3==0)
		printf("Possible\n");
		else printf("Impossible\n");
		
	}
	
	
	
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);
	int n,xn=0;
	cin>>n;
	int a[n];
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		xn^=a[i];
	}
	for(auto e:a)
		cout<<(xn^e)<<" ";
}

Measured memory_bytes: 4372
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;

int main(){
    int n,d,x,c=0;
    cin>>n>>d>>x;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    rep(i,n){
        int e = a[i];
        while(a[i]+1<=d){
            c++;
            a[i] += e;
        }
    }
    c += n;
    cout<<c+x<<endl;
    return 0;
}

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

int main(void)
{
    int r, g, b;
    cin >> r >> g >> b;
    int temp = 10 * g + b;
    if (temp % 4 == 0)
    {
        cout << "YES" << endl;
    }
    else
    {
        cout << "NO" << endl;
    }
}

Measured memory_bytes: 256
using System;

namespace AtcoderProblem
{
    class Program
    {
        static void Main(string[] args)
        {
                var x = int.Parse(Console.ReadLine());
                if (x == 0)
                {
                    Console.WriteLine("1");
                }
                else if (x == 1)
                {
                    Console.WriteLine("0");
                }
        }
    }
}


Measured memory_bytes: 27320
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
using namespace std;
#define rep(i,n) for(int i = 0;i<n;i++)
const long long MOD = 1000000007LL;
const string alpha = "abcdefghijklmnopqrstuvwxyz";
int main(){
  long long x,y;
  cin >> x >> y;
  if(x%y==0) cout << -1 << endl;
  else cout << x << endl;
}

Measured memory_bytes: 256
import sys

N = int(input())
A = list(map(int, input().split()))
a = 1

if 0 in A :
    print(0)
    sys.exit()

for i in range(N):
    a = a*A[i]
    if a > 10**18 :
        print(-1)    
        sys.exit()

else : print(a)



Measured memory_bytes: 21608
package main

import (
	"fmt"
)

func main() {
	var x int
	yen := 100
	fmt.Scanf("%d", &x)

	for i := 0; i <= x; i++ {
		if yen >= x {
			fmt.Println(i)
			break
		}
		yen += int(float64(yen) * 0.01)
	}
}

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

using namespace std;

int main(){
    int N,L;
    cin >> N >> L;
    string s[110];
    for (int i=0;i<N;i++){
	cin >> s[i];
    }
    sort(s,s+N);
    for (int i=0;i<N;i++){
	cout << s[i];
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
	int r;
	scanf("%d",&r);
	if (r<1200)
	{
		printf("ABC\n");
	}else if (r<2800)
	{
		printf("ARC\n");
	}else if (r<=4208)
	{
		printf("AGC\n");
	}
}

Measured memory_bytes: 128
import bisect as bs

x, n = map(int,input().split())
# l = list(map(int,input().split()))

if n == 0:
    print(x)
    exit(0)

nums = list(map(int,input().split()))
nums2 = [False]*101
# print(nums)
for p in nums:
    nums2[p] = True

for i in range(102):
    # print(x-i,x+i)
    if x - i < 1:
        print(0)
        exit(0)
    elif x + i > 100 and nums2[x-i]==True:
        print(101)
        exit(0)
    elif nums2[x-i]==False:
        print(x-i)
        exit(0)
    elif nums2[x+i]==False:
        print(x+i)
        exit(0)


Measured memory_bytes: 9156
import itertools
import sys

N, M, R = map(int, input().split())
r = [int(i) for i in input().split()]
r.sort()
a = [[sys.maxsize] * N for i in range(N)]
for i in range(M):
	A, B, C = map(int, input().split())
	a[A - 1][B - 1] = C
	a[B - 1][A - 1] = C
for i in range(N):
	a[i][i] = 0
for i in range(N):
	for j in range(N):
		if a[j][i] == sys.maxsize:
			continue
		for k in range(N):
			if a[i][k] == sys.maxsize:
				continue
			a[j][k] = min(a[i][k] + a[j][i], a[j][k])
ans = sys.maxsize
for i in itertools.permutations(r):
	b, j = 0, 1
	while j < R:
		b += a[i[j - 1] - 1][i[j] - 1]
		j += 1
	ans = min(b, ans)
print(ans)

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

using namespace std;

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

  int n;
  cin >> n;
  vector<int> x(n);
  for (int i = 0; i < n; ++i) {
    cin >> x[i];
  }
  int l, q;
  cin >> l >> q;

  const int cached = 20;
  vector<vector<int>> hotel_dist(cached, vector<int>(n + 1));
  for (int i = 0; i < n; ++i) {
    auto reached_hotel = lower_bound(x.begin(), x.end(), x[i] + l + 1);
    hotel_dist[0][i] = reached_hotel - x.begin() - 1;
  }
  hotel_dist[0][n] = n;

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

  for (int i = 0; i < q; ++i) {
    int start, goal;
    cin >> start >> goal;
    start--;
    goal--;
    if (goal < start)
      swap(start, goal);

    int days = 1;
    for (int j = cached - 1; 0 <= j && start < goal; --j) {
      if (hotel_dist[j][start] < goal) {
        days += (1 << j);
        start = hotel_dist[j][start];
      }
    }
    cout << days << "\n";
  }
}


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

int main()
{

    vector<int>vec;
    int a,b,c,res=0;
    cin>>a>>b>>c;
    vec.push_back(a);
    vec.push_back(b);
    vec.push_back(c);
    sort(vec.begin(),vec.end());
    for(int i=1;i<3;i++){
        res+=abs(vec[i]-vec[i-1]);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 256
// Package main provides
//
// File:  c.go
// Author: ymiyamoto
//
// Created on Sun Jan 27 01:52:44 2019
//
package main

import (
	"fmt"
	"sort"
)

func min(slice ...int) int {
	sort.Ints(slice)
	return slice[0]
}

func main() {
	var N int
	fmt.Scan(&N)

	var S string
	fmt.Scan(&S)

	wests := make([]int, N)
	easts := make([]int, N)
	for i, s := range S {
		if s == 'W' {
			wests[i] = 1
		} else {
			easts[i] = 1
		}
	}
	for i := range wests {
		if i+1 < len(easts) {
			easts[i+1] += easts[i]
		}
		if N-1-i-1 >= 0 {
			wests[N-1-i-1] += wests[N-1-i]
		}
	}

	ans := 1 << 60
	for i := range easts {
		if i == 0 {
			ans = min(ans, N-1-wests[1])
		} else if i == N-1 {
			ans = min(ans, N-1-easts[N-2])
		} else {
			ans = min(ans, N-1-easts[i-1]-wests[i+1])
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 10624
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
int main(void)
{
    int n,i,t[100000],j,p,x,sum,ya[50000];
	scanf("%d",&n);
	for(i=0;i<n;i++)	scanf("%d",&t[i]);
	sort(t,t+n,greater<int>());
	p=0;
	for(i=1;i*i<t[0];i++)	{
		if(t[0]%i==0)	{
			ya[p]=t[0]/i;
			ya[p+1]=i;
			p+=2;
		}
	}
	if(i*i==t[0])	{
		ya[p]=i;	p++;
	}
	sort(ya,ya+p,greater<int>() );
	sum=0;
	for(i=1;i<n;i++)	{
		for(j=0;j<p;j++)	{
			if(t[i]>ya[j])	break;
		}
//		printf("%d %d \n",t[i],ya[j]);
		j--;
		sum+=ya[j]-t[i];
	}
    printf("%d\n",sum);
    return 0;
}


Measured memory_bytes: 3148
class Mychain:
    # 名前はこれでいいんだろうか・・・

    def __init__(self, n):
        self.n = n
        self.lst = [0 for _ in range(n * (n + 1) // 2)]

    def get_index(self, i, j):
        return i - 1 + ((j - i) * (2*self.n - j + i + 1) // 2)

    def get_value(self, i, j):
        return self.lst[self.get_index(i, j)]

    def set_value(self, i, j, value):
        index = self.get_index(i, j)
        self.lst[self.get_index(i, j)] = value


n = int(input())
res = Mychain(n)
matrix = [int(i) for i in input().split()]
matrix.extend([int(input().split()[1]) for i in range(n - 1)])


for n1 in range(1, n + 1):
    for i in range(1, n - n1 + 1):
        j = n1 + i
        value = min(res.get_value(i, i + k) + res.get_value(i + k + 1, j)
                    + matrix[i - 1] * matrix[i + k] * matrix[j]
                    for k in range(n1))
        res.set_value(i, j, value)

print(res.get_value(1, n))



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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int abdis = abs(a-b);
  int bcdis = abs(c-b);
  int acdis = abs(a-c);
  if(abdis <= d && bcdis <= d)
  {
    cout<<"Yes"<<endl;
    return 0;
  }
  if(acdis <= d)
  {
    cout<<"Yes"<<endl;
    return 0;
  }
  else
    cout<<"No"<<endl;
  return 0;
}


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

#define name ""
#define ini freopen(name".inp","r",stdin); freopen(name".out","w",stdout)
#define foe(it,c) for (__typeof(c.begin()) it = c.begin(); it != c.end(); it++)
#define long long long 
#define db double 
#define pii pair <int, int>
#define pll pair <long, long>
#define all(c) c.begin(), c.end()
#define fastio ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int INF = 1e9+7;
const int MOD = 1e9+7;
const int dx[4] = {0,0,-1,1};
const int dy[4] = {-1,1,0,0};

string s; 

bool Check(int l, int r){
  while (l <= r){
    if (s[l] != s[r]) return false;
    l++; r--;
  }
  return true;
}

int main()
{
  fastio;
  cin >> s;
  int n = s.size(); s = '#' + s;
  if (Check(1, n) && Check(1, (n - 1) / 2) && Check((n + 3) / 2, n)) cout << "Yes";
  else cout << "No";
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int k,a,b;
	cin >> k >> a >> b;
	for(int i = a; i <= b; i++){
		if(i % k == 0) {
			cout << "OK" << endl;
			return 0;
		}
	}
	cout << "NG" << endl;
	return 0;
}


Measured memory_bytes: 3564
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;



vector<ll> gf2_rank(vector<ll> &v) {
    int n = v.size();
    rep(i, n) {
        int x = max_element(v.begin() + i, v.end()) - v.begin();
        if (v[x] == 0) break;
        swap(v[i], v[x]);
        ll msb = 1;
        while (msb << 1 <= v[i]) msb <<= 1;
        rep(j, n) if (j != i) if (v[j] & msb) v[j] ^= v[i];
    }
    while (v.size() && v.back() == 0) v.pop_back();
    return v;
}

int main() {
    int n;
    cin >> n;
    vector<ll> v;
    vector<ll> a(n);

    ll x = 0;


    rep(i, n) {
        cin >> a[i];
        x ^= a[i];
    }
    rep(i, n) {
        a[i] &= ~x;
        v.push_back(a[i]);
    }
    gf2_rank(v);
    ll ret = 0;
    for (ll l: v) ret = max(ret, ret ^ l);
    cout << ret * 2 + x << endl;


}

Measured memory_bytes: 5108
import java.util.*;

public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int a = scan.nextInt();
    for (int i=a;i<10000000;i++){
      boolean find = false;
      for (int j=2;j<i;j++){
        if (i%j == 0){
          find = true;
          break;
        }
      }
      if (find == false){
        System.out.println(i);
        break;
      }
    }
  }
}


Measured memory_bytes: 35676
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class T>
istream& operator >> (istream& is, vector<T>& v)
{
	for (auto &i : v) is >> i;
	return is;
}
template<class T>
ostream& operator<<(ostream& os, vector<T>& v)
{
	const string delimiter = "\n";
	REP(i, v.size())
	{
		os << v[i];
		if (i != v.size() - 1) os << delimiter;
	}
	return os;
}
/*--------------------template--------------------*/

int n, z, w;
vi a;
ll dp[2222][2];

ll solve(int p, int t)
{
	if (dp[p][t] >= 0) return dp[p][t];
	ll res;
	if (t == 0)
	{
		res = 0;
		ll e;
		if (p == 0) e = w;
		else e = a[p - 1];
		chmax(res, abs(e - a.back()));
		FOR(i, p + 1, n) chmax(res, solve(i, 1));
	}
	if (t == 1)
	{
		res = LLONG_MAX;
		ll e;
		if (p == 0) e = z;
		else e = a[p - 1];
		chmin(res, abs(e - a.back()));
		FOR(i, p + 1, n) chmin(res, solve(i, 0));
	}
	return dp[p][t] = res;
}

int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	MS(dp, -1);
	cin >> n >> z >> w;
	a.resize(n); cin >> a;
	cout << solve(0, 0) << endl;
	return 0; 
}

Measured memory_bytes: 384
import numpy as np
from numba import njit
def main():
    N = int(input())
    nlist = list(map(int, input().split()))

    def gdc(x, y):
        b = max(x, y)
        s = min(x, y)
        r = b % s
        if r == 0:
            return s
        else:
            return gdc(s, r)

    scp = False
    pcp = False

    sgdc = nlist[0]
    for n in nlist:
        sgdc = gdc(sgdc, n)
        if sgdc == 1:
            scp = True
            break

    if not scp:
        print('not coprime')
        exit()

    pcheckl = [0] * (10**6+1)
    for n in nlist:
        pcheckl[n] = 1

    pcp = all([sum(pcheckl[i::i]) <= 1 for i in range(2, 10**6+1)])

    if pcp:
        print('pairwise coprime')
    elif scp:
        print('setwise coprime')

if __name__ == '__main__':
    main()

Measured memory_bytes: 208632
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, a[109], b[109]; string s;
int main() {
	cin >> n;
	int sumd = 0;
	for (int i = 0; i < n; i++) {
		cin >> s;
		int d = 0; b[i] = 0;
		for (int j = 0; j < s.size(); j++) {
			if (s[j] == '(') d++;
			if (s[j] == ')') d--;
			b[i] = max(b[i], -d);
		}
		a[i] = d;
		sumd += d;
	}
	vector<pair<int, int> > ls, rs;
	for (int i = 0; i < n; i++) {
		if (a[i] >= 0) ls.push_back(make_pair(b[i], a[i]));
		else rs.push_back(make_pair(b[i] + a[i], -a[i]));
	}
	sort(ls.begin(), ls.end());
	sort(rs.begin(), rs.end());
	bool ok = (sumd == 0);
	int lx = 0;
	for (int i = 0; i < ls.size(); i++) {
		if (lx - ls[i].first < 0) ok = false;
		lx += ls[i].second;
	}
	int rx = 0;
	for (int i = 0; i < rs.size(); i++) {
		if (rx - rs[i].first < 0) ok = false;
		rx += rs[i].second;
	}
	cout << (ok ? "Yes" : "No") << endl;
	return 0;
}

Measured memory_bytes: 3184
using System;
using System.Linq;
using System.Collections.Generic;

using E = System.Linq.Enumerable;

public class Program
{
    public static void Main()
    {
        var tx = Console.ReadLine().Split().Select(x => double.Parse(x)).ToArray();
        Console.WriteLine((tx[0] / tx[1]).ToString("F4"));
    }
}


Measured memory_bytes: 13268
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iterator>
#pragma warning(disable:4996)
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223000000000000000
#define INF 2147000000
#define MOD 1000000007
using namespace std;

ll d[105][105];

int main(int argc, char* argv[])
{
    long n,m;
    scanf("%ld%ld", &n, &m);

    vector<long> count(m);
    long i,j;
    for(i=0; i<n; i++) {
        long k;
        scanf("%ld", &k);
        for(j=0; j<k; j++) {
            long tmp=0;
            scanf("%ld", &tmp);
            count[tmp-1]++;
        }
    }

    long ans=0;
    for(i=0; i<m; i++) {
        if(count[i]==n) ans++;
    }
    printf("%ld\n", ans);

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vi = vector<int>;
using vvi = vector<vi>;
#define ote(x) cout<<(x)<<endl
#define all(x) (x).begin(),(x).end()
#define rp(i,s,e) for(int i=(s);i<(e);++i)
#define rpz(i,e) rp(i,0,e)

int main(){
	int N; cin>>N;
	ote((N-1)/2);
}


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

int main(){
  string str;

  while(cin >> str){
    for(int i = 0 ; i < str.length() ; ++i){ 
      if(str[i] == '@'){
	int len = str[i+1] - '0';
	for(int j = 0 ; j < len ; ++j){
	  cout << str[i+2];
	}
	++i;i++;
      }
      else cout << str[i];
    }
    cout << endl;
  }

  return 0;
}

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

#define rep(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define all(x) (x).begin(), (x).end()
using i32 = int32_t;
using i64 = int64_t;
using f32 = float;
using f64 = double;
using P   = pair<int, int>;

template <class T>
bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    } else {
        return false;
    }
}
template <class T>
bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    } else {
        return false;
    }
}

struct Setup {
    Setup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} SETUP;

template <class T>
void dump_vector(const vector<T> &v) {
    auto len = v.size();
    rep(i, 0, len) {
        cout << v[i] << (i == len - 1 ? "\n" : " ");
    }
}

template <class T>
void insertion_sort(vector<T> vec) {
    auto len = vec.size();
    rep(i, 1, len) {
        auto a = vec[i];
        auto j = i - 1;
        while (j >= 0 && vec[j] > a) {
            vec[j + 1] = vec[j];
            j--;
        }
        vec[j + 1] = a;
        dump_vector(vec);
    }
}

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) {
        cin >> A[i];
    }
    dump_vector(A);
    insertion_sort(A);
}



Measured memory_bytes: 3144
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <queue>
#include <set>
#include <vector>
using namespace std;

int main() {
  string a, b, c;
  cin >> a >> b >> c;
  cout << a[0] << b[0] << c[0] << endl;

  return 0;
}


Measured memory_bytes: 3604
S = input()
N = len(S)
ans = 0
for i in range(2 ** (N-1)):
    p = 0
    for j in range(N-1):
        if (i >> j) & 1:
            ans += int(S[p:j+1])
            p = j+1
    ans += int(S[p:])
print(ans)

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

int x, y, a, b, c;
pair<long long, int> apple[300005];
int pf[3];

long long res = 0;


int main() {
	cin >> x >> y >> a >> b >> c;
	int k = 0;
	rep(i, a) {
		long long t;
		cin >> t;
		apple[k].first = t;
		apple[k].second = 0;
		k++;
	}
	rep(i, b) {
		long long t;
		cin >> t;
		apple[k].first = t;
		apple[k].second = 1;
		k++;
	}
	rep(i, c) {
		long long t;
		cin >> t;
		apple[k].first = t;
		apple[k].second = 2;
		k++;
	}
	sort(apple, apple + k);
	for(int i = k - 1; i >= k - x - y; i--) {
		res += apple[i].first;
		pf[apple[i].second] += 1;
	}
	if (pf[0] > x) {
		int ss = pf[0] - x;
		int u = k - x - y;
		int v = k - x - y - 1;
		rep(i, ss) {
			for(;; u++) {
				if (apple[u].second == 0) {
					res -= apple[u].first;
					break;
				}
			}
			u++;
		}
		rep(i, ss) {
			for(;; v--) {
				if (apple[v].second != 0) {
					res += apple[v].first;
					break;
				}
			}
			v--;
		}
	} else if (pf[1] > y) {
		int ss = pf[1] - y;
		int u = k - x - y;
		int v = k - x - y - 1;
		rep(i, ss) {
			for(;; u++) {
				if (apple[u].second == 1) {
					res -= apple[u].first;
					break;
				}
			}
			u++;
		}
		rep(i, ss) {
			for(;; v--) {
				if (apple[v].second != 1) {
					res += apple[v].first;
					break;
				}
			}
			v--;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,s1=0,s2=0;
	cin>>a>>b>>c>>d;
	do{
		a=a-d;
		s1++;
	}while(a>0);
	do{
		c=c-b;
		s2++;
	}while(c>0);
	if(s1>=s2)cout<<"Yes";
	else if(s1<s2)cout<<"No";
	return 0;
}	//46 4 40 5	10 

Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef struct pair<int,int> P;
typedef long long ll;

ll n,k,l;

int dp1[16002][3]={};
int dp2[16002][3]={};
ll c[200001]={};
int main() {
	int n;
	ll t;
	ll t1;
	ll s=0;

	cin>>n>>t;
	ll e=0;
	for(int i=0;i<n;++i){
		cin>>t1;
		if(t1<e){
			s=s+t-e+t1;
		}else{
			s+=t;
		}
		e=t1+t;
	}
	cout<<s<<endl;
//	int ls=s.length();
//
//	int m=0;
//	int a1=0;
//	int a2=0;
//	int a3=0;
//	int a0=0;
//	bool flg=true;
//	for(a1=1;(s[a1]==s[a1-1])&&(a1<ls);a1++);
//	m=a1-a0;
//	for(a2=a1+1;(s[a2]==s[a2-1])&&(a2<ls);a2++);
//	m=max(a2-a1,a1-a0);
//	if(a2==ls)flg=false;
//	for(a3=a2+1;a3<ls;a3++){
//		for(;(s[a3]==s[a3-1])&&(a3<ls);a3++);
//		m=max(m,((a2-a1)+min(a1-a0,a3-a2)));
//		a0=a1;
//		a1=a2;
//		a2=a3;
//	}
//	if(flg)m=max(m,((a2-a1)+min(a1-a0,a3-a2)));
//	cout<<m<<endl;
	return 0;
}


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


int main() {
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<string> arr(n);
    for (auto &el: arr) cin >> el;

    sort(begin(arr), end(arr));
    for (auto el: arr) cout << el;
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
H, W, h, w = map(int, input().split())

if H % h == 0 and W % w == 0:
    print("No")
    exit(0)

blocks = (H//h) * (W//w)
left = H * W - blocks * h * w
offset = blocks // left + 1
v = [offset, -offset * (h * w - 1) - 1]

print("Yes")
for i in range(H):
    a = []
    for j in range(W):
        a.append(v[1 if i % h == h-1 and j % w == w-1 else 0])
    print(" ".join(list(map(str, a))))


Measured memory_bytes: 4084
#include <iostream>
#include<cstdlib>
#include<queue>
#include<set>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<map>
#include<cstdio>
using namespace std;
#define rep(i,a) for(int i=0;i<a;i++)
#define mp make_pair
#define pb push_back
#define P pair<int,int>
#define ll long long
#define cat(p) cout<<p<<endl
#define catA(p,n) for(int i=0;i<n;i++)cout<<p[i]<<((i==n-1)?"\n":" ")

int n,l;

int main(){

  cin>>n>>l;
  int ans=100000000,score=0,hoge=0,z=100000;

  for(int i=1;i<=n;i++){
    score+=i+l-1;
  }

  for(int i=1;i<=n;i++){
    //ans+=i+l-1;
    int cnt=0;
    for(int j=1;j<=n;j++){
      if(j!=i)cnt+=j+l-1;
    }
    if(abs(score-cnt)<z)z=abs(score-cnt),ans=cnt;
  }


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


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define int long long
using namespace std;
long long le,ans,n,k;
int a[200010],f[200010],tt,ri;
inline int read(){
	char ch=getchar();int o=0;
	while(!isdigit(ch)) ch=getchar();
	while(isdigit(ch)) o=(o<<3)+(o<<1)+(ch^48),ch=getchar();
	return o;
} 
inline bool check(long long x){
	long long sum=0;
	for(register int i=1;i<=n;i++){
		if((a[i]-(int)(x*1.0/f[i]))>0) sum+=a[i]-(int)(x*1.0/f[i]);
	}
	if(sum>k) return 0;
	return 1;
}
inline bool cmp(int a,int b){
	return a<b;
}
inline bool cmp1(int a,int b){
	return a>b;
}
signed main(){
	n=read(),k=read();
	for(register int i=1;i<=n;i++) a[i]=read(),ri=max(ri,a[i]);
	for(register int i=1;i<=n;i++) f[i]=read(),tt=max(tt,f[i]);
	sort(f+1,f+n+1,cmp);sort(a+1,a+n+1,cmp1);
	ri=ri*tt;
	while(le<=ri){
		long long mid=(le+ri)>>1;
		if(check(mid)) ans=mid,ri=mid-1;
		else le=mid+1; 
	} 
	cout<<ans<<endl;	
}

Measured memory_bytes: 3328
SN=[5,1,2,6]
WE=[4,1,3,6]

def EWSN(d):
  global SN,WE
  if d == "S" :
    SN = SN[3:4] + SN[0:3]
    WE[3] = SN[3]
    WE[1] = SN[1]
  elif d == "N":
    SN = SN[1:4] + SN[0:1]
    WE[3] = SN[3]
    WE[1] = SN[1]
  elif d == "E":
    WE = WE[3:4] + WE[0:3]
    SN[3] = WE[3]
    SN[1] = WE[1]
  elif d == "W":
    WE = WE[1:4] + WE[0:1]
    SN[3] = WE[3]
    SN[1] = WE[1]

dice = list(map(int,input().split(" ")))
op = input()

for i in op:
  EWSN(i)
print(dice[SN[1] - 1])


Measured memory_bytes: 5608
# coding: utf-8
# Your code here!

N, Y = map(int, input().split())

for x in range(N + 1):
    for y in range(N + 1):
        z = N - (x + y)
        if (z <= N) and (z >= 0) and (Y == 10000 * x + 5000 * y + 1000 * z):
            print(x, y, z)
            exit()
else:
    print(-1, -1, -1)

Measured memory_bytes: 3060
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		//List<String> list= new ArrayList<String>(Arrays.asList(s.split("")));
		List<Integer> list=new ArrayList<Integer>();
		//Integer[] Republican = new Integer[m];
		int n = sc.nextInt();
		for(int i=0;n>i;i++) {
			int a = sc.nextInt();
			list.add(a);
		}
		int count=0;
		for(int i=0;n-1>i;i++) {
			for(int j=i+1;n>j;j++) {
				count=count+list.get(i)*list.get(j);
			}
		}

		System.out.println(count);

	}
}



Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int main() {
    long long N;
    cin >> N;
    long long a[N];
    long long M1=100000000000, M2=-1000000000, M3=0;
    for(long long i=0; i<N; i++) {
        cin >> a[i];
        M1=min(M1,a[i]);
        M2=max(M2,a[i]);
        M3+=a[i];
    }
    cout << M1 << ' ' << M2 << ' ' << M3 << endl;
    return 0;
}


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

int main() {
	int h,w,a,b,i,j,k,ans,cur;
	cin >> h >> w >> a >> b;
	for(i=0; i<h; i++){
		for(j=0; j<w; j++){
			if((i<b && j<a) || (i>=b && j>=a)){
				cout << 0;
			}else{
				cout << 1;
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1280
N, M = map(int, input().split())

cnt = 0

l = 0
k = M
while cnt < M and k > 0:
    print(l + 1, l + k + 1)
    cnt += 1
    l += 1
    k -= 2

l = M + 1
k = M - 1
while cnt < M:
    print(l + 1, l + k + 1)
    cnt += 1
    l += 1
    k -= 2


Measured memory_bytes: 75676
N = int(input())
A = [int(e)-1 for e in input().split()]

ad = [set() for _ in range(N)]

for i, a in enumerate(A):
    ad[a].add(i)

ans = 0

for i, a in enumerate(A):
    if a in ad[i]:
        ans += 1

print(ans//2)

Measured memory_bytes: 33636
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
//#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 4e3 + 100, OO = 1e9, T = 4500 + 100, M = 924844033, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
int fac[N], dp[N][N][4];
bool is[N];

int32_t main() {
	use_fast;
    int n, m, ans = 0;
	cin >> n >> m;
    fac[0] = 1;
    for(int i = 1; i <= n; ++i) {
        fac[i] = (1ll * fac[i - 1] * i) % M;
	}
	int t = 0;
	for(int i = 1; i <= m; ++i) {
        for(int j = 0; j <= 1; ++j) {
            for(int k = i; k <= n; k += m) {
                ++t;
                if(k == i)
                    is[t] = true;
            }
		}		
	}
    dp[0][0][0] = 1;
    for(int i = 1; i <= t; ++i) {
        for(int j = 0; j <= i; ++j) {
            dp[i][j][0] = (dp[i - 1][j][0] + dp[i - 1][j][1]) % M;
            if(!is[i])
                dp[i][j][1] = dp[i - 1][j - 1][0];
        }
	}
    for(int i = 0; i <= n; ++i) {
        if(i & 1)
            ans = (ans - 1ll * fac[n - i] % M * 1ll * (dp[t][i][0] + dp[t][i][1]) % M) % M;
        else
            ans = (ans + 1ll * fac[n - i] % M * 1ll * (dp[t][i][0] + dp[t][i][1]) % M) % M;
	}
    cout << (ans + M) % M << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



Measured memory_bytes: 144416
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repr(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define FORR(i, m, n) for (int i = (m); i >= (n); --i)
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll mod2 = 998244353;

int main() {
  string s;
  cin >> s;
  int n = s.size();
  rep(i, n) {
    if (s[i] == 'R') {
      if (i % 2 == 1) {
        cout << "No" << endl;
        return 0;
      }
    }
    if (s[i] == 'L') {
      if (i % 2 == 0) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define ld long double
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n;i>=0;i--)
#define rep_a(i,a,n) for(int i=a;i<n;i++)
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()

int solve()
{
    int n,w;
    cin>>n>>w;
    ll dp [n + 1] [w + 1];
    memset(dp,0,sizeof(dp));
    ll w1,v;
        rep_a(i,1,n + 1)
        {
            cin>>w1>>v;
            rep_a(j,1,w+1)
            {
                if(w1>j)
                {
                    dp[i][j] = dp[i-1][j];
                }
                else
                {
                    dp[i][j] = max(dp[i-1][j],dp[i-1][j-w1]+v);
                }
            }
        }
    cout<<dp[n][w]<<endl;
    return 0;
}
int main()
{
    /* #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #else
    #endif */
    solve();
    /* #ifndef ONLINE_JUDGE
    cout<<"\nTime Elapsed: "<<1.0*clock()/ CLOCKS_PER_SEC<<" Sec\n";
    #endif */

    return 0;
} 

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

int main()
{
  int n;
  int num_sum=0;
  int each_num[10];
  cin >> n;
  int dandan = n;
  int p = 0;

  for (int i=9; i>=0; --i) {
    p = pow(10, i);
    each_num[i] = dandan / p;
    dandan %= p; 
    num_sum += each_num[i];
  }

  if (n % num_sum == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))
#コストの配列 全部無限にしておく
cost = [float("inf") for _ in range(N)]
cost[0] = 0
for i in range(N-1):
    cost[i + 1] = min(cost[i + 1], cost[i] + abs(A[i+1] - A[i]))
    if(i + 2 < N):
        cost[i + 2] = min(cost[i+2], cost[i] + abs(A[i+2] - A[i]))
print(cost[N-1])

Measured memory_bytes: 53320
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    Int n;
    cin >> n;
    vector<vector<bool>> f(n, vector<bool>(10, false));
    vector<vector<Int>> p(n, vector<Int>(11));
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j < 10; j++) {
            Int in;
            cin >> in;
            if (in == 1) {
                f[i][j] = true;
            }
        }
    }
    for (Int i = 0; i < n; i++) {
        for (Int j = 0; j <= 10; j++) {
            cin >> p[i][j];
        }
    }

    Int ans = -1000000000;
    for (Int i = (1LL << 10) - 1; i; --i) {
        Int tem = 0;
        for (int l = 0; l < n; l++) {
            int cnt = 0;
            int t = i;
            for (int k = 0; k < 10; k++) {
                if (t & 1 && f[l][k]) {
                    cnt++;
                }
                t >>= 1;
            }

            tem += p[l][cnt];
        }

        if (__builtin_popcount(i) != 0) {
            ans = max(ans, tem);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strconv"
)

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func main() {
	var s string
	fmt.Scan(&s)
	ans := 1000
	for i := 0; i+2 < len(s); i++ {
		X, _ := strconv.Atoi(s[i : i+3])
		ans = min(ans, abs(X-753))
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512