akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define F first
#define S second
#define pb push_back
#define INF 1e18
#define MOD 1000000007
#define N 1000005
#define BB(V) V[V.size()-2]
#define ex(V) return printf(V),0
using namespace std;
int d1[2005][2005],d2[2005][2005];
int chk1[2005][2005],chk2[2005][2005];
int n,a[2005],srt[2005];
int s(int idx,int z,int w);
int f(int idx,int z,int w){
	if(idx==n)return abs(srt[z]-srt[w]);
	if(chk1[idx][w])return d1[idx][w];
	int ret=INT_MIN;
	for(int i=idx;i<n;i++){
		int t=s(i+1,a[i],w);
		ret=max(ret,t);
	}
	chk1[idx][w]=1;
	return d1[idx][w]=ret;
}
int s(int idx,int z,int w){
	if(idx==n)return abs(srt[z]-srt[w]);
	if(chk2[idx][z])return d2[idx][z];
	int ret=INT_MAX;
	for(int i=idx;i<n;i++){
		int t=f(i+1,z,a[i]);
		ret=min(ret,t);
	}
	chk2[idx][z]=1;
	return d2[idx][z]=ret;
}
int main(){
	int z,w;
	scanf("%d%d%d",&n,&z,&w);
	for(int i=0;i<n;i++){
		scanf("%d",a+i);
		srt[i]=a[i];
	}
	srt[n]=z;srt[n+1]=w;
	sort(srt,srt+n+2);
	int k=unique(srt,srt+n+2)-srt;
	for(int i=0;i<k;i++)a[i]=lower_bound(srt,srt+k,a[i])-srt;
	z=lower_bound(srt,srt+k,z)-srt;
	w=lower_bound(srt,srt+k,w)-srt;
	printf("%d",f(0,z,w));
}

Measured memory_bytes: 61440
#include<iostream>
//#include<string.h>
using namespace std;
//cout << "Yes" << endl;
//cout << "No" << endl;
int seiyaku_check(long i,int Min,long Max){
	if(Min <= i && i <= Max){
		return 1;
	}else{
		exit(1);
	}
}

