akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

namespace {

    /** whole range */
    #define whole(xs) (xs).begin(), (xs).end()

    struct Graph {
        static const int INF = 1<<28;
        struct Edge {
            int to, cap;
            shared_ptr<Edge> rev;
        };
        vector<vector<shared_ptr<Edge>>> vs;
        vector<int> level, iter;
        Graph(int v) { 
            vs = vector<vector<shared_ptr<Edge>>>(v); 
            level = vector<int>(v);
            iter = vector<int>(v);
        }
        void addEdge(int from, int to, int cap) {
            auto e = shared_ptr<Edge>(new Edge());
            auto rev = shared_ptr<Edge>(new Edge());
            e->to = to; e->cap = cap; e->rev = shared_ptr<Edge>(rev);
            rev->to = from; rev->cap = 0; rev->rev = shared_ptr<Edge>(e);
            vs[from].push_back(e);
            vs[to].push_back(rev);
        }

        void bfs(int s) {
            fill(whole(level), -1);
            queue<int> Q;
            level[s] = 0;
            Q.push(s);
            while (not Q.empty()) {
                auto i = Q.front(); Q.pop();
                for (auto& e : vs[i]) {
                    if (e->cap > 0 and level[e->to] < 0) {
                        level[e->to] = level[i] + 1;
                        Q.push(e->to);
                    }
                }
            }
        }

        int dfs(int v, int t, int f) {
            if (v == t) return f;
            auto& i = iter[v];
            for (; i < vs[v].size(); i++) {
                auto& e = vs[v][i];
                if (e->cap > 0 and level[v] < level[e->to]) {
                    auto d = dfs(e->to, t, min(f, e->cap));
                    if (d > 0) {
                        e->cap -= d;
                        e->rev->cap += d;
                        return d;
                    }
                }
            }
            return 0;
        }
        
        int maxFlow(int s, int t) {
            auto flow = 0;
            while (true) {
                bfs(s);
                if (level[t] < 0) return flow;
                fill(whole(iter), 0);
                while (true) {
                    auto f = dfs(s, t, INF);
                    if (f <= 0) break;
                    flow += f;
                }
            }
        }
    };

    int V, E;
    Graph* g;
    void input() {
        cin >> V >> E;
        g = new Graph(V);
        for (auto i = 0; i < E; i++) {
            int u, v, c;
            cin >> u >> v >> c;
            g->addEdge(u, v, c);
        }
    }

    void solve() {
        cout << g->maxFlow(0, V - 1) << endl;
        delete(g);
    }
}

int main() {
    input(); solve();
    return 0;
}

Measured memory_bytes: 3272
import Data.Char
f a b r =
  if r == ' '
  then r
  else 
    let i = (ord r) - (ord 'a')
        o = (a * i + b) `mod` 26
    in
      chr (o + ord 'a')

try w =
  concat $ map (\ww -> [(a,b) | a <- [0..25], b <- [0..25], (map (f a b) w)==ww ]) ["this","that"]

spt :: String -> [String]
spt [] = []
spt s@(sh:ss)
  | sh == ' ' || sh == '.' = let ss = takeWhile (== sh) s
                                 rr = dropWhile (== sh) s
                             in
                               ss:(spt rr)
spt s@(sh:ss) =
  let ss = takeWhile (\c -> c /= ' ' && c /= '.') s
      rr = dropWhile (\c -> c /= ' ' && c /= '.') s
  in
    ss:(spt rr)

ans s =
  let w = filter (\x -> length(x) == 4) s
      (a,b) = head $ concat $ map try w
  in
    concat $ map (map (f a b)) s

main = do
  _ <- getLine
  c <- getContents
  let i = map spt $ lines c
      o = map ans i
  mapM_ putStrLn o

Measured memory_bytes: 3844
import sys
from collections import defaultdict

A, B, C = map(int, input().split())

cnt = 0
memo = defaultdict(int)

while (A % 2 != 1) & (C % 2 != 1) & (C % 2 != 1):
    if memo[(A, B, C)]==1:
        print(-1)
        sys.exit()
    tmp_a = A // 2
    tmp_b = B // 2
    tmp_c = C // 2
    memo[(A, B, C)] = 1
    A = tmp_b + tmp_c
    B = tmp_c + tmp_a
    C = tmp_a + tmp_b
    cnt += 1

print(cnt)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
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; }

long long a, b, c;
int main() {
    cin >> a >> b >> c;
    long long right, left;
    if((c-a-b) > 0) {
        right = powl((c-a-b), 2);
    }else {
        right = 0;
    }

    left = 4*a*b;

    if((right - left) > 0) {
        cout << "Yes" << endl;
    }else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<queue>
#include<cmath>
#include <numeric>
#include<iomanip>
#include <cstdint>
#include<deque>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main() {
	int n, c, k;
	cin >> n >> c >> k;
	vector<int>t(n);
	for (int i = 0; i < n; i++) {
		cin >> t[i];
	}
	sort(t.begin(),t.end());
	int l = 0;
	int ans = 0;
	while (l < n) {
		int j = l;
		int tmp = t[l];
		while (t[j] - tmp <= k && (j - l) < c) {
			j++;
		}
		l = j;
		ans++;
	}
	cout << ans << endl;
}


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

int main()
{
    int a, b;
    while (cin >> a >> b)
    {
        if (a == 0 && b == 0)
        {
            break;
        }
        else
        {
            if (a > b)
            {
                cout << b << " " << a << endl;
            }
            else
            {
                cout << a << " " << b << endl;
            }
            
        }
        
    }
    return 0;
}



Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
using namespace std;
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
#define int ll
#define F first
#define S second

const int INF = 1e9 + 10;
const int N = 1e5 + 10;
vector<int> g[N];
int mx[N], vl[N], ans[N];

void precalc(int v, int p = 0, int curh = 0) {
	mx[v] = -INF;
	if (vl[v] != -1) {
		mx[v] = max(mx[v], vl[v] - curh);
	}
	for (auto u : g[v]) {
		if (u != p) {
			precalc(u, v, curh + 1);
			mx[v] = max(mx[v], mx[u]);
		}
	}
}

