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

#define sz(x) int(x.size())
#define pii pair<int, int>
#define Task "abc"
#define For(i, a, b) for(int i = (a), _b = (b); i <= b; ++i)
#define Debug(X) cout << #X << " = " << X << '\n'
#define All(x) (x).begin(), (x).end()
#define mp make_pair

typedef unsigned long long ull;
typedef long long ll;

const int maxn = 1e4 + 10;
const int inf = 0x3f3f3f3f;
const ll mod = 1e9 + 7;

ll Pow(ll a, ll b){
  if (b == 0) return 1;
  ll tmp = Pow(a, b / 2);
  tmp = (tmp * tmp) % mod;
  if (b % 2) return (tmp * a) % mod;
  return tmp;
}

int n;
const int mx = 1e6;
bool f[mx + 10];
int cnt[mx + 10];

void init(){
  for (int i = 2; i <= mx; ++i){
    f[i] = true;
  }
  for (int i = 2; i <= mx; ++i){
    if (f[i] == true)
    for (int j = i * 2; j <= mx; j += i)
      f[j] = false;
  }
}

void Update(int a){
  int x = a;
  for (int i = 2; i * i <= a; ++i){
    int d = 0;
    while (x % i == 0) x /= i, ++d;
    cnt[i] = max(cnt[i], d);
  }
  if (x > 1) cnt[x] = max(cnt[x], 1);
}

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
//  freopen(Task".inp", "r", stdin);  freopen(Task".out", "w", stdout);
  cin >> n;
  ll X = 1;
  vector<ll> a(n);

  for (int i = 0; i < n; ++i){
    cin >> a[i];
    Update(a[i]);
  }
  init();
  for (int div = 2; div <= mx; ++div){
    if (f[div] == false) continue;
    X = X * Pow(div, cnt[div]);
    X %= mod;
  }
  ll ans = 0;
  for (int i = 0; i < n; ++i){
    ans = ans + X * Pow(a[i], mod - 2);
    ans %= mod;
  }
  cout << ans;
}




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

int read() {
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') {
        if (c == '-') f = -1;
        c = getchar();
    }
    while (c >= '0' && c <= '9') {
        x = x * 10 + c - '0';
        c = getchar();
    }
    return x * f;
}