int main(){
	
	int a;
	
	cin >> a;
	
	seiyaku_check(a,1,100);
	
	cout << a*a << endl;
	
return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
    int a[10],i,j,b,c;
    for(i=0;i<10;i++){
        scanf("%d",&a[i]);
    }
    for(i=0;i<9;i++){
        for(j=i+1;j<10;j++){
            if(a[i]<a[j]){
            b=a[i];
            a[i]=a[j];
            a[j]=b;
            }
        }
    }
    printf("%d\n%d\n%d\n",a[0],a[1],a[2]);
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
//#include <ext/hash_map>
#include <tr1/unordered_map>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using namespace tr1;
//using namespace __gnu_cxx;

#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define mp make_pair
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define DEB 0

#define SZ 885777

/*
real	0m2.093s  --> 
real	0m2.000s
*/
const int dx[] = {1,0,-1,0}; //r,d,l,u
const int dy[] = {0,1,0,-1};

int w,h,sx,sy,home,last;
int field[16][16];
int num[16][16];
int hS[25],hx[25],hy[25],edge[25][4][25]; //[src][dir][dest]
//hash_map<int,int> hii(SZ);
unordered_map<int,int> hii(2000000);


inline bool isnotgoal(int s){
  return (((last&s)) == last);
}
inline bool isnot(int s){
  rep(i,home)if( !(s&(1<<i)) ){
    if( (hS[i]&s)==hS[i] ) return true;
  }
  return false;
}
inline bool inside(int x, int y){
  return (x<0 || y<0 || x>=w || y>=h);
}

int dfs(int S){
  int src = S&((1<<5)-1);
  int x = hx[src];
  int y = hy[src];
  int s = S>>5;

  if( (1<<home)-1 == s ){ //ツ静「ツ妥篠づ可姪淞づェツづゥ
    return 1;
  }
  if( isnotgoal(s) ){ //ツ仰ウツ嘉ッツづ可姪淞づゥツつスツづ淞づ個嘉づーツ湘氾ッツつオツつスツつゥツづつ、ツつゥ
    return 0;
  }
  //hash_map<int,int>::iterator it = hii.find(S);
  unordered_map<int,int>::iterator it = hii.find(S);
  if( it!=hii.end() ){ //ツ探ツ催オツ催渉づ敖づ個湘ウツ妥板つゥツづつ、ツつゥ
    return it->second;
  }

  // ツプツδ個ゼツδ督トツつェツ置ツつッツづ按つ「ツ嘉づ個有ツ鳴ウ
  if( s>0 && ((s&(s-1))!=0) && isnot(s&~(1<<src)) ){
    return 0;
  }
  
  int ret = 0;
  rep(k,4){
    for(int j=0; edge[src][k][j]!=-1; j++){
      int dest = edge[src][k][j];
      int nx = hx[dest];
      int ny = hy[dest];
      if( field[ny][nx]==1 ){
	field[ny][nx] = 0;
	ret += dfs(((s|(1<<dest))<<5)|dest);
	field[ny][nx] = 1;
	break;
      }
    }
  }
  hii.insert(make_pair(S,ret));
  return ret;
}

int main(){

  while(scanf("%d%d",&w,&h),w|h){
    hii.clear();
    memset(num,-1,sizeof(num));
    memset(edge,-1,sizeof(edge));
    memset(hS,0,sizeof(hS));
    home = last = 0;
    rep(i,h){
      rep(j,w){
	scanf("%d",&field[i][j]);
	if( field[i][j]==2 ){
	  sx=j; sy=i;
	}
	if( field[i][j]==1 ){
	  hx[home]=j; hy[home]=i;
	  num[i][j] = home;
	  home++;
	}
      }
    }
    hx[home] = sx;
    hy[home] = sy;

    // other homes
    rep(i,home){
      rep(k,4){
	int sz = 0;
	for(int j=1; j<20; j++){
	  int tx = hx[i] + dx[k]*j;
	  int ty = hy[i] + dy[k]*j;
	  if( inside(tx,ty) ) break;
	  if( field[ty][tx]==1 ){
	    hS[i] |= (1<<num[ty][tx]);
	    edge[i][k][sz++] = num[ty][tx];
	  }
	}
      }
    }

    //last homes
    rep(k,4){
      int sz = 0;
      for(int i=1; i<20; i++){
	int tx = sx + dx[k]*i;
	int ty = sy + dy[k]*i;
	if( inside(tx,ty) )break;
	if( field[ty][tx]==1 ){
	  last |= (1<<num[ty][tx]);
	  edge[home][k][sz++] = num[ty][tx];
	}
      }
    }
    printf("%d\n",dfs(home));
  }
  

  return 0;
}

Measured memory_bytes: 22000
#include <bits/stdc++.h>
#define BIT(n) (1LL << (n))
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPB(i, n) for (int i = 0; i < BIT(n); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); 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 FORS(i, m, n) for (int i = m; i <= n; i++)
#define INF 2e9
#define MOD (1000000007)
#define EPS 1e-9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef long long int lli;
lli gcd(lli m, lli n)
{
    return (m % n == 0) ? n : gcd(n, m % n);
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    lli T, A, B, C, D;
    cin >> T;
    REP(i, T)
    {
        cin >> A >> B >> C >> D;
        if (A < B || D < B)
        {
            cout << "No"
                 << "\n";
        }
        else
        {
            //            D>=B,A>=B
            if (C >= B - 1)
            {
                cout << "Yes"
                     << "\n";
            }
            else
            {
                lli d = gcd(B, D);
                //C+1とB-1にA%dのやつが存在しないようにする。
                if (B - d + A % d >= C + 1)
                {
                    cout << "No"
                         << "\n";
                }
                else
                {
                    cout << "Yes"
                         << "\n";
                }
            }
        }
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <sstream>
#include <math.h>
#include <queue>
#include <map>
#include <set>
#include <ios>     // std::left, std::right
#include <iomanip> // std::setw(int), std::setfill(char)
using namespace std;


int main(){
long long N,K,p;
cin>>N>>K;
long long dice[N];
for(long long i=0;i<N;++i){
  cin>>p;
  dice[i]=p;
}
long long sum_memo[N-K+1];
long long tmp=0;
for(long long i=0;i<K;++i){
  tmp+=dice[i];
}
sum_memo[0]=tmp;
for(long long i=0;i<N-K;++i){
  tmp=tmp-dice[i]+dice[i+K];
  sum_memo[i+1]=tmp;
}
long long ans=0;
for(long long i=0;i<N-K+1;++i){
  ans=max(ans,sum_memo[i]);
}
std::string str;
str = std::to_string((K+ans)/2);
if((ans+K)%2==1){
  str=str+".5";
}

cout<<str<<"\n";
return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    string s;
    cin>>s;
    int r=0, b=0;
    rep(i,0,N){
        if(s[i]=='R') r++;
        else b++;
    }
    cout <<(r>b?"Yes":"No")<<"\n";
}

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

int main() {
    string s,t;
    cin >> s >> t;
    int a,b;
    cin >> a >> b;
    string ss;
    cin >> ss;
    if (ss == s) {
        cout << a - 1 << " " << b << endl;
    } else {
        cout << a << " " << b - 1 << endl;
    }
    return 0;
}

Measured memory_bytes: 256
# nとmを受け取る
n, m = map(int, input().split())

# Aを受け取る
a = [input().split() for i in range(n)]

# bを受け取る
b = [input() for j in range(m)]

# 処理実行
for k in range(n):
    # 行ごとにアウトプット用の変数を初期化
    output = 0
    for l in range(m):
        output = output + int(a[k][l]) * int(b[l])
    print(output)



Measured memory_bytes: 6248
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
//ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 998244353;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

int main() {
	int n, v, r;
	cin >> n >> r;
	rep(i, 1, n) {
		cin >> v;
		r = gcd(r, v);
	}
	printf("%d\n", r);
	return 0;
}


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

int main()
{
    int n,m; cin >> n >> m;
    vector<int> ac(n), wa(n);
    rep(i,m) {
        int p; string s;
        cin >> p >> s;
        p--;
        if (ac[p]) continue;
        if (s == "AC") {
            ac[p] = 1;
        } else {
            wa[p]++;
        }
    }
    int AC = 0, WA = 0;
    rep(i,n) {
        AC += ac[i];
        if (ac[i]) WA += wa[i];
    }

    printf("%d %d", AC, WA);

    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>

int main(){
    unsigned N, K;
    scanf("%u %u", &N, &K);
    unsigned A[N];
    for(int i = 0; i < N; ++i){
        scanf("%u", A + i);
    }
    for (unsigned i = 0; i < N - K; i++){
        if(A[i] < A[K + i]) printf("Yes\n");
        else printf("No\n");
    }
	return 0;
}

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

long long n, k, m = 0;
const long long M = 1e9 + 7;

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

	for (long long i = k; i <= n + 1; i++)
		m = (m + i * (n - i + 1) + 1) % M;

	cout << m << endl;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 5;
const ll INF = 2e18;

int n;
int main(){
    #ifdef Irene
    freopen("in.txt", "r", stdin);
    #endif // Irene
    ios_base::sync_with_stdio(false);

    cin >> n;
    ll a, b, s = 0, ans = 0;
    for(int i = 1;i <= n;i++){
        cin >> a >> b;
        s += a * b;
        ans += b;
    }
    s -= 9;
    if(s <= 0)s = 0;
    else s = s / 9ll + (s%9 > 0);
    cout << ans + s - 1 << endl;
}


Measured memory_bytes: 256
indexed :: [Double] -> [(Int, Double)]
indexed = zip [1..]

fromHeightToTemperature :: Double -> Double -> Double
fromHeightToTemperature base height = base - (0.006 * height)

fromHeightToDiff :: Double -> Double -> Double -> Double
fromHeightToDiff average base height = abs $ temperature - average
  where temperature = fromHeightToTemperature base height

fromHeightsToDiffs :: Double -> Double -> [(Int, Double)] -> [(Int, Double)]
fromHeightsToDiffs average base = map (\(index, height) -> (index, fromHeightToDiff average base height))

extract :: [(Int, Double)] -> (Int, Double)
extract [x] = x
extract (x@(index, diff):xs)
  | diff == 0.0 = x
  | diff < diffOfRemains = x
  | otherwise = another
  where another@(indexOfRemains, diffOfRemains) = extract xs

main :: IO ()
main = do
  _ <- getLine
  [base, average] <- map read . words <$> getLine
  heights <- map read . words <$> getLine
  let indexedDiff = fromHeightsToDiffs average base $ indexed heights
  let extracted = extract indexedDiff
  print $ fst extracted

Measured memory_bytes: 1404
#include<stdio.h>
#define F(a,b) for(a=2;a<=b;a++)
main(){int i,j,n,p[1000000];while(scanf("%d",&n)!=EOF){F(i,n)p[i]=1;F(i,n)F(j,n/i)p[i*j]=0;j=0;F(i,n)j+=p[i];printf("%d\n",j);}}

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

using namespace std;

int main() {
    string S, T;
    cin >> S >> T;
    int cnt = 0;
    for (int i = 0; i < S.size(); i++) {
        if (S[i] != T[i]) cnt++;
    }
    cout << cnt << endl;
}


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

int main(void){
    while (1) {
        float x, y, s;
        cin >> x >> y >> s;
        
        if (x == 0 && y == 0 && s == 0) return 0;
        
        int mx = 0;
        for (float i = 1.0; i <= s; i += 1.0) {
            for (float j = 1.0; j <= s; j += 1.0) {
                if (int(i * (100.0 + x) / 100.0) + int(j * (100.0 + x) / 100.0) == s) {
                    mx = max(mx, int(i * (100.0 + y) / 100.0) + int(j * (100.0 + y) / 100.0));
                }
            }
        }
        
        cout << mx << endl;
    }
}



Measured memory_bytes: 3176
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False


n,m = m()
k = 1
co = 0
while k < m:
    k = k-1 + n
    co += 1 
print(co)



Measured memory_bytes: 3316
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
void judge(bool b){
    cout << (b ? "Yay!" : ":(") << endl;
}
main(){
    int N,K;
    cin >> N >> K;
    if(K==1)cout << 0 << endl;
    else cout << N-K << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(void) {
	int N; cin >> N;
	vector<int> A(N); for (auto &a : A) cin >> a;
	vector<int> nums(5);
	for (int i = 0; i < A.size(); ++i) {
		if (A[i] % 4 == 0) nums[4]++;
		else if (A[i] % 2 == 0) nums[2]++;
		else nums[1]++;
	}

	if (nums[2] % 2 != 0) nums[1]++;
	cout << (nums[1] <= nums[4] + 1 ? "Yes" : "No") << endl;
}


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

using namespace std;

using ll = long long;

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

    int n, k;
    cin >> n >> k;

    const int MAX_N = 200002;
    vector<int> cnt(MAX_N);
    for (int i = 0, a; i < n; ++i) {
        cin >> a;
        ++cnt[a];
    }

    sort(cnt.begin(), cnt.end(), greater<int>());
    int ub = 0;
    while (ub < n && cnt[ub]) ++ub;

    if (ub <= k) cout << "0\n";
    else {
        int ans = 0;

        --ub;
        while (0 <= ub && k < ub + 1)
            ans += cnt[ub--];

        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x)          (x).begin(), (x).end()
#define rep(i, n)       for (i64 i = 0, i##_limit = (n); i < i##_limit; ++i)
#define reps(i, s, t)   for (i64 i = (s), i##_limit = (t); i <= i##_limit; ++i)
#define repr(i, s, t)   for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(Type, ...)  Type __VA_ARGS__; input(__VA_ARGS__)
#ifndef DBG
#define trace(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U> inline bool chmax(T &a, const U &b) { return b > a && (a = b, true); }
template <class T, class U> inline bool chmin(T &a, const U &b) { return b < a && (a = b, true); }
inline i64  sigma(i64 n)            { return (n * (n + 1) >> 1); }
inline i64  updiv(i64 a, i64 b)     { return (a + b - 1) / b; }
inline i64  sqr(i64 n)              { return n * n; }
inline string to_string(char c)     { return string(1, c); }
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

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

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

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

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

template <typename Func>
struct FixPoint : Func {
    inline constexpr FixPoint(Func &&f) noexcept : Func(forward<Func>(f)) {}

    template <typename... Args>
    inline decltype(auto) operator()(Args &&... args) const {
        return Func::operator()(*this, forward<Args>(args)...);
    }
};

template< typename Func >
inline decltype(auto) makeFixPoint(Func &&f) {
    return FixPoint< Func >{forward< Func >(f)};
}
// }}} End Header

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

    var(i64, N, K);

    vector<i64> x(N);
    rep(i, N) input(x[i]);

    int l = 0;
    int r = K - 1;

    i64 ans = LINF;
    while(r < N) {
        if (x[l] <= 0 && x[r] <= 0) {
            chmin(ans, abs(x[l]));
        }
        else if (x[l] <= 0 && x[r] >= 0) {
            chmin(ans, min(
                        abs(x[l]) * 2 + abs(x[r]),
                        abs(x[l]) + abs(x[r]) * 2));
        }
        else if (x[l] >= 0 && x[r] >= 0) {
            chmin(ans, abs(x[r]));
        }
        else {
            trace("Error");
        }
        ++l; ++r;
    }

    print(ans);

    return 0;
}


Measured memory_bytes: 1024
N, K = map(int, input().split())
darega = [[] for _ in range(N)]
for i in range(K):
    _ = input()
    hito = map(int, input().split())
    for j in hito:
        darega[j-1].append(i+1)
ans = 0
for x in darega:
    if x == []:
        ans += 1
print(ans)

Measured memory_bytes: 9300
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<ctime>
#include<map>
#include<bitset>
#include<set>
#define LL long long
#define mp(x,y) make_pair(x,y)
#define pll pair<long long,long long>
#define pii pair<int,int>
using namespace std;
inline int read()
{
	int f=1,x=0;char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
    if(!x){putchar('0');return;}
    int top=0;
    while(x)stack[++top]=x%10,x/=10;
    while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x);putchar(' ');}
inline void pr2(int x){write(x);putchar('\n');}
const int MAXN=100005;
struct edge{int x,y,next;}a[2*MAXN];int len,last[MAXN];
void ins(int x,int y){len++;a[len].x=x;a[len].y=y;a[len].next=last[x];last[x]=len;}
int d[MAXN],fa[MAXN];
void dfs(int x,int c)
{
	d[x]=c;
	for(int k=last[x];k;k=a[k].next)
	{
		int y=a[k].y;
		if(y!=fa[x])fa[y]=x,dfs(y,c+1);
	}
}
bool check(int x,int f)
{
	for(int k=last[x];k;k=a[k].next)if(a[k].y!=f)return false;
	return true;
}
int n;
int cnt[MAXN],ln;
bool mark[MAXN];
int ans[MAXN];
int main()
{
	n=read();
	for(int i=1;i<n;i++)
	{
		int x=read(),y=read();
		ins(x,y);ins(y,x);
	}
	fa[1]=0;dfs(1,0);
	int L=0;
	for(int i=1;i<=n;i++)if(d[i]>d[L])L=i;
	fa[L]=0;dfs(L,0);
	int R=0;
	for(int i=1;i<=n;i++)if(d[i]>d[R])R=i;
	for(int i=R;;i=fa[i])
	{
		mark[i]=true;++ln;
		for(int k=last[i];k;k=a[k].next)
		{
			int y=a[k].y;
			if(y!=fa[i]&&!mark[y])
			{
				if(!check(y,i))return puts("-1"),0;
				cnt[ln]++;
			}
		}
		if(i==L)break;
	}
	bool op=false;
	for(int i=1;i<=ln;i++)
	{
		if(cnt[ln-i+1]<cnt[i]){op=true;break;}
		if(cnt[ln-i+1]>cnt[i])break;
	}
	if(op)reverse(cnt+1,cnt+1+ln);
	int len=0;
	for(int i=1,lst=0;i<=ln;i++)
	{
		if(!cnt[i])ans[++len]=++lst;
		else
		{
			int ps=++lst;
			for(int j=1;j<=cnt[i];j++)ans[++len]=++lst;
			ans[++len]=ps;
		}
	}
	for(int i=1;i<=n;i++)pr1(ans[i]);
	return 0;
}


Measured memory_bytes: 9472
<?php
$N = explode(" ",fgets(STDIN));
$ab = abs($N[1]-$N[0]);
$bc = abs($N[2]-$N[1]);
$ac = abs($N[2]-$N[0]);
if ($ab<=$N[3]and$bc<=$N[3]or$ac<=$N[3]){
echo "Yes";
}else{
echo "No";
}

Measured memory_bytes: 3576
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<list>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
#define MK make_pair
const ll E=1e18+7;
const ll MOD=1000000007;

ll count(ll a){
    ll ret=0;
    for(int i=1;i<=a;i++){
        if(a%i==0){ret++;}
    }
    return ret;
}



int main(){
    ll n;
    cin>>n;
    ll c=0;
    for(int i=1;i<=n;i+=2){
        if(count(i)==8){c++;}
    }
    cout<<c<<endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //全ての標準ライブラリ
#define rep(i,n) for(int i = 0;i < n;i++)
using namespace std;
int sumVector (const std::vector<int>& v){ //int配列計算
    int sum = 0;
    rep(i, v.size()) sum += v.at(i);
    return sum; 
}
int main(void){
    int n,m,sum = 0, cnt = 0;
    cin >> n >> m;
    std::vector<int> a(n);
    rep(i,n){
        cin >> a[i];
        sum += a[i];
    }
    double kizyun= double(sum) / (4 * m);
    rep(i,n){
        if(a[i] >= kizyun) cnt++;
    }
    if(cnt >= m) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#pragma GCC optimize("Ofast")
//*********************************************DO IT NOW****************************************************************
#include<bits/stdc++.h> 
#include<random>
#define int long long   
#define pp pair<int,int> 
#define ss second 
#define ff first 
#define pb push_back
#define mod 1000000007
#define pi 3.14159265359
#define mk(arr,n,type)  type *arr=new type[n];
#define sl s1.length();
#define yes cout<< "YES"<<endl
#define no  cout<< "NO"<<endl
#define all(v) (v).begin(),(v).end()
#define s(v)   sort(v,v+n)
#define  mt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define read(a,n) for(int i=0;i<n;i++)cin>>a[i]
#define print(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" "
#define for1(i,a,n)  for(int i=0;i<n;i++)
#define rep(i, c) for(int i = 0; i < (int)c; i++)
using namespace std;
//**********************************************DO IT NOW***************************************************************
void fastio()
{  
  #ifndef ONLINE_JUDGE
  freopen("INPUT.txt","r",stdin);
  freopen("OUTPUT.txt","w",stdout); 
  #endif
  ios_base :: sync_with_stdio(false); 
  cin.tie(NULL) ; 
  cout.tie(NULL);
}
int dp[101][1001],ans1=1e9,dp1[1000001];
int num[10];
int a[1000000];
signed main()
{   
    fastio();
    int t=1;
   // cin>>t;
    while(t--)
    { 
        int n;
        cin>>n;
        cout<<2*pi*n;
    }
}
    
// 🍪 🍪 🍪


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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   400005
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/

ll a[N];

int main()
{
    char c,x;
    cin>>c;
    ll k=c-'0'+1;
    x=k+'0';
    cout<<x<<endl;

    return 0;
}
































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

int main(){
  int n,t;
  int d[100000];
  cin >> n >> t;
  for(int i=0;i<n;i++)cin >> d[i];

  sort(d,d+n);
  long long ans = 1, m = 1000000007;
  for(int i=0;i<n;i++){
    int prv = lower_bound(d,d+n,d[i]-t) - d;
    ans *= i-prv+1; ans %= m;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1564
#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

const int MAX_N = 1e5 + 5;

ll L [MAX_N];
ll R [MAX_N];

int main () {
  ios::sync_with_stdio(false);

  int n;
  cin >> n;

  for (int i = 0; i < n; i++) {
    cin >> L[i] >> R[i];
    L[i] *= 2;
    R[i] *= -2;
  }

  sort(L, L + n, greater<ll>());
  sort(R, R + n, greater<ll>());

  ll cur = 0;
  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, cur + L[i]);
    ans = max(ans, cur + R[i]);
    cur += L[i] + R[i];
    ans = max(ans, cur);
  }

  cout << ans << endl;
}


Measured memory_bytes: 5196
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
 
int n,x[15],y[15],p[15],D[15],d[15];
ll ans[16];
 
int main(){
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    cin>>n;
    for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>p[i];
    memset(ans,0x3f,sizeof(ans));
    ans[0]=0;
    for(int i=0;i<n;i++){
        D[i]=min(abs(x[i]),abs(y[i]));
        ans[0]+=(ll)p[i]*D[i];
    }
    for(int s=0;s<1<<n;s++){
        for(int t=s;t;t=(t-1)&s){
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    if(t>>i&1){
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(x[i]-x[j]));
                        }
                    }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                    }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
        }
        {
            int t=0;
            memcpy(d,D,sizeof(d));
            for(int i=0;i<n;i++){
                if(s>>i&1){
                    if(t>>i&1){
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(x[i]-x[j]));
                        }
                    }else{
                        for(int j=0;j<n;j++){
                            d[j]=min(d[j],abs(y[i]-y[j]));
                        }
                    }
                }
            }
            ll cur=0;
            for(int i=0;i<n;i++){
                cur+=(ll)d[i]*p[i];
            }
            ans[__builtin_popcount(s)]=min(ans[__builtin_popcount(s)],cur);
        }
    }
    for(int i=0;i<=n;i++)cout<<ans[i]<<'\n';
 
    return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define il inline
#define vd void
typedef long long ll;
il ll gi(){
	ll x=0,f=1;
	char ch=getchar();
	while(!isdigit(ch))f^=ch=='-',ch=getchar();
	while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
	return f?x:-x;
}
int n,d,x[11][11];
il double dist(int a,int b){
	int tot=0;
	for(int i=1;i<=d;++i)tot+=(x[a][i]-x[b][i])*(x[a][i]-x[b][i]);
	return sqrt(tot);
}
int main(){
#ifdef XZZSB
	freopen("in.in","r",stdin);
	freopen("out.out","w",stdout);
#endif
	n=gi(),d=gi();
	for(int i=1;i<=n;++i)
		for(int j=1;j<=d;++j)
			x[i][j]=gi();
	int ans=0;
	for(int i=1;i<=n;++i)
		for(int j=i+1;j<=n;++j){
			double x=dist(i,j);
			if(fabs(x-round(x))<1e-9)++ans;
		}
	printf("%d\n",ans);
	return 0;
}



Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

typedef pair<int, int> P;
#define fs first
#define sc second

int main() {
    ll x;
    cin >> x;

    ll d = x / 500;
    ll ans = d * 1000;
    x -= d * 500;

    d = x / 5;
    ans += d * 5;

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

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF 1000000000
#define MOD 1000000007
#define EPS 0.00000001


class UnionFind {
public:
    vector<int> Parent;

    UnionFind(int N){
        Parent = vector<int>(N, -1);
    }
    
    int root(int A){
        if(Parent[A] < 0) return A;
        else return Parent[A] = root(Parent[A]);
    }
    
    int size(int A){
        return -Parent[root(A)];
    }
    
    bool unite(int A, int B){
        A = root(A);
        B = root(B);
        if(A==B) return false;
        
        if(size(A) < size(B)) swap(A, B);
        Parent[A] += Parent[B];
        Parent[B] = A;
        return true;
    }
};

int main(){
    ll N, M; cin >> N >> M;
    UnionFind U(N);
    vector<PII> E(M);
    for(int i=0; i<M; i++){
        ll a, b; cin >> a >> b;
        a--; b--;
        E[i] = PII(a, b);
    }
    
    ll X = (N-1)*N/2;
    vector<ll> G(N);
    vector<ll> S(N, 1);
    vector<ll> Ans;
    
    for(ll i=M-1; i>=0; i--){
        Ans.push_back(X);
        ll a = E[i].first;
        ll b = E[i].second;
        if(U.root(a)!=U.root(b)){
            X -= (ll)U.size(a)*U.size(b);
            U.unite(a, b);
        }
    }
    
    for(int i=M-1; i>=0; i--)
        cout << Ans[i] << endl;
    
    return 0;
}


Measured memory_bytes: 4980
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n = I()

    return

#B
def B():
    n = I()

    return

#C
def C():
    n = I()
    t = LI()
    a = LI()
    f = [1]*n
    h = [float("inf")]*n
    ma = 0
    for i in range(n):
        if t[i] > ma:
            ma = t[i]
            f[i] = 0
        h[i] = ma
    ma = 0
    for i in range(n)[::-1]:
        if a[i] > ma:
            ma = a[i]
            if not f[i] and h[i] != ma:
                print(0)
                return
            f[i] = 0
            if h[i] < ma:
                print(0)
                return
        if ma < h[i]:
            h[i] = ma
    ans = 1
    for i in range(n):
        if f[i]:
            ans *= h[i]
            ans %= mod
    print(ans)
    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 76900
var lines = [];

var readline = require('readline');

var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var N = Number(lines.shift());
    var b = Array(N + 1);

    var tmp = lines[0].split(" ");
    b[0] = -1;
    for (var i = 0; i < N; i++) {
        b[i + 1] = Number(tmp[i]);
    }

    var result = [];

    for (var i = 1; i <= N; i++) {
        var max = -1;
        for (var j = 1; j <= b.length; j++) {
            if (b[j] === j) { max = j; }
        }
        if (max !== -1) {
            result.push(b.splice(max, 1));
        }
        else {
            console.log("-1");
            return (0);
        }
    }
    for (var i = 0; i < N; i++) {
        console.log(Number(result.pop()));
    }
});

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