void dfs(int v, int p, int cur, int val) {
	ans[v] = val;
	for (auto u : g[v]) {
		if (u != p) {
			if (mx[u] >= val - cur) {
				dfs(u, v, cur + 1, val + 1);
			}
			else {
				dfs(u, v, cur + 1, val - 1);
			}
		}
	}
}

signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}
	for (int i = 1; i <= n; i++) {
		vl[i] = -1;
	}
	int k;
	cin >> k;
	int root;
	for (int i = 0; i < k; i++) {
		int a, b;
		cin >> a >> b;
		vl[a] = b;
		root = a;
	}
	precalc(root);
	dfs(root, 0, 0, vl[root]);
	for (int i = 1; i <= n; i++) {
		if (vl[i] != -1) {
			if (ans[i] != vl[i]) {
				cout << "No\n";
				exit(0);
			}
		}
	}
	cout << "Yes\n";
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << '\n';
	}
}

Measured memory_bytes: 16512
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define int long long
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int LCM(int a, int b) { int g = gcd(a, b); return a / g * b; }
//----------------------------------------------
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout<<fixed<<setprecision(15);
    
    int n; cin >> n;
    if(n%2 == 0) cout << (n/2) / (double)n << endl;
    else cout << (n/2 + 1) / (double)n << endl;

    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

def main():
  n = int(input())
  
  a = []
  b = []
  for i in range(n):
    s = input()
    c1, c2 = 0, 0
    for i in range(len(s)):
      if s[i] == "(":
        c2 += 1
      if s[i] == ")":
        if c2:
          c2 -= 1
        else:
          c1 += 1
    if c1 >= c2:
      b.append((c2, c1))
    else:
      a.append((c1, c2))
  a.sort()
  b.sort(reverse=True)
  ans = False
  sub = 0
  for value in a:
    k1, k2 = value[0], value[1]
    if sub < k1:
      ans = True
      break
    sub += k2-k1
  for value in b:
    k2, k1 = value[0], value[1]
    if ans or sub < k1:
      ans = True
      break
    sub += k2-k1
  print("No" if ans or sub else "Yes")

if __name__ == "__main__":
  main()

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

using namespace std;

typedef long long ll;

#define N 2000005
#define mod 1000000007

ll fact[N];
ll invfact[N];

ll nCr(ll n,ll r){
    if(n<0 || r<0){
        return 0LL;
    }
    if(r>n){
        return 0LL;
    }
    return (fact[n]*((invfact[r]*invfact[n-r])%mod))%mod;
}

ll power(ll a,ll b,ll p){
    if(b==0){
        return 1;
    }
    if(b%2==0){
        ll shortans=power(a,b/2,p);
        return (shortans*shortans)%p;
    }
    else{
        ll shortans=power(a,b-1,p);
        return (shortans*a)%p;
    }
}

ll moduloInverse(ll a){
    ll p=mod;
    ll b=p-2,ans=1;
    return power(a,b,p);
}

