akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;

int main() {
    int H,W;
    cin >> H >> W;
    vector<string> S(H);
    vector<vector<int>> wi(H, vector<int>(W, 0));
    vector<vector<int>> hi(H, vector<int>(W, 0));
    rep(i,H) cin >> S[i];
    rep(h,H){
      rep(w,W){
        if(S[h][w] == '#')continue;
        if(w == 0){
          wi[h][w] = 1;
          continue;
        }
        wi[h][w] = wi[h][w-1]+1;
      }
      rep(w,W){
        int rw = W-w-1;
        if (S[h][rw] == '#') continue;
        if(rw == W-1) continue;
        wi[h][rw] = max(wi[h][rw],wi[h][rw+1]);
      }
    }
    rep(w, W) {
        rep(h, H) {
            if (S[h][w] == '#') continue;
            if (h == 0){
              hi[h][w] = 1;
              continue;
            }
            hi[h][w] = hi[h-1][w] + 1;
        }
        rep(h, H) {
            int rh = H - h - 1;
            if (S[rh][w] == '#') continue;
            if (rh == H - 1) continue;
            hi[rh][w] = max(hi[rh][w],hi[rh+1][w]);
        }
    }
    int ans = 0;
    rep(h,H)rep(w,W){
      ans = max(ans,hi[h][w]+wi[h][w]);
    }
    cout << ans-1 << endl;
}

Measured memory_bytes: 35712
//
//  ALDS1_2_A.cpp
//  
//
//  Created by mk on 2015/11/23.
//
//

#include <stdio.h>
#include <iostream>
using namespace::std;

void bubbleSort(int* A, int N){
    int flag = 1;
    int cnt = 0;
    while (flag) {
        flag = 0;
        for (int j = N-1; j > 0; j--) {
            if (A[j] < A[j-1]) {
                int temp = A[j];
                A[j] = A[j-1];
                A[j-1] = temp;
                flag = 1;
                cnt++;
            }
        }
    }
    
    for (int i = 0; i < N; i++) {
        cout << A[i];
        if(i != N-1){
            cout << " ";
        }
    }
    cout << "\n";
    cout << cnt;
    cout << endl;
}


int main(int argc, const char * argv[]) {
    int n;
    int A[100];
    cin >> n;
    for (int i = 0; i < n; i++) {
        scanf("%d", &A[i]);
    }
    bubbleSort(A, n);
    
    return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    int n,t; cin>>n>>t;
    vector<int> a(n), b(n);
    rep(i,n) cin>>a[i]>>b[i];

    vector<vector<ll>> dp(n+1, vector<ll>(t+2, 0));
    vector<vector<ll>> rdp(n+1, vector<ll>(t+2, 0));

    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= t; ++w) {
            chmax(dp[i+1][w], dp[i][w]);
            if (w-a[i]>=0) {
                chmax(dp[i+1][w], dp[i][w-a[i]]+b[i]);
            }
        }
    }

    vector<int> c(b);
    reverse(a.begin(), a.end());
    reverse(b.begin(), b.end());

    for (int i = 0; i < n; ++i) {
        for (int w = 0; w <= t; ++w) {
            chmax(rdp[i+1][w],rdp[i][w]);
            if (w-a[i]>=0) {
                chmax(rdp[i+1][w], rdp[i][w-a[i]]+b[i]);
            }
        }
    }

    ll ans = 0;
    rep(i,n) {
        ll tmp = 0;
        int u = t-1;
        rep(j,t) {
            int p = u-j;
            ll x = dp[i][j]+rdp[n-i-1][p]+c[i];
            chmax(tmp,x);
        }
        chmax(ans,tmp);
    }

    cout << ans << '\n';

    return 0;
}

// 0 2
// 1 1
// 2 0

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

namespace AtCoder.Question
{
    public class QuestionB
    {
        public static void Main(string[] args)
        {
            var (x, y) = ReadHelper.ReadValue<decimal, decimal>();
            var tsuru = 2 * x - y / 2;
            var kame = y / 2 - x;
            Console.WriteLine(tsuru >= 0 && kame >= 0 && (int)tsuru == tsuru && (int)kame == kame ? "Yes" : "No");
        }

        static class ReadHelper
        {
            internal static T ReadValue<T>()
            {
                return (T)Convert.ChangeType(Console.ReadLine(), typeof(T));
            }
            internal static (T1, T2) ReadValue<T1, T2>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)));
            }
            internal static (T1, T2, T3) ReadValue<T1, T2, T3>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)));
            }
            internal static (T1, T2, T3, T4) ReadValue<T1, T2, T3, T4>()
            {
                var input = Console.ReadLine().Split(' ');
                return ((T1)Convert.ChangeType(input[0], typeof(T1)), (T2)Convert.ChangeType(input[1], typeof(T2)), (T3)Convert.ChangeType(input[2], typeof(T3)), (T4)Convert.ChangeType(input[3], typeof(T4)));
            }
            internal static T[] ReadValues<T>()
            {
                var input = Console.ReadLine().Split(' ');
                return input.Select(x => (T)Convert.ChangeType(x, typeof(T))).ToArray();
            }
        }

        static class MathAlgorithm
        {
            internal static bool IsPrime(long n)
            {
                if (n == 2) return true;
                if (n < 2 || n % 2 == 0) return false;
                var sqrt = Math.Sqrt(n);
                for (int i = 3; i <= sqrt; i += 2) if (n % i == 0) return false;
                return true;
            }
            internal static IEnumerable<long> EnumeratePrimes(long n)
            {
                var i = 2L;
                while (i * i <= n)
                {
                    if (n % i == 0)
                    {
                        n /= i;
                        yield return i;
                    }
                    else
                    {
                        i += i == 2 ? 1 : 2;
                    }
                }
                if (n != 1) yield return n;
            }
        }
    }
}


