akhauriyash/Code-Regression huggingface dataset:
//#include <bits/stdc++.h>
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#include "boost/multiprecision/cpp_int.hpp"
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
typedef pair<dd,dd> d_d;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define fi first
#define se second
///////////////////////////

ll cal(vector<ll>b,ll mid){
    ll sum=0;
    ll n=b.size();
    if(n<=1)return 0;
    rep(i,0,n-1){
        ll x=b[i];
        ll pos=upper_bound(b.begin()+i+1,b.end(),mid/x)-(b.begin()+1+i)-1;
        sum+=pos+1;
    }
    return sum;
}

int main(){fastio
    inf=1E18+5;
    ll n,k;cin>>n>>k;
    ll a[n];rep(i,0,n-1)cin>>a[i];
    vector<ll>po,ne;
    ll ze=0;
    rep(i,0,n-1){
        if(a[i]>0)po.pb(a[i]);
        else if(a[i]<0)ne.pb(a[i]);
        else ze++;
    }
    ll s1=po.size()*ne.size();
    ll s2=ze*(ze-1)/2+ze*(po.size()+ne.size());
    if(k<=s1){
        vector<ll>a,b;
        for(auto x:po)a.pb(x);
        for(auto x:ne)b.pb(-x);
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        ll newk=a.size()*b.size()-k+1;
        ll ok=inf;
        ll ng=0;
        
        while(abs(ok-ng)>1){
            ll mid=(ok+ng)/2;
            ll sum=0;
            for(auto x:a){
                ll pos=upper_bound(b.begin(),b.end(),mid/x)-b.begin()-1;
                sum+=pos+1;
            }
            if(sum>=newk)ok=mid;
            else ng=mid;
        }
        cout<<-1*ok<<endl;
    }else if(k<=s1+s2){
        cout<<0<<endl;
    }else{
        vector<ll>a,b;
        for(auto x:po)a.pb(x);
        for(auto x:ne)b.pb(-x);
        sort(a.begin(),a.end());
        sort(b.begin(),b.end());
        ll ok=inf;
        ll ng=0;
        ll newk=k-s1-s2;
        while(abs(ok-ng)>1){
            ll mid=(ok+ng)/2;
            ll sum=0;
            /*
            for(auto x:a){
                ll pos=upper_bound(b.begin(),b.end(),mid/x)-b.begin()-1;
                sum+=pos+1;
            }*/
            sum+=cal(a,mid);
            sum+=cal(b,mid);
            if(sum>=newk)ok=mid;
            else ng=mid;
        }
        cout<<ok<<endl;
    }
    return 0;
}


Measured memory_bytes: 6256
/**
 *    created by : PawPaw       
**/

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

using namespace __gnu_pbds;  
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,  
        tree_order_statistics_node_update>  
        ordered_set;  

#define F(i,a,b) for(int i = (int)(a); i <= (int)(b); i++)
#define RF(i,a,b) for(int i = (int)(a); i >= (int)(b); i--)
#define LL long long
#define PHI acos(-1)
#define EPS 0.000000001
#define N 1000001
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define FbO find_by_order
#define OoK order_of_key

int solve(){
  int n;
  LL sum = 0, a;
  cin >> n;
  F(i, 0, n-1){
    cin >> a;
    sum += (a-1);
  }
  cout << sum << endl;
  return 0;
}

void fun(){
  int t = 1;
  // cin >> t;
  while(t--) solve();
} 

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

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

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep1(i, n) for (ll i = 1; i < (ll)(n); i++)
#define INF 10000000000
#define MAX 1000010
#define MOD 1000000007

int main(){
  int a,b; cin>>a>>b;
  cout<<max(a+b,max(a-b,a*b))<<endl;
}

Measured memory_bytes: 256
/*
 * 16-11-20_chu2_A.cpp
 *
 *  Created on: 2016/11/20
 *      Author: ryoma
 */

#include<iostream>
#include<algorithm>

using namespace std;