void factorialInverse(){
    invfact[N-1]=moduloInverse(fact[N-1]);
    for(ll i=N-2;i>=0;i--){
        invfact[i]=invfact[i+1]*(i+1);
        invfact[i]=invfact[i]%mod;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int k;
    string s;
    cin>>k>>s;
    int n=s.size();
    ll ans=0;
    fact[0]=1;
    for(int i=1;i<N;i++){
        fact[i]=i*fact[i-1];
        fact[i]=fact[i]%mod;
    }
    factorialInverse();
    for(int i=0;i<=k;i++){
        ll temp=(power(26,i,mod)*power(25,k-i,mod))%mod;
        temp=(temp*nCr(n+k-i-1,n-1))%mod;
        ans=(ans+temp)%mod;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 35668
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <cstdio>
#include <vector>
#include <bitset>
#include <cstring>
#include <utility>
#include <iostream>
#include <algorithm>
#define LL long long
#define Rg register
#define RI register int
#define RC register char
#define ed puts("") 
#define pair pair<LL,LL>
#define space putchar(' ')
using namespace std;
    
template <typename tp> inline void read(tp & x)
{	
    x=0;
    RI f=1;
    RC c=getchar();
    while(c<'0' || c>'9'){if(c=='-') f=-1;c=getchar(); }
    while(c>='0' && c<='9'){x=(x<<1)+(x<<3)+(c^48);c=getchar();} 
 	x*=f;
} 	
    
template <typename Tp> inline void print(Tp x)
{		
    if(x<0) x=-x,putchar('-');
    if(x>9) print(x/10);
    putchar(x%10+'0');
}	

int n,k;
LL a[1000005];
LL s[1000005];
LL b[1000005];//b[i]表示正数的前缀和 正序
LL c[1000005];//c[i]表示正数的前缀和 逆序 
LL ans;

int main()
{
	read(n);
	read(k);
	for(RI i=1;i<=n;++i)
	{
		read(a[i]);
		if(a[i]>0) b[i]=b[i-1]+a[i];
		else b[i]=b[i-1];
		s[i]=s[i-1]+a[i];
	}
	for(RI i=n;i>=1;--i)//逆序求正数的前缀和 
	{
		if(a[i]>0) c[i]=c[i+1]+a[i];
		else c[i]=c[i+1];
	}
	for(RI i=0;i<=n-k;++i)
	{
		if(s[i+k]-s[i]<0) ans=max(ans,b[i]+c[i+k+1]);//中间那段连续的区间和为负 此时可以把它们涂成白色 使总的和变大 
		else ans=max(ans,b[i]+c[i+k+1]+s[i+k]-s[i]);
	}
	print(ans);
	return 0;
}

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

#define rep(i, n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
bool custom1 (pair<int, int> a, pair<int, int> b) {
  return (a.first < b.first);
}
bool custom2(pair<int, int> a, pair<int, int> b) {
  return (a.second < b.second);
}

int main() {
  int n, k;
  cin >> n >> k;
  int lim = 0;
  for(int i=0;i<10000;i++) {
    if(n / (long long)pow(k, i) == 0) {
      lim = i;
      break;
    }
  }
  cout << lim << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>

#include <algorithm>

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

ll MOD = 1e9 + 7;

int main()
{

    int n;
    cin >> n;

    vector<int> b(n);
    vector<int> a(n);

    REP(i, n - 1)
    cin >> b[i];

    a[0] = b[0];
    for (int i = 1; i <= n - 2; ++i)
    {
        a[i] = min(b[i], b[i - 1]);
    }
    a[n - 1] = b[n - 2];

    int ans = 0;
    REP(i, n)
    ans += a[i];

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

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








int main(){
    long long A, V, B, W, T;
    std::cin >> A >> V >> B >> W >> T;
    long long dist(std::abs(A - B));
    std::cout << ((T*V >= T*W + dist) ? "YES": "NO") << std::endl;
    return 0;
}


Measured memory_bytes: 3632
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

AB = []
ABC = []

for i in A:
    for j in B:
        AB.append(i+j)

AB.sort(reverse=True)
AB_max = AB[:K]

for j in AB_max:
    for h in C:
        ABC.append(j+h)

ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])

Measured memory_bytes: 155448
import java.io.PrintWriter;
import java.util.*;

public class Main {
    static Integer[] seg;
    static int size;
    static void update(int i, int x) {
        i += size;
        seg[i] = x;
        i >>= 1;
        while (i > 0) {
            seg[i] = seg[i * 2] | seg[i * 2 + 1];
            i >>= 1;
        }
    }
    static int query(int l, int r) {
        l += size;
        r += size;
        int s = 0;
        while (l < r) {
            if ((l & 1) == 1) {
                s |= seg[l];
                l++;
            }
            if ((r & 1) == 1) {
                r--;
                s |= seg[r];
            }
            l >>= 1;
            r >>= 1;
        }
        return Integer.bitCount(s);
    }
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = Integer.parseInt(sc.next());
        size = n;
        seg = new Integer[size * 2];
        Arrays.fill(seg, 0);
        String s = sc.next();
        for (int i = 0; i < n; i++) update(i, 1 << s.charAt(i) - 'a');
        int q = Integer.parseInt(sc.next());
        for (int i = 0; i < q; i++) {
            int p = Integer.parseInt(sc.next());
            if (p == 1) {
                int j = Integer.parseInt(sc.next()) - 1;
                char c = sc.next().charAt(0);
                update(j, 1 << c - 'a');
            }
            else {
                int l = Integer.parseInt(sc.next()) - 1;
                int r = Integer.parseInt(sc.next());
                out.println(query(l, r));
            }
        }
        out.flush();
    }
}

Measured memory_bytes: 119332
#include "bits/stdc++.h"
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)n; ++i)
#define RREP(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define FOR(i, s, n) for (int i = s; i < (int)n; ++i)
#define RFOR(i, s, n) for (int i = (int)n - 1; i >= s; --i)
#define ALL(a) a.begin(), a.end()
#define IN(a, x, b) (a <= x && x < b)
template<class T>inline void out(T t){cout << t << "\n";}
template<class T,class... Ts>inline void out(T t,Ts... ts){cout << t << " ";out(ts...);}
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;}
constexpr int INF = 1e18;

signed main(){
	int A,B,N;
	cin >> A >> B >> N;
	auto f = [&](int x){
		return A*x/B - A*(x/B);
	};
	if(B - 1 <= N)out(f(B - 1));
	else out(f(N));
}

Measured memory_bytes: 3636
import java.util.Scanner;
public class Main { //C

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] a = new int[N];
		int max = 0;

		for(int i=0; i<N; i++) {
			a[i] = sc.nextInt();
			max += a[i];
		}

		System.out.println(max - N);

	}

}


