akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        s: String
    }

    let ans = if s.as_str() <= "2019/04/30" {
        "Heisei"
    } else {
        "TBD"
    };

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


Measured memory_bytes: 4352
/*
ID: anonymo14
TASK: wormhole
LANG: C++                 
*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pair<int,int>> vpii;

#define F first
#define S second
#define PU push
#define PUF push_front
#define PUB push_back
#define PO pop
#define POF pop_front
#define POB pop_back

#define REP(i,a,b) for(int i=a; i<=b; i++)

#define MOD 1000000007

void solve(int test_case) {//227
	int n;
	cin>>n;
	vi a(n),b(n),c(n);
	vector<pair<ll,ll>> brr(n);
	for(int &i:a)cin>>i;
	for(int &i:b)cin>>i;
	for(int &i:c)cin>>i;
	sort(c.begin(),c.end());
	sort(b.begin(),b.end());
	REP(i,0,n-1) {
		//cerr<<c.end()-upper_bound(c.begin(),c.end(),b[i])<<"\n";
		brr[i]={b[i],c.end()-upper_bound(c.begin(),c.end(),b[i])};
	}
	for(int i=n-2;i>=0;i--) {
		//cerr<<brr[i].S+brr[i+1].S<<"\n";
		brr[i]={brr[i].F,brr[i].S+brr[i+1].S};
	}
	ll sum = 0;
	for(int i:a) {
		pair<ll,ll> p ={i,LONG_MAX};
		//cerr<<brr[(upper_bound(brr.begin(),brr.end(),p)-brr.begin())].S<<"\n";
		auto up = upper_bound(brr.begin(),brr.end(),p);
		if(up-brr.begin()<n)
		sum+=brr[(up-brr.begin())].S;
	}
	cout<<sum;
}

int main() {
	
	////// FILE BASED IO////
	//freopen("wormhole.in", "r", stdin);
	//freopen("wormhole.out", "w", stdout);
	///////////////
	
	ios::sync_with_stdio(0);
	cin.tie(0);
	int t=1;
	//cin>>t;
	REP(i,1,t) {
		solve(i);
	}
	return 0;
}	


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

int main(){
  int N;
  vector<int>A;
  cin >>N;

  for (int i = 0; i<N;i++){
    int x;
    cin >>x;
    A.push_back(x);
  }

  sort(A.begin(),A.end());
  cout <<abs(A[0]-A[(int)A.size()-1])<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mp make_pair
#define mt make_tuple
#define ll long long
#define eb emplace_back
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define mod(a,b) ((a%b +b)%b)
#define bit(x,i) (x&(1<<i))  //select the bit of position i of x
#define lowbit(x) ((x)&((x)^((x)-1))) //get the lowest bit of x
#define hBit(msb,n) asm("bsrl %1,%0" : "=r"(msb) : "r"(n)) //get the highest bit of x, maybe the fastest
#define max(a,b) (a<b?b:a)
#define min(a,b) (a>b?b:a)
#define abs(x) (x<0?(-x):x) 
#define IN(i,l,r) (l<i&&i<r)
#define LINR(i,l,r) (l<=i&&i<=r)
#define LIN(i,l,r) (l<=i&&i<r)
#define INR(i,l,r) (l<i&&i<=r)
#define lastEle(vec) vec[vec.size()-1] 
#define SZ(x) ((int)((x).size()))
#define FOREACH(i,t) for (typeof(t.begin()) i=t.begin(); i!=t.end(); i++) 
#define ll long long 
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define INF 1001001001
#define PI 3.1415926535897932384626

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;

int av (int n){
    if( n<0){
        return -n;
    }
    return n;
}

int main(){
    std::ios_base::sync_with_stdio(false); cin.tie(0);
    int n;
    cin >> n;
    vi arr (n);
    forn(i,n){
        cin >> arr[i];
    }
    vi sol (n);
    sol[0] = 0;
    sol[1] = av(arr[1] - arr[0]);
    for(int i = 2;i < n;i++){
        int a = sol[i-2] + av (arr[i] - arr[i-2]);
        int b = sol[i-1] + av (arr[i] - arr[i-1]);
        sol[i] = min(a,b);
    }
    cout << av(sol[n-1]) << endl;
    return 0;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
int PREP = (cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(9), 0);
//int SEGV = getenv("D") || (exit(system("D= SEGFAULT_SIGNALS=all catchsegv ./prog.exe") >> 8), 0);
const Int MOD = 1000000007;
Int TWO[200001];
int main() {
    TWO[0] = 1;
    for (int i = 1; i <= 200000; i++) TWO[i] = 2 * TWO[i - 1] % MOD;
    int N; cin >> N;
    int zero = 0;
    using Tup = tuple<Int, Int, Int>;
    map<Tup, int> M;
    for (int i = 0; i < N; i++) {
        Int a, b; cin >> a >> b;
        if (a == 0 && b == 0) {
            zero += 1;
        } else {
            int sign = 1;
            if ((a < 0) ^ (b < 0)) sign = -1;
            if (a == 0 || b == 0) sign = 1;
            Int g = gcd(abs(a), abs(b));
            M[Tup(sign, abs(a) / g, abs(b) / g)] += 1;
        }
    }
    Int ans = 1;
    for (auto &p : M) {
        if (p.second == -1) continue;
        auto [s, a, b] = p.first;
        auto other = Tup(-s, b, a);
        if (a == 0 || b == 0) get<0>(other) = 1;
        if (M.count(other)) {
            ans = (TWO[p.second] + TWO[M[other]] + MOD - 1) % MOD * ans % MOD;
            M[other] = -1;
        } else {
            ans = ans * TWO[p.second] % MOD;
        }
    }
    cout << (ans + MOD - 1 + zero) % MOD << '\n';
    return 0;
}


Measured memory_bytes: 20808
n = int(input())
h = list(map(int, input().split()))
ans = [0] * n

for i in range(1, n):
    if i-1 == 0:
        ans[i] = abs(h[i]-h[i-1])
    elif i-1 == 1:
        ans[i] = min(ans[i-1]+abs(h[i]-h[i-1]), abs(h[i]-h[i-2]))
    else:
        ans[i] = min(ans[i-1]+abs(h[i]-h[i-1]), ans[i-2]+abs(h[i]-h[i-2]))

print(ans[-1])

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

int main() {
  int n, hp = 0, b;
  cin >> n;
  vector<int> a(n), c(n + 1);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  for(int i = 0; i < n; i++) {
    cin >> b;
    hp += b;
  }
  for(int i = 1; i < n; i++) cin >> c.at(i);
  for(int i = 1; i < n; i++) {
    if((a.at(i) - 1) == a.at(i - 1)) hp += c.at(a.at(i - 1));
  }
  cout << hp << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(int i = 1;i <= n;i++)
#define ll long long
#define INF 1999999999
#define MINF -1999999999
#define INF64 1999999999999999999
#define ALL(n) n.begin(),n.end()
#define ABS(a,b) max(a,b) - min(a,b)


int main() {
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(0, a + b - n) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
using namespace std;
int f(double x){
	return x * x;
}

 int main()
 {
 	int D, E;
 	while(1){
 		cin >> D >> E;
 		double min = 1000000;
 		if(D == 0 && E == 0)	break;
 		for(double i = 0; i <= D/2; i++){
 			for(double j = D; j >= D/2; j--){
 				if(i + j == D){
 					if(min > fabs(sqrt(f(i) +f(j))-E)){
 						min = fabs(sqrt(f(i) +f(j))-E);
 					}
 				}
 			}
 		}
 		cout << min << endl;
 	}
 	
 	
 	return 0;
 }


Measured memory_bytes: 3224
#include <stdio.h>

int main(void) {
    int q, c, a, n;
    int i;

    scanf("%d", &q);

    for (i=0; i<q; i++) {
        int count = 0;
        scanf("%d %d %d", &c, &a, &n);

        while (c > 0 && a > 0 && n > 0) {
            count++;
            c--;
            a--;
            n--;
        }

        while (c >= 2 && a > 0) {
            count++;
            c -= 2;
            a--;
        }

        while (c >= 3) {
            count++;
            c -= 3;
        }

        printf("%d\n", count);
    }

    return 0;
}

Measured memory_bytes: 600
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCorder1
{
    class AtCorder160B
    {
        static void Main(string[] args)
        {

            var moneyInParse = Console.ReadLine();

            int moneyOutFh = int.Parse(moneyInParse) / 500;

            int moneyOutF = (int.Parse(moneyInParse) - 500 * moneyOutFh) / 5;

            Console.WriteLine(moneyOutFh * 1000 + moneyOutF * 5);

        
        }
    }
}


Measured memory_bytes: 13140
import sys
input = sys.stdin.readline
n, k = map(int,input().split())
A = list(map(int,input().split()))
S = [0]
for i in range(n):
    S.append(A[i] + S[-1])
B = []
for i in range(len(S)):
    for j in range(i+1, len(S)):
        B.append(S[j] - S[i])
# B.sort()
# print(B)

ans = 0
for i in range(50, -1, -1):
    ans += 2**i
    c = 0
    for j in range(len(B)):
        if B[j] & ans == ans:
            c += 1
    # print(i, c)
    if c < k:
        ans -= 2**i
print(ans)

Measured memory_bytes: 65916
#include<stdio.h>
#include<string>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    int a[200005]={};
    int ball[200005];
    int ballsum=0;
    REP(i,200005)ball[i]=-1;
    scanf("%d",&n);
    REP(i,n)scanf("%d",&a[i+1]);
    for(int i=n;i>0;i--){
        int sum=0;
        for(int j=i*2;j<=n;j+=i)sum+=ball[j];
        sum%=2;
        if(sum==a[i])ball[i]=0;
        else 
        {
            ball[i]=1;
            ballsum++;
        }
    }
    printf("%d\n",ballsum);
    REP(i,n)if(ball[i+1]==1)printf("%d ",i+1);
    printf("\n");
    return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h> 
using namespace std;
#define rep(i, N) for(int i=0; i<N; i++)
typedef long long ll;
#define dump(x) cerr<<#x<<"="<<x<<endl
using P = pair<int, int>;

int main() {
  ll a; 
  string b;
  cin >> a >> b;
  string t;
  rep(i, b.size()){
    if(b.at(i)=='.'){
      continue;
    }
    else{
      t+=b.at(i);
    }
  }
  int c = stoi(t);
  ll ans = a*c;
  ans /= 100;

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3632
#include<stdio.h>
#include<string.h>
void swap (int *x, int *y) {
  int temp;    // 値を一時保存する変数

  temp = *x;
  *x = *y;
  *y = temp;
}

/***
* pivotを決め、
* 全データをpivotを境目に振り分け、
* pivotの添え字を返す
***/
int partition (long array[], int left, int right) {
  int i, j, pivot;
  i = left;
  j = right + 1;
  pivot = left;   // 先頭要素をpivotとする

  do {
    do { i++; } while (array[i] < array[pivot]);
    do { j--; } while (array[pivot] < array[j]);
    // pivotより小さいものを左へ、大きいものを右へ
    if (i < j) { swap(&array[i], &array[j]); }
  } while (i < j);

  swap(&array[pivot], &array[j]);   //pivotを更新

  return j;
}