typedef long long int ll;
typedef pair<int, int> P;

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int a, b;
  cin >> a >> b;

  if (a == b) {
    cout << "Draw" << endl;
    return 0;
  }

  if (a == 1) {
    cout << "Alice" << endl;
    return 0;
  } else if (b == 1) {
    cout << "Bob" << endl;
    return 0;
  }

  if (a > b) {
    cout << "Alice" << endl;
    return 0;
  } else {
    cout << "Bob" << endl;
    return 0;
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cstdio>
using namespace std;
int main(void) {
    string n;

    cin >> n;
    if (n == "ABC")
        cout << "ARC" << endl;
    else
    {
        cout << "ABC" << endl;
    }

    return 0;
}

Measured memory_bytes: 3628
# 29
S = str(input())

ans = 100000
i = 0
while i < len(S) - 2:
    x = int(str(S[i]) + str(S[i + 1]) + str(S[i + 2]))
    ans = min(ans, abs(753 - x))
    i += 1

print(ans)

Measured memory_bytes: 9176
{-# LANGUAGE BangPatterns #-}
 
module Main
  ( main
  )
where
 
import           Control.Applicative
import           Control.Monad
import           Control.Monad.ST
import           Data.Bits
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as MV
import qualified Data.Vector.Unboxed           as UV

parse = fst . fromJust
parseInt = parse . BS.readInt
parseInteger = parse . BS.readInteger
readInt = parseInt <$> BS.getLine
readInteger = parseInteger <$> BS.getLine
readIntList = map parseInt . BS.words <$> BS.getLine
readIntegerList = map parseInteger . BS.words <$> BS.getLine

m = 1000000000 + 7

main = do
  n <- readInt
  arr <- group . sort <$> readIntegerList
  print $ solve arr

solve (x:xs)
  | head x == 0 && length x == 1 = solve xs
  | head x /= 0 && length x == 2 = (2 * solve xs) `mod` m
  | otherwise = 0
solve _ = 1


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

using namespace std;

vector<int> ans1,ans2;

int main()
{
  int n,i;

  scanf("%d",&n);
  ans1.resize(n);
  ans2.resize(n);
  ans1[0]=1;
  ans2[0]=1+(20000*(n-1));
  for(int c=1;c<n;c++)
  ans1[c]=ans1[c-1]+20000,ans2[c]=ans2[c-1]-20000;
  for(int c=0;c<n;c++)
  {
    scanf("%d",&i);
    ans1[i-1]+=c;
  }
  printf("%d",ans1[0]);
  for(int c=1;c<n;c++)
  printf(" %d",ans1[c]);
  printf("\n");
  printf("%d",ans2[0]);
  for(int c=1;c<n;c++)
  printf(" %d",ans2[c]);
  printf("\n");
}


Measured memory_bytes: 768
A,B,K = map(int, input().split())

for k in range(K):
    if k%2 == 0:
        A = A - A%2
        A,B = A//2, B + A//2
    else:
        B = B - B%2
        A,B = A + B//2, B//2

print(A,B)


Measured memory_bytes: 2940
import sys
sys.setrecursionlimit(20000000)
input = sys.stdin.readline
mod = 10**9 + 7
n = int(input())
s = input().rsplit()[0]
kuro = [0]*n
siro = [0]*n
for i in range(n):
    if s[i] == "#":
        siro[i]+=1
    if s[-i-1] == ".":
        kuro[-i-1] += 1
    siro[i] += siro[i-1]
    kuro[-i-1] += kuro[-i]
ans = min(kuro[0],siro[-1])
for i in range(1,n):
    ans = min(ans,siro[i-1]+kuro[i])
print(ans)

Measured memory_bytes: 21188
N = int(input())
p = list(map(lambda x: float(x), input().split()))

#dp[i][h] = i+1番目までで表h枚の確率
dp = [[0]*(N+1) for i in range(N)]
dp[0][0] = 1-p[0]
dp[0][1] = p[0]

for i in range(1, N):
  for h in range(N+1):
    dp[i][h] = dp[i-1][h]*(1-p[i]) + (0 if h==0 else dp[i-1][h-1]*p[i])
    
print(sum(dp[N-1][int((N+1)/2):]))

Measured memory_bytes: 261768
import java.util.*;

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

        int n = sc.nextInt();

        if(n%10 == 3){
            System.out.println("bon");
        }
        else if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8){
            System.out.println("pon");
        }
        else{
            System.out.println("hon");
        }
    }
}

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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var solver = new Solver();
            solver.Calc();
        }

    }
    public class Solver
    {
        public void Calc()
        {
            var N = int.Parse(Console.ReadLine());

            long sum = 0;
            foreach (var i in Enumerable.Range(1, N))
            {
                if (i % 3 != 0 && i % 5 != 0)
                {
                    sum += i;
                }
            }
            Console.WriteLine(sum);

        }


    }
}


