akhauriyash/Code-Regression huggingface dataset:
#ifndef call_from_test
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
#endif
//BEGIN CUT HERE
int expression(string,int&);
int term(string,int&);
int factor(string,int&);
int number(string,int&);

bool f;

int expression(string s,int& p){
  int res=term(s,p);
  while(p<(int)s.size()){
    if(s[p]=='+'){
      p++;
      res+=term(s,p);
      continue;
    }
    if(s[p]=='-'){
      p++;
      res-=term(s,p);
      continue;
    }
    break;
  }
  return res;
}

int term(string s,int& p){
  int res=factor(s,p);
  while(p<(int)s.size()){
    if(s[p]=='*'){
      p++;
      res*=factor(s,p);
      continue;
    }
    if(s[p]=='/'){
      p++;
      int tmp=factor(s,p);
      if(tmp==0){
        f=1;
        break;
      }
      res/=tmp;
      continue;
    }
    break;
  }
  return res;
}

int factor(string s,int& p){
  int res;
  if(s[p]=='('){
    p++;
    res=expression(s,p);
    p++;
  }else{
    res=number(s,p);
  }
  return res;
}

int number(string s,int& p){
  int res=0;
  while(p<(int)s.size()&&isdigit(s[p]))
    res=res*10+s[p++]-'0';
  return res;
}
//END CUT HERE
#ifndef call_from_test
signed main(){
  int n;
  cin>>n;
  while(n--){
    string s;
    int p=0;
    cin>>s;s.pop_back();
    cout<<expression(s,p)<<endl;
  }
  return 0;
}

/*
  verified on 2017/11/20
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?lang=jp&id=0109
*/
#endif



Measured memory_bytes: 3140
#include<bits/stdc++.h>
#define S 100000
#define rep(i,n)for(int i=0;i<n;i++)
using namespace std;vector<int>E[S];int u[2*S],v[2*S],r[2*S],ans[2*S],d[S],cnt=1,b[2*S],ok[S]{1};queue<int>que;void bfs(int u, int t) {que.push(u); while (!que.empty()) {int p = que.front(); que.pop(); for (int v : E[p]) {if (t) {if (d[v] > d[p] && !ok[v]) {ok[v] = 1; cnt++; que.push(v);}}else if (!~d[v]) {d[v] = d[p] + 1; que.push(v);}}}}int main() {int n, m, q; scanf("%d%d%d", &n, &m, &q);rep(i, m) {scanf("%d%d", &u[i], &v[i]);u[i]--; v[i]--;E[u[i]].push_back(v[i]); E[v[i]].push_back(u[i]);}memset(d, -1, sizeof(d));d[0] = 0; bfs(0, 0);rep(i, m) {if (d[u[i]] > d[v[i]])swap(u[i], v[i]);}rep(i, n)E[i].clear();rep(i, q) {scanf("%d", &r[i]); r[i]--;b[r[i]] = 1;}rep(i, m) {if (!b[i]) {if (d[v[i]] > d[u[i]]) {E[u[i]].push_back(v[i]);}}}bfs(0, 1);for (int i = q - 1; i >= 0; i--) {ans[i] = n - cnt;if (d[v[r[i]]] > d[u[r[i]]] && !ok[v[r[i]]]) {E[u[r[i]]].push_back(v[r[i]]);if (ok[u[r[i]]]) {cnt++; ok[v[r[i]]] = 1;bfs(v[r[i]], 1);}}}rep(i, q)printf("%d\n", ans[i]);}

Measured memory_bytes: 14588
#include <bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
typedef long long ll;
#define FOR(i,n) for(int i=0;i<n;i++)

