akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<vector>
#include<string>
#define reep(a,s,d) for(int a=d;a<s;a++)
#define rep(a,s) reep(a,s,0)
using namespace std;
struct edge{
    int to,cost,tick;
    edge(int to,int cost,int tick):to(to),cost(cost),tick(tick){}
    edge(){}
};
bool operator<(const edge &a,const edge &b){
    return a.cost>b.cost;
}
int main(){
    int c,n,m,s,d;
    while(cin>>c>>n>>m>>s>>d,c){
        vector<edge> G[128];
        rep(i,m){
            int a,b,c;
            cin>>a>>b>>c;
            G[--a].push_back(edge(--b,c,0));
            G[b].push_back(edge(a,c,0));
        }
        bool vis[16][128];
        memset(vis,false,sizeof(vis));
        priority_queue<edge> Q;
        Q.push(edge(s-1,0,0));
        int ret=-1;
        while(!Q.empty()){
            edge n=Q.top();Q.pop();
            if(vis[n.tick][n.to])continue;
            vis[n.tick][n.to]=true;
            if(n.to==d-1){
                if(ret!=-1)ret=min(ret,n.cost);
                else ret=n.cost;
            }
            rep(i,G[n.to].size()){
                Q.push(edge(G[n.to][i].to,n.cost+G[n.to][i].cost,n.tick));
                if(n.tick<c){
                    Q.push(edge(G[n.to][i].to,n.cost+G[n.to][i].cost/2,n.tick+1));
                }
            }
        }
        cout<<ret<<endl;
    }
}

Measured memory_bytes: 1340
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for (int i = 0; i < n; ++i) 
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define debug1(a) cout<<" a : "<<a<<"\n"
#define debug2(a,b) cout<<" a : "<<a<<" b : "<<b<<"\n"
#define debug3(a,b,c) cout<<" a : "<<a<<" b : "<<b<<" c : "<<c<<"\n"

signed main()
{
	int n,w;
	cin>>n>>w;
	pair <int,int> a[n+1];
	rep(i,n) 
	{
		cin>>a[i+1].F>>a[i+1].S;
	}
	sort(a,a+n+1);
	int dp[n+1][w+1];
	rep(i,n+1)
	memset(dp[i],0,sizeof(dp[i]));
	REP(i,1,n)
	{
		rep(j,w+1)
		{
			if (j<a[i].F)
			dp[i][j]=dp[i-1][j];
			else
			dp[i][j]=max(dp[i-1][j],dp[i-1][j-a[i].F]+a[i].S);
		}
	}
//	rep(i,n+1)
	//{
	//	rep(j,w+1) cout<<dp[i][j]<<" ";
	//	cout<<"\n";
	//}
	cout<<dp[n][w];
    return 0;
}


Measured memory_bytes: 79104
#include<iostream>
#include<deque>

using namespace std;

int A[200005],B[200005];
int n;

bool ok(int poz)
{
    if(B[poz]==A[poz])
        return 0;

    if(B[poz]-B[(poz-1+n)%n]-B[(poz+1)%n]>0)
        return 1;
    return 0;
}

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

    cin>>n;
    for(int i=0; i<n; i++)
        cin>>A[i];

    deque<int> Q;
    for(int i=0; i<n; i++)
        cin>>B[i];

    for(int i=0; i<n; i++)
    {
        if(ok(i))
            Q.push_back(i);
    }

    long long rez=0LL;
    while(!Q.empty())
    {
        int vf=Q.front();
        Q.pop_front();

        int nr=(B[vf]-A[vf])/(B[(vf-1+n)%n]+B[(vf+1)%n]);
        B[vf]-=nr*(B[(vf-1+n)%n]+B[(vf+1)%n]);
        rez+=1LL*nr;

        if(nr==0)
        {
            cout<<"-1\n";
            return 0;
        }

        if(ok((vf-1+n)%n))
            Q.push_back((vf-1+n)%n);
        if(ok((vf+1)%n))
            Q.push_back((vf+1)%n);
    }

    for(int i=0; i<n; i++)
    {
        if(A[i]!=B[i])
        {
            cout<<"-1\n";
            return 0;
        }
    }

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


Measured memory_bytes: 2176
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
using namespace std;
bool sortbysec(const pair<pair<int,int>,int> &a, const pair<pair<int,int>,int> &b)
{
    return (a.first.second<b.first.second);
}
bool sortbysecll(const pll &a, const pll &b)
{
    return (a.second<b.second);
}
ll modinv(ll x, ll y, ll modulo)
{
    return ((x%modulo)*(P(y,modulo-2LL,modulo)%modulo))%modulo;
}
void vok()
{
    FAST
    FO
    FI
//    #ifndef ONLINE_JUDGE
//        freopen("input.txt","r",stdin);
//        freopen("output.txt","w",stdout);
//    #endif
}
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    if(n%k==0)
    {
        OUT 0<<endl
        return 0;
    }
    OUT min(n,(k)-(n%k))<<endl
    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
#include <cstdlib>
#include <iostream>
#include <cmath>

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

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

  int n;
  cin >> n;
  string ans = n<=999 ? "ABC" : "ABD";
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
a, b, c, d, e, f = gets.split.map(&:to_i)
wa, wb = a * 100, b * 100

wperm = []
0.step(f, wa){|wa_|
  0.step(f, wb){|wb_|
    if (sum = wa_ + wb_) <= f
      wperm << sum
    end
  }
}
sperm = []
0.step(f, c){|c_|
  0.step(f, d){|d_|
    if (sum = c_ + d_) <= f
      sperm << sum
    end
  }
}
wperm = wperm.uniq.select{|x| !x.zero?}
sperm.uniq!