int a[2003], b[2003];
int kn[2000006], km[2000006];
long long mod = 1000000007;
int main() {
    int n = read(), m = read();
    for (int i = 1; i <= n; ++i) {
        a[i] = read();
        if (kn[a[i]]) {
            puts("0");
            return 0;
        }
        kn[a[i]] = 1;
    }
    for (int i = 1; i <= m; ++i) {
        b[i] = read();
        if (km[b[i]]) {
            puts("0");
            return 0;
        }
        km[b[i]] = 1;
    }
    int xn = 0, xm = 0;
    int c = 0;
    long long res = 1;
    for (int i = n * m; i >= 1; --i) {
        if (km[i] && kn[i]) {
            c += xn + xm;
            xn++, xm++;
        } else if (kn[i]) {
            if (!xm) {
                puts("0");
                return 0;
            }
            (res *= (long long)xm) %= mod;
            c += xm - 1;
            xn++;
        } else if (km[i]) {
            if (!xn) {
                puts("0");
                return 0;
            }
            (res *= (long long)xn) %= mod;
            c += xn - 1;
            xm++;
        } else {
            if (!c) {
                puts("0");
                return 0;
            }
            (res *= (long long)c) %= mod;
            c--;
        }
    }
    printf("%lld\n", res);
    return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

#define MAX_N 20
i64 N;
i64 A[MAX_N];
i64 B[MAX_N];
i64 C[MAX_N - 1];

void solve() {
  i64 s = 0;

  REP(i, N) {
    s += B[A[i]];
    if ((i >= 1) && (A[i] == A[i - 1] + 1)) {
      s += C[A[i-1]];
    }
  }

  cout << s << endl;
}

int main() {
  cin >> N;
  REP(i, N) {
    cin >> A[i];
    A[i]--;
  }
  REP(i, N) cin >> B[i];
  REP(i, N-1) cin >> C[i];

  solve();

  return 0;
}

Measured memory_bytes: 256
def solve():
  n=int(input())
  a=list(map(int,input().split()))
  s=input()
  base=[]
  for i in range(n-1,-1,-1):
    v=a[i]
    for x in base:
      v=min(v,v^x)
    if v:
      if s[i]=='0':
        base.append(v)
      else:
        return 1
  return 0

def main():
  t=int(input())
  for _ in range(t):
    print(solve())

if __name__ == '__main__':
  main()

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

int main() {

  int N;
  cin >> N;

  vector<pair<int,int>> TA(N);
  for (int i = 0; i < N; i++) {
    cin >> TA[i].first >> TA[i].second;
  }

  long long t = TA[0].first;
  long long a = TA[0].second;

  for (int i = 1; i < N; i++) {
    long long n = max(ceil((double long) t / TA[i].first), ceil((double long) a / TA[i].second));
    t = n * TA[i].first;
    a = n * TA[i].second;
  }

  cout << t + a << endl;
  
  return 0;

}


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

struct BIT {
	std::vector<int> data;
	int n;
	BIT(int n) {
		this->n = n;
		data.resize(n + 1);
	}
	void add(int i, int val) {
		for (i++; i <= n; i += i & -i) data[i] += val;
	}
	int sum(int i) {
		int res = 0;
		for (; i; i -= i & -i) res += data[i];
		return res;
	}
};

#ifdef _WIN32
#	define getchar_fast _getchar_nolock
#else
#	define getchar_fast getchar_unlocked
#endif
int ri() {
	int r = 0, c, s = 0;
	for (;;) {
		c = getchar_fast();
		if (c == '-') {
			s = 1;
			break;
		}
		if (c <= '9' && c >= '0') {
			r = c - '0';
			break;
		}
	}
	for (;;) {
		c = getchar_fast();
		if (c < '0' || c > '9') break;
		r = r * 10 + c - '0';
	}
	if (s) r = -r;
	return r;
}

void radix_sort(std::pair<int, int> *x, int n) {
	int c[256] = { 0 };
	std::pair<int, int> *r0 = (std::pair<int, int> *) malloc(sizeof(std::pair<int, int>) * n);
	assert(r0);
	for (int i = 0; i < n; i++) c[x[i].first & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) r0[--c[x[i].first & 0xFF]] = x[i];
	memset(c, 0, sizeof(c));
	for (int i = 0; i < n; i++) c[r0[i].first >> 8 & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) x[--c[r0[i].first >> 8 & 0xFF]] = r0[i];
	memset(c, 0, sizeof(c));
	for (int i = 0; i < n; i++) c[x[i].first >> 16 & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) r0[--c[x[i].first >> 16 & 0xFF]] = x[i];
	memset(c, 0, sizeof(c));
	for (int i = 0; i < n; i++) c[r0[i].first >> 24 & 0xFF]++;
	for (int i = 1; i < 256; i++) c[i] += c[i - 1];
	for (int i = n - 1; i >= 0; i--) x[--c[r0[i].first >> 24 & 0xFF]] = r0[i];
	for (int i = 0; i < n; i++) std::cerr << x[i].first << ":" << x[i].second << std::endl;
	// for (int i = 1; i < n; i++) assert(x[i].first >= x[i - 1].first);
	free(r0);
}

int main() {
	int n = ri();
	std::pair<int, int> a[n];
	for (int i = 0; i < n; i++) a[i].first = ri() + 1000000000, a[i].second = ri() + 1000000000;
	
	int b2[n + 3];
	b2[0] = 1;
	for (int i = 1; i <= n + 2; i++) {
		b2[i] = b2[i - 1] + b2[i - 1];
		if (b2[i] >= MOD) b2[i] -= MOD;
	}
	
	std::sort(a, a + n, [](const std::pair<int, int> &a, const std::pair<int, int> &b) { return a.second < b.second; });
	int cnt = 0;
	for (auto &i : a) i.second = cnt++;
	radix_sort(a, n);
	
	BIT tree(cnt);
	int64_t res = 0;
	for (int i = 0; i < n; i++) {
		int v = tree.sum(a[i].second);
		res += b2[v];
		res += b2[i - v];
		res += b2[a[i].second - v];
		res += b2[n - a[i].second - 1 - i + v];
		
		tree.add(a[i].second, 1);
	}
	res += (int64_t) (b2[n] - 1) * n;
	res -= b2[n + 2] - 4;
	std::cout << res % MOD << std::endl;
	
	return 0;
}


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

#define DIV 1000000007
#define BLACK 0
#define WHITE 1

long long N;
long long ban[200005];
string S;

int main(){
	cin >> N;
	cin >> S;

	for(long long i = 0; i < 2*N; i++){
		if(i%2 == 0){
			if(S[i] == 'B'){
				ban[i] =  WHITE;
			}else{
				ban[i] =  BLACK;
			}
		}else{
			if(S[i] == 'B'){
				ban[i] =  BLACK;
			}else{
				ban[i] =  WHITE;
			}
		}
	}
	

	long long left = 0;
	long long ans = 1;

	for(long long i = 0; i < 2*N; i++){
		if(ban[i] == WHITE){
			left++;
		} else {
			ans *= left;
			ans %= DIV;
			left--;
		}
	}

	if(left!=0){
		cout << 0 << endl;
		return 0;
	}

	for(long long i = 1; i <= N; i++){
		ans *= (i);
		ans %= DIV;
	}
	cout << ans << endl;
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
#define rep0(i,b) for(int i=0 ; i< b ;i++)
#define rep1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007
# define M_PI     3.14159265358979323846

using namespace std;


int main()
{
  ll a,b,c,k,res=0;
  cin>>a>>b>>c>>k;


  if(a>=k)
      res = k;
  else if(a+b>=k)
    res = a;
  else if (a+b<k)
    res = a - (k-a-b);

cout<<res;


  return 0 ;
}


Measured memory_bytes: 3540
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <utility>
#include <tuple>
#include <algorithm>
#include <numeric>
#include <cstring>
#include <cmath>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
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; }

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];
  int mn = 1e9, mx = 0;
  rep(i, n) {
    chmin(mn, a[i]);
    chmax(mx, a[i]);
  }
  if (mx-mn > 1) {
    cout << "No" << endl;
    return 0;
  }
  if (mx == mn) {
    if (mx <= n/2 || mx == n-1)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  } else {
    int num1 = 0, num2 = 0;
    rep (i, n) {
      if (a[i] == mn)
        num1++;
      else
        num2++;
    }
    if (mn >= num1 && mx <= num1+num2/2 && num2 >= 2)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 768
A=list(input())
B=list(input())
C=list(input())

nxt="a"
while True:
    if nxt=="a":
        if len(A)==0:
            print("A")
            break
        else:
            nxt=A.pop(0)
    if nxt=="b":
        if len(B)==0:
            print("B")
            break
        else:
            nxt=B.pop(0)
    if nxt=="c":
        if len(C)==0:
            print("C")
            break
        else:
            nxt=C.pop(0)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;

// ユークリッドの互除法
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a; }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }

int main(){
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a[i];
  
  ll ans=a[0];
  rep(i,n-1){
    ans = gcd(ans, a[i+1]);
  }
  
  cout << ans;
  
  return 0;
}

