akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        n = n % 10;
        if(n == 3){
            System.out.println("bon");
        }else if(n < 2 || n == 6 || n == 8){
            System.out.println("pon");
        }else{
            System.out.println("hon");
        }
        sc.close();
    }
}

Measured memory_bytes: 35656
s = input()
t = input()
s1 = [str(a) for a in s]
t1 = [str(a) for a in t]
s1.sort()
t1.sort()
import copy
t2 = copy.copy(t1)
for i in range(len(t1)):
  t1[i] = t2[len(t1)-i-1]

n = 0
l = 0
i = 0
while n==0 and i <= min(len(t),len(s))-1:
  if s1[i] == t1[i]:
    l = l + 1
    i = i + 1
  elif s1[i] < t1[i]:
    n = n + 1
    print('Yes')
  elif s1[i] > t1[i]:
    n = n + 1
    print('No')
if l == len(t) and len(t) <= len(s):
  print('No')
elif l == len(s) and len(s) < len(t):
  print('Yes')

Measured memory_bytes: 3700
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(m)]

adj = [[] for _ in range(n)]
for a, b in ab:
    a -= 1
    b -= 1
    adj[a].append(b)
    adj[b].append(a)

group = [0] * n
color = 1


def dfs(s, c):
    stack = [s]
    group[s] = c
    cnt = 1
    while stack:
        u = stack.pop()
        for v in adj[u]:
            if group[v] == 0:
                group[v] = c
                stack.append(v)
                cnt += 1

    return cnt


ans = 0
for i in range(n):
    if group[i] == 0:
        cnt = dfs(i, color)
        color += 1
        ans = max(ans, cnt)

print(ans)


Measured memory_bytes: 133800
#include <iostream>
#include <map>
#define ll long long
using namespace std;

map <ll, int> freq;
ll arr[200005];
ll prefsum[200005];
int main()
{
    int n;
    cin >> n;
    
    prefsum[0] = 0;
    for (int i = 1; i <= n; i++){
        cin >> arr[i];
        prefsum[i] = prefsum[i-1] + arr[i];
    }
    
    freq[0] = 1;
    ll ans = 0;
    for (int i = 1; i <= n; i++){
        ll g = prefsum[i];
        ll f = freq[g];
        if (f > 0){
            ans = ans + f;
        }
        freq[g]++;
    }
    
    
    cout << ans << endl;
    return 0;
}


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

int main() {
    // input
    int N, X;
    cin >> N >> X;
    vector<int> m(N);
    for (int i = 0; i < N; ++i) {
        cin >> m[i];
    }

    // solve
    int ans = 0;
    for (int i = 0; i < m.size(); ++i) {
        X -= m[i];
        ans++;
    }
    if (X > 0) ans += X / *min_element(m.begin(), m.end());

    // output
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i,n) for(int i = 0; i < n; i++)
#define ll long long
using namespace std;

int main(){
  	ll n;
    cin>>n;
    string tmp = " ";
    while( n > 0){
        n -= 1;
        tmp += (char)('a' + n%26);
        n/=26;
    }
    reverse(tmp.begin(), tmp.end());
    cout<<tmp<<endl;
    return 0;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
#define pi acos(-1)
#define mod 1000000007
#define ll long long
#define ull unsigned long long
#define mem(a) memset(a,0,sizeof(a))
#define cio ios::sync_with_stdio(false);

int main()
{
    ll x;
    cin >> x;
    int cnt = 0;
    ll y = 100;
    while(y<x){
        y = y*(1.01);
        // cout << y  << endl;
        cnt++;
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 3632
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(){
		
		var UF = new UnionFind(N);
		for(int i=0;i<M;i++){
			UF.Unite(X[i], Y[i]);
		}
		Console.WriteLine(UF.Compo);
		
		
	}
	int N,M;
	int[] X,Y,Z;
	public Sol(){
		var d = ria();
		N = d[0]; M = d[1];
		X = new int[M];
		Y = new int[M];
		Z = new int[M];
		for(int i=0;i<M;i++){
			d = ria();
			X[i] = d[0] - 1;
			Y[i] = d[1] - 1;
			Z[i] = d[2] % 2;
		}
	}

	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));}
}

class UnionFind{
	
	int[] parent;
	int[] mem;
	int compo;
	int N;
	public UnionFind(int n_){
		Initialize(n_);
	}
	
	public void Initialize(int n_){
		N=n_;
		parent=new int[N];
		mem=new int[N];
		for(int i=0;i<N;i++){
			parent[i]=i;
			mem[i]=1;
		}
		compo=N;
	}
	
	public int Parent(int a){
		if(parent[a]==a) return a;
		return parent[a] = Parent(parent[a]);
	}
	
	public bool IsUnited(int a,int b){
		return Parent(a) == Parent(b);
	}
	
	public void Unite(int a,int b){
		a = Parent(a); b = Parent(b);//Parent()を呼ぶことでa以上のノードは全てparentがrootになる
		if(a == b) return;
		parent[a] = b;
		mem[b] += mem[a];
		compo -= 1;
	}
	
	public bool IsRoot(int x){
		return x == parent[x];
	}
	public int MemCnt(int x){
		return mem[Parent(x)];
	}
	