res = [-1, 0, 0]
wperm.each{|w|
  sperm.each{|s|
    next if (ws = w + s) > f || w / 100 * e < s
    res_ = [s.to_f / ws, ws, s]
    res = res_ if res[0] < res_[0]
  }
}
puts res[1..2] * " "


Measured memory_bytes: 3836
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
bool so[1234567];
vector<int> s;
int main()
{
	memset(so,false,sizeof(so));
	REP(i,2,1234560){
		if(so[i]) continue;
		s.pb(i);
		for(int j=i+i;j<1234560;j+=i) so[j]=true;
	}
	int n;lint p,out=1;
	cin>>n>>p;
	if(n==1){
		cout<<p<<endl;return 0;
	}
	rep(i,s.size()){
		int t=0;
		while(p%s[i]==0){
			p/=s[i];t++;
		}
		rep(j,t/n) out*=s[i];
	}
	cout<<out<<endl;
}


Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define int long long
using namespace std;

const int M = 1e9+7;

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

    int n , m;
    cin >> n >> m;
    int a[n] , sum = 0;
    for(int i = 0; i < n; i++) cin >> a[i] , sum += a[i];
    sort(a , a+n);
    int cnt = 0; double req = (sum*1.0) / (4 * m);
    for(int i = n-1; i >= 0; i--) {
        if(cnt == m) break;
        else {
            if(a[i] >= req) cnt++;
            else break;
        }
    }
    if(cnt == m) cout << "Yes\n";
    else cout << "No\n";

    return 0;
}


Measured memory_bytes: 256
import sys
from math import gcd
input = sys.stdin.readline

K = int(input())
ans = 0

for i in range(1, K+1):
    for j in range(i, K+1):
        for k in range(j, K+1):
            if i == j and k == i:
                ans += gcd(gcd(i, j), k)
            elif i == j or k == i or j == k:
                ans += 3 * gcd(gcd(i, j), k)
            else:
                ans += 6 * gcd(gcd(i, j), k)

print(ans)


Measured memory_bytes: 9200
import itertools

n = int(input())
l = [list(map(int, input().split())) for i in range(n)]
ans = 0

for i in itertools.combinations(l,2):
    ans += ((i[0][0]-i[1][0])**2 + (i[0][1]-i[1][1])**2)**(1/2)

print(ans*2/n)

Measured memory_bytes: 3064
N=int(input())
s = [int(input()) for i in range(N)]

if sum(x%10!=0 for x in s) == 0:
    print(0)
elif sum(s)%10!=0:
    print(sum(s))
else:
    l = [i for i in s if i % 10 != 0 ]
    l.sort()
    ans=sum(s)-l[0]
    print(ans)

Measured memory_bytes: 3064
[n,m] = [int(i) for i in input().split()]
ans = 0
ab = []
stage = [[0] * n for i in range(n)]
for i in range(m):
    ab.append([int(j)-1 for j in input().split()])
    stage[ab[-1][0]][ab[-1][1]] = 1
    stage[ab[-1][1]][ab[-1][0]] = 1
for i in range(m):
    visit = [0] * n
    now = 0
    stage[ab[i][0]][ab[i][1]] = 0
    stage[ab[i][1]][ab[i][0]] = 0
    next = [0]
    while len(next):
        now = next.pop()
        visit[now] = 1
        for j in range(n):
            if stage[now][j] == 1 and visit[j] != 1:
                next.append(j)

    stage[ab[i][0]][ab[i][1]] = 1
    stage[ab[i][1]][ab[i][0]] = 1



    if 0 in visit:
        ans += 1
print(ans)


Measured memory_bytes: 40048
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int MAX = 510000;
const int MOD = 1e17;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


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 Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=100010;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}



/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  ll n;
  cin>>n;
  vector<ll> v(n);
  rep(i,n) cin>>v[i];
  ll ans=MOD,tmp=v[0],sum=Svec(v);
  rep(i,n-1){
    chmin(ans,abs(2*tmp-sum));
    
    tmp+=v[i+1];
    
  }
  chmin(ans,abs(2*tmp-sum));
  cout<<ans<<endl;
  
  
}


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

using namespace std;

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

	if (a + b == c || a + c == b || b + c == a) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
const int mod=1000000007;
int N,M,pw2[2010];
long long X;
struct edge{int u,v,w;bool operator<(const edge&e)const{return w<e.w;}}E[2010];
int fa[1010],add[2010];
bool isnes[2010];
int find(int i){return fa[i]==i?i:fa[i]=find(fa[i]);}
int main(){
	scanf("%d%d%lld",&N,&M,&X);
	if(N<=2){
		puts("0");
		return 0;
	}
	for(int i=*pw2=1;i<=M;i++)pw2[i]=pw2[i-1]*2%mod;
	for(int i=0;i<M;i++)scanf("%d%d%d",&E[i].u,&E[i].v,&E[i].w);
	std::sort(E,E+M);
	for(int i=1;i<=N;i++)fa[i]=i;
	int nes=0;
	long long S=0;
	for(int i=0,j=0;i<M;i=j){
		for(;j<M&&E[i].w==E[j].w;j++){
			if(find(E[j].u)!=find(E[j].v))isnes[j]=1,nes++;
		}
		for(j=i;j<M&&E[i].w==E[j].w;j++){
			if(find(E[j].u)!=find(E[j].v)){
				S+=E[i].w;
				fa[find(E[j].u)]=find(E[j].v);
			}
		}
	}
	if(S==X){
		int ans=(pw2[M]-pw2[M-nes+1]+mod)%mod;
		printf("%d\n",ans);
		return 0;
	}
	int tot=0,ban=0;
	for(int j=0;j<M;j++)if(!isnes[j]){
		for(int i=1;i<=N;i++)fa[i]=i;
		S=E[j].w;
		fa[find(E[j].u)]=find(E[j].v);
		for(int i=0;i<M;i++){
			if(find(E[i].u)!=find(E[i].v))
				fa[find(E[i].u)]=find(E[i].v),S+=E[i].w;
		}
		if(S<X)ban++;
		if(S==X)tot++;
	}
	int ans=2ll*(pw2[tot]-1)*pw2[M-nes-tot-ban]%mod;
	printf("%d\n",ans);
}

