akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
//#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
 

signed main(void){
    int N;
    int P[10],Q[10];
    int d[10]={1,2,3,4,5,6,7,8};
    cin >> N;
    REP(i,N){
        cin >> P[i];
    }
    REP(i,N){
        cin >> Q[i];
    }
    int i=0,a,b;
    do{
        bool c=true;
        REP(i,N){
            if(P[i]!=d[i]){
                c=false;
            }
        }
        if(c){
            a=i;
        }
        
        c=true;
        REP(i,N){
            if(Q[i]!=d[i]){
                c=false;
            }
        }
        if(c){
            b=i;
        }
        
        i++;
    }while(next_permutation(d,d+N));
    
    cout << abs(a-b) << endl;
    return 0;
}



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

int main()
{
    ll  N, M = 100;
    cin >> N;
    for (int i = 1;; i++)
    {
        M *= 1.01;
        if (M >= N)
        {
            cout << i;
            return 0;
        }
    }

    return 0;
}

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

int main() { 
    ios_base::sync_with_stdio(0); 
    cin.tie(0);
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a) {
        cout << k << '\n';
        return 0;
    }
    int sum = a;
    k -= a;
    if (k <= b) {
        cout << sum << '\n';
        return 0;
    }
    k -= b;
    sum -= k;
    cout << sum << '\n';
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
string S;
int K, dp[300][300][300];
int dfs(int l,int r,int k){
  if(dp[l][r][k]!=-1)return dp[l][r][k];
  if(l>r)return dp[l][r][k]=0;
  if(l==r)return dp[l][r][k]=1;
  dp[l][r][k]=0;
  if(S[l]==S[r])dp[l][r][k]=dfs(l+1,r-1,k)+2;
  dp[l][r][k]=max(dp[l][r][k],dfs(l+1,r,k));
  dp[l][r][k]=max(dp[l][r][k],dfs(l,r-1,k));
  if(k>0)dp[l][r][k]=max(dp[l][r][k],dfs(l+1,r-1,k-1)+2);
  return dp[l][r][k];
}
int main(){
  for(int i=0;i<300;i++)for(int j=0;j<300;j++)for(int k=0;k<300;k++)dp[i][j][k]=-1;
  cin>>S>>K;
  cout<<dfs(0,S.length()-1,K)<<endl;
}

Measured memory_bytes: 105728
#pragma GCC optimize("O3")
#pragma GCC target("avx")
#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
#define repr(i ,n) for(int i=n;i>(int)(n);--i)
#define rep1(i ,n) for(int i=1;i<=(int)(n);++i)
#define ALL(a) a.begin(), a.end()
#define RSORT(a) sort(ALL(a),greater<>())
#define SORT(a) sort(ALL(a))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define PRINT(x) printf("%d\n",(x));
#define ENDL printf("\n");
using namespace std;
typedef long long int i64;
typedef unsigned long long u64;
template<class T> using V = vector<T>;
using VI = V<int>;
const int INF = 2e9;
const i64 MOD = 1e9 + 7;

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

set<string> ss;
vector<bool> ans;

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    int n; cin >> n;
    string op , s;
    bool f = false;
    rep(i ,n) {
        cin >> op >> s;
        if ( op == "insert") ::ss.insert(s);
        else if ( op == "find"){
            if(ss.find(s)!=ss.end()) cout << "yes" << endl; 
            else cout << "no" << endl;
        }
    }
}


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

int main() {
	int k, a, b; scanf( "%d%d%d", &k, &a, &b );
	if ( b - a <= 2 or k <= a ) {
		printf( "%d\n", k + 1 );
		return 0;
	}
	k -= a - 1;
	printf("%" PRId64 "\n", a + ( ( int64_t )( b - a ) ) * ( k >> 1 ) + ( k & 1 ) );
	return 0;
}

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

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

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

    int n, w;
    cin >> n >> w;
    int we[n];
    ll va[n];
    for (int i = 0; i < n; ++i) {
      cin >> we[i] >> va[i];
    }

    ll dp[w + 1];
    memset(dp, 255, sizeof dp);
    dp[0] = 0;
    ll res = 0;
    for (int i = 0; i < n; ++i) {
      int wi =  we[i]; ll vi = va[i];
      for (int j = w; j >= 0; --j) {
        if (dp[j] != -1 && j + wi <= w) {
          dp[j + wi] = max(dp[j + wi], dp[j] + vi);
          res = max(res, dp[j + wi]);
        }
      }
    }
    cout << res << endl;
    
    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int n, k;
vector<ll> x, y;
vector<P> v;

