akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long int ll;
int main(){
  ll n,k;
  cin >>n>>k;
  ll h[n+1];
  ll dp[n+1];
  for(ll i=1;i<n+1;i++) cin >>h[i];
  for(ll i=0;i<n+1;i++) dp[i]=1e13+7;
  dp[1]=0;//足場1動かなくていいので0
  dp[2]=abs(h[2]-h[1]);
  for(ll i=3;i<n+1;i++){
    ll d=1e13;
    for(ll j=1;j<=k;j++){
      if(i-j<0) continue;
      d=min(d,dp[i-j]+abs(h[i-j]-h[i]));
    }
    dp[i]=d;
  }
  cout << dp[n]<<endl;
  return 0;
}


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

using namespace std;

int main()
{
    string s,t;
    cin>>s>>t;
    for (int i = 0; s[i]!='\0'; i++)
    {
        if(s[i]!=t[i])
           {
               cout<<"No"; return 0;
           }
    }
    cout<<"Yes"; return 0;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include<string.h>

int main()
{
	char a[11],b[11],c[11];
	
	scanf("%s%s%s",&a,&b,&c); 
	
	if(a[strlen(a)-1]==b[0] && b[strlen(b)-1]==c[0])printf("YES");
	  else printf("NO");
	return 0;
}
 


Measured memory_bytes: 1728
#include <stdio.h>

int heap[255];

int parent(int i) {
    return i/2;
}

int left(int i) {
    return 2*i;
}

int right(int i) {
    return 2*i+1;
}


int main(void) {
	int i, n, t;
	scanf("%d\n", &n);
	
	for(i=1;i<=n;i++) {
		scanf("%d", &heap[i]);
	}

	for(i=1;i<=n;i++) {
		int r, l;
		printf("node %d: key = %d,",i, heap[i]);
		if(i>1) {
			printf(" parent key = %d,",heap[parent(i)]);
		}
		l = left(i);
		r = right(i);
		if(l <= n) printf(" left key = %d,", heap[l]);
		if(r <= n) printf(" right key = %d,", heap[r]);
		printf(" \n");
	}
	
	return 0;
}

Measured memory_bytes: 608
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  string s;
  cin >> s;
  int size = s.size();
  int i = size - 1;
  ll ans = 0;
  ll check = 0;
  while (i >= 0)
  {
    if (i == 1)
    {
      if (s[i] == 'A')
      {
        ans += check;
      }
      i--;
    }
    else
    {
      if (s[i] == 'A')
      {
        ans += check;
        i--;
      }
      if (s[i] == 'C' && s[i - 1] == 'B')
      {
        check++;
        i -= 2;
      }
      if (s[i] == 'C' && s[i - 1] != 'B')
      {
        check = 0;
        i--;
      }
      if (s[i] == 'B')
      {
        check = 0;
        i--;
      }
    }
  }
  cout << ans << "\n";
}

Measured memory_bytes: 640
import os
import os
import sys
from collections import deque

import numpy as np

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

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

N = int(sys.stdin.readline())
A = [int(sys.stdin.readline()) for _ in range(N)]