Measured memory_bytes: 256
#Macで実行する時
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../atcoder/input.txt'))
	#print(name)
	sys.stdin = open(name)

a, b = map(int,input().split())

c = int(a/b)

if a%b!=0:
    c+=1

print(c)



Measured memory_bytes: 61860
#include <set>
#include <map>
#include <deque>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

typedef long long LL;
typedef pair<LL, LL> pLL;
typedef pair<LL, int> pLi;
typedef pair<int, LL> pil;;
typedef pair<int, int> pii;
typedef unsigned long long uLL;

#define lson rt<<1
#define rson rt<<1|1
#define lowbit(x) x&(-x)
#define name2str(name) (#name)
#define bug printf("*********\n")
#define debug(x) cout<<#x"=["<<x<<"]" <<endl
#define FIN freopen("D://code//in.txt","r",stdin)
#define IO ios::sync_with_stdio(false),cin.tie(0)

const double eps = 1e-8;
const int mod = 1000000007;
const int maxn = 2e5 + 7;
const double pi = acos(-1);
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;

int a, b;

int main(){
    while(~scanf("%d%d", &a, &b)) {
        if(b % a == 0) printf("%d\n", a + b);
        else printf("%d\n", b - a);
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int a,n,i,min=1000000,max=-1000000;
    long int sum=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&a);
        sum+=a;
        if(min>a)
            min=a;
        if(max<a)
            max=a;
    }
    printf("%d %d %ld\n",min,max,sum);
    return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    Init();
    string s; cin >> s;
    // 逆順にする
    reverse(all(s));
    bool ans = true;
    // 追加文字も逆順にする
    vector<string> dic = {"dream", "dreamer", "erase", "eraser"};
    rep(i, 4) reverse(all(dic[i]));

    while(s.size() > 0){
        // mから始まるのはdreamの逆しかない
        if(s[0] == 'm'){
            if(s.substr(0, 5) == dic[0]) s = s.substr(5);
            else{
                ans = false;
                break;
            }
        }
        // eから始まるのはeraseの逆しか無い
        else if(s[0] == 'e'){
            if(s.substr(0, 5) == dic[2]) s = s.substr(5);
            else{
                ans = false;
                break;
            }
        }
        // reで始まるのは2種類なのでどっちも試す
        else{
            if(s.substr(0, 6) == dic[3]) s = s.substr(6);
            else if(s.substr(0, 7) == dic[1]) s = s.substr(7);
            else{
                ans = false;
                break;
            }
        }
    }
    (ans) ? YES() : NO();
}