Measured memory_bytes: 1024
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define DB double
#define SG string
#define LL long long
#define Fp(A,B,C,D) for(A=B;A<=C;A+=D)
#define Fm(A,B,C,D) for(A=B;A>=C;A-=D)
#define Clear(A) memset(A,0,sizeof(A))
using namespace std;
const LL Max=1e3+5;
const LL Mod=1e9+7;
const LL Inf=1e18;
LL N,M;
inline LL Read(){
	LL X=0;char CH=getchar();bool F=0;
	while(CH>'9'||CH<'0'){if(CH=='-')F=1;CH=getchar();}
	while(CH>='0'&&CH<='9'){X=(X<<1)+(X<<3)+CH-'0';CH=getchar();}
	return F?-X:X;
}
inline void Write(LL X){
	if(X<0)X=-X,putchar('-');
	if(X>9)Write(X/10);
	putchar(X%10+48);
}
int main(){
	LL I,J,K;
	N=Read(),M=Read();
	if(M<N){
		Write(N-1);
	} else {
		Write(N);
	}
	return 0;
}

Measured memory_bytes: 256
CMAP = {">" => 0, "^" => 1, "<" => 2, "v" => 3}
CMAP.default = -1

DIREC = [[1, 0], [0, -1], [-1, 0], [0, 1]]

while true
  h, w = gets.chomp.split(" ").map{|s| s.to_i}
  break if h == 0 && w == 0

  room = []
  visit = []

  h.times do
    hl = gets.chomp.split("").map{|s| CMAP[s]}

    room.push hl
    visit.push hl.map{false}
  end

  x = 0
  y = 0
  loop = true

  while ! visit[y][x]
    visit[y][x] = true
    d = room[y][x]

    if d < 0
      puts [x, y].join(" ")
      loop = false
      break
    end

    dx, dy = DIREC[d]
    x += dx
    y += dy
  end

  puts "LOOP" if loop
end

Measured memory_bytes: 6208
from math import factorial

n, m = tuple(map(int, input().split()))

comb_n = 0
comb_m = 0

if n > 1:
    comb_n = (factorial(n) // factorial(n - 2)) // factorial(2)

if m > 1:
    comb_m = factorial(m) // factorial(m - 2) // factorial(2)

print(comb_n + comb_m)


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


int main() {
  int n,k; cin >> n >> k;
  int x,y; cin >> x >> y;

  if (n < k) cout << x*n;
  else cout << x*k + y*(n-k);
  cout << endl;
  return 0;

}
  


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

int main() {
	int n;
	cin >> n;
	vector<int> a(n);
	int sum=0;
	for(int i=0;i<n;i++){
		cin >> a[i];
		sum^=a[i];
	}
	for(int i=0;i<n;i++){
		cout << (sum^a[i]) << " ";
	}
	cout << endl;
	return 0;
}

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


int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);


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

    set<int> s;
    rep(i, k) {
        int d;
        cin >> d;
        rep(j, d) {
            int buf;
            cin >> buf;
            s.insert(buf);
        }
    }
    cout << n - s.size() << endl;


    return 0;
}



Measured memory_bytes: 3652
N=int(input())
f=[0 for i in range(10001)]


for x in range(1,101):
    for y in range(1,101):
        for z in range(1,101):
            tmp=x**2+y**2+z**2+x*y+y*z+z*x
            if tmp >10000:
                continue
            f[tmp]+=1

for i in range(1,N+1):
    print(f[i])

Measured memory_bytes: 9236
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <climits>
#include <cmath>
#include <cstring>
#include <forward_list>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

const ll MOD = 1E+09 + 7;
const ll INF = 1E18;
const int MAX_V = 1E+03;

struct edge {
    int from, to;
    ll cost;
};

vector<edge> G[MAX_V];
ll d[MAX_V];

int V, E;

string bellford(int s, int t);

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

    cin >> V >> E;

    for (int i = 0; i < E; i++) {
        int s, t;
        ll c;
        std::cin >> s >> t >> c;
        edge et = { s - 1, t - 1, -c };
        G[s - 1].push_back(et);
    }

    cout << bellford(0, V - 1) << "\n";

    return 0;
}

string bellford(int s, int t)
{
    std::fill(d, d + V, INF);
    d[s] = 0;
    int cnt = 0;
    while (true) {
        bool update = false;
        bool tupdate = false;
        for (int i = 0; i < V; i++) {
            for (int j = 0; j < G[i].size(); j++) {
                edge e = G[i][j];
                if (d[e.from] != INF && d[e.to] > d[e.from] + e.cost) {
                    d[e.to] = d[e.from] + e.cost;
                    update = true;
                    if (e.to == t) {
                        tupdate = true;
                    }
                }
            }
        }
        if (!update)
            break;
        if (cnt >= V - 1) {
            if (tupdate) {
                return "inf";
            } else {
                break;
            }
        }
        cnt++;
    }
    return to_string(-d[t]);
}

Measured memory_bytes: 3820
#include <iostream>
#include <string>
#include <math.h>

using namespace std;

int main()
{
    string N,ans;
    
    cin >> N;
    
   
    if(N[0]==N[1]&&N[1]==N[2]) ans ="Yes";
    
    else if (N[1]==N[2]&&N[2]==N[3]) ans ="Yes";
   
    
    else ans = "No";

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


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int H,W;
  scanf("%d%d\n",&H,&W);
  char s[H+2][W+2];//隣接マスを見るため添字0,maxをピリオドで埋める
  char bin;// \n
  for(int i = 0; i < H + 2; ++i){
	s[i][0] = '.';
	s[i][W + 1] = '.';
  }
  for(int j = 0; j < W + 2; ++j){
	s[0][j] = '.';
	s[H + 1][j] = '.';
  }
  for(int i = 1; i < H + 1; ++i){
	for(int j = 1; j < W + 1; ++j){
	  scanf("%c", &s[i][j]);
	}
    scanf("%c", &bin);
  }
  int flag = 0;
  for(int i = 1; i < H + 1; ++i){
	for(int j = 1; j < W + 1; ++j){
	  if(s[i][j] == '#'){
		if(s[i-1][j]=='.'&&s[i+1][j]=='.'&&s[i][j-1]=='.'&&s[i][j+1]=='.') flag = 1;
	  }
	}
  }
  if(flag == 0) printf("Yes\n");
  else printf("No\n");
  return 0;
}

Measured memory_bytes: 128
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>

namespace adaptor = boost::adaptors;