Measured memory_bytes: 26324
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  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{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int n;
  cin >> n;
  vi a(n);
  rep(i, n) cin >> a[i];
  ll ans = 0;
  int x = a[0];
  rep(i, n) {
    if (i == 0) continue;
    x = max(x, a[i]);
    ans += x - a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 4044
#include<cstdio>
using namespace std;
int n,m,cnt[100005],A,B,ans;
bool flag[100005];
int main()
{
	scanf("%d%d",&n,&m);for(int i=1;i<=n;++i) cnt[i]=1;flag[1]=true;
	for(int i=1;i<=m;++i) {
		scanf("%d%d",&A,&B);
		if(flag[A]) flag[B]=true;
		if(cnt[A]==1&&flag[A]) flag[A]=false;
		cnt[A]--;cnt[B]++;
	}
	for(int i=1;i<=n;++i) if(flag[i]) ++ans;
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
 using namespace std;
 long long N, A[87], CurrentMoney = 1000;
 int main() {
 cin >> N;
 for (int i = 1; i <= N; i++) cin >> A[i];
 for (int i = 1; i <= N - 1; i++) {
 long long Stocks = 0; if (A[i] < A[i + 1]) Stocks = CurrentMoney / A[i];
 CurrentMoney += (A[i + 1] - A[i]) * Stocks;
 }
 cout << CurrentMoney << endl;
 }


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  int N, M;
  cin >> N >> M;
  vector<tuple<int, int, int>> city;
  vector<tuple<int, int, int>> IDs;
  int ID1, ID2;
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    city.emplace_back(a, b, i);
  }
  sort(city.begin(), city.end());
  int P = 0, L = 0;

  REP(i, M) {
    ID1 = get<0>(city.at(i));
    if (L != ID1) {
      P = 0;
      L = ID1;
    }
    P++;
    ID2 = P;
    IDs.emplace_back(get<2>(city.at(i)), ID1, ID2);
  }
  sort(IDs.begin(), IDs.end());
  REP(i, M) printf("%06d%06d\n", get<1>(IDs.at(i)), get<2>(IDs.at(i)));
}

Measured memory_bytes: 3956
#include "bits/stdc++.h"
#define rep(i,cc,n) for(int i=cc;i<(n);++i)
#define drep(i,cc,n) for(int i=cc;i>(n);--i)
#define llrep(i,cc,n) for(long long i=cc;i<(n);++i)
using namespace std;
using ll = long long;
 
int main()
{
	int N;
	cin >> N;
	switch (N % 10)
	{
	case 0:
		cout << "pon" << endl;		break;
	case 1:
		cout << "pon" << endl;		break;
	case 2:
		cout << "hon" << endl;		break;
	case 3:
		cout << "bon" << endl;		break;
	case 4:
		cout << "hon" << endl;		break;
	case 5:
		cout << "hon" << endl;		break;
	case 6:
		cout << "pon" << endl;		break;
	case 7:
		cout << "hon" << endl;		break;
	case 8:
		cout << "pon" << endl;
		break;
	case 9:
		cout << "hon" << endl;
		break;
	default:
		break;
	}
}

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

#define N_MAX 100001

int main() {
    int n; cin >> n;
    vector<int> odd(n / 2), even(n / 2);
    vector<int> odd_cnt(N_MAX, 0), even_cnt(N_MAX, 0);
    for(int i = 0; i < n / 2; i++) {
        cin >> odd[i] >> even[i];
        odd_cnt[odd[i]]++;
        even_cnt[even[i]]++;
    }

    int odd_fir = 0, odd_sec = 0, even_fir = 0, even_sec = 0;
    for(int i = 1; i < N_MAX; i++) {
        if(odd_cnt[odd_fir] < odd_cnt[i]) {
            odd_sec = odd_fir;
            odd_fir = i;
        } else if(odd_cnt[odd_sec] < odd_cnt[i]) {
            odd_sec = i;
        }
        if(even_cnt[even_fir] < even_cnt[i]) {
            even_sec = even_fir;
            even_fir = i;
        } else if(even_cnt[even_sec] < even_cnt[i]) {
            even_sec = i;
        }
    }

    if(odd_fir == even_fir) {
        int ans1 = n - odd_cnt[odd_fir] - even_cnt[even_sec];
        int ans2 = n - even_cnt[even_fir] - odd_cnt[odd_sec];
        cout << min(ans1, ans2) << endl;
        return 0;
    }

    cout << n - odd_cnt[odd_fir] - even_cnt[even_fir] << endl;
    return 0;
}


Measured memory_bytes: 1408
n, l = map(int, input().split())
taste = 0
ans = 0
diff = 999

for i in range(n):
    taste = taste + l + i

for i in range(n):
    if diff > abs(taste - (taste - (l + i))):
        diff = abs(taste - (taste - (l + i)))
        ans = taste - (l + i)
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define M 505
#define XFZSB {printf("No\n"); return 0;}
#define YXQAK {printf("Yes\n");}
using namespace std;

struct node{
	int id,x; node(){id=x=0;}
	node(int iid,int nnum){id=iid; x=nnum;}
	friend bool operator <(node a,node b){return a.x<b.x;}
}a[M];
int num[M*M]={0},now=1; short sum[M*M][M]={0};
int main(){
	int n; scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x; scanf("%d",&x);
		a[i]=node(i,x);
	}
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++){
		num[a[i].x]=a[i].id; 
		int ci=sum[now][a[i].id]+1;
		while(now<=a[i].x&&ci<a[i].id){
			if(!num[now]){
				num[now]=a[i].id; ci++;
			}
			for(int j=1;j<=n;j++)
			sum[now][j]=sum[now-1][j]+(num[now]==j);
			now++;
		}
		//if(sum[a[i].x][a[i].id]!=a[i].id) XFZSB
	}
	for(int i=1;i<=n;i++){
		int ci=sum[now-1][a[i].id]+(now<=a[i].x);
		while(now<=n*n&&ci<n){
			if(!num[now]){
				num[now]=a[i].id; ci++;
			}
			for(int j=1;j<=n;j++)
			sum[now][j]=sum[now-1][j]+(num[now]==j);
			now++;
		}
	}
	for(int j=1;j<=n;j++)
	sum[n*n][j]=sum[n*n-1][j]+(num[now]==j);
	for(int i=1;i<=n;i++)
	if(sum[a[i].x][a[i].id]!=a[i].id) XFZSB;
	YXQAK
	for(int i=1;i<=n*n;i++) printf("%d ",num[i]);
}

Measured memory_bytes: 251648
def nCr(a,b):
	tmp=1
	for i in range(a,a-b,-1):tmp*=i
	for i in range(1,b+1,1):tmp//=i
	return tmp

n=int(input())
out=[]
co=1
coo=0
while n>0:
	t=2
	while True:
		sum1=0
		for j in range(2,t+1,2):
			sum1+=nCr(t,j)
#		print(n,sum)
		if n<sum1:
			t-=1
#			n-=rco
			break
		rco=sum1
		t+=1
	ad=[co for _ in range(t)]
	sum1=rco
	ma=sum1
#	print(ma)
	for toa in range(1,4):
		for tob in range(1,4):
			CO=0
			for r in range(1,min(toa,tob)+1):
				CO+=nCr(toa,r)*nCr(tob,r)
		
			for a in range(1,t):
				sum2=sum1+((2**(toa+tob-1))-1)
				for b in range(1,a+1):
					sum2+=nCr(a,b)*nCr(t-a,b)*CO
				if sum2>n:continue
				if ma<sum2:
					ma=sum2
					ad=[co for _ in range(a)]
					for _ in range(toa):ad.append(100-coo)
					for _ in range(t-a):ad.append(co)
					for _ in range(tob):ad.append(100-coo)
	
#	print(ad,0,ma)
	for t in ad:out.append(t)
#	out.append(ad)
	n-=ma
	coo+=1
	co+=1
print(len(out))
print(*out)
			

Measured memory_bytes: 3188
#include<stdio.h>
#include<math.h>