/* クイックソート */
void quick_sort (long array[], int left, int right) {
  int pivot;

  if (left < right) {
    pivot = partition(array, left, right);
    quick_sort(array, left, pivot-1);   // pivotを境に再帰的にクイックソート
    quick_sort(array, pivot+1, right);
  }
}

int main(void){
   int N,flag=0;
   long A[200001];
   scanf("%d",&N);
   for(int i=0;i<N;i++){
      scanf("%ld",&A[i]);
   }
   quick_sort(A,0,N-1);
   for(int i=0;i<N;i++){
      if(A[i]==A[i+1]){
         flag=1;
         break;
      }
   }
   if(flag==1){
      printf("NO");
   }else{
      printf("YES");
   }
   return 0;
}


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

void maxHeap( vector<int> &A, int i )
{
	int H = A.size() - 1;
	int l = i * 2;
	int r = i * 2 + 1;
	int ma = i;
	if( l <= H && A[l] > A[i] ) {
		ma = l;
	}
	if( r <= H && A[r] > A[ma] ) {
		ma = r;
	}
	if( ma != i ) {
		swap( A[i], A[ma] );
		maxHeap( A, ma );
	}
}

int main()
{
	int H;
	cin >> H;
	vector<int> A( H + 1 );
	for( int i = 1; i <= H; i++ ) {
		cin >> A[i];
	}

	for( int i = H / 2; i > 0; i-- ) {
		maxHeap( A, i );
	}

	for( int i = 1; i <= H; i++ ) {
		cout << " " << A[i];
	}
	cout << endl;
}