void solve()
{
    int64_t X;
    std::cin >> X;

    if (X == 1)
    {
        std::cout << 1 << std::endl;
        return;
    }

    int64_t ans = 0;
    for (int64_t b = 2; b <= X; b++)
    {
        for (int64_t p = 2;; p++)
        {
            int64_t tmp = (int64_t)pow(b, p);
            if (tmp > X) break;
            if (tmp > ans) ans = tmp;
        }
    }

    std::cout << ans << std::endl;
}

int main()
{
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    solve();
}


Measured memory_bytes: 4084
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
ll a, b, c;

int main(){
	cin >> a >> b >> c;
	cout << a*b*c/(2*max(a, max(b, c))) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
using namespace std;

int main() {
    cin.tie(0)->sync_with_stdio(false);

    int n; cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    REP(i, n) cin >> s[i] >> t[i];
    string x; cin >> x;

    int index = 0;
    REP(i, n) if (x == s[i]) index = i;

    int sum = 0;
    for (int i = index + 1; i < n; i++)
        sum += t[i];

    cout << sum << '\n';
    return 0;
}

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

using namespace std;

#define MAX 100000

vector<int> vprimes;
bool isPrime[MAX];

void MakePrime()
{
  for(int i =0 ; i < MAX; ++i){
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for(long long i=2; i <MAX;++i){
    if(isPrime[i]){
      for(long long j=2;i*j<MAX;++j){
	isPrime[i*j]=false;
      }
    }
  }
  for(int i = 0; i < MAX; ++i){
    if( isPrime[i] ){
      vprimes.push_back( i );
    }
  }
}

int main()
{
  MakePrime();
  while(true){
    int m,a,b;
    cin >> m >> a >> b;
    if( m == 0 && a == 0 && b == 0 ) break;
    
    double s = double(a)/b;
    long long maxarea = 0;
    int ans_p, ans_q;
    for(int i = 0; i < (int)vprimes.size(); ++i){
      int q = vprimes[i];
      vector<int>::iterator it = lower_bound( vprimes.begin(), vprimes.end(), m/q);
      if( it == vprimes.end() ) continue;
      vector<int>::iterator itt= lower_bound( vprimes.begin(), it, q );
      /*
      if( i < 120 ){
	cout << q << ' ' << m/q << endl;
      }
      */
      if( *itt * q > m ){
	if( itt == vprimes.begin() ) continue;
	--itt;
      }
      int p = *itt;
      
      if( p > q ) swap( p , q );
      if( double(p)/q >= s ){
	if( maxarea < (long long)p * q ){
	  maxarea = (long long)p * q;
	  ans_p = p;
	  ans_q = q;
	}
      }
    }
    
    cout << ans_p << ' ' << ans_q << endl;
  }
  return 0;
}

Measured memory_bytes: 1108
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
using namespace std;
const int maxn = 5010;
const long long oo = 1e18;
int n, p[maxn], m;
long long A, B;
long long dp[maxn][maxn << 1], mx[maxn][maxn << 1];
int main()
{
	std::ios::sync_with_stdio(false);
	cin >> n >> A >> B;
	for(int i = 1; i <= n; i ++)
	{
		int a;
		cin >> a;
		p[a] = i * 2;
	}
	m = n * 2 + 1;
	for(int i = 1; i <= n; i ++)
	{
		mx[i][0] = oo;
		for(int j = 1; j <= m; j ++)
		{
			long long a;
			if(j % 2 == 0)
				a = mx[i - 1][j - 1];
			else
				a = mx[i - 1][j];
			if(j > p[i])
				a += A;
			else if(j < p[i])
				a += B;
			dp[i][j] = a;
			mx[i][j] = min(mx[i][j - 1], dp[i][j]);
			//cout << i << " " << j << " " << dp[i][j] << endl;
		}
	}
	cout << mx[n][m] << endl;
	return 0;
}
/*
5 1 9
3 5 1 4 2 
*/

Measured memory_bytes: 784640
#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""

input:
6
1 2 2 3
2 2 3 4
3 1 5
4 1 6
5 1 6
6 0

output:
1 1 12
2 2 11
3 3 8
4 9 10
5 4 7
6 5 6

"""
import sys

UNVISITED, VISITED_IN_STACK, POPPED_OUT = 0, 1, 2


def dfs(v_init):
    global timer

    # init the first node of overall graph iterations(times >= 1)
    stack = list()
    stack.append(v_init)
    d_time[v_init] += timer
    # init end

    while stack:
        current = stack[-1]
        v_table = adj_table[current]
        visited[current] = VISITED_IN_STACK
        # if adj is None, current's adj(s) have been all visited
        adj = v_table.pop() if v_table else None

        if adj:
            if visited[adj] is UNVISITED:
                visited[adj] = VISITED_IN_STACK
                timer += 1
                d_time[adj] += timer
                stack.append(adj)
        else:
            stack.pop()
            visited[current] = POPPED_OUT
            timer += 1
            f_time[current] += timer

    return None


def dfs_init():
    global timer
    for v in range(v_num):
        if visited[v + 1] == UNVISITED:
            timer += 1
            dfs(v + 1)


if __name__ == '__main__':
    _input = sys.stdin.readlines()
    v_num = int(_input[0])
    vertices = map(lambda x: x.split(), _input[1:])

    visited = [UNVISITED] * (v_num + 1)
    d_time, f_time = ([0] * (v_num + 1) for _ in range(2))
    adj_table = tuple([] for _ in range(v_num + 1))
    for v_info in vertices:
        v_idx, adj_num, *adj_list = map(int, v_info)
        # assert len(adj_list) == adj_num
        adj_table[v_idx].extend(sorted(adj_list, reverse=True))

    timer = 0
    dfs_init()

    for v_idx, time_info in enumerate(zip(d_time[1:], f_time[1:]), 1):
        print(v_idx, *time_info)

Measured memory_bytes: 7776
#include"iostream"
#include"string"
#include"algorithm"
using namespace std;

int a,b,k;

char s[50][50];

int main()
{


	cin >> a >> b;
	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			cin >> s[i][j];
		}
	}

	for (int i = 0; i < a; i++) {
		for (int j = 0; j < b; j++) {
			if (s[i][j] == '#') {
				if (s[i - 1][j] == '.' || i == 0) {
					if (s[i + 1][j] == '.' || i == a - 1) {
						if (s[i][j - 1] == '.' || j == 0) {
							if (s[i][j + 1] == '.' || j == b - 1) {
								cout << "No";
								system("pause");
								return 0;
							}
						}
					}
				}
								
			}
		}
	}
	cout << "Yes";
	system("pause");
	return 0;
}


Measured memory_bytes: 504
n, m, k = map(int, input().split())
mod = 10**9 + 7


def nCr(n, r, MOD=10**9 + 7):
    from functools import reduce
    if r == 0:
        return 1
    num = reduce(lambda x, y: x * y % MOD, range(n, n - r, -1))
    den = reduce(lambda x, y: x * y % MOD, range(1, r + 1))
    return num * pow(den, MOD - 2, MOD) % MOD


ncr = nCr(n * m - 2, k - 2)
ans = 0
for d in range(1, m):
    temp = d * (m - d) * n**2
    temp %= mod
    ans += temp
    ans %= mod
for d in range(1, n):
    temp = d * (n - d) * m**2
    temp %= mod
    ans += temp
    ans %= mod
ans *= ncr
ans %= mod
print(ans)


Measured memory_bytes: 9624
while True:
    try:
        (a, b, e, c, d, f) = map(float, input().split())

        D = a * d - b * c
        x = (d * e - b * f) / D
        y = (a * f - c * e) / D

        if abs(x) < 1e-4:
            x = 0.0
        if abs(y) < 1e-4:
            y = 0.0

        print("{0:.3f} {1:.3f}".format(x, y))

    except EOFError:
        break



Measured memory_bytes: 5584
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
 
int main(){
	int n;
	cin >> n;
	unsigned long long ans = 1;
	int f = 0;
	rep(i, n){
		unsigned long long in;
		cin >> in;
		unsigned long long ans0 = ans;
		unsigned long long in0 = in;
		int ansk = 0;
		int ink = 0;
		ans *= in;
		while(ans0 >= 10){
			ans0 /= 10;
			ansk++;
		}
		while(in0 >= 10){
			in0 /= 10;
			ink++;
		}
		if(ink + ansk > 18){
			f = 1;
			ans = 1;
		}
		if(ink + ansk == 18 && ans0 * in0 > 1){
			f = 1;
			ans = 1;
		}
		//cout << ink << ' '  << ansk << endl;
		
		if(ans > 1000000000000000000){
			f = 1;
			ans = 1;
		}
	}
	if(ans == 0){
		cout << 0 << endl;
	}else if(f == 1){
		cout << -1 << endl;
	}else{
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3632
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_6_B&lang=jp
#include <iostream>
using namespace std;

void swap(int A[],int i,int j){
  int buf = A[j];
  A[j] = A[i];
  A[i] = buf;
}

int partition(int A[], int l, int r){
  const int x = A[r]; //????????¨?????????
  int i = l-1; //??§???????????????????????¨??????????????????-1
  for(int j = l; j < r; j++){
    //j?????????????????£???????????¨??????????????????????????¨????????????
     if (A[j] <= x){
       i += 1;
       //??´??????????????????????????¨???
       swap(A,i,j);
     }
  }
  swap(A,i+1,r);
  return i+1;
}


int main(){
  int n;
  cin >> n;
  int S[n];
  for(int i=0; i<n; i++){
    cin >> S[i];
  }//????????????????????????

  int mark = partition(S,0,n-1);
  for(int i=0; i<mark; i++){
    cout << S[i] << " ";
  }
  cout << "[" << S[mark] << "] ";
  for(int i=mark+1; i<n-1; i++){
    cout << S[i] << " ";
  }
  cout << S[n-1] << endl;
  return 0;
}

Measured memory_bytes: 1556
#include<bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
int main(void)
{
    unsigned long long int n,ans=0,i,temp;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        temp=n/i;
        ans+=((temp*(temp+1))/2)*i;
    }
    cout<<ans;
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define TYPE int
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}

int main(void){
	int r=in(),g=in();
	print(2*g-r);
	return 0;
}

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

struct UnionFind {
    vector<int> d;
    UnionFind(int n=0): d(n,-1) {}
    int find(int x) {
        if (d[x] < 0) return x;
        return d[x] = find(d[x]);
    }
    bool unite(int x, int y) {
        x = find(x); y = find(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return find(x) == find(y);}
    int size(int x) { return -d[find(x)];}
};

int deg[100005];
vector<int> to[100005];

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    UnionFind uf(n);
    rep(i,m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        deg[a]++;
        deg[b]++;
        uf.unite(a,b);
    }
    rep(i,k) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        to[a].push_back(b);
        to[b].push_back(a);
    }
    rep(i,n) {
        int ans = uf.size(i)-1-deg[i];
        for (int u : to[i]) {
            if (uf.same(i,u)) --ans;
        }
        printf("%d%c", ans, i==n-1?'\n':' ');
    }
    return 0;
}

Measured memory_bytes: 6784
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	ll K;
	cin >> N >> K;
	vector<int> A(N);
	for (auto& x : A) { cin >> x; -- x; }
	int pos = 0;
	vector<int> a(N, -1);
	bool flag = true;
	for (int t = 0; K > 0; ++ t) {
		if (flag && a[pos] >= 0) {
			int x = t-a[pos];
			K -= (K-1)/x*x;
			flag = false;
		} else {
			a[pos] = t;
		}
		pos = A[pos];
		-- K;
	}
	cout << pos+1 << endl;
}


Measured memory_bytes: 4852
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<set>
#include<string>
#include<stdio.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < n; i++)
#define repn(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define lint long long

int main(){
    int x,y,z; cin>>x>>y>>z;
    if(x+y+z >= 22) cout<<"bust"<<endl;
    else cout<<"win"<<endl;
}

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

#define pii pair<int, int>
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define sz(v) int(v.size())
#define all(v) v.begin(), v.end()
#define vec vector<int>
#define dead not_bad
#define bad gooood

#define left not_right
#define y1 what

using namespace std;

const int N = (int) 1e5 + 10;
const int M = (int) 1e6 + 10;
const ll LINF = (ll) 1e18;
const int INF = (int) 1e9 + 7;
const int ALPHA = 26;
const int mod = INF + 2;
const double PI = 3.14159265359;
const ld EPS = (ld) 1e-12;

const int nx[4] = {0, 0, -1, 1};
const int ny[4] = {1, -1, 0, 0};

int n;
ll c;
ll a[N], v[N];
ll suff[N], pref[N];

int main() {
  #define fn "saddle"
  #ifdef witch
      freopen("input.txt", "r", stdin);
  //    freopen("output.txt", "w", stdout);
  #else
      //freopen(fn".in", "r", stdin);
      //freopen(fn".out", "w", stdout);
  #endif
  cin >> n >> c;
  a[0] = 0;
  a[n + 1] = c;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> v[i];
  }
  ll cur = 0;
  for (int i = n; i >= 1; i--) {
    cur += v[i];
    suff[i] = max(suff[i + 1], cur - (c - a[i]));
  }
  cur = 0;
  ll ans = 0;
  for (int i = 0; i <= n; i++) {
    cur += v[i];
    if (i)
      pref[i] = pref[i - 1];
    pref[i] = max(pref[i], cur - a[i]);
    ans = max(ans, cur + suff[i + 1] - 2 * a[i]);
    ans = max(ans, cur - a[i]);
  }
  cur = 0;
  for (int i = n; i >= 1; i--) {
    cur += v[i];
    ans = max(ans, cur + pref[i - 1] - 2 * (c - a[i]));
    ans = max(ans, cur - (c - a[i]));
  }
  cout << ans;
  return 0;
}


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

const int INF=0x3f3f3f3f;
const int MN=12;
const int MM=1005;

int dp[MM][(1<<MN)+5];

int main()
{
	int n,m;
	scanf("%d%d",&n,&m);
	int a,b,ci,c;
	int mask=(1<<n)-1;
	memset(dp,INF,sizeof(dp));
	dp[0][0]=0;
	int ans=INF;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a,&b);
		c=0;
		for(int j=0;j<b;j++)
		{
			scanf("%d",&ci);
			c|=1<<(ci-1);
		}
		//cout<<"!!!!!!!! "<<c<<endl;
		for(int j=0;j<=mask;j++)
			dp[i][j]=dp[i-1][j];
		for(int j=0;j<=mask;j++)
		{
			dp[i][j|c]=min(dp[i][j|c],min(dp[i-1][j|c],dp[i-1][j]+a));
			//cout<<"!!!!!!!!!!!!!!!!!!!!!  "<<(j|c)<<" "<<dp[i][j|c]<<endl;
		}
		//cout<<dp[i][1]<<" "<<dp[i][2]<<endl;
		ans=min(ans,dp[i][mask]);
		//cout<<i<<" "<<ans<<endl;
	}
	printf("%d\n",ans>=INF?-1:ans);
	return 0;
}


Measured memory_bytes: 16384
#include <bits/stdc++.h>
using namespace std;
#define gc getchar_unlocked
#define fo(i,n) for(i=0;i<n;i++)
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define ll long long
#define si(x)	scanf("%d",&x)
#define sl(x)	scanf("%lld",&x)
#define ss(s)	scanf("%s",s)
#define pi(x)	printf("%d\n",x)
#define pl(x)	printf("%lld\n",x)
#define ps(s)	printf("%s\n",s)
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pl;
typedef vector<int>		vi;
typedef vector<ll>		vl;
typedef vector<pii>		vpii;
typedef vector<pl>		vpl;
typedef vector<vi>		vvi;
typedef vector<vl>		vvl;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 3e5, M = N;
//=======================

vi g[N];
int a[N];
void fac(ll no, vi &a){
	a.clear();
	while(no){
		a.pb(no%2);
		no /= 2;
	}
	while(a.size() < 60) a.pb(0);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int i,n,j;
	ll A, B;
	cin >> A >> B;
	if(A == B){
		cout << 1 << endl;
		return 0;
	}
	int r = -1, k = -1, cur = -1;
	vi L, R;
	fac(A, L);
	fac(B, R);
	int p = 59;
	while(p>=0 and L[p] == R[p]){
		if(L[p]) L[p] = R[p] = 0, A -= 1LL<<p, B -= 1LL<<p;
		p--;
	}
	fo(i, 60){
		if(L[i] != R[i]) r = i;
		if(R[i]) k = cur, cur = i;
	}
	ll T = 1LL<<r;
	//[A, T-1]
	ll ans = (T-1) - A + 1;
	
	//[T, T+2^(k+1)-1]
	ans += 1LL<<(k+1);
	//[T+A, 2T-1]
	ans += 2*T-1 - (T+A) + 1;
	//If overlap
	ll x = (1LL<<(k+1)) - 1;
	if(A <=  x)
		ans -= x-A+1;
	cout << ans << endl;
	
	return 0;
} 



Measured memory_bytes: 7296
#include <iostream>
#include<math.h>
#include <algorithm>
#include<string>
using namespace std;

int main() {
        int N, M;
        string s[110], t[110];
        int Ans = 0;

        cin >> N;
        for(int i=0; i<N; i++) cin >>s[i];
        cin >> M;
        for(int i=0; i<M; i++) cin >>t[i];

        for(int i=0; i<N; i++){
                int keep = 1;
                for(int j=i+1; j<N; j++){
                        if(s[i]==s[j]) keep++;
                }
                for(int j=0; j<M; j++){
                        if(s[i]==t[j]) keep--;
                }
                Ans = max(Ans,keep);
        }
        cout << Ans << endl;
        return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define pb push_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define LCM(a, b) (a) / __gcd((a), (b)) * (b)
#define CEIL(a, b) (a)/(b)+(((a)%(b))?1:0)
#define ln '\n'

using namespace std;
using LL = long long;
using ldouble = long double;
using P = pair<int, int>;
using LP = pair<LL, LL>;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1e9 + 7;
static const int SIZE = 200005;

const int dx[] = {0, -1, 1, 0};
const int dy[] = {-1, 0, 0, 1};

vector<LL> Div(LL n) {
    vector<LL> ret;
    for(LL i = 1; i * i <= n; ++i) {
        if(n % i == 0) {
            ret.pb(i);
            if(i * i != n) ret.pb(n / i);
        }
    }
    sort(all(ret));
    return ret;
}

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

    int N, K;
    cin >> N >> K;

    vector<int> v(N);
    int imos[SIZE] = {};
    for(int i = 0; i < N; ++i) {
        cin >> v[i];
        imos[max(0, i - v[i])]++;
        imos[min(N, i + v[i] + 1)]--;
    }

    bool ef = false;
    int tmp[SIZE];
    for(int i = 0; i < K && !ef; ++i) {
        int sum = 0;
        for(int j = 0; j < N; ++j) {
            sum += imos[j];
            tmp[j] = v[j];
            v[j] = sum;
        }

        bool f = true;
        for(int j = 0; j < N; ++j) {
            if(v[j] != N) f = false;
            imos[max(0, j - v[j])]++;
            imos[min(N, j + v[j] + 1)]--;
            imos[max(0, j - tmp[j])]--;
            imos[min(N, j + tmp[j] + 1)]++;
        }
        if(f) ef = true;
    }

    for(int i = 0; i < N; ++i) cout << v[i] << " ";
    cout << endl;
    return 0;
}



Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
using namespace std::chrono; 
#define ll long long
#define fo(i,v,e) for(v=i;v<e;v++)
#define rfo(i,v,e) for(v=i;v>e;v--)
#define pb(x) push_back(x)
#define pll pair<ll,ll>
#define pii pair<int,int>
#define fi first 
#define se second
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define vl vector<ll>
#define sz(x) (int)x.size()
#define ull unsigned long long
#define vvi vector<vi>
#define vvl vector<vl>
#define vpi vector<pii>
#define vpl vector<pll>
ll mod = 1000000007;
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x);
#else
#define deb(x...)
#endif
void init()
{
}

void solve()
{
   string s;cin>>s;
   ll n = sz(s)-1;
   if(s[n]=='3')
   {
       cout<<"bon"<<endl;
   }
   else if (s[n]=='0' or  s[n]=='6' or s[n]=='1' or s[n]=='8')
   {
       cout<<"pon"<<endl;
   }
   else
   {
       cout<<"hon"<<endl;
   }
   
   
}
int main()
{
    init();
    #ifndef ONLINE_JUDGE
    // freopen("input.txt","r",stdin);
    // freopen("output.txt","w",stdout);
    #endif
    auto start = high_resolution_clock::now(); 
    int T = 1;
    // cin>>T;
    while(T--)
    {
        solve();
    }
    auto stop = high_resolution_clock::now(); 
    auto duration = duration_cast<milliseconds>(stop - start); 
    #ifndef ONLINE_JUDGE
    // cout << "time taken : "<<duration.count()<<" ms" << endl;
     #endif
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ll long long
#define inf 0x3f3f3f3f
#define fast    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const int N = 3e5+10;
const ll mod =   1e9+7;
int n,k;int arr[N];
int main()
{  fast
cin>>n>>k;
for(int i=0;i<n;i++)
cin>>arr[i];
sort(arr,arr+n);
int sum=0;
for(int i=0;i<k;i++)
sum+=arr[i];
cout<<sum;

}

Measured memory_bytes: 3652
#include<iostream>
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define rrep(i, j) RFOR(i, j, 0, 1)
#define MP make_pair
#define PB push_back
#define INF (int)1e9
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl;

void solve()
{
    int nr,ng,nb;
    cin>>nr>>ng>>nb;
    int r[nr],g[ng],b[nb];
    rep(i,nr)
    cin>>r[i];
    rep(i,ng)
    cin>>g[i];
    rep(i,nb)
    cin>>b[i];
    sort(r,r+nr);
    sort(g,g+ng);
    sort(b,b+nb);
}
void b()
{
    ll b,a,n;
    cin>>a>>b>>n;
    ll x=min(b-1, n);
    cout<<((a*x)/b)-a*(x/b);
            
}
int main() 
{
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
    cout.tie(NULL);
    #ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
	#endif
    b();
    return 0;
    int t;
    cin>>t;
    while(t--)
    b();
}


Measured memory_bytes: 3612
import collections

h,w = map(int, input().split())
cells = []
for i in range(h):
    row = input()
    cells.append([c == '#' for c in row])

blacks = collections.deque()

for i in range(h):
    for j in range(w):
        if cells[i][j]:
            blacks.append((i,j,0))
res = 0
while blacks:
    y,x,c = blacks.popleft()
    for dy,dx in ((-1, 0), (1, 0), (0, -1), (0,1)):
        if 0<=y+dy<h and 0<=x+dx<w and not cells[y+dy][x+dx]:
            cells[y+dy][x+dx] = True
            blacks.append((y+dy, x+dx, c+1))
            res = c+1
print(c)



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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long n, a, b;
  cin >> n >> a >> b;
  long long ans = n / (a + b) * a + min(n % (a + b), a);
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3608
n = int(input())
count = 0

for i in range(1, n + 1):
    if i < 10:
        count += 1
    elif i >= 10 ** 2 and i < 10 ** 3:
        count += 1
    elif i >= 10 ** 4 and i < 10 ** 5:
        count += 1
print(count)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define mid (left + right)/2
using namespace std;
const int MAXN = 100010;
const int INTMAX = 2147483647;
int a[MAXN];
int st[4 * MAXN];
void init(int idx, int left, int right){
	if(left == right) {
		st[idx] = a[left];
		return;
	}
	init(2 * idx, left, mid);
	init(2 * idx + 1, mid + 1, right);
	st[idx] = min(st[2 * idx], st[2 * idx + 1]);
}
void update(int idx, int left, int right, int pos, int val){
	if(left == right){
		st[idx] = val;
		return;
	}
	if(pos > mid) update(2 * idx + 1, mid + 1, right, pos, val);
	else update(2 * idx, left, mid, pos, val);
	st[idx] = min(st[2 * idx], st[2 * idx + 1]);
}
int query(int idx, int left, int right, int l, int r){
	if(l <= left && right <= r) return st[idx];
	int ret = INTMAX;
	if(r > mid) ret = min(ret, query(2 * idx + 1, mid + 1, right, l, r));
	if(l <= mid) ret = min(ret, query(2 * idx, left, mid, l, r));
	return ret;
}
int main(){
	int n, q;
	scanf("%d %d", &n, &q);
	for(int i = 1; i <= n; i++){
		a[i] = INTMAX;
	}
	init(1, 1, n);
	while(q--){
		int a, b, c;
		scanf("%d %d %d", &a, &b, &c);
		if(a == 0){
			update(1, 1, n, b + 1, c);
		} else {
			printf("%d\n", query(1, 1, n, b + 1, c + 1));
		}
	}
	return 0;
}

Measured memory_bytes: 4616
x, y = [int(i) for i in input().split()]
print("Yes") if (((4*x)-y)/(2) >= 0 and (y-(2*x))/(2) >= 0) and (((4*x)-y)/(2))-int(((4*x)-y)/(2)) == 0 and ((y-(2*x))/(2))-int((y-(2*x))/(2)) == 0 else print("No")


Measured memory_bytes: 9204
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair<int, int> P; 
const int inf = 1<<21;
const ll INF = 1LL << 60;
const ll mod = 1e9+7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << ((n/1000 + 1) * 1000 - n%1000)%1000 << endl;
    return 0;
}

Measured memory_bytes: 3648
S = input().strip()

num = list(map(int, list(S)))
num.reverse()
num.append(0)

ans = 0
for i in range(len(S)):
    n = num[i]
    if n < 5:
        ans += n
    if n > 5:
        ans += 10-n
        num[i+1] += 1
    if n == 5:
        ans += 5
        if num[i+1] >= 5:
            num[i+1] += 1


print(ans+num[-1])


Measured memory_bytes: 22072
from collections import Counter
n,m=list(map(int,input().split()))
a=list(map(int,input().split()))
d=Counter(a)
p=[]
for c in d:
    p.append([d[c],c])

for i in range(m):
    c,d=list(map(int,input().split()))
    p.append([c,d])
p=sorted(p,key=lambda g:g[1], reverse=True)
c=0
s=0
while n>0:
    s+=p[c][1]*min(n,p[c][0])
    n-=min(n,p[c][0])
    c+=1
print(s)
    

Measured memory_bytes: 122508
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <climits>

using namespace std;

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

bool F[100][10];
ll P[100][11];
int c[100];

int ret_num(int bin, int f){
    int num = 0;
    REP(i,10){
        bool b = (bin >> i) & 1;
        if(b & F[f][9-i])
            num++;
    }
    return num;
}

int main(){
    int N;
    cin >> N;
    REP(i,N)
        REP(k,10)
            cin >> F[i][k];
    REP(i,N)
        REP(k,11)
            cin >> P[i][k];

    ll max = LLONG_MIN;
    ll sum;
    for(int b = 1; b < 1024; b++){
        sum = 0;
        REP(i,N)
            c[i] = ret_num(b, i);
        REP(i,N)
            sum += P[i][c[i]];
        //if(b==3) printf("c0=%d, c1=%d, c2=%d, sum=%lld\n",c[0],c[1], c[2],  sum);
        if(sum > max)
            max = sum;
    }
    cout << max << endl;
    return 0;
}


Measured memory_bytes: 256
#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 ; }
////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////
void solve(){
    ll n , a , b ;
    cin >> n >> a >> b ;
    if((b-a)%2==0){
        cout << (b-a)/2 ;
    }
    else{
        ll nb = b-(a-1);
        ll ans = a-1 + (nb-1)/2 + (1-nb%2) ;
        ll na = a+(n-b) ;

        ll d = n-na ;
        ans = min(ans,n-b+d/2+d%2);
        cout << ans ;
    }

}
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: 256
#include<bits/stdc++.h>
using namespace std;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int MAP[91][91];
int MAX=-1;
int h,w;
void func(int y,int x,int cnt); 
int main(void){
	int i,j;
	while(1){
		cin>>w>>h;
		MAX=-1;
		if(w==0&&h==0){
			break;
		}
		fill(MAP[0],MAP[91],0);
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				cin>>MAP[i][j];
			}
		}
		for(i=0;i<h;i++){
			for(j=0;j<w;j++){
				if(MAP[i][j]==1){
					func(i,j,0);
				}
			}
		}
		cout<<MAX<<endl;
	}
	return 0;
}
void func(int y,int x,int cnt){
	int i;
	int xx,yy;
	MAX=max(MAX,cnt);
	for(i=0;i<4;i++){
		yy=y+dy[i];
		xx=x+dx[i];
		if(xx>=0&&yy>=0&&yy<h&&xx<w&&MAP[yy][xx]==1){
			MAP[yy][xx]=0;
			func(yy,xx,cnt+1);
			MAP[yy][xx]=1;
		}
	}
}
		
		
		


Measured memory_bytes: 3080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
  int N, R;
  cin >> N >> R;
  if (N >= 10) {
    cout << R << endl;
  } else {
    cout << R + 100 * (10 - N) << endl;
  }
  return 0;
}

Measured memory_bytes: 256