Measured memory_bytes: 18672
#include <iostream>
#include <cstring>
using namespace std;
char s[100001],c;
int n,i,nr1,nr2;
int main()
{
    cin>>s;
    n=strlen(s);
    c=1;
    for(i=0;i<n;i++)
     {if(s[i]!=c+'0')
     nr1++;
     c^=1;
     }
     c=0;
    for(i=0;i<n;i++)
     {if(s[i]!=c+'0')
     nr2++;
     c^=1;
     }
     cout<<min(nr1,nr2);
    return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <stack>
#include <vector>
#include <iostream>
#include <stdlib.h>
using namespace std;

int main()
{

  int n,m;
  int v[100001]={};
  cin >> n >> m;

  for(int i=0;i<m;i++){
    int x,y;
    cin >> x >> y;  x--;  y--;
    v[x]++;
    v[y]++;
  }

  bool flag = false;

  for(int i=0;i<n;i++){
    if(v[i]%2 == 1){
      flag = true;
      break;
    }
  }


  if(flag)
    cout << "NO" << endl;
  else
    cout << "YES" << endl;

  return 0;
}

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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var line = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int A = line[0], B = line[1];
            Console.WriteLine(A * B % 2 == 1 ? "Yes":"No");
        }
    }
}


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

typedef long long ll;