Measured memory_bytes: 27592
#include<stdio.h>

int main (void){
  int k,a,b;
  
  scanf("%d %d %d",&k,&a,&b);
  
  for(int i = a;i <=b;i++){
    if(i%k==0){
      printf("OK");
      return 0;
    }
  }
  printf("NG");
  
  return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vll = vector<long long>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;
    for (int i = 0; r*i <= n; ++i) {
        for (int j = 0; r*i + g*j <= n; ++j) {
            int bk = n - r*i - g*j;
            if (bk%b) continue;
            ans++;  
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#include <queue>
#include <cstdio>
inline int getInt(){ int s; scanf("%d", &s); return s; }

#include <set>
using namespace std;

int main(){
  while(true){
    const int n = getInt();
    const int m = getInt();
    const int l = getInt();
    const int k = getInt();

    if(n + m + l + k == 0) break;

    vector<vector<int> > e(n, vector<int>(n));
    vector<vector<vector<int> > >
      memo(n, vector<vector<int> >(1 << l));

    REP(i,m){
      const int a = getInt() - 1;
      const int b = getInt() - 1;
      const int c = getInt();
      e[a][b] = e[b][a] = c;
    }

    typedef pair<int, pair<int, int> > data;
    priority_queue<data, vector<data>, greater<data> > pq;

    const int s = getInt() - 1;
    const int g = getInt() - 1;

    vector<int> boll(n);
    REP(i,l) boll[getInt() - 1] = i + 1;

    pq.push(data(0, make_pair(0, s)));

    while(pq.size()){
      const data d = pq.top(); pq.pop();
      const int cost = d.first;
      const int pos  = d.second.second;
      const int bs   = d.second.first | (boll[pos] ? (1 << (boll[pos] - 1)) : 0);

      if((int)memo[pos][bs].size() >= k){
        if(cost != memo[pos][bs][k - 1])
          continue;
      }else{
        memo[pos][bs].push_back(cost);
      }

      if(bs == (1 << l) - 1 && pos == g){
        if((int)memo[pos][bs].size() == k){
          break;
        }
      }

      REP(i,n) if(e[pos][i]){
        pq.push(data(cost + e[pos][i], make_pair(bs, i)));
      }
    }

    if((int)memo[g][(1 << l) - 1].size() != k){
      puts("NA");
    }else{
      printf("%d\n", memo[g][(1 << l) - 1][k - 1]);
    }
  }
}

Measured memory_bytes: 91544
#include <iostream>
#include <cstdio>
#include <algorithm>
#define rep(i,a,b) for(int i = a; i <= b; i++)
#define dep(i,a,b) for(int i = a; i >= b; i--)
using namespace std;
const int N = 3010;
int n, a[N];

struct edge { int to, pre; } e[N << 1]; int u[N], l = 0;
void ins(int a, int b) { e[++l] = (edge){b, u[a]}, u[a] = l; }
#define v e[i].to
#define reg(i,a) for(int i = u[a]; i; i = e[i].pre)

bool f[N];
void dfs(int x, int fa) {
	f[x] = false;
	reg(i,x) if (v != fa) {
		dfs(v, x);
		if (a[v] < a[x] && !f[v]) f[x] = true;
	}
}

int main() {
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a + i);
	rep(i,1,n - 1) {
		int a, b; scanf("%d%d",&a,&b);
		ins(a, b), ins(b, a);
	}
	rep(i,1,n) { dfs(i, 0); if (f[i]) printf("%d ",i); }
	printf("\n");
	return 0; 
}

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

#define int long long
#define pb push_back
#define f first
#define s second
#define all(container) container.begin(),container.end()

#define fast ios::sync_with_stdio(0); cin.tie(0)

int32_t main(){
  
    fast;
    int n; cin >> n;
    int ar[n+1];

    for(int i=1;i<=n;i++) cin >> ar[i];

    int leftgcd[n+1] = {0};
    int rightgcd[n+2] = {0};

    leftgcd[0] = 0;
    rightgcd[n+1] = 0;

    for(int i=1;i<=n;i++) leftgcd[i] = __gcd(ar[i],leftgcd[i-1]);

    for(int i=n;i>=1;i--) rightgcd[i] = __gcd(ar[i],rightgcd[i+1]);
    
    int maxx = -1;
    
    for(int i=1;i<=n;i++) maxx = max(maxx,__gcd(leftgcd[i-1],rightgcd[i+1]));

    cout << maxx;
    
    return 0;
} 

Measured memory_bytes: 2560
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;

namespace AtCorder
{
	public class Program
	{
		public static void Main()
		{
			int n = int.Parse(ReadLine());
			var list = ReadLine().Split().Select(x => int.Parse(x))
				.ToList();

			// 累積和を使う
			var sum = new List<double>();
			sum.Add(list[0]);
			for (int i = 1; i < n; i++)
			{
				sum.Add(sum[i - 1] + list[i]);
			}

			var ans = double.MaxValue;
			var list2 = new double[4];

			// 中央の区切りは全探索
			// 中央の区切りが移動した場合は、計算済みの左区切りと右区切りを利用する
			int left = 0;
			int right = 2;
			for (int i = 1; i < n - 2; i++)
			{
				// 左区間の区切り
				while (left < i &&
					 // sum[left + 1] - (sum[i] - sum[left + 1]) = 2 * sum[left + 1] - sum[i]
					 // sum[left] - (sum[i] - sum[left]) = sum[left] - sum[i] + sum[left] = 2 * sum[left] - sum[i]
					 // 境界を求める。一つ先が減っているなら、次へ移動する。
					 Math.Abs(2 * sum[left + 1] - sum[i]) < Math.Abs(2 * sum[left] - sum[i]))
				{
					left++;
				}

				// 右区間の区切り
				while (right < n &&
					// (sum[right] - sum[i]) - (sum[n-1] - sum[right]) = sum[right] - sum[i] - sum[n-1] - sum[right] = 2 * sum[right] - sum[i] - sum[n-1]
					Math.Abs(2 * sum[right + 1] - sum[i] - sum[n - 1]) < Math.Abs(2 * sum[right] - sum[i] - sum[n - 1]))
				{
					right++;
				}

				list2[0] = sum[left];
				list2[1] = sum[i] - sum[left];
				list2[2] = sum[right] - sum[i];
				list2[3] = sum[n - 1] - sum[right];
				ans = Math.Min(ans, list2.Max() - list2.Min());
			}

			WriteLine(ans);
		}
	}
}


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

int main() {
  
  int N;
  cin >> N;
  string S;
  int q=0;
  
  int i=0;
  while (i<N) {
    
    cin >> S;
    if (S=="P") q+=0;
    if (S=="W") q+=0;
    if (S=="G") q+=0;
    if (S=="Y") q+=1;
    
    if (q>0) break;
    i++;
  }
  
  if (q==0) cout << "Three" << endl;
  else cout << "Four" << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
#include<functional>
#include<cstdlib>
#include<queue>
#include<deque>
const double PI = acos(-1);
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
using ll =long long;
const int mod = 1000000007;

//map<string>a
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;
	}
};
int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}
//組み合わせ
void recursive_comb(vector<int> indexes, int s, int rest, std::function<void(vector<int>)> f) {
	if (rest == 0) {
		f(indexes);
	}
	else {
		if (s < 0) return;
		recursive_comb(indexes, s - 1, rest, f);
		indexes[rest - 1] = s;
		recursive_comb(indexes, s - 1, rest - 1, f);
	}
}