Measured memory_bytes: 4524
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <cmath>
#include <iomanip>

int main(){
    std::vector<int> v(6);
    for (int i = 0; i < 6; i++) {
        std::cin >> v[i];
    }

    std::string s;

    std::cin >> s;

    for (int i = 0; i < s.length(); i++) {
        if (s[i] == 'E') {
            char tmp = v[0];
            v[0] = v[3];
            v[3] = v[5];
            v[5] = v[2];
            v[2] = tmp;
        } else if (s[i] == 'S') {
            char tmp = v[0];
            v[0] = v[4];
            v[4] = v[5];
            v[5] = v[1];
            v[1] = tmp;
        } else if (s[i] == 'N') {
            char tmp = v[0];
            v[0] = v[1];
            v[1] = v[5];
            v[5] = v[4];
            v[4] = tmp;
        } else {
            char tmp = v[0];
            v[0] = v[2];
            v[2] = v[5];
            v[5] = v[3];
            v[3] = tmp;
        }
    }

    std::cout << v[0] << std::endl;

    return 0;
}

Measured memory_bytes: 3152
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices.ComTypes;

class Program
{
    
    static void Main(string[] args)
    {
        int x = crI();
        if (x >= 30) Console.WriteLine("Yes");
        else Console.WriteLine("No");
    }

    




    //入力受け取り用
    static string crS() { return Console.ReadLine(); }
    static int crI() { return int.Parse(Console.ReadLine()); }
    static int[] arrInt(){return Console.ReadLine().Split(' ').Select(v => int.Parse(v)).ToArray();}
    static long[] arrLong(){ return Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray(); }
    static string[] arrStr(){return Console.ReadLine().Split(' ').ToArray();}
    static List<int[]> mapInt(int h)
    {
        List<int[]> mapInt = new List<int[]>();
        for (int i = 0; i < h; i++)
        {
            mapInt.Add(arrInt());
        }
        return mapInt;
    }

    static List<string[]> mapStr(int h)
    {
        List<string[]> mapStr = new List<string[]>();
        for (int i = 0; i < h; i++)
        {
            mapStr.Add(arrStr());
        }
        return mapStr;
    }

    static List<char[]> mapChar(int h)
    {
        List<char[]> mapChar = new List<char[]>();
        for (int i = 0; i < h; i++)
        {
            string s = crS();
            mapChar.Add(s.ToCharArray());
        }
        return mapChar;
    }

    static List<char[]> mapCharCopy(List<char[]> map)
    {
        List<char[]> copyMap = new List<char[]>();
        foreach (var arr in map)
        {
            List<char> list = new List<char>();
            foreach (var ele in arr)
            {
                list.Add(ele);
            }
            copyMap.Add(list.ToArray());
        }
        return copyMap;
    }
}

Measured memory_bytes: 27372
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
#include <cassert>
//#include <boost/multiprecision/cpp_int.hpp>
#include <complex>
#include <cstdio>
#include <list>

//< in.txt > out.txt
using namespace std;
//std::ios::sync_with_stdio(false);
//std::cin.tie(0);
const long long MOD = 1e9 + 7;
typedef long long LL;
typedef long double LD;
typedef pair<LL, LL> PLL;
typedef pair<LD, LL> PDL;
typedef pair<LD, LD> PDD;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;
//typedef boost::multiprecision::cpp_int bigint;

template<class T>
void in(T& x) {
	cin >> x;
}

template<class T1,class T2>
void in(pair<T1, T2>& p) {
	in(p.first);
	in(p.second);
}

template<class T>
void in(vector<T>& v,LL st=-1,LL en=-1) {
	if (st == -1) {
		st = 0;
		en = v.size() - 1;
	}
	for (LL n = st; n <= en; n++) {
		in(v[n]);
	}
}

int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	string S;
	cin >> S;
	LL N = S.size();
	VLL A(N);
	LL K;
	cin >> K;
	for (LL n = 0; n < N; n++) {
		A[n] = S[n] - '0';
	}
	LL ans = 1;
	for (LL k = 0; k < K; k++)ans *= (N-1 - k);
	for (LL k = 1; k <= K; k++)ans /= k;
	for (LL k = 0; k < K; k++)ans *= 9;
	vector<VVLL> DP;
	DP.resize(N, VVLL(2, VLL(K + 1, 0)));
	DP[0][0][1] = A[0] - 1;
	DP[0][0][0] = 0;
	DP[0][1][1] = 1;
	DP[0][1][0] = 0;
	for (LL n = 1; n < N; n++) {
		DP[n][0][0] += DP[n - 1][0][0];
		if (A[0] > 0)DP[n][0][0] += DP[n - 1][1][0];
		else DP[n][1][0] += DP[n - 1][1][0];
		for (LL k = 1; k <= K; k++) {
			DP[n][0][k] += 9 * DP[n - 1][0][k - 1];
			DP[n][0][k] += DP[n - 1][0][k];
			if (A[n] > 0) {
				DP[n][0][k] += (A[n] - 1) * DP[n - 1][1][k - 1];
				DP[n][0][k] += DP[n - 1][1][k];
				DP[n][1][k] += DP[n - 1][1][k - 1];
			}
			else DP[n][1][k] += DP[n - 1][1][k];
		}
	}
	cout << ans+DP[N-1][0][K] + DP[N-1][1][K] << "\n";
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		String sb = s.nextLine();
		int na = sb.length();

		String ans = "yes";
		int i = 0;
		int j = 1;

		for (i = 0; i < na; i++) {
			for (j = 1; j < na - i; j++) {
				String a = sb.charAt(i) + "";
				String b = sb.charAt(j + i) + "";
				if (a.equals(b)) {
					ans = "no";
					break;
				}

			}
		}
		System.out.println(ans);
	}

}