def solve(A):
    if N % 2 == 0:
        ans = [-1] * N
        for i, a in enumerate(A[:N // 2]):
            ans[i * 2 + 1] = a
        for i, a in enumerate(A[N // 2:]):
            ans[i * 2] = a
    else:
        ans = deque()
        que = deque(A)
        while len(que) > 1:
            ans.append(que.popleft())
            ans.append(que.pop())
        ans.appendleft(que.pop())
        ans = list(ans)
    return np.abs(np.diff(ans)).sum()


A.sort()
a = solve(A)
A.reverse()
b = solve(A)
print(max(a, b))

#
# def solve():
#     ans = []
#     for li in itertools.permutations(A):
#         ans.append((np.abs(np.diff(li)).sum(), li))
#     ans.sort()
#
#     print(*ans, sep='\n')
#
#
# solve()


Measured memory_bytes: 28988
#include <bits/stdc++.h>
using namespace std;
using LL = long long;

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
   return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
   os << "[";
   bool a = 1;
   for (auto e : v ) {
      os << (a ? "" : " "); 
      os << e;
      a = 0;
   }
   os << "]";
   return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
   os << "(" << p.first << " " << p.second << ")";
   return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
   os << "{";
   bool a = 1;
   for (auto e : st) {
      os << (a ? "" : " ");
      os << e;
      a = 0;
   }
   os << "}";
   return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
   os << "{";
   bool a = 1;
   for (auto e : mp) {
      os << (a ? "" : " ");
      os << e.first << ":" << e.second;
      a = 0;
   }
   os << "}";
   return os;
}

// std::tuple Debug
template<int N,class Tuple>
void out(ostream &os,const Tuple &t){}
template<int N,class Tuple,class H,class ...Ts>
void out(ostream &os,const Tuple &t){
   if(N)os<<" ";
   os<<get<N>(t);
   out<N+1,Tuple,Ts...>(os,t);
}
template<class ...Ts>
ostream& operator<<(ostream &os, const tuple<Ts...> &t){
   os<<"(";
   out<0,tuple<Ts...>,Ts...>(os,t);
   os<<")";
   return os;
}

// Debug
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

bool in(int a) {
   return 1 <= a && a <= 12;
}

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

   int a = s / 100, b = s % 100;

   if (in(a) && in(b)) {
      cout << "AMBIGUOUS" << endl;
   } else if (in(a) && !in(b)) {
      cout << "MMYY" << endl;
   } else if (!in(a) && in(b)) {
      cout << "YYMM" << endl;
   } else {
      cout << "NA" << endl;
   }

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
#include<complex>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e18 + 1e18;
const ll MOD = 1000000007;
const ll MAX = 4000001;
const long double eps = 1E-14;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};

class mint {
	long long x;
public:
	mint(long long x = 0) : x((x% MOD + MOD) % MOD) {}
	mint operator-() const {
		return mint(-x);
	}
	mint& operator+=(const mint& a) {
		if ((x += a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator-=(const mint& a) {
		if ((x += MOD - a.x) >= MOD) x -= MOD;
		return *this;
	}
	mint& operator*=(const  mint& a) {
		(x *= a.x) %= MOD;
		return *this;
	}
	mint operator+(const mint& a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint& a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint& a) const {
		mint res(*this);
		return res *= a;
	}

	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime MOD
	mint inv() const {
		return pow(MOD - 2);
	}
	mint& operator/=(const mint& a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint& a) const {
		mint res(*this);
		return res /= a;
	}

	friend ostream& operator<<(ostream& os, const mint& m) {
		os << m.x;
		return os;
	}
};

mint pw(mint a, ll b) {
	if (b == 0) { return 1; }
	mint ret = pw(a, b >> 1);
	ret *= ret;
	if (b & 1) { ret *= a; }
	return ret;
}

typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;

typedef vector<mint> vmint;
typedef vector<vector<mint>> vvmint;
typedef vector<vector<vector<mint>>> vvvmint;

//////////////////////////////////////

int main() {
	ll X;
	cin >> X;
	cout << 10 - X / 200 << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <stack>

using namespace std;

int main()
{
	while(true){
		char line[105];
		cin.getline(line, sizeof(line));
		if(line[0] == '.'){break;}
		else{
			stack<char> s;
			if( ( line[0] == '(' ) || ( line[0] == '[' )||( line[0] == ')' ) || ( line[0] == ']' ) ){
				s.push(line[0]);
			}
			for(int i=1; ;i++){
				char k = ' ';
				if(!s.empty()){
					k = s.top();
				}
				if(line[i] == '.'){break;}
				else if( ( line[i] == ')' ) && ( k == '(' ) ){
					s.pop();
				}
				else if(( line[i] == ']' )&&( k == '[' )){
					s.pop();
				}
				else if( ( line[i] == '(' ) || ( line[i] == '[' ) ){
					s.push(line[i]);
				}
				else if(( line[i] != '(' ) && ( line[i] != ')' ) && ( line[i] != '[' ) && ( line[i] != ']' )){
					;
				}
				else if( ( line[i] == ')' ) || ( line[i] == ']' ) )
				{
					s.push(line[i]);
				}
				else{;}
			}
			if(s.empty()){
				cout << "yes" << endl;
			}
			else{cout << "no" << endl;}
		}
	}

	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
#define per(i,a,b) for (int i=(b)-1; i>=(a); i--)
#define debug(x) cout << #x << " => " << x << endl
using namespace std;
typedef long long ll;

#define fi first
#define se second
#define mp make_pair
typedef pair<int,int> pii;

#define pb push_back
typedef vector<int> vi;

const int MAX_N = 7 + 200000;
///----------------------------------------------
int dig[MAX_N];
ll Abs(ll d) { return d>=0 ? d : -d; }
int main() {

    ///freopen ( "xx.in" , "r" , stdin );

    ///init

    ///read
    int n; cin>>n;
    rep(i,0,n) scanf("%d",&dig[i]);

    ///work
    ll sum=0; rep(i,0,n) sum+=dig[i];
    ll sum1=0;
    ll ans=-1;
    rep(i,0,n-1) {
        sum1+=dig[i];
        ll tmp=Abs(sum-sum1-sum1);
        if (!~ans||ans>tmp) ans=tmp;
    }

    cout << ans;

}





Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class Main {

	public static void main(String args[]) throws Exception {
		MyScanner sc = new MyScanner();
		PrintWriter pr = new PrintWriter(System.out);

		int n = sc.nextInt();

		long ar[] = new long[n];
		boolean zero = false;
		
		BigInteger ans = new BigInteger("1");

		for (int i = 0; i < n; i++) {

			ar[i] = sc.nextLong();
			if (ar[i] == 0)
				zero = true;
		}

		if (zero) {
			pr.println("0");
			pr.close();
			return;
		}

		for (int i = 0; i < n; i++) {

			long a = ar[i];

			if (a == 0) {

				ans = BigInteger.ZERO;
				break;
			}

			ans = ans.multiply(new BigInteger(Long.toString(a)));
			
			if(ans.compareTo(new BigInteger("1000000000000000000")) > 0) {
				
				ans = new BigInteger("-1");
				break;
			}
		}

		pr.println(ans);

		pr.close();
	}

	public static class MyScanner {
		BufferedReader br;
		StringTokenizer st;

		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}

		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}


Measured memory_bytes: 57524
line = [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]
K = int(input())

print(line[K-1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  long long int a[n];
  for(int i=0;i<n;i++)
    cin>>a[i];
  stack<int>s;
  vector<int>ans(n);
  ans[n-1]=-1;
  s.push(n-1);
  for(int i=n-2;i>=0;i--)
  {
      if(!s.empty() && a[s.top()]<=a[i]) s.pop();
      if(s.empty()) ans[i]=-1;
      else ans[i]=s.top();
      s.push(i);
  }
  int temp=0;
  for(int i=0;i<n;i++)
  {
      int cur;
      if(ans[i]==-1)
      cur=n-1-i;
      else cur=ans[i]-i-1;
      temp=max(temp,cur);

  }

  cout<<temp;
  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <string.h>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <queue>
#include <stack>
#include <bitset>
#include <map>
using namespace std;
template <typename lx> inline void read(lx &x){
	x = 0;int f = 1;char c = getchar();
	for(;c < '0' || '9' < c; c = getchar()) if(c == '-') f = -1;
	for(;'0' <= c && c <= '9'; c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
	x *= f;return;
}
template <typename lx> inline void print(lx x){
	if(x < 0) putchar('-'),x = -x;
	if(x > 9) print(x / 10);
	putchar(x % 10 + 48);
	return;
}
#define rg register
#define ll long long
#define r_2(a,b) read(a),read(b)
#define r_3(a,b,c) read(a),read(b),read(c)
#define print_n(a) print(a),puts("")
#define print_(a) print(a),putchar(' ')
const int inf = 2147483647;
const int maxn = 2e5 + 4;
int n,l,r;
int a[maxn],b[maxn];
int main()
{
	read(n);
	for(rg int i = 1;i <= n; i++) read(a[i]),b[i] = a[i];
	sort(a + 1,a + 1 + n);
	r = a[n];l = a[n - 1];
	for(rg int i = 1;i <= n; i++) print_n(b[i] != r ? r : l);
	return 0;
}

Measured memory_bytes: 3200
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    public double getProbability(int index, int headsRemaining, double[] prob, Double[][] memo) {
       //System.out.println(String.format("<%d,%d>", index, headsRemaining));
       int n = prob.length;
       if (index == prob.length && headsRemaining <= n/2) {
           return 1.0;
       }
       if (index == n) {
           return 0.0;
       }
       if (memo[index][headsRemaining] != null) {
           return memo[index][headsRemaining];
       }
       double res = 0.0;
       res += getProbability(index + 1, headsRemaining - 1, prob, memo) * prob[index];
       res += getProbability(index + 1, headsRemaining, prob, memo) * (1 - prob[index]);
       return memo[index][headsRemaining] = res;
    }
    public static void main(String[] args)  {
        try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
            br.readLine();
            String[] split = br.readLine().split(" ");
            int n = split.length;
            double[] prob = new double[n];
            for (int i = 0; i < n; i++) {
               prob[i] = Double.parseDouble(split[i]); 
            }
            Double[][] memo = new Double[n][n + 1];
          	Main app = new Main();
            double result = app.getProbability(0, n, prob, memo);
            /*for(Double[] row: memo) {
                for (Double d: row) {
                    System.out.print(String.format("%.2f ", d == null ? 0.0 : d));
                }
                System.out.println();
            }*/
            System.out.println(result);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 227444
#include<stdio.h>
int main()
{
    long long int x,y,r,GCD,a,b;
    while(scanf("%lld%lld",&x,&y)==2)
    {
        a=x;b=y;
        if(x>=y)
        {
        do
        {
            r=a%b;
            a=b;
            b=r;
        }while(r!=0);
        GCD=a;
        printf("%lld %lld\n",GCD,(GCD*(x/GCD)*(y/GCD)));
        }
        else
         {
        do
        {
            r=b%a;
            b=a;
            a=r;
        }while(r!=0);
        GCD=b;
        printf("%lld %lld\n",GCD,(GCD*(x/GCD)*(y/GCD)));
        }
    }
    return 0;
}



Measured memory_bytes: 1972
n, q = map(int,input().split())
S = list(input())
lr = [[] for i in range(q)]
for i in range(q):
  lr[i] =list(map(int,input().split()))

Sl = [0 for i in range(n+1)]
for i in range(1,n):
  if (S[i-1] == "A")&(S[i]=="C"):
    Sl[i] = Sl[i-1]+1
  else:
    Sl[i] = Sl[i-1]
Sl[n] = Sl[n-1]

ans = []
for i,j in lr:
  ans.append(Sl[j-1]-Sl[i-1])
  
for i in ans:
  print(i)


Measured memory_bytes: 35252
from itertools import permutations
from copy import copy

choices = list(map(int, input().split()))
combs = permutations(choices, 2)

res = 0

for comb in combs:
    left = copy(choices)
    for num in comb:
        left.remove(num)
    right = int(str(comb[0]) + str(comb[1]))
    total = left[0] + right
    if total > res:
        res = total

print(res)


Measured memory_bytes: 3568
use std::io::{stdin, BufRead};
fn main() {
    let stdin = stdin();
    let mut stdinlock = stdin.lock();
    let mut n = String::with_capacity(5);
    let _ = stdinlock.read_line(&mut n);
    let mut scores: Vec<u32> = stdinlock
        .lines()
        .map(|score| score.expect("unwrap").trim().parse().expect("parse"))
        .collect();
    scores.sort();
    let scores: Vec<u32> = scores;
    println!("{}", solve(&scores));
}

fn solve(scores: &[u32]) -> u32 {
    let total = scores.iter().sum();
    if total % 10 != 0 {
        return total;
    }
    for score in scores {
        if score % 10 != 0 {
            return total - score;
        }
    }
    0
}


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

int main() {
  int N;
  cin >> N;
  
  vector<int> P(N), Q(N);
  for (int i = 0; i < N; i++) {
    cin >> P.at(i);
  }
  for (int i = 0; i < N; i++) {
    cin >> Q.at(i);
  }
  
  vector<int> a(N), b(N);
  for (int i = 0; i < N; i++) {
    a.at(i) = i + 1;
    b.at(i) = i + 1;
  }
  
  int x = 0;
  int y = 0;
  
  
  do {
    bool check = true;
    x++;
    for (int i = 0; i < N; i++) {
      if (a.at(i) != P.at(i)) {
        check = false;
        break;
      }
    }
    if (check) {
      break;
    }
  } while (next_permutation(a.begin(), a.end()));
  
  do {
    bool check = true;
    y++;
    for (int i = 0; i < N; i++) {
      if (b.at(i) != Q.at(i)) {
        check = false;
        break;
      }
    }
    if (check) {
      break;
    }
  } while (next_permutation(b.begin(), b.end()));
  
  cout << abs(x - y) << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

class Main {
	public static Scanner sc = new Scanner(in);
	public static Random rand=new Random();

	public void run() {
		int n=sc.nextInt();
		TCase:while(n--!=0){
			int y=sc.nextInt(),m=sc.nextInt(),d=sc.nextInt();
			int res=0;
			//y年部分
			res+=(y-1)/3*10*20;
			res+=((y-1)-(y-1)/3)*(5*19+5*20);

			//m月部分
			if(y%3==0){
				res+=(m-1)*20;
			}else{
				res+=(m-1)/2*19+((m-1)-(m-1)/2)*20;
			}

			//日部分
			res+=(d-1);

			ln(196470-res);
		}
	}
	public static void main(String[] args) {
		new Main().run();
	}

	public int[] nextIntArray(int n){
		int[] res=new int[n];
		for(int i=0;i<n;i++){
			res[i]=sc.nextInt();
		}
		return res;
	}
	public static void pr(Object o) {
		out.print(o);
	}
	public static void ln(Object o) {
		out.println(o);
	}
	public static void ln() {
		out.println();
	}
}

Measured memory_bytes: 20484
#include<bits/stdc++.h>
#include<iomanip>
using namespace std;
typedef long long ll;
typedef long  l;
typedef pair<int,int> P;
#define rep(i,n) for(int i=0;i<n;i++)
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
const int INF=1000000001;
const double PI=3.141592653589;
const ll LMAX=1000000000000001;
ll gcd(ll a,ll b){if(a<b)swap(a,b);while((a%b)!=0){a=b;b=a%b;}return b;}
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};



int main(){
  int a [] = {0 , 1 , 3 , 1 , 2 , 1 , 2 , 1 , 1 , 2 , 1 , 2 , 1};
  // 配列の添字は 0 から始まるので，a [0] は 0 にしている．
  int x , y ; cin >> x >> y ;
  cout << ( a [ x ] == a [ y ] ? " Yes " : " No ") << endl ;
  
  return 0;
}


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

int main() {
    int N; cin >> N;
    N %= 10;
    if(N == 3) {
        cout << "bon\n";
    } else if(N == 0 || N == 1 || N == 6 || N == 8) {
        cout << "pon\n";
    } else {
        cout << "hon\n";
    }
}

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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> p(m);
  vector<string> s(m);
  rep (i, m) {
    cin >> p.at(i) >> s.at(i);
  }

  vector<bool> anser(100001, false);
  vector<int> wa_cnt(100001, 0);
  int ac = 0;
  int wa = 0;
  rep (i, m) {
    if (s.at(i) == "WA") {
      if (anser.at(p.at(i)) == false) {
        wa_cnt.at(p.at(i))++;
      }
    } else {
      if (anser.at(p.at(i)) == false) {
        ac++;
        wa += wa_cnt.at(p.at(i));
        anser.at(p.at(i)) = true;
      }
    }
  }

  cout << ac << ' ' << wa << endl;
  return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
int main(){
   long x,y;
   cin >> x >> y;
   if(x==y) cout << 0 << endl;
   else if(y-x==1||y==-x) cout << 1 << endl;
   else cout << min({abs(x-y),abs(x+y-1),abs(x+y+1),abs(x-y+2)})+2 << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
//#include <stack>
//#include <queue>
//#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
//#include <list>
#include <iomanip>

using namespace std;

#define IOS ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define prec std::cout << std::fixed << std::setprecision(15);
#define endl "\n"
#define MOD 1000000007
#define Int int64_t
#define PI 3.14159265358979
#define ssort(z) sort(z.begin(), z.end())
#define rsort(z) sort(z.rbegin(), z.rend())
#define eerase(z) z.erase(unique(z.begin(), z.end()), z.end())
#define ccnt(z, w) count(z.begin(), z.end(), w)
#define rep(i,a,n) for(Int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(Int (i)=(a); (i)<=(n); (i)++)
const int MAX_N = 1000000;
const Int MAX_N_Int = 1000000000000;

template <typename T>
void printV(const std::vector<T>& v, const char * const separator = " ")
{
    if(!v.empty())
    {
        std::copy(v.begin(),
                  --v.end(),
                  std::ostream_iterator<T>(std::cout, separator));
        std::cout << v.back() << "\n";
    }
}

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 gcd(Int a, Int b) {
    return b != 0 ? gcd(b, a % b) : a;
}

Int lcm(Int a, Int b) {
    return a / gcd(a, b) * b;
    //a*bは64bit integer overflow
}

int Max(int a, int b, int c) {
    int temp = max(a, b);
    return max(temp, c);
}

int Min(int a, int b, int c) {
    int temp = min(a, b);
    return min(temp, c);
}

bool integer(double num) {
    return floor(num) == num;
}

Int fact(int num) {
    if (num == 0)
        return 1;
    else
        return num * fact(num - 1);
}

Int yakusu(int n) {
    int cnt = 0;
    for (int i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            cnt++;
            if (i * i != n) cnt++;
        }
    }
    return cnt;
}


Int fact_mod(Int n, Int mod) {
    Int f = 1; repq(i,2,n) f = f * (i % MOD) % MOD;
    return f;
}

// 繰り返し二乗法 (modの世界での累乗)
Int mod_pow(Int x, Int n, Int mod) {
    Int res = 1;
    while(n > 0) {
        if(n & 1) res = (res * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return res;
}

// 組み合わせ nCr を求める
Int combination_mod(Int n, Int r, Int mod) {
    if(r > n-r) r = n-r;
    if(r == 0) return 1;
    Int a = 1;
    rep(i, 0, r) a = a * ((n-i) % mod) % mod;
    Int b = mod_pow(fact_mod(r, mod), mod-2, mod);
    return (a % mod) * (b % mod) % mod;
}

int main() {
    //COMinit();
    IOS;
    prec;
    Int a,b,c,n,m,k,x,y=0,ans=1;
    string str,s="",t,u;


    cin>>x>>y;
    if(x%y==0){
        cout<<-1;
        
    }else cout<<x;





    cout<<endl;
    return 0;
}




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

#define ll long long
#define endl "\n"
#define m 1000000007

ll a[1000005];

void solve() {
  ll n;
  cin >> n;
  ll ans1 = INT_MAX;
  ll ans2 = INT_MAX;
  ll ans3 = INT_MIN;
  ll ans4 = INT_MIN;
  ll x, y;
  ll ans = INT_MIN;
  for (ll i = 0; i < n; ++i) {
    cin >> x >> y;
    ans1 = min(ans1, x+y);
    ans2 = min(ans2, x-y);
    ans3 = max(ans3, x+y);
    ans4 = max(ans4, x-y);
  }
  cout << max(ans, max(ans3-ans1, ans4-ans2)) << endl;
}

int main() {
  ll t;
  // cin >> t;
  t = 1;
  while (t--)
    solve();
  return 0;
}

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

namespace ForATCODER
{
    public class Program
    {
        public static void Main(string[] args)
        {
            int res = 0;
          int x = s2i(Console.ReadLine());
            int a = x / 500;
            res += a * 1000;
            x -= a * 500;
            a = x / 5;
            res += a * 5;
            x -= a * 5;
            RESULT(res);


        }
      
      
        static int s2i(String s)
        {
            return Convert.ToInt32(s);
        }
        static void RESULT(double res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(long res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(ulong res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(int res)
        {
            Console.WriteLine(res);
        }
        static void RESULT(String res)
        {
            Console.WriteLine(res);
        }
        static String[] ReadLineAll(int count)
        {
            String[] res = new String[count];
            for (int i = 0; i < count; i++)
            {
                res[i] = Console.ReadLine();
            }
            return res;
        }

        static int[] S2Iarray(String[] src)
        {
            int len = src.Length;
            int[] res = new int[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt32(src[i]);
            }
            return res;
        }
        static long[] S2Larray(String[] src)
        {
            int len = src.Length;
            long[] res = new long[len];
            for (int i = 0; i < len; i++)
            {
                res[i] = Convert.ToInt64(src[i]);
            }
            return res;
        }
    }
}


Measured memory_bytes: 13268
roll_dict = dict(E = (3, 1, 0, 5, 4, 2), W = (2, 1, 5, 0, 4, 3), S = (4, 0, 2, 3, 5, 1), N = (1, 5, 2, 3, 0, 4))

def judge_dice(dice1s, dice2):
  for i in range(6):
    if dice1s[i][0] == dice2[0] and dice1s[i][5] == dice2[5]:
      str_dice1 = "".join(map(str, dice1s[i]))
      str_dice2 = "".join(map(str, dice2))

      side1 = str_dice1[1:3]+str_dice1[4]+str_dice1[3]
      side1 += side1
      side2 = str_dice2[1:3]+str_dice2[4]+str_dice2[3]
      return side2 in side1
      break
  return False

n = int(input())
dices = []
for i in range(n):
  dices.append(list(map(int, input().split())))

dice1s = []
dice1s.append(dices[0])
judges = [False for i in range(n - 1)]

for i in "EWSN":
  dice = dice1s[0]
  new_dice = []
  for j in range(6):
    new_dice.append(dice[ roll_dict[i][j] ])
  dice1s.append(new_dice)

dice = dice1s[1]
new_dice = []
for i in range(6):
  new_dice.append(dice[ roll_dict["E"][i] ])
dice1s.append(new_dice)

for i in range(n - 1):
  judges[i] = judge_dice(dice1s, dices[i + 1])

if True in judges:
  print("No")
else:
  print("Yes")



Measured memory_bytes: 5616
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int[] a = new int[N+1];
        int[] knot = new int[N];
        for(int i=1;i<=N;i++) a[i]=sc.nextInt();
        for(int i=1;i<=N-1;i++){
            knot[i]=a[i]+a[i+1];
        }
        int max=0;
        int pos=-1;
        for(int i=1;i<N;i++){
            if(knot[i]>max){
                max = knot[i];
                pos=i;
            }
        }
        if(max<L){
            System.out.println("Impossible");
        }
        else{
            System.out.println("Possible");
            for(int i=1;i<pos;i++) System.out.println(i);
            for(int i=N-1;i>=pos+1;i--) System.out.println(i);
            System.out.println(pos);
        }
    }
}

Measured memory_bytes: 67104
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(string a, string b, string c) {
    int ans = 0;
    for (int i = 0; i < a.length; i++) {
        bool[char] m;
        m[a[i]] = m[b[i]] = m[c[i]] = true;
        ans += m.keys.length - 1;
    }
    return ans;
}

void main() {
    readint;
    string a = read!string;
    string b = read!string;
    string c = read!string;
    writeln(calc(a, b, c));
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBUG
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pair;
const int inf = 1000000000; //10^9
const ll inff = 1000000000000000000; //10^18

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

    if (a+b > c + d) cout << "Left" << endl;
    else if (a+b == c+d) cout << "Balanced" << endl;
    else cout << "Right" << endl;

    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define int long long int
#define ii pair<int,int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
using namespace std;
#define MOD 998244353
#define output(x) for (auto a:x) cout<<a<<" ";cout<<endl;
#define output2(x) for (auto a:x) cout<<a.fi<<" "<<a.se<<endl;
 
int power(int x,int y,int mod) 
{ 
 	int ret = 1;
 	x = x % mod;
 	while (y){
 		if(y&1) ret = (ret*x)%mod;
 		y = y>>1;
 		x = (x*x)%mod;
    } 
    return ret%mod; 
}

int isprime(int x)
{
	for (int i=2;i*i<=x;i++)
		if (x%i==0) return 0;
	return 1;
}
 
 bool cmp(ii a,ii b){
	return a.se<b.se;
}


char choose (char x,char y){
	if (x=='R'){
		if (y=='G'){
			return 'B';
		}
		return 'G';
	}
	if (x=='G'){
		if (y=='R') return 'B';
		return 'R';
	}
	if (x=='B'){
		if (y=='R') return 'G';
		return 'R';
	}
}
void solve()
{	
	int n;
	cin>>n;
	string inp;
	cin>>inp;
	vector<map<char,int>> occ(n);
	occ[0]['R'] = 0;
	occ[0]['G'] = 0;
	occ[0]['B'] = 0;
	for (int i=0;i<n;i++){
		if (i) occ[i] = occ[i-1];
		occ[i][inp[i]]++;
	}
	int ans = 0;
	for (int i=0;i<n-2;i++){
		for (int j=i;j<n-1;j++){
			if (inp[i]==inp[j]) continue;
			char req = choose(inp[i],inp[j]);
			// cout<<2*j-i<<" "<<req<<endl;
			if (2*j-i < n && 2*j-i >-1){
				ans +=occ[n-1][req] - occ[j][req];
				ans -= (inp[2*j-i]==req);
			} else {
				ans +=occ[n-1][req] - occ[j][req];
			}
		}
	}
	cout<<ans<<endl;
}
 
 
signed main(){
	// int t;
	// cin>>t;
	// while (t--)	
	solve();	
 
}

Measured memory_bytes: 4360
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;


int main(){

    int N;
    cin >> N;
    string s, t;
    cin >> s >> t;
    for(int i = 0; ;i++){
        int flg = 1;
        for(int j = 0; j < N && j+i < N; j++){
            if(s[j+i] != t[j])flg = 0;
        }
        if(flg){
            cout << N + i << endl;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 256
// In god we trust
 
#include <bits/stdc++.h>
#include <chrono>
#include <algorithm>
#include <signal.h>
#include <thread>
 
#define pb push_back
#define fi first
#define se second
#define Vi vector<int>
#define Vb vector<bool>
#define Pi pair<int, int>
#define MP make_pair
#define MT make_tuple
#define INF 1000000000 
#define LINF 1000000000000000000
#define int long long
using namespace std;
using namespace std::chrono;
 
  
 
signed main(){
  ios_base::sync_with_stdio(false); 
  cin.tie(NULL);

  int n, k;
  cin >> n >> k;
  int m = n % k;
  cout << min(m, k - m) << endl;
  
}


Measured memory_bytes: 256
n,m,l=list(map(int,input().split()))
A = [[0 for j in range(m)] for i in range(n)]
B = [[0 for k in range(l)] for j in range(m)]
C = [[0 for k in range(l)] for i in range(n)]
for i in range(n):
    A[i] = list(map(int,input().split()))
for j in range(m):
    B[j] = list(map(int,input().split()))
for i in range(n):
    for k in range(l):
        c = 0
        for j in range(m):
            c += A[i][j]*B[j][k]
        C[i][k]=c
for i in range(n):
    for k in range(l-1):
        print(C[i][k],end=" ")
    print(C[i][l-1])


Measured memory_bytes: 7088
#include <iostream>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <algorithm>
#include <utility>
#include <map>
#include <climits>
#include <tuple>
#include <queue>
#include <cassert>
#include <set>
//#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define el '\n'
 

 
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int n;
	cin >>n;
	map<string, int> mp;
	string s;
	vector<string> v={"AC", "WA","TLE" ,"RE"};
		for (auto c: v){
		mp[c] = 0;
	}
	while(n--){
		cin >>s;
		mp[s]++;
	}


	for (auto c: v){
		cout << c<<" x "<<mp[c]<<el;
	}
    return 0;
}

Measured memory_bytes: 3228
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
#include<map>
using namespace std;

int main(){
    int mod=1000000007;
    int n,s,ans;
    for (;;) {
        scanf("%d %d",&n,&s);
        ans=0;
        if (n==0 && s==0) break;
        for (int a=0;a<10-n+1;a++) {
            if (n==1 && a==s) ans++;
            if (n>1){
                for (int b=a+1;b<10-n+2;b++) {
                    if (n==2 && a+b==s) ans++;
                    if (n>2) {
                        for (int c=b+1;c<10-n+3;c++) {
                            if (n==3 && a+b+c==s) ans++;
                            if (n>3) {
                                for (int d=c+1;d<10-n+4;d++) {
                                    if (n==4 && a+b+c+d==s) ans++;
                                    if (n>4) {
                                        for (int e=d+1;e<10-n+5;e++) {
                                            if (n==5 && a+b+c+d+e==s) ans++;
                                            if (n>5) {
                                                for (int f=e+1;f<10-n+6;f++) {
                                                    if (n==6 && a+b+c+d+e+f==s) ans++;
                                                    if (n>6) {
                                                        for (int g=f+1;g<10-n+7;g++) {
                                                            if (n==7 && a+b+c+d+e+f+g==s) ans++;
                                                            if (n>7) {
                                                                for (int h=g+1;h<10-n+8;h++) {
                                                                    if (n==8 && a+b+c+d+e+f+g+h==s) ans++;
                                                                    if (n>8) {
                                                                        for (int i=h+1;i<10-n+9;i++) {
                                                                            if (n==9 && a+b+c+d+e+f+g+h+i==s) ans++;
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        printf("%d\n",ans);    
    }
    return 0;
}

Measured memory_bytes: 3140
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = s; i < (int)(n); i++)
#define Clear(a) a = decltype(a)();
typedef long long ll;
typedef pair<int,int> p;
//const ll big=998244353;
const ll big=1000000007;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
if(x<y)return x;
else return y;
}
ll expm(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||x==0)return x;
    if(y%2==1)return (expm(x,y-1)*x)%big;
    ll t=expm(x,y/2);
    return (t*t)%big;
}
ll exp(ll x,ll y){
    if(y==0)return 1;//0^0=1
    if(x==1||y==0)return x;
    if(y%2==1)return exp(x,y-1)*x;
    ll t=exp(x,y/2);
    return t*t;
}
ll inv(ll x){
    return expm(x,big-2);
}


int main(){
    ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    cout << fixed << setprecision(10);
    /*--------------------------------*/

    int n;cin >> n;
    int a=0,b=0,c=0,d=0;
    rep(i,n){
        string s;cin >> s;
        if(s[0]=='A')a++;
        else if(s[0]=='W')b++;
        else if(s[0]=='T')c++;
        else d++;
    }
    printf("AC x %d\nWA x %d\nTLE x %d\nRE x %d\n",a,b,c,d);
}

Measured memory_bytes: 3744
s = input()

a = s[0]+s[1]
b = s[2]+s[3]

a = int(a)
b = int(b)

if 0 < a and a <= 12:
  if  0 < b and b <= 12:
    print('AMBIGUOUS')
  elif b == 0 or 12 < b:
    print('MMYY')
    
if a == 0 or 12 < a:
  if 0 < b and b <= 12:
    print('YYMM')
  elif b == 0 or 12 < b:
    print('NA')



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

#define endl '\n'
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define test cout<<"test"<<endl;
#define fi first
#define se second
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = n; i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = m - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
void chmin(T &a,T b){if(a>b)a=b;}
template<typename T>
void chmax(T &a,T b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  //cout<<fixed<<setprecision(10);
  ll res=0,buf=0;
  bool judge = true;
  ll n;cin>>n;
  res=INF;
  for(ll i=1;i*i<=n;i++){
    if(n%i==0)chmin(res,i+n/i);
  }
  cout<<res-2<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<cctype>
#include<stack>
using namespace std;
int sum(int n) {
	int num = 0;
	while (n > 0) { // n が 0 になるまで
		num += n % 10;
		n /= 10;
	}
	return num;

}
int main(void) {
	int A, B, C, D;
	int res = 0;
	cin >> A >> B >> C >> D;
	for (int i = A; i < B; i++) {
		for (int j = C; j < D; j++) {
			if (i == j)res++;
		}
	}
	cout << res << endl;
}

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

using namespace std;

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

  string s; 
  cin >> s;
  string res = (s[0] == 'A' ? "AC" : "WA");
  if (count(s.begin()+2, s.end()-1, 'C') != 1) 
    res = "WA";
  else { 
    int n = s.size();
    for (int i = 1; i < n; ++i) {
      if (s[i] <= 'Z' && s[i] != 'C') {
        res = "WA";
        break;
      }
    }
  }
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<fstream>

#define MOD (1000000007)

using namespace std;

typedef long long int Int;

Int gcd(Int x,Int y) {
    if(y == 0)
        return x;
    return gcd(y,x % y);
}

Int minbyte(Int x,Int y) {
    return (x*y) / gcd(x,y);
}

int main(void) {
    Int a,b,c,d;
    cin>>a>>b>>c>>d;

    Int sum = b-a+1;

    Int diff1 = (b/c-(a-1)/c);
    Int diff2 = (b/d-(a-1)/d);
    Int x = minbyte(c,d);
    Int diff3 = (b/x-(a-1)/x);
    cout<<sum-diff1-diff2+diff3<<endl;

    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl "\n"
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define F first
#define S second
#define bitcnt(v) __builtin_popcount(v)
#define all(v) v.begin(), v.end()

vector<ll> a;
int n; 

void solution(){
	cin >> n;
	a = vector<ll>(n); for(auto& x : a) cin >> x;
	// Game Theory DP
	// dp[i][j] - max value of X - Y for a[i]...a[j]
	// X - who moves first in that move
	// Y - second player in that move
	ll dp[n][n];
	memset(dp,-1e9,sizeof(dp));
	for(int i = 0; i < n; i++) dp[i][i] = a[i];
	for(int x = 1; x < n; x++){
		for(int y = 0; y+x < n; y++){
			int i = y, j = y+x;
			dp[i][j] = max(a[i] - dp[i+1][j], a[j] - dp[i][j-1]);
		}
	}
	cout << dp[0][n-1] << endl;
}	


int main(){ 

	fio;
	int t;
	t = 1;
	// cin >> t;
	for(int i = 1; i <= t; i++){
		// cout << "Case #" << i << ": ";
		solution();
	} 
	return 0;
}


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

int main() {
  int N, A, B, X, answer;
  cin >> N >> A >> B;
  for (int i = 1; i <= N; i++) {
    int sum = 0;
    X = i;
    while (X > 0) {
      sum += X % 10;
      X /= 10;
    }  
    X = i;
    if (A <= sum && B >= sum) answer += X;
  }
  cout << answer << endl;
} 

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+N)

int main(void)
{
	string test;
	cin >> test;
	test.insert(test.begin() + 4, ' ');
	cout << test << endl;
}

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

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

int main() {
    int h, w;
    cin >> h >> w;
    vector<string>s(h);
    const int di[] = { -1,0,1,0 };
    const int dj[] = {0,-1,0,1};
    rep(i, h)cin >> s[i];
    int ans = 0;
    rep(si, h)rep(sj, w) {
        if (s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, 500));
        queue<P> q;
        auto update = [&](int i, int j, int x) {
            if (dist[i][j] != 500) return;
            dist[i][j] = x;
            q.push(P(i, j));
        };
        update(si, sj, 0);
        while (!q.empty()){
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            rep(dir, 4) {
                int ni = i + di[dir];
                int nj = j + dj[dir];
                if (ni < 0 || ni >= h || nj < 0 || nj >= w) continue;
                if (s[ni][nj] == '#') continue;
                update(ni, nj, dist[i][j] + 1);
            }
        }
        rep(i, h)rep(j, w) {
            if (dist[i][j] == 500) continue;
            int mx = dist[i][j];
            ans = max(ans, mx);
        }
    }
    cout << ans << endl;
}


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

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = LLONG_MIN;
    ans = max(ans, a * c);
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    if (a * b <= 0 || c * d <= 0) {
        ans = max(ans, 0ll);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3688
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!int;
    auto R = new int[](N-1);

    foreach (d; 1..N) {
        auto end = true;
        auto s = true;
        foreach (ref x; R) {
            if (x == 0) {
                end = false;
                if (s) {
                    s = false;
                    x = d;
                } else {
                    s = true;
                }
            }
        }
        if (end) break;
    }
    foreach (i; 1..N) writeln(R[0..N-i].to!(string[]).join(" "));
}

Measured memory_bytes: 4976
L=gets.chomp.to_i

#if(L==1)

arr = []
l = Math.log2(L).to_i

# bone
1.upto(l){|i|
	arr << "#{i} #{i+1} 0"
	arr << "#{i} #{i+1} #{2**(i-1)}"
}
rem = L
n = 0 # max l-1
base = 2**l
from = 1
while(rem > 1)
	x = rem%2
	# puts "x rem n from #{x} #{rem} #{n} #{from}"
	if(x != 0)
		# add 2**n paths
		arr << "#{from} #{l+1} #{base}"
		base += 2**n
	end
	rem /= 2
	n += 1
	from += 1
end

puts "#{l+1} #{arr.size}"
puts arr


Measured memory_bytes: 3836
#include <iostream>
using namespace std;
 
int main() {
	string s;
cin>>s;
int x, y ;
for(int i=0;i<s.length();i++) {
if(s[i]=='A') {
x=s.find_first_of("A");
} 
if(s[i]=='Z') {
y=s.find_last_of("Z");
 
 
} 
 
 
} 
cout<<y-x+1;
	return 0;
}

Measured memory_bytes: 640
def resolve():
    a = [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]
    n = int(input())
    print(a[n-1])
resolve()

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


int main() {
	
	int N, M, c, cnt=0;
	cin >> N >> M >> c;
	vector<int> b(M);
	for(auto &i:b) cin >> i;
	for(int i=0; i<N; i++){
		int sum = c;
		for(int j=0; j<M; j++){
			int a;
			cin >> a;
			sum += a*b.at(j);
		}
		if(sum > 0) cnt++;
	}
	cout << cnt << endl;
	
	
	return 0;
}

Measured memory_bytes: 256
MOD = 10**9 + 7
import sys
input = sys.stdin.readline
from functools import reduce
from itertools import starmap
n,m = map(int,input().split())
x = list(map(int,input().split()))
y = list(map(int,input().split()))

mulmod = lambda x,y : (x*y) % MOD
summod = lambda x,y : (x+y) % MOD
coefx = range(-(n-1),n+1,2)
xds = reduce(summod, starmap(mulmod, zip(x,coefx)))
coefy = range(-(m-1),m+1,2)
yds = reduce(summod, starmap(mulmod, zip(y,coefy)))

print((xds*yds) % MOD)



Measured memory_bytes: 94524
#include<iostream>
using namespace std;
#define ll long long
int main() {
	ll a, b, n;
	cin >> a >> b >> n;
	if (n >= a + b)
		return cout << 0 << " " << 0 << endl, 0;
	if (n < a)
		return cout << a - n << " " << b << endl, 0;
	else
		return cout << 0 << " " << (a + b - n) << endl, 0;
	return 0;
}

Measured memory_bytes: 256