akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var (
	sc *bufio.Scanner = bufio.NewScanner(os.Stdin)
	M  int            = 0
	C  int            = 0
	G  []int          = []int{}
)

func print(A []int) {
	s := make([]string, len(A))
	for i, o := range A {
		s[i] = strconv.Itoa(o)
	}
	fmt.Println(strings.Join(s, " "))
}

func scan() int {
	sc.Scan()
	n, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return n
}

func insertion(A []int, N int, g int) {
	for i := g; i < N; i++ {
		v := A[i]
		j := i - g
		for j >= 0 && A[j] > v {
			A[j+g] = A[j]
			j = j - g
			C++
		}
		A[j+g] = v
	}
}

func shell(A []int, N int) {
	h := 1
	for h <= N {
		G = append([]int{h}, G[0:]...)
		h = 3*h + 1
	}
	M = len(G)
	for i := 0; i < M; i++ {
		insertion(A, N, G[i])
	}
}

func main() {

	N := scan()

	A := make([]int, N)
	for i := range A {
		A[i] = scan()
	}

	shell(A, N)

	fmt.Println(M)
	print(G)
	fmt.Println(C)
	for _, n := range A {
		fmt.Println(n)
	}
}


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

int64_t calc(const vector<int64_t>& A, int64_t x) {
    int64_t ret = 0;
    for (int i = 0; i < A.size(); i++) {
        ret += abs(A[i] - x);
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    vector<int64_t> A(n);
    for (int i = 0; i < n; i++) {
        cin >> A[i];
        A[i] -= i;
    }
    sort(A.begin(), A.end());
    if (n % 2 != 0) {
        cout << calc(A, A[max(0, n/2)]) << endl;
    } else {
        cout << min(calc(A, A[n/2 - 1]), calc(A, A[n/2])) << endl;
    }
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;

vl<ll> divisor(ll n)
{
    vl<ll> v;
    for(int i=2;i<=sqrt(n);i++)
    {
        if(n%i==0) 
        {
            if(n/i==i) v.pb(i);
            else
            {
                v.pb(i);
                v.pb(n/i);
            }
        }
    }
    return v;
}

int main()
{
    ll a,b,i,j,n,t;
    cin>>n;
    vl<ll> v;
    ll count=0;
    v=divisor(n);
    for(i=1;i<=n;i++) 
    {
        count+=n/i;
    }
    count-=v.size();
    cout<<count-2;
}

Measured memory_bytes: 3724
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
  int n;
  cin>>n;
  string s;
  cin>>s;

  if(n==1) cout<<1<<endl;
  else
  {
    char tmp = s.at(0);
    int cnt=1;

    for(int i= 1;i<n;i++){
      if(tmp != s.at(i)){
          cnt ++;
          tmp = s.at(i);
      }
    }
    cout<<cnt<<endl;
  }
}

Measured memory_bytes: 512
x, y = map(int, input().split())
if x == 3:
  x_cost = 100000
elif x == 2:
  x_cost = 200000
elif x == 1:
  x_cost = 300000
else:
  x_cost = 0

if y == 3:
  y_cost = 100000
elif y == 2:
  y_cost = 200000
elif y == 1:
  y_cost = 300000
else:
  y_cost = 0

print(x_cost + y_cost + 400000 if x_cost == y_cost == 300000 else x_cost + y_cost)

Measured memory_bytes: 3064
import java.io.*;
class Main
{
    public static void main(String args[])throws IOException
    {
	BufferedReader input=new BufferedReader(new InputStreamReader(System.in));
	char a[]=input.readLine().toCharArray();
	String str=String.valueOf(a);
	for(int i=0;i<a.length;i++)
	    {
		if(a[i]=='A')
		    {
			a[i]='X';
			str=String.valueOf(a);
		    }
		else if(a[i]=='B')
		    {
			a[i]='Y';
			str=String.valueOf(a);
		    }
		else if(a[i]=='C')
		    {
			a[i]='Z';
			str=String.valueOf(a);
		    }
		else
		    {
			a[i]=(char)(a[i]-3);
			str=String.valueOf(a);
		    }
	    }
	System.out.println(str);
    }
}

Measured memory_bytes: 20004
def resolve():
    a = []
    for _ in range(3):
        a.append(list(map(int, input().split())))
    n = int(input())
    b = []
    for _ in range(n):
        b.append(int(input()))

    check = [[False] * 3 for _ in range(3)]

    for b_one in b:
        for i in range(3):
            for j in range(3):
                if a[i][j] == b_one:
                    check[i][j] = True

    if check[0][0] and check[0][1] and check[0][2]:
        print('Yes')
        return
    if check[1][0] and check[1][1] and check[1][2]:
        print('Yes')
        return
    if check[2][0] and check[2][1] and check[2][2]:
        print('Yes')
        return
    if check[0][0] and check[1][0] and check[2][0]:
        print('Yes')
        return
    if check[0][1] and check[1][1] and check[2][1]:
        print('Yes')
        return
    if check[0][2] and check[1][2] and check[2][2]:
        print('Yes')
        return
    if check[0][0] and check[1][1] and check[2][2]:
        print('Yes')
        return
    if check[0][2] and check[1][1] and check[2][0]:
        print('Yes')
        return

    print('No')

resolve()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int MOD =1e9+7;
using ll=long long;
using Graph = vector<vector<int>>;

int main() {
    ll n;
    cin >> n;
    n--;
    vector<int> ans;
    while(n>25){
        int res = 0;
        res = n % 26;
        n /=26;
        ans.push_back(res);
        n--;
    }
    ans.push_back(n);
    reverse(ans.begin(),ans.end());
    for(int num: ans){
        cout << char('a' + num);
    }
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str = sc.nextLine();
		String ans = "";
		for (int i = 0; i < str.length(); ++i) {
			char ch = str.charAt(i);
			if ('A' <= ch && ch <= 'Z')
				ans += (char)(ch - ('A' - 'a'));
			else if ('a' <= ch && ch <= 'z')
				ans += (char)(ch + ('A' - 'a'));
			else
				ans += ch;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 31504
#include<iostream>
#include<complex>
#include<queue>
using namespace std;
typedef complex<double> xy_t;
double cross_product(xy_t p,xy_t q)
{
  return (conj(p)*q).imag();
}
int main()
{
  double x[4],y[4];
  while(true){
    for( int i = 0; i < 4; ++i) cin >> x[i] >> y[i];
    if(!cin) break;
    xy_t a(x[0],y[0]),b(x[1],y[1]),c(x[2],y[2]),p(x[3],y[3]);
    double S1,S2,S3;
    S1 = cross_product(a - p, b - p);
    S2 = cross_product(b - p, c - p);
    S3 = cross_product(c - p, a - p);
    bool ok = (S1 > 0 && S2 > 0 && S3 > 0) || (S1 < 0 && S2 < 0 && S3 < 0);
    cout << (ok ? "YES":"NO") << endl;
  }
}

Measured memory_bytes: 1220
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
n,a,b=MI()
lis=LI()
ans=0
for i in range(n-1):
    ans+=min(a*(lis[i+1]-lis[i]),b)
print(ans)

Measured memory_bytes: 14636
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    cout << max(c-(a-b),0) << endl;
    return 0;
}

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

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

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

  vector<int> res(4, 0);
  for (int i = 0; i < N; i++) {
    string s = cases.at(i);
    if (s == "AC") {
      res.at(0)++;
    } else if (s == "WA") {
      res.at(1)++;
    } else if (s == "TLE") {
      res.at(2)++;
    } else if (s == "RE") {
      res.at(3)++;
    }
  }

  cout << "AC x " << res.at(0) << endl;
  cout << "WA x " << res.at(1) << endl;
  cout << "TLE x " << res.at(2) << endl;
  cout << "RE x " << res.at(3) << endl;
}

Measured memory_bytes: 6372
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
const int INF = 1e8;
using namespace std;

#define int long long

vector<pair<int,int>> g[100005];

int bfs(int k){
	vector<int> dis(k,INF);
	dis[1] = 0;

	deque<int> q;
	q.push_front(1);

	while(not q.empty()){
		int u = q.front(); q.pop_front();
		for(auto e : g[u]){
			if(dis[e.first] > dis[u] + e.second){
				dis[e.first] = dis[u] + e.second;
				if(e.second == 1){
					q.emplace_back(e.first);
				}else{
					q.emplace_front(e.first);
				}
			}
		}
	}
	return dis[0] + 1;
}

signed main(){
	int k;
	cin >> k;


	rep(i,k){
		g[i].emplace_back((i + 1) % k, 1);

		int t = 10;
		while(t <= 100000){
			g[i].emplace_back((t * i) % k, 0);
			t *= 10;
		}
	}

	cout << bfs(k) << endl;
}


Measured memory_bytes: 17792
#include <stdio.h>
#define MAX_N 20

int n;
int A[MAX_N];

int dfs(int num, int index) {
  if (num == 0) return 1;
  if (index == n || num < 0) return 0;

  if (dfs(num - A[index], index+1) || dfs(num, index+1)) {
    return 1;
  }
  return 0;
}

int main(void) {
  int i, q;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &q);
  for (i = 0; i < q; i++) {
    int num;
    scanf("%d", &num);
    if (dfs(num, 0)) {
      printf("yes\n");
    } else {
      printf("no\n");
    }
  }

  return 0;
}

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