int n, k;
int ans;
int main() {
	cin >> n >> k;
	int kk = (5 * k + 3) % 11;
	int cnt = 0;
	for (int i = 0; i < min(11, n - 2); i++) {
		for (int j = 1; j <= 5; j++) {
			if ((7 * i + j) % 11 == kk)
				cnt++;
		}
	}
	if (n <= 11) {
		cout << cnt << endl;
		return 0;
	}
	int q = n / 11, r = n % 11;
	ans = (q - 1) * cnt;
	for (int i = 0; i < r +9; i++) {
		for (int j = 1; j <= 5; j++) {
			if ((7 * i + j) % 11 == kk)
				ans++;
		}
	}

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



Measured memory_bytes: 256
# -*- coding:utf-8 -*-

def solve(n):
	s = "%05d" % n
	
	s[0]
	t = [ [ ' ' for _ in xrange(5) ] for _ in xrange(8) ]
	for i in xrange(5):
		t[2][i] = '='
	
	for j in xrange(5):
		x = int(s[j])
		if x >= 5:
			t[1][j] = '*'
			x -= 5
		else:
			t[0][j] = '*'
		
		t[3][j] = t[4][j] = t[5][j] = t[6][j] = t[7][j] = '*'
		t[3 + x][j] = ' '
	
	for l in t:
		print "".join(l)

import sys
first = True
while True:
	s = sys.stdin.readline().strip()
	if not s : break
	if first :
		first = False
	else:
		print
	solve(int(s))

Measured memory_bytes: 4260
//# define FLAG
///delet....................................
# include   <bits/stdc++.h>
using namespace std;
# define    pb                      push_back
# define    mp                      make_pair
# define    IOS                     ios::sync_with_stdio(false)
# define    mem(a,b)                memset(a,b,sizeof(a))
# define    FO(i,n,a)               for(int i=n; i>=a; --i)
# define    FOR(i,a,n)              for(int i=a; i<=n; ++i)
# define    MAX(a,b)                (a)>(b)?(a):(b)
# define    MIN(a,b)                (a)<(b)?(a):(b)
# define    lowbit(x)               ((x)&(-x))
# define    LINF                    0xfcfcfcfcfcfcfcf
# define    INF                     0x3f3f3f3f
# define    MOD                     1000000007
# define    eps                     0.00000001
# define    pi                      3.141592653
# define    ee                      2.718281828459
# define    hr                      ptc('\n')
# define    kb                      ptc(' ')
# define    bug                     puts("H");
# pragma    comment(linker,"/STACK:1024000000,1024000000")
typedef     pair<int,int>           PII;
typedef     vector<int>             VI;
typedef     long long               LL;
typedef     unsigned long long      ULL;
inline char gtc() {
    static char buf[100000],*p1=buf-1,*p2=buf-1;
    return p1==p2&&(p2=(p1=buf-1)+fread(buf,1,100000,stdin),p1==p2)?EOF:*++p1;
}
static char bufout[2000000],*chout=bufout-1;
inline void ptc(char ch) {
    *++chout=ch;
}
# define    Template                LL
inline Template read() {
    char ch=gtc();
    while(!(ch>='0'&&ch<='9'||ch=='-'))ch=gtc();
    Template sum=0,flag=(ch=='-'?(ch=gtc()):0);
    while(ch>='0'&&ch<='9')sum=sum*10+ch-'0',ch=gtc();
    return flag?-sum:sum;
}
inline void out(Template x) {
    if(x<0)ptc('-'),x=-x;
    if(x>9)out(x/10);
    ptc(x%10+'0');
}
inline void write() {
    fwrite(bufout,1,chout-bufout+1,stdout);
}
///coding...................................

struct node {
    int a,b;
}a[100005];

bool cmp(node i,node j) {
    return i.a<j.a;
}

int main() {
    IOS;
#ifdef FLAG
    //freopen("in.txt","r",stdin);
    freopen("out.txt","w",stdout);
#endif
    int n;
    cin>>n;
    FOR(i,1,n)cin>>a[i].a>>a[i].b;
    sort(a+1,a+n+1,cmp);
    cout<<a[n].a+a[n].b<<endl;
    return 0;
}










///delete FLAG..............................




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e5 + 5, mod = 1e9 + 7;

ll solve(ll x){
    if(x == 1) return 1;
    return solve(x / 2) * 2 + 1;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll h;
    cin >> h;
    cout << solve(h);

    return 0;
}


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

int main() {
	long long n, d, a;
	cin >> n >> d >> a;
	vector<pair<long long, long long>> x(n);
	for (int i = 0; i < n; i++) {
		cin >> x[i].first >> x[i].second;
		x[i].second = (x[i].second + a - 1) / a;
	}
	sort(x.begin(), x.end());
	long long ans = 0;
	vector<long long> v(n+1, 0);
	for (int i = 0, j = 0; i < n; i++) {
		if (v[i] < x[i].second) {
			long long b = x[i].second - v[i];
			ans += b;
			v[i] += b;
			while (j < n && x[j].first <= x[i].first + 2*d) j++;
			v[j] -= b;
		}
		v[i+1] += v[i];
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
    vector<int>vec(3);
    for(int i=0;i<3;i++)cin>>vec.at(i);
    sort(vec.begin(),vec.end());
    //for(int i=0;i<3;i++)cout<<vec.at(i);
    cout<<vec.at(1)+vec.at(0)<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		
		int cnt = 0;
		int tot = A.Sum();
		for(int i=0;i<N;i++){
			if(A[i] * 4 * M >= tot) cnt++;
		}
		Console.WriteLine(cnt >= M ? "Yes" : "No");
		
	}
	int N,M;
	int[] A;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
n=int(input())
arr=list(map(int,input().split()))
arr2=[]
cnt=0
for i in range(n):
  if arr[i]<0:
    cnt+=1
  arr2.append(abs(arr[i]))
if cnt%2==0:
  print(sum(arr2))
else:
  print(sum(arr2)-min(arr2)*2)

Measured memory_bytes: 14228
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>

using namespace std;

int main(void) {
    int N;
    cin >> N;
    int grid[10][10];
    for(int i=0; i<10; i++) {
        for(int j=0; j<10; j++) {
            grid[i][j] = 0;
        }
    }

    for(int A=1; A<=N; A++) {
        int b = A % 10;
        if(b != 0) {
            int f = stoi(to_string(A).substr(0, 1));
            grid[f][b] ++;
        }
    }

    int64_t ans = 0;
    for(int B=1; B<=N; B++) {
        int b = B % 10;
        if(b != 0) {
            int f = stoi(to_string(B).substr(0, 1));
            ans += grid[b][f];
        }
    }

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


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

result = 0
for ai, i in enumerate(a):
    result += b[i - 1]
    if ai > 0 and i - a[ai - 1] == 1:
        result += c[a[ai - 1] - 1]
print(result)


Measured memory_bytes: 3060
import sys
from itertools import permutations
N, C = map(int, input().split())
D = [list(map(int, sys.stdin.readline().split())) for _ in range(C)]
CM = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]

CG = [[0]*C for _ in range(3)]
for i in range(N):
    for j in range(N):
        nc = CM[i][j] - 1
        for c in range(C):
            CG[(i+j)%3][c] += D[nc][c]
ans = 10**10
for c1, c2, c3 in permutations(range(C), 3):
    ans = min(ans, CG[0][c1] + CG[1][c2] + CG[2][c3])
print(ans)

Measured memory_bytes: 44252
#include <stdio.h>

int main(void) {
	double x[4],y[4];
	int yes;
	double katamuki,seppen;
	while(1) {
		if(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",
			&x[0],&y[0],&x[1],&y[1],&x[2],&y[2],&x[3],&y[3])==-1)break;
		yes=1;
		if(x[0]==x[2]) {
			if((x[1]-x[0])*(x[3]-x[0])>0)yes=0;
		} else if(y[0]==y[2]) {
			if((y[1]-y[0])*(y[3]-y[0])>0)yes=0;
		} else {
			katamuki=(y[0]-y[2])/(x[0]-x[2]);
			seppen=y[0]-katamuki*x[0];
			if((y[1]-(katamuki*x[1]+seppen))*(y[3]-(katamuki*x[3]+seppen))>0)
				yes=0;
		}
		if(x[1]==x[3]) {
			if((x[0]-x[1])*(x[2]-x[1])>0)yes=0;
		} else if(y[1]==y[3]) {
			if((y[0]-y[1])*(y[2]-y[1])>0)yes=0;
		} else {
			katamuki=(y[1]-y[3])/(x[1]-x[3]);
			seppen=y[1]-katamuki*x[1];
			if((y[0]-(katamuki*x[0]+seppen))*(y[2]-(katamuki*x[2]+seppen))>0)
				yes=0;
		}
		printf("%s\n",yes?"YES":"NO");
	}
	return 0;
}

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

int main(){
	
	int n; cin>>n;
	ll sum = 0;
	for(int i = 1; i <= n; i++){	
		if(i%3 == 0) continue;
		if(i%5 == 0) continue;
		sum += i ;
	}
	cout<<sum<<"\n";
}

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using llint = long long;
using vint = vector<int>;

int main () {
    int n, ans = 0; cin >> n;
    vint l(n), r(n);
    rep (i, n) {
        cin >> l[i] >> r[i];
        ans += r[i] - l[i] + 1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import sys

input=sys.stdin.readline
p2D = lambda x: print(*x, sep="\n")
def MI(): return map(int, sys.stdin.readline().split())

def main():
    h, w = MI()
    s = [[c == "#" for c in input()[:-1]] for _ in range(h)]
    #if w == 2:
    #    s = [list(sc) for sc in zip(*s)]
    #    h, w = w, h
    # p2D(s)
    t = [[-1] * (w - 1) for _ in range(h - 1)]
    for i in range(h - 1):
        si = s[i]
        si1 = s[i + 1]
        t[i] = [1 - (sum(si[j:j + 2]) + sum(si1[j:j + 2])) % 2 for j in range(w - 1)]
    # p2D(t)
    # print()
    ti=t[0]
    for i in range(1, h - 1):
        ti1=ti
        ti=t[i]
        for j in range(w - 1):
            if ti[j]: ti[j] = ti1[j] + 1
    # p2D(t)
    ans = 0
    for i in range(h - 1):
        jtol = [0] * (w - 1)
        jtor = [0] * (w - 1)
        ti=t[i]
        # 高さ、位置の順
        stack = [[-1, 0]]
        for j in range(w - 1):
            tij=ti[j]
            while stack[-1][0] >= tij: stack.pop()
            jtol[j] = stack[-1][1]
            stack.append([tij, j + 1])

        stack = [[-1, w - 1]]
        for j in range(w - 2, -1, -1):
            tij=ti[j]
            while stack[-1][0] >= tij: stack.pop()
            jtor[j] = stack[-1][1]
            stack.append([tij, j])

        for j in range(w - 1):
            tmp = (jtor[j] - jtol[j] + 1) * (ti[j] + 1)
            if tmp > ans: ans = tmp
    print(max(ans,h,w))

main()


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

using namespace std;

typedef long long ll;

const int N = 1e5+5;

int n;
int m;
int ar[N];
int prefix[N];

int main(){
    scanf("%d%d " , &n , &m);
    map < int , int > cnt;
    cnt[0] = 1;
    long long ans = 0;
    for(int i = 1; i <= n; i++){
        scanf("%d" , &ar[i]);
        prefix[i] = (0LL + prefix[i - 1] + ar[i]) % m;
        ans += cnt[prefix[i]];
        cnt[prefix[i]]++;
    }
    printf("%lld\n" , ans);
}


Measured memory_bytes: 7500
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <tuple>
#include <math.h>
#include <deque>
#include <stack>
#include <queue>

#define PI 3.14159265358979323846

using namespace std;

typedef long long ll;
typedef long double ld;


int solve() {
    ll n;
    cin >> n;
    for(ll i = 1;i <= 9; i++){
        for(ll j = 1;j <= 9; j++){
            if(n == i * j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,i,j,k,n,m,t;
ll s[2000005];
string s1,s2;

int main(){
	scanf("%lld",&n);
	for(i=0;i<n;i++){
		scanf("%lld",&s[i]);
	}
	j=1; t=0;
	for(i=0;i<n;i++){
		if(s[i]==j)
			j++;
		else
			t++;
	}
	if(t!=n)
	printf("%lld",t);
	else
        printf("-1");
	return 0;
}


Measured memory_bytes: 1792
from collections import defaultdict

import sys
sys.setrecursionlimit(10**6)
ii = lambda: int(input())
mis = lambda: map(int,input().split())
lmis = lambda: list(mis())
INF = float('inf')

def main():
    n,k=mis()
    a=lmis()
    print(-(-(n-1)//(k-1)))


if __name__ == "__main__":
    main()

Measured memory_bytes: 14188
#include<cstdio>
using namespace std;
const int N=200200,M=2002000;
int i,j,k,n,m,En,ch,ff,rtA,rtB;
int h[N],A[N],B[N],fg[N],z[M],ans[N];
struct edge { int s,n;} E[M];
void R(int &x) {
	ff=x=0;ch=getchar();
	while (ch<'0' || '9'<ch) { if (ch=='-') ff=1;ch=getchar();}
	while ('0'<=ch && ch<='9') x=x*10+ch-'0',ch=getchar();
	if (ff) x=-x;
}
void W(int x) {
	if (x<0) putchar('-'),x=-x;
	if (x>=10) W(x/10);
	putchar(x%10+'0');
}
void E_add(int x,int y) {
	E[++En].s=y;E[En].n=h[x];h[x]=En;
	E[++En].s=x;E[En].n=h[y];h[y]=En;
}
void dfs(int x,int F) {
	fg[x]=1;
	for (int k=h[x];k;k=E[k].n) if (E[k].s!=F) {
		dfs(E[k].s,x);
		fg[x]^=1;
	}
}
void Dfs(int x) {
	for (int &k=h[x];k;k=E[k].n) if (!z[k>>1]) {
		z[k>>1]=1;
		if (x+n==E[k].s) ans[x]=1;
		if (x-n==E[k].s) ans[x-n]=-1;
		Dfs(E[k].s);
	}
}
int main() {
	R(n);
	En=1;
	for (i=1;i<=n;i++) {
		R(A[i]);
		if (A[i]==-1) rtA=i;
		else E_add(A[i],i);
	}
	for (i=1;i<=n;i++) {
		R(B[i]);
		if (B[i]==-1) rtB=n+i;
		else E_add(n+B[i],n+i);
	}
	dfs(rtA,0);dfs(rtB,0);
	for (i=1;i<=n;i++) {
		if (fg[i]!=fg[n+i]) return puts("IMPOSSIBLE"),0;
		if (fg[i]) E_add(i,n+i);
	}
	puts("POSSIBLE");
	E_add(rtA,n+n+1);
	E_add(rtB,n+n+1);
	Dfs(rtA);
	for (i=1;i<=n;i++) W(ans[i]),putchar(' ');
	puts("");
}

Measured memory_bytes: 24832
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 5e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll N;
    cin >> N;
    ll a = N % 10;
    if(a==2 or a==4 or a== 5 or a== 7 or a==9)
        cout << "hon" << endl;
    else if(a==0 or a==1 or a==6 or a==8)
        cout << "pon" << endl;
    else
        cout << "bon" << endl;
}

Measured memory_bytes: 3648
import sys
from bisect import bisect_left, bisect_right

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())

N = I()

l = [1, 2, 4, 8, 16, 32, 64]

if N >= 64:
    print(64)
elif N >=32:
     print(32)
elif N >=16:
     print(16)
elif N >=8:
     print(8)
elif N >=4:
     print(4)
elif N >=2:
     print(2)
elif N ==1:
     print(1)

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

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

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 T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

using pss = pair<string, string>;

int n;
string s;
map<pss, int> mp;

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

   for (int mask = 0; mask < (1<<n); mask++) {
      string R = "", B = "";
      rep (i, n) {
         if (mask & (1<<i)) {
            R.push_back(s[i]);
         } else {
            B.push_back(s[i]);
         }
      }
      mp[{R, B}]++;
   }

   ll ans = 0;
   for (int mask = 0; mask < (1<<n); mask++) {
      string R = "", B = "";
      rep (i, n) {
         if (mask & (1<<i)) {
            R.push_back(s[n+i]);
         } else {
            B.push_back(s[n+i]);
         }
      }
      reverse(all(R));
      reverse(all(B));
      ans += mp[{B, R}];
   }

   cout << ans << endl;

   return 0;
}

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

int main(){
	int n,x,t;
	cin >> n >> x >> t;

	if(n % x == 0) cout << n/x * t ;
	else cout <<  (n/x+1)*t;

	return 0;
}

Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] a=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
		}
		int[]b=new int[n];
		for(int i=0;i<n;i++){
			b[i]=check(a[i]);
		}
		int count2=0;
		int count1=0;
		int count0=0;
		for(int i=0;i<n;i++){
			if(b[i]==2)count2++;
			else if(b[i]==1)count1++;
			else if(b[i]==0)count0++;
		}
		if(count1==0){
			if(count2>=count0-1){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
		else{
			if(count2>=count0){
				System.out.println("Yes");
			}else{
				System.out.println("No");
			}
		}
	}
	int check(int n){
		int ret=0;
		while(true){
			if(ret>=2){
				return ret;
			}
			if(n%2==0){
				n/=2;
				ret++;
			}else{
				break;
			}
		}
		return ret;
	}
}

Measured memory_bytes: 50472
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-8;
const int inf=1e8;
int main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(a+b==c||a+c==b||b+c==a)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}
/*int main(){
	int n,m,s;
	while(cin>>n>>m>>s,n+m+s){
		vvi in(n,vi(3));
		rep(i,n)rep(j,3)cin>>in[i][j];
		vvp area(n);
		rep(i,n)rep(j,n){
			
		}
	}
}//*/












Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main() {
	int N,A,B,hs[100008];
	cin >> N >> A >> B;
	for(int i=0;i<N;i++) cin >> hs[i];
	int minv=0;
	int maxv=1000000008;
	while(minv<maxv) {
		int hf=(minv+maxv)/2;
		long long A_total=0;
		for(int i=0;i<N;i++) {
			long long req=(long long)hs[i] - (long long)hf * B;
			if(req>0) {
				if(req % (A-B)) {
					A_total+=req/(A-B)+1;
				} else {
					A_total+=req/(A-B);
				}
			}
		}
		if(hf<A_total) {
			minv=hf+1;
		} else {
			maxv=hf;
		}
	}
	cout << minv << endl;
	return 0;
}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {

            int N = in.nextInt();
            for (int i = 0; i < N; i++) {
                long A = in.nextLong();
                long B = in.nextLong();

                long a = Math.min(A, B);
                long b = Math.max(A, B);

                long ans = 2L * (a - 1) + przedzial(a, b);

                out.println(ans);
            }
        }

        private long przedzial(long a, long b) {
            if (a == b || a + 1 == b) {
                return 0;
            }

            return 1L + szukaj(a + 1, b - 2, a * b);
        }

        private long szukaj(long a, long b, long LIMIT) {
            if (a > b) return 0;
            if (a == b) {
                return a * b < LIMIT ? 1 : 0;
            }
            long lo = a, hi = b;

            while (lo + 1 < hi) {
                long m = lo + (hi - lo) / 2;

                if (m * m >= LIMIT) {
                    hi = m;
                } else {
                    lo = m;
                }
            }

            long ans1 = 1 + 2L * (lo - 1 - a + 1);
            long ans2 = 0;
            if (lo * (lo + 1) < LIMIT) {
                ans2 = 2L * (lo - a + 1);
            }

            return Math.max(ans1, ans2);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

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

    }
}



Measured memory_bytes: 21460
using namespace std;
#include <bits/stdc++.h>
#define rep(i, s) for (int i = 0; i < s; ++i)
#define repr(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define all(v) (v.begin(), v.end())
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
#define EPS (1e-7)
#define INF (1e10)
#define PI (acos(-1))
const ll mod = 1000000007;
bool f(string s){
  bool ans=true;
  rep(i,s.size()/2){
    if(s[i]!=s[s.size()/2+i]){
      ans=false;
      break;
    }
  }
  return ans;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string N;
  cin>>N;
  if (N=="SUN")
    cout<<7<<endl;
  if (N=="MON")
    cout<<6<<endl;
  if (N=="TUE")
    cout<<5<<endl;
  if (N=="WED")
    cout<<4<<endl;
  if (N=="THU")
    cout<<3<<endl;
  if (N=="FRI")
    cout<<2<<endl;
  if (N=="SAT")
    cout<<1<<endl;
}


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

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

int main(){

    int A, B;
    cin >> A >> B;

    int h = 100, w = 100;
    cout << h << " " << w << endl;

    --A, --B;
    REP(i, h/2-1){
        REP(j, w){
            if(i%2 == 0 and A > 0){
                cout << ".#";
                --A, ++j;
            }else cout << "#";
        }
        cout << endl;
    }
    REP(j, w) cout << "#"; cout << endl;
    REP(j, w) cout << "."; cout << endl;
    REP(i, h/2-1){
        REP(j, w){
            if(i%2 == 0 and B > 0){
                cout << "#.";
                --B, ++j;
            }else cout << ".";
        }
        cout << endl;
    }

    return 0;

}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

class Main {
    final double eps = 1e-10;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            Double[] list = Arrays.stream(sc.nextLine().split(",")).map(Double::parseDouble).toArray(Double[]::new);
            Point a = new Point(list[0],list[1]);
            Point b = new Point(list[2],list[3]);
            Point c = new Point(list[4],list[5]);
            Point d = new Point(list[6],list[7]);
            System.out.println(innerTriangle(a, b, c, d) || innerTriangle(a, c, d, b) || innerTriangle(a, b, d, c) || innerTriangle(b, c, d, a) ? "NO" : "YES");
        }
    }

    static Point sub(Point a, Point b) {
        return new Point(b.x - a.x, b.y - a.y);
    }

    static double cross(Point a, Point b) {
        return a.x * b.y - a.y * b.x;
    }

    static boolean innerTriangle(Point a, Point b, Point c, Point p) {
        return cross(sub(a, b), sub(b, p)) < 0.0 &&
                cross(sub(b, c), sub(c, p)) < 0.0 &&
                cross(sub(c, a), sub(a, p)) < 0.0 ||
                cross(sub(a, b), sub(b, p)) > 0.0 &&
                        cross(sub(b, c), sub(c, p)) > 0.0 &&
                        cross(sub(c, a), sub(a, p)) > 0.0 ? true : false;
    }
}