int main(void){
  unsigned long int n;
  scanf("%lu",&n);
  int kotae[10000],i=0,j,amari,sho;

  for(i=0;i<10000000;i++){
    if(n/26 >= 1){
      if(n%26 != 0){
      amari = n%26;
      kotae[i] = amari;
      n = (n - amari)/26;
      }
      else {
      	kotae[i] = 26;
        n = (n-26)/26;
      }
    }
    else{
      if(n!=0){
        kotae[i] = n;
      }
	break;
    } 
  }

  //a=97 z=122
  for(j=i;j>=0;j--){
if(kotae[j] == 0){
j--;
}
    printf("%c",kotae[j]+96);
  }
  
  return 0;
}

Measured memory_bytes: 1652
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for( int i = 0; i < n; i++ )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


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

    string N;
    cin >> N;

    rep(i ,2) {
        if (N[i] == '9') {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
	int n;
	cin>>n;
	long long a[n+1];
	a[0]=0;
	for(int i=1;i<=n;i++){
		cin>>a[i];
		a[i]+=a[i-1];
	}
	n=a[n]-n;	
	cout<<n<<endl;
	return 0;
}

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

#define watch(x) cerr << (#x) << ": " << (x) << endl
#define int long long

int32_t main() {

    int n; cin >> n;
    vector<vector<int>> edges(n+1);
    vector<int> deg(n+1, 0);
    for(int i = 0; i < n-1; ++i) {
        int a, b; cin >> a >> b;
        edges[a].push_back(b);
        edges[b].push_back(a);
        deg[a]++;
        deg[b]++;
    }
    
    int m = 0;
    vector<int> c(n);
    for(int i = 0; i < n; ++i) {
        int x; cin >> x;
        m += x;
        c[i] = x;
    }
    sort(c.begin(), c.end());
    m -= c.back();

    vector<int> ans(n+1);

    for(int i = 0; i < n-1; ++i) {
        int cur = c[i];
        for(int j = 1; j <= n; ++j) {
            if(deg[j] == 1) {
                ans[j] = cur;
                deg[j]--;
                for(int edge : edges[j]) deg[edge]--;
                break;
            }
        }
    }
    for(int j = 1; j <= n; ++j) {
        if(ans[j] == 0) ans[j] = c.back();
    }

    cout << m << endl;
    for(int i = 1; i <= n; ++i) {
        cout << ans[i] << " ";
    }
    cout << endl;
    
    return 0;
}


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

// Union-Find
struct UnionFind {
    vector<int> par;
    vector<int> black;
    vector<int> white;

    //最初は全てが根であるとして初期化
    UnionFind(int N) : par(N), black(N, 0), white(N,0){
        for(int i = 0; i < N; i++) par[i] = i;
    }

    // データxが属する木の根を再帰で得る
    int root(int x){
        if (par[x] == x) return x;
        par[x] = root(par[x]); // 親を根にする付け替えによって次回以降の参照を高速化
        return par[x];
    }

    // xとyの木を併合
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        par[ry] = rx;
        white[rx] += white[ry];
        black[rx] += black[ry];
    }
};

int main() {
    int H, W;
    cin >> H >> W;
    vector<string>S(H);
    for (int i = 0; i < H; ++i) {
      cin >> S[i];
    }
    UnionFind tree(H*W);
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int k = W * i + j;
            if(S[i][j] == '#') {
                tree.black[k]++;
            } else{
                tree.white[k]++;
            }
        }
    }
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int k = W * i + j;
            if(i != H-1 && S[i][j] != S[i+1][j]){
                tree.unite(k, k+W);
            }
            if(j != W-1 && S[i][j] != S[i][j+1]){
                tree.unite(k, k+1);
            }
        }
    }

    ll ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            int k = W * i + j;
            if(tree.par[k] == k){
                ll temp = tree.black[k];
                ans += temp * tree.white[k];
            }
        }
    }
    cout << ans;
    return 0;
}

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

using namespace std;

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

    int n;
    cin >> n;

    vector<int> score(n);
    vector<string> name(n);
    for (int i = 0 ;i < n ;i++)
        cin >> name[i] >> score[i];


    vector<int> order(n);
    iota(order.begin() , order.end() , 0);

    sort(order.begin() , order.end() , [&](int i , int j){
        if (name[i] != name[j])
            return name[i] < name[j];
        return score[i] > score[j];
    });

    for (int x : order)
        cout << x + 1 << '\n';
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
#define ll long long
#define iof ios_base::sync_with_stdio(false); cin.tie(NULL)
#define pi 3.1415926535897
#define mod 1000000007
#define inf (1ll<<60)
using namespace std;

int main()
{
    iof;
  ll n; cin>>n;
  ll arr[n];
  for(ll i=0;i<n;i++)
    cin>>arr[i];
  ll dp[n][n];
  for(ll i=0;i<n;i++)
    for(ll j=0;j<n;j++)
     dp[i][j]=0;
  for(ll i=0;i<n;i++)
    dp[i][i]=arr[i];
  ll k=1;
  while(k<n)
  {
      ll i=0,j=k;
      while(j<n)
      {
          dp[i][j]=max(arr[i]-dp[i+1][j],arr[j]-dp[i][j-1]);
          j++;
          i++;
      }
      k++;
  }
  /*for(ll i=0;i<n;i++)
  {
      for(ll j=0;j<n;j++)
      {
          cout<<dp[i][j]<<" ";
      }
      cout<<endl;
  }*/
  cout<<dp[0][n-1]<<endl;

}


Measured memory_bytes: 70656
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<vector>
#include<utility>

using namespace std;