Measured memory_bytes: 23764
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
int n;
vector<int> g[100000];
string c;
int deg[100000];
bool nuee[100000];
int ct, ct2;
int dmx[100000];
bool used[100000];
void dfs(int x){
    used[x]=1;
  int d0=1;
  if((c[x]=='B' && deg[x]%2==1) || (c[x]=='W' && deg[x]%2==0)) d0++;
  else d0--;
    for(auto y:g[x]){
        if(used[y] || nuee[y]) continue;
        dfs(y);
        dmx[x]=max(dmx[y]+d0, dmx[x]);
    }
}
int dmx1[100000], ans[100000];
void dfs2(int x){
    used[x]=1;
    int mx=0, mx2=0;
  int d0=1;
  if((c[x]=='B' && deg[x]%2==1) || (c[x]=='W' && deg[x]%2==0)) d0++;
  else d0--;
    for(auto y:g[x]){
      if(nuee[y]) continue;
        if(used[y]){
            if(mx<dmx1[x]){
                mx2=mx;
                mx=dmx1[x];
            }else if(mx2<dmx1[x]){
                mx2=dmx1[x];
            }
        }else{
            if(mx<dmx[y]+d0){
                mx2=mx;
                mx=dmx[y]+d0;
            }else if(mx2<dmx[y]+d0){
                mx2=dmx[y]+d0;
            }
        }
    }
    for(auto y:g[x]){
        if(used[y] || nuee[y]) continue;
      int d1=1;
  if((c[y]=='B' && deg[y]%2==1) || (c[y]=='W' && deg[y]%2==0)) d1++;
  else d1--;
        if(mx==dmx[y]+d0){
            dmx1[y]=mx2+d1;
        }else{
            dmx1[y]=mx+d1;
        }
    }
    ans[x]=2*(ct-1)+ct2-max(dmx[x], dmx1[x]);
    for(auto y:g[x]){
        if(!used[y] && !nuee[y]) dfs2(y);
    }
}
 
int main()
{
    cin>>n;
    for(int i=0; i<n-1; i++){
        int u, v;
        cin>>u>>v;
        u--; v--;
      deg[u]++;
      deg[v]++;
        g[u].push_back(v);
        g[v].push_back(u);
    }
  cin>>c;
  if(n==1){
    if(c[0]=='B') cout<<0<<endl;
    else cout<<1<<endl;
    return 0;
  }
  queue<int> que;
  for(int i=0; i<n; i++){
    if(c[i]=='B' && deg[i]==1) que.push(i);
  }
  while(!que.empty()){
    int x=que.front();
    que.pop();
    nuee[x]=1;
    for(auto y:g[x]){
      if(nuee[y]) continue;
      deg[y]--;
      if(deg[y]==1 && c[y]=='B') que.push(y);
    }
  }
  int s=-1;
  for(int i=0; i<n; i++){
    if(!nuee[i]){
      s=i; ct++;
      if((deg[i]%2==1 && c[i]=='B') || (deg[i]%2==0 && c[i]=='W')) ct2++;
    }
  }
  if(s==-1){
    cout<<0<<endl;
    return 0;
  }
    dfs(s);
    fill(used, used+n, 0);
    dfs2(s);
  int ans0=1e9;
    for(int i=0; i<n; i++){
      if(!nuee[i]) ans0=min(ans[i], ans0);
    }
  cout<<ans0<<endl;
    return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
using namespace std;
typedef long long lli;
typedef double lld;
#define mod 1000000007
#define mod2 998244353
#define fori(n) for (int i = 0; i < n; i++)
#define forj(n) for (int j = 0; j < n; j++)
#define pb push_back
#define F first
#define S second
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl "\n"
template <typename T, typename U>ostream &operator<<(ostream &out, const pair<T, U> &p){out << "(" << p.first << ", " << p.second << ")";return out;}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>void print(const ContainerType<ValueType, Args...> &c){for (const auto &v : c)cout << v << ' ';cout << '\n';} void print(){cout<<'\n';}
template <typename T, typename... Args>void print(T a, Args... args){cout << a << " ";print(args...);}
lli llipower(lli x, lli y, lli p = LLONG_MAX){lli res = 1;x = x % p;while (y > 0){if (y & 1)res = (res * x) % p;y = y >> 1;x = (x * x) % p;}return res;}

//8====================================D

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

    fori(n) cin>>a[i];
    lli tot=0;
    fori(n) tot^=a[i];
    fori(n){
        cout<<(tot^a[i])<< " ";
    }
    cout<<endl;
}

Measured memory_bytes: 4840
#include <bits/stdc++.h>
using namespace std;
 
#define int         long long
#define endl        "\n"
#define pii         pair<int, int>
 
 
void solve(int TC) {
    int a, b; cin >> a >> b;
    int c = a + b;
    if(c >= 10) {
        cout << "error";
    } else {
        cout << c;
    }
}
 