using namespace std;

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

    double d, t, s;
    cin >> d >> t >> s;
    double tf=(double)d/s;
    if(tf>t) cout << "No" << endl;
    else cout << "Yes" << endl;

	return 0;
}


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

#define REP(i, s, n) for (ll i = s; i < n; i++)
#define setarr(arr, v) for (ll i = 0; i < sizeof(arr)/sizeof(arr[0]); ++i) {arr[i] = v;}
#define pvar(x) cout << #x << " = " << x << endl;
#define mset(x, v) memset(x, v, sizeof(x));
#define fi first
#define se second
#define pb push_back
#define be() begin()
#define en() end()
#define len() length()
#define mp(x, y) make_pair(x, y)

using namespace std;

typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<pll> vpll;
typedef set<ll> sll;
typedef queue<ll> qll;

template<class U, class V>
ostream& operator<<(ostream& os, const pair<U, V>& p) {os << "(" << p.first << ", " << p.second << ")";return os;}

template<class U, class V>
istream& operator>>(istream& in, pair<U, V>& p) {in >> p.first >> p.second;return in;}

namespace cp {
    template <typename T>
    T min (T first) {return first;}
    template <typename T, typename... Args>
    T min (T first, Args... args) {return std::min (first, min (args...));}

    template <typename T>
    T max (T first) {return first;}
    template <typename T, typename... Args>
    T max (T first, Args... args) {return std::max (first, max (args...));}
};

using cp::min;
using cp::max;

ll solve (ll h) {
    if (h == 1) return 1;
    return 1 + (solve (h/2) * 2);
}

int main ()
{
    ll h; cin >> h;
    cout << solve (h) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int i,j;
	int hit,blow;
	int dataA[4],dataB[4];

	while(scanf("%d",&dataA[0])!=EOF) {

		hit=0;
		blow=0;

		for(i=1;i<4;i++){
			scanf("%d",&dataA[i]);
		}
		
		for(i=0;i<4;i++) {
			scanf("%d",&dataB[i]);
		}

		for(i=0;i<4;i++) {
			for(j=0;j<4;j++){
				if(dataA[i] == dataB[j] && i==j) {
					hit++;
				}
				else if(dataA[i] == dataB[j] && i!=j){
					blow++;
				}
			}
		}

		printf("%d %d\n",hit,blow);
		}

		return 0;
}