class Point {
    double x;
    double y;

    Point(double x, double y) {
        this.x = x;
        this.y = y;
    }
}


Measured memory_bytes: 31884
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<map>
#define int long long 
using namespace std;

signed main() {
	int N,A,B;
	cin >> N >> A >> B;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int answer = 0;
	for(int i = 0;i < N - 1;i++) {
		answer += min((vec.at(i + 1) - vec.at(i)) * A,B);
	} 
	cout << answer << endl;
}

Measured memory_bytes: 1024
/* ****Ragnar7 _Lawliet_**** */
/* First, solve the problem.Then write the code. */
#include<bits/stdc++.h>
#define ll          long long
#define ld 			long double
#define hell        1000000007
#define time        cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifndef ONLINE_JUDGE
	freopen ("input.txt","r",stdin);
	// freopen ("output.txt","w",stdout);
	#endif
	ll t = 1;
	// cin>>t;
	while(t--)
	{
		ll x,k,d;
		cin>>x>>k>>d;
		x = abs(x);
		ll req = x/d;
		ll pos = x - min(req,k)*d;
		k -= min(req,k);
		if(k%2==0)
			cout<<pos;
		else
			cout<<abs(pos-d);

		
	}

	
	time
	return 0;
}

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

#define int long long
#define ll long long
#define pb push_back