// nCkの組み合わせに対して処理を実行する
void foreach_comb(int n, int k, std::function<void(vector<int>)> f) {
	vector<int>indexes(k);
	recursive_comb(indexes, n - 1, k, f);
}

ll gcd(ll a, ll b) {
	if (a % b == 0) {
		return b;
	}
	else {
		return gcd(b, a % b);
	}
}
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
};


int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	int ans = 1;
	rep(i, N) {
		if (i > 0 && s[i] != s[i - 1]) {
			ans++;

		}

	}
	cout << ans;
}


Measured memory_bytes: 3320
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
int rate[1001];
double per[15][3];
double dp[15][1<<14][1<<3];
double dp2[1<<14];

double solve(int bit){
	if(dp2[bit]>=-0.1)return dp2[bit];
	if(bit==0)return 1.0;
	double res=0.0;
	for(int i=0;i<3;i++){
		double now=0.0;
		for(int j=1;j<8;j++){
			int nbit=j|(1<<i);
			if(nbit==1 || nbit==2 || nbit==4 || nbit==7){
				bool flag=true;
				for(int k=0;k<n-1;k++){
					if(rate[n-1]<rate[k] && (bit>>k & 1))flag=false;
				}
				if(flag)now+=dp[n-1][bit][j];
			}else{
				if(nbit==3 && i==0)continue;
				if(nbit==5 && i==2)continue;
				if(nbit==6 && i==1)continue;
				for(int k=(bit-1)&bit;k>=0;k=(k-1)&bit){
					double pr=1.0;
					int rest=3;
					if(nbit==3 && j==2)rest=2;
					if(nbit==3 && j==1)rest=1;
					if(nbit==5 && j==1)rest=2;
					if(nbit==5 && j==4)rest=1;
					if(nbit==6 && j==4)rest=2;
					if(nbit==6 && j==2)rest=1;

					for(int l=0;l<n-1;l++){
						if(!(bit>>l & 1))continue;
						if(nbit==3){
							if(k>>l & 1){
								if(j==1)pr=0.0;
								pr*=per[l][1];
								if(rest>=2)rest-=2;
							}
							else{
								if(j==2)pr=0.0;
								pr*=per[l][0];
								if(rest%2==1)rest-=1;
							}
						}
						if(nbit==5){
							if(k>>l & 1){
								if(j==4)pr=0.0;
								pr*=per[l][0];
								if(rest>=2)rest-=2;
							}else{
								if(j==1)pr=0.0;
								pr*=per[l][2];
								if(rest%2==1)rest-=1;
							}
						}
						if(nbit==6){
							if(k>>l & 1){
								if(j==2)pr=0.0;
								pr*=per[l][2];
								if(rest>=2)rest-=2;
							}else{
								if(j==4)pr=0.0;
								pr*=per[l][1];
								if(rest%2==1)rest-=1;
							}
						}
					}
					if(rest==0 && pr>1e-15)now+=pr*solve(k);
					if(k==0)break;
				}
			}
		}
		res=max(res,now);
	}
	dp2[bit]=res;
	return dp2[bit];
}

int main(void){
	scanf("%d",&n);
	scanf("%d",&rate[n-1]);
	for(int i=0;i<n-1;i++){
		scanf("%d",&rate[i]);
		for(int j=0;j<3;j++){
			scanf("%lf",&per[i][j]);
			per[i][j]/=100.0;
		}
	}
	for(int i=0;i<(1<<(n-1));i++){
		dp[0][i][0]=1.0;
	}
	for(int i=0;i<n-1;i++){
		for(int j=0;j<1<<(n-1);j++){
			for(int k=0;k<8;k++){
				if(dp[i][j][k]<1e-15)continue;
				if(j>>i & 1){
					for(int l=0;l<3;l++){
						dp[i+1][j][k|(1<<l)]+=dp[i][j][k]*per[i][l];
					}
				}else{
					dp[i+1][j][k]=dp[i][j][k];
				}
			}
		}
	}
	for(int i=0;i<(1<<n-1);i++){
		dp2[i]=-1.0;
	}
	printf("%.12f\n",solve((1<<n-1)-1));
	return 0;
}