Measured memory_bytes: 1024
N, M = map(int, input().split())
ans = {}
flg = False
for _ in range(M):
    s, c = map(int, input().split())
    if s == 1 and c == 0:
        if N == 1:
            flg = True
            ans[s] = c
        else:
            print(-1)
            exit()
    else:
        if s in ans.keys():
            if c != ans[s]:
                print(-1)
                exit()
        else:
            ans[s] = c
if flg:
    print(0)
else:
    if N >= 2:
        num = ["1"] + ["0"]*(N-1)
        for k, v in ans.items():
            num[k-1] = str(v)
        print("".join(num))
    else:
        if ans.keys():
            print(ans[1])
        else:
            print(0)


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

int main(void) {
  int N, K;
  cin >> N >> K;
  vector<int> s(N, 0);
  for (int i = 0; i < K; i++) {
    int d;
    cin >> d;
    for (int j = 0; j < d; j++) {
      int A;
      cin >> A;
      A--;
      s[A] += 1;
    }
  }
  int ans = 0;
  for (auto x : s)
    if (x == 0)
      ans++;
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define all(c) (c).begin(),(c).end()
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define iter(c) __typeof((c).begin())
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
#define mem(a) memset(a,0,sizeof(a))
#define pd(a) printf("%.10f\n",a)
#define pb(a) push_back(a)
#define in(a) insert(a)
#define pi M_PI
#define R cin>>
#define F first
#define S second
#define C class
#define ll long long
#define ln cout<<'\n'
#define _(_1,_2,_3,N,...)N
#define pr(...) _(__VA_ARGS__,pr3,pr2,pr1)(__VA_ARGS__)
template<C T>void pr1(T a){cout<<a;ln;}
template<C T,C T2>void pr2(T a,T2 b){cout<<a<<' '<<b;ln;}
template<C T,C T2,C T3>void pr3(T a,T2 b,T3 c){cout<<a<<' '<<b<<' '<<c;ln;}
template<C T>void PR(T a,int n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
bool check(int n,int m,int x,int y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<60,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

ll l[500001],r[500001],d[500001],a[500001],dp[500001],dp2[500001];
void Main() {
  int n;
  R n;
  rep(i,n-1) {
    cin >> l[i] >> r[i];
    l[i]--,r[i]--;
    d[l[i]]=d[r[i]]=d[i]+1;
  }
  a[n-1]=1;
  rrep(i,n-1) {
    a[i]=a[l[i]]+a[r[i]];
    dp[i]=a[i]+dp[l[i]]+dp[r[i]];
    dp2[i]=dp2[l[i]]+dp2[r[i]]+d[i]+2;
    dp2[i]=min(dp2[i],a[l[i]]+dp[l[i]]+dp2[r[i]]+1);
    dp2[i]=min(dp2[i],a[r[i]]+dp[r[i]]+dp2[l[i]]+1);
  }
  pr(dp2[0]);
}
 
int main() {
  ios::sync_with_stdio(0);cin.tie(0);
  Main();return 0;
}


Measured memory_bytes: 24636
n = int(input())
h = list(map(int,input().split()))

o = [0 for i in range(n)]

o[1] = abs(h[1]-h[0])

for i in range(2,n):
    o[i] += min(o[i-1]+abs(h[i]-h[i-1]),o[i-2]+abs(h[i]-h[i-2]))

print(o[-1])


Measured memory_bytes: 13928
#include<bits/stdc++.h>
using namespace std;
using ll =long long;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define SORT(i) sort((i).begin(),(i).end())
constexpr int INF = 2000000000;
constexpr int mod = 1000000007;

int main() {
	int N;cin >> N;
	map<char, int>mp;
	rep(i, N) {
		string s; cin >> s;
		if (s[0] == 'M' || s[0] == 'A' || s[0] == 'R' || s[0] == 'C' || s[0] == 'H') {
			mp[s[0]]++;
		}
	}
	if (mp.size() < 3)cout << 0 << "\n";
	else {
		vector<ll>vec;
		ll ans = 0;
		for (auto p : mp) {
			auto a = p.second;
			vec.push_back(a);
		}
		for (int i = 0;i < vec.size();++i) {
			for (int j = i + 1;j < vec.size();++j) {
				for (int k = j + 1;k < vec.size();++k) {
					ans += vec[i] * vec[j] * vec[k];
				}
			}
		}
		cout << ans << "\n";
	}

	return 0;
}

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

/* 大文字を小文字に変換 */
char tolower(char c) {return (c + 0x20);}
/* 小文字を大文字に変換 */
char toupr(char c) {return (c - 0x20);}

// if('A'<=s[i] && s[i]<='Z') s[i] += 'a'-'A';

/*
string s = "abcdefg"
s.substr(4) "efg"
s.substr(0,3) "abc"
s.substr(2,4) "cdef"

// イテレータ要素のインデックス
distance(A.begin(), itr);
*/

const int INF = 1000100100;
const int MAX_V = 100100, MAX_E = 500500;
const int WHITE = 0, GRAY = 1, BLACK = 2;

int v, e;
vector<P> to[MAX_V];
int dis[MAX_V], color[MAX_V];

void dijkstra(int s){
    fill(dis, dis+MAX_V, INF);
    fill(color, color+MAX_V, WHITE);

    color[s] = BLACK;
    dis[s] = 0;
    priority_queue<P> pq;
    pq.push(make_pair(-dis[s], s));
    while(!pq.empty()){
        P pu = pq.top(); pq.pop();
        int u = pu.second; int udis = -pu.first;
        color[u] = BLACK;
        for(P pv: to[u]){
            int v = pv.first; int vc = pv.second;
            if(color[v] != BLACK && dis[v]>udis+vc){
                dis[v] = udis+vc;
                pq.push(make_pair(-dis[v], v));
            }
        }
    }
}

int main()
{
    int s;
    cin >> v >> e >> s;
    rep(i,e){
        int si, ti, di; cin >> si >> ti >> di;
        to[si].push_back(make_pair(ti, di));
    }

    dijkstra(s);

    rep(i,v){
        if(dis[i] == INF) cout << "INF" << endl;
        else cout << dis[i] << endl;
    }
}


Measured memory_bytes: 13420
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
typedef long long ll;
typedef vector<int> vint;
typedef pair<int, int> pint;
typedef vector<long long> vlong;
typedef vector<string> vstring;
#define vpush(a,x) a.push_back(x);
#define rep(i, n) REP(i, 0, n)
#define all(v) v.begin(), v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)
const int INF = 1 << 30;
const int dx[] = {1,0,-1,0,1,1,-1,-1};
const int dy[] = {0,-1,0,1,1,-1,-1,1};
#define stp(x)  setprecision(x)
const long double PI=3.14159265358979323846264338327950;
int main(){
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int x;
  cin>>x;
  cout<<(x==1?0:1)<<'\n';
  return(0);
}

Measured memory_bytes: 3544
#include <stdio.h>
int main(void){
	int dice[6];
	int swap;				//????????¨
	char c;
	
	int i;
	
	for(i=0;i<6;i++){
		scanf("%d",&dice[i]);
	}
	
	while(scanf("%c",&c)!=EOF){
	
		if(c=='E'){
			swap=dice[0];
			dice[0]=dice[3];
			dice[3]=dice[5];
			dice[5]=dice[2];
			dice[2]=swap;
		}
		if(c=='W'){
			swap=dice[0];
			dice[0]=dice[2];
			dice[2]=dice[5];
			dice[5]=dice[3];
			dice[3]=swap;
		}
		if(c=='S'){
			swap=dice[0];
			dice[0]=dice[4];
			dice[4]=dice[5];
			dice[5]=dice[1];
			dice[1]=swap;
		}	
		if(c=='N'){
			swap=dice[0];
			dice[0]=dice[1];
			dice[1]=dice[5];
			dice[5]=dice[4];
			dice[4]=swap;
		}
	}
	
	printf("%d\n",dice[0]);
	
	return 0;

}



Measured memory_bytes: 2104
#include <iostream>
#include <queue>
#include <stack>
#include <string>
#define MAXN 40
#define MAXM 400
#define INF "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

using namespace std;


class edge{
	public:
		int from;
		int to;
		string cost;
};


void solve(edge E[MAXM],int s,int g,string min[MAXN],int n,int a){
	min[s]="";

	string minD="";
	for(int i=0;i<2*6*n;i++){
		if(i==6*n) minD=min[g];
		for(int j=0;j<a;j++){
			int from=E[j].from;
			int to=E[j].to;

			if((min[from]!=INF) && (min[to]>E[j].cost+min[from])){
				 min[to]=E[j].cost+min[from];
			}
		}
	}
	if(min[g]==minD && min[g]!=INF) cout << min[g] << endl;
	else cout << "NO" << endl;
}


int main(void){

	int n,a,s,g;

	string map[MAXN][MAXN];
	int adX[2]={1,0};
	int adY[2]={0,1};
	string min[MAXN];
	int parent[MAXN];

	edge E[MAXM];


	while(1){
		for(int i=0;i<MAXN;i++){
			min[i]=INF;
			parent[i]=-1;
			E[i].from=-1;
			E[i].to=-1;
			E[i].cost=INF;
		}
		cin >> n;
		if(n==0) return 0;
		cin >> a;
		cin >> s;
		cin >> g;

		for(int i=0;i<a;i++){
			int x,y;
			string lab;
			cin >> x;
			cin >> y;
			cin >> lab;

			E[i].from=y;
			E[i].to=x;
			E[i].cost=lab;
		}

		solve(E,g,s,min,n,a);
	}

	return 0;
}

Measured memory_bytes: 2320
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
 
using namespace std;
 
#define INF 1e9
 
int t,ans,size,diff;
vector<int> a,path;
map<int,int> mp;
 
int calc(int idx,int N){
    int res = 0, p = 1;
    for(int i = N-1 ; i >= idx ; i--){
        res += a[i]*p;
        p *= 10;
    }
    return res;
}
 
void solve(int idx,int val,vector<int> &v){
    if(idx == size){
        if(val > t) return;
        if(t-val <= diff){
            diff = t-val;
            ans = val; mp[ans]++;
            path = v;
        }
        return;
    }
    for(int i = 1 ; i <= size ; i++){
        if(idx + i > size) continue;
        int c = calc(idx,idx+i);
        v.push_back(c);
        solve(idx+i,val+c,v);
        v.pop_back();
    }
}
 
int main(){
    int num;
    while(true){
        cin >> t >> num;
        if(t == 0 && num == 0) break;
        mp.clear(); a.clear(); 
        diff = ans = INF;
        for(int i = 0 ; ; i++){
            if(num == 0) break;
            a.push_back(num%10);
            num /= 10;
        }
        reverse(a.begin(),a.end());
        size = a.size();
        vector<int> v;
        solve(0,0,v);
        if(diff == INF){
            cout << "error" << endl;
        }else{
            if(mp[ans] != 1){
                cout << "rejected" << endl;
            }else{
                cout << ans;
                for(int i = 0 ; i < (int)path.size() ; i++){
                    cout << " " << path[i];
                }
                cout << endl;
            }
        }
    }
    return 0;
}

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

int main() {
  string S;
  cin >> S;
  
  int answer = 0;
  for(int i = 0; i < 4; i++) {
    if(S.at(i) == '+')
      answer++;
    else
      answer--;
  }
  
  cout << answer << endl;
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

constexpr int MOD = 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(int, N);
    vector<int> a(N);
    read(a);

    array<int, 3> p{};
    i64 ans = 1;
    rep(i, 0, N) {
        ans *= count(all(p), a[i]);
        ans %= MOD;

        if (ans == 0) break;
        *find(all(p), a[i]) += 1;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 640
def solve():
  n, m = map(int,input().split())
  plst = list(map(int,input().split()))
  pare_inds = [i for i in range(n)]
  rank = [0 for i in range(n)]
  
  def find(x):
    p = pare_inds[x]
    if p == x:
      return x
    a = find(p)
    pare_inds[x] = a
    return a
  
  def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
      return
    if rank[x] < rank[y]:
      pare_inds[x] = y
    else:
      pare_inds[y] = x
      if rank[x] == rank[y]:
        rank[x] += 1

  def same(x, y):
    return find(x) == find(y)

  for i in range(m):
    x, y = map(int,input().split())
    x, y = x - 1, y - 1
    unite(x, y)
  
  ans = 0
  for i in range(n):
    if same(i, plst[i] - 1):
      ans += 1

  print(ans)
solve()

Measured memory_bytes: 14004
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n;
        int r;
        int tmp[] = new int[50];
        while((n = sc.nextInt()) != 0 && (r = sc.nextInt()) != 0 ){
            int fuda[] = new int[n];
            for(int i=0;i<n;i++){
                fuda[i] = n - i;
            }
            for(int i=0;i<r;i++){
                int p = sc.nextInt();
                int c = sc.nextInt();
                for(int j=0;j<p-1;j++){
                    tmp[j] = fuda[j];
                }
                for(int j=p-1;j<=p+c-2;j++){
                    fuda[j-p+1] = fuda[j];
                }
                for(int j=c;j<=p+c-2;j++){
                    fuda[j] = tmp[j-c];
                }
            }
            System.out.println(fuda[0]);
        }  
        sc.close();
    }
}


Measured memory_bytes: 36808
#include <bits/stdc++.h>
using namespace std;
int main ()
{
    string e, r;
    cin >> e >> r;
    int f=e.size();
    int t=1;
    for (int i=0; i<f; ++i)
        if (e[i]!=r[i])
            t=0;
    if (t==0)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}





Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vl = vector<ll>;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> bool cmax(T& a, U b) { if (a<b) {a = b; return true;} else return false; }
template<class T, class U> bool cmin(T& a, U b) { if (a>b) {a = b; return true;} else return false; }

ll modpow(ll a, ll n, ll p) {
  ll res = 1;
  while (n) {
    if (n&1) res = res * a % p;
    a = a * a % p;
    n >>= 1;
  }
  return res;
}

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

  ll n, k;
  cin >> n >> k;
  vl a(n);
  rep(i, n) {
    cin >> a[i];
  }

  vector<vl> cnt(n+1, vl(n+1));

  rep(i, n) {
    rep(j, n) {
      if (a[i] > a[j]) {
        cnt[i][j+1]++;
      }
    }
  }

  rep(i, n) {
    rep(j, n) {
      cnt[i][j+1] += cnt[i][j];
    }
  }

  const ll mod = 1e9+7;
  ll ans = 0;

  ll tmp = ((k-1) * k /2) % mod;

  rep(i, n) {
    ans += ((cnt[i][n]-cnt[i][i]) * (k%mod)) % mod;
    ans %= mod;
    //ans += (cnt[i][n] * ((k-1) * k * modpow(2, mod-2, mod)))%mod;
    //ans += (cnt[i][n] * (k-1) * k / 2) % mod;
    ans += (cnt[i][n] * tmp) % mod;
    ans %= mod;
  }
  cout << ans%mod << endl;
}


Measured memory_bytes: 31616
#include <bits/stdc++.h>
#define FOR(i,a,b) for(ut i=(a);i<(ut)(b);i++)
#define REP(i,b) FOR(i,0,b)
#define ALL(c) c.begin(),c.end()
#define PB push_back
#define cat //cout << __LINE__ << endl;
using namespace std;
typedef long long LL;
typedef double ld;
typedef LL ut;
typedef vector<ut> VI;
typedef pair<ut,ut> pr;
typedef vector<pr> Vpr;
typedef pair<ut,ut> prs;
const int SIZE=2*1e5;
const LL p=7+1e9;
LL X[SIZE],W[SIZE],D[SIZE];
LL ans[SIZE];
inline void IN(ut &x){cin >> x;}
inline void INA(ut n,ut x[]){REP(i,n) cin >> x[i];}
inline void INE(ut m,VI edges[]){
	ut a,b;
	REP(i,m){
		cin >> a >> b;
		edges[a].PB(b);
		edges[b].PB(a);
	}
}
inline void INEC(ut m,Vpr edges[]){
	ut a,b,c;
	REP(i,m){
		cin >> a >> b >> c;
		edges[a].PB(pr(c,b));
		edges[b].PB(pr(c,a));
	}
}
VI confro;
Vpr last;
int main(){
	LL N,L,T;
	cin >> N >> L >> T;
	REP(i,N){
		cin >> X[i] >> W[i];
		if(W[i]==1) D[i]= (X[i]+T%L)%L;
		else 	 	D[i]= (X[i]-T%L+L)%L;

		last.PB(pr(D[i],W[i]));
	}
	sort(ALL(last));
	LL def=W[0];
	LL hit=0;
	FOR(i,1,N){
		if(def!=W[i]){
			confro.PB(i);
		}
	}
	T*=2;
	LL turns=T/L;
	hit+=turns*confro.size();
	T%=L;
	REP(i,confro.size()){
		int next=confro[i];
		LL dist=X[next]-X[0];
		if(def==2) dist=L-dist;
		if(dist<T) hit++;
	}
	hit%=N;
	int st=0;
	REP(i,N){
		if(D[0]==last[i].first && W[0]==last[i].second) st=i;
	}
	REP(i,N){
		if(def==1) ans[(hit+i)%N]=last[(st+i)%N].first;
		else ans[(N-hit+i)%N]=last[(st+i)%N].first ;
	}
	REP(i,N){
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 9072
x = int(input())
a = 0
if 400 <= x < 600:
  a = 8
if 600 <= x < 800:
  a = 7
if 800 <= x < 1000:
  a = 6
if 1000 <= x < 1200:
  a = 5
if 1200 <= x < 1400:
  a = 4
if 1400 <= x < 1600:
  a = 3
if 1600 <= x < 1800:
  a = 2
if 1800 <= x < 2000:
  a = 1
print(a)

Measured memory_bytes: 9188
import bisect
N = int(input())
A = sorted(list(map(int,input().split())))
B = sorted(list(map(int,input().split())))
C = sorted(list(map(int,input().split())))

ans = 0
for i in range(N):
    a = bisect.bisect_left(A,B[i])
    c = bisect.bisect_right(C,B[i])
    ans += a*(len(C)-c)
print(ans)


Measured memory_bytes: 23092
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
//#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <string>


int main(int argc, char **argv) {
    int A,B;

    std::cin >> A >> B;

    int ret = 0;
    if (A >= B) {
        ret += A;
        A--;
    } else {
        ret += B;
        B--;
    }

    if (A >= B) {
        ret += A;
        A--;
    } else {
        ret += B;
        B--;
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

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

        String str = scanner.nextLine();

        String[] strings = str.split(" ");

        String first = strings[0];
        String second = strings[1];
        String third = strings[2];

        if(first.charAt(first.length()-1) == second.charAt(0) && second.charAt(second.length()-1) == third.charAt(0)){
            System.out.println("YES");
        }else{
            System.out.println("NO");
        }

    }
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
typedef		 long long int    ll;
typedef		vector<ll>      vll;
#define     fi              first
#define     print(v)        for(ll i:v) cout<<i<<ss
#define     se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
#define		gcd(a,b)        __gcd(a,b)
#define		lcm(a,b)        (a*b)/gcd(a,b)
const double eps = 1e-8;



int main()
{

    ll n,k;
    cin>>n>>k;
    ll ar[n+10];
    for(ll i=1; i<=n; i++)
    {
        cin>>ar[i];
    }

    ll dp[n+10];

    for(ll i=1; i<=n; i++)
    {
        dp[i]=1e18;
    }
    dp[1]=0;
    for(ll i=1; i<=n; i++)
    {
        for(ll j=1; j<=k; j++)
        {
            if(i+j>n)
                continue;

            dp[i+j]=min(dp[i+j],dp[i]+abs(ar[i]-ar[i+j]));
        }
   

    }

    

     cout<<dp[n]<<nn;




}


/* Final check before submit :

1. array size or integer overflow,like uninitialised 0 index.

2. Think twice,code once.check all possible counter test case.

3. Be careful about corner case! n=1?k=1? something about 0?

4. avoid stupid mistake!complexity(t/m)?precision error?submit same code twice?

5. if got WA than remember that you are missing something common.
   *** Be confident!!! who knows? may be your one step back to AC ***
4. minus mod ans=(ans-k+mod)%mod;

*/






Measured memory_bytes: 5148
#include <bits/stdc++.h>
using namespace std;
#define INF 1001001001

int main() {
    int N;
    cin >> N;
    vector<int> t(N+3);
    t[0] = t[1] = 0;
    for(int i=1; i<=N; ++i) {
        int tmp; cin >> tmp;
        t[i+1] = t[i] + tmp;
    }
    t[N+2] = t[N+1];
    vector<int> v(N+2);
    v[0] = 0;
    for(int i=1; i<=N; ++i) cin >> v[i];
    v[N+1] = 0;

    int tmax = t[N+2];
    vector<double> v2(2 * tmax + 1, INF);
    for(int i=0; i<=N+1; ++i) {
        for(int tm=0; tm<=2*tmax; ++tm) {
            if(0.5 * tm < t[i]) {
                v2[tm] = min(v2[tm], v[i] + t[i] - 0.5 * tm);
            } else if(0.5 * tm > t[i+1]) {
                v2[tm] = min(v2[tm], v[i] + 0.5 * tm - t[i+1]);
            } else {
                v2[tm] = min(v2[tm], (double)v[i]);
            }
        }
    }

    double ans = 0;
    for(int tm=0; tm<2*tmax; ++tm) {
        ans += 0.25 * (v2[tm] + v2[tm+1]);
    }
    printf("%.4f\n", ans);
    return 0;
}

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

using int64 = long long;
constexpr int MAX = 100000;

int main()
{
    int64 N, K;
    std::cin >> N >> K;
    
    std::vector<int64> sum(MAX + 1);
    for (int i = 0; i < N; i++) {
        int a, b;
        std::cin >> a >> b;
        sum[a] += b;
    }
    
    int64 s = 0;
    for (int i = 1; i <= MAX; i++) {
        s += sum[i];
        if (s >= K) {
            std::cout << i << std::endl;
            break;
        }
    }
    
    return 0;
}


Measured memory_bytes: 1152
# coding: utf-8
from collections import deque
S = deque(input())
Q = int(input())
cnt = 0
for i in range(Q):
    q = input().split()
    if q[0] == "1":
        cnt += 1
    else:
        if (int(q[1]) + cnt) % 2 == 1:
            S.appendleft(q[2])
        else:
            S.append(q[2])
ans = "".join(S)
print(ans if cnt % 2 == 0 else ans[::-1])

Measured memory_bytes: 8692
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int N = ni();
        long[] L = new long[N];
        for (int i = 0; i < N; i++) {
            L[i] = nl();            
        }
        long ans = 1;
        for (int j = 0; j < N; j++) {
            ans = ans /MCD(ans, L[j]) * L[j];
        }
        out.println(ans);
    }

    long MCD(long a, long b){
        if(a>b) MCD(b, a);
        if(a==0) return b;
        return MCD(b%a, a);
    }

    final int mod = 1000000007;
    final BigInteger MOD = BigInteger.valueOf(mod);

    int mul(int x, int y){
        int val = (int)((x * 1L * y) % mod);
        return val>=0 ? val : val+mod;
    }
    int add(int x, int y) {
        x += y;
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    int sub(int x, int y){
        x = add(x,mod-y);
        if(x < 0) x += mod;
        if(x>=mod) x -= mod;
        return x;
    }
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

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

using namespace std;

using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FORE(i, a, b) for(int i=(a);i<=(b);++i)
#define rep(i, n) for(int i=0;i<(n);++i)
#define repe(i, n) for(int i=0;i<=(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define SP cout<<fixed<<setprecision(10)
typedef pair<int, int> P;
const int INF = (int) 1e9;
const int MOD = (int) 1e9 + 7;

int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }

vector<int> g[1000005];
bool memo[1000005];

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int n, m;
	cin >> n >> m;
	rep(i, m) {
		int u, v;
		cin >> u >> v;
		u--, v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	
	vector<int> a, b;
	a.push_back(0);
	memo[0] = true;
	int cur = 0;
	while (1) {
		bool flag = true;
		for (int u:g[cur]) {
			if (!memo[u]) {
				memo[u] = true;
				a.push_back(u);
				cur = u;
				flag = false;
				break;
			}
		}
		if (flag) break;
	}
	
	cur = 0;
	while (1) {
		int flag = true;
		for (int u:g[cur]) {
			if (!memo[u]) {
				memo[u] = true;
				b.push_back(u);
				cur = u;
				flag = false;
				break;
			}
		}
		if (flag) break;
	}
	
	reverse(b.begin(), b.end());
	for (int x:a) b.push_back(x);
	cout << b.size() << endl;
	for (int x:b) cout << x + 1 << " ";
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 28408
//
// Created by yuu on 2019-07-27.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>

using namespace std;


int main(void){
    int A,B;
    cin>>A>>B;

    int C;
    if(A>B){
        swap(A,B);
    }


    C = B-A;

    if(C%2!=0){
        cout<<"IMPOSSIBLE"<<endl;
    }else{
        C = C/2;
        cout<<A+C<<endl;
    }



    return 0;
}

Measured memory_bytes: 256
def solve():
    N, *vl = map(float, open(0).read().split())
    vl.sort()
    
    for _ in range(int(N)-1):
        a, b = vl[0], vl[1]
        vl[1] = (a + b) / 2
        vl = vl[1:]
    
    print(vl[0])

if __name__ == '__main__':
    solve()

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
 
struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while (x->left != NIL) {
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while (x->right != NIL) {
    x = x->right;
  }
  return x;
}

Node treeSearch(Node u, int k){
  if (u == NIL || k == u->key) return u;

  else if (k < u->key) return treeSearch(u->left, k);

  else return treeSearch(u->right, k);

}

Node treeSuccessor(Node x){
  Node y;
  
  if (x->right != NIL) return treeMinimum(x->right);

  y = x->parent;
  while (y != NIL && x == y->right) {
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if (z->left == NIL || z->right == NIL) y = z;
  else y = treeSuccessor(z);

  if (y->left != NIL) x = y->left;
  else x = y->right;

  if(x != NIL) x->parent = y->parent;

  if (y->parent == NIL) root = x;
  else if (y == y->parent->left) y->parent->left = x;
  else y->parent->right = x;

  if (y != z) z->key = y->key;
}


void insert(int k){
  Node y = NIL; //xの親
  Node x = root; //root
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while (x != NIL) {
    y = x;
    if (z->key < x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;

  if (y == NIL) root = z; // T empty
  else if (z->key < y->key) y->left = z;
  else y->right = z;
}

void inorder(Node u){
  if (u != NIL) {
    inorder(u->left);
    printf(" %d", u->key);
    inorder(u->right);
  }
}

void preorder(Node u){
  if (u != NIL) {
    printf(" %d", u->key);
    preorder(u->left);
    preorder(u->right);
  }
}

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 20460
#include<stdio.h>
int main(void){
	int m,d,i,t[12]={0,31,29,31,30,31,30,31,31,30,31,30};
	scanf("%d%d",&m,&d);
	while(m!=0||d!=0){
		for(i=1; i<m; i++){
			t[0]+=t[i];
		}
		t[0]+=d;
		switch(t[0]%7){
		case 1:
			printf("Thursday\n");
			break;
		case 2:
			printf("Friday\n");
			break;
		case 3:
			printf("Saturday\n");
			break;
		case 4:
			printf("Sunday\n");
			break;
		case 5:
			printf("Monday\n");
			break;
		case 6:
			printf("Tuesday\n");
			break;
		case 0:
			printf("Wednesday\n");
			break;
		}
		scanf("%d%d",&m,&d);
		t[0]=0;
	}
	return 0;
}

Measured memory_bytes: 584
import java.util.Scanner;

public class Main {

    public static void main(String[] args) throws Exception {
        Scanner stdIn = new Scanner(System.in);
        int N = stdIn.nextInt();
        int heights[] = new int[N];

        for (int i = 0; i < N; i++) {
            int h = stdIn.nextInt();
            heights[i] = h;
        }

        System.out.println(solve(heights));
    }

    private static int solve(int[] h) {
        int[] w = new int[h.length];

        w[0] = 0;
        w[1] = Math.abs(h[1] - h[0]);

        for (int i = 2; i < h.length; i++) {
            w[i] = Math.min(w[i - 1] + Math.abs(h[i - 1] - h[i]), w[i - 2] + Math.abs(h[i - 2] - h[i]));
        }

        return w[w.length - 1];
    }
}


Measured memory_bytes: 49032
#include <iostream>

long long H, W;
long long num_place = 0;

int main() {
  std::cin >> H >> W;
  if (H == 1 || W == 1) {
    num_place = 1;
  } else {
    long long half_w = W/2;
    num_place += W * (H/2);
    if (H & 1) {
      if (W & 1) {
        num_place += half_w + 1;
      } else {
        num_place += half_w;
      }
  }
  }
  std::cout << num_place << std::endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,M;
  scanf("%d %d", &N, &M);
  
  vector<vector<int>> data(M, vector<int>(2));
  
  for(int i = 0; i < M; i++){
    for(int j = 0; j < 2; j++){
      scanf("%d", &data.at(i).at(j));
    }
  }
  
  vector<int> vecL(M);
  vector<int> vecR(M);
  for(int i = 0; i < M; i++){
    vecL.at(i) = data.at(i).at(0);
    vecR.at(i) = data.at(i).at(1);  
  }
  
  sort(vecL.begin(), vecL.end());
  sort(vecR.begin(), vecR.end());
  
  int ans = vecR.at(0) - vecL.at(M-1) + 1;
  int S = max(ans, 0);
  cout << S << endl; 
}

Measured memory_bytes: 6528
#include<iostream>
#include<vector>
#include<functional>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
//=なし
void recursive_comb(vector<int>&co, int s, int rest,vector<int>a,vector<int>b,vector<int>c,vector<int>d,int* max) {
	if (rest == 0) {
		//do st
		int sum = 0;
		rep(i,a.size()){
			if(co[b[i]-1]-co[a[i]-1]==c[i]){
				sum += d[i];
			}
		}
		if(*max<sum)*max=sum;
		} else {
		if (s < 0) return;
		recursive_comb(co, s - 1, rest,a,b,c,d,max);
		co[rest - 1] = s;
		recursive_comb(co, s - 1, rest - 1,a,b,c,d,max);
	}
}
//=あり
void recursive_comb2(vector<int>&co, int s, int rest,vector<int>a,vector<int>b,vector<int>c,vector<int>d,int* max) {
	if (rest == 0) {
		//do st
		int sum = 0;
		rep(i,a.size()){
			if(co[b[i]-1]-co[a[i]-1]==c[i]){
				sum += d[i];
			}
		}
		if(*max<sum)*max=sum;
		//rep(i,co.size())cout<<co[i]<<" ";
		//cout<<endl;
		} else {
		if (s < 0) return;
		recursive_comb2(co, s - 1, rest,a,b,c,d,max);
		co[rest - 1] = s;
		recursive_comb2(co, s, rest - 1,a,b,c,d,max);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k,vector<int>a,vector<int>b,vector<int>c,vector<int>d,int*max) {
	vector<int> co(k);
	recursive_comb2(co, n - 1, k,a,b,c,d,max);
}
int main(){
	int n,m,q;
	cin>>n>>m>>q;
	vector<int>a(q),b(q),c(q),d(q);
	rep(i,q)cin>>a[i]>>b[i]>>c[i]>>d[i];
	int max = 0;
	foreach_comb(m,n,a,b,c,d,&max);
	cout<<max<<endl;
	return 0;
}

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

int main(){
    int a[32] = { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int n;
    cin >> n;
    cout << a[n - 1] << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define io ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
const int N=2e5+100;
using namespace std;	
int main()
{
	
	string s;
	while(cin>>s)
	{
		int n=s.length();
		LL ans=0;
		LL tmp=0;
		for(int i=0;i<(1<<(n-1));i++)
		{
			tmp=0;
			for(int j=0;j<n;j++)
			{
				tmp=tmp*10+(int)(s[j]-'0');
				if((i>>j)&1||j==n-1)
				{
					ans+=tmp;
					tmp=0;
				}
			}
		}
		cout<<ans<<endl;
		
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
template<typename T> inline void chkmin(T &a, const T &b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T &a, const T &b) { a = a > b ? a : b; }

const int MAXN = 305;
int C[MAXN][MAXN], f[MAXN][MAXN], n, m, MOD;

int main() {
	scanf("%d%d%d", &n, &m, &MOD);
	for (int i = 1; i <= m + 1; i++) f[0][i] = 1;
	for (int i = C[0][0] = 1; i <= n; i++)
	for (int j = C[i][0] = 1; j <= i; j++)
		C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
	for (int i = 1; i <= n; i++)
	for (int k = m; k > 0; k--) {
		f[i][k] = f[i][k + 1];
		for (int j = 1; j <= i; j++)
			f[i][k] = (f[i][k] + (LL)f[j - 1][k + 1] * f[i - j][k] % MOD * C[i][j - 1]) % MOD;
	}
	printf("%d\n", f[n][1]);
	return 0;
}

Measured memory_bytes: 1024
fn main() {
    let n: i32 = read();

    let mut total_count = 0;

    // 1以上N以下の整数
    for i in 1..(n + 1) {
        if i % 2 == 0 {
            // 偶数は対象外
            continue;
        }
        // 整数iの約数の個数を調べる
        let mut count = 0;
        for j in 1..(i + 1) {
            if i % j == 0 {
                count += 1;
            }
        }

        if count == 8 {
            total_count += 1;
        }
    }

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

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}



Measured memory_bytes: 2096