int main(){

	int k,x;
	cin>>k>>x;

	if(500*k>=x)cout<<"Yes";
	else cout<<"No";




	cout<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define REP(i, a, b) for(int i = (a); i <= (b); i++)
#define PER(i, a, b) for(int i = (a); i >= (b); i--)
#define rep(i, a, b) for(int i = (a); i < (b); i++)
#define all(S) (S).begin(), (S).end()
#define pf push_front
#define pb push_back
#define mk make_pair
#define S second
#define F first
typedef long long ll;
typedef long double lf;
typedef pair<int, int> ii;
const int MAX = 1e5+5;
int N, D, m[12][12];
int	 pd[MAX], ans;

int main(int argc, char ** argv) {
	for(int i = 1; i*i < MAX; i++)
		pd[i*i] = 1;
	scanf("%d%d", &N, &D);
	rep(i, 0, N) rep(j, 0, D) scanf("%d", &m[i][j]);
	rep(i, 0, N) rep(j, i+1, N) {
		int cnt = 0;
		rep(k, 0, D) cnt += (m[i][k]-m[j][k])*(m[i][k]-m[j][k]);
		ans += pd[cnt];
	}
	printf("%d\n", ans);
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<long long int> a(n);
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    if(n==1){
        cout << a[0];
        return 0;
    }    
    vector<vector<long long int>> dp(n,vector<long long int>(n,0));
    for(int k=0;k<n;k++){
        for(int j=k,i=0;i<n&&j<n;i++,j++){
            if(i==j) dp[i][j] = a[i];
            else if(j-i==1) dp[i][j] = max(a[i],a[j]);
            else dp[i][j] = max( min( dp[i+2][j] , dp[i+1][j-1] )+a[i], min( dp[i+1][j-1],dp[i][j-2] )+a[j] );
        }
    }
    if(dp[1][n-1] < dp[0][n-2]) cout << dp[0][n-1] - dp[1][n-1];
    else cout << dp[0][n-1] - dp[0][n-2];
	return 0;
}

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

const int MAX = 1000000;
const int MP = 999983;
int n;
bool is_prime[(MAX + 1) * 2 + 1];
int prime_count[(MAX + 1) * 2 + 1];

void sieve()
{
    for(int i = 0; i <= (MAX + 1) * 2; i++) 
        is_prime[i] = false;

    is_prime[2] = true;
    for(int i = 3; i <= MP; i+=2) {
        is_prime[i] = true;
        for(int j = 3; j*j <= i; j+=2) {
            if(i % j == 0) {
                is_prime[i] = false;
                break;
            }
        }
    }
}

void calc_count()
{
    prime_count[0] = 0;
    for(int i = 1; i <= (MAX + 1) * 2; i++) {
        prime_count[i] = prime_count[i-1];
        if(is_prime[i])
            prime_count[i]++;
    }
}

int main()
{
    sieve();
    calc_count();
    while(cin >> n && n) {
        int p,m,sum,x;
        sum = 0;
        for(int i = 0; i < n; i++) {
            cin >> p >> m;
            int lb, ub;
            lb = (p - m - 1 >= 0) ? p - m - 1 : 0;
            ub = p + m;
            x = prime_count[ub] - prime_count[lb];
            sum += x - 1;
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 6464
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<array>
#include<map>
#include<iomanip>
#include<assert.h>
#include<bitset>
#include<stack>
#include<memory>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
/*
cout<<setprecision(20);
cin.tie(0);
ios::sync_with_stdio(false);
*/
const llint mod=1000000007;
const llint big=2.19e15+1;
const long double pai=3.141592653589793238462643383279502884197;
const long double eps=1e-15;
template <class T,class U>bool mineq(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool maxeq(T& a,U b){if(a<b){a=b;return true;}return false;}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){if(a==0){return b;}return a/gcd(a,b)*b;}
template<class T> void SO(T& ve){sort(ve.begin(),ve.end());}
template<class T> void REV(T& ve){reverse(ve.begin(),ve.end());}
template<class T>llint LBI(vector<T>&ar,T in){return lower_bound(ar.begin(),ar.end(),in)-ar.begin();}
template<class T>llint UBI(vector<T>&ar,T in){return upper_bound(ar.begin(),ar.end(),in)-ar.begin();}
int main(void){
	llint n,m,ans;cin>>n>>m;
	if(n>=2*m){ans=0;}
	else if(2*n<=m){ans=1;}
	else if(n>=m){ans=2;}
	else if(2*n<=3*m-2*n+m/2){ans=3;}
	else{ans=4;}
	cout<<ans<<endl;
}


Measured memory_bytes: 3092
#include <cstdio>

using namespace std;
typedef long long ll;

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

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

int main() {
	int n; scanf("%d", &n);
	ll cumu = 1;
	for (int i = 0; i < n; ++i) {
		ll ti; scanf("%lld", &ti);
		cumu = lcm(cumu, ti);
	}
	printf("%lld\n", cumu);
	return 0;
}

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

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

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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;
using vpi = vector<Pi>;
using vpl = vector<Pl>;

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
  cout << "{"; for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i]; cout << "}";
  return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
  cout << "{\n"; for (auto& vec : arr)cout << "  " << vec << ",\n"; cout << "}";
  return out;
}
template<class S,class T> ostream &operator << (ostream& out, const pair<S,T>& p){
  cout << "{" << p.first << "," << p.second << "}" << '\n';
  return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
  for (auto& i : arr)cin >> i; return in;
}

/////////////////////////////////////////////////////////////////////////
ll n,v[3],d;
ll ans = (1LL << 55);
ll _div[3] = {2,3,5};
map<ll,ll> M;
void func(ll X,ll tmp){
  if(M.count(X)){
    if(M[X] <= tmp) {
      return;
    }else{
      M[X] = tmp;
    }
  }else{
    M[X] = tmp;
  }

  if(X == 0){
    chmin(ans , tmp);
    return;
  }
  if(X == 1) {
    chmin(ans , tmp + d);
    return;
  }
  if(d < (LONG_MAX - tmp) / X){
    chmin(ans,tmp + X * d);
  }
  REP(i,3){
    ll fl = X / _div[i];
    ll se = (X + _div[i] - 1) / _div[i];
    func(fl,tmp + v[i] + d*abs(X - fl*_div[i]));
    func(se,tmp + v[i] + d*abs(X - se*_div[i]));
  }
}

void main2(){
  cin >> n;
  cin >> v[0] >> v[1] >> v[2] >> d;
  ans = (1LL<<55);
  M.clear();
  func(n,0);
  cout << ans << endl;
}
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  //cout << fixed << setprecision(20);

  int tt;cin >> tt;
  while(tt--) main2();
  return 0;
}


Measured memory_bytes: 4492
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cctype>
 
#include <algorithm>
#include <tuple>
#include <random>
#include <bitset>
#include <queue>
#include <functional>
#include <set>
#include <map>
#include <vector>
#include <chrono>
#include <iostream>
#include <limits>
#include <numeric>
 
#define LOG(FMT...) fprintf(stderr, FMT)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

// mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (T& x : v)
    is >> x;
  return is;
}
 
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  if (!v.empty()) {
    os << v.front();
    for (int i = 1; i < v.size(); ++i)
      os << ' ' << v[i];
  }
  return os;
}

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

  int k;
  cin >> k;
  if (k == 1)
    cout << "1\n1";
  else {
    int n = (k + 3) / 4 * 2;
    vector<vector<int>> ans(n, vector<int>(n));
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j) {
        ans[i][j] = 1 + ((i & 1) ? (n + (i + j) % n) : ((i + j) % n));
        while (ans[i][j] > k) ans[i][j] -= n;
      }
    cout << n << '\n';
    for (int i = 0; i < n; ++i)
      cout << ans[i] << '\n';
  }

  return 0;
}


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

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

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()