Measured memory_bytes: 10544
n = int(input())
xs = input()
x = int(xs, 2)

ansl = [0]*n
for i in range(1,n):
    ans = 0
    num = i
    while True:
        pc = bin(num).count("1")
        num %= pc
        ans += 1
        if num == 0: break
    ansl[i] = ans

pc = bin(x).count("1")
if pc == 0:
    for i in range(n):
        print(1)
        exit()


next_num = x%pc
next_num_p1 = x%(pc+1)
if pc != 1:
    next_num_m1 = x%(pc-1)
else:
    next_num_m1 = None

for i in range(n):
    bit = (1<<(n-1-i))
    if xs[i] == '0':
        num = (next_num_p1 + pow(2,n-1-i,pc+1)) % (pc+1)
        ans = ansl[num] + 1
    else:
        if pc != 1:
            num = (next_num_m1 - pow(2,n-1-i,pc-1)) % (pc-1)
            ans = ansl[num] + 1
        else:
            ans = 0
    print(ans)

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



int main(){
    int n, h;
    cin >> n >> h;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }

    sort(a.begin(), a.end(), greater<int>());
    sort(b.begin(), b.end(), greater<int>());

    vector<ll> sum(n + 1);
    for (int i = 1; i <= n; i++){
        sum[i] = sum[i - 1] + b[i - 1];
    }

    int ans = h;

    for (int i = 0; i <= n; i++){
        int hp = h - sum[i];
        int cnt = (hp < 0?0:(hp + a[0] - 1) / a[0]);
        ans = min(ans, i + cnt);
    }

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

Measured memory_bytes: 1792
#include <cstdio>
#include <vector>
#include <iostream>
#include <queue>
#define INF 500000+500
#define Max 0x3f3f3f3f
#define Mod 1000000007
typedef long long int ll;
using namespace std;
struct edge{
	int next,to,dis;
}edge[INF];
int head[INF],pi=0,count[INF],cnt[INF],n,m;
int vis[INF],dis[INF];
queue<int> q;
void addedge(int from,int to,int dis)
{
	edge[++pi].next = head[from];
	edge[pi].to = to;
	edge[pi].dis = dis;
	head[from] = pi;
	
}
void init()
{ 
	for(int i=0; i<INF; i++)
	{
		vis[i] = 0;
		dis[i] = Max;
	}	
}
void bfs(int x,int fa)
{
	
	q.push(x);
	vis[x]=1;
	while(!q.empty())
	{
		int u = q.front();
		q.pop();
		cnt[u] ++;
		int color = u==1?m-1:m-2;	
		if(cnt[u] > n) {
			return ;
		}
		for(int i=head[u]; i; i=edge[i].next)
        {
            int v = edge[i].to;
            if(!vis[v])
            {
            	count[v] = color--;
                q.push(v);
                vis[v] = 1;
            }
        }
	}
	
	
}
int main() 
{
    
    cin >> n >> m;
    for(int i=1; i<n; i++) {
    	int x,y;
    	cin >> x >> y;
		addedge(x,y,1);
		addedge(y,x,1);
	}
	count[1]=m;vis[1]=1;
	bfs(1,0);
	ll ans = 1;
	for(int i=1; i<=n; i++) {
//		cout << count[i] << " ";
		ans *= count[i];
		ans %= Mod;
	}
	cout<<ans;
	
    return 0;
}

Measured memory_bytes: 11008
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#define REP(i,n) for(int i=0;i<(n);++i)
using namespace std;

int main(){
  int A, B, C;
  cin >> A >> B >> C;
  if(A == B && B == C) {
    cout << "No" << endl;
  } else if(A == B || B == C || C == A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

using namespace std;

typedef long long int ll;

const int N = 2e5 + 5;

vector < vector < int > > adj(N);

pair < int, int > dfs (int s) {
  vector < int > d(N, INT_MAX);
  d[s] = 0;
  queue < int > q;
  vector < bool > used(N, false);
  used[s] = true;
  q.push(s);
  int mx = s, mx_dis = 0;
  while (!q.empty()) {
    int u = q.front(); q.pop();
    for (auto to : adj[u]) {
      if (!used[to]) {
        d[to] = d[u] + 1;
        if (d[to] > mx_dis) {
          mx_dis = d[to];
          mx = to;
        }
        used[to] = true;
        q.push(to);
      }
    }
  }
  return {mx, mx_dis};
}

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

  int n;
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }

  int u = dfs(1).first;
  pair < int, int > p = dfs(u);
  int v = p.first, diameter = p.second;

  if (diameter % 3 == 1) {
    cout << "Second\n";
  } else {
    cout << "First\n";
  }
}


Measured memory_bytes: 13684
def examA():
    A, P = LI()
    ans = (A*3+P)//2
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examA()


Measured memory_bytes: 3544
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <iostream>
using namespace std;

int main() {
  string S;
  cin >> S;
  int s=S.size();
  if (s==1||s==2) {
    cout << S.at(0) << endl;
  }
  else {
    if (s%2==0) {
      for (int i=0; i<s/2-1; i++) {
        cout << S.at(2*i);
      }
      cout << S.at(s-2) << endl;
    }
    else {
      for (int j=0; j<(s-1)/2; j++) {
        cout << S.at(2*j);
      }
      cout << S.at(s-1) << endl;
    }
  }
}

Measured memory_bytes: 3756
#include <cmath>
#include <iostream>

using namespace std;

#define EPS 1e-9

#define PI 3.1415926535897932385

double dist(long long x, long long y)
{
	return sqrt(x * x + y * y);
}

double angle(int x, int y)
{
	return atan2((double)(y), (double)(x));
}