signed main() {
 
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(12);
 
 
    int T = 1;
    //cin >> T;
    for(int i=1; i<=T; i++) {
        solve(i);
    }
    return 0;
 
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
int n,k,a;vector<int> e[2010];
int t(int x,int p,int d,int mx){
	if(d==mx)return 1;
	int s=1;
	for(int i:e[x])if(i!=p)s+=t(i,x,d+1,mx);
	return s;
}
int main(){
	cin>>n>>k;
 	REP(i,n-1){
		int a,b;cin>>a>>b;a--;b--;
		e[a].push_back(b),e[b].push_back(a);
	}
	if(k%2==0)REP(i,n)a=max(a,t(i,-1,0,k/2));
	else REP(i,n)for(int j:e[i])a=max(a,t(i,j,0,k/2)+t(j,i,0,k/2));
	cout<<n-a;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define PI 3.14159265358979323846
#define MAXINF (1e18L)
#define INF (1e9L)
#define EPS (1e-9)
#define MOD ((ll)(1e9+7))
#define REP(i, n) for(int i=0;i<int(n);++i)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define ALL(v) v.begin(),v.end()
#define FIND(v,x) (binary_search(ALL(v),(x)))
#define SORT(v) sort(ALL(v))
#define RSORT(v) sort(ALL(v));reverse(ALL(v))
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define pb push_back
#define fi first
#define se second
using namespace std;
template<class A>void pr(A a){cout << (a) << endl;}
template<class A,class B>void pr(A a,B b){cout << a << " "  ;pr(b);}
template<class A,class B,class C>void pr(A a,B b,C c){cout << a << " " ;pr(b,c);}
template<class A,class B,class C,class D>void pr(A a,B b,C c,D d){cout << a << " " ;pr(b,c,d);}
template<class T> inline bool chmin(T& a, T b){return a>b ? a=b, true : false;}
template<class T> inline bool chmax(T& a, T b){return a<b ? a=b, true : false;}
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll,ll> pll;

int main(void)
{
    int S,W;
    cin >> S >> W;
    if(S<=W){
        pr("unsafe");
    }else{
        pr("safe");
    }
}

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

#define times(n, i)      uptil(0, n, i)
#define upto(f, t, i)    for(decltype(t) _##i = (t), i = (f); i <= _##i; i++)
#define uptil(f, t, i)   for(decltype(t) _##i = (t), i = (f); i < _##i; i++)
#define downto(f, t, i)  for(decltype(t) _##i = (t), i = (f); i >= _##i; i--)
#define downtil(f, t, i) for(decltype(t) _##i = (t), i = (f); i > _##i; i--)
#define unless(c) if(!(c))
#define until(c) while(!(c))
#define loop while(true)

#define all(v) v.begin(), v.end()
#define ln << "\n"

struct line{};

template<class T> istream& operator>>(istream& in, vector<T>& v) {
    times(v.capacity(), i) in >> v[i];
    return in;
}

template<class T> const ostream& operator<<(ostream& out, const vector<T>& v) {
    times(v.size(), i) out << (i ? " " : "") << v[i];
    return out;
}

template<class T, class...U> typename enable_if<is_same<T, line>::value, string>::type next(istream& in, const U&... args) {
    string s;
    getline(in, s, args...);
    return move(s);
}

template<class T, class...U> typename enable_if<!is_same<T, line>::value, T>::type next(istream& in, const U&... args) {
    T t(args...);
    in >> t;
    return move(t);
}
template<class T, class...U> auto next(const U&... args) -> decltype(next<T>(cin)) {
    return next<T>(cin, args...);
}

template<class T> T sum(const vector<T>& v) {
    T ans = T();
    for(const T& t : v) ans += t;
    return ans;
}

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

    times(2, i) {
        auto a = next<vector<int>>(10);
        sort(all(a));
        cout << a[7] + a[8] + a[9] << (i ? '\n' : ' ');
    }

    return 0;
}

Measured memory_bytes: 1216
from operator import itemgetter

# input
N = int(input())
S, P = ['0']*N, [0]*N
SP = []
for i in range(N):
    tmp_s, tmp_p = map(str, input().split())
    S[i], P[i] = tmp_s, tmp_p
    SP.append((tmp_s,int(tmp_p)))

# 点数で逆順ソート
SSP = sorted(SP, key=itemgetter(1), reverse=True)
# 名前で昇順ソート
SSP = sorted(SSP, key=itemgetter(0))

answer = [0]*N
for i in range(N):
    for j in range(N):
        if SSP[i] == SP[j]:
            answer[i] = j+1

for i in answer:
    print(i)


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


short ans[4][4]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,0}};

int diff1(short s1[4][4], short s2[4][4]){
  int sum=0;
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      if(s1[i][j] != s2[i][j])sum++;
    }
  }
  return sum;
}


int diff2(short s1[4][4]){
  int sum = 0;
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      int x,y; //correct pos
      if(s1[i][j]==0){ continue; }
      else{
	y = (s1[i][j]-1)/4;
	x = (s1[i][j]-1)%4;
      }
      
      sum += abs(i-y) + abs(j-x);
    }
  }
  return sum;
}


void swap(short& a, short& b){ int tmp=a; a=b; b=tmp; }


int solve(short state[4][4], int step, int depth, int sx,int sy, int prex, int prey){
  
  if(diff1(state,ans)==0)return step;
  if(step + diff2(state) > depth)return -1;

  //up
  if(sy>0 && sy-1 != prey){
    swap(state[sy][sx] , state[sy-1][sx]);
    int res=solve(state, step+1, depth, sx, sy-1, sx,sy);
    if(res != -1)return res;
    swap(state[sy][sx] , state[sy-1][sx]);
  }
  //down
  if(sy<3 && sy+1 != prey){
    swap(state[sy][sx] , state[sy+1][sx]);
    int res=solve(state, step+1, depth, sx, sy+1, sx,sy);
    if(res != -1)return res;
    swap(state[sy][sx] , state[sy+1][sx]);
  }
  //left
  if(sx>0 && sx-1 != prex){
    swap(state[sy][sx] , state[sy][sx-1]);
    int res=solve(state, step+1, depth, sx-1, sy, sx,sy);
    if(res != -1)return res;
    swap(state[sy][sx] , state[sy][sx-1]);
  }
  //right
  if(sx<3 && sx+1 != prex){
    swap(state[sy][sx] , state[sy][sx+1]);
    int res=solve(state, step+1, depth, sx+1, sy, sx,sy);
    if(res != -1)return res;
    swap(state[sy][sx] , state[sy][sx+1]);
  }

  return -1;
}



int main(){
  short input[4][4];
  int sx,sy;
  
  for(int i=0; i<4; i++){
    for(int j=0; j<4; j++){
      cin >> input[i][j];
      if(input[i][j]==0){ sx=j, sy=i; }
    }
  }


  
  int depth = 1;
  int step;
  while((step=solve(input,0,depth,sx,sy,sx,sy)) == -1 ){
    depth++;
  }

  cout << step << endl;

}



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


#define ll              long long int
#define fo(i,n)         for(int i=0;i<n;i++)
#define rfo(i,n)        for(int i=n-1;i>=0;i--)
#define Ull             unsigned long long
#define pb              push_back
#define F               first
#define S               second
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<ll,ll>
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);
#define tr(it, a)       for(auto it = a.begin(); it != a.end(); it++)
#define deb(x)          cout << #x << "=" << x << endl
#define deb2(x, y)      cout << #x << "=" << x << "," << #y << "=" << y << endl

const int N = 2;
const ll MOD = 1e9 + 7;


ll dx[4] = { -1, 1, 0, 0};
ll dy[4] = {0, 0, 1, -1};


bool comp(const pll &p1, const pll &p2)
{
	if (p1.first == p2.first)
		return p1.second > p2.second;

	else
		return p1.first > p2.first;
}

bool isPrime(ll x)
{
	if (x < 2)
		return false;

	if (x <= 3) return true;

	if (x % 2 == 0 || x % 3 == 0) return false;

	for (ll i = 5; i <= sqrt(x); i += 6)
	{
		if (x % i == 0 || x % (i + 2) == 0)
			return false;
	}

	return true;
}

bool vis[1000001];














void Solve()
{
	ll x, y;
	cin >> x >> y;
	if (y % 2 == 0)
	{

		if (y >= 2 * x && y <= 4 * x)
			cout << "Yes" << "\n";

		else
			cout << "No" << "\n";
	}

	else
		cout << "No" << "\n";






}