	public void Dump(){
		for(int i=0;i<parent.Length;i++){
			Console.Write(i==0?"{0}":" {0}",parent[i]);
		}
		Console.WriteLine("");
	}
	
	public int Compo{
		get{
			return compo;
		}
	}
	
}


Measured memory_bytes: 17216
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

long long int power(long long int x, long long int n, long long int M) {
	long long int tmp = 1;
	if (n > 0) {
		tmp = power(x, n / 2, M);
		if (n % 2 == 0) tmp = (tmp*tmp) % M;
		else tmp = (((tmp*tmp) % M)*x) % M;
	}
	return tmp;
}

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

	string s;
	cin >> s;
	s = 'D' + s + 'D';
	N = s.size();
	vector<long long int>a(N);
	vector<long long int>c(N);
	vector<long long int>lq(N);
	vector<long long int>rq(N);
	for (int i = 0; i < N; i++) {
		if (s[i] == 'A') {
			a[i]++;
		}
		if (s[i] == '?') {
			lq[i]++;
		}
		if (i) {
			a[i] += a[i - 1];
			lq[i] += lq[i - 1];
		}
	}
	for (int i = N - 1; i >= 0; i--) {
		if (s[i] == 'C') {
			c[i]++;
		}
		if (s[i] == '?') {
			rq[i]++;
		}
		if (i != N - 1) {
			c[i] += c[i + 1];
			rq[i] += rq[i + 1];
		}
	}
	vector<long long int>by(100001);
	by[1] = 1;
	for (int i = 2; i <= 100000; i++) {
		by[i] = by[i - 1] * 3 + power(3, i - 1, MOD);
		by[i] %= MOD;
	}
	long long int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (s[i] == 'B' || s[i] == '?') {
			long long int aadd = by[lq[i - 1]] + a[i] * power(3, lq[i - 1], MOD);
			aadd %= MOD;
			long long int cadd = by[rq[i + 1]] + c[i] * power(3, rq[i + 1], MOD);
			cadd %= MOD;
			ans += aadd * cadd;
			ans %= MOD;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4332
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;

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

    string s;
    cin>>s;
    bool flag = false;
    rep(i,s.size())if(s[i] == '7')flag = true;
    if(flag)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int x[N];
  int y[N];
  int a[N];
  
  for (int i = 0; i < N; i++) {
    cin >> x[i];
    cin >> y[i];
    a[i] = i;
  }
  
  double sum = 0;
  int count = 0;
  do {
    for (int i = 0; i < N-1; i++) {
      double tmp = (x[a[i]]-x[a[i+1]]) * (x[a[i]]-x[a[i+1]])
      + (y[a[i]]-y[a[i+1]]) * (y[a[i]]-y[a[i+1]]);
      sum += sqrt(tmp);
    }
    count++;
  } while(next_permutation(a, a+N));
  
  cout << fixed << setprecision(6) << sum/count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include <list>
using namespace std;
using ll=long long;
const ll MAX=3e2+5,mod=998244353,inf=0x3f3f3f3f3f3f3f3f;
#define X first
#define Y second
#define pb push_back

typedef pair < int , int > ii;
int n;
ll a[30];
ll solve(int l,int r,ll p1,ll p2){
    if(l+1==r) return 0;
    ll temp=inf;
    for(int i=l+1;i<r;i++) {
        temp=min(temp,solve(l,i,p1,p1+p2)+solve(i,r,p1+p2,p2)+a[i]*(p1+p2));
    }
    return temp;
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("agc046.inp","r",stdin);
    //freopen("agc046.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    cout<<solve(1,n,1,1)+a[1]+a[n];
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
const long long int INF = 1e18;

int main(){
    int n;
    long long int W;
    cin >> n >> W;

    vector<long long int> w(n), v(n);
    for(int i=0; i<n; i++){
        cin >> w[i] >> v[i];
    }
    
    // dp[i][j] = max_value among realization of value <= j, using up to i-th item)
    vector<vector<long long int>> dp(n+1,vector<long long int>(1000*n+1, INF));
    dp[0][0] = 0;

    for(int i=0; i<n; i++){
        for(int j=0; j<=1000*n; j++){
            if(j >= v[i]) dp[i+1][j] = min(dp[i+1][j], dp[i][j-v[i]] + w[i]);
            dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
        }
    }
    
    long long int ans = 0;
    for(int j=0; j<=1000*n; j++){
        if(dp[n][j] <= W) ans = j;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
   int n;
   cin >> n;
   vector<long> a(3*n);
   for (int i=0;i<3*n;i++){
      cin >> a.at(i);
   }
   sort(a.begin(),a.end());
   long sum=0;
   for (int i=n;i<3*n;i+=2){
      sum+=a.at(i);
   }
   cout << sum << endl;
}

Measured memory_bytes: 2560
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)
#include <functional> // std::function<void(int)>

#define rep(i,n) for(int i = 0; i < (n); i++)
#define ENDL '\n'
#define print(i) std::cout << (i) << '\n'

#define int long long // at least int64 > 9*10^18
#define all(v) (v).begin(), (v).end()
/* libraries */

signed main() {
	int n,k;
	std::cin >> n >> k;
	int count = 0;
	rep(i,n) {
		int h;
		std::cin >> h;
		if(h>=k) count++;
	}
	print(count);

	return 0;
}


Measured memory_bytes: 256
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var mod = 1e9+7;
function mul(){for(var a=arguments,r=a[0],i=a.length;--i;)r=((r>>16)*a[i]%mod*65536+(r&65535)*a[i])%mod;return r;}
var fac=[],finv=[],invs=[],pow2=[];
function fset(n){
  fac.length=n+1,fac[0]=fac[1]=1;
  for(var i=2;i<=n;)fac[i]=mul(fac[i-1],i++);
  finv.length=n+1,finv[0]=finv[1]=1,finv[n]=inv(fac[n]);
  for(i=n;2<i;)finv[i-1]=mul(finv[i],i--);
  invs.length=n+1,invs[0]=invs[1]=1;
  for(i=2;i<=n;)invs[i]=mul(fac[i-1],finv[i++]);
  pow2.length=n+1,pow2[0]=1;
  for(i=1;i<=n;i++)pow2[i]=pow2[i-1]*2%mod;
}
function inv(b){for(var a=mod,u=0,v=1,t;b;v=t)t=a/b|0,a-=t*b,u-=t*v,t=a,a=b,b=t,t=u,u=v;u%=mod;return u<0?u+mod:u;}
function pow(a,n){for(var r=1;n;a=mul(a,a),n>>=1)if(n&1)r=mul(a,r);return r;}
function ncr(n,r){return mul(fac[n],finv[r],finv[n-r]);}
function npr(n,r){return mul(fac[n],finv[r]);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var n = next(), a = next(), b = next();
  var ans = pow(2,n) - 1, x = 1;
  for(var i = 1; i <= b; i++){
    x = mul(x,n-i+1,inv(i));
    if(i === a)ans -= x;
  }
  ans -= x;
  ans %= mod;
  ans += mod;
  return ans %= mod;
}

Measured memory_bytes: 10060
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<algorithm>
#include<cstdio>
#include<stdio.h>
#include<stack>
#include<sstream>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<list>
#include<numeric>
#include <utility>
typedef long long ll;

#define pi 3.14159265358979323846
#define VI vector<int>
#define VLL vector<long long>
#define MAX max_element
#define MIN min_element
#define all(v) v.begin(), v.end()
const ll MOD = 1e9 + 7;
const ll unllMOD = 1e18;
using namespace std;
template<typename T>
T gcd(T a, T b) {
	return b ? gcd(b, a % b) : a;
}
template<typename T>
T lcm(T a, T b) {
	return a * b / gcd(a, b);
}

template<typename T>
T binarysearch(vector<T> A, T key) {
	ll left = 0;ll right = 4;ll mid;
	while (left < right) {
		mid = (left + right) / 2;
		if (key == A[mid]) return 1;
		if (key > A[mid]) left = mid + 1;
		else if (key < A[mid]) right = mid;
	}
	return 0;
}

template<typename T>
T finder(vector<T> vec, T number) {
	auto itr = find(vec.begin(), vec.end(), number);
	size_t index = distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}
ll frac(ll n)//階乗
{
	if (n == 0) {
		return 1;
	}
	return (n * frac(n - 1)) % MOD;
}

template<typename T>
T keta(T a) {
	ll kazu = 1;
	while (1) {
		if (a / 10 != 0) { a /= 10;kazu++; }
		else break;
	}
	return kazu;
}//桁数


template<typename T>
T nCr(ll n, T r) {
	ll ans = 1;
	for (int i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (int i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
/*char r[4];
int yaju[4];
char op[3];
int sum = 0;
scanf("%s", r);
for (int i = 0;i < 4;i++) {
	yaju[i] = r[i] - '0';
}
*///map < string, ll> s;

/*i++ずつずらす
a[0] a[1] a[2]//a[1] a[2] a[3]
a[0] a[2] a[4]//a[1] a[3] a[5]
/*if (N % 2 != 0)a = N / 2;
else a = N / 2 - 1;
for (int i = 1;i <= a;i++) {
	for (int j = 0;j < N - (i * 2);j++) {
		if (S[j] != S[j + i] && S[j + i * 2] != S[j] && S[j + i] != S[j + i * 2]) sum--;
		if (sum == 0)break;
	}
}*/

//mapの使い方
/*map<int, int> mp;
for (int i = 0; i < N; i++)
	mp[a[i]]++;

int ans = 0;
for (auto p : mp) {
	int x = p.first;
	int n = p.second;
	if (n < x) ans += n;
	else ans += n - x;
}*/
//cout << std::fixed << std::setprecision(12) <<<< endl;

int main() {
	ll N;
	cin>>N;
	vector<ll> a(N);
	ll ans=1;
	bool ok=1;
	for(ll i=0;i<N;i++){
		cin>>a[i];
		if(a[i]==0){
			ans=0;
			ok=0;
		}
	}
	if(ok){
		for(ll i=0;i<N;i++){
			if(a[i]>1000000000000000000/ans){ans=-1; break;}
			ans*=a[i];
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3992
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<climits>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<numeric>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i = m; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a)  (a).rbegin(),(a).rend()
#define PI 3.14159265359
typedef long long LL;

template<class T> inline void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> inline void chmin(T& a, T b) { if (a > b) { a = b; } }
template<class T> void print_vector(vector<T> vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << vec[i] << " ";
	}
	cout << "]" << endl;
}
template<class T> void print_pair_vector(vector<pair<T, T> > vec) {
	cout << "[ ";
	for (int i = 0; i < vec.size(); i++) {
		cout << "(" << vec[i].first << "," << vec[i].second << ") ";
	}
	cout << "]" << endl;
}

const int INF = 1 << 30;

int main(void) {
	string S;
	cin >> S;

	string ans;

	for (int i = 0; i < S.size(); i++)
	{
		if (S[i] == '0') {
			ans.push_back('0');
		}
		else if (S[i] == '1') {
			ans.push_back('1');
		}
		else if (!ans.empty()) {
			ans.pop_back();
		}
		else {
			continue;
		}
	}

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

Measured memory_bytes: 256
#include <string>
#include <iostream>

int main(){
std::string O, E;

std::getline(std::cin, O);
std::getline(std::cin, E);

for (unsigned int i = 0; i < O.length(); ++i){
std::cout << O[i];
if (i < E.length()){
std::cout << E[i];
}
}

std::cout << std::endl;

return 0;
}

Measured memory_bytes: 256
H,W = map(int, input().split())
A = [input() for _ in range(H)]
ind_H = []
ind_W = []
for h,a in enumerate(A):
    if '#' in a:
        ind_H.append(h)
        for w,s in enumerate(a):
            if s == '#':
                ind_W.append(w)
for h in ind_H:
    ans = ''
    for w in range(W):
        if w in ind_W:
            ans += A[h][w]
    print(ans)


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

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b;
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
def main():
    _ = int(input())
    A = [int(x) for x in input().split()]

    highest = 0
    ans = 0
    for a in A:
        if a > highest:
            highest = a
        else:
            ans += highest - a
    print(ans)


if __name__ == '__main__':
    main()


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


int main() {
  int n;
  int c = 0;
  int ansa = 0, ansb = 0;
  cin >> n;
  vector<int> A(n);
  vector<int> B(n);
  vector<int> C(n);
  rep(i, n) A[i] = i + 1;
  rep(i, n) cin >> B[i];
  rep(i, n) cin >> C[i];
  while (next_permutation(A.begin(), A.end())){
    c++;
    if (A == B){
      ansa = c;
    }
    if(A == C) ansb = c;
  }
  cout << abs(ansa - ansb) << endl;
  return 0;
}

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

int n,m,a,p,q,h;

int main() {
    while(cin>>n>>m>>a, n|m|a) {
        vector<pair<int,int> > amida[1010];

        for(int i=0; i<m; ++i) {
            cin>>h>>p>>q;
            amida[h].push_back(make_pair(p,q));
        }

        int pos = a;
        for(int i=1009; i>=0; --i)
            for(int j=0; j<amida[i].size(); ++j) {
                if(amida[i][j].first == pos) pos = amida[i][j].second;
                else if(amida[i][j].second == pos) pos = amida[i][j].first;
            }

        cout<<pos<<endl;
    }
}

Measured memory_bytes: 932
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;
string s;
int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    while(cin >> n >> s){
        vector<map<string, int>> mp(n + 1);
        REP(b, 1 << n) {
            string t;
            int bits = 0;
            REP(i, n) {
                if (b & (1 << i)) {
                    t.push_back(s[i]);
                    bits ++;
                }
            }
            RREP(i, n) {
                if (!(b & (1 << i))) {
                    t.push_back(s[i]);
                }
            }
            mp[bits][t] ++;
        }
        ll ans = 0;
        REP(b, 1 << n) {
            string t;
            int bits = 0;
            RREP(i, n) {
                if (!(b & (1 << i))) {
                    t.push_back(s[n + i]);
                    bits ++;
                }
            }
            REP(i, n) {
                if (b & (1 << i)) {
                    t.push_back(s[n + i]);
                }
            }
            ans += mp[bits][t];
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 73984
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define forn1(i, n) for (int i = 1; i < int(n); i++)
ll mod=1000000007;


int main() {
    std::ios::sync_with_stdio(false);
    string s,s1="";
    ll k;
    cin>>s>>k;
    s1=s+s;
    int n=s.size();
    if(n==1){
        ll ans=k/2;
        cout<<ans;
        return 0;
    }
    ll co=1,a=0,b=0,fl=0;
    forn1(i,n){
        if(s[i]==s[i-1])co++;
        else{
            fl=1;
            a+=co/2;
            co=1;
        }
    }
    if(fl==0){
        ll ans=k*n;
        ans=ans/2;
        cout<<ans;
        return 0;
    }
    a+=co/2;
    co=1;
    forn1(i,s1.size()){
        if(s1[i]==s1[i-1])co++;
        else{
            b+=co/2;
            co=1;
        }
    }
    b+=co/2;
    ll d=b-a;
    ll ans=d*(k-1);
    ans+=a;
    cout<<ans;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n, k, a[100001], f[100001], rt;
int main()
{
    //freopen("test.inp","r",stdin);
    //freopen("test.out","w",stdout);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        f[i]=1e9;
    }
    f[1]=0;
    f[0]=1e9;
    a[0]=-1e9;
    for(long long i=2;i<=n;i++)
    {
        rt=min(i,k);
        for(int j=1;j<=rt;j++)
            f[i]=min(f[i], f[i-j]+abs(a[i]-a[i-j]));
    }
    cout<<f[n];
    return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <stack>
#include <fstream>
#include <cmath>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)

using namespace std;

struct UnionFind {
    vector<ll> par;

    UnionFind(ll N) : par(N) {
        Rep (i, N) par[i] = i;
    }

    ll root (ll x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

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

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

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

    ll N;
    cin >> N;
    vector<ll> A(N), B(N);
    vector<pair<ll, ll>> a(N), p(N);
    Rep (i, N) {
        cin >> A[i];
    }
    Rep (i, N) cin >> B[i];
    Rep (i, N) {
        p[i] = make_pair(B[i], A[i]);
    }
    sort(p.begin(), p.end());
    Rep (i, N) {
        a[i] = make_pair(p[i].second, i);
    }
    sort(a.begin(), a.end());
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());

    Rep (i, N) {
        if (A[i] > B[i]) {
            cout << "No\n";
            return 0;
        }
    }    

    UnionFind tree(N);
    Rep (i, N) {
        tree.unite(i, a[i].second);
    }

    set<ll> s;
    Rep (i, N) {
        s.insert(tree.root(i));
    }

    // cout << s.size() << "\n";

    if (s.size() > 1) {
        cout << "Yes\n";
        return 0;
    }

    Rep (i, N-1) {
        if (B[i] >= A[i+1]) {
            cout << "Yes\n";
            return 0;
        }
    }

    cout << "No\n";
    return 0;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;

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

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

int main() {
  int N;
  cin >> N;
  vector<ll> a(N);
  map<ll, ll> m;
  rep(i, N) {
    cin >> a[i];
    m[a[i]]++;
  }

  if (m.size() == 3) {
    if (N % 3 != 0) {
      cout << "No" << endl;
      return 0;
    }
    ll X[3];
    ll i = 0;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
      X[i] = (iter->fi);
      if ((iter->se) != N / 3) {
        cout << "No" << endl;
        return 0;
      }
      i++;
    }
    if ((X[0] ^ X[1] ^ X[2]) == 0) {
      cout << "Yes" << endl;
      return 0;
    } else {
      cout << "No" << endl;
      return 0;
    }

  } else if (m.size() == 2) {
    if (N % 3 != 0) {
      cout << "No" << endl;
      return 0;
    }
    ll X[2];
    ll cnt[2];
    ll i = 0;
    for (auto iter = m.begin(); iter != m.end(); iter++) {
      X[i] = iter->fi;
      cnt[i] = iter->se;
      i++;
    }
    if (X[0] > X[1]) {
      swap(X[0], X[1]);
      swap(cnt[0], cnt[1]);
    }
    if (X[0] == 0 && cnt[1] == N * 2 / 3) {
      cout << "Yes" << endl;
      return 0;
    } else {
      cout << "No" << endl;
      return 0;
    }

  } else if (m.size() == 1) {
    auto iter = m.begin();
    ll X = iter->fi;
    if (X == 0) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }

  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 5632
n = int(input())
L = list(map(int, input().split()))

L.sort()
cnt = 0

for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            cnt += L[i] + L[j] > L[k] and L[i] != L[j] != L[k]

print(cnt)


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

#define whole(f, x, ...)                                 \
  ([&](decltype((x)) whole) {                            \
    return (f)(begin(whole), end(whole), ##__VA_ARGS__); \
  })(x)

using namespace std;
using ll = long long;

void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> um(n, -1);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    --s;
    if (um[s] == -1) {
      um[s] = c;
    } else if (um[s] == c) {
      continue;
    } else {
      cout << -1 << endl;
      return;
    }
  }

  if (n != 1 && um[0] == 0) {
    cout << -1 << endl;
    return;
  }
  if (n == 1 && um[0] == -1) um[0] = 0;

  if (n != 1 && um[0] == -1) um[0] = 1;

  for (int i = 0; i < n; i++)
    if (um[i] == -1) um[i] = 0;

  int ans = um[0];
  for (int i = 1; i < n; i++) {
    ans *= 10;
    ans += um[i];
  }

  cout << ans << endl;
}

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

  solve();
  return 0;
}


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

int main() {
  int n, l;
  cin >> n >> l;
  bool answer = false;
  vector<int> aji(n); //りんごの味
  for(int i = 0; i < n; i++){
    aji.at(i) = l + i;
    if(l + i == 0){
      answer = true; //0があるかどうか判断
    }
  }
  auto pie = 0; //すべてのりんごを使ったアップルパイ
  for(int i = 0; i < n; i++){
    pie += aji.at(i);
  }
  //食べるりんごを判断
  if(answer == true){
    cout << pie << endl;
  }
  else if(answer == false && pie > 0){
    sort(aji.begin(), aji.end());
    cout << pie - aji.at(0) << endl;
  }
  else if(answer == false && pie < 0){
    sort(aji.begin(), aji.end());
    reverse(aji.begin(), aji.end());
    cout << pie - aji.at(0) << endl;
  }
}


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

int main(){
	int N; cin>>N;
	vi A(N), B(N), C(N-1);
	rp(i,N){cin>>A[i]; --A[i];}//Ai={0~N-1}
	rp(i,N) cin>>B[i];
	rp(i,N-1) cin>>C[i];

	int ans = 0;
	rp(i,N){
		ans += B[A[i]];
		if(i>0 && A[i]==A[i-1]+1) ans += C[A[i-1]];
	}
	cout<< ans <<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import deque

H,W,K=map(int,input().split())
x1,y1,x2,y2=map(int,input().split())
MAP=[list(input().strip()) for i in range(H)]

for i in range(H):
    for j in range(W):
        if MAP[i][j]==".":
            MAP[i][j]=1<<30
        else:
            MAP[i][j]=-1

Q=deque()
Q.append((x1-1,y1-1))
MAP[x1-1][y1-1]=0

while Q:
    x,y=Q.pop()

    for i in range(1,K+1):
        if 0<=x+i<H and 0<=y<W and (MAP[x+i][y]==1<<30 or MAP[x+i][y]>MAP[x][y]):
            if MAP[x+i][y]==1<<30:
                MAP[x+i][y]=MAP[x][y]+1
                Q.appendleft((x+i,y))
        else:
            break

    for i in range(1,K+1):
        if 0<=x-i<H and 0<=y<W and (MAP[x-i][y]==1<<30 or MAP[x-i][y]>MAP[x][y]):
            if MAP[x-i][y]==1<<30:
                MAP[x-i][y]=MAP[x][y]+1
                Q.appendleft((x-i,y))
        else:
            break

    for i in range(1,K+1):
        if 0<=x<H and 0<=y+i<W and (MAP[x][y+i]==1<<30 or MAP[x][y+i]>MAP[x][y]):
            if MAP[x][y+i]==1<<30:
                MAP[x][y+i]=MAP[x][y]+1
                Q.appendleft((x,y+i))
        else:
            break

    for i in range(1,K+1):
        if 0<=x<H and 0<=y-i<W and (MAP[x][y-i]==1<<30 or MAP[x][y-i]>MAP[x][y]):
            if MAP[x][y-i]==1<<30:
                MAP[x][y-i]=MAP[x][y]+1
                Q.appendleft((x,y-i))
        else:
            break
if MAP[x2-1][y2-1]==1<<30:
    print(-1)
else:
    print(MAP[x2-1][y2-1])


Measured memory_bytes: 168796
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
ll n,ans;
int main(){
	cin>>n;
	for(ll i=1;i*i<=n;i++){
		if(n%i != 0) continue;
		ll M = i-1;
		ll A = n/i;
		if(0<=A && A<M){
			ans+=M;
		}
		if(i*i==n) continue;
		M = n/i-1;
		A = i;
		if(0<=A && A<M){
			ans+=M;
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

double g, kg[] = { 48, 51, 54, 57, 60, 64, 69, 75, 81, 91 };
string c[] = { "light fly", "fly", "bantam", "feather", "light",
"light welter", "welter", "light middle", "middle", "light heavy",
"heavy" };

int main(){
	while (cin >> g){
		bool f = 0;
		for (int i = 0; i < 10; i++){
			if (g <= kg[i]){
				cout << c[i] << endl;
				break;
			}
			if (i == 9)f = 1;
		}
		if (f)cout << c[10] << endl;
	}
}

Measured memory_bytes: 1228
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <deque>
using namespace std;

#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF (1LL<<60)
#define MOD 1000000007
typedef pair<long long, long long> P;

struct SlideMin {
  long long *src;
  int right;
  deque<P> deq;
  SlideMin() : src(NULL), right(0) {}
  SlideMin(long long *src) : src(src), right(0) {}
  void add(int x, long long y) {
    while (!deq.empty() && deq.back()._2 >= y) deq.pop_back();
    deq.push_back(P(x, y));
  }
  long long query(int l, int r) {
    while (right <= r) {
      add(right, src[right]);
      right++;
    }
    while (!deq.empty() && deq.front()._1 < l) deq.pop_front();
    if (deq.empty()) return INF;
    return deq.front()._2;
  }
};

int N, M, K;
int A[100000];
long long dp[301][100000];
SlideMin smin[301];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M >> K;
  rep(i, N) cin >> A[i];
  rep(k, K+1) rep(i, N) dp[k][i] = INF;
  rep(i, N) dp[0][i] = 0;
  rep(k, K+1) smin[k] = SlideMin(dp[k]);
  dp[1][0] = -A[0];
  rep(k, K) rep(i, N) {
    dp[k+1][i] = min(dp[k+1][i], -(-smin[k].query(i-M, i-1) + 1LL*(k+1)*A[i]));
  }
  long long m = 0;
  rep(i, N) m = max(m, -dp[K][i]);
  cout << m << "\n";
  return 0;
}


Measured memory_bytes: 236032
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  int b[n];
  int c[n-1];
  for(int i=0;i<n;i++)
    cin>>a[i];
  for(int i=0;i<n;i++)
    cin>>b[i];
  for(int i=0;i<n-1;i++)
    cin>>c[i];
  
  int sum=b[a[0]-1];
  
  for(int i=1;i<n;i++)
  {
    if(a[i]-1==a[i-1]) sum+=c[a[i-1]-1];
    
    sum+=b[a[i]-1];
    
    
  }
  cout<<sum;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(2e5)+10;
typedef long long ll;
int n,a[maxn],ans;
ll m;
map<int,int> s;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) read(a[i]),s[a[i]]++;
	sort(a+1,a+n+1); m=1LL<<31;
	for (int i=n;i>=1;i--) {
		if (!s[a[i]]) continue;
		while (m/2>a[i]) m/=2;
		if (a[i]*2==m&&s[a[i]]==1) continue;
		if (s[m-a[i]])
			s[m-a[i]]--,s[a[i]]--,ans++;
	}
	printf("%d\n",ans);
	return 0;
}

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

vector<ll> memo(100001, -1);

bool prime(ll x) {
  if(x % 2 == 0) {
    if(x == 2) return true;
    else return false;
  }
  if(x == 1) {
    memo[1] = 0;
    return false;
  }
  if(memo[x] != -1) return memo[x];
  rep(i, 3, sqrt(x)+1) {
    if(x % i == 0) {
      memo[x] = 0;
      return false;
    }
  }
  memo[x] = 1;
  return true;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  ll q;
  cin >> q;
  
  vector<ll> a(100000);
  for(ll i = 1; i <= 100000; i += 2) {
    if(prime(i) and prime((i+1)/2))
      a[i-1]++;
  }
  vector<ll> wa(100001, 0);
  rep(i, 0, 100001) {
    wa[i+1] = wa[i] + a[i];
  }
  
  rep(i, 0, q) {
    ll l, r;
    cin >> l >> r;
    cout << wa[r]-wa[l-1] << "\n";    
  }
  
}

Measured memory_bytes: 2944
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>
#define forn(i,n) for(int i=0; i<(int)n; i++)
ll power(ll x,ll n);
bool isprime(ll n);
void test_case()
{
    ll n,sum=0;
    cin>>n;
    for(ll k=1;k<=n;k++) {
        sum+=k*(n/k)*(1+n/k);
    }
    cout<<sum/2;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}
ll power(ll x,ll n)
{
    ll ans=1;
    while(n>0) {
        if(n&1)
            ans*=x;
        n>>=1;
        x*=x;
    }
    return ans;
}

bool isprime(ll n)
{
    if(n==2 || n==3)
        return true;
    if(n<=1 || n%2==0 || (n%6!=1 && n%6!=5))
        return false;
    for(int i=3;i*i<=n;i+=2) {
        if(n%i==0)
            return false;
    }
    return true;
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;
#define rep(i, a, n) for (ll i = (a); i < (n); i++)
#define debug(x) cerr << #x << ": " << x << endl;
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;}

int main() {
    ll H, W, h, w;
    cin >> H >> W >> h >> w;
    cout << H*W - h*W - H*w + h*w << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000002


int main(){

	int N;
	cin>>N;
	
	vector<long long> A(N),B(N);
	
	for(int i=0;i<N;i++)cin>>A[i]>>B[i];
	
	long long ans = Inf;
	
	{
		long long s = 0;
		for(int i=0;i<N;i++)s+=A[i];
		ans = min(ans,s);
		
		s=0;
		for(int i=0;i<N;i++)s+=B[i];
		ans = min(ans,s);
	}
	
	vector<pair<long long,int>> P;
	for(int i=0;i<N;i++){
		P.emplace_back(A[i],i);
		P.emplace_back(B[i],i);
	}
	
	sort(P.begin(),P.end());
	set<int> S;
	long long s = 0;
	for(int i=0;i<N;i++){
		s += P[i].first;
		S.insert(P[i].second);
	}
	
	if(S.size()!=N){
		ans = min(ans,s);
	}
	else{
		for(int i=0;i<N;i++){
			long long t = s;
			t -= P[i].first;
			t += A[P[i].second]+B[P[i].second];
			if(i!=N-1){
				t -= P[N-1].first;
			}
			else{
				t -= P[N-2].first;
			}
			ans = min(ans,t);
		}
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 12700
// type a
//a...いけそう
//b...自信がない
//c...お試し
#pragma region header
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cctype>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <math.h>
#include <cstring>
#include <array>
// ===============================================================
//using系
#pragma region header
using namespace std;
using lint = long long;
using ld = long double;
using ulint = unsigned long long;
const int dx[] = { 1,0,-1,0 };
const int dy[] = { 0,1,0,-1 };
constexpr lint mod = 1000000007;
constexpr long double pi = 3.141592653589793238462643383279;
#pragma endregion
// ========================================================================
//define
#define INF (lint)10000000000000000;
#define mod (int)1000000007
#pragma endregion



int main() {
	string a, b, c; cin >> a >> b >> c;
	int x, y, z;
	x = 0; y = 0; z = 0;
	int cnt = 0;
	while (true) {
		if (cnt == 0) {
			if (x == (int)a.size()) {
				puts("A");
				break;
			}
			cnt = (int)a[x] - 97;
			x++;
			continue;
		}
		if (cnt == 1) {
			if (y == (int)b.size()) {
				puts("B");
				break;
			}
			cnt = (int)b[y] - 97;
			y++;
			continue;
		}
		if (cnt == 2) {
			if (z == (int)c.size()) {
				puts("C");
				break;
			}
			cnt = (int)c[z] - 97;
			z++;
			continue;
		}
	}

	return 0;
}

Measured memory_bytes: 3572
#include<stdio.h>

int main(void){
	int h, i;
	int h1 = 0, h2 = 0, h3 = 0;
        for(i = 0; i < 10 ; i++){
		scanf("%d", &h);
		if(h <= h3){
		}
		else if(h3 < h && h <= h2){
			h3 = h;
		}
		else if(h2 < h && h <= h1){
			h3 = h2;
			h2 = h;
		}
		else{
			h3 = h2;
			h2 = h1;
			h1 = h;
		}
        }
	printf("%d\n%d\n%d\n", h1, h2, h3);	
}

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


/// File input & output /////
#define fRead(x)        freopen("x.txt","r",stdin)
#define fWrite(x)       freopen ("x.txt","w",stdout)


#define ld              long double
#define ll              long long
#define ull             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             2e16
#define PI              acos(-1.0)
#define mp              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>


#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())


#define FASTIO        ios_base::sync_with_stdio(0);cin.tie(nullptr);




///..................Sort by second element in a pair in decending order............. ///
bool SortbySecDesc(const pair<long long,long long > &a, const pair<long long,long long > &b)
{
    return a.second>b.second;
}

///.........................first element of pair in descending order..........................//////
bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
{
       return (a.first > b.first);
}



///.............................................................TEMPLATE................................................./////

int main()
{
    FASTIO;


    int n , l;



    cin >> n >> l;


    string st[n];

    //vector<pair<char,string>>v;

    for(int i=0; i<n; i++)
    {
        cin >> st[i];

        //v.pb(make_pair(st))
    }

    sort(st,st+n);

    for(int i=0; i<n; i++)
    {
        cout << st[i];

    }





    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 idx = -1;
		double min = 1e9;
		for(int i=0;i<N;i++){
			double t = T - 0.006 * H[i];
			if(Math.Abs(A - t) < min){
				min = Math.Abs(A - t);
				idx = i;
			}
		}
		
		Console.WriteLine(idx + 1);
	}
	int N;
	int T,A;
	int[] H;
	public Sol(){
		N = ri();
		var d = ria();
		T = d[0]; A = d[1];
		H = 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: 13204
#include <bits/stdc++.h>
using namespace std;
int n,a,b,h[100001],cpy[100001];
int check(long long x) {
    for (int i=0; i<n; i++) cpy[i]=h[i];
    vector<int> v;
    for (int i=0; i<n; i++) {
        if (cpy[i]>x*b) v.push_back(cpy[i]-x*b);
    }
    long long y=0;
    for (int i=0; i<v.size(); i++) y+=((v[i]+(a-b-1))/(a-b));
    if (y>x) return 0;
    else return 1;
}
int main() {
    cin>>n>>a>>b;
    for (int i=0; i<n; i++) cin>>h[i];
    int low=0,high=1e9;
    while (low!=high) {
        int med=(low+high)/2;
        int x=check(med);
        if (x) high=med;
        else low=med+1;
    }
    cout<<low<<'\n';
}

Measured memory_bytes: 4784
a, b, c = map(int, raw_input().split())
if a == 5 and b == 5 and c == 7:
  print('YES')
elif a == 5 and b == 7 and c == 5:
  print('YES')
elif a == 7 and b == 5 and c == 5:
  print('YES')
else:
  print('NO')

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

#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,x,n) for(int i=x; i<(n); i++)
#define rrep(i,n) for(int i=(n)-1; i>=0; i--)
#define all(X) (X).begin(),(X).end()
#define X first
#define Y second
#define pb push_back
#define eb emplace_back

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

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 (a>b) { a=b; return 1; } return 0; }

template<class A, size_t N, class T> void Fill(A (&a)[N], const T &v){ fill( (T*)a, (T*)(a+N), v ); }

template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {os<<"{"; rep(i,t.size()) {os<<t[i]<<",";} os<<"}"; return os;}
template<class T,size_t n> ostream& operator<<(ostream &os, const array<T,n> &t) {os<<"{"; rep(i,n) {os<<t[i]<<",";} os<<"}"; return os;}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}

const ll INF = 1e9+7;


int main(){
	ios_base::sync_with_stdio(false);
	int a, b, ans=0;

	cin >> a >> b;

	if( a + b == 15 ){
		cout << "+" << endl;
	}else if( a * b == 15 ){
		cout << "*" << endl;
	}else{
		cout << "x" << endl;
	}

	return 0;
}

Measured memory_bytes: 256