Measured memory_bytes: 620
#include<iostream>
#include<string>
using namespace std;
int main(){
  int ans=-1,len=0;
  string s;
  while(getline(cin,s)){
    while(1){
      ans = s.find("the");
      if(ans!=-1)break;
      ans = s.find("this");
      if(ans!=-1)break;
      ans = s.find("that");
      if(ans!=-1)break;
      for(int i=0;i<s.size();i++){
	if(s[i]=='z') s[i]='a';
	else if(s[i]>='a' && s[i]<'z') s[i]++;
      }
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 1176
n =  int(input())
for i in range(n):
    tri_list = list(map(int,input().split(" ")))
    tri_list.sort()
    a = int(tri_list[2]) ** 2
    b = int(tri_list[0]) ** 2 + int(tri_list[1]) ** 2
    if a == b:
        print("YES")
    else:
        print("NO")


Measured memory_bytes: 5596
import java.io.*;
import java.util.*;
import java.math.*;
public class Main {
    public static void main(String[] args)
            throws java.io.IOException{
        Scanner scan = new Scanner(System.in);
        int [] ball =new  int [10];
int n=scan.nextInt();
            for(int j=0;j<n;j++){
                for(int i=0;i<10;i++)ball[i] = scan.nextInt();
                boolean flag =true;
                Stack <Integer> b =new Stack <Integer>();
                Stack <Integer> c =new Stack<Integer>();
b.push(0);
c.push(0);
                int i;
                for(i=0;i<10;i++){
                    if(b.peek() > ball[i]){
                        if(c.peek()>ball[i]){
                            System.out.println("NO");
                            flag = false;
                            break;
                        }
                        else {c.push(ball[i]);}
                    }

                    else {
                        if(c.peek() > ball[i]){
                            b.push(ball[i]);}
                        else {
                                   if(ball[i]-b.peek()<=ball[i]-c.peek()){
                                             b.push(ball[i]);}
else{c.push(ball[i]);}
}
}
}if(flag)System.out.println("YES");
}
}
}

Measured memory_bytes: 12000
from collections import deque
import sys
sys.setrecursionlimit(10**7)

N=int(input())
M=N*(N-1)//2
D=[[]for i in range(M)]
F=[[]for i in range(M)]
for i in range(N):
  x=list(map(int,input().split()))
  for j in range(N-2):
    a,b,c=i+1,x[j],x[j+1]
    x1,x2=min(i+1,x[j]),max(i+1,x[j])
    y1,y2=min(i+1,x[j+1]),max(i+1,x[j+1])
    e=M-(N-x1)*(N-x1+1)//2
    f=e+(x2-x1-1)
    g=M-(N-y1)*(N-y1+1)//2
    h=g+(y2-y1-1)
    D[f].append(h)
    F[h].append(f)
    
q=deque()
P=[0]*M
for i in range(M):
  if len(F[i])==0:
    q.append((i,0))

r=[]
while q:
  v1,cnt=q.popleft()
  r.append((v1,cnt))
  for v2 in D[v1]:
    P[v2]+=1
    if P[v2]==len(F[v2]):
      q.append((v2,cnt+1))

if len(r)!=M:
  print(-1)
else:
  print(r[-1][-1]+1)

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

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

  vector<int> H(N, 0);
  for (int i = 0; i < N; i++) {
    scanf("%d", &H.at(i));
  }

  for (int i = N - 1; i > 0; i--) {
    if (H.at(i) < H.at(i - 1)) {
      H.at(i - 1)--;
    }

    if (H.at(i) < H.at(i - 1)) {
      printf("No");
      return 0;
    }
  }
  
  for (int i = 1; i < N - 1; i++) {
    if (H.at(i - 1) <= H.at(i) && H.at(i) <= H.at(i + 1)) {
      continue;
    } else {
      printf("No");
      return 0;
    }
  }  
  
  printf("Yes");
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
const int maxn = 10;
int flag = 0;
int a[maxn];
void dfs(int l, int r, int x) {
	if (x == 10) {
		flag = 1;
		return;
	}
	if (a[x] > l) dfs(a[x], r, x + 1);
	else if (a[x] > r) dfs(l, a[x], x + 1);
	if (flag == 1) return;

}


int main() {
	int t = 0;
	scanf("%d", &t);
	while (t--) {
		flag = 0;
		for (int i = 0; i < 10; i++) {
			scanf("%d", &a[i]);
		}
		dfs(0, 0, 0);
		if (flag == 1) printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}





Measured memory_bytes: 3144
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using db = double;
using pii = pair < int, int >;
using pll = pair < ll, ll >;

template < typename T > using OrderedSet = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std::endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) sort(all(x)), x.resize(distance(x.begin(), unique(all(x))))

const db PI = acos(-1);
const ll LINF = LLONG_MAX;
const int INF = INT_MAX, MOD = 1e9 + 7, N = 1e5 + 10;

void test_case();

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	int x, a;
	cin >> x >> a;
	cout << (x < a ? 0 : 10) << "\n";
}

Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
int n;
vector<bool> vis;
vector<vector<int>> g;
const int N=1e5;
int f=0,h=0;
void dfs(int node)
{
	vis[node]=1;
	if(node<N)f++;
	else h++;
	for(auto u:g[node])
	{
		if(!vis[u])dfs(u);
	}
}
int32_t main()
{
	#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
	#endif
	cin>>n;
	int u,v;
	g=vector<vector<int>>(2*N+1);
	vis=vector<bool>(2*N+1);
	for(int i=0;i<n;i++)
	{
		cin>>u>>v;
		u--;v--;
		v+=N;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	
	int ans=0;

	for(int i=0;i<N;i++)
	{
		if(!vis[i]){f=0,h=0;dfs(i);ans+=f*h;}
	}
	cout<<ans-n;




	

}

Measured memory_bytes: 12888
use std::io::prelude::*;
use std::io;
use std::str::FromStr;
#[cfg(local)]
use std::fs::File;
#[cfg(local)]
use std::io::BufReader;

#[cfg(local)]
fn buf_read() -> io::Result<(Vec<String>)> {
    let f = try!(File::open("input.txt"));
    let input_lines: Vec<_> = BufReader::new(f).lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

#[cfg(not(local))]
fn buf_read() -> io::Result<(Vec<String>)> {
    let stdin = io::stdin();
    let input_lines: Vec<_> = stdin.lock().lines().collect();
    let lines: Vec<String> = input_lines.into_iter().map(|e| e.unwrap()).collect();
    Ok((lines))
}

fn main() {
    type Element = String;
    let input = buf_read().unwrap();
    let mut input_vectors: Vec<Vec<Element>> = vec![];
    for input_line in input {
        let input_str: Vec<String> = input_line.split(' ').map(String::from).collect();
        let mut input_vector: Vec<Element> = vec![];
        for input_elem_str in input_str {
            let elem: Element = Element::from_str(input_elem_str.as_str()).unwrap();
            input_vector.push(elem);
        }
        input_vectors.push(input_vector);
    }
    let mut input_string = input_vectors[0][0].clone();
    if input_string.len() % 2 == 0 {
        let last_char = input_string.pop().unwrap();
        let first_char = input_string.remove(0);
        // println!("{:?}", last_char);
        // println!("{:?}", initial_char);
        if last_char == first_char {
            println!("First");
        } else {
            println!("Second");
        }
    } else {
        let last_char = input_string.pop().unwrap();
        let first_char = input_string.remove(0);
        // let (initial_char, _) = input_string.split_at(1);
        if last_char == first_char {
            println!("Second");
        } else {
            println!("First");
        }
        // println!("{:?}", last_char);
        // println!("{:?}", initial_char);
        // println!("{:?}", first_char);
    }
}


Measured memory_bytes: 636
#include <stdio.h>
int main(void) {
	int a, b, c, k;
	scanf("%d", &a);
	scanf("%d", &b);
	if (a > b) {
		c = a - b;
	}
	else {
		c = b - a;
	}
	if (c % 2 == 0) {
		if (a > b) {
			k = c / 2;
			k = a - k;
		}
		else {
			k = c / 2;
			k = b - k;
		}
		printf("%d\n", k);
	}
	else {
		printf("IMPOSSIBLE\n");
	}
	return 0;
}

Measured memory_bytes: 128
s = input()
n = len(s)
a = s[0:(n-1)//2] == s[-(n+3)//2:-n-1:-1]
b = s[(n+1)//2:n] == s[-1:-(n+1)//2:-1]
c = s == s[-1:-n-1:-1]
print('Yes' if a and b and c else 'No')


Measured memory_bytes: 3060
x, n = map(int, input().split())
lst = []
x1 = x
x2 = x

def minus(num):
    return int(num) - 1


def plus(num):
    return int(num) + 1


if n != 0:
    lst = list(map(int, input().split()))
    for j in range(n):
        count = 0
        for i in lst:
            if x1 == i:
                x1 = minus(x1)
                break
            count += 1
        if count == n:
            break
    for j in range(n):
        count = 0
        for i in lst:
            if x2 == i:
                x2 = plus(x2)
                break
            count += 1
        if count == n:
            break

    if x >= 0:
        ans1 = x - x1
        ans2 = x2 - x
        if ans1 <= ans2:
            print(x1)
        else:
            print(x2)
    else:
        ans1 = (x1 - x) * (-1)
        ans2 = (x - x2) * (-1)
        if ans1 <= ans2:
            print(x1)
        else:
            print(x2)
else:
    print(x)


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

using namespace std;
typedef long long ll;

const ll INF = 1e9;
const ll MOD = 1e9 + 7;

int main() {
  int A, B, C, D, E, F;
  cin >> A >> B >> C >> D >> E >> F;

  double rate = -1.0;
  int max_sum = 0;
  int max_sugar = 0;
  for (int a = 0; a * 100 <= F; a+=A) {
    for (int b = 0; (b + a) * 100 <= F; b+=B) {
      for (int c = 0; (b + a) * 100 + c <= F; c+=C) {
        for (int d = 0; (b + a) * 100 + c + d <= F; d+=D) {
          if (a + b == 0) continue;
          if (c + d > E * (a + b)) continue;
          double sum = ((a + b) * 100 + c + d);
          double sugar = c + d;
          if (rate < 0 || rate < sugar / sum * 100) {
            rate = sugar / sum * 100;
            max_sum = sum;
            max_sugar = sugar;
          }
        }
      }
    }
  }
  cout << max_sum << " " << max_sugar << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
from collections import defaultdict
import heapq

g = defaultdict(list)
input = sys.stdin.buffer.readline
N,u,v= map(int,input().split())
for i in [0]*(N-1):
    A,B = map(int,input().split())
    g[A].append(B)
    g[B].append(A)

def dijkstra(start):
    inf = 10**10
    d = [inf]*(N+1)
    d[start] = 0
    que = []
    heapq.heappush(que,(start,0))
    while que:
        s, dist = heapq.heappop(que)
        if d[s] < dist:
            continue
        for t in g[s]:
            if d[t] > d[s] + 1:
                d[t] = d[s] + 1
                heapq.heappush(que,(t,d[t]))
    return d

d1 = dijkstra(u)
d2 = dijkstra(v)
ans = 0
for i in range(1,N+1):
    if d1[i] < d2[i]:
        ans = max(ans,d2[i]-1)
print(ans)





Measured memory_bytes: 34748
#include <iostream>
#include <vector>
#include <fstream>
using namespace std;
#define bit(x, i) (x & (1 << i))          //select the bit of position i of x
#define lowbit(x) ((x) & ((x) ^ ((x)-1))) //get the lowest bit of x
#define max(a, b) (a < b ? b : a)
#define min(a, b) (a > b ? b : a)
#define abs(x) (x < 0 ? (-x) : x)   
#define IN(i, l, r) (l < i && i < r) //the next for are for checking bound
#define LINR(i, l, r) (l <= i && i <= r)
#define LIN(i, l, r) (l <= i && i < r)
#define INR(i, l, r) (l < i && i <= r)
#define clr(a, x) memset(a, x, sizeof(a)) //set elements of array to some value
#define char2Int(c) (c - '0')
#define lastEle(vec) vec[vec.size() - 1]
#define SZ(x) ((int)((x).size()))
#define REMAX(a, b) (a) = max((a), (b)) // set a to the maximum of a and b
#define REMIN(a, b) (a) = min((a), (b));
#define FOREACH(i, t) for (typeof(t.begin()) i = t.begin(); i != t.end(); i++) // traverse an STL data structure
#define ALL(c) (c).begin(), (c).end()                                          //handy for function like 
#define PRESENT(c, x) ((c).find(x) != (c).end())
#define CPRESENT(c, x) (find(ALL(c), x) != (c).end())
#define ll long long //data types used often, but you don't want to type them time by time
#define ull unsigned long long
#define us unsigned short
#define IOS ios_base::sync_with_stdio(0); //to synchronize the input of cin and scanf
#define INF 1001001001
#define PI 3.1415926535897932384626
#define mp make_pair
#define fi first
#define se second
#define ui unsigned int
//for vectors
#define pb push_back
typedef int elem_t;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<pair<int, int>> vpi;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vpi> vvpi;
typedef pair<int, int> ii;
#define F(i, L, R) for (int i = L; i < R; i++) //next four are for for loops
#define FE(i, L, R) for (int i = L; i <= R; i++)
#define FF(i, L, R) for (int i = L; i > R; i--)
#define FFE(i, L, R) for (int i = L; i >= R; i--)
namespace EU
{
void max_self(int &a, int b)
{
a = max(a, b);
}
}


const int mod = 1000000007;
int N,h[200200],a[200200]; long long B[200200];

ll out(int x) {
    ll res = 0;
    while(x > 0) {
        res = max(res, B[x]);
        x -= x & -x;
    }
    return res;
}

void in(int x, long long p) {
    while(x <= N) {
        B[x] = max(B[x], p);
        x += x & -x;
    }
}



int main() {
    scanf ("%d",&N);
	for (int i=1;i<=N;i++) scanf ("%d",&h[i]);
	for (int i=1;i<=N;i++) scanf ("%d",&a[i]);
	for (int i=1;i<=N;i++){
        ll o = out(h[i]) + a[i];
        in(h[i], o);
    }
    printf("%lld\n", out(N));
    return 0;
}


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

char A[20];
char B[20];
char C[20];

int main(){

	scanf("%s %s %s",A,B,C);

	int len_A=strlen(A);
	int len_B=strlen(B);
	int len_C=strlen(C);

	if(A[len_A-1]==B[0]&&B[len_B-1]==C[0]){
	printf("YES\n");
	}
	else{
	printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include<iostream>

int main() {
	int N, M;

	std::cin >> N;
	std::cin >> M;

	// To be even, must be odd + odd or even + even
	
	int evenCount = 0;
	int oddCount = 0;

	if (N > 1) {
		int buffer = 1;
		for (int i = N; i > N - 2; i--) {
			buffer *= i;
		}

		evenCount = buffer / 2;
	}

	if (M > 1) {
		int buffer = 1;
		for (int i = M; i > M - 2; i--) {
			buffer *= i;
		}

		oddCount = buffer / 2;
	}

	std::cout << evenCount + oddCount;

	return 0;
}


Measured memory_bytes: 256
/* 
	بسم الله الرحمن الرحیم
	
	(; طلا یک جهانی
*/	

#include <bits/stdc++.h>
using namespace std;

const int MOD = 1e9 + 7;

int pw(int b, int p) {
	int res = 1;
	for (; p; p >>= 1, b = 1LL * b * b % MOD)
		if (p & 1)
			res = 1LL * res * b % MOD;
	return res;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
	int n, m, k;
	cin >> n >> m >> k;
	int a = 0, b = 0;
	for (int i = 1; i < m; i++)
		a = (a + 1LL * i * (m - i)) % MOD;
	for (int i = 1; i < n; i++)
		b = (b + 1LL * i * (n - i)) % MOD;
	a = 1LL * a * n % MOD * n % MOD;
	b = 1LL * b * m % MOD * m % MOD;
	if (1LL * n * m - 2 >= MOD)
		return cout << 0, 0;
	int ans = 1, fac = 1;;
	for (int i = 1; i <= n * m - 2; i++) {
		fac = (1LL * i * fac) % MOD;
		if (i == k - 2)
			ans = 1LL * ans * pw(fac, MOD - 2) % MOD;
		if (i == n * m - k)
			ans = 1LL * ans * pw(fac, MOD - 2) % MOD;
	}
	ans = 1LL * ans * fac % MOD;
	ans = 1LL * ans * (a + b) % MOD;
	cout << ans;
}


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

Measured memory_bytes: 128
import sys
import math
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()


def make_grid(h, w, num): return [[int(num)] * w for _ in range(h)]


class UnionFind:
    def __init__(self, n):
        #親要素のノード番号を格納　xが根のとき-(サイズ)を格納
        self.par = [-1 for i in range(n)]
        self.n = n

    def find(self, x):
        #根ならその番号を返す
        if self.par[x] < 0:
            return x
        else:
            #親の親は親
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def is_same(self, x, y):
        #根が同じならTrue
        return self.find(x) == self.find(y)

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y: return

        #木のサイズを比較し、小さいほうから大きいほうへつなぐ
        if self.par[x] > self.par[y]:
            x, y = y, x

        self.par[x] += self.par[y]
        self.par[y] = x

    def size(self, x):
        return -self.par[self.find(x)]

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.par) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


#隣接リスト 1-order
def make_adjlist_nond(n, edges):
    res = [[] for _ in range(n+1)]
    for edge in edges:
        res[edge[0]].append(edge[1])
        res[edge[1]].append(edge[0])
    return res


def main():
    N, M = NMI()
    edges = [NLI() for _ in range(M)]

    uf = UnionFind(N)
    ans = [0]*(M+1)
    for i in range(M, 0, -1):
        if i == M:
            ans[i] = N * (N - 1) // 2
            continue

        x, y = edges[i][0] - 1, edges[i][1] - 1
        if uf.is_same(x, y):
            ans[i] = ans[i+1]
            continue
        num = uf.size(x) * uf.size(y)
        uf.unite(x, y)
        ans[i] = ans[i+1] - num

    for a in ans[1:]:
        print(a)

if __name__ == "__main__":
    main()

Measured memory_bytes: 34320
import bisect
from operator import itemgetter
import math
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

x,y = IL()
ga = [1,3,5,7,8,10,12]
gb = [4,6,9,11]

if (x in ga and y in ga) or (x in gb and y in gb):
  print("Yes")
else:
  print("No")

Measured memory_bytes: 12196
N, M = map(int, input().split())
graph = [set() for _ in range(N)]
for _ in range(M):
    A, B = map(int, input().split())
    graph[A - 1].add(B - 1)
    graph[B - 1].add(A - 1)

arrows = [-1] * N
queue = [0]
seen = {0}
while queue:
    new = []
    for cur in queue:
        for nei in graph[cur]:
            if nei in seen:
                continue
            seen.add(nei)
            new.append(nei)
            arrows[nei] = cur
    queue = new

if all(a != -1 for a in arrows[1:]):
    print('Yes')
    for a in arrows[1:]:
        print(a + 1)
else:
    print('No')

Measured memory_bytes: 69092
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner scan = new FastScanner(System.in);
		final int N = scan.nextInt();
		int[] H = new int[N];
		for (int i = 0; i < N; i++) {
			H[i] = scan.nextInt();
		}

		boolean ans = true;
		if (H[0] > 0) {
			H[0]--;
		}
		for (int i = 1; i < N; i++) {
			if (H[i] > H[i - 1]) {
				H[i]--;
			} else if (H[i] < H[i - 1]) {
				ans = false;
				break;
			}
		}
		if (ans) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}

	static class FastScanner {
        private BufferedReader reader = null;
        private StringTokenizer tokenizer = null;

        public FastScanner(InputStream in) {
            reader = new BufferedReader(new InputStreamReader(in));
            tokenizer = null;
        }

        public String next() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public String nextLine() {
            if (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    return reader.readLine();
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }

            return tokenizer.nextToken("\n");
        }

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

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

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

        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }

}


Measured memory_bytes: 40824
#include <bits/stdc++.h>
using namespace std;
#define TRACE(x) x
#define WATCH(x) TRACE( cout << #x" = " << x << endl)
#define PRINT(x) TRACE(printf(x))
#define WATCHR(a, b) TRACE( for(auto c = a; c != b;) cout << *(c++) << " "; cout << endl)
#define WATCHC(V) TRACE({cout << #V" = "; WATCHR(V.begin(), V.end()); } )
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x).size()
#define mp make_pair
#define st first
#define nd second

using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using ld = long double;
using pll = pair<ll, ll>;
using vll = vector<ll>;
using pll = pair<ll, ll>;

void buff() { ios::sync_with_stdio( false ); cin.tie( nullptr ); }

constexpr ll MOD = 1e9 + 7;

inline ll pow_mod( ll a, ll b, ll mod = MOD) {
    ll res = 1; a %= mod; assert(b >= 0);
    for(;b;b>>=1) {
        if(b&1) res = (res * a) % mod;
        a = (a * a) % mod;
    }
    return res;
}
// End of template code!
int main() 
{
    buff();
    int x; cin >> x; x %= 10;
    if(x == 3) cout << "bon\n";
    else if(x == 0 || (x == 1 || (x == 6 || x == 8) ) ) cout << "pon\n";
    else cout << "hon\n";
    return 0;
}



Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define im 2147483647
#define lm 9223372036854775807
#define ll long long
#define ii pair<int, int>
#define debug(index, num) cerr << "Case #" << index << ": " << num << endl
#define be(x) x.begin(), x.end()
#define rbe(x) x.rbegin(), x.rend()
#define pb push_back
const ll MOD = 1000000007;
int main() {
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    ll n, k;
    cin >> n >> k;
    vector<int> dp(n+2, im), h(n+1);
    for(int i = 1; i <= n; i++) cin >> h[i];
    dp[1] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 1; j <= k; j++) {
            if(i + j > n) continue;
            dp[i+j] = min(dp[i+j], dp[i] + abs(h[i] - h[i+j]));
        }
    }
    cout << dp[n];
}

Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int const NMAX = 50;
int v[1 + NMAX];

int main()
{
  int n, m, sum = 0, ans = 1;
  cin >> n >> m;
  for(int i =1;i <= n;i++){
    cin >> v[i];
    sum += v[i];

    if(m >= sum){
      ans++;
    }
  }
  cout << ans;
  return 0;
}


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

using namespace std;

constexpr int MAXV=55,MAXE=105,MAXCOIN=2501;
int n,m,s;
int head[MAXV];
int C[MAXV],D[MAXV];
unsigned long long ans[MAXV][MAXCOIN];
bool use[MAXV][MAXCOIN];

struct Edge{int to,next,a,b;}edge[MAXE*2];
struct Node{
	int id;
	unsigned long long coin,time;
	friend bool operator >(Node lhs,Node rhs){
		return lhs.time>rhs.time;
	}
};

void add_edge(int u,int v,int a,int b){
	static int ecnt;
	auto add=[](int from,int to,int a,int b)->void{
		edge[++ecnt]=Edge{to,head[from],a,b};
		head[from]=ecnt;
	};
	add(u,v,a,b),add(v,u,a,b);
}

void A_star(){
	for(int i=1;i<=n;++i)
		fill_n(ans[i],MAXCOIN,numeric_limits<unsigned long long>::max());
	priority_queue<Node,vector<Node>,greater<Node>> pq;
	ans[1][s]=0;
	pq.push({1,s,0});
	while(!pq.empty()){
		auto [u,coin,time]=pq.top();
		pq.pop();
		if(use[u][coin]) continue;
		use[u][coin]=true;
		for(int i=head[u];i;i=edge[i].next){
			int v=edge[i].to;
			if(coin>=edge[i].a){
				unsigned long long j=coin-edge[i].a;
				if(unsigned long long k=time+edge[i].b;k<ans[v][j]){
					ans[v][j]=k;
					pq.push({v,j,k});
				}
			}
		}
		if(unsigned long long j=coin+C[u];j<MAXCOIN){
			if(unsigned long long k=time+D[u];k<ans[u][j]){
				ans[u][j]=k;
				pq.push({u,j,k});
			}
		}
	}
}

int main(){
	scanf("%d%d%d",&n,&m,&s);
	s=min(s,MAXCOIN-1);
	for(int i=1;i<=m;++i){
		int u,v,a,b;
		scanf("%d%d%d%d",&u,&v,&a,&b);
		add_edge(u,v,a,b);
	}
	for(int i=1;i<=n;++i)
		scanf("%d%d",&C[i],&D[i]);
	A_star();
	for(int i=2;i<=n;++i){
		unsigned long long mn=numeric_limits<unsigned long long>::max();
		for(auto tm:ans[i])
			mn=min(mn,tm);
		printf("%llu\n",mn);
	}
}


Measured memory_bytes: 7524
#include<cstdio>
long long gcd(long long a,long long b){
    if(a<b)return gcd(b,a);
    else if(a%b==0)return b;
    else return gcd(b,a%b);
}
//max_k (a+kn)mod m
long long maxmod(long long a, long long n, long long m){
    long long g=gcd(m,n);
    return a%g-g+m;
}
int main(){
    int t;
    long long a,b,c,d;
    bool flag;
    scanf("%d",&t);
    for(int i=0;i<t;i++){
        scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
        if(d<b||a<b)flag=false;
        else if(c>=b)flag=true;
        else flag=(maxmod(a,d,b)<=c);
        if(flag)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define fi first
#define se second
#define pb push_back
using namespace std;

char c;

int main()
{

    ios_base::sync_with_stdio(false);
    cin.tie(0);

    cin >> c;
    c++;
    cout << c;

    return 0;
}


Measured memory_bytes: 256
# 088 B

N = int(input())
A =[int(j) for j in input().split()]

A.sort(reverse=True)
Alice =[]
Bob = []

for i in range(N):
    if i % 2 ==0:
        Alice.append(A[i])
    else:
        Bob.append(A[i])
print(sum(Alice) -sum(Bob))

Measured memory_bytes: 3064
#include <cmath>
#include <cstdio>
#include <algorithm>
#define rg register
#define llint long long
using namespace std;

struct ios{
	template <typename _tp>
	inline ios operator >> (_tp &x){
		char c = getchar();int f = 1;x = 0; 
		for(;c<'0'||c>'9';c=getchar()) if(c=='-') f = -1;
		for(;c>='0'&&c<='9';c=getchar()) x = (x<<1)+(x<<3)+(c^48);
		x *= f;
		return *this;
	}
	template <typename _tp>
	inline ios operator << (_tp x){
		char s[66];int dgt = 0;
		if(x==0) putchar('0');
		if(x<0) putchar('-'),x = -x;
		while(x)
			++dgt,s[dgt] = x%10+'0',x /= 10;
		while(dgt)
			putchar(s[dgt]),--dgt;
		return *this; 
	}
}io;

int n,inv,mx; 

int main()
{
	io >> n;
	for(rg int i=1;i<=n;++i){
		io >> inv;
		if(i==1){
			mx = inv;
		}
		else{
			if(mx-inv>1){
				puts("No");return 0; 
			}
			mx = max(mx,inv);
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
n, x = map(int, input().split())

sizes = [1] * (n + 1)
nums = [1] * (n + 1)
for i in range(1, (n + 1)):
  sizes[i] = 2 * sizes[i - 1] + 3
  nums[i] = 2 * nums[i - 1] + 1

def f(m, y):
  if m == 0:
    return 1
  if sizes[m] - 1 <= y:
    return nums[m]
  ret = 0
  y -= 1
  if y > 0:
    ret += f(m - 1, min(y, sizes[m - 1]))
    y -= sizes[m - 1]
  if y > 0:
    ret += 1
    y -= 1
  if y > 0:
    ret += f(m - 1, min(y, sizes[m - 1]))
  return ret

print(f(n, x))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std; 
#define int long long int
#define loop for(int i=0;i<n;i++)
#define pb push_back
 

int32_t main()
{
	int n;
	cin>>n;
	int k=n%10;
	if(k==2 or k==4 or k==5 or k==7 or k==9)
	cout<<"hon";
	else if(k==0 or k==1 or k==6 or k==8)
	cout<<"pon";
	else
	cout<<"bon";
}
	



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

// 総数を1000000007（素数）で割った余り
const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

const string YES = "Yes";
const string NO = "No";

int main(){
    string s;
    cin >> s;
    if (s.find('7') != string::npos) cout << YES << endl;
    else cout << NO << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long d,n,d2;cin >>d>>n;
  if (d==0) d2=1;
  if (d==1) d2=100;
  if (d==2) d2=10000;
    if (n<100) cout << n*d2 << endl;
	else cout << 101*d2 <<endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  char ch; cin>>ch;
  int n=(int) ch;
  if(n >=65 && n <=90) cout<<"A";
  else cout<<"a";
  return 0;
}


Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
#include <cstring>

using namespace std;

const int MAX_N=3000,MAX_T=3000;

int N,T;
int S;
int A[MAX_N],B[MAX_N];

int memo[MAX_N][MAX_T+1];

int dfs(int n,int t){
	//n番目の夜店に入るかどうか
	//現在の時刻はt
	if (n==N){
		//すべて決め終わった
		return 0;
	}
	if (memo[n][t]!=-1){
		return memo[n][t];
	}
	int res;
	res=dfs(n+1,t);	//夜店に入らない場合
	if (S<=t || t+B[n]<=S){
		//花火を待たずに夜店に入れる場合
		if (t+B[n]<=T) res=max(res,dfs(n+1,t+B[n])+A[n]);
	}
	else{
		//花火を待って夜店に入る場合
		if (S+B[n]<=T) res=max(res,dfs(n+1,S+B[n])+A[n]);
	}
	return memo[n][t]=res;
}

int main(){
	scanf("%d %d %d",&N,&T,&S);
	for (int i=0;i<N;i++){
		scanf("%d %d",A+i,B+i);
	}
	memset(memo,-1,sizeof(memo));
	printf("%d\n",dfs(0,0));
	return 0;
}

Measured memory_bytes: 36368