#define debug(arr) cout << #arr << " = " << arr << '\n'
#define debug2(a,b) cout << "[" << #a << "," << #b << "] = " << "[" << a << "," << b << "]" << '\n'
template<class T> ostream &operator << (ostream& out, const vector<T>& arr) {
	cout << "{";
	for (int i = 0; i < arr.size(); i++)cout << (!i ? "" : ", ") << arr[i];
	cout << "}";
	return out;
}
template<class T> ostream &operator << (ostream& out, const vector<vector<T> >& arr) {
	cout << "{\n";
	for (auto& vec : arr)cout << "  " << vec << ",\n";
	cout << "}";
	return out;
}
template<class T> istream &operator >> (istream& in, vector<T>& arr) {
	for (auto& i : arr)cin >> i; return in;
}

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

	// input
	int n, k; cin >> n >> k;
	vector<ll> p(n), c(n);
	REP(i, n)cin >> p[i], p[i]--;
	REP(i, n)cin >> c[i];

	vector<vector<int>> ps;
	vector<bool> used(n, false);
	REP(i, n) {
		int tmp = i;
		if (!used[tmp]) {
			vector<int> s;
			while (true) {
				s.pb(tmp);
				used[tmp] = true;
				tmp = p[tmp];
				if (used[tmp])break;
			}
			ps.pb(s);
		}
	}

	ll res = -(1LL << 55);

	// for(auto a : ps)cout << a << '\n';
	// return 0;

	for (auto a : ps) {

		int sz = a.size();
		// int now = a[0];
		vector<ll> b(2 * sz);
		REP(i, sz) {
			b[i] = b[i + sz] = c[a[i]];
		}
		vector<ll> cum(2 * sz + 1, 0);
		REP(i, 2 * sz) {
			cum[i + 1] = cum[i] + b[i];
		}

		// cout << b << '\n'; cout << cum << '\n';

		auto func = [&](int len) -> ll{
			ll res = -LONG_MAX;

			for (int i = 0; i + len <= 2 * sz; i++) {
				res = max(res , cum[i + len] - cum[i]);
			}

			return res;
		};
		//debug(func(1));
		// k > n
		if (k > sz) {
			// sum > 0 -> (k / n) * SUM + (k % n) len max.
			ll sum = 0;
			REP(i, sz) sum += b[i];
			ll ans = -(1LL << 55);

			if (sum >= 0) {

				ans = 0;
				// one roop and rest / other
				ll roop = (k / sz);
				roop--;
				ans += roop * sum;

				ll rest = k % sz;
				ll cand_add = 0 ;

				// 1,2,...rest : roop ++
				for (int i = 0; i <= rest; i++) {
					cand_add = max(cand_add , sum + func(i));
				}

				// other
				for (int i = rest + 1; i <= sz; i++) {
					cand_add = max(cand_add , func(i));
				}

				ans += cand_add;

			}
			else {
				// otherwise , 1 - n len max (O(N^2) works)

				for (int i = 1; i <= sz; i++) {
					ans = max(ans , func(i));
				}

			}

			// cout << ans << '\n';
			res = max(res , ans);

		} else {
			// 1 - k O(N**2) search.

			ll ans = -(1LL << 55);
			for (int i = 1; i <= k; i++) {
				ans = max(ans , func(i));
			}

			// cout << ans << '\n';
			res = max(res , ans);

		}
	}
	cout << res << '\n';

}


Measured memory_bytes: 3776
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;
//#define mod 1000000007
#define PI acos(-1.0)
const long long MAX=200005;
typedef long long ll;
//const int INF=0x3f3f3f3f;
//int d[8][2]={-1,0,0,-1,0,1,1,0,1,1,-1,-1,-1,1,1,-1};
int n,m,t=0;
char b[9]={'A','K','I','H','A','B','A','R','A'};
int main()
{
    char a[100];
    scanf("%s",&a);
    int l=strlen(a);
    if(l<5||l>9)
    {
        printf("NO\n");
        return 0;
    }
    for(int i=0;i<l;i++)
    {
        if(a[i]==b[t])
        {
            t++;
            continue;
        }
        else if(b[t]=='A')
        {
            t++;
            i--;
        }
        else
        {
            printf("NO\n");
            return 0;
        }
    }
    if(t<8)
    {
        printf("NO\n");
        return 0;
    }
    printf("YES\n");
    return 0;
}


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

using ll = long long;

// min segtree

