akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using pi = tuple<int, int, int>;
const int INF = 100000000;

int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	int N, M, H, K, S, T, P;
	while (cin >> N >> M >> H >> K, N | M | H | K) {
		vector<int> a(M), b(M), c(M), h(M), r(M);
		for (int i = 0; i < M; i++) {
			cin >> a[i] >> b[i] >> c[i] >> h[i] >> r[i]; a[i]--; b[i]--; r[i]--;
		}
		cin >> S >> T >> P; S--; T--;
		vector<int> dp(1 << K, INF); dp[0] = 0;
		for (int i = 0, l, d; i < P; i++) {
			cin >> l >> d;
			int val = 0;
			for (int j = 0, k; j < l; j++) {
				cin >> k;
				val += 1 << (k - 1);
			}
			for (int j = 0; j < (1 << K); j++) {
				if (dp[j] != INF) {
					dp[j | val] = min(dp[j | val], dp[j] + d);
				}
			}
		}
		int res = INF;
		for (int i = 0; i < (1 << K); i++) {
			if (dp[i] == INF) continue;
			vector<vector<int>> d(N, vector<int>(H + 1, INF));
			vector<vector<pi>> G(N);
			for (int j = 0; j < M; j++) {
				if (i & (1 << r[j])) {
					G[a[j]].push_back(pi(0, h[j], b[j]));
					G[b[j]].push_back(pi(0, h[j], a[j]));
				}
				else {
					G[a[j]].push_back(pi(c[j], h[j], b[j]));
					G[b[j]].push_back(pi(c[j], h[j], a[j]));
				}
			}
			priority_queue<pi, vector<pi>, greater<pi>> pq;
			pq.push(pi(0, 0, S));
			while (!pq.empty()) {
				auto p = pq.top(); pq.pop();
				if (d[get<2>(p)][get<1>(p)] != INF) {
					continue;
				}
				d[get<2>(p)][get<1>(p)] = get<0>(p);
				for (auto v : G[get<2>(p)]) {
					if (get<1>(p) + get<1>(v) <= H && d[get<2>(v)][get<1>(p) + get<1>(v)] == INF) {
						pq.push(pi(get<0>(p) + get<0>(v), get<1>(p) + get<1>(v), get<2>(v)));
					}
				}
			}
			int mid = INF;
			for (int i = 0; i <= H; i++) {
				mid = min(mid, d[T][i]);
			}
			res = min(res, dp[i] + mid);
		}
		printf("%d\n", (res != INF ? res : -1));
	}
	return 0;
}

Measured memory_bytes: 3620
h,w,d = gets.split.map(&:to_i)
ha={}
h.times do |i|
  ar=gets.split.map(&:to_i)
  w.times do |j|
    ha[ar[j]]=[i,j]
  end
end

dis=Array.new(h*w+1,0)
(1..h*w).each do |i|
  if i>d
    dis[i]=dis[i-d]+(ha[i].first-ha[i-d].first).abs+(ha[i].last-ha[i-d].last).abs
  end
end

gets.to_i.times do
  l,r=gets.split.map(&:to_i)
  puts dis[r]-dis[l]
end

Measured memory_bytes: 16764
// abc134_b
#include <bits/stdc++.h>
#ifdef LOCAL
#include "../cxx-prettyprint/prettyprint.hpp"
#endif
using namespace std;

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

#define REP(i, n) for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n) for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define REP_REV(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (int (i) = (int)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) x.begin(), x.end()

#define INF ((1 << 29)-1)
#define MOD (1000000007)

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }
struct PreMain {PreMain(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(20);}} premain;