int main()
{
	int x0, y0, x1, y1, x2, y2, q;

	cin >> x0 >> y0 >> x1 >> y1 >> q;

	for (int i = 0; i < q; i++)
	{
		cin >> x2 >> y2;

		int ax = x1 - x0;
		int ay = y1 - y0;
		int bx = x2 - x0;
		int by = y2 - y0;

		double ad = dist(ax, ay);
		double bd = dist(bx, by);

		double at = angle(ax, ay);
		double bt = angle(bx, by);

		double st = bt - at;

		if (st < -PI - EPS)
		{
			st += 2 * PI;
		}

		if (st > PI + EPS)
		{
			st -= 2 * PI;
		}

		double da, db;

		if (bx != 0 || by != 0)
		{
			if (ax == 0 || bx == 0)
			{
				da = 1.0 * ax / ay;
				db = 1.0 * bx / by;
			}
			else
			{
				da = 1.0 * ay / ax;
				db = 1.0 * by / bx;
			}
		}

		if (bx == 0 && by == 0)
		{
			cout << "ON_SEGMENT" << endl;
		}
		else if (-EPS < db - da && db - da < EPS)
		{
			if (ax * bx < 0 || ay * by < 0)
			{
				cout << "ONLINE_BACK" << endl;
			}
			else
			{
				if (ad < bd)
				{
					cout << "ONLINE_FRONT" << endl;
				}
				else
				{
					cout << "ON_SEGMENT" << endl;
				}
			}
		}
		else if (st > EPS)
		{
			cout << "COUNTER_CLOCKWISE" << endl;
		}
		else
		{
			cout << "CLOCKWISE" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3388
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  int a; // to input 
  int b; // to input 
  int c; // to input 
  int d; // to input 
  int takahp = 0;
  int aohp = 0;

  scan = scanf("%d", &a);
  scan = scanf("%d", &b);
  scan = scanf("%d", &c);
  scan = scanf("%d", &d);

  while (a > 0)
  {
    takahp++;
    a = a - d;
  }
  while (c > 0)
  {
    aohp++;
    c = c - b; 
  }

  if (takahp < aohp)
    printf("No");
  else
    printf("Yes");
  return (0);
}


Measured memory_bytes: 1732
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
#include<complex>
using namespace std;

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<ll> vec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-5;
const ld pi = acos(-1.0);



void solve() {
	int n; cin >> n;
	vector<int> p(n);
	rep(i, n) {
		cin >> p[i];
	}
	vector<P> v;
	rep(i, n) {
		v.push_back({ p[i],i });
	}
	sort(v.begin(), v.end(), greater<P>());
	set<int> st;
	ll ans = 0;
	rep(i, n) {
		int loc = v[i].second;
		st.insert(loc);
		auto itr = st.find(loc);
		ll l1, l2, r1, r2;
		if (itr == st.begin()) {
			l1 = loc + 1; l2 = 0;
		}
		else {
			itr--;
			int z = *itr;
			l1 = loc - z;
			if (itr == st.begin()) {
				l2 = z+1;
			}
			else {
				itr--;
				int zz = *itr;
				l2 = z - zz;
				itr++;
			}
			itr++;
		}
		if (itr == --st.end()) {
			r1 = n - loc; r2 = 0;
		}
		else {
			itr++;
			int z = *itr;
			r1 = z - loc;
			if (itr == --st.end()) {
				r2 = n - z;
			}
			else {
				itr++;
				int zz = *itr;
				r2 = zz - z;
			}
		}
		ll num = r2 * l1 + r1 * l2;
		ans += num * v[i].first;
	}
	cout << ans << endl;
}

signed main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	//cout << fixed << setprecision(50);
	//init();
	solve();

	//cout << "finish" << endl;
	//stop
		return 0;
}


Measured memory_bytes: 6132
#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int cnt[100005]= {};
int main() {
  int n,k,q;
  cin >> n >> k >> q;
  vector<lli> a(q);
  rep(i,q){
    cin >> a[i],a[i]--;
    cnt[a[i]]++;
  }
rep(i,n){
  if(k-(q-cnt[i]) >0){
    cout << "Yes"<<endl;
  }else{
    cout << "No"<<endl;
  }
}


}


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

using namespace std;

const int INF = numeric_limits<int>::max();
const int MAXN = 1e6 + 100;
const int MOD = 1e9 + 7;
const double eps = 1e-6;
const double PI = acos(-1);
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

#define int int64_t

signed main() {
#if(DEBUG_LEVEL > 0)
    freopen("../input.txt", "r", stdin);
    freopen("../out.txt", "w", stdout);
#endif
    int n, m;
    cin >> n >> m;
    multiset <int> q;
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        q.insert(x);
    }
    int ans = 0;
    while(m > 0) {
        auto it = prev(q.end());
        int now = *it;
        q.erase(it);
        now /= 2;
        q.insert(now);
        m--;
    }
    for (auto u : q) {
        ans += u;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 4992
N = input()
H = input()


N = int(N)
H = [int(x) for x in H.split(" ")]
C = 0
R = 0
M = H[0]

while C < (N-1):
    if H[C] - H[C+1] > 1:
        R = 1
        C = N
    elif H[C] - H[C+1] == 1:
        if M > (H[C]-1):
            R = 1
            C = N
        else:
            M = max(M, H[C+1])
            C += 1
    else:
        C+=1

if R == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 15196
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{

  vector<char> kisuu = {'R', 'U', 'D'};
  vector<char> guusuu = {'L', 'U', 'D'};
  string s; cin >> s;
  ui res = true;
  for(size_t index = 0; index < s.size(); ++index)
  {
    if((index + 1) % 2){
      // kisuu
      if(s[index] == 'R'){
        continue;
      }
      else
      {
        
      }
    }
    else
    {
      if(s[index] == 'L'){
        continue;
      }
      else
      {
        
      }
    }
    if(s[index] == 'U' || s[index] == 'D'){
      continue;
    }
    else
    {
      res = false;
      break;
    }
  }

  cout << (res ? "Yes" : "No") << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
N,X = map(int,input().split())
a,p =[1],[1]
for i in range(N):
    a.append(a[i]*2+3)
    p.append(p[i]*2+1)
def f(N,X):
    if N==0: return 0 if X<=0 else 1
    elif X <=1+a[N-1]:
        return f(N-1,X-1)
    else:
        return p[N-1] + 1 + f(N-1,X-2-a[N-1])
print(f(N,X))

Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>

bool update(int*m, const std::vector<int>& max);

int main(int argc, char* argv[]){
  int n, k;
  std::ios::sync_with_stdio(false);

  std::vector<int> a;
  std::cin >> n >> k;
  std::cin.ignore(); 
  int id = 0;
  int min = INT_MAX;

  for(int i = 0; i < n; i++){
    int a_i;
    std::cin >> a_i;
    if (a_i < INT_MAX){
      id = i;
      min = a_i;
    }
    a.push_back(a_i);
  }

  int t_min(INT_MAX);
  int less_num = id - 1;
  int more_num = n - id;
  for(int i = 0; i < k; i++){
    int l_num = std::abs(less_num - i);
    int m_num = std::abs(more_num -  (k - i - 1));
    int t_l = (l_num == 0) ? 0: (l_num - 1)/ (k - 1) + 1;
    int t_m = (m_num == 0) ? 0: (m_num - 1)/ (k - 1) + 1;
//    std::cout << l_num << "/" << t_l << "," << m_num << "/" << t_m << std::endl;
    
    int t = 1 + t_l + t_m;
    if (t < t_min){
      t_min = t;
    }
  }

  std::cout << t_min;
  return 0;  
}


Measured memory_bytes: 892
S=input()
ls=list(map(int,[S[i] for i in range(4)]))
for bit in range(1<<3):
  su=ls[0]
  st=str(ls[0])
  for i in range(3):
    if bit&(1<<i):
      su+=ls[i+1]
      st=st+"+"+str(ls[i+1])
    else:
      su-=ls[i+1]
      st=st+"-"+str(ls[i+1])
  if su==7:
    st=st+"=7"
    print(st)
    exit()

Measured memory_bytes: 3064
/******************************************
* AUTHOR : HRITIK AGGARWAL *
******************************************/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
#define MOD 1000000007
#define dd double
#define vi vector<int>
#define vll vector<ll>
#define forr(i, n) for(int i = 0; i < n; i++)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,b) for(int i=1;i<=b;i++)
#define pb push_back
#define mp make_pair
#define clr(x) x.clear()
#define sz(x) ((int)(x).size())
#define ms(s, n) memset(s, n, sizeof(s))
#define F first
#define S second
ll po(ll a, ll x,ll m){ if(x==0){return 1;}ll ans=1;ll k=1;  while(k<=x) {if(x&k){ans=((ans*a)%m);} k<<=1; a*=a; a%=m; }return ans; }
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	/*#ifndef ONLINE_JUDGE
	 freopen("input.txt", "r", stdin);
	 freopen("a.txt", "w", stdout);
	#endif*/
	int n;
	cin>>n;
	int a[n];
	forr(i,n)
		cin>>a[i];
	int dp[n]={0};
	dp[n-1]=0;
	int mx=a[n-1];
	//mx[n-1] = a[n-1];
	for(int i=n-2;i>=0;i--){
		if(mx<=a[i]){
			dp[i] = dp[i+1]+1;
		}else{
			dp[i]=0;
		}
		mx = a[i];
	}	
	
	cout<<*max_element(dp,dp+n);
return 0;
}

Measured memory_bytes: 1152
def main():
    s = input()
    q = int(input())
    is_fwd = True
    before = ''
    after = ''

    for i in range(q):
        fields = [i for i in input().split()]
        t = int(fields[0])
        if t == 1:
            is_fwd = not is_fwd
        elif t == 2:
            f = int(fields[1])
            c = fields[2]
            if (f == 1) == is_fwd:
                before += c
            else:
                after += c

    res = before[::-1] + s + after
    if is_fwd:
        print(res)
    else:
        print(res[::-1])

main()


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

void readV(T...)(ref T t){auto r=readln.splitter;foreach(ref v;t){v=r.front.to!(typeof(v));r.popFront;}}

void main()
{
  int n; readV(n);
  auto l = new long[](n+1);
  l[0] = 2; l[1] = 1;
  foreach (i; 2..n+1) l[i] = l[i-1]+l[i-2];
  writeln(l[n]);
}


Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>){
    val sc = Scanner(System.`in`)
    val s = sc.next()
    var ans = 0L
    var wCnt = 0L
    for (i in 0 until s.length) {
        if (s[i] == 'W') {
            ans += i.toLong() - wCnt
            wCnt++
        }
    }
    println(ans)
}


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

if N == 1:
  ans = ["*"]
elif N == 2:
  ans = ["*","*"]
else: #N==3
  ans = ["*","*","*"]
  
ng = False
for i in range(M):
  s, c = input().split()
  s = int(s)-1
  if ans[s] != '*' and ans[s] != c:
    ng = True
    break
  elif s==0 and c=="0" and N>1:
    ng = True
    break
  else:
    ans[s] = c

if N == 1 and ans[0] == "*":
  ans[0] = "0"
if N == 2:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
if N == 3:
  if ans[0] == "*":
    ans[0] = "1"
  if ans[1] == "*":
    ans[1] = "0"
  if ans[2] == "*":
    ans[2] = "0"

if ng:
  print(-1)
else:
  print("".join(ans))

Measured memory_bytes: 3064
A, B, Q = map(int, input().split())

S = [0]*A
for i in range(A):
  S[i] = int(input())

T = [0]*B
for i in range(B):
  T[i] = int(input())

import bisect
ans = []
for i in range(Q):
  mini = 10**11
  x = int(input())
  indS = bisect.bisect(S,x)
  indT = bisect.bisect(T,x)
  if indS != A: #Sの右
    if indT != B:
        mini = min(max(S[indS],T[indT])-x,mini) #右右
        # print('rr',mini)
    if indT != 0:
        mini = min(S[indS]-T[indT-1]+min(S[indS]-x,x-T[indT-1]),mini) #右左
        # print('rl',mini)
  if indS != 0: #Sの左
    if indT != B:
        mini = min(T[indT]-S[indS-1]+min(x-S[indS-1],T[indT]-x),mini)  #左右
        # print('lr',mini)
    if indT != 0:
        mini = min(x-min(S[indS-1],T[indT-1]),mini) #左左
        # print('ll',mini)
  ans.append(mini)



# print(ans)
print(*ans, sep='\n')

Measured memory_bytes: 17972
# include<bits/stdc++.h>
using namespace std;
int main(){
  // taking input into an array
  int n;
  cin >> n;
  int arr[n];
  for(int i = 0; i < n; i++){
       cin >> arr[i];
  }
  sort(arr, arr+n);
  cout << arr[n/2]-arr[n/2-1] << '\n';
	return 0;
}

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

using namespace std;

int main(){
    string O,E;
    cin>>O>>E;

    for(int i=0;i<E.size();i++){
        cout<<O[i]<<E[i];
    }
    if(E.size()!=O.size())
        cout<<O[O.size()-1];
}


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

int main(void)
{
        int i,D,E,x,y;
        double result,min;

        while(1){
                min = 100;
                cin >> D >> E;
                if(D == 0 && E == 0){ 
                        break;
                }   
                    
                for(i = 0; i <= D /2; i++){
                        x = i;
                        y = D - i;
                        result = fabs(double(sqrt(x*x + y*y)) - E); 
                        if(result < min){
                                min = result;
                        }   
                }   
                cout << min << endl;
                    
        }   
        return 0;
}

Measured memory_bytes: 3184
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>    //pow(x,y)=x^y 99999とかの場合+1するif文
#include <algorithm> //sort(a.begin(), a.end());reverse(a.begin(), a.end());
#include <ctime>     //実行時間を測る
#define ll long long
#define vecvec(h,w,name) vector<vector<ll>> name(h, vector<ll>(w));
#define rep(init, i, n) for (ll i = init; i < (n); i++)
#define rev(s) reverse(s.begin(), s.end())
#define sor(v) sort(v.begin(), v.end()) //昇順
#define PI 3.14159265358979323846264338327950L
//コード自動整形 Shift + Option + F @vscode
//変数名一括置換　command+fn+f2 @vscode
using namespace std;
using vec = vector<ll>;
//function
ll facctorialMethod(ll k);     //階乗を出力する
ll modpow(ll a, ll n, ll mod); // a^n mod を計算する
ll gcd(ll a, ll b);//最大公約数
ll lcm(ll a, ll b);//最小公倍数
//

//struct
// UnionFind
// coding: https://youtu.be/TdR816rqc3s?t=726
// comment: https://youtu.be/TdR816rqc3s?t=6822
struct UnionFind
{
  vector<ll> d;
  UnionFind(ll n = 0) : d(n, -1) {}
  ll find(ll x)
  { //根っこを返す
    if (d[x] < 0)
      return x;
    return d[x] = find(d[x]); //根っこの場所を貼り付ける
  }
  bool unite(ll x, ll y)
  { //くっつける操作、連結成分の情報整理 ABC177,157D参照
    x = find(x);
    y = find(y);
    if (x == y)
      return false;
    if (d[x] > d[y])
      swap(x, y); //dはマイナスをかけたサイズだからxの方がサイズ小さいようにする
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  //find(i)でi番目の属しているグループ番号を出力
  bool same(ll x, ll y) { return find(x) == find(y); } //同じ集合に属しているかを判定
  ll size(ll x) { return -d[find(x)]; }                //あるID、xが所属するグループに所属するIDの数を得る ABC177,157D参照
};
//

/////main/////
int main()
{
  int clock_on = 0; //提出時は0!!!!!!!!!!!!!!!!!
  int time_clock = clock();
  //
  int N;
  cin>>N;
  N %= 10;
if(N==0||N==1||N==6||N==8){
cout<<"pon"<<endl;
}else if(N==3){
cout<<"bon"<<endl;
}else{cout<<"hon"<<endl;}
  //
  if (clock_on == 1)
    printf("Execution Time: %.4lf sec\n", 1.0 * (clock() - time_clock) / CLOCKS_PER_SEC);
  return 0;
}
/////main/////

/////function/////
//階乗を出力する
ll facctorialMethod(ll k)
{
  ll sum = 1;
  for (ll i = 1; i <= k; ++i)
  {
    sum *= i;
  }
  return sum;
}

// a^n mod を計算する
ll modpow(ll a, ll n, ll mod)
{
  ll res = 1;
  while (n > 0)
  {
    if (n & 1)
      res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

//最大公約数
ll gcd(ll a, ll b){
  if(a%b == 0){
    return b;
  }else{
    return gcd(b, a%b);
  }
}

//最小公倍数
ll lcm(ll a, ll b){
  return a*b / gcd(a, b);
}

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

#define int long long
#define pb emplace_back
#define f(i,a,n) for(int i=a ; i<n ; i++)
#define F first
#define S second
#define fast ios:: sync_with_stdio(false),cin.tie(0);

int32_t main(){
	fast;
	int n;
	cin >> n;
	
	int a[n],b[n];
	f(i,0,n)
	{
		cin >> a[i];
		b[i] = a[i];

	}
	sort(b,b+n);
	f(i,0,n)
	{
		if(a[i] == b[n-1])  cout << b[n-2] << "\n";
		else    cout << b[n-1] << "\n";
	}
}







Measured memory_bytes: 4736
//Author : Sidiq Tri Pratikto
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(v) v.begin(), v.end()

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> new_data_set;
//order_of_key(x) = number of elements stricly smaller than x
//find_by_order(x) = return x-th largest element
typedef long long LL;
const LL MOD = 998244353;
const double PI = 2 * acos(0);
int frek[200001];

int main() {
	int N, x;
	scanf("%d", &N);
	for (int i = 2; i <= N; i++) {
		scanf("%d", &x);
		frek[x]++;
	}
	for (int i = 1; i <= N; i++) {
		printf("%d\n", frek[i]);
	}
}

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

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

  int cnt;
  if (s[0] =='1') cnt = cnt + 1; 
  if (s[1] =='1') cnt = cnt+ 1; 
  if (s[2] =='1') cnt = cnt +1; 
 cout <<cnt  << endl;

}


Measured memory_bytes: 256
from collections import deque
import sys
input = sys.stdin.readline


def main():
    N, M, P = map(int, input().split())
    edge = []
    g = [[] for _ in range(N)]
    rg = [[] for _ in range(N)]
    for _ in range(M):
        A, B, C = map(int, input().split())
        A -= 1
        B -= 1
        C -= P
        C = -C
        edge.append((A,B,C))
        g[A].append(B)
        rg[B].append(A)

    # 0 => N-1の間にある閉路を検出したいので
    # 0とN-1からたどりつけない場所は前処理で取り除く
    
    visited1 = set() 
    visited2 = set()
    visited1.add(0)
    visited2.add(N-1)
    Q = deque()
    Q.append(0)
    while Q:
        v = Q.popleft()
        for dest in g[v]:
            if dest in visited1:
                continue
            visited1.add(dest)
            Q.append(dest)
    
    Q.append(N-1)
    while Q:
        v = Q.popleft()
        for dest in rg[v]:
            if dest in visited2:
                continue
            visited2.add(dest)
            Q.append(dest)
    
    OK = visited1 & visited2
    
    flag = True
    d = [float('inf')] * N
    d[0] = 0
    #ベルマンフォード法、N回実行してまだ更新されている場合は負の閉路が存在する
    #for _ in range(N):
    #    flag = False
    #    for a, b, c in edge:
    #        if not a in OK:
    #            continue
    #        if not b in OK:
    #            continue
    #        newD = d[a] + c
    #        if newD < d[b]:
    #            d[b] = newD
    #            flag = True
    #    if not flag:
    #        print(max(0,-d[N-1]))
    #        exit()
    #else:
    #    print(-1)
    #    exit()
    step = 0
    while flag:
        flag = False
        for A, B, C in edge:
            if not A in OK:
                continue
            if not B in OK:
                continue
            newD = d[A] + C
            if newD < d[B]:
                d[B] = newD
                flag = True
        step += 1
        if step > N:
            print(-1)
            exit()
 
    print(max(0,-d[N-1]))


if __name__ == "__main__":
    main()

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

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	int x; cin >> x;
	while (true) {
		bool isPrime = true;
		for (int i = 2; i <= sqrt(x); i++) {
			if (x % i == 0) {
				isPrime = false; 
				break;
			}
		}
		if (isPrime) break;
		x++;
	}
	cout << x;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Phuong_ ios_base::sync_with_stdio(0); cin.tie(0);
#define pb push_back
#define mp make_pair

/// easy access -------------
using namespace std;
using ll = long long;
using ld = long double;
typedef pair<int,int> pii;
///-------------------------

int main()
{
    Phuong_; /// <3
    int n;
    cin >> n;
    ll sum=0;
    vector<ll> a(n);
    for(ll i=1; i<=n; ++i)
    {
        ll u;
        cin >>u;
        u-=i;
        a[i-1]=u;
    }
    sort(a.begin(), a.end());
    sum=0;
    for(int i=0; i<n; ++i)
    {
        sum+=abs((a[i]-a[n/2]));
    }
    cout << sum;
    return 0;
}



Measured memory_bytes: 1792
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input!{
        xy: [usize1; 2],
    }
    let g = vec![1,2,1,3,1,3,1,1,3,1,3,1];
    println!("{}", if g[xy[0]] == g[xy[1]] {"Yes"} else {"No"});
}


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

int main()
{ 
  int n;
  scanf("%d", &n);
  int arr[n];
  for(int i = 0; i < n; i++)
    scanf("%d", &arr[i]);
  sort(arr, arr + n);
  for(int i = 0; i < n - 1; i++)
    if(arr[i] == arr[i+1])
    {
      cout << "NO\n";
      return 0;
    }
  cout << "YES\n";
}

Measured memory_bytes: 1024
#include <stdio.h>



int main (void){
    int i,j;
    int a=0; 
    int b;
    int n,m,k;
   

    scanf("%d %d %d",&n,&m,&k);
    
    for(i=0;i<=n;i++){
        for(j=0;j<=m;j++){
            if(i*m+j*n-2*i*j == k){
            printf("Yes\n");
            a++;
            break;
            }
        }
        if(a != 0){
            break;
        }
    }
    
    if(a == 0){
        printf("No\n");
    }
    
    
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main(void){
	int a,b;
	cin>>a>>b;
	if(a<=12)b/=2;
	if(a<=5)b=0;
	cout<<b<<endl;
}


Measured memory_bytes: 256
import std.stdio,std.array,std.conv,std.algorithm,std.range,std.string;

void main(string[] args) {
  string[2] a;
  a[0] = readln.chomp;
  a[1] = readln.chomp;
  if(a[0][0]==a[1][2]&&a[0][1]==a[1][1]&&a[0][2]==a[1][0]){
    "YES".writeln;
  }else{
    "NO".writeln;
  }
}

Measured memory_bytes: 256