struct node {
	ll val;
	ll lazy;
	node *l, *r;
};

void push(node* v){
	if(!v) return;
	v->val += v->lazy;
	if(v->l) v->l->lazy += v->lazy;
	if(v->r) v->r->lazy += v->lazy;
	v->lazy = 0;
}

node* build(const vector<ll>& a, int lx, int rx){
	node* v = new node();
	v->lazy = 0;
	if(lx == rx){
		v->l = v->r = nullptr;
		v->val = a[lx];
	} else {
		v->l = build(a, lx, (lx + rx) / 2);
		v->r = build(a, (lx + rx) / 2 + 1, rx);
		v->val = min(v->l->val, v->r->val);
	}
	return v;
}

ll query(node* v, int vlx, int vrx, int lx, int rx){
	if(!v || vrx < lx || rx < vlx) return 1e9;
	push(v);
	if(lx <= vlx && vrx <= rx) return v->val;
	return min(query(v->l, vlx, (vlx + vrx) / 2, lx, rx),
		       query(v->r, (vlx + vrx) / 2 + 1, vrx, lx, rx));
}

void upd(node* v, int vlx, int vrx, int lx, int rx, ll val){
	push(v);
	if(!v || vrx < lx || rx < vlx) return;
	if(lx <= vlx && vrx <= rx){
		v->lazy += val;
		push(v);
	} else {
		upd(v->l, vlx, (vlx + vrx) / 2, lx, rx, val);
		upd(v->r, (vlx + vrx) / 2 + 1, vrx, lx, rx, val);
		v->val = min(v->l->val, v->r->val);
	}
}

ll solve(vector<ll> types){
	vector<ll> sums;
	ll cur = 0;
	for(int i = 0; i <= (int)types.size(); i++){
		sums.push_back(cur);
		if(i == (int)types.size()) break;
		if(types[i] == 1 || types[i] == 3){
			cur -= 1;
		} else if(types[i] == 2){
			cur += 1;
		} else if(types[i] == 0){
			cur += 0;
		}
	}
	sums.back() += 1;

	int Z = (int)sums.size() - 1;

	node* segtree = build(sums, 0, Z);

	ll best = 1e9;
	for(int i = 0; i <= (int)types.size(); i++){
		ll cost = -2 * query(segtree, 0, Z, 0, Z) + query(segtree, 0, Z, 0, 0) + query(segtree, 0, Z, Z, Z) + (int)types.size() + 1;
		best = min(best, cost);
		if(i == (int)types.size()) break;
		// flip ones to twos from left to right
		if(types[i] == 3){
			upd(segtree, 0, Z, i+1, Z, 2);
		}
	}

	return best;
}

int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	ll n, L;
	cin >> n >> L;
	vector<ll> x(n);
	for(int i = 0; i < n; i++) cin >> x[i];
	vector<ll> t(n);
	for(int i = 0; i < n; i++) cin >> t[i];
	ll ans = 0;
	for(int i = 0; i < n; i++){
		ll f = (t[i] - 1) / (2 * L);
		ans += f * 2;
		t[i] -= f * 2 * L;
	}
	vector<ll> types;
	for(int i = 0; i < n; i++){
		bool goleft = t[i] <= 2 * (L - x[i]);
		bool goright = t[i] <= 2 * x[i];
		if(!goleft && !goright){
			ans += 1;
		}
		types.push_back((ll(goleft) << 0) ^ (ll(goright) << 1));
	}
	cout << L * (solve(types) + ans) << '\n';
}

Measured memory_bytes: 43116
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,d=0;
    cin>>a;
    b=a;
    while(b){
        c=b%10;
        d+=c;
        b=b/10;
    }
    if(a%d==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

/*--- Macro ---*/
#define rep(i, n) for(int i=0; i<(int)n; i++)
#define rep1(i, n) for(int i=1; i<(int)n; i++)
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()

/*---  Type ---*/
typedef long long ll;

/*--- Constants ---*/
template <typename T> const T INF = numeric_limits<T>::max() / 10;
const int MOD = (int)1e9 + 7;

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

// Util
int max(int a, int b, int c) {return max(a, max(b, c));}
int min(int a, int b, int c) {return min(a, min(b, c));}
ll max(ll x, ll y) {return x > y ? x : y;}
ll min(ll x, ll y) {return x < y ? x : y;}
ll max(ll a, ll b, ll c) {return max(a, max(b, c));}
ll min(ll a, ll b, ll c) {return min(a, min(b, c));}

// How to use 「map」
/*
  - 宣言
    map<{key_type}, {value_type}> salary;
  - 要素の挿入
    salary["Alice"] = 1000;
  - 要素の取得 O(logn)
    salary.at("Alice");
  - 要素の削除
    salary.erase("Alice");
  - キー検索
    salary.find("Alice"); -> true
    salary.find("Bob");   -> false
  - イテレーション
    for(auto& [key, value] : salary) {...}
 */
// -------------------------------------


// How to use 「lower_bound」, 「upper_bound」
/*
  vector<int> a = {1, 2, 3, 4, 5};
  auto iter1 = lower_bound(all(a), 3);  <- 第二引数「以上」の最小イテレータが返る
  auto iter2 = upper_bound(all(a), 3);  <- 第二引数「より大きい」最小のイテレータが返る
 */
// -------------------------------------


// How to use 「struct sort」
/*
  struct Person {
    string name;
    int age;

    Person(string _name, int _age) {
      name = _name;
      age = _age;
    }

    bool operator<(const Person &another) const {
      return age < another.age;
    }
  };

  vector<Person> people;
  people.pb(Person("Alice", 20));
  people.pb(Person("Bob", 19));
  people.pb(Person("John", 40));
  people.pb(Person("Chris", 30));
  sort(all(people));
 */
 // -------------------------------------

// -------------------------------------------------------------------------------------



int main() {
  double h, a;

  cin >> h >> a;

  cout << ceil(h / a) << endl;

  return 0;
}

Measured memory_bytes: 256