int main() {
#ifdef LOCAL
    ifstream in("../arg.txt"); cin.rdbuf(in.rdbuf());
#endif

    int N, D;
    cin >> N >> D;
    int ans = (N + 2 * D) / (2 * D + 1);
    print(ans);

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
template<class T, class Compare = less<T> >
using MaxHeap = priority_queue<T, vector<T>, Compare>;
template<class T, class Compare = greater<T> >
using MinHeap = priority_queue<T, vector<T>, Compare>;
using llong = long long;

llong n;

int main() {
    cin >> n;

    llong a = 1;
    while (a <= n) {
        a *= 2;
    }
    a /= 2;

    cout << a << endl;

    return 0;
}



Measured memory_bytes: 3084
#include <iostream>
#include <string>
using namespace std;
int main(void){
  int i;
  string s,sa[16]={"KIHBR","AKIHBR","KIHABR","AKIHABR","KIHBAR","AKIHBAR","KIHABAR",
                   "AKIHABAR","KIHBRA","AKIHBRA","KIHABRA","AKIHABRA","KIHBARA",
                   "AKIHBARA","KIHABARA","AKIHABARA"};
  cin >> s;
  for (i=0;i<16;i++) if (s==sa[i]) break;
  if (i==16) cout << "NO" << endl;
  else cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn main() {
	let x: u32 = read();
	let ans = (x/500)*1000 + ((x%500)/5)*5;
	println!("{}", ans);
}

fn read<T: FromStr>() -> T {
	let stdin = stdin();
	let stdin = stdin.lock();
	let token: String = stdin
		.bytes()
		.map(|c| c.expect("failed to read char") as char)
		.skip_while(|c| c.is_whitespace())
		.take_while(|c| !c.is_whitespace())
		.collect();
	token.parse().ok().expect("failed to parse token")
}



Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define pb push_back
#define cmin(a,b) (a>b?a=b:a)
#define cmax(a,b) (a<b?a=b:a)
#define all(v) v.begin(),v.end()
#define mem(a,k) memset(a,k,sizeof(a))
#define lop(i,s,t) for(int i=s;i<(t);++i)
#define rep(i,s,t) for(int i=s;i<=(t);++i)
#define dec(i,s,t) for(int i=s;i>=(t);--i)
#define fore(i,v) for(int i=g[v],d=es[i].d;i;i=es[i].nxt,d=es[i].d)
using namespace std;

#define Pr(f,...) fprintf(stdout,f,##__VA_ARGS__),fflush(stdout)

typedef long long ll;

template<typename T>
void read(T &x){
	x=0; 
	char c;
	for(c=getchar();!isdigit(c);c=getchar()); 
	for(;isdigit(c);c=getchar())x=x*10+c-'0'; 
}

const int N=2e5+50;
const ll oo=1ll*N*N;

int n;
struct E { int d,w; } ; 
struct S { ll x,y; } ; 
bool cmpX(S a,S b){ return a.x==b.x?a.y<b.y:a.x<b.x; }
bool cmpY(S a,S b){ return a.y==b.y?a.x<b.x:a.y<b.y; }
bool operator==(S a,S b){ return a.x==b.x&&a.y==b.y; }
typedef vector<S> V; 
vector<E> g[N]; 
namespace Checker{
	ll L; 
	V a[N];
	void merge(V&s1,ll va,V&s2,ll vb,V&d){
		size_t p; ll mn;

		p=0,mn=oo;
		sort(all(s1),cmpY);
		reverse(all(s1));
		sort(all(s2),cmpX);
		for(S v:s1){
			for(;p<s2.size()&&v.y+s2[p].x<=L-va-vb;++p){
				cmin(mn,vb+s2[p].y);
			}
			if(mn!=oo)d.pb((S){va+v.x,mn});
		}

		sort(all(s1),cmpX);
		reverse(all(s1));
		sort(all(s2),cmpY);
		p=0,mn=oo;
		for(S v:s1){
			for(;p<s2.size()&&v.x+s2[p].y<=L-va-vb;++p){
				cmin(mn,vb+s2[p].x);
			}
			if(mn!=oo)d.pb((S){mn,va+v.y});
		}
		
		sort(all(d),cmpX);
		d.erase(unique(all(d)),d.end()); 
	}
	void dfs(int v){
		for(E e:g[v])dfs(e.d); 
		if(g[v].empty())a[v].pb((S){0,0}); 
		else{
			assert(g[v].size()==2);
			E e1=g[v][0],e2=g[v][1];
			if(a[e1.d].size()>a[e2.d].size())swap(e1,e2);
			merge(a[e1.d],e1.w,a[e2.d],e2.w,a[v]);
		}
	}
	bool chk(ll _L){
		L=_L;
		rep(i,1,n)a[i].clear(); 
		dfs(1); 
		return !a[1].empty(); 
	}
}

int main(int argc,char *argv[]){
#ifdef CURIOUSCAT
	freopen("dat.in","r",stdin);
	freopen("my.out","w",stdout);
#endif
	read(n); 	
	rep(i,2,n){
		int p,w; 
		read(p),read(w);
		g[p].pb((E){i,w}); 
	}
	ll l=-1,r=oo;
	while(r-l>1){
		ll mid=(l+r)>>1;
		if(Checker::chk(mid))r=mid;
		else l=mid;
	}
	printf("%lld\n",r); 
	return 0;
}

Measured memory_bytes: 33504
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T, class C> void chmax(T& a, C b) { a > b ? : a = b; }
template<class T, class C> void chmin(T& a, C b) { a < b ? : a = b; }


bool is_reachable(const string& S, int start, int end) {
    REP(i, start - 1, end - 1) {
        if (S[i] == '#' && S[i + 1] == '#') {
            return false;
        }
    }
    return true;
}

bool is_triple(const string& S, int start, int N) {
    REP(i, start - 1, N) {
        if (S[i - 1] == '.' && S[i] == '.' && S[i + 1] == '.') {
            return true;
        }
    }
    return false;
}

int main() {
    int N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    string S;
    cin >> S;
    if (C < D) {
        if (is_reachable(S, A, C) == true && is_reachable(S, B, D) == true) {
            cout << "Yes" << endl;
            return 0;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    else {
        if (is_reachable(S, A, C) == true && is_reachable(S, B, D) == true && is_triple(S, B, D) == true) {
            cout << "Yes" << endl;
            return 0;
        }
        else {
            cout << "No" << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

public class Main {
	public static void main(String[] args) {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    
		String str = "";
		try {
			while ((str = in.readLine()) != null) {
				if (str.equals("0 0")) break;
				String[] ab = str.split(" ");
				
				int[] numbers = new int[2];
				numbers[0] = Integer.parseInt(ab[0]);
				numbers[1] = Integer.parseInt(ab[1]);
				
				Arrays.sort(numbers);
				System.out.println(numbers[0] + " " + numbers[1]);
			}
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

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

int main(){
    int N,K,h;
    int ans = 0;
    cin >> N >> K;
    for (int a = 0; a < N;a++){
        cin >> h;
        if(h>=K){
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1001001001;

int main() {
int A,B;
cin >> A >> B;
if (A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
  cout << "Possible" << endl;
}else cout << "Impossible" << endl;



return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,m;
int s,c;
int a[10];
bool ans;
int main() {
	cin>>n>>m;
	if(n==1&&m==0) {
		cout<<0;
		return 0;
	}
	for(int i=1;i<=5;i++) a[i]=-1;
	for(int i=1;i<=m;i++) {
		cin>>s>>c;
		if(s==1&&c==0&&n!=1) ans=1;
		else if(a[s]==-1) a[s]=c;
		else if(a[s]!=c) ans=1;
	}
	if(ans) {
		cout<<-1;
		return 0;
	}
	if(a[1]==-1) cout<<1;
	else cout<<a[1];
	for(int i=2;i<=n;i++) {
		if(a[i]==-1) cout<<0;
		else cout<<a[i];
	} 
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
typedef long long ll;

int N;
ll calc(vector<pair<int, ll>> &v){
    sort(all(v));
    int sz = v.size();
    ll res = 0;
    priority_queue<ll> pq;
    int idx = sz-1;
    for(int i = N - 1; i >= 0; i--){
        while(idx >= 0 && v[idx].first == i){
            pq.push(v[idx].second);
            idx--;
        }
        if(pq.empty())continue;
        res += pq.top();
        pq.pop();
    }
    return res;
}
void solve(){
    cin >> N;
    vector<pair<int, ll>> lefts, rights;
    ll base = 0;
    rep(i,N){
        int K;
        ll L, R;
        cin >> K >> L >> R;
        K--;
        ll minn = min(L, R);
        base += minn;
        L -= minn;
        R -= minn;
        if(L == R)continue;
        if(L > R)lefts.emplace_back(K, L);
        if(L < R){
            K++;
            rights.emplace_back(N-1-K, R);
        }
    }
    cout << base + calc(lefts) + calc(rights) << endl;
}
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while(t--)solve();
}


Measured memory_bytes: 6608
//includes
#include<iostream>
#include<vector>
#include<set>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<string>
#include<stack>
#include<map>
#include<queue>
#include<iomanip>
#include<numeric>
#include<assert.h>
#include<cstring>
#include<unordered_map>
#include<bitset>

//macros and consts
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(),(a).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define FORE(i,a) for(auto &i : a)
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define accm accumulate
#define Fi first
#define Se second
#define INF 1e9
#define mINF -1e9
#define endl "\n"
#define CONT continue
#define BRK break

//shorter types
using namespace std;
using ll = long long;
using vi = std::vector<int>;
using vc = std::vector<char>;
using vll = std::vector<long long>;
//here begins your code
int N;
vll a;
signed main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  cin >> N;
  a.resize(3*N);
  REP(i,3*N){
    cin >> a[i];
  }


    vector<long long> S(N*2+1, 0);
    priority_queue<long long, vector<long long>, greater<long long> > que1;
    for (int i = 0; i < N; ++i) {
        S[i+1] = S[i] + a[i];
        que1.push(a[i]);
    }
    for (int i = N; i < N*2; ++i) {
        long long mi = que1.top();
        if (a[i] > mi) {
            S[i+1] = S[i] - mi + a[i];
            que1.pop();
            que1.push(a[i]);
        }
        else S[i+1] = S[i];
    }

 
  vector<ll> T(N * 2 + 1 ,0);
  priority_queue<ll> que2;
  for(int i = 0 ; i < N ; i++){
    T[i+1] = T[i] + a[N*3-1-i];
    que2.push(a[N*3-1-i]);
  }
  for(int i = N ; i < N * 2 ; i++){
    ll ma = que2.top();
    if(a[N*3 - i - 1] < ma){
      T[i+1] = T[i] - ma + a[N * 3 - 1 - i];
      que2.pop();
      que2.push(a[N*3 - 1 - i]);
    }
    else{
      T[i+1] = T[i];
    }
  }
 


  ll ret = -(1LL<<60);
  for(int i = N ; i <= N * 2 ; i++){
    ret = max(ret,S[i] - T[N*3 - i]);
  }
  cout << ret << endl;
  
  return 0;
}



Measured memory_bytes: 8052
import java.util.Scanner;

	public class Main {

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

			int num = sc.nextInt();
			String s = sc.next();

			char [] c = new char[s.length()];

			for(int i =0;i<s.length();i++) {
				c[i]=s.charAt(i);
			}

			String start = "A";
			String end = "Z";

			for(int i =0;i<c.length;i++) {
				for(int j=0;j<num;j++){
					if(c[i] == end.charAt(0)){
						c[i] = start.charAt(0);
					}else {
						c[i]++;
					}

				}

			}

			for(int i=0;i<c.length;i++) {
				System.out.print(c[i]);
			}
	}
}




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

const int MAX = 510000;
const int MOD = 998244353;
long long fac[MAX], finv[MAX], inv[MAX];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
    // 前処理
    COMinit();
    ll N,M,K;
    cin >> N >> M >> K;
    // N-1個の境目の中からk個選んで同じ色の組を作る
    ll ans=0;
    ll tmp=M;
    rep(i,N-1-K){
        tmp*=M-1;
        tmp%=MOD;
    }
    ans += COM(N-1,K)*tmp;
    ans %= MOD;
    for(int k=K-1;k>=0;k--){
        tmp *= M-1;
        tmp %= MOD;
        ans += COM(N-1,k)*tmp;
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 15580
#include <bits/stdc++.h>
using namespace std;
int main(){
    long long x, a, b, i, j, f=0;
    cin >> x;
    for(i=-1000;i<=1000;i++){
        for(j=-1000;j<=1000;j++){
            if(x==(i*i*i*i*i)-(j*j*j*j*j)){
                f=1;
                a=i;b=j;
                break;
            }
        }
        if(f==1) break;
    }
    cout << a << " " << b <<endl;
    return 0;
}


Measured memory_bytes: 3592
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

long long const N = 3e5 + 5;
long long cnt[N];
long long pr[N];
vector<long long> f;
long long n;

bool check(long long k, long long t) {
    if (t * k > pr[n])
        return false;
    long long i = lower_bound(f.begin(), f.end(), t) - f.begin();
    if (pr[i] >= (i - (n - k)) * t)
        return true;
    else
        return false;
}

int bin_search(long long k) {
    int l = 0; int r = 3 * N;
    while(l < r) {
        int med = (l + r) / 2;
        if (check(k, med))
            l = med + 1;
        else
            r = med;
    }
    return l - 1;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long cpn;
    cin >> cpn;
    for (int i = 0; i < cpn; ++i) {
        long long x;
        cin >> x;
        ++cnt[x];
    }
    for (auto x : cnt) {
        if (x)
            f.push_back(x);
    }
    sort(f.begin(), f.end());
    n = f.size();
    for (int i = 0; i < f.size(); ++i)
        pr[i + 1] = pr[i] + f[i];
    for (int i = 1; i <= cpn; ++i) {
        if (i > f.size()) {
            cout << 0 << '\n';
            continue;
        }
        cout << bin_search(i) << '\n';
    }
    return false;
}


Measured memory_bytes: 8300
#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;


int main() {
    int n,m;
    cin >> n >> m;
    int arr[100] = {};
    for(int i = 0; i < n; i++) {
        int k;
        cin >> k;
        for(int j = 0; j < k; j++) {
            int a;
            cin >> a;
            arr[a]++;
        }
    }
    int ans = 0;
    for(int i = 0; i < 100; i++) {
        ans += (arr[i]==n)?1:0;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<cstdlib>
using namespace std;

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  if(a + b == c || b + c == a || a + c == b) {
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
                     
#define int             long long
#define ld              long double
#define mp              make_pair
#define ff              first
#define ss              second
#define pb              push_back
#define fo(i,n)         for(i=0;i<n;i++)
#define fo1(i,n)        for(i=1;i<=n;i++)
#define FO(i,k,n)       for(i=k;k<=n?i<=n:i>=n;k<=n?i++:i--)
#define all(c)          c.begin(),c.end()
#define rall(c)         c.rbegin(),c.rend()
#define si              set<int>
#define vi              vector<int>
#define mii             map<int,int>
#define pii             pair<int,int>
#define vpii            vector<pii>
#define vvi             vector<vi>
#define usi             unordered_set<int>
#define umii            unordered_map<int,int>
#define pqmx            priority_queue<int>
#define pqmn            priority_queue<int,vi,greater<int> >
#define sp(x)           cout<<setprecision(x)<<fixed;
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)     __builtin_ctzll(x)
#define in(a,n)         vi a(n);fo(i,n)cin>>a[i];
#define in1(a,n)        vi a(n+1);fo1(i,n)cin>>a[i];
#define w(t)            int t;cin>>t;while(t--)
#define gcd             __gcd
#define lcm(x,y)        x*(y/gcd(x,y))
#define endl            '\n'
#define PI              3.14159265358979323846
const int inf =         1e18;
const int mod =         1e9+7;
void __p(int x) {cout<<x;}
void __p(int32_t x){cout<<x;}
void __p(float x){cout<<x;}
void __p(double x){cout<<x;}
void __p(ld x) {cout<<x;}
void __p(char x){cout <<'\''<<x<<'\'';}
void __p(const char *x){cout <<'\"' <<x<<'\"';}
void __p(const string &x) {cout<<'\"'<<x<<'\"';}
void __p(bool x) {cout<<(x?"true":"false");}
void _p() {cout << "]\n";}
template<typename T,typename V>     void __p(const pair<T,V> &x) {cout<<'{';__p(x.first);cout<<',';__p(x.second);cout<<'}';}
template<typename T>                void __p(const T &x) {int f = 0; cout << '{'; for (auto &i: x) cout << (f++ ? "," : ""), __p(i); cout << "}";}
template <typename T,typename... V> void _p(T t, V... v) {__p(t);if(sizeof...(v))cout<<", ";_p(v...);}
int po(int x,int p,int m = inf) {int ans=1;x%=m;while(p>0){if(p&1)ans=(ans*x)%m;p=p>>1;x=(x*x)%m;}return ans;}
int inv(int x,int m=mod){return po(x,m-2,m)%m;}
#ifndef ONLINE_JUDGE
#define dbg(x...) cout<<"["<<#x<<"]=[";_p(x)
#else 
#define dbg(x...)
#endif
//=================================================================================




const int N=1e6+6;
int n,m,k,x,y,z,a,b,c,d,i,j,l,r;








void sol()
{   
    cin>>n;
    
    a=n%10;
    if(a==2 ||a==4 || a==5 ||a==7 ||a==9)cout<<"hon";
    else if(a==3)cout<<"bon";
    else cout<<"pon";
    
    
    
    //cout<<  <<endl;
}





int32_t main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //sp(10);
    // w(t)
    sol();
    return 0;
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define N 25000000
#define pb push_back
int a[2][3],dp[N+1];
vector<int> le,gr;
signed main(){
	int n,i,j;
	scanf("%lld%lld%lld%lld%lld%lld%lld",&n,a[0],a[0]+1,a[0]+2,a[1],a[1]+1,a[1]+2);
	for(i=0;i<3;i++)a[0][i]<a[1][i]?le.pb(i):gr.pb(i);
	if(le.size()==3){
		for(i=0;i<3;i++)for(j=a[0][i];j<=n;j++)
			dp[j]=max(dp[j],dp[j-a[0][i]]+a[1][i]-a[0][i]);
		dp[n]+=n;
	}
	else if(le.size()==2){
		for(i=0;i<2;i++)for(j=a[0][le[i]];j<=n;j++)
			dp[j]=max(dp[j],dp[j-a[0][le[i]]]+a[1][le[i]]-a[0][le[i]]);
		dp[n]+=n;
		dp[n]+=dp[n]/a[1][gr[0]]*(a[0][gr[0]]-a[1][gr[0]]);
	}
	else if(le.size()==1){
		n+=n/a[0][le[0]]*(a[1][le[0]]-a[0][le[0]]);
		for(i=0;i<2;i++)for(j=a[1][gr[i]];j<=n;j++)
			dp[j]=max(dp[j],dp[j-a[1][gr[i]]]+a[0][gr[i]]-a[1][gr[i]]);
		dp[n]+=n;
	}
	else{
		for(i=0;i<3;i++)for(j=a[1][i];j<=n;j++)
			dp[j]=max(dp[j],dp[j-a[1][i]]+a[0][i]-a[1][i]);
		dp[n]+=n;
	}
	printf("%lld\n",dp[n]);
	return 0;
}
/*1
23
1 1 1
2 1 1
*/

Measured memory_bytes: 194816
in1 = input().split()
in1num = [int(x) for x in in1]
N = in1num[0]
K = in1num[1]
#print(N, K)

#while abs(N-K) < N:
#  N = abs(N-K)
#print(N)

q, mod = divmod(N, K)
#print(q, mod)
if mod == 0:
  print(0)
else:
  if K - mod < mod:
    print(K-mod)
  else:
    print(mod)

Measured memory_bytes: 2940
let rev_iter (f : int -> unit) (a : int array) =
  let rec doit i =
    if i >= 0 then (f a.(i); doit (i - 1))
  in
  doit (Array.length a - 1)

let counting_sort a b k =
  let c = Array.make (k + 1) 0 in
  Array.iter (fun e -> c.(e) <- c.(e) + 1) a;
  Array.iteri (fun i _ -> if i <> 0 then c.(i) <- c.(i) + c.(i - 1)) c;
  rev_iter (fun e -> b.(c.(e) - 1) <- e; c.(e) <- c.(e) - 1) a

let () =
  let n = read_int () in
  let a = Array.init n (fun _ -> Scanf.scanf "%d " (fun e -> e)) in
  let b = Array.make n 0 in
  counting_sort a b 10000;
  Array.iteri (fun i e -> if i <> 0 then print_string " "; print_int e) b;
  print_newline ()

Measured memory_bytes: 36176
#![allow(non_snake_case,unused_imports)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let _N = iter.next().unwrap().parse::<usize>().unwrap();
    let M = iter.next().unwrap().parse::<usize>().unwrap();
    let mut AB:Vec<_> =
            (0..M)
            .map(|_| (iter.next().unwrap().parse::<usize>().unwrap(),
                      iter.next().unwrap().parse::<usize>().unwrap()) )
            .collect();
    AB.sort_by(|x,y| x.1.cmp(&y.1));
    let mut ans = 0;
    let mut br = 0;
    for &(a,b) in &AB{
        if a < br{ continue;}
        if b > br{
            ans += 1;
            br = b;
        }
    }
    println!("{}",ans);

}

Measured memory_bytes: 8444
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,a,b) for(int i=(a),_end_=(b);i<=_end_;i++)
#define DREP(i,a,b) for(int i=(a),_end_=(b);i>=_end_;i--)
#define EREP(i,u) for(int i=start[u];i;i=e[i].next)
#define fi first
#define se second
#define mkr(a,b) make_pair(a,b)
#define SZ(A) ((int)A.size())
template<class T>inline void chkmin(T &a,T b){ if(a>b)a=b;}
template<class T>inline void chkmax(T &a,T b){ if(a<b)a=b;}
inline int read()
{
	int s=0,f=1;char ch=getchar();
	while(!isdigit(ch) && ch!='-')ch=getchar();
	if(ch=='-')ch=getchar(),f=-1;
	while(isdigit(ch))s=s*10+ch-'0',ch=getchar();
	return ~f?s:-s;
}

const int maxn=(1<<14)+20;
const int mod=998244353;
const int MAX=1<<14;

inline int power(int a,int b)
{
	int ans=1;
	while(b)
	{
		if(b&1)ans=(ll)ans*a%mod;
		b>>=1;
		a=(ll)a*a%mod;
	}
	return ans;
}

int jc[maxn],jcn[maxn],inv[maxn];
int W[maxn];

int n,m;

inline void prepare()
{
	jc[0]=jc[1]=jcn[0]=jcn[1]=inv[1]=1;
	REP(i,2,MAX)jc[i]=(ll)i*jc[i-1]%mod,inv[i]=(ll)(mod-mod/i)*inv[mod%i]%mod,jcn[i]=(ll)jcn[i-1]*inv[i]%mod;
	W[0]=1; W[1]=power(3,(mod-1)/MAX);
	REP(i,2,MAX-1)W[i]=(ll)W[i-1]*W[1]%mod;
}

inline int C(int n,int m){ if(n<m || m<0)return 0; return 1ll*jc[n]*jcn[m]%mod*jcn[n-m]%mod;}

inline void FFT(int *p,int n,int op)
{
	static int rev[maxn];
	int l=0; while(1<<l<n)l++;
	REP(i,1,n-1)rev[i]=(rev[i>>1]>>1)|((i&1)<<l-1);
	REP(i,1,n-1)if(i<rev[i])swap(p[i],p[rev[i]]);
	for(int i=1;i<n;i<<=1)
		for(int j=0,w=MAX/(i<<1);j<n;j+=i<<1)
			for(int k=0;k<i;k++)
			{
				int x=p[j+k],y=(ll)W[w*k]*p[i+j+k]%mod;
				p[j+k]=(x+y)%mod;
				p[i+j+k]=(x-y+mod)%mod;
			}
	if(op==-1)
	{
		REP(i,0,n-1)p[i]=(ll)p[i]*inv[n]%mod;
		reverse(p+1,p+n);
	}
}

inline void debug()
{
	int A[8]={1,2,3,4,5,0,0,0},B[8]={2,3,4,5,6,0,0,0},C[8];
	FFT(A,8,1); FFT(B,8,1);
	REP(i,0,7)C[i]=(ll)A[i]*B[i]%mod;
	FFT(C,8,-1);
	REP(i,0,7)cerr<<C[i]<<" "; cerr<<endl;
}

inline void init()
{
	n=read();m=read();
}

int dp[320][maxn];

inline void doing()
{
	dp[0][0]=1;
	int N=1;
	while(N<=(2*n))N<<=1;
	REP(i,1,m)
	{
		static int A[maxn],B[maxn];
		memset(A,0,sizeof(int)*N); memset(B,0,sizeof(int)*N);
		REP(j,0,n)A[j]=(ll)dp[i-1][j]*jcn[j]%mod;
		REP(j,1,n)B[j]=jcn[j+2];
		FFT(A,N,1); FFT(B,N,1);
		REP(j,0,N-1)A[j]=(ll)A[j]*B[j]%mod;
		FFT(A,N,-1);
		REP(j,0,n)dp[i][j]=((ll)A[j]*jc[j+2]+(ll)dp[i-1][j]*(C(j+1,2)+1))%mod;
	}
	int ans=0;
	REP(j,0,n)ans=(ans+(ll)dp[m][j]*C(n,j))%mod;
	printf("%d\n",ans);
}

int main()
{
	prepare();
	debug();
	init();
	doing();
	return 0;
}


Measured memory_bytes: 14080
import java.util.Scanner;

/**
 *
 */

/**
 * @author bluen
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc=new Scanner(System.in);
		int A=sc.nextInt();
		int B=sc.nextInt();

		sc.close();

		if(A==B) {
			System.out.println(A+B);
		}else if(A>B) {
			System.out.println(A+(A-1));
		}else if(A<B) {
			System.out.println(B+(B-1));
		}

	}
}

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

#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false

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

int main() {

	ll n, a;
	cin >> n >> a;

	ll dp[n+1][50*n+1] = {0};
	dp[0][0] = 1;

	rep(k, n){
		ll x;
		cin >> x;

		for(int i = n; i > 0; i--){
			for(int j = x; j < 50*n+1; j++){
				dp[i][j] += dp[i-1][j-x];
			}
		}
	}

	ll ans = 0;
	REP(i, 1, n+1){
		ans += dp[i][i*a];
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1280
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
#include<stack>
#include<queue>
#include<list>
using namespace std;
long long int inf = 1e18;

int main() {
  int n, m;
  cin >> n >> m;

  long long int ans = (n-m) * 100 + m * 1900;
  for(int i=0; i<m; i++){
    ans *= 2;
  }
  cout << ans << endl;
  return 0;
}




//


Measured memory_bytes: 256
import sys

s=str(input())
ans=0
tmp=0
for i in range(len(s)):
    if s[i]=='A' or  s[i]=='G' or s[i]=='C' or  s[i]=='T':
        tmp+=1
        ans=max(ans,tmp)
    else:
        tmp=0

print(ans)

Measured memory_bytes: 61916
#include<bits/stdc++.h>
using namespace std ;
#define ll long long
#define ld long double
#define ff first
#define ss second
const ll mod =  1e9 + 7 ;
ll multiply(ll a, ll b ){ return ((a % mod) * (b % mod)) % mod; }
ll add(ll a, ll b) {     return ((a % mod) + (b % mod)) % mod; }
ll sub(ll a, ll b) { return ((a%mod) - (b % mod)+ mod) % mod ; }
////////////////////////////////////////////////////////////////
ll maxProductSubarrayOfSizeK(vector < ll >  A, int n, int k)
{
    sort(A.begin(), A.end());
    ll product = 1;
    if (A[n - 1] == 0 && (k & 1))
        return 0;
    if (A[n - 1] <= 0 && (k & 1)) {
        for (int i = n - 1; i >= n - k; i--)
            product = multiply(product,A[i]);
        return product;
    }
    int i = 0;
    int j = n - 1;
    if (k & 1) {
        product = multiply(product,A[j]);
        j--;
        k--;
    }
    k >>= 1;
    for (int itr = 0; itr < k; itr++) {
        ll left_product =A[i]*A[i + 1];
        ll right_product = A[j]*A[j - 1];
        if (left_product > right_product) {
            product = multiply(product,left_product);
            i += 2;
        }
        else {
            product = multiply(product,right_product);
            j -= 2;
        }
    }
    return product;
}
///////////////////////////////////////////////////////////////
void solve(){
    int n , k ;
    cin >> n >> k ;
    vector < ll > a(n) ;
    for( int i = 0 ; i < n ; i++) cin >> a[i] ;
    cout << ((maxProductSubarrayOfSizeK(a,n,k)+mod)%mod+mod)%mod << " " ;
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int t = 1 ;
    //cin >> t ;
    while(t--){
        solve( );
    }
}


Measured memory_bytes: 6376
#include <iostream>
#include <string>
using namespace std;
 //Compiler version g++ 6.3.0

 int main()
 {
 	bool ans=true;
 	string s;
 	char a,b;
 	int x,y;
 	cin >> a>>b>>s;
 	if(a=='1')
 	x=1;
 	else if(a=='2')
 	x=2;
 	else if (a=='3')
 	x=3;
 	else if(a=='4')
 	x=4;
 	else if(a=='5')
 	x=5;
 	if(b=='1')
 	y=1;
 	else if(b=='2')
 	y=2;
 	else if (b=='3')
 	y=3;
 	else if(b=='4')
 	y=4;
 	else if(b=='5')
 	y=5;
 	for (int i = 0; i < x; i++){
 		if(s[i]=='-'){
 			ans=false;
 		}
 	if(s[x]!='-'){
 		ans=false;
 		}
 		for (int i = 0; i < y; i++){
 			if(s[x+i+1]=='-'){
 				ans=false;
 			}
 		}
 	}
 	if(ans)
 	cout << "Yes" << endl;
 	else
 	cout << "No" << endl;
 }

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

using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define MIN(a,b) ((a)>(b)? (b): (a))
#define MAX(a,b) ((a)<(b)? (b): (a))

const long long INF = 1LL << 60;

typedef unsigned long long ll;

const long long MOD = 1000000000 + 7;

//For DP
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;
}

//Union-Find tree
struct UnionFind{
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

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

    int root(int x) { // データxが属する木の根を再帰で得る : root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }
    
    void unite(int x, int y) { //xとyの木を併合
        int rx = root(x); //xの木の根をrx
        int ry = root(y); //yの木の根をyx
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)ときはそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時 : xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};



int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    cout << MAX(a*b,c*d) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
  int h,a;
  cin >> h >> a;
  if(h%a==0){
      cout << h/a << endl;
  }else{
      cout << h/a+1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
// C - Forbidden List
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
#define rep(i,n) for(int i=0;i<(int)(n);++i)

int main(){
	int x, n; cin>>x>>n;
	vi P(n); rep(i, n) cin>>P[i];
	int inf = 1e9, ans = inf;
	rep(d, 100){ // [0,100)
		int min_x = x - d, max_x = x + d;
		bool min_ok = true, max_ok = true;
		for(auto p:P){
			if(min_x == p) min_ok = false;
			if(max_x == p) max_ok = false;
		}
		if(min_ok && abs(ans - x) > abs(min_x - x)) ans = min_x;
		if(max_ok && abs(ans - x) > abs(max_x - x)) ans = max_x;
	}
	if(ans == inf) ans = x;
	cout<< ans <<endl;
}


Measured memory_bytes: 3612
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var n = o.a();
  var l = o.l();
  var a = Math.max(...l);
  var b = l.reduce((a,b)=>a+b) - a;
  return b - a > 0 ? "Yes" : "No";
}

Measured memory_bytes: 9420
#include <iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<limits>
#include<string.h>
#include<vector>
#include<stack>
#include<queue>
using namespace std;

int main()
{
    string s;
    cin>>s;
    int a=0;
    int b;
    string s1;
    for (int i = 0; i < s.size(); i++)
    {
        s1=s[i];
        b=atoi(s1.c_str());
        a+=b;
        a=a%9;
    }
    if (a==0)
    {
        cout<<"Yes"<<endl;
    }else
    {
        cout<<"No"<<endl;
    }
    
    
    

    return 0;
}

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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n,sz;
    cin >> n >> sz;
    vector<ll> dp(sz+1,0);
    for(int i=0;i<n;i++)
    {
        int w,v;
        cin >> w >> v;
        for(int j=sz-w;j>=0;j--) dp[j+w]=max(dp[j+w],dp[j]+v);
    }
    ll res=0;
    for(int i=0;i<=sz;i++) res=max(res,dp[i]);
    cout << res << "\n";
    return 0;
}


Measured memory_bytes: 1024
class Dice:
    def __init__(self):
        self.u = 1
        self.w = 2
        self.s = 3
        self.e = 4
        self.n = 5
        self.d = 6
        self.dic = {"W": 0, "S": 1, "E": 2, "N": 3}

    def __init__(self, u, w, s, e, n, d):
        self.u = u
        self.w = w
        self.s = s
        self.e = e
        self.n = n
        self.d = d
        self.dic = {"W": 0, "S": 1, "E": 2, "N": 3}

    def rot(self, way):
        if isinstance(way, str):
            way = self.dic[way]

        if way == 0:
            c = self.u
            self.u = self.e
            self.e = self.d
            self.d = self.w
            self.w = c
        elif way == 1:
            c = self.u
            self.u = self.n
            self.n = self.d
            self.d = self.s
            self.s = c
        elif way == 2:
            c = self.u
            self.u = self.w
            self.w = self.d
            self.d = self.e
            self.e = c
        else:
            c = self.u
            self.u = self.s
            self.s = self.d
            self.d = self.n
            self.n = c


u, s, e, w, n, d = map(int, input().split())
dice = Dice(u, w, s, e, n, d)
st = input()
for c in st:
    dice.rot(c)
print(dice.u)



Measured memory_bytes: 5608
#include <iostream>
#include <vector>

using namespace std;
typedef vector<int> vi;
typedef pair<int,int> ii;
#define REP(i,n) for (int i = 0; i < n; ++i)
#define FORE(x,xs) for (auto x : xs)
#define MP make_pair

const int MAX = 2e5+10;

int N;
vi edge[MAX];
bool used[MAX];
int result[MAX];

ii depth(int n) {
    int d = 0;
    int x = n;
    FORE (e, edge[n]) if (!used[e]) {
        used[e] = true;
        ii res = depth(e);
        if (res.second > d) {
            d = res.second;
            x = res.first;
        }
    }
    return MP(x,d+1);
}

int dfs(int x) { // x個残っている時に勝てるかどうか
    if (result[x] != -1) return result[x];
    int r = dfs(x-2) & dfs(x-1);
    return result[x] = 1-r;
}

int main() {
    cin >> N;
    REP (i, N-1) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        edge[a].push_back(b);
        edge[b].push_back(a);
    }
    REP (i, N+3) used[i] = false;
    used[0] = true;
    int n1 = depth(0).first;
    REP (i, N+3) used[i] = false;
    used[n1] = true;
    int diam = depth(n1).second;
    
    if (diam%3 != 2) cout << "First" << endl;
    else cout << "Second" << endl;
}

Measured memory_bytes: 20736
N,W = map(int,input().split())
dp = [[0 for i in range(W+1)] for j in range(N+1)]

for i in range(1,(N+1)):
    w, v = map(int, input().split())
    for j in range(1,W+1):

        if j-w<0:
            dp[i][j] = max(dp[i-1][j],dp[i][j-1])
        else:
            dp[i][j] = max(dp[i-1][j-w]+v,dp[i-1][j])

print(max(max(dp)))

Measured memory_bytes: 173448
#include<iostream>
#include<vector>
#include<queue>
#include<algorithm>
#include<map>
#include<string>
#include<set>

const long long int MOD=1e9+7;

using namespace std;

int main(){
    int n, a[29], b[29], c[29], sm=0;
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a[i];
        a[i]--;
    }
    for(int i=0;i<n;i++){
        cin >> b[i];
        sm+=b[i];
    }
    for(int i=0;i<n-1;i++){
        cin >> c[i];
    }
    int prev=a[0];
    for(int i=1;i<n;i++){
        if(a[i]-1==prev){
            sm+=c[prev];
        }
        prev=a[i];
    }
    cout << sm << endl;
}



Measured memory_bytes: 256
import collections
import math

n, p = [int(i) for i in input().split()]
d = collections.defaultdict(lambda: 0)

def bunkai(q):
	if q == 1:
		return 0
	for i in range(2, math.ceil(math.sqrt(p))):
		if q % i == 0:
			d[i] += 1
			return bunkai(q//i)

if n == 1 or p == 1:
	print(p)
else:
	bunkai(p)
	ans = 1

	for j in d.keys():
		k = d[j]
		if k // n >= 1:
			ans *= j**(k//n)
	print(ans)

Measured memory_bytes: 3316
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder
{
	public class ABC
	{
		static readonly int mod = 1000000007;  // 10^9+7

		static void Main(string[] args)
		{
			Console.SetOut(new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false });


			//int n = int.Parse(Console.ReadLine());
			string s = Console.ReadLine();
			//long x = long.Parse(Console.ReadLine());
			//int[] vs = Console.ReadLine().Split().Select(int.Parse).ToArray();
			//long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
			char c = Convert.ToChar(s[0]);
			c++;
			Console.WriteLine(c.ToString());


			Console.Out.Flush();
		}
	}
}


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

int main()
{
    string str, w;
    int q, i, j, a, b;
    char order[7];

    cin >> str;
    cin >> q;

    for(i = 0; i < q; i++){
        cin >> order;
        cin >> a >> b;

        if(order[2] == 'i'){
            cout << str.substr(a, b - a + 1) << endl;

        }else if(order[2] == 'v'){
            w = str.substr(a, b - a + 1);
            for(j = 0; j < b - a + 1; j++){
                str[a + j] = w[b - a - j];
            }

        }else{
            cin >> w;
            for(j = 0; str[j]; j++);
            str = str.substr(0, a) + w + str.substr(b + 1, j - b - 1);
        }
    }

    return 0;
}

Measured memory_bytes: 1216
n=int(input())
*l,=map(int,input().split())
c=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            L=[l[i],l[j],l[k]]
            if max(L)<sum(L)-max(L) and len(L)==len(set(L)):
                c+=1
print(c)

Measured memory_bytes: 9188
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;
template <class T>
inline void chmin(T &a, const T &b) { a = min(a, b); }
template <class T>
inline void chmax(T &a, const T &b) { a = max(a, b); }
template <class T>
inline bool kbit(const T &x, const int &k) { return ((x >> k) & 1LL); }
inline int popcount(const int &n) { return __builtin_popcount(n); }
inline ll popcountll(const ll &n) { return __builtin_popcountll(n); }
inline ll mask(const ll &k) { return (1LL << k) - 1LL; }
template <class T>
void zip(V<T> &v) {
    sort(all(v));
    v.erase(unique(all(v)), v.end());
}
template <class T>
int lwb(V<T> &v, const T &x) { return lower_bound(all(v), x) - v.begin(); }
template <class T>
int upb(V<T> &v, const T &x) { return upper_bound(all(v), x) - v.begin(); }
void dump() {
    cerr << '\n';
}
template <class Head, class... Tail>
void dump(Head &&head, Tail &&... tail) {
    cerr << head << (sizeof...(Tail) == 0 ? " " : ", ");
    dump(std::move(tail)...);
}
template <class T>
void print(const vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cout << v[i] << (i + 1 == v.size() ? '\n' : ' ');
}
template <class T>
void read(vector<T> &v) {
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}
constexpr char sp = ' ', newl = '\n';
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
//////////////////////////////////////////////INSERT ABOVE HERE
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s, t;
    cin >> s >> t;
    int res = INF;
    for (int i = 0; i + t.length() <= s.length(); i++) {
        int co = 0;
        for (int j = 0; j < t.length(); j++) {
            co += t[j] != s[i + j];
        }
        chmin(res, co);
    }
    cout << res << newl;
}


Measured memory_bytes: 3664
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int r, g, b, n, cnt=0;

	cin>> r >> g >> b >> n;

	for(int i=0;i<=n;i++){
		for(int j=0;j<=n;j++){
			if(i*r+j*g<=n && (n-(i*r+j*g))%b==0){
				cnt++;
				//cout<< r << " " << g << " " << b << "  " << i << " " << j << endl;
				//break;
			}
		}
	}

	cout<< cnt << endl;


}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        if (n == 2)
        {
            Console.WriteLine(-1);
            return;
        }
        if (n == 4)
        {
            Console.WriteLine(
@"
aacd
bbcd
cdaa
cdbb
");
            return;
        }
        
        var res = Enumerable.Range(0, n).Select(_ => Enumerable.Repeat('.', n).ToArray()).ToArray();
        res[1][0] = 'c';
        res[2][0] = 'c';
        res[n - 1][1] = 'c';
        res[n - 1][2] = 'c';
        res[n - 2][n - 1] = 'c';
        res[n - 3][n - 1] = 'c';
        res[0][n - 2] = 'c';
        res[0][n - 3] = 'c';

        res[0][0] = 'a';
        res[0][1] = 'a';
        res[0][n - 1] = 'b';
        res[1][n - 1] = 'b';
        res[n - 1][n - 1] = 'a';
        res[n - 1][n - 2] = 'a';
        res[n - 1][0] = 'b';
        res[n - 2][0] = 'b';

        char c1 = 'd';
        char c2 = 'e';
        for (int i = 1; i < n - 3; i++)
        {
            res[i][i + 1] = c1;
            res[i][i + 2] = c1;
            res[i + 1][i] = c2;
            res[i + 2][i] = c2;
            var tmp = c1; c1 = c2; c2 = tmp;
        }
        Console.WriteLine(string.Join("\n", res.Select(x => string.Join("", x))));
    }
}


Measured memory_bytes: 26560
import sys

n = int(input())
a = list(map(int, input().split()))
cur = 1
for x in a:
    if ( x == 0 ):
        print(0)
        exit()

for x in a:
    cur = cur * x
    if ( cur > 1000000000000000000 ):
        print(-1)
        exit()
print(cur)


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

using namespace std;

int main(){
	
	int n, ans = 0;
	
	cin >> n;
	
	int a[n+1];
	
	for (int i = 0; i < n; i++){
		
		cin >> a[i];
		
	}
	
	sort(a, a+n);
	
	for (int i = 0; i < n; i++){
		if (a[i] == a[i+1]){
			ans++;
		}
	}
	
	if (ans > 0){
		cout << "NO";
	} else {
		cout << "YES";
	}
	
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <random>
#include <complex>
#include <assert.h>

#include <atcoder/dsu.hpp>
#include <atcoder/fenwicktree.hpp>
#include <atcoder/segtree.hpp>
#include <atcoder/lazysegtree.hpp>
#include <atcoder/maxflow.hpp>

using namespace std;
using namespace atcoder;

////////////////	型名など
typedef long long ll;
#define endl '\n'

////////////////	各種定数
const ll INF = 1LL << 60;
const double EPS = 1e-12;

////////////////	便利なテンプレート関数
template<typename T>
inline bool chmin(T& x, T a) {
	if (x >= a) { x = a; return true; }
	return false;
}

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

////////////////	UnionFind
#define UnionFind dsu

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

	int N, M; cin >> N >> M;
	vector<string> S(N);
	for (int i = 0; i < N; i++) {
		cin >> S[i];
	}

	mf_graph<int> G(N * M + 2);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			if ((i + j) % 2 == 0) {
				G.add_edge(N * M, i * M + j, 1);
			}
			else {
				G.add_edge(i * M + j, N * M + 1, 1);
			}
		}
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M - 1; j++) {
			if (S[i][j] == '#' || S[i][j + 1] == '#') { continue; }
			if ((i + j) % 2 == 0) {
				G.add_edge(i * M + j, i * M + (j + 1), 1);
			}
			else {
				G.add_edge(i * M + (j + 1), i * M + j, 1);
			}
		}
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < M; j++) {
			if (S[i][j] == '#' || S[i + 1][j] == '#') { continue; }
			if ((i + j) % 2 == 0) {
				G.add_edge(i * M + j, (i + 1) * M + j, 1);
			}
			else {
				G.add_edge((i + 1) * M + j, i * M + j, 1);

			}
		}
	}

	cout << G.flow(N * M, N * M + 1) << endl;

	auto e = G.edges();

	for (int i = 0; i < e.size(); i++) {
		if (e[i].flow == 1 && e[i].from < N * M && e[i].to < N * M) {
			int n0 = e[i].from / M, m0 = e[i].from % M;
			int n1 = e[i].to / M, m1 = e[i].to % M;
			if (n0 < n1) { S[n0][m0] = 'v', S[n1][m1] = '^'; }
			if (n0 > n1) { S[n0][m0] = '^', S[n1][m1] = 'v'; }
			if (m0 < m1) { S[n0][m0] = '>', S[n1][m1] = '<'; }
			if (m0 > m1) { S[n0][m0] = '<', S[n1][m1] = '>'; }
		}
	}

	for (int i = 0; i < N; i++) {
		cout << S[i] << endl;;
	}

	return 0;
}

Measured memory_bytes: 5556
def main():
    n = int(input())
    a = list(map(int,input().split()))

    ans = 0
    from collections import Counter
    cnt = Counter(a)
    lim = max(a) + 1
    tmp = [0] * (lim)
    # set_a = list(set(a))
    # set_a.sort()
    a.sort()

    for aa in a:
        if tmp[aa] == 0:
            for j in range(aa,lim,aa):

                tmp[j] = 1

            if cnt[aa] == 1:
                # print(aa, ans)
                ans += 1




    print(ans)

if __name__=='__main__':
    main()


Measured memory_bytes: 38564