int main(){
  ll n;
  ll ans;
  cin >> n;
  for(ll i=0;i<n;i++){
    ans += i;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MAX_V 3500
#define INF 1<<28
typedef pair<int,int> P;
struct edge{
  int to,cap,cost,rev;
  edge(){}
  edge(int to,int cap,int cost,int rev):to(to),cap(cap),cost(cost),rev(rev){}
};

int V;
vector<edge> G[MAX_V];
int h[MAX_V];
int dist[MAX_V];
int prevv[MAX_V],preve[MAX_V];

void add_edge(int from,int to,int cap,int cost){
  G[from].push_back(edge(to,cap,cost,G[to].size()));
  G[to].push_back(edge(from,0,-cost,G[from].size()-1));
}
bool ff;
int min_cost_flow(int s,int t,int f){
  int res=0;
  fill(h,h+V,0);
  while(f>0){
    priority_queue<P,vector<P>,greater<P> > que;
    fill(dist,dist+V,INF);
    dist[s]=0;
    que.push(P(0,s));
    while(!que.empty()){
      P p=que.top();que.pop();
      int v=p.second;
      if(dist[v]<p.first) continue;
      for(int i=0;i<(int)G[v].size();i++){
	edge &e=G[v][i];
	if(e.cap>0&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
	  dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
	  prevv[e.to]=v;
	  preve[e.to]=i;
	  que.push(P(dist[e.to],e.to));
	}
      }
    }
    if(dist[t]==INF){
      return res;
    }
    for(int v=0;v<V;v++) h[v]+=dist[v];

    int d=f;
    for(int v=t;v!=s;v=prevv[v]){
      d=min(d,G[prevv[v]][preve[v]].cap);
    }
    f-=d;
    res+=d*h[t];
    for(int v=t;v!=s;v=prevv[v]){
      edge &e=G[prevv[v]][preve[v]];
      e.cap-=d;
      G[v][e.rev].cap+=d;
    }
  }
  return res;
}

int main(){
  int n;
  cin>>n;
  vector<P> ab(n);
  vector<int> v(n*2);
  for(int i=0;i<n;i++){
    cin>>ab[i].first>>ab[i].second;
    v[i*2]=ab[i].first;
    v[i*2+1]=ab[i].second;
  }
  sort(v.begin(),v.end());
  v.erase(unique(v.begin(),v.end()),v.end());
  int m=v.size();
  map<int,int> r;
  for(int i=0;i<m;i++) r[v[i]]=i;
  V=n+m+2;
  int s=n+m,t=n+m+1;
  for(int i=0;i<n;i++) add_edge(s,i,1,0),add_edge(i,t,1,0);
  for(int i=0;i<m;i++) add_edge(n+i,t,1,0);
  for(int i=0;i<n;i++){
    add_edge(i,n+r[ab[i].first],1,-ab[i].second);
    add_edge(i,n+r[ab[i].second],1,-ab[i].first);
  }
  cout<<-min_cost_flow(s,t,n)<<endl;
  return 0;
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define lbd(a, x) lower_bound(all(a), x)
const int mod = 1e9 + 7;
int power_mod(int a, int b) {
  int res = 1;
  for(; b; b >>= 1, a = (ll) a * a % mod)
		if(b & 1) res = (ll) res * a % mod;
	return res;
}
const int N = 2e5 + 10;
vector<int> E[N];
int fac[N], ifac[N];
int dp[N], sz[N], n;
void dfs1(int u, int pre) {
  dp[u] = sz[u] = 1;
  for(auto &v : E[u]) {
		if(v == pre) continue;
		dfs1(v, u);
		sz[u] += sz[v];
    dp[u] = (ll) dp[u] * dp[v] % mod * ifac[sz[v]] % mod;
  }
  dp[u] = (ll) dp[u] * fac[sz[u] - 1] % mod;
}
int up[N];
void dfs2(int u, int pre) {
  for(auto &v : E[u]) {
    if(v == pre) continue;
    up[v] = (ll) dp[u] * power_mod(dp[v], mod - 2) % mod;
    up[v] = (ll) up[v] * ifac[n - 1] % mod * fac[n - sz[v] - 1] % mod * fac[sz[v]] % mod;
    dp[v] = (ll) dp[v] * ifac[sz[v] - 1] % mod * fac[n - 1] % mod;
    dp[v] = (ll) dp[v] * ifac[n - sz[v]] % mod;
    dp[v] = (ll) dp[v] * up[v] % mod;
    dfs2(v, u);
  }
}
int main() {
#ifdef local
	freopen("in.txt", "r", stdin);
#endif
	ios::sync_with_stdio(false);
	cin.tie(0), cout.tie(0);
	fac[0] = ifac[0] = 1;
	for(int i = 1; i < N; i++) fac[i] = (ll) fac[i - 1] * i % mod;
	ifac[N - 1] = power_mod(fac[N - 1], mod - 2);
	for(int i = N - 2; i; i--) ifac[i] = (ll) ifac[i + 1] * (i + 1) % mod;
	cin >> n;
	for(int i = 1, u, v; i < n; i++) {
		cin >> u >> v;
		E[u].push_back(v);
		E[v].push_back(u);
	}
	dfs1(1, 0);
	dfs2(1, 0);
	for(int i = 1; i <= n; i++) {
		cout << dp[i] << '\n';
	}
	return 0;
}


Measured memory_bytes: 17908
#include<iostream>
#include<cstdio>
#include<string>
using namespace std;
int main()
{
	int n,sum=0;
	string str1;
	string str2="ABC";
	scanf("%d",&n);
	cin>>str1;
	while(str1.find(str2)!=string::npos)
	{
		str1.replace(str1.find(str2),3,"");
		sum++;
	}
	printf("%d",sum);
	return 0;
}

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

#define loop(i,a,b) for(int i=(a);i<int(b);i++)
#define rep(i,b) loop(i,0,b)

int main (void) {
    int n;
    int a[100];
    while(cin>>n && n){
        rep(i,n)cin>>a[i];
        int f;
        cin>>f;
        int l=0; int r=n-1;
        int ans=0;
        while(l<=r) {
            ans++;
            int m=(l+r)/2;
            if(a[m] == f) break;
            else if(a[m]<f)l=m+1;
            else r=m-1;
            m=(l+r)/2;
        }
        cout << ans << endl;
    }
    return 0;
}

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

using namespace std;

#define ll long long
#define endl '\n'
#define pb push_back
#define inf 1e9

int main ()
{
    double n, k; cin >> n >> k;

    double probability = 0;

    for (double i = 1; i <= n; i++)
    {
        //cout << "----" << i << endl;
        if (i < k)
        {
            double expo = ceil( ( log(k/i) ) / log(2) );
            probability += pow( 0.5 , expo);
        } else
        {
            //cout << "100%" << endl;
            probability += 1.0;
        }

    }

    probability /= n;

    cout << setprecision(12) << fixed << probability << endl;

    return 0;
}


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

int main() {
  string S;
  cin >> S;
  int price = 700;
  if (S[0] == 'o') price+=100;
  if (S[1] == 'o') price+=100;
  if (S[2] == 'o') price+=100;
  cout << price << endl;
}

Measured memory_bytes: 256
def calc(ary, i, n, a, b)
    return a + 10 * b + ary[i] if i == n - 1
    x = calc(ary, i + 1, n, a + b * 10 + ary[i], 0)
    y = calc(ary, i + 1, n, a, b * 10 + ary[i])
    x + y
end

ary = gets.chomp.chars.map(&:to_i)
puts calc(ary, 0, ary.size, 0, 0)

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

using namespace std;

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

  vector<char> tmp;
  int head = 0;

  for(int i = 0;i < s.length();i++){
    switch(s[i]){
    case 'B':
      if(!tmp.empty())
	tmp.pop_back();
      break;
    case '0':
      tmp.push_back('0');
      break;
    case '1':
      tmp.push_back('1');
      break;
    default:
      std::cerr << "unkown char \"" << s[i] << "\"" << std::endl;
      break;
    }
  }

  for(auto& c : tmp){
    std::cout << c;
  }
  std::cout << std::endl;
}


Measured memory_bytes: 256
H,W,D=map(int,input().split())
G=[[]]*(H*W)
J=[0]*(H*W)
for i in range(H):
  for j,a in enumerate(list(map(int,input().split()))):
    G[a-1]=[i,j]
    
for i in range(H*W):
  if i-D>=0:
    J[i]=J[i-D]+abs(G[i][0]-G[i-D][0])+abs(G[i][1]-G[i-D][1])
      
for i in range(int(input())):
  l,r=map(int,input().split())
  print(J[r-1]-J[l-1])

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

signed main() {
  int X, Y;
  cin >> X >> Y;
  
  if( X % Y == 0 ){
    cout << -1 << endl;
    return 0;
  }else{
    for( int i = 2; i*X <= 1e+18; i++ ){
      if( (X*i) % Y != 0 ){
        cout << X*i << endl;
        return 0;
      }
    }
  }
    
}


Measured memory_bytes: 256
S=*$<;p~((0..S.size-2).map{|i|d,p,q,r=0,0,1<<i;(d,p,q,r=d-1,p|q,0,p&q^q;s=r;(q|=S[-i.bit_length].to_i 2;s^=i)while(i=s&-s)>0;0<q&r&&x)while 0<q;d}.min rescue 0)

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

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

	long long tmp = n/k;
	long long res = tmp * tmp * tmp;

	if ((k&1)==0) {
		tmp = n/k;
		if (n%k >= k/2) {
			tmp++;
		}
		res += tmp * tmp * tmp;
	}
	
	cout << res << endl;
	return 0;
}

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

using namespace std;

void solve(void)
{
	int n, m;
	cin >> n >> m;
	if (m == 1)
	{
		cout << 0 << endl;
		return;
	}
	int maxi = n - m + 1;
	cout << maxi - 1 << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


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


int main(void) {
    int x, y, r;
    cin >> x >> y;
    if (x < y) swap(x, y);
    while (y > 0) {
        r = x % y;
        x = y;
        y = r;
    }
    cout << x << endl;
}



Measured memory_bytes: 3104
n,m = map(int,input().split())
a = list(map(int,input().split()))
sum_a = sum(a)
border = sum_a / (4*m)
kosu = 0
for i in a:
  if i >= border:
  	kosu += 1
if kosu >= m:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define FORR(i,a,b) for (int i=(a);i>=(b);i--)
#define pb push_back
#define pcnt __builtin_popcount
#define show(x) cout<<#x<<" = "<<x<<endl;
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define fi first
#define se second
#define rng(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define sz(x) (int)(x).size()
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef set<int> si;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<pll> vpll;
typedef set<ll> sl;
typedef __int128_t lll;
typedef pair<lll,lll> plll;
typedef vector<lll> vlll;
template<typename T>string join(vector<T>&v)
{stringstream s;FOR(i,0,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename A, size_t N, typename T>void Fill(A (&array)[N], const T&v)
{fill((T*)array,(T*)(array+N),v);}
ll gcd(ll a,ll b){if(a>b)swap(a,b);for(;a>0;b%=a,swap(a,b));return b;}
int modpow(ll a,ll n,int m){if(a==0)return a;ll p=1;for(;n>0;n/=2,a=a*a%m)if(n&1)p=p*a%m;return(int)p;}
void dout(double d){printf("%.12f\n",d);}

const int iinf = 1e9;
const ll linf = 1e18;
const int mod = 1e9+7;
const double pi = acos(-1);
const double eps = 1e-10;
ll a[7];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll ans = 0;
  FOR(i, 0, 7) cin >> a[i];
  ans += a[1];
  if(a[0]%2 + a[3]%2 + a[4]%2 == 2){
    if(a[0] > 0 && a[3] > 0 && a[4] > 0){
      ans += 3;
      a[0]--;
      a[3]--;
      a[4]--;
    }
  }
  ans += (a[0]/2 + a[3]/2 + a[4]/2) * 2;
  a[0] %= 2;
  a[3] %= 2;
  a[4] %= 2;
  ans += min(min(a[0], a[3]), a[4]) * 3;
  cout << ans << endl;
  return 0;
}

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

int main() {
  int n, tmp = 1, c = 0;
  bool b = 1;
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  rep(i, n){
    ++c;
    tmp = v[tmp-1];
    if(tmp == 2) break;
    else if(i == n-1) b = 0;
  }
  if(b) cout << c << endl;
  else cout << -1 << endl;
  return 0;
}

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

#define int long long
#define rep(i,a,n) for(int i = a; i < n; i++)
#define pb push_back
#define eb emplace_back
#define dump(x) cout << #x << " = " << (x) << endl
#define chk() cout << "now" << endl;
#define SORT(c) sort((c).begin(), (c).end())
#define SORTG(c) sort((c).begin(), (c).end(), greater<int>());
#define fi first
#define se second
  
typedef pair<int,int> P;
typedef vector<int> vi;

int N, M;
int MAX = 1e5 + 1;
vi A(MAX), B(MAX);
vi ctn;

class UnionFind {
  private:
    vi par;
    vi siz;

  public:
    UnionFind(int sz_) : par(sz_), siz(sz_, 1) { // すべて根とする
      rep(i, 0, sz_) par[i] = i;
    }

    void init(int sz_) { // 初期化
      par.resize(sz_);
      siz.resize(sz_, 1);
      rep(i, 0, sz_) par[i] = i;
    }

    int root(int x) { // 根を求める
      if(par[x] == x) return x;
      return par[x] = root(par[x]);
    }

    void unite(int x, int y) {
      int rx, ry;
      rx = root(x);
      ry = root(y);
      if(rx == ry) return;
      if(siz[rx] < siz[ry]) swap(rx, ry);
      siz[rx] += siz[ry];
      par[ry] = rx;
    }

    bool same(int x, int y) {
      return root(x) == root(y);
    }

    int size(int x) {
      return siz[root(x)];
    }
};

signed main() {
  cin >> N >> M;
  rep(i, 0, M) cin >> A[i] >> B[i];

  UnionFind tree(N);

  int ans = 0;
  ctn.pb(N*(N-1)/2);
  rep(i, 0, M) {
    int a = A[M-1-i]-1, b = B[M-1-i]-1;
    if(!tree.same(a, b)) {
      ctn.pb(ctn[i] - tree.size(a)*tree.size(b));
      tree.unite(a, b);
    }else{
      ctn.pb(ctn[i]);
    }
  }
  rep(i, 0, M) {
    ans = ctn[M-1-i];
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 5364
n,m = map(int,input().split())
li = [list(map(int,input().split())) for _ in range(n)]
li.sort(key = lambda x:x[0])

money = 0
count = 0

while m > 0:
    if m > li[count][1]:
        money += li[count][0] * li[count][1]
        m -= li[count][1]
        count += 1
    else:
        money += li[count][0] * m
        m = 0
        count += 1

print(money)


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

int main()
{
	int n,W;
	cin>>n>>W;
	vector<int>wt(n,0),val(n,0);
	int sum=0;
	for(int i=0;i<n;i++)
	{
		int x,y;
		cin>>x>>y;
		wt[i]=x;val[i]=y;
		sum+=val[i];
	}

	vector<vector<ll>>dp(n+1,vector<ll>(sum+1,1e18));
	int ans=INT_MIN;
	dp[0][0]=0;
	for(int i=1;i<=n;i++)
	{
		dp[i][0]=0;
		for(int j=1;j<=sum;j++)
		{
			dp[i][j]=dp[i-1][j];
			if(j-val[i-1]>=0)
				dp[i][j]=min(dp[i-1][j],dp[i-1][j-val[i-1]]+wt[i-1]);
			 // cout<<dp[i][j]<<" ";
		}
		// cout<<endl;
	}
	for(int i=sum;i>=0;i--)
		if(dp[n][i]<=W)
			{
				ans=i;
				break;
			}

	cout<<ans<<endl;

}


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

int main()
{
    long long s=0;
    string n;
    cin>>n;
    for(int i=0;i<n.length();++i)
    {
        s+=(n[i]-'0');
    }
    if(s%9==0)
    cout<<"Yes"<<endl;
    else
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3744
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<int, pii> pipii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> key;

map<ll, int> dp[60];
const int MOD = 1000000007;

ll modpow(ll b, ll e, ll m) {
  ll r = 1;
  while(e) {
    if(e%2) {
      r*=b;
      r%=m;
    }
    b*=b;
    b%=m;
    e/=2;
  }
  return r;
}

ll solve(int idx, ll sum) {
  if(idx < 0) return 1;
  if(dp[idx].count(sum)) return dp[idx][sum];
  ll maxIn = (1LL << (idx+1)) - 1;
  if(2*maxIn <= sum) return modpow(3, idx+1, MOD);
  ll ret = solve(idx-1, sum);
  if((1LL<<idx) <= sum) ret += solve(idx-1, sum-(1LL<<idx));
  if((2LL<<idx) <= sum) ret += solve(idx-1, sum-(2LL<<idx));
  ret %= MOD;
  dp[idx][sum] = ret;
  return ret;
}

void solve() {
  ll n;
  cin >> n;
  cout << solve(59, n) << "\n";
}

void casesolve() {
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << " ";
    solve();
  }
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  solve();
  // casesolve();
}


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

int main(){
  int N,M;
  cin>>N>>M;
  vector<int> road(2*M);
  vector<int> ans(N);
  	for(int i=0;i<2*M;i++){
      cin>>road.at(i);
    }
  for(int i=0;i<N;i++){
    for(int j=0;j<2*M;j++){
      if(road.at(j)==i+1){
        ans.at(i)++;
      }
    }
  }
    for(int i=0;i<N;i++){
      cout<<ans.at(i)<<endl;
    }
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    N = Scanner.int()
    F = Scanner.int_list_list(N)
    P = Scanner.int_list_list(N)
    ans = -INF
    for i in range(1, 1 << 10):
        o = [False for _ in range(10)]
        for j in range(10):
            if i >> j & 1:
                o[j] = True
        t = [0 for _ in range(N)]
        for j in range(10):
            if not o[j]:
                continue
            for k in range(N):
                t[k] += F[k][j]
        tmp = 0
        for j in range(N):
            tmp += P[j][t[j]]
        ans = max(ans, tmp)
    print(ans)


def main():
    # sys.stdin = open("sample.txt")
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 65496
A,B,C,K = input().split(' ')
A = int(A) # 1
B = int(B) # 0
C = int(C) # -1
K = int(K)


# 1 x ?,  0 x ?,  -1 x ?
if (K <= A + B):
  if (A >= K):
    print(K)
  else:
    print(A)
else:
  print(A + ((K - (A + B)) * -1))


Measured memory_bytes: 61736
N, M, X = [int(i) for i in input().split()]
mass = [0 for i in range(N + 1)]
for i in input().split():
    mass[int(i)] = 1

r = 0
for i in range(X, N + 1):
    r += mass[i]
l = 0
for i in range(X, 0, -1):
    l += mass[i]

if r >= l:
    print(l)
else:
    print(r)

Measured memory_bytes: 3064
import bisect


def calc(X, Y):
    dic = dict([(X * (2**x), x) for x in range(80)])
    ret = bisect.bisect(list(dic.keys()), Y)

    return ret


def calc2(X, Y):
    cnt = 0
    tmp = X
    while tmp <= Y:
        tmp *= 2
        cnt += 1
    return cnt


def main():
    X, Y = list(map(int, input().split()))
    print(calc2(X, Y))
    # print(calc(X, Y))


if __name__ == '__main__':
    main()
    # import random
    # for i in range(3000000):
    #     x = random.randint(1, 1000000000000000000)
    #     y = random.randint(x, 1000000000000000000)
    #     if (calc(x, y) != calc2(x, y)):
    #         print(x, y)


Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

int compare(const void *a, const void *b) {
	int A, B;
	A = *(int *)a;
	B = *(int *)b;
	if(A > B) {
		return -1;
	} else if(A < B) {
		return 1;
	} else {
		return 0;
	}
}

int main(void) {
	int i;
	int N, K, ans;
	int *l;
	char buf[512], *ch;

	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	N = atoi(ch);
	ch = strtok(NULL, " ");
	K = atoi(ch);

	l = (int *)calloc(N, sizeof(int));
	fgets(buf, sizeof(buf), stdin);
	ch = strtok(buf, " ");
	l[0] = atoi(ch);
	for(i = 1; i < N; i += 1){
		ch = strtok(NULL, " ");
		l[i] = atoi(ch);
	}
	qsort(l, N, sizeof(int), compare);
	ans = 0;
	for(i = 0; i < K; i += 1) {
		ans += l[i];
	}

	printf("%d\n", ans);

	free(l);
	return 0;
}


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

int main() {
    int arr[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << arr[k-1] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <array>
#include <cmath>

using namespace std;

int main()
{
	// Value
	long long N;
	vector<array<long long,2>> params;
	array<long long,2> recent_param;
	long long result_man_num;
	long long recent_sum;

	// Input
	cin >>N;
	for(long long i=0;i<N;++i){
		params.push_back(array<long long,2>{0,0});
		cin >> params.at(i).at(0) >> params.at(i).at(1);
	}

	// Cal
	recent_param.at(0) = params.at(0).at(0);
	recent_param.at(1) = params.at(0).at(1);
	recent_sum = params.at(0).at(0) + params.at(0).at(1);
	for(long long i=1;i<N;++i){
		long long now_param_a = params[i][0];
		long long now_param_b = params[i][1];
		long long new_a = now_param_a;
		long long new_b = now_param_b;
		if(new_a < recent_param[0] || new_b < recent_param[1]){
			long long baisu_a = recent_param[0] / new_a;
			long long baisu_b = recent_param[1] / new_b;
			long long baisu;
			if(baisu_a > baisu_b){
				baisu = baisu_a;
				if(recent_param[0] % new_a != 0) baisu++;
			}else{
				baisu = baisu_b;
				if(recent_param[1] % new_b != 0) baisu++;
			}
			//long long baisu = (baisu_a > baisu_b ? baisu_a : baisu_b) + 1;
			new_a = now_param_a * baisu;
			new_b = now_param_b * baisu;
		}
		//cout<<new_a<<","<<new_b<<"-";
		/*
		long long new_sum = new_a + new_b;
		if(new_sum < recent_sum){
			long long now_param_sum = now_param_a + now_param_b;
			long long haba = recent_sum - new_sum;
			long long more_size = haba / now_param_sum - 10;
			new_a += now_param_a * more_size;
			new_b += now_param_b * more_size;
		}
		while(new_a + new_b < recent_sum){
			new_a += now_param_a;
			new_b += now_param_b;
		}
		*/
		//cout<<new_a<<","<<new_b<<endl;
		recent_param[0] = new_a;
		recent_param[1] = new_b;
		recent_sum = new_a + new_b;
	}
	//result_man_num = recent_param[0] + recent_param[1];
	result_man_num = recent_sum;

	// Output
	cout << result_man_num << endl;

	// Fin
	return 0;
}

Measured memory_bytes: 256
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    S = i2s()
    d = defaultdict(lambda: 0)
    for s in S:
        d[s] += 1
    for k, v in d.items():
        if v != 2:
            print('No')
            return
    print('Yes')

main()


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

#define ll long long
#define f(i, x, n) for(int i = x; i < (int)(n); ++i)
#define all(c) (c).begin(), (c).end()
#define speed ios::sync_with_stdio(0); cin.tie(0);

int const N = 2e5 + 2, MOD = 1e9 + 7;
int n, a[N];
vector<pair<int, int>> v1, v2;

void solve(){
	f(i, 0, n){
		int ck1 = v1[0].second;
		int ck2 = v2[i].second;
		if (ck1 != ck2)cout << v1[0].first << endl; else cout << v1[1].first << endl;
	}
}

int main(){
	speed
	cin >> n;
	f(i, 0, n){
		cin >> a[i];
		v1.push_back({a[i], i});
		v2.push_back({a[i], i});
	}
	sort(v1.rbegin(), v1.rend());
	solve();
}

Measured memory_bytes: 5732
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

int a[111111];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n; cin>>n;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
	}
	sort(a+1,a+n+1); reverse(a+1,a+n+1);
	int cur=1;
	for(int i=1;i<=n;i++)
	{
		if(a[i]>=i)
		{
			cur=i;
		}
		else break;
	}
	int res=0;
	int cntr=0;
	for(int i = cur + 1; i <= n; i++)
	{
		if(a[i]==cur)
		{
			cntr++;
		}
		else break;
	}
	if(cntr&1) res=1;
	if((a[cur]-cur)&1) res=1;
	cout<<(res?"First":"Second")<<'\n';
}


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

using ll = int64_t;
#define int ll

#define FOR(i, a, b) for (int i = int(a); i < int(b); i++)
#define REP(i, b) FOR(i, 0, b)
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(x) x.begin(), x.end()

using pi = pair<int, int>;
using vi = vector<int>;
using ld = long double;

template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}

template <class T> ostream &operator<<(ostream &os, const vector<T> &v) {
  os << "{";
  REP(i, (int)v.size()) {
    if (i)
      os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}

ll read() {
  ll i;
  scanf("%" SCNd64, &i);
  return i;
}

void printSpace() { printf(" "); }

void printEoln() { printf("\n"); }

void print(ll x, int suc = 1) {
  printf("%" PRId64, x);
  if (suc == 1)
    printEoln();
  if (suc == 2)
    printSpace();
}

string readString() {
  static char buf[3341000];
  scanf("%s", buf);
  return string(buf);
}

char *readCharArray() {
  static char buf[3341000];
  static int bufUsed = 0;
  char *ret = buf + bufUsed;
  scanf("%s", ret);
  bufUsed += strlen(ret) + 1;
  return ret;
}

template <class T, class U> void chmax(T &a, U b) {
  if (a < b)
    a = b;
}

template <class T, class U> void chmin(T &a, U b) {
  if (b < a)
    a = b;
}

template <class T> T Sq(const T &t) { return t * t; }

const int mod = 1e9 + 7;

signed main() {
  int n = read();
  vector<pi> diff;
  REP(i, n) {
    int tmp = read();
    if (tmp != i + 1)
      diff.EB(i + 1, tmp);
  }
  if (diff.size() == 0) {
    std::cout << "YES" << std::endl;
    return 0;
  } else if (diff.size() == 2) {
    if (diff[0].first == diff[1].second && diff[0].second == diff[1].first) {
      std::cout << "YES" << std::endl;
      return 0;
    }
  }
  std::cout << "NO" << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<queue>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
/************************************************/
#define rep(i,n) for(int i=0;i<n;i++)
#define m_p make_pair
#define pb push_back
#define fr first
#define se second
#define forn(i,a,n) for(int i=a;i<n;i++)
#define foreach(i,c) for(__typeof(c.begin())i=(c.begin());i!=(c).end();i++)
#define pii pair<int,int>
#define vi vector<int>
#define ll long long
#define sz(s) s.size()
#define all(s) s.begin(),s.end()
#define zero(x) memset(x,0,sizeof(x))
#define vii vector<pair<int,int> >
#define mpis map<int,string>
#define mpii map<int,int>
#define mpsi map<string,int>
#define re return
#define mod 1000000007
/************************************************/
using namespace std;

long long get(){
	char c=getchar();
	long long x=0LL;
	while(c<'0'||c>'9')
	c=getchar();
	while(c>='0'&&c<='9'){
		x*=10LL;
		x+=(c-'0');
		c=getchar();
	}
	return x;
}
ll k,now;
int main(){
	ios::sync_with_stdio(0);
	cin>>k;
	now=7;
	int ans=1;
	int kk=k;
	while(kk--&&now%k){
		now%=k;
		now*=10;
		now+=7;
		ans++;
	}
	if(now%k){
		cout<<"-1";
	}else
	cout<<ans;
	re 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define inf (ll)1e9
#define d(x) cerr<<#x<<"="<<x<<endl;

int a[100001],n,dp[100001];

int main(void){
    cin>>n;
    rep(i,n)cin>>a[i];
    dp[1]=abs(a[1]-a[0]);
    repi(i,2,n)dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1]<<endl;
    return 0;
}


Measured memory_bytes: 1024
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;

#[allow(dead_code)]
struct Scanner<'a> {
    cin: StdinLock<'a>,
}
#[allow(dead_code)]
impl<'a> Scanner<'a> {
    fn new(cin: StdinLock<'a>) -> Scanner<'a> {
        Scanner { cin: cin }
    }

    fn read<T: FromStr>(&mut self) -> Option<T> {
        let token = self.cin.by_ref().bytes().map(|c| c.unwrap() as char)
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        token.parse::<T>().ok()
    }

    fn input<T: FromStr>(&mut self) -> T {
        self.read().unwrap()
    }

    fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.input()).collect()
    }

    fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin);

    let n: usize = sc.input();
    let mut a = vec![];
    let mut b = vec![];
    for _ in 0..n {
        let ai: usize = sc.input();
        let bi: usize = sc.input();
        a.push(ai);
        b.push(bi);
    }

    a.sort();
    b.sort();
    if n % 2 == 0 {
        let mi = a[n / 2 - 1] + a[n / 2];
        let ma = b[n / 2 - 1] + b[n / 2];
        println!("{}", ma - mi + 1);
    } else {
        let mi = a[n / 2];
        let ma = b[n / 2];
        println!("{}", ma - mi + 1);
    }
}


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

using namespace std;

int N;

int main() {
	int num, cnt;

	cnt = 0;
	cin >> N;
	for (int i = 0; i < N; ++i) {
		cin >> num;
		for (int y = 1; 2 * y * (y + 1) <= num; ++y) {
			if ((num - y) % (2 * y + 1) == 0) {
				++cnt;
				break;
			}
		}
	}
	cout << N - cnt << endl;

	return 0;
}


Measured memory_bytes: 3088
N,  *_ABC,  = map(int, open(0).read().split())

A = _ABC[:N]
B = _ABC[N: 2*N]
C = _ABC[2*N:]

ans = 0

for i, a in enumerate(A):
    ans += B[a-1]

    if i != len(A)-1 and A[i+1] == a + 1:
        ans += C[a-1]

print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;

typedef long long ll;
// constexpr ll MOD = 998244353;
constexpr ll MOD = 1000000007;

// struct UnionFind {
//     vector<int> par;
    
//     UnionFind(int N): par(N) {
//         for (int i=0;i<N;i++) par[i] = i;
//     }

//     int root(int x) {
//         if (par[x] == x) return x;
//         else return par[x] = root(par[x]);
//     }

//     void unite(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         if (rx == ry) return;
//         par[rx] = ry;
//     }

//     bool same(int x, int y) {
//         int rx = root(x);
//         int ry = root(y);
//         return rx == ry;
//     }
// };

int main(void) {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int i=a, j=b;
    for (;j<d;j++) cout << 'U';
    for (;i<c;i++) cout << 'R';
    for (;j>b;j--) cout << 'D';
    for (;i>a;i--) cout << 'L';
    // i == a, j == b
    cout << 'L'; i--;
    // i == a-1, j == b
    for (;j<d+1;j++) cout << 'U';
    // i == a-1, j == d+1
    for (;i<c;i++) cout << 'R';
    // i == c, j == d+1
    cout << "DR"; j--; i++;
    // i == c+1, j == d
    for (;j>b-1;j--) cout << 'D';
    // i == c+1, j == b-1
    for (;i>a;i--) cout << 'L';
    // i == a, j == b-1
    cout << 'U' << endl;

    return 0;
}


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

int main(void){
   int N,Y;
   cin>>N>>Y;
   for(int i=0;i<=N;i++){
      for(int j=0;j<=N;j++){
         int ans_z=N-i-j;
         if(ans_z>=0){
            if(10000*i+5000*j+1000*ans_z==Y){
               cout<<i<<" "<<j<<" "<<N-i-j<<endl;
               return 0;
            }
         }
      }
   }
   cout<<-1<<" "<<-1<<" "<<-1<<endl;
   return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main() {
  int n, m, x, a, l = 0, r = 0;
  scanf("%d %d %d", &n, &m, &x);
  for(int i = 0; i < m; i++) {
    scanf("%d", &a);
    if(a < x)
      l++;
    else
      r++;
  }
  printf("%d\n", l < r ? l : r);
}

Measured memory_bytes: 128
n,*a=`dd`.split.map &:to_i;l,r=[a,a.reverse].map{|b|s=[[n=0,i=-1]];r=b*2;b.map{|e|i+=1;s.pop while e<s[-1][0];r[e]=i-s[-1][1];s<<[e,i]};r};a.map{|e|n+=e*l[e]*r[e]};p n

Measured memory_bytes: 44680
import sys
sys.setrecursionlimit(10**7)
INTMAX = 9223372036854775807
INTMIN = -9223372036854775808
DVSR = 1000000007
def POW(x, y): return pow(x, y, DVSR)
def INV(x, d=DVSR): return pow(x, d - 2, d)
def DIV(x, y, d=DVSR): return (x * INV(y, d)) % d
def LI(): return [int(x) for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LS(): return input().split()
def II(): return int(input())

N=II()
INL = []
for i in range(N):
    a,b = LI()
    INL.append((b,a))
INL.sort()

cum = 0
for b, a in INL:
    cum += a
    if cum > b:
        print('No')
        exit()

print('Yes')

Measured memory_bytes: 69336
n,m=map(int,input().split())
l=list(map(int,input().split()))
if m==1:
  print(0)
  exit()
l.sort()
l2=[]
x0=l[0]
l.remove(x0)
for x in l:
  l2.append(x-x0)
  x0=x
l2.sort()
if n==1:
  print(sum(l2))
else:
  print(sum(l2[:-(n-1)]))

Measured memory_bytes: 13968
S = [int(x) if x != "?" else -1 for x in input()]
mod = int(1e9+7)
r = [0]*13
if S[0] != -1:
    r[S[0]] = 1
else:
    for i in range(10):
        r[i] = 1
for i in range(1, len(S)):
    dp = [0] * 26
    for j in range(13):
        dp[j * 10 % 13] += (r[j] % mod)

    dp[13:26] = dp[0:13]
    r = [0]*13
    if S[i] == -1:
        s = sum(dp[4:14])
        for j in range(13):
            r[j] += s
            s += dp[j+1] - dp[4+j]
    else:
        for j in range(13):
            r[j] += dp[13 - S[i] + j]
print(r[5] % mod)

Measured memory_bytes: 4092
from collections import Counter

n, p = map(int, input().split())
s = list(map(int, list(input())))

ans = 0
if p in {2, 5}:
    for i, num in enumerate(s):
        if num % p == 0:
            ans += i + 1
else:
    bfo, cnt = 0, [1] + [0] * (p - 1)
    for i, num in enumerate(s[::-1]):
        bfo = (bfo + pow(10, i, p) * num) % p
        ans += cnt[bfo]
        cnt[bfo] += 1
print(ans)


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

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

    vector< vector<ll> > num(10, vector<ll>(10, 0));
    // num[p][q] := 最上位p,一の位qである1~Nの整数の個数
    for(int n=1; n<=N; n++){
        vector<int> d;
        int nn = n;
        while(nn != 0){
            d.push_back(nn % 10);
            nn /= 10;
        }

        int a = d[0]; // 一の位q (0も含む)
        int b = d[d.size()-1]; // 最上位p
        num[b][a]++;
    }

    ll ans = 0;
    for(int i=1; i<10; i++){
        for(int j=1; j<10; j++){
            ans += num[i][j] * num[j][i];
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
using namespace std;
typedef long long ll;
vector<ll> g[200005];
#define pi 3.14159265358979
ll ok[200005]={0};
ll n,m; 
int main()
{
	ll n;
	cin>>n;
	n=n%10;
	if(n==3) puts("bon");
	else if(n==0||n==1||n==6||n==8) puts("pon");
	else puts("hon");
}

Measured memory_bytes: 8324
/* きり！みん！ちゃん！！！！ */

#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <iomanip>	//cout << fixed << setprecision(桁数);

#define debug(x) (#x " : " + to_string(x))
#define debug_cout(x) (cout << #x << " : " << to_string(x) << endl)
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; i++)
#define rep1(i, n) for(int i=1, i##_len=(n); i<=i##_len; i++)
#define rrep(i, n) for(int i=(n)-1; i >= 0; i--)
#define rrep1(i, n) for(int i=(n); i > 0; i--)
#define all(x) (x).begin(), (x).end()
#define pair(a, b) make_pair((a), (b));
using namespace std;
using ll = long long;
//#define int long long
template<class T> bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
constexpr int INF = (int)2e9;

/*****/

int n, W;
vector<pair<int, int>> things;

int main()
{
	int K, S;
	cin >> K >> S;

	int run = 0;
	int cnt = 0;
	for (int x = 0; x <= K && x <= S; x++)
	{
		for (int y = 0; y <= K && x + y <= S; y++)
		{
			run++;
			/*if (S - x - y <= y && S - x - y <= K)
			{
				if (x == y && y == S - x - y)
				cnt++;
				else
					cnt += 3;
			}*/
			if (S - x - y <= K)
			{
				cnt++;
			}
		}
	}

	cout << cnt << endl;
	//debug_cout(run);

	return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    string s; cin>>s;
    rep(i,19){
        if(i==5 || i==13) cout<<" ";
        else cout<<s[i];
    }
    cout<<endl;
}

Measured memory_bytes: 256
N, M = gets.split.map(&:to_i)

as = []
N.times do
  as << gets.chomp
end
bs = []
M.times do
  bs << gets.chomp
end

(0..(N-M)).each do |n|
  (0..(N-M)).each do |m|
    tmp = []
    M.times do |dn|
      tmp << (as[n + dn][m, M] == bs[dn])
    end
    if tmp.all? { |e| e == true }
      puts('Yes')
      exit
    end
  end
end
puts('No')

Measured memory_bytes: 2044
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
using namespace std;

int main() {
    int a,b;
    char op;
    cin >> a >> op >> b;
    if(op == '+') cout << a+b << endl;
    else cout << a-b << endl;
}

Measured memory_bytes: 256
#include <cstdio>
int main() {
	int p[100]={0},n;
	scanf("%d",&n);
	for(int i=0;i<n*(n-1)/2;i++) {
		int a,b,c,d;
		scanf("%d %d %d %d",&a,&b,&c,&d);
		if(c>d)p[a-1]+=3;
		else if(c<d)p[b-1]+=3;
		else p[a-1]++,p[b-1]++;
	}
	for(int i=0;i<n;i++) {
		int rate=0;
		for(int j=0;j<n;j++)if(p[i]<p[j])rate++;
		printf("%d\n",rate+1);
	}
}

Measured memory_bytes: 1028
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<(n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) (s.substr(f-1,t-f+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;
struct Grid{ll x,y,t;};
struct Edge{ll to,cost;};
struct Graph{vector<vector<Edge>>E;int V;
  const ll Inf = llINF;const int MAX_V=201010;vector<ll>d;
  Graph(int n):E(n){d.resize(MAX_V);E.resize(n);V=n;}
  void init(){for(int i=0;i<MAX_V;i++)d[i]=Inf;}
  void add_edge(ll from,ll to,ll cost){E[from].pb({to,cost});}
};
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  double r1,r2;
  cin>>r1>>r2;
  printf("%.10f\n",r1*r2/(r1+r2));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
int main() {
	int n, k;
	scanf("%d%d", &n, &k);
	vector<int> A(n);
	for (int i = 0; i < n; ++i) {
		scanf("%d", &A[i]);
		A[i] = min(A[i], k);
	}
	vector<vector<bool>> dp(n + 1, vector<bool>(k + 1));
	vector<vector<bool>> dp2(n + 1, vector<bool>(k + 1));
	vector<int> S(k + 1);
	dp[n][0] = 1;
	for (int i = n - 1; i >= 0; --i) {
		dp[i] = dp[i + 1];
		for (int j = A[i]; j <= k; ++j) {
			dp[i][j] = dp[i][j] || dp[i + 1][j - A[i]];
		}
	}
	dp2[0][0] = 1;
	for (int i = 0; i < n; ++i) {
		dp2[i + 1] = dp2[i];
		for (int j = A[i]; j <= k; ++j) {
			dp2[i + 1][j] = dp2[i + 1][j] || dp2[i][j - A[i]];
		}
	}
	int ans = 0;
	for (int i = 0; i < n; ++i) {
		// Get sum in [k-A[i], k-1].
		bool nec = false;
		S[0] = dp[i + 1][0];
		for (int j = 1; j <= k; ++j) {
			S[j] = S[j - 1] + dp[i + 1][j];
		}
		for (int j = 0; j <= k; ++j) {
			if (!dp2[i][j]) continue;
			int lo = k - A[i] - j;
			int hi = k - 1 - j;
			if (hi < 0) continue;
			int v = S[hi];
			if (lo - 1 >= 0) v -= S[lo - 1];
			if (v >= 1) {
				nec = true;
				break;
			}
		}
		if (!nec) ++ans;
	}
	printf("%d\n", ans);
}


Measured memory_bytes: 6912
n,k=map(int,input().split())
a=list(map(int,input().split()))
s=sum(a)
ii=[]
for i in range(1,int(s**0.5)+1):
  if s%i>0:
    continue
  ii+=[i,s//i]
ii.sort(reverse=True)
for i in ii:
  r=[]
  for j in range(n):
    r+=[a[j]%i]
  r.sort()
  b=0
  l=0
  while l<n and b+r[l]<=k:
    b+=r[l]
    l+=1
  if sum([i-x for x in r[l:]]) <= k:
    print(i)
    break

Measured memory_bytes: 43996
import java.util.*;

class Main
{
    public static void main (String[] args)
    {
        Scanner sc = new Scanner(System.in);
        int[][] c = new int[3][3];
        for(int i=0; i<3; i++)
        {
            for(int j=0; j<3; j++){
                c[i][j] = sc.nextInt();
            }
        }

        String ans = "Yes";
        boolean bl = true;

        for(int i=0; i<2; i++)
        {
            for(int j=0; j<2; j++)
            {
               if (c[j][i] - c[j][i+1] != c[j+1][i] - c[j+1][i+1]
                || c[i][j] - c[i+1][j] != c[i][j+1] - c[i+1][j+1])
                {
                        ans = "No";
                        break;
                }
            }
        }
        System.out.println(ans);
    }
}

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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG2(x,y) cout<<#x<<": "<<x<<" "<<#y<<": "<<y<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define DEBUG_ARR(v,n) cout<<#v<<":";REP(i,n)cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;

    int pos=0;
    int ans=0;
    //OXXOX
    while(pos<n-1){
        if( (s[pos]=='O' && s[pos+1]=='X')
        || (s[pos]=='X' && s[pos+1]=='O') ){
            ans++;
            pos+=2;
        }else{
            pos+=1;
        }
    }
    cout << ans << endl;
    return 0;
}


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

typedef uint64_t u64;
typedef int64_t i64;
typedef uint32_t u32;
typedef int32_t i32;

using namespace std;

template <typename T>
static inline void ArrayInput(vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cin >> *itr;
}

template <typename T>
static inline void ArrayPut(const vector<T>& A) {
  for (auto itr = A.begin(); itr < A.end(); ++itr) cout << *itr << " ";
  cout << endl;
}

bool Sec_compare(pair<uint64_t, uint64_t> a, pair<uint64_t, uint64_t> b) {
  if (a.second != b.second) {
    return a.second < b.second;
  } else {
    return a.first < b.first;
  }
}

u64 dec_dig(u64 num) {
  u64 res = 0;
  while (num > 0) {
    num /= 10;
    ++res;
  }
  return res;
}

u64 gcd(u64 a, u64 b) {
  if (a < b) {
    a ^= b;
    b ^= a;
    a ^= b;
  }

  return b ? gcd(b, a % b) : a;
}

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

int main() {
  string S, T, U;
  cin >> S >> T;
  map<string, u32> M;
  u32 A, B;
  cin >> A >> B;
  M[S] = A;
  M[T] = B;
  cin >> U;
  M[U]--;
  cout << M[S] << " " << M[T] << endl;
  return 0;
}


Measured memory_bytes: 256