#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back

const long double PI = acos(-1);

ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll GetDigit(ll num) {return log10(num)+1;}

int main(){
  ll n, k;
  cin >> n >> k;
  cout << (int)(log(n)/log(k)+1) << endl;
  return 0;
}

Measured memory_bytes: 640
#include<cstdio>
using namespace std;
int a,b;
int main()
{
while(true){
 scanf("%d%d",&a,&b);
 if(a==0&&b==0)break;
 if(a<b)printf("%d %d\n",a,b);
 else printf("%d %d\n",b,a);
}
return 0;
}

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

#include <iostream>
#include <vector>

using namespace std;

#define rep(i,n) for(int i = 0; i < (n); ++i)

typedef long long ll;

int GetLoopEntrance(vector<int> a, ll n, int *loopStartAt, int *loopSize)
// 戻り値：ループが始まるまでの手数
{
    int count = 1;
    vector<int> visited(n,0); // 訪れた事がある場合は最初に訪れるまでの手数
    
    *loopStartAt = 0;
    while(1){
        if (visited[*loopStartAt]) break; // visited[pos]が0以外なら、既に訪れた場所
        visited[*loopStartAt] = count++;
        *loopStartAt = a[*loopStartAt];
    }

    // ループの長さを調べる
    int pos = *loopStartAt;
    *loopSize = 0;
    // pos = loopStart;
    while(1){
        pos = a[pos];
        ++(*loopSize);
        if (pos == *loopStartAt) break;
    }

    // ループが始まるまでの手数
    count = 0;
    pos = 0;
    while(1){
        if (pos == *loopStartAt) break;
        pos = a[pos];
        ++count;
    }
    return count;
}