int main()
{

	FastRead;
	int T = 1;
	//cin >> T;

	while (T--)
	{
		Solve();
	}


	return 0;
}







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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N, std::vector<long long> a) {
    vvi dp(N + 1, vi(N + 1, 0));
    for (int i = 1; i <= N; i++) {
        rep(l, N - i + 1) {
            int r = l + i;
            if ((N - i) % 2 == 0) {
                dp[l][r] = max(dp[l + 1][r] + a[l], dp[l][r - 1] + a[r - 1]);
            } else {
                dp[l][r] = min(dp[l + 1][r] - a[l], dp[l][r - 1] - a[r - 1]);
            }
        }
    }
    cout << dp[0][N] << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    std::vector<long long> a(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &a[i]);
    }
    solve(N, std::move(a));
    return 0;
}


Measured memory_bytes: 70784
#include <bits/stdc++.h>
 
using namespace std;
 
#define PI M_PI
#define EPS 1e-9
 
int main(){
    double R;
    while(cin >> R, R > 0){
	double n = 0,d = 1;
	while(true){
	    if(fabs(PI-n/d) <= R+EPS){
		cout << (int)n << "/" << (int)d << endl;
		break;
	    }else{ R+n/d < PI ? n++ : d++; }
	}
    }
    return 0;
}

Measured memory_bytes: 3136
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define FOR(i, s, n) for (int i = (s); i < (n); i++)
#define RFOR(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define ALL(a) a.begin(),a.end()
#define IN(a,x,b) (a<=x && x<b)
const long long MOD = 1e9+7, INF = 1e18;
template<class T>inline bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}


signed main(){
	int N,M;
	cin>>N>>M;
	vector<int>g[N];
	REP(i,M){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].push_back(b);
	}
	vector<vector<int>>dist(N,vector<int>(3,INF));
	queue<pair<int,int>>que;
	int S,T;
	cin>>S>>T;
	que.push({S-1,0});
	dist[S-1][0] = 0;
	while(!que.empty()){
		int now = que.front().first;
		int cost = que.front().second;
		que.pop();
		if(now==T-1&&cost%3==0){
			cout<<cost/3<<endl;
			return 0;
		}
		for(auto e:g[now]){
			if(dist[e][(cost+1)%3]!=INF)continue;
			dist[e][(cost+1)%3] = cost + 1;
			que.push({e,cost+1});
		}
	}
	cout<<-1<<endl;
}

Measured memory_bytes: 11136
input()
slimeList = list(map(int, input().split()))
result = 0
count = 1
tmpSlime = slimeList[0]
for nextSlime in slimeList[1:]:
  if tmpSlime == nextSlime:
    count += 1
  else:
    result += count // 2
    count = 1
    tmpSlime = nextSlime
result += count // 2
print(result)

Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include<iostream>
using namespace std;

#define int long long int
#define all(x) (x).begin(), (x).end()
#define removeDuplicates(a) a.resize(unique(all(a))-a.begin())
#define endl '\n'

void solve(){
	int n;
	cin>>n;
	int ans=0;
	for(int i=1;i<n;i++){
		ans+=(n-1)/i;
	}
	cout<<ans<<endl;
}

int32_t main(){

	//remove for interactive problems
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	solve();
	cerr<<"Time : "<<1000*((double)clock())/(double)CLOCKS_PER_SEC<<"ms\n";

	return 0;
}

Measured memory_bytes: 3800
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] p = new int[n];
    int ans = 0;
    for(int i = 0; i < n; i++) {
      p[i] = sc.nextInt();
    }
    Arrays.sort(p);
    for(int i = 0; i < (n - 1); i++) {
      ans += p[i];
    }
    ans += (p[n - 1] / 2);
    System.out.println(ans);
  }
}

Measured memory_bytes: 21972
n = int(input())
x = list(map(int, input().split( )))
x2 = [x[i] for i in range(n)]

x2.sort()