main(){
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    int f[a];
    int s[b];
    int t[c];
    for(int i = 0; i < a; i++) cin >> f[i];
    for(int i = 0; i < b; i++) cin >> s[i];
    sort(f, f + a);
    sort(s, s + b);
    for(int i = 0; i < c; i++) cin >> t[i];
    vector<int> all;
    for(int i = a - x; i < a; i++) all.pb(f[i]);
    for(int i = b - y; i < b; i++) all.pb(s[i]);
    for(int i = 0; i < c; i++) all.pb(t[i]);
    sort(all.begin(), all.end());
    int ans = 0;
    for(int i = c; i < x + y + c; i++) ans += all[i];
    cout << ans;
}


Measured memory_bytes: 8816
#include <bits/stdc++.h>
#define pb push_back
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ggdem=b;i<ggdem;++i)
#define SZ(x) ((int)x.size())
#define ALL(x) x.begin(),x.end()
#define mset(a,v) memset((a),(v),sizeof(a))
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;

int main(){FIN;
	ll n; cin>>n;
	ll a[n+1];
	fore(i,0,n+1)cin>>a[i];
	ll res=0,dd=1;
	ll d[n+1];
	fore(i,0,n+1){
		if(dd>=1e18){
			d[i]=dd;
			continue;
		}
		dd-=a[i];
		d[i]=dd;
		if(dd<0){
			cout<<-1;
			return 0;
		}
		dd*=2;
	}
	ll h=0;
	fore(i,0,n+1){
		
		//h+=a[n-i];
		h=min(h,d[n-i])+a[n-i];
		res+=h;
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 5184
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
#include<bits/stdc++.h>
using namespace std;
int main(){
  int x,t,a;
  cin >> x >> t >> a;
  int h[x];
  rep(i,x) cin >> h[i];
  double min = t - h[0]*0.006;
  double sa = abs(a-min);
  int ans = 1;
  repi(i,1,x){
    double chiten = t-h[i]*0.006;
    if(sa>abs(a-chiten)){
      sa = abs(a-chiten);
      ans = i+1;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <cstring>
#include <functional>
#include <cctype>
#include <locale>
#include <complex>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<long long,long long> Pll;
#define fout(num) cout << fixed << setprecision(20) << (num) << endl
//s[i]=tolower(s[i]); islower(s[i]); cout << tolower(s[i])はバグ
//vector<vector<ll>> dp(n,vector<ll>(n))
//2-dim:vector<vector<Type>> vv(n, vector<Type>(m, d));
//3-dim:vector<vector<vector<Type>>> vvv(n, vector<vector<Type>>(m, vector<Type>(l, d)));
typedef complex<double> Complex;
const double PI = acos(-1);
struct FastFourierTransform{
private:
    static void dft(vector<Complex>& func,int inverse){
        int sz=(int)func.size();
        if(sz==1) return;
        vector<Complex> f0,f1;
        for(int i=0;i<sz/2;i++){
            f0.push_back(func[2*i+0]);
            f1.push_back(func[2*i+1]);
        }
        dft(f0,inverse);
        dft(f1,inverse);
        Complex zeta = Complex(cos(2.0*PI/sz),sin(2.0*PI/sz)*inverse);
        Complex pow_zeta = 1;
        for(int i=0;i<sz;i++){
            func[i]=f0[i%(sz/2)]+pow_zeta*f1[i%(sz/2)];
            pow_zeta*=zeta;
        }
    }
public:
    template<typename T>
    static vector<double> multiply(vector<T> f,vector<T> g){
        int sz=1;
        vector<Complex> nf,ng;
        while(sz<(int)f.size()+(int)g.size()) sz*=2;
        nf.resize(sz);
        ng.resize(sz);
        for(int i=0;i<(int)f.size();i++){
            nf[i]=f[i];
            ng[i]=g[i];
        }
        dft(nf,1);
        dft(ng,1);
        for(int i=0;i<sz;i++) nf[i]*=ng[i];
        dft(nf,-1);
        vector<double> ret;
        for(int i=0;i<sz;i++) ret.push_back(nf[i].real()/sz);
        return ret;
    }
};

signed main(){
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    int n; cin >> n;
    ll m; cin >> m;
    vector<int> f(100100,0);
    rep(i,n){
        int a; cin >> a;
        f[a]++;
    }
    vector<double> res=FastFourierTransform::multiply(f, f);
    ll cnt=0;
    ll ans=0;
    int now=200200;
    while(cnt<=m){
        if(cnt+res[now]>m){
            ll x=m-cnt;
            ans+=x*now;
            break;
        }
        cnt+=(ll)(res[now]+0.1);
        ans+=(ll)(res[now]+0.1)*now;
        now--;
    }
    cout << ans << endl;
}




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

using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef unsigned long long ull;

typedef pair < db, db > pdd;
typedef pair < db, ld > pdl;
typedef pair < ld, db > pld;
typedef pair < ld, ld > ldp;

typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;

#define F first
#define S second

#define en end()
#define bg begin()

#define rev reverse
#define mp make_pair
#define pb push_back

#define y1 y1234567890
#define um unordered_map

#define all(x) x.bg, x.en
#define sz(x) (int)x.size()
#define len(x) (int)strlen(x)

#define sqr(x) ((x + 0ll) * (x))
#define sqrd(x) ((x + 0.0) * (x))

#define forn(i, n) for (int i = 1; i <= n; i++)

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;

const db eps = (db)1e-9;
const db pi = acos(-1.0);

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

const int N = 2005;

int n, k, q, a[N], ar[N], arr[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	//freopen(".err", "w", stderr);

	//srand(time(NULL));

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	//cout << setprecision(10) << fixed;
	
	cin >> n >> k >> q;

	for (int i = 1; i <= n; i++)
		cin >> a[i];

	int ans = (int)2e9;

	for (int i = 1; i <= n; i++) {
		int m = 0;
		for (int j = 1; j <= n; j++) {
			if (a[j] < a[i])
				continue;
			int ptr = j - 1, sz = 0;
			while (ptr < n && a[ptr + 1] >= a[i])
				ar[++sz] = a[++ptr];
			sort(ar + 1, ar + 1 + sz);
			for (int it = 1; it <= sz - k + 1; it++)
				arr[++m] = ar[it];
			j = ptr;
		}
		sort(arr + 1, arr + 1 + m);
		if (m >= q)
			ans = min(ans, arr[q] - a[i]);
	}

	cout << ans;
	
	//cerr << (clock() + 0.0) / CLOCKS_PER_SEC;

	return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(o,0,n)cout<<v[o]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 

#define M 100010


int main(){
	IOS;
	tihs;
	
	ll a,b,m;cin>>a>>b>>m;
	ll aa[a],bb[b];
	ll mn1=inf,mn2=inf;
	rep(i,0,a)cin>>aa[i],mn1=min(mn1,aa[i]);
	rep(i,0,b)cin>>bb[i],mn2=min(mn2,bb[i]);
	ll ans = mn1+mn2;
	rep(i,0,m){
		ll x,y,c;cin>>x>>y>>c;
		ans=min(ans,aa[x-1]+bb[y-1]-c);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 1792
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    V = LI()
    C = LI()
    ans = 0
    for i in range(N):
        ans += max(V[i] - C[i], 0)
    print(ans)



main()



Measured memory_bytes: 83324
//#include<cstdio>
//#include<iostream>
//#include<algorithm>
//#include<vector>
//#include<cstring>
//#include<cmath>
//#include<map>
#include<bits/stdc++.h>
using namespace std;

#define fast ios_base::sync_with_stdio(false)
#define outs(x) cout << x << " "
#define outn(x) cout << x << "\n"
#define sf scanf
#define pf printf

typedef long long LL;
typedef vector<int>vii;
typedef vector<LL>vll;

int main()
{
    fast;
    int a, b, h;
    while(cin >> a >> b >> h)
    {
        outn(((a + b) * h) / 2);
    }

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double

int32_t main()
{                
    IOS;
    
   
    int n;
    cin >> n;
    int a[n][n];
    for(int i = 0;i < n;i++)
    {
        for(int j = 0;j < n;j++)
            cin >> a[i][j];
    }
    int cost[1<<n];

    for(int i = 0;i < (1<<n);i++)
    {
        cost[i] = 0;
        for(int j = 0;j < n;j++)
        {
            for(int k = j+1;k < n;k++)
            {
                if(i & (1<<j))
                {
                    if(i & (1<<k))
                        cost[i] += a[j][k];
                }

            }
        }
    }
    int dp[(1<<n)];
    dp[0] = 0;
    for(int i = 1;i < (1<<n);i++)
    {
        dp[i] = -inf;
        for(int j = i;  ; j = (j - 1)&i)
        {
            dp[i] = max(dp[i],cost[j] + dp[i ^ j]);
            if( j == 0)
                break;
        }
    }
    cout << dp[(1<<n) - 1];
    return 0;

}

Measured memory_bytes: 1280
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long a,b,k;
	cin>>a>>b>>k;
	if(a+b<=k)
	{
		cout<<"0 0\n"<<endl;
		return 0;
	}
	if(a+b>k&&a<=k)
	{
		cout<<0<<" "<<b-(k-a);
		return 0;
	}
	if(a+b>k&&a>=k)
	{
		cout<<a-k<<" "<<b<<endl;
		return 0;
	}
	return 0;
}

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

int main(int argc, char *argv[]) {
	std::string S;
	int N;

	std::cin >> N >> S;

	std::string X;
	std::string Y;
	int max_kinds = INT_MIN;

	for (int i = 1; i < S.size() ; i++) {
		X = S.substr(0, i);
		Y = S.substr(i);

		std::set<char> pair1;
		std::set<char> pair2;

		for (int j = 0; j < X.size(); j++) {
			pair1.insert(X[j]);
		}
		for (int k = 0; k < Y.size(); k++) {
			pair2.insert(Y[k]);
		}

		int common = 0;
		if (pair1.size() >= pair2.size()) {
			for (auto p1 = pair1.begin(); p1 != pair1.end(); p1++) {
				if (pair2.count(*p1) > 0) {
					common++;
				}
			}
			if (common >= max_kinds) {
				max_kinds = common;
			}
		} else {
			for (auto p2 = pair2.begin(); p2 != pair2.end(); p2++) {
				if (pair1.count(*p2) > 0) {
					common++;
				}
			}
			if (common >= max_kinds) {
				max_kinds = common;
			}
		}
	}

	std::cout << max_kinds << std::endl;
	return 0;
}


Measured memory_bytes: 256
def f_minimum_bounding_box(N, Positions, INF=float('inf')):
    # 参考: https://betrue12.hateblo.jp/entry/2019/06/17/202327
    x_dict, y_dict = [{'L': [], 'R': [], 'U': [], 'D': []} for _ in range(2)]
    for x, y, d in Positions:
        x_dict[d].append(int(x) * 2)
        y_dict[d].append(int(y) * 2)

    xs, ys = [], []
    for c in 'LRUD':
        if len(x_dict[c]) != 0:
            xs.extend((max(x_dict[c]), min(x_dict[c])))
        if len(y_dict[c]) != 0:
            ys.extend((max(y_dict[c]), min(y_dict[c])))

    def f(lst, ret=[]):
        for e1 in lst:
            for e2 in lst:
                d = abs(e1 - e2)
                ret.extend((d, d // 2))
        return ret
    time_candidates = f(xs) + f(ys)

    dx = {'L': -1, 'R': 1, 'U': 0, 'D': 0}
    dy = {'L': 0, 'R': 0, 'U': 1, 'D': -1}
    ans = INF
    for d in time_candidates:
        xmax, ymax, xmin, ymin = -INF, -INF, INF, INF
        for c in 'LRUD':
            for i in x_dict[c]:
                x = i + dx[c] * d
                xmax, xmin = max(xmax, x), min(xmin, x)
            for j in y_dict[c]:
                y = j + dy[c] * d
                ymax, ymin = max(ymax, y), min(ymin, y)
        ans = min(ans, (xmax - xmin) * (ymax - ymin) / 4)  # 各座標2倍したため
    return round(ans, 12)

N = int(input())
Positions = [[i for i in input().split()] for j in range(N)]
print(f_minimum_bounding_box(N, Positions))

Measured memory_bytes: 84568
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i = 0; i < (n); i++)
#define MEM(a, x) memset(a, x, sizeof(a))
#define ALL(a) a.begin(), a.end()
#define UNIQUE(a) a.erase(unique(ALL(a)), a.end())
typedef long long ll;

ll n, MOD = 1000000007;

int main(int argc, char const *argv[]) {
	ios_base::sync_with_stdio(false);
	cin >> n;
	ll x = 1;
	for (ll i = 1; i <= n; i++) x = x * i % MOD;
	cout << x << endl;
	return 0;
}

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

int getDigitSum(int x){
    int sum = 0;

    while(x>0){
        sum += x%10;
        x /= 10;
    }
    return sum;
}

int n;

int main()
{
    cin>>n;
    if(n%getDigitSum(n) == 0) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE OR BY WRONG COMPILER
//ABC 173, task a, 2020/07/05
//ms,
/*
*/

int main(void){
  int H, W, K;
  int c[6][6];
  int ans =0;
  //input
  cin >>H >>W >>K;
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      char tmp_c;
      cin >>tmp_c;
      if(tmp_c == '#') c[i][j] = 1;
      else c[i][j] = 0;
    }
  }

  for(int bin=0;bin<(1<<H+W);bin++){
    //bin & (1<<i)==1 → i is red (i<H)
    int tmp_blacks=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(!(bin & (1<<i)) && !(bin & (1<<j+H))) tmp_blacks += c[i][j];
      }
    }
    if(tmp_blacks == K) ans++;
  }

  cout <<ans;
  return 0;
}
/*
計算資源マジで気にしなくていいな。
*/


Measured memory_bytes: 3628
n,m=map(int,input().split())
data=[[] for i in range(3*n+1)]
for i in range(m):
    u,v=map(int,input().split())
    data[u].append(v+n)
    data[u+n].append(v+2*n)
    data[u+2*n].append(v)
s,t=map(int,input().split())
inf=float("inf") 
flag=[inf]*(3*n+1)
flag[s]=0
que=[s]
while que:
    h=[]
    for u in que:
        for v in data[u]:
            if flag[v]==inf:
                flag[v]=flag[u]+1
                h.append(v)
    que=h
if flag[t]==inf:
    print(-1)
else:
    print(flag[t]//3)

Measured memory_bytes: 90468
#include<iostream>
#include<bitset>
#include<string>
using namespace std;
bool iseven(int x){ return x % 2 == 0; }
bool isodd(int x){ return !iseven(x); }

int dist(int x, int y) { return abs(x - y); }
int main(){
    int A, B;
    cin >> A >> B;
    int ncakes = 16;
    // 方針：単純に奇数番目にAを偶数番目にBを割り当ててやればよいはず
    if ((A > ncakes / 2) || (B > ncakes / 2)){ cout << ":("; }
    else { cout << "Yay!"; }
    return 0;
}


Measured memory_bytes: 256