bool check(int x1, int x2, int y1, int y2){
    int cnt = 0;
    rep(i,n){
        if(v[i].first < x[x1] || x[x2] < v[i].first) continue;
        if(v[i].second < y[y1] || y[y2] < v[i].second) continue;
        cnt++;
    }
    return cnt >= k;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    cin >> n >> k;
    x.resize(n);
    y.resize(n);
    rep(i,n){
        cin >> x[i] >> y[i];
        v.emplace_back(x[i], y[i]);
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    ll ans = 1e30;
    for(int x1 = 0; x1 < n; x1++){
        for(int x2 = x1; x2 < n; x2++){
            for(int y1 = 0; y1 < n; y1++){
                for(int y2 = y1; y2 < n; y2++){
                    if(check(x1, x2, y1, y2)){
                        ll cmp = (y[y2] - y[y1]) * (x[x2] - x[x1]);
                        chmin(ans, cmp);
                    }
                }
            }
        }
    }
    cout << ans << endl;
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n, x, y;
    cin >> n >> x >> y;
    x--; y--;
    map<int, int> mp;
    int tmp;
    for (int i = 0; i < n - 1; ++i) {
        for (int j = i + 1; j < n; ++j) {
            tmp = min({j-i, abs(i-x) + abs(j-y) + 1, abs(i-y) + abs(j-x) + 1});
            mp[tmp]++;
        }
    }
    for (int i = 1; i < n; ++i) {
        cout << mp[i] << endl;
    }
}

Measured memory_bytes: 3696
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#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 998244353
#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())
string s,t;
int A,B;
ll modpow(ll x,ll n)
{
	ll res=1;
	while(n>0)
	{
		if(n&1) res=res*x%mod;
		x=x*x%mod;
		n>>=1;
	}
	return res;
}
ll F[50005],R[50005];
void make(){
	F[0] = 1;
	for(int i=1;i<50005;i++) F[i] = F[i-1]*i%mod;
	for(int i=0;i<50005;i++) R[i] = modpow(F[i],mod-2);
}
ll C(int a,int b){return F[a]*R[b]%mod*R[a-b]%mod;}
int main(){
	cin>>s>>t;make();
	rep(i,s.size()){
		if(s[i]==t[i]&&s[i]=='1') A++;
		else if(s[i]=='1') B++;
	}
	ll ans = 0;
	for(int i=0;i<=A;i++){
		ll ret = F[i]*F[A-i]%mod*F[A-i]%mod;
		ll add = 0;
		//B個,sum=i
		int sum = i+B;
		for(int i=0;i<=B;i++){
			ll x = C(B,i);
			x = x*modpow(B-i,sum)%mod;
			if(i%2==0) add=(add+x)%mod;
			else add=(add+mod-x)%mod;
		}
		ans += ret*add%mod*F[B]%mod*C(A+B,i+B)%mod*C(A,i)%mod;
	}
	cout<<ans%mod<<endl;
}

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

int main(){

  int n, y, m, d;

  cin>>n;

  for(n;n;n--){
    cin>>y>>m>>d;
    int ans=0;
    for(int i=y+1;i<1000;i++){
      if(i%3==0) ans+=20*10;
      else ans+=(20+19)*5;
    }
    if(y%3==0) ans+=20*(10-m);
    else{
      for(int i=m+1;i<=10;i++){
	if(i%2) ans+=20;
	else ans+=19;
      }
    }
    if(y%3==0) ans+=20-d;
    else{
      if(m%2) ans+=20-d;
      else ans+=19-d;
    }

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

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

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

  int a, b, c, d;
  a = N/1000;
  b = (N-a*1000)/100;
  c = (N-a*1000-b*100)/10;
  d = (N-a*1000-b*100-c*10)/1;
  
  if ((a==b && b==c) || (b==c && c==d)){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/ruby
class TLLI
	def initialize
		@trianies=[nil,[0,0,0]]
	end
	def root_triany
		1
	end
	def allocate_triany
		siz=@trianies.size
		@trianies[siz]=[0,0,0]
		return siz
	end
	def set_a(id,value)
		return if !@trianies[id]
		@trianies[id][0]=value
	end
	def set_b(id,value)
		return if !@trianies[id]
		@trianies[id][1]=value
	end
	def set_c(id,value)
		return if !@trianies[id]
		@trianies[id][2]=value
	end
	def get_a(id)
		return if !@trianies[id]
		@trianies[id][0]
	end
	def get_b(id)
		return if !@trianies[id]
		@trianies[id][1]
	end
	def get_c(id)
		return if !@trianies[id]
		@trianies[id][2]
	end
end

class SETI <TLLI # a=>key, b=>left, c=>right
	def set_entry(key)
		x=root_triany
		y=0
		while x!=0&&!(x==root_triany&&get_a(x)==0) #fixme
			y=x
			if key<get_a(x)
				x=get_b(x)
			else
				x=get_c(x)
			end
		end
		if y==0
			set_a(root_triany,key)
		else
			leaf=allocate_triany
			set_a(leaf,key)
			if key<get_a(y)
				set_b(y,leaf)
			else
				set_c(y,leaf)
			end
		end
	end
	def find_entry(key)
		t=root_triany
		loop{
			return true if key==get_a(t)
			if key<get_a(t)
				t=get_b(t)
				return false if t==0
			else
				t=get_c(t)
				return false if t==0
			end
		}
	end
	def delete_entry(key)
		left=false
		prev=nil
		t=root_triany
		loop{
			break if key==get_a(t)
			prev=t
			if key<get_a(t)
				t=get_b(t)
				left=true
				return false if t==0
			else
				t=get_c(t)
				left=false
				return false if t==0
			end
		}
		if get_b(t)>0&&get_c(t)>0
			children=inorder_internal(get_c(t))+[t]
			set_a(t,get_a(children[0]))
 
			prev=children[1]
			#left of parent of t
			if prev!=t
				set_b(prev,0)
				left=true
			else
				left=false
			end
			t=children[0]
		end
		if get_b(t)+get_c(t)>0
			n=get_b(t)+get_c(t)
			if left
				set_b(prev,n)
			else
				set_c(prev,n)
			end
		else
			if left
				set_b(prev,0)
			else
				set_c(prev,0)
			end
		end
	end
	def inorder_internal(t)
		t==0 ? [] : inorder_internal(get_b(t))+[t]
	end
	def print_preorder(t)
		return if t==0
		Kernel.print " #{get_a(t)}"
		print_preorder(get_b(t))
		print_preorder(get_c(t))
	end
	def print_inorder(t)
		return if t==0
		print_inorder(get_b(t))
		Kernel.print " #{get_a(t)}"
		print_inorder(get_c(t))
	end
	def print_postorder(t)
		return if t==0
		print_postorder(get_b(t))
		print_postorder(get_c(t))
		Kernel.print " #{get_a(t)}"
	end
	def print
		print_inorder(root_triany);puts
		print_preorder(root_triany);puts
	end
end
 
seti=SETI.new
gets.to_i.times{
	a=gets.split
	if a[0]=='insert'
		seti.set_entry(a[1].to_i)
	elsif a[0]=='find'
		puts seti.find_entry(a[1].to_i) ? :yes : :no
	elsif a[0]=='delete'
		seti.delete_entry(a[1].to_i)
	elsif a[0]=='print'
		seti.print
	end
}

Measured memory_bytes: 53536
#include<iostream>
#define MAX_NUM 101
using namespace std;

char grid[MAX_NUM][MAX_NUM];

int main() {
    int H, W;
    cin >> H >> W;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) cin >> grid[i][j];
    }
    for (int i = 0; i < W + 2; i++) cout << '#';
    cout << endl;
    for (int i = 0; i < H; i++) {
        cout << '#';
        for (int j = 0; j < W; j++) cout << grid[i][j];
        cout << '#' << endl;
    }
    for (int i = 0; i < W + 2; i++) cout << '#';
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.ComponentModel.DataAnnotations;
using System.Runtime.InteropServices;

namespace ConsoleApp2
{
	class Program
	{
		static void Main(string[] args)
		{

			var abc = Console.ReadLine().Split();
			var a = int.Parse(abc[0]);
			var b = int.Parse(abc[1]);
			var c = int.Parse(abc[2]);

			var x = (a + c - 1) / c;

			if (x <= b)
			{
				Console.WriteLine("Yes");
			}
			else
			{
				Console.WriteLine("No");
			}
		}
	}
}


Measured memory_bytes: 27488
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int d = sc.nextInt();
      double num = (double)n/(2*d+1);
      double x = Math.ceil(num);
      int y = (int) x;
      System.out.println(y);
    }
}

Measured memory_bytes: 23764
class UnionFind:
    def __init__(self, n):
        self.parent = [i for i in range(n + 1)]
        self.rank = [0 for _ in range(n + 1)]

    def find(self, x):
        # If x is root
        if self.parent[x] == x:
            return x
        # If x is not root, search again by using x's parent
        else:
            self.parent[x] = self.find(self.parent[x])
            return self.parent[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if self.rank[x] < self.rank[y]:
            self.parent[x] = y
        else:
            self.parent[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def check_same(self, x, y):
        return self.find(x) == self.find(y)


N, M = map(int, input().split())
p_list = list(map(int, input().split()))
union_find = UnionFind(N)
for i in range(M):
    x, y = map(int, input().split())
    union_find.union(x, y)

result = 0
for i in range(N):
    if union_find.check_same(p_list[i], i + 1):
        result += 1
print(result)


Measured memory_bytes: 14452
import java.util.*;
public class Main{
	public static void main(String args[]) {
		Scanner sc=new Scanner(System.in);
		String S=sc.next();
		sc.close();
		int i=0;
		for(int j=0;j<3;j++) {
			for(int k=j+1;k<S.length();k++) {
				if(S.charAt(j)==S.charAt(k)) {
					i++;
				}
			}
		}
		if(i==2) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}

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

int main() {
    int n;
    cin >> n;
    int a;
    
    stack<int> s;
    for (int i = 0; i < n; i++) {
        cin >> a;
        s.push(a);
    }
    
    for (int i = 0; i < n - 1; i++) {
        cout << s.top() << " ";
        s.pop();
    }
    cout << s.top() << endl;
    
    return 0;
}


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

int main(){
  int w,h,n;
  cin>>w>>h>>n;
  bool grid[h][w];
  rep(hi,h)rep(wi,w){
    grid[hi][wi]=0;
  }
  rep(i,n){
    int x, y, a;
    cin>>x>>y>>a;
    if(a==1){
      x--;
      for(int wi=x; wi>=0; wi--){
        rep(hi,h){
          grid[hi][wi]=1;
        }
      }
    }
    if(a==2){
      for(int wi=x; wi<w; wi++){
        rep(hi,h){
          grid[hi][wi]=1;
        }
      }
    }
    if(a==3){
      y--;
      for(int hi=y; hi>=0; hi--){
        rep(wi,w){
          grid[hi][wi]=1;
        }
      }
    }
    if(a==4){
      for(int hi=y; hi<h; hi++){
        rep(wi,w){
          grid[hi][wi]=1;
        }
      }
    }
  }
  int ans=0;
  rep(hi,h)rep(wi,w){
    if(!grid[hi][wi]) ans++;
  }
  cout<<ans<<endl;
}


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

using namespace std;

vector<double> v;
int N;

int main(){
    cin >> N;
    v.resize(N);
    for(int i=0;i<N;i++) cin >> v[i];
    sort(v.begin(),v.end());
    for(int i=1;i<N;i++){
        v[i] = (v[i]+v[i-1]) / 2;
    }
    cout << v[N-1] << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
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; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
const ll INF = 1e18;
template <typename T>
T pow(T a, long long n, T e = 1) {
    T ret = e;
    while (n) {
        if (n & 1) ret *= a;
        a *= a;
        n >>= 1;
    }
    return ret;
}
ll r, c, n;

inline bool inside(ll x, ll y) {return x > 0 and x < r and y > 0 and y < c;}

ll cir_long(ll x, ll y){
    if(y == 0) return x;
    if(x == r) return r + y;
    if(y == c) return 2 * r + c - x;
    if(x == 0) return 2 * r + 2 * c - y;
}

typedef pair<ll,ll> P; 

int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> r >> c >> n;
    V<P> cir;
    REP(i, n){
        ll x1, y1, x2, y2; cin >> x1 >> y1 >> x2 >> y2;
        if(inside(x1 ,y1) or inside(x2, y2)) continue;
        cir.pb({cir_long(x1, y1), i});
        cir.pb({cir_long(x2, y2), i});
    }
    sort(all(cir));
    stack<ll> st;
    REP(i, SZ(cir)){
        ll now = cir[i].second;
        if(st.empty() or st.top() != now) st.push(now);
        else st.pop();
    }
    YES(st.empty());
}

Measured memory_bytes: 7424
#include <iostream> 
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mk make_pair
#define MAX 1000001
ll prime[MAX];
#define FAST           ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007

ll rec(vector<vector<ll> >& dp,vector<ll>& arr,int n,int i,int k,int w)
{
  ll ans=0;
  if(i>=n)
    return 0;

  if(dp[i][k]!=-1)
    return dp[i][k];


  if(k!=0)
  ans=max(rec(dp,arr,n,i+1,w,w),arr[i]+rec(dp,arr,n,i+1,k-1,w));
  else
  ans=max(rec(dp,arr,n,i+1,k,w),rec(dp,arr,n,i+1,w,w));

  return dp[i][k]=ans;

}

//ll t[400008];
// void build(vector<ll>& a, int v, int tl, int tr) {
//     if (tl == tr) {
//         t[v] = a[tl];
//     } else {
//         int tm = (tl + tr) / 2;
//         build(a, v*2, tl, tm);
//         build(a, v*2+1, tm+1, tr);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }

// ll maxi(int v, int tl, int tr, int l, int r) {
//     if (l > r) 
//         return 0;
//     if (l == tl && r == tr) {
//         return t[v];
//     }
//     int tm = (tl + tr) / 2;
//     return max(maxi(v*2, tl, tm, l, min(r, tm)) ,maxi(v*2+1, tm+1, tr, max(l, tm+1), r));
// }



// void update(int v, int tl, int tr, int pos, ll new_val) {
//     if (tl == tr) {
//         t[v] = new_val;
//     } else {
//         int tm = (tl + tr) / 2;
//         if (pos <= tm)
//             update(v*2, tl, tm, pos, new_val);
//         else
//             update(v*2+1, tm+1, tr, pos, new_val);
//         t[v] = max(t[v*2] ,t[v*2+1]);
//     }
// }


int main() { 

int n;
ll m=0,t,ans=0;
cin>>n;
for(int i=0;i<n;i++)
{
  cin>>t;
  m=max(m,t);
  ans+=(m-t);
}
cout<<ans;

return 0;
}


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

int main() {
	long long int n, a, b;
	cin >> n;
	a = 0;
	map <long, long> ma;
	
	for (int i = 0; i < n; i++){
		cin >> b;
		ma[b]++;
		if(ma[b] % 2 == 1){
			a++;
		}else{
			a--;
		}
	//	cout << ma[b] << endl;
	}
	
	cout << a << endl;
	
}

Measured memory_bytes: 6528
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	//数値の入力
		int n = sc.nextInt();
      	//配列
        int num[] = new int[n];
        for(int i = 0; i < n; i++){
        	num[i] = sc.nextInt();
        }
      	//カウント
        int count = 0;
      
        for(int i = 0; i < n; i++){
        	if(i + 1 == num[num[i]-1]){
            	count++;
            }
        }
        System.out.println(count / 2);
     }
}

Measured memory_bytes: 59180
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <algorithm>
#include <functional>
#include <deque>
#include <cctype>
#include <ctime>
#include <cstdlib>
#include <iomanip>
using namespace std;

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i = 0; i < n; ++i){
        int p;
        cin >>p;
        a[i] = p;
    }
    int sum = 0;
    int yasui = -1;
    for(int i = 0; i < n; ++i){
        sum += a[i];
        if(yasui < a[i]) yasui = a[i];
    }
    cout << sum - yasui/2 << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
#include <list>
#include <ctime>
#include <numeric>
#include <fstream>
#include <valarray>
using namespace std;
static const double EPS = 1e-6;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SZ(a) (int(a.size()))
#define F first
#define S second
const long double pi=acos(-1.0);
int dx[]={0,1,0,-1,1,1,-1,-1,0},dy[]={1,0,-1,0,1,-1,1,-1,0};

int n;
pair<double,double> in[300];
int ans;

int getpointnum(double x,double y,double r){
  int ret=0;
  rep(i,n){
    double tx=in[i].F-x;
    double ty=in[i].S-y;
    if(r*r+EPS>=tx*tx+ty*ty)++ret;
  }
  return ret;
}

void square(double x,double y,double wh){
  int t=getpointnum(x+wh/2,y+wh/2,wh/sqrt(2)+1);
  if(wh<=0.0001)return;
  if(t<=ans)return;
  ans=max(ans,getpointnum(x+wh/2,y+wh/2,1));

  square(x,y,wh/2);
  square(x+wh/2,y,wh/2);
  square(x,y+wh/2,wh/2);
  square(x+wh/2,y+wh/2,wh/2);    
}

void solve(){
  rep(i,n)cin>>in[i].F>>in[i].S;
  ans=1;

  square(-1,-1,11);
  cout<<ans<<endl;
}

main(){
  while(cin>>n,n)
    solve();
}

Measured memory_bytes: 968
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
bool actg(string s) {
	for (auto& e:s) {
		if (e == 'A' || e == 'T' || e == 'C' || e == 'G') continue;
		return false;
	}
	return true;
}
int main() {
	int n, ans = 0;
	string s;
	cin >> s;
	n=s.size();
	for (int i=0; i<n; i++) {
		for (int j=1; j<=n-i; j++) {
			string subs = s.substr(i,j);
			// cout << subs << '\n';
			if(actg(subs)) ans = max(ans, (int)subs.size());
		}
	}
	return cout << ans, 0;
}


Measured memory_bytes: 3576
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

LL N, K, ans;

int main()
{
	in >> N >> K;
	std::vector<LL>A(N);
	rep(i, N) in >> A[i];
	LL now = K;
	ans = 1;
	while (now <= N - 1)
	{
		now += K - 1;
		++ans;
	}
	out << ans << std::endl;
	return 0;
}


Measured memory_bytes: 1024
fun f(x: Int, m: Long): Long = if (x > 0) 1L * x * f(x - 1, m) % m else 1L

fun main(args: Array<String>) {
  val MOD = (1e9 + 7).toLong()
  val n = readLine()!!.toInt()
  val x = readLine()!!.split(" ").map { it.toLong() }
  var ans = 1L
  var l = 0
  for (r in 1..n) {
    if (x[r - 1] >= 2 * (r - l) - 1) continue
    ans *= r - l
    ans %= MOD
    l++
  }
  println(ans * f(n - l, MOD) % MOD)
}


Measured memory_bytes: 58692
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main
{

  public static void main
  (
    String[] args
  )
  {
    BufferedReader in_stream;
    String         in_str;

    int in_A;
    int in_B;
    int in_C;
    int in_X;

    int cnt_50;
    int cnt_100;
    int cnt_500;

    int tmp_num;
    int ans;

    try
    {
      in_stream = new BufferedReader(new InputStreamReader(System.in));

      in_str = new String(in_stream.readLine());
      in_A  = Integer.parseInt(in_str);

      in_str = new String(in_stream.readLine());
      in_B  = Integer.parseInt(in_str);

      in_str = new String(in_stream.readLine());
      in_C  = Integer.parseInt(in_str);

      in_str = new String(in_stream.readLine());
      in_X   = Integer.parseInt(in_str);


      ans = 0;

      for(cnt_500=0; cnt_500<=in_A; cnt_500++)
      {
        for(cnt_100=0; cnt_100<=in_B; cnt_100++)
        {
          for(cnt_50=0; cnt_50<=in_C; cnt_50++)
          {
            tmp_num = (500 * cnt_500) + (100 * cnt_100) + (50 * cnt_50);
            if(in_X == tmp_num)
            {
              ans ++;
              break;
            }
            else if(in_X < tmp_num)
            {
              break;
            }
            else
            {
              /* Nothing to do. */
            }
          }
        }
      }

      UtilLog.ans_ln("" + ans);
    }
    catch(Exception e)
    {
      e.printStackTrace();
    }
  }
}

class UtilLog
{
  private static boolean is_debug_mode = false;



  public static void ans_ln
  (
    String i_message
  )
  {
    System.out.println(i_message);
  }



  public static void ans_f
  (
    String i_message
  )
  {
    System.out.printf(i_message);
  }



  public static void inf_ln
  (
    String i_message
  )
  {
    StackTraceElement[] stack;


    if(is_debug_mode)
    {
    stack = new Throwable().getStackTrace();

    System.out.println
      (
        String.format
          (
            "[inf][%s:%s():%5d]",
            stack[1].getClassName(),
            stack[1].getMethodName(),
            stack[1].getLineNumber(),
            i_message
          )
      );
    }
  }
}


Measured memory_bytes: 24788
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on
void main()
{
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    long K;
    K = input.front.to!long;
    input.popFront;

    long[] A = new long[](cast(size_t)(N));
    foreach (i; 0 .. cast(size_t)(N))
    {
        A[i] = input.front.to!long;
        input.popFront;
    }

    solve(N, K, A);
}

void solve(long N, long K, long[] A)
{
    long ok = 1_000_000_000;
    long ng = 0;
    long cnt(long x)
    {
        // writeln(x);
        return A.map!(a => (a <= x) ? 0 : (a + x - 1) / x - 1)().sum();
    }

    while (1 < ok - ng)
    {
        long m = ng + (ok - ng) / 2;
        if (cnt(m) <= K)
        {
            ok = m;
        }
        else
        {
            ng = m;
        }
    }
    writeln(ok);
}


Measured memory_bytes: 14180
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;
ll INF = 1e12+10;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
vector<pair<ll, ll> > pairs;
#define print1(x) cerr << "x = " << x << endl;
#define print2(x, y) cerr<< "x,y = "  << x << "," << y << endl;
#define print3(x, y, z) cerr << "x,y,z = " << x << "," << y << "," << z << endl;
#define print4(x, y, z, w) cerr << "x,y,z,w = " << x << "," << y << "," << z << "," << w << endl;

ll A[400000];
ll cnt[64];

ll mod = ll(1e9 + 7);

ll dp [100003][3];
int main()
{
    ll N, K, R, S, P, ans = 0;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    string X = "rsp";
    ll score[3];
    score[0] = P; score[1] = R; score[2] = S;
    
    for (int k = 0; k < K; k++){
        int i;
        for (i = k; i < N; i += K){
            
            if (i < K){
                for (int j = 0; j < 3; j++){
                    if (T[i] == X[j]){
                        dp[i][j] = score[j];
                    }
                }
            } else {
                for (int j = 0; j < 3; j++){
                    ll pre = max(dp[i - K][(j+1)%3], dp[i - K][(j+2)%3]);
                    if (T[i] == X[j]){
                        dp[i][j] = pre + score[j];
                    } else {
                        dp[i][j] = pre;
                    }
                }
            }
        }
        ll score = 0;
        for (int j = 0; j < 3; j++){
            score = max(score, dp[i - K][j]);
        }
        ans += score;
        //fprintf(stderr, "%d, score = %d\n", i - K, score);
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 4608
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 999999999

ll gcd (ll a,ll b){
    if(a<b)swap(a,b);
    if(a%b==0)return b;
    return gcd(b,a%b);
}

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

int main(){
    int a,b;
    while(cin>>a>>b){
        cout<<gcd(a,b)<<" "<<lcm(a,b)<<endl;
    }
}

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

int main() {
  // 入力
  int a, b;
  cin >> a >> b;
  
  // 計算
  int coin;
  coin = max(a, b) + max(max(a, b) - 1, min(a, b));
  
  // 出力
  cout << coin << endl;
  
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

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

  int n,m;
  cin>>n>>m;
  vector<ll>X(n),Y(m);
  for(int i=0;i<n;i++)cin>>X[i];
  for(int i=0;i<m;i++)cin>>Y[i];
  ll sumx=0;
  for(int i=0;i<n;i++)sumx=(sumx+(i+1-(n-i))*X[i])%MOD;
  ll sumy=0;
  for(int i=0;i<m;i++)sumy=(sumy+(i+1-(m-i))*Y[i])%MOD;
  cout<<(sumx*sumy)%MOD<<endl;
  return 0;
}


Measured memory_bytes: 1792
import java.io.*;
import java.util.*;

public class Main{
	
	public static void main(String[] args){
	
	MyScanner sc = new MyScanner();
	out = new PrintWriter(new BufferedOutputStream(System.out));
	
	/**/
	
	long coordinate = sc.nextLong();
	long moves = sc.nextLong();
	long distance = sc.nextLong();
	long x;
	long temp;
	
	x = absoluteValue(coordinate) / distance;
	if(coordinate >= 0){
	coordinate = coordinate - (Math.min(x, moves) * distance);
	}else{
	coordinate = coordinate + (Math.min(x, moves) * distance);
	}
	moves = moves - x;
	
	if(absoluteValue(coordinate + distance) < absoluteValue(coordinate - distance)){
			temp = coordinate + distance;
		}else{
			temp = coordinate - distance;
		}
	
	
	for(long i = 0; i < moves; i++){
		
		if(absoluteValue(coordinate + distance) < absoluteValue(coordinate - distance)){
			coordinate = coordinate + distance;
		}else{
			coordinate = coordinate - distance;
		}
		
		
		if(absoluteValue(coordinate) > absoluteValue(temp)){
			if((moves - i) % 2 == 0){
				
				if(absoluteValue(coordinate + distance) < absoluteValue(coordinate - distance)){
				coordinate = coordinate + distance;
				}else{
				coordinate = coordinate - distance;
				}
				
			}else{
				
				
				
			}
			
			
			break;
		}
		temp = coordinate;
		
	}
	
	System.out.println(absoluteValue(coordinate));
	/**/
	 
	 out.close();	
	}
	
	public static long absoluteValue(long n){
		
		if(n > 0){
			return n;
		}else{
			return -1 * n;
		}
		
	}
	
	public static PrintWriter out;
	
	public static class MyScanner{
		
		BufferedReader br;
		StringTokenizer st;
		
		public MyScanner(){
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		String next() {
          while (st == null || !st.hasMoreElements()) {
              try {
                  st = new StringTokenizer(br.readLine());
              } catch (IOException e) {
                  e.printStackTrace();
              }
          }
          return st.nextToken();
      }
 
      int nextInt() {
          return Integer.parseInt(next());
      }
 
      long nextLong() {
          return Long.parseLong(next());
      }
 
      double nextDouble() {
          return Double.parseDouble(next());
      }
 
      String nextLine(){
          String str = "";
	  try {
	     str = br.readLine();
	  } catch (IOException e) {
	     e.printStackTrace();
	  }
	  return str;
      }

   }
	
}


Measured memory_bytes: 32804
#include <stdio.h>
#include <limits.h>
#include <string.h>

int main(void)
{
	char s1[102];
	char s2[102];
	scanf("%s%s", s1,s2);
	if (strlen(s1) > strlen(s2))
	{
		printf("GREATER\n");
		return 0;
	}
	else if (strlen(s1) < strlen(s2))
	{	
		printf("LESS\n"); 
		return 0;
	}
	else if (strcmp(s1, s2) == 0)
	{
		printf("EQUAL\n");
		return 0;
	}	
	int i = 0;
	while (i < strlen(s1))
	{
		if (s1[i] > s2[i])
		{
			printf("GREATER\n");
			return 0;
		}
		else if (s1[i] < s2[i])
		{
			printf("LESS\n");
			return 0;
		}
		i++;
	}
	printf("EQUAL");
	return (0);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
        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 sum = 0;
        for(int w:a) sum += w;
        int ans = -1;
        int dif = Integer.MAX_VALUE;
        for(int i=0;i<n;i++){
            int cur = Math.abs(sum-n*a[i]);
            if(cur<dif){
                dif=cur;
                ans = i;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define ll long long
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define pback push_back
#define mpair make_pair
#define MODN 1000000007

using namespace std;

int digit(int n){
    int k = 1;
    while(n >= 10){
        n = n / 10;
        k++;
    }

    return k;
}

int main(){

    int n;
    cin >> n;

    int ans = 0;

    for(int i = n; i > 0; i--){
        if(digit(i) % 2 == 1) ans++;
    }

    cout << ans << endl;

    return 0;

}

Measured memory_bytes: 256
def insertion_sort(n, as)
  puts as.join(' ')
  i = 1
  while i < n
    j = i
    while j > 0
      if as[j] < as[j - 1]
        a = as[j]
        as[j] = as[j - 1]
        as[j - 1] = a
      end
      j = j - 1
    end
    puts as.join(' ')
    i = i + 1
  end
end

n = STDIN.gets.to_i
as = STDIN.gets.split(' ').map {|x| x.to_i }
insertion_sort(n, as)



Measured memory_bytes: 6876
//Volume1-0134
import java.util.*;

public class Main {

	public static void main(String[] args) {
		
		//declare
		long n,num,sum = 0;
		
		//input
		Scanner sc = new Scanner(System.in);
		num = n = sc.nextLong();
		while(n-- > 0){
			
			//calculate
			sum += sc.nextLong();
		}
		
		//output
		System.out.println(sum / num);
	}
}

Measured memory_bytes: 30984
#include <bits/stdc++.h>
#define pii pair<int, pair<int, int>>
#define ss second
#define ff first
#define all(x) ((x).begin(), (x).end())

using namespace std;
using ll = long long;

const int mod = 1e9 + 7;
const ll oo = 1e14;
const double PI = 3.14159265;

int main(){
    ios_base::sync_with_stdio(false);
    cout.precision(20);
    double a, b, x;
    cin >> a >> b >> x;
    x/=a;

    if (x <= a*b/2.0){
        double l = (x/b)*2.0, hip;
        hip = sqrt(l*l + b*b);
        double angle = acos(b/hip);

        cout << 90.0 - angle*180.0/PI << endl;
    }
    else {
        double B = ((2*x)/a) - b;
        double l = b - B;
        double hip = sqrt(l*l + a*a);
        double angle = acos(a/hip);

        cout << angle*180.0/PI << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
using namespace std;
int n;
unsigned long long cnt;
int ys(int a){
	int s=1;
    for(int i=2;i*i<=a;i++){
        if(a%i==0){
            int x=0;
            while(a%i==0){
                a/=i;
                x++;
            }
            s=s*(x+1);
        }
    }
    if(a>1)s*=2;
    return s;
}
int main(){
	scanf("%d",&n);
	for(int c=1;c<=n;c++){
		cnt+=ys(n-c);
	}
	cout<<cnt-1<<endl;
	return 0;
}

Measured memory_bytes: 3792
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define run(v) for(int k=head[v];k;k=e[k].ne)
#define v e[k].t
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)a.size())
#define all(a) a.begin(),a.end()
#define mp make_pair
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<ll,ll> pa;
const int N=1e6+5,M=1e7+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il ll qpow(ll a,ll b,ll p){ll ret=1;for(;b;b>>=1,a=a*a%p)if(b&1)ret=ret*a%p;return ret;}il ll qpow(ll a,ll b){ll ret=1;for(;b;b>>=1,a=a*a%mod)if(b&1)ret=ret*a%mod;return ret;}
il ll qmul(ll a,ll b,ll p){ll ret=0;for(;b;b>>=1,a=(a<<1)%p)if(b&1)adm(ret,a,p);return ret;}il ll qmul(ll a,ll b){ll ret=0;for(;b;b>>=1,a=(a<<1)%mod)if(b&1)adm(ret,a,mod);return ret;}
il void judge(){
	freopen("data.in","r",stdin);
	freopen("data.out","w",stdout);}
il void gen(){freopen("data.in","w",stdout);}
int x,y,z,n;
ll a[N],b[N],c[N],f1[N],f2[N];
pa p[N];
priority_queue<ll,vector<ll>,greater<ll> >pq;
int main(){
	read(x,y,z);
	n=x+y+z;
	ll ad=0;
	rep(i,1,n){
		read(a[i],b[i],c[i]);
		ad+=c[i];a[i]-=c[i];b[i]-=c[i];
		p[i]=pa(a[i]-b[i],i);
	}
	sort(p+1,p+1+n);reverse(p+1,p+1+n);
	rep(i,1,n){
		f1[i]=f1[i-1]+a[p[i].w2];
		pq.push(a[p[i].w2]);
		while(pq.size()>x){
			f1[i]-=pq.top();
			pq.pop();
		}
	}
	while(!pq.empty())pq.pop();
	repd(i,n,1){
		f2[i]=f2[i+1]+b[p[i].w2];
		pq.push(b[p[i].w2]);
		while(pq.size()>y){
			f2[i]-=pq.top();
			pq.pop();
		}
	}ll lover=-1e18;
	rep(i,x,n-y)gmax(lover,f1[i]+f2[i+1]);
	cout<<ad+lover<<endl;
}

Measured memory_bytes: 17272
#include <bits/stdc++.h>
using namespace std;
int main(){
	int t;
	cin >> t;
	
	int a = t % 10;
	
	if(a == 0 || a == 1 || a == 6 || a == 8){
		cout << "pon";
	}
	
	if(a == 2 || a == 4 || a == 5 || a == 7 || a == 9){
		cout << "hon";
	} 
	
	if(a == 3){
		cout << "bon";
	}
	
	return 0;
}



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

int n, s, w, e;

int main() {
  string a;
  cin >> a;
  int l = a.size();
  for (int i = 0; i < l; i++)
    if (a[i]=='N') n++;
    else if (a[i]=='S') s++;
    else if (a[i]=='W') w++;
    else e++;

  if (n==0 && s>0 ||
      s==0 && n>0 ||
      w==0 && e>0 ||
      e==0 && w>0 ) cout << "No" << endl;
  else cout << "Yes" << endl;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;
  
  scanf("%d", &n);
  
  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  for(i = 0 ; i < n; i++){
    scanf("%d", &A[i]);
  }

  for(i = 0; i <= VMAX; i++){
    C[i] = 0;
  }

  for(j = 0; j < n; j++){
    C[A[j]]++;
  }
  
  for(i = 1; i <= VMAX; i++){
    C[i] = C[i] + C[i-1];
  }

  for(j = n; j >= 0; j--){
    B[C[A[j]]] = A[j];
    C[A[j]]--;
  }

  for(i = 1; i < n; i++){
    printf("%d ", B[i]);
  }
  printf("%d\n", B[i]);
  
  
  return 0;
}



Measured memory_bytes: 9588
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize("Ofast")
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<50);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

void solve(){
  ll n;cin>>n;
	string s=to_string(n);
  ll ans=9*((int)s.size()-1);
  bool isOK=true;
  rep(i,(int)s.size()){
    if(i==0)continue;
    if(s[i]!='9')isOK=false;
  }
  if(isOK)ans+=s[0]-'0';
  else ans+=s[0]-'1';
  cout<<ans<<endl;
}

signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout<<fixed;
	cout<<setprecision(30);
	solve();
}


Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#define LL long long
LL N;
LL T[1010];
LL A[1010];
LL gcd(LL a, LL b) { return (a%b ? gcd(b, a%b) : b); }
int main() {
	std::cin >> N;
	for (int i = 0; i < N; i++) {
		std::cin >> T[i] >> A[i];
	}
	for (int i = 1; i < N; i++) {
		if (T[i] >= T[i - 1] && A[i] >= A[i - 1])continue;
		LL M = (T[i - 1] - 1) / T[i] + 1;
		M = std::max(M, (A[i - 1] - 1) / A[i] + 1);
		T[i] *= M;
		A[i] *= M;
	}
	std::cout << T[N - 1] + A[N - 1] << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int N = 2e5 + 20;
int n, q, u, v, dp[N];
vector<int> adj[N];

void dfs(int node, int parent, int sum) {
	dp[node] += sum;
	for (auto child : adj[node]) {
		if (child == parent)
			continue;
		dfs(child, node, dp[node]);
	}
}

int main() {
	scanf("%d%d", &n, &q);
	for (int i = 0; i < n - 1; i++) {
		scanf("%d%d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}

	while (q--) {
		scanf("%d%d", &u, &v);
		dp[u] += v;
	}

	dfs(1, 0, 0);
	for (int i = 1; i <= n; i++)
		printf("%d ", dp[i]);
}

Measured memory_bytes: 23424
#!/usr/bin/env python3

def main():
    N = int(input())
    L =  [int(s) for s in input().split()]
    most_long = 0
    other_longs = 0
    for l in L:
        if(l>most_long):
            other_longs += most_long
            most_long = l
        else:
            other_longs += l
    if(other_longs>most_long):
        print('Yes')
    else:
        print('No')



if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long
#define mod 1000000007
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;

int main(){
	int n;
	cin>>n;
	string a,b,c;
	cin>>a>>b;
	
	for(int i=0;i<n;i++){
		c=c+a[i];
		c=c+b[i];	
	}
	
	//cout<<c;
	for(int i=0;i<2*n;i++){
		cout<<c[i];
	}
	
	return 0;
}

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

struct UnionFind{
private:
    std::vector<int> par;
    std::vector<int> siz;
public:
    UnionFind(int size){
        par=std::vector<int>(size);
        siz=std::vector<int>(size);
        for(int i=0;i<size;++i){
            par[i]=i;
            siz[i]=1;
        }
    }

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

    bool same(int x,int y){//0-indexed
        return root(x)==root(y);
    }

    void unite(int x,int y){//0-indexed
        x=root(x);
        y=root(y);
        if(x==y)return;

        if(siz[x]<siz[y]){
            par[x]=y;
            siz[y]+=siz[x];
        }
        else{
            par[y]=x;
            siz[x]+=siz[y];
        }
    }

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

using namespace std;

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    vector<int> f(n,0),b(n,0);
    UnionFind uf(n);
    for (int i = 0; i < m; ++i) {
        int x,y;
        cin>>x>>y;
        --x;--y;
        ++f[x];
        ++f[y];
        uf.unite(x,y);
    }
    for (int j = 0; j < k; ++j) {
        int x,y;
        cin>>x>>y;
        --x;--y;
        if(uf.same(x,y)){
            ++b[x];
            ++b[y];
        }
    }
    for (int i = 0; i < n; ++i) {
        cout<<uf.size(i)-f[i]-b[i]-1;
        if(i==n-1)cout<<endl;
        else cout<<" ";
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
typedef vector<ll> VI;
typedef vector<VI> VVI;
const ll MOD = 1000000007;
const ll INF = 1e18;
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

int main() {
	int n, k; cin >> n >> k;
	VI a(n); REP(i,n) cin >> a[i];
	ll ok=1e9, ng=0;
	while(ok-ng>1){
		ll s=(ok+ng)/2;
		ll sum=0;
		REP(i,n){
			sum+=(a[i]-1)/s;
		}
		if(sum<=k)
			ok=s;
		else
			ng=s;
	}
	cout << ok << endl;
	return 0;
}

Measured memory_bytes: 4748