ans1 = x2[n//2-1]
ans2 = x2[n//2]

for i in range(n):
    if x[i]<=ans1:
        print(ans2)
    #elif x[i]==ans2:
    #    print(ans1)
    else:
        print(ans1)###


Measured memory_bytes: 102100
#include <stdio.h>

#define N_MIN       (1)
#define N_MAX       (50000)
#define M_MIN       (1)
#define M_MAX       (20)
#define C_MIN       (1)
#define C_MAX       (10000)

typedef enum
{
    ERROR  =-1,
    SUCCESS= 0
} ResultType;

static ResultType checkRangeOfNum(int, int, int);
static int getTheNumberOfCoin(int n, int m, int *C);

int main(void)
{
    int C[M_MAX], n, m, i;
    ResultType eResult;
    ResultType eFlag = ERROR;

    /* input line 1 */
    scanf("%d", &n);
    eResult = checkRangeOfNum(n, N_MIN, N_MAX);
    if(eResult < SUCCESS)
    {
        printf("Err: %d is out of range.", n);
        return eResult;
    }

    scanf("%d", &m);
    eResult = checkRangeOfNum(m, M_MIN, M_MAX);
    if(eResult < SUCCESS)
    {
        printf("Err: %d is out of range.", m);
        return eResult;
    }

    /* input line 2 */
    for(i=0; i<m; i++)
    {
        scanf("%d", &C[i]);
        eResult = checkRangeOfNum(C[i], C_MIN, C_MAX);
        if(eResult < SUCCESS)
        {
            printf("Err: %d is out of range.", C[i]);
            return eResult;
        }
        
        if((eFlag != SUCCESS) && (C[i] == 1))
        {
            eFlag = SUCCESS;
        }
    }

    if(eFlag < SUCCESS)
    {
        printf("Err: Coin values do not contain 1.");
        return eResult;
    }
    
    /* execute getTheNumberOfCoin()*/
    printf("%d\n", getTheNumberOfCoin(n, m, &C[0]));
    return SUCCESS;
}

static int getTheNumberOfCoin(int n, int m, int *C)
{
    int T[n+1];
    int i;
    int j;

    for (j=0; j<=n; j++)
    {
        T[j] = j;   /* This T[j] is maximum because Array C contains 1.*/
    }

    for (i=0; i<m; i++)
    {
        for (j=C[i]; j<=n; j++)
        {
            if (T[j] > (T[j - C[i]] + 1))
            {
                T[j] = T[j - C[i]] + 1;
            }
        }
    }

    return T[n];
}

static ResultType checkRangeOfNum(int n, int nMin, int nMax)
{
    if((n < nMin) || (nMax < n))
    {
        return ERROR;
    }
    return SUCCESS;
}

Measured memory_bytes: 1976
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>

using namespace std;

#define REP(i, n) for(ll i = 0;i < n;i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(ll i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD 1000000007
#define P pair<ll, ll>

ll n;
void dfs(ll a, ll b, string s) {
	if (a == n) {
		printf("%s\n", s.c_str());
		return;
	}
	REP(i, b + 1) {
		char c = 'a' + i;
		dfs(a + 1, max(b, i + 1), s + c);
	}
}
int main() {
	cin >> n;
	dfs(0, 0, "");
}


Measured memory_bytes: 1536
input()
A=input().split()
H=len(A)
for i in range(H):
 print(f'node {i+1}: key = {A[i]}, {f"parent key = {A[(i-1)//2]}, "if i>0 else""}{f"left key = {A[2*i+1]}, "if 2*i+1<H else""}{f"right key = {A[2*i+2]}, "if 2*i+2<H else""}')


Measured memory_bytes: 5588
#include <bits/stdc++.h>
using namespace std;
int main(){
    int x;
    cin >> x;
    while(x >= 100){
        x -= (100 + (x%100 > 5?5:x%100));
    }
    if(x == 0) cout << 1 << endl;
    else cout << 0 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<28)
#define MAX 35
#define next(a,b) ((((a+3)%4)+b)%4)
using namespace std;

struct P
{
  int x,y,dir;
  P(int x=inf,int y=inf,int dir=inf):x(x),y(y),dir(dir){}
};

int dx[] = {+1,+0,-1,+0};
int dy[] = {+0,-1,+0,+1};
int H,W;
char G[MAX][MAX];
int  D[MAX][MAX];
string DIR = "ENWS";
vector<P> vec;

bool Finish()
{
  rep(i,vec.size())if(G[vec[i].y][vec[i].x] != 'X')return false;
  return true;
}

void print()
{
  cout << "print- ---" << endl;
  rep(i,H)
    {
      rep(j,W)
	{
	  cout << G[i][j];
	}
      cout << endl;
    }
  cout << endl;
}

void decide()
{
  rep(i,vec.size())
    {
      int x = vec[i].x, y = vec[i].y, dir = vec[i].dir;
      if(G[y][x] == 'X')continue;

      rep(j,4)
	{
	  int nx = x + dx[next(dir,j)];
	  int ny = y + dy[next(dir,j)];
	  if(!(0 <= nx && nx < W && 0 <= ny && ny < H))continue;
	  if(!(G[ny][nx] == '.' || G[ny][nx] == 'X'))continue;
	  vec[i].dir = next(dir,j);
	  D[ny][nx]++;
	  break;
	}
    }
}

bool check(int x,int y,int cx,int cy)
{
  rep(i,4)
    {
      int nx = cx + dx[i];
      int ny = cy + dy[i];
      if(!(0 <= nx && nx < W && 0 <= ny && ny < H))continue;
      if(G[ny][nx] == '.' || G[ny][nx] == 'X' || G[ny][nx] == '#')continue;
      return nx == x && ny == y;
    }
}

void move()
{
  rep(i,vec.size())
    {
      int x = vec[i].x;
      int y = vec[i].y;
      if(G[y][x] == 'X')continue;

      int dir = vec[i].dir;
      int nx = x + dx[dir];
      int ny = y + dy[dir];
      if(!(0 <= nx && nx < W && 0 <= ny && ny < H))continue;
      if(!(G[ny][nx] == '.' || G[ny][nx] == 'X'))continue;
      if(D[ny][nx] == 0)continue;
      if(D[ny][nx] == 1 || (D[ny][nx] >= 2 && check(x,y,nx,ny)))
	{
	  D[ny][nx] = 0;
	  G[y][x] = '.';
	  vec[i].x = nx, vec[i].y = ny;
	  if(G[ny][nx] != 'X')G[ny][nx] = DIR[dir];
	}

    }
  rep(i,H)rep(j,W)D[i][j] = 0;
}

int main()
{
  while(cin >> W >> H,W|H)
    {
      vec.clear();
      rep(i,H)rep(j,W)
	{
	  cin >> G[i][j];
	  if(!(G[i][j] == '.' || G[i][j] == '#' || G[i][j] == 'X'))
	    {
	      char c = G[i][j];
	      int dir = (c=='E'?0:(c=='N'?1:(c=='W'?2:(c=='S'?3:-inf))));
	      vec.push_back(P(j,i,dir));
	    }
	}

      if(vec.empty())
	{
	  cout << 0 << endl;
	  continue;
	}

      rep(phase,180)
	{
	  decide();

	  move();

	  if( Finish() )
	    {
	      cout << phase+1 << endl;
	      goto Fin;
	    }
	}
      cout << "NA" << endl;
    Fin:;
    }

  return 0;
}

Measured memory_bytes: 1220
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 520000

int main(void){
  int i,j,t,l,p,q,a,b;
  int next[32][524288];
  int doubling[32][524288];
  char s[524288];
  scanf("%s",s);
  l=strlen(s);
  for(i=0;i<=26;i++){
    next[i][inf]=inf;
    next[i][l]=inf;
  }
  for(i=l-1;i>=0;i--){
    t=s[i]-'`';
    next[t][i]=i+1;
    p=i+1;
    for(j=t+1;j<=t+26;j++){
      if(j>=28){
        next[j%27][i]=next[j%27][p];
      }
      else{
        p=next[(j+26)%27][p];
        next[j%27][i]=p;
      }
      //if(j%27==0 || j%27==25 || j%27==26){
      //  printf("%d %c:%d\n",i,'`'+(j%27),next[j%27][i]);
      //}
    }
  }
  for(i=0;i<l;i++){
    doubling[0][i]=next[0][i];
  }
  doubling[0][l]=inf;
  doubling[0][inf]=inf;  
  for(i=1;i<32;i++){
    doubling[i][l]=inf;
    doubling[i][inf]=inf;
    for(j=l-1;j>=0;j--){
      doubling[i][j]=doubling[i-1][doubling[i-1][j]];
    }
  }
  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d%d",&a,&b);
    a--;
    p=a;
    for(j=31;j>=0;j--){
      if(doubling[j][p]<=b){
        p=doubling[j][p];
      }
    }
    if(p==b){
      printf("Yes\n");
    }
    else{
      printf("No\n");
    }
  }
  return 0;
}


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

#define ll long long
#define ar array
#define vi vector<int>
#define vvi vector<vector<int>>
#define vll vector<long long>
#define forn(i,n) for(ll i=0; i<(n); i++)
#define fori(i,k,n) for(ll i=k; i<(n); i++) 
#define all(x) (x).begin(),(x).end()
#define en '\n'

template<typename T> void print(vector<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(deque<T>& a)
{
	for (int i = 0; i < a.size(); i++)
		cout << a[i] << ' ';
	cout << en;
}
 
template<typename T> void print(vector<vector<T>>& a)
{
	for (int i = 0; i < a.size(); i++)
	{
		for (int j = 0; j < a[i].size(); j++)
			cout << a[i][j] << ' ';
		cout << en;
	}
}

void solve(){
	int n;
	ll ans = 0;
	cin >> n;
	fori(i, 1, n+1)
		fori(j, 1, n+1)
			fori(k, 1, n+1) {
				ans += __gcd(i, __gcd(j, k));
			}
	cout << ans << en;
}

int main(){
    ios::sync_with_stdio(0);
	cin.tie(0);
    cout.tie(0);
 
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
#endif
    int t = 1; 
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3652
package main

import "fmt"

/*func printslice(dp [][]int, h int, w int){
	for i:=0 ; i<h ; i++ {
		for j:=0 ; j<w;j++ {
			fmt.Printf("%d ",dp[i][j])
		}
		fmt.Println("")
	}
	fmt.Println("")
}*/

func dynamic(s [][]int, dp [][]int, h int, w int) [][]int {
	//引数：ルート(0:black,1:white),調べるポイント
	//返り値：DP
//fmt.Println(h,w)
//printslice(h+1,w+1)
	height := len(s)-1
	width := len(s[0])-1
//printslice(height+1,width+1)
	if h != height {
		down := dp[h+1][w]
		if w != width {
			right := dp[h][w+1]
			if right == -1{
//fmt.Println("search : ",h,w+1)
				dp = dynamic(s,dp,h,w+1) //怪しい
				right = dp[h][w+1]
			}
			if down == -1{
//fmt.Println("search : ",h+1,w)
				dp = dynamic(s,dp,h+1,w) //怪しい
				down = dp[h+1][w]
			}

			if s[h][w] == 0 {
				if s[h][w+1] == 1{
				//黒から白へ
					right++
				}
				if s[h+1][w] == 1{
					down++
				}
			}
			if right <= down {
				dp[h][w] = right

			} else {
				dp[h][w] = down
			}
		} else {
			if down == -1 {
				dp = dynamic(s,dp,h+1,w)
				down = dp[h+1][w]
			}
			if s[h][w] == 0 && s[h+1][w] == 1{
				down++
			}
			dp[h][w] = down
		}
	} else {
		if w == width {
			if s[h][w] == 0 {
				dp[h][w] = 1
			} else {
				dp[h][w] = 0
			}
		} else {
			right := dp[h][w+1]
			if right == -1{
				dp = dynamic(s,dp,h,w+1)
				right = dp[h][w+1]
			}
			if s[h][w] == 0 && s[h][w+1] == 1{
				right++
			}
			dp[h][w] = right
		}
	}
//printslice(dp,height+1,width+1)
	return dp
}

func main(){
	var h,w int
	var r string
	//var s [][]int
	//var temp []int
	fmt.Scan(&h,&w)
	s := make([][]int,h)
	for i:=0 ; i<h ; i++ {
		fmt.Scan(&r)
		var temp []int
		for j:=0 ; j<w ; j++{
			if r[j:j+1] == "." {
				temp = append(temp,1)
			} else {
				temp = append(temp,0)
			}
		}
		s[i] = temp
	}
	dp := make([][]int,h)
	for i:=0 ; i<h ; i++ {
		temp := make([]int,w)
		for j:=0 ; j<w ; j++{
			temp[j] = -1
		}
		dp[i] = temp
	}
//fmt.Println("complete dp")
	//fmt.Println(dynamic(s,0,0))
	dp = dynamic(s,dp,0,0)
//printslice(h,w)
	fmt.Println(dp[0][0])
}


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

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


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

const ll MOD = (ll)(1e9 + 7);

const int MAX_N = 2123;

int S[MAX_N];
int T[MAX_N];

ll dp[MAX_N][MAX_N];

int main2() {
  int N = nextInt();
  int M = nextInt();
  REP(i, N) S[i] = nextInt();
  REP(i, M) T[i] = nextInt();

  CLR(dp, 0);
  REP(j, M+1) dp[0][j] = 1;
  for (int i = 1; i <= N; i++) {
    map<int, ll> f;
    for (int j = 0; j <= M; j++) {
      ll res = dp[i-1][j];
      res += f[S[i-1]];
      dp[i][j] = res % MOD;
      if (j < M) (f[T[j]] += dp[i-1][j]) %= MOD;
    }
  }
  ll ans = dp[N][M];
  cout << ans << endl;
  return 0;
}

int main() {

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


Measured memory_bytes: 35584
#include <bits/stdc++.h>
#define INF 1e18
#define MOD 1000000007
#define PI M_PI
#define ll long long
#define vi vector<int>
#define all(v) v.begin(), v.end()
#define FOR(i, a, b) for (int i=a; i<b; i++)
#define REP(i, n) for (int i=0; i<n; i++)
#define REPD(i, n) for (int i=n-1; i>=0; i--)
#define print(x) cout << x << endl;
#define debug(x) cout << #x << " = " << endl;

using namespace std;

void solve()
{
    int A, B;
    cin >> A >> B;
    int ans = ceil(double(B - 1) / (A - 1));
    print(ans);
}

int main()
{
    solve();

    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
import os
import math


a, b = list(map(int, input().split()))
# a?????§?????????????????????
if b > a:
    a, b = b, a

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

result = gcd(a, b)
print(result)

Measured memory_bytes: 7788
n = int(input())
for a in range(1,3501):
    for b in range(1,3501):
        if -a*n-b*n+4*a*b != 0:
            if (a*b*n)/(4*a*b-a*n-b*n) > 1 and int((a*b*n)/(4*a*b-a*n-b*n)) == (a*b*n)/(4*a*b-a*n-b*n):
                print(a,b,int((a*b*n)/(4*a*b-a*n-b*n)))
                exit()

Measured memory_bytes: 41324