signed main()
{
    ll n,k; cin >> n >> k;
    vector<int> a(n); rep(i,n) cin >> a[i], --a[i]; // 0-base にしておく

    if (k <= n){ // k が小さい場合は、全部やってみる
        int pos = 0;
        rep(i,k) pos = a[pos];
        cout << pos + 1 << endl;
        return 0;
    }

    // k > n の場合
    int loopStartAt, loopSize;
    int moveTimeBeforeLoop = GetLoopEntrance(a,n,&loopStartAt,&loopSize);

    // k > n なので k > (loopStartAt + loopSize)
    k -= moveTimeBeforeLoop;
    int goal = k % loopSize;
    int pos = loopStartAt;
    rep(i,goal) pos = a[pos];
    cout << pos + 1 << endl;  // 0-base にしたので解答に1を足す

    return 0;
}


Measured memory_bytes: 5640
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

typedef long long ll;
ll ans;

int main(){
	int i, j, n, k;
	while(~scanf("%d %d", &n, &k)){
		ans = k;
		for(i = 0; i < n - 1; i++)
			ans *= k - 1;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

#define rep(i, n) for (int i = 0; i < n; i = i + 1)
#define MAX 10010
#define MAX_INT 9223372036854775807

int asc(const void * a, const void * b) {
  // printf("a: %d\n", *(int *)a);
  // printf("b: %d\n", *(int *)b);
  return *(int *)a - *(int *)b;
}

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  int p[n];
  rep(i, n) {
    scanf("%d", p + i);
  }

  qsort(p, n, sizeof(int), asc);

  /* rep(i, n) { */
  /*   printf("i: %d\n", i); */
  /*   printf("p[i]: %d\n", p[i]); */
  /* } */

  int ans = 0;
  rep(i, k) {
    ans += p[i];
  }

  printf("%d\n", ans);

  return 0;
}


Measured memory_bytes: 1728
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    long A=gl();
	    long B=gl();
	    long K=gl();
	    
       // System.out.print(sb.toString());

        if (A>K) {
        	System.out.println((A-K) + " " + B);
        }else if(A+B>K){
        	System.out.println("0 " + (B-K+A));
        } else {
        	System.out.println("0 0");
        }
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 38728