akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;

int N, A, B, C;
int INF = 1000000000;
vector<int> l;

int dfs(int count, int a, int b, int c){
    if(count == N){
        if(a * b * c == 0) return INF;
        else return abs(A - a) + abs(B - b) + abs(C - c) - 30;
    }
    int ret0 = dfs(count + 1, a, b, c);
    int reta = dfs(count + 1, a + l[count], b, c) + 10;
    int retb = dfs(count + 1, a, b + l[count], c) + 10;
    int retc = dfs(count + 1, a, b, c + l[count]) + 10;
    return min({ret0, reta, retb, retc});
}

int main(){
    cin>>N>>A>>B>>C;   
    int tmp;
    for(int i = 0;i < N;i++){
        cin>>tmp;
        l.push_back(tmp);
    }
    cout<<dfs(0, 0, 0, 0)<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
using namespace std;
typedef long long lint;
#define rep(i,n) for(lint (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(lint (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(lint (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
const lint MOD =1000000007;
const lint MAX = 1000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;
typedef map<lint,lint> M;
 
lint fac[MAX], finv[MAX], inv[MAX];
 
void COMinit() 
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
 
lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0;
 
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return 0;
        }
    }
 
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
    lint lcm(lint a,lint b){
        return a/__gcd(a,b)*b;
    }
     lint gcd(lint a,lint b){
        return __gcd(a,b);
    } 
    lint maxv=100005;
    struct edge{lint to;lint cost;};
    vector<vector<edge>> x(maxv);
    lint d[100005];
    void dijkstra(lint s){    
        priority_queue<P,vector<P>,greater<P>>que;
        fill(d,d+maxv,INF);
        d[s]=0;
        que.push(P(0,s));
            while(!que.empty()){
             P p=que.top();que.pop();
             lint v=p.second;
             if(d[v]<p.first)continue;
             rep(i,x[v].size()){
                 edge e=x[v][i];
                 if(d[e.to]>d[v]+e.cost){
                     d[e.to]=d[v]+e.cost;
                     que.push(P(d[e.to],e.to));
                 }
             }   
            }
    }
  int main(){
    lint n,m;
    cin>>n>>m;
    rep(i,m){
        lint a,b;
        cin>>a>>b;
        --a;--b;
        x[a].push_back({b,1});
        x[b].push_back({a,1});
    }
    dijkstra(0);
    cout<<"Yes"<<endl;
    repp(i,1,n){
        lint comp=INF;
        lint ans;
        rep(j,x[i].size()){
           lint g= x[i][j].to;
          if(comp>d[g]){
              comp=d[g];
              ans=g;
          }
        }
        cout<<ans+1<<endl;
    }

  } 
      
      
    

  
          
  

Measured memory_bytes: 18576
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

vec idy={0,1};
vec idx={1,0};
ll h,w;
mat memo(101,vec(101,-1));
vector<string> maze(101);

ll dfs(ll y,ll x) {
  if(memo[y][x]!=-1) return memo[y][x];
  ll res=inf;
  for(ll i=0;i<2;i++) {
    ll ny=y+idy[i];
    ll nx=x+idx[i];
    if(ny<h&&nx<w) {
      res=min(res,dfs(ny,nx)+(maze[y][x]=='.'&&maze[ny][nx]=='#'));
    }
  }
  return memo[y][x]=res;
}

int main() {
  cin >> h >> w;
  for(ll i=0;i<h;i++) {
    cin >> maze[i];
  }
  memo[h-1][w-1]=0;
  ll ans=dfs(0,0);
  if(maze[0][0]=='#') ans++;
  cout << ans << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

using namespace std;

#define rep(i, a, b) for(ll i = a; i < ll(b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (ll)(x).size()
typedef long long ll;
typedef pair<ll, ll> pii;
typedef vector<ll> vi;

int main() {
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    string str;
    cin>>str;

    vi a(1,0);
    ll mn = 0;
    ll ind = 0;
    while(ind<sz(str)){
        ll numUp = 0;
        while(ind<sz(str)&&str[ind]=='<'){
            numUp++;
            ind++;
        }
        rep(i,1,numUp)
            a.push_back(i);

        ll numDown = 0;
        while(ind<sz(str)&&str[ind]=='>'){
            numDown++;
            ind++;
        }
        a.push_back(max(numDown,a.back()+1));
        rep(i,1,numDown+1)
            a.push_back(numDown-i);
    }
    //if(str[0]=='>') a[0] = a[1]+1;

    ll ans = 0;
    trav(ai,a){
        //cout<<ai<<" ";
        ans += ai;
    }
    //cout<<endl;

    cout<<ans<<endl;
}

Measured memory_bytes: 7188
/**
 *   created: 11 October 2019  12:36:46
**/
#include<bits/stdc++.h>
using namespace std;

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

#define PB push_back
#define PPB pop_back
#define all(c) c.begin(),c.end()
#define rep(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define rrep(i,a,b) for(int i = (int)(a-1); i>=(int)(b); i--)
#define INFLL 2000000000000000007
#define INF 2000000007
#define MOD 1000000007


#define TRACE

#ifdef TRACE
#define trace1(x)                cerr << #x << ": " << x << endl;
#define trace2(x, y)             cerr << #x << ": " << x << " | " << #y << ": " << y << endl;
#define trace3(x, y, z)          cerr << #x << ": " << x << " | " << #y << ": " << y << " | " << #z << ": " << z << endl;
#define trace4(a, b, c, d)       cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << endl;
#define trace5(a, b, c, d, e)    cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << endl;
#define trace6(a, b, c, d, e, f) cerr << #a << ": " << a << " | " << #b << ": " << b << " | " << #c << ": " << c << " | " << #d << ": " << d << " | " << #e << ": " << e << " | " << #f << ": " << f << endl;

#else

#define trace1(x)
#define trace2(x, y)
#define trace3(x, y, z)
#define trace4(a, b, c, d)
#define trace5(a, b, c, d, e)
#define trace6(a, b, c, d, e, f)

#endif


void optimizeIO()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
}

//                                        //AUTHOR: Kaushalesh Shukla

//=========================================================================================================

int main()
{
	optimizeIO();
	int tt=1;
	// cin>>tt;
	while(tt--){
		int n;
		cin>>n;
		vector< pair<int,int> > v(n);
		rep(i,0,n){
			cin>>v[i].first;
			v[i].second = i+1;
		}
		sort(all(v));
		rep(i,0,n)
			cout<<v[i].second<<" "; 
	}
	return 0;
}



Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
#define mp make_pair
using namespace std;
using ll=long long;
using P=pair<ll,ll>;
const ll INF=1LL<<30;
const ll LINF=1LL<<60;
const double eps=1e-5;
const ll MOD=1000000007LL;
template<typename T>void chmin(T &a,T b){a=min(a,b);};
template<typename T>void chmax(T &a,T b){a=max(a,b);};
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};
int main(){
    int n,m;cin>>n>>m;
    vector<vector<int>> G(n),rG(n);
    vector<int> h(n);
    for(int i=0;i<n-1+m;i++){
        int a,b;cin>>a>>b;--a;--b;
        G[a].push_back(b);
        rG[b].push_back(a);
        h[b]++;
    }    
    stack<int> st;
    for(int i=0;i<n;i++){
        if(h[i]==0){
            st.push(i);
        }
    }
    vector<int> vs;
    while(!st.empty()){
        int v=st.top();st.pop();
        vs.push_back(v);
        for(auto e:G[v]){
            h[e]--;
            if(h[e]==0)st.push(e);
        }
    }
    vector<int> id(n+10);
    for(int i=0;i<n;i++){
        id[vs[i]]=i;
    }
    for(int i=0;i<n;i++){
        int ma=-1;
        for(auto e:rG[i]){
            ma=max(ma,id[e]);
        }
        if(ma!=-1){
            cout<<vs[ma]+1<<endl;
        }else{
            cout<<0<<endl;
        }
    }
}

Measured memory_bytes: 13052
#include<stdio.h>

int main(){
	
	int A,B,Resul;
	scanf("%d %d",&A,&B);
	
	if(A >= 13)
	{
		Resul =B;
	}
	else{
		if(A >= 6 && A<=12)
		{
			Resul = B/2;
		}
		else{
			Resul =0;
		}
	}
	printf("%d\n",Resul);
	return 0;
	}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <climits>
#include <math.h>
 
using namespace std;
typedef unsigned long ul;
typedef pair<long, int> P;

int main() {
	int a,p;
	cin>>a>>p;
	cout<<(a*3+p)/2<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
char a,b,c;
int ans=1;
int main()
{
	cin>>a>>b>>c;
	if (a=='R'&&b=='R'&&c=='R') ans=3;
	else if ((c=='R'&&b=='R')||(a=='R'&&b=='R')) ans=2;
	else if (a!='R'&&b!='R'&&c!='R') ans=0;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define pi acos(-1.0)

int main()
{
    ll i, j, n, m, cnt = 0;
    string s, t;
    cin >> n;
    cin >> s >> t;

    for(i = 0; i < n; i++){
        cout << s[i] << t[i];
    }

    cout << endl;

    return 0;
}


Measured memory_bytes: 3576
/**
 *    author:  FromDihPout
 *    created: 2020-07-29
**/

#include <bits/stdc++.h>
using namespace std;


int n, a, b;
vector<int> h;

bool check(int cnt) {
    int diff = a - b;
    long long need = 0;
    for (int i = 0; i < n; i++) {
        int rem = h[i] - b * cnt;
        if (rem > 0) {
            need += rem / diff + (rem % diff != 0);
        }
    }
    return need <= cnt;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    cin >> n >> a >> b;
    h.resize(n);
    int mx = 0;
    for (int i = 0; i < n; i++) {
        cin >> h[i];
        mx = max(mx, h[i]);
    }
    
    int l = 0, r = mx / b + 2;
    while (l < r) {
        int mid = l + (r - l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid + 1;
        }
    }
    cout << r << '\n';
    return 0;
}

Measured memory_bytes: 3656
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

a = readInt()
print(a+a**2+a**3)

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
#define MOD (ll)(1e9+7)

ll gcd(ll p,ll q){
    if(q==0)
        return p;
    return gcd(q, p % q);
}
ll moddiv(ll a,ll b){
    a %= MOD;
    b %= MOD;
    for(ll m=MOD-2;m>0;m/=2){
        if(m&1){
            a=a*b%MOD;
        }
        b=b*b%MOD;
    }
    return a;
}

ll pow(ll a,ll b){
    if(b==0)
        return 1;
    ll c = pow(a * a % MOD, b / 2);
    if(b&1){
        return c * a%MOD;
    }
    return c;
}

ll N,A[10101];
vector<pll> pr;
vector<ll> mk[1010101];
ll abc;
ll i, j,ans;

int main(){
    scanf("%lld",&N);
    fornum(i,0,N){
        scanf("%lld", &A[i]);
    }
    fornum(i,2,1010100){
        if(mk[i].size())
            continue;
        pr.push_back({i, 0});
        ll a = pr.size() - 1;
        for (j = i; j < 1010100;j+=i){
            mk[j].push_back(a);
        }
    }

    //printf("%d\n", pr.size());
    fornum(i,0,N){
        ll c = A[i];
        fornum(j,0,mk[A[i]].size()){
            ll p = mk[A[i]][j];
            ll a = pr[p].first;
            ll b = 0;
            while(c%a==0){
                c /= a;
                ++b;
            }
            pr[p].second = max(pr[p].second, b);
        }
    }
    abc = 1;
    fornum(i,0,pr.size()){
        ll a = pr[i].first;
        ll b = pr[i].second;
        abc = abc * pow(a, b) % MOD;
    }
    fornum(i,0,N){
        ans = (ans + moddiv(abc , A[i])) % MOD;
        //ans = (ans + abc / A[i]) % MOD;
    }
    printf("%lld", ans);
    return 0;
}

Measured memory_bytes: 72948
import java.util.Scanner;

class Main{
    public static int gcd(int a, int b){
        int t;
        if(a < b){
            t = a;
            a = b;
            b = t;
        }
        while(b > 0){
            t = b;
            b = a % b;
            a = t;
        }
        return a;
    }
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int a = in.nextInt();
            int b = in.nextInt();
            System.out.println(gcd(a, b) + " " + a / gcd(a, b) * b);
        }
    }
}

Measured memory_bytes: 17204
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        String s = stdIn.next();
        int[] n = new int[4];

        String[] str = s.split("");
        for(int i = 0; i < 4;i++) {
            n[i] = Integer.parseInt(str[i]);
        }

        if(n[0] != n[1] && n[1] != n[2] && n[2] != n[3]) {
            System.out.println("Good");
        }else {
            System.out.println("Bad");
        }
    }
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
const int M=1e6+10;
typedef long long ll;
const ll MOD=1e9+7;
ll fact[M*2];

ll quick_mod(ll a,ll b,ll mod){
	ll ans=1;
	a%=mod;
	while(b){
		if(b&1)ans=(ans%mod * a%mod)%mod;
		a=(a%mod * a%mod)%mod;
		b>>=1;
	}
	return ans%mod;
}
ll get_inv(ll x){
	return quick_mod(x,MOD-2,MOD);
}

ll C_mod(ll n,ll k){
	return (fact[n] * get_inv(fact[k])%MOD * get_inv(fact[n-k])%MOD)%MOD;
}

int main(int argc, char const *argv[])
{
	ll c1,r1,c2,r2;
	cin>>r1>>c1>>r2>>c2;
	fact[0]=1;
	for(int i=1;i<=r2+c2+2;i++)fact[i]=(ll)fact[i-1]*i%MOD;//阶乘
	ll ans=(C_mod(r1+c1,c1)+C_mod(r2+c2+2,c2+1)-C_mod(c1+r2+1,c1)-C_mod(r1+c2+1,c2+1)+MOD)%MOD;
	printf("%lld\n",ans%MOD);
	return 0;
}

Measured memory_bytes: 15872
#include <stdio.h>


int main (void){

    int a[1000];
    int n,m,total=0;
    int i,j;
    int temp;
    double comparer;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        total+=a[i];
        for(j=0;j<i;j++)
        {
            if (a[j]<a[i])
            {
                temp=a[i];
                a[i]=a[j];
                a[j]=temp;
            }
        }
    }

    // for(i=0;i<n;i++)
    // {
    //     printf("%d ",a[i]);
    // }
    int checker=0;
    for(i=0;i<m;i++)
    {
        comparer=(double)total/(4*(double)m);
        if(a[i]<comparer)checker=1;
    }

    if (checker==0)printf("Yes");
    else printf("No");



}

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

typedef long long ll;

int digit(ll a){
  int d=0;
  while(a>0){
    a/=10;
    d++;
  }
  return d;
}

int main(){
  ll N;
  cin >> N;
  
  int ans=0;
  long double m=sqrtl(N);
  int sq=floor(m);
  for(ll i=sq; i>=1; i--){
    if(N%i!=0) continue;
    int temp=max(digit(i), digit(N/i));
    if(ans==0) ans=temp;
    else ans=min(ans,temp);
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <queue>
#include <vector>
#include <utility>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <list>
#include <unordered_map>
#include <string>
using namespace std;
#define ll long long
#define pb push_back
using vi = vector<int>;
using vvi = vector<vector<int>>;

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

	vi heights(n);
	vvi costs(n);
	for (int i = 0; i < n; i++) {
		cin >> heights[i];
	}

	costs[0].pb(0);
	costs[1].pb(abs(heights[1] - heights[0]));
	for (int rock = 2; rock < n; rock++) {
		for (int i = 1; i <= 2; i++) {
			int cost = abs(heights[rock] - heights[rock-i]);
			int prevCost = costs[rock-i][0];

			for (int j = 1; j < costs[rock-i].size(); j++) {
				prevCost = min(prevCost, costs[rock-i][j]);
			}
			costs[rock].pb(prevCost + cost);
		}	
	}
	int minCost = costs[n-1][0];
	for (int i = 0; i < costs[n-1].size(); i++) {
		minCost = min(minCost, costs[n-1][i]);
	}

	cout << minCost << endl;
	return 0;
}

Measured memory_bytes: 6144
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <map>
#include <utility>

using namespace std;

#define ll long long

void solve()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> sortedA(N);

    for (ll i = 0; i < N; i++)
    {
        ll a;
        cin >> a;
        A.at(i) = a;
        sortedA.at(i) = a;
    }

    sort(sortedA.begin(), sortedA.end());
    ll maxValue = sortedA.at(N - 1);
    ll secondValue = sortedA.at(N - 2);

    for (ll i = 1; i < N + 1; i++)
    {
        if (A.at(i - 1) == maxValue)
        {
            cout << secondValue << endl;
        }
        else
        {
            cout << maxValue << endl;
        }
    }
}

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


Measured memory_bytes: 4736
#include <assert.h>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <algorithm>
#include <numeric>
#include <functional>
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <bitset>
typedef long long ll;
typedef unsigned long long ull;

# define INF 0x3f3f3f3f

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define DEBUG(vec) for (auto v : vec) { cout << v << " "; } cout << endl;

using namespace std;

int N;
int c[501] = {};
int s[501] = {};
int f[501] = {};

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

  int N;
  cin >> N;

  REP(i, N - 1) {
    cin >> c[i] >> s[i] >> f[i];
  }

  REP(i, N) {
    int t = 0;
    for (int j = i; j < N - 1; j++) {
      int k = max(0.0, ceil((double)(t - s[j]) / f[j]));

      t = s[j] + k * f[j];
      t += c[j];
    }
    cout << t << endl;
  }
  return 0;
}


Measured memory_bytes: 256
h,n = map(int, input().split())
max_h = 10**4
inf = 10**30
info = []
for i in range(n):
    info.append(list(map(int, input().split())))

import math

mp_sort = sorted(info, key = lambda x : x[1])
damage_sort = sorted(info, key = lambda x : x[0], reverse = True)
max_damage = damage_sort[0][0]
'''
efficiency = [0]*n
for i in range(n):
    efficiency[i] = mp_sort[i][0]/mp_sort[i][1]

max_efficiency = max(efficiency)
max_eff_index = efficiency.index(max_efficiency)

max_eff_attack = mp_sort[max_eff_index][0]
max_eff_mp = mp_sort[max_eff_index][1]
'''
dp = [inf]*(max_h + max_damage + 1)
dp[0] = 0
for i in range(n):
    min_mp = info[i][1]
    tem_damage = info[i][0]
    for j in range(tem_damage+1):
        dp[j] = min(dp[j], min_mp)

#eff_fre = math.ceil(h / max_eff_attack)
for i in range(h):
    for j in range(n):
        tem = i + info[j][0]
        if tem <= h:
            dp[tem]= min(dp[tem], dp[i] + info[j][1])

print(dp[h])



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

using namespace std;
typedef long long ll;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const int INF = 1000000;
const double PI=3.14159265359;

int main(){

  ll n,m;cin>>n>>m;
  ll a[n+10],b[m+10],c[m+10];
  set<ll,greater<ll>>ms;
  // multiset<ll,greater<ll>>ms;
  map<ll,ll>mp;
  rep(i,0,n){
    cin>>a[i];
    ms.insert(a[i]);
    mp[a[i]]++;
  }
  rep(i,0,m)cin>>b[i]>>c[i];

  // mult
  rep(i,0,m){
    ms.insert(c[i]);
    mp[c[i]]+=b[i];
  }
  ll ans=0;
  set<ll>::iterator itr=ms.begin();
  // multiset<ll>::iterator itr=ms.begin();
  ll k=n;
  while(k>0){
    int p=0;
    if(k-mp[*itr]<0)p=k;
    else p=mp[*itr];

    ans+=p*(*itr);
    k-=p;
    itr++;
  }

  // rep(i,0,n){
  //   ans+=(*itr);
  //   itr++;
  // }

  out(ans);

  // rep(i,0,m){

  // }


  return 0;
}


Measured memory_bytes: 24448
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 1000000007;
 
signed main(){

    int a,b,c;
    cin >> a >> b >> c;
    cout << min({a+b,b+c,c+a}) << endl;
    
    return 0;
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://abc129.contest.atcoder.jp/tasks/abc129_a

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


using namespace std;

using ll   = long long;
using ii   = pair   < int , int >;
using i3   = pair   < int , ii  >;
using li   = pair   < ll  , int >;
using lii  = pair   < ll  , ii  >;
using pll  = pair   < ll  , ll  >;
using vi   = vector < int       >;
using vl   = vector < ll        >;
using vii  = vector < ii        >;
using vli  = vector < li        >;
using vpll = vector < pll       >;
using vi3  = vector < i3        >;
using vlii = vector < lii       >;


const int N = 2e5 + 5;
const ll INF = 1e17 + 7;
const double eps = 1e-9 , PI = acos(-1);



int n , m;


void solve(int testCase){

    scanf("%d %d" , &n , &m);
    for(int i = 1 ; i <= 3 ; i ++){
            if((i != m) && (i != n)){
                    printf("%d\n" , i);
                    return;
            }
    }

}

main(){

    int t = 1;
    // scanf("%d" , &t);

    for(int testCase = 1 ; testCase <= t ; testCase ++){
            solve(testCase);
    }

    return 0;
}


Measured memory_bytes: 384
#![allow(unused_imports)]

use proconio::{input, fastout};
use proconio::marker::*;

#[fastout]
fn main() {
    input! {
    a: usize,
    b: usize,
    c: usize,
    d: usize
    }
    let cd = c * d / gcd(&c, &d);
    let ans = (b - a + 1) + count(cd, a, b) - count(c, a, b) - count(d, a, b);
    println!("{}", ans);
}

fn count(t: usize, a: usize, b: usize) -> usize {
    b / t - if a % t == 0 {a / t - 1} else {a / t}
}

// O(log(N))
fn gcd(a: &usize, b: &usize) -> usize {
    let (mut x, mut y) = if a < b { (*b, *a) } else { (*a, *b) };
    let mut r = x % y;
    while r != 0 {
        x = y;
        y = r;
        r = x % y;
    }
    y
}


Measured memory_bytes: 2140
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
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;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

int n,m;
vector<vector<int> > to;
int dp[100010];
int dfs(int v){
  if(dp[v]!=-1) return dp[v];
  int depth=0;
  rep(i,to[v].size()){
    int nv=to[v][i];
    chmax(depth,dfs(nv)+1);
  }
  return dp[v]=depth;
}

int main(){
  cin >> n >> m;
  to.resize(n);
  rep(i,n) dp[i]=-1;
  rep(i,m){
    int x,y;
    cin >> x >> y;
    x--; y--;
    to[x].push_back(y);
  }
  int ans=0;
  rep(i,n) chmax(ans,dfs(i));
  cout << ans << endl;
}

Measured memory_bytes: 10624
from collections import deque
N,M = [int(hoge) for hoge in input().split()]
Friend = [[] for _ in range(N)]
for m in range(M):
    A,B = [int(hoge)-1 for hoge in input().split()]
    Friend[A].append(B)
    Friend[B].append(A)
Root = [-1]*N
Youso = []
curnum = 0
for n in range(N):
    Y = 0
    if Root[n] == -1:
        Root[n] = curnum
        Y += 1
        queue = deque()#pop,appendleft
        queue.append(n)
        while queue:
            curpos = queue.pop()
            for tsugi in Friend[curpos]:
                if Root[tsugi] == -1:
                    queue.appendleft(tsugi)
                    Root[tsugi] = curnum
                    Y += 1
        Youso.append(Y)
print(max(Youso))


Measured memory_bytes: 108008
#include <iostream>
using namespace std;
int main(){
        long long int A,B,C;
        cin>>A>>B>>C;
        if(A==B && B==C && A%2==0){
            cout<<-1<<endl;
        }else if(A%2==1 || B%2==1 || C%2==1){
            cout<<0<<endl;
        }else{
            int noTimes = 0;
            while(A%2==0 && B%2==0 && C%2==0){
                long long int tempA = (B/2) + (C/2);
                long long int tempB = (A/2) + (C/2);
                long long int tempC = (A/2) + (B/2);
                A = tempA;
                B = tempB;
                C = tempC;
                noTimes++;
            }
            cout<<noTimes<<endl;
        }
}

Measured memory_bytes: 3580
# coding: utf-8
# Your code here!
# coding: utf-8
from fractions import gcd 
from functools import reduce
import sys
sys.setrecursionlimit(200000000)
from inspect import currentframe


# my functions here!
#標準エラー出力
def printargs2err(*args):
    names = {id(v):k for k,v in currentframe().f_back.f_locals.items()}
    print(', '.join(names.get(id(arg),'???')+' : '+repr(arg) for arg in args),file=sys.stderr)
def debug(x):
    print(x,file=sys.stderr)
def printglobals():
    for (symbol, value) in globals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)
def printlocals():
    for (symbol, value) in locals().items():
        print('symbol="%s"、value=%s' % (symbol, value),file=sys.stderr)


#入力（後でいじる）
def pin(type=int):
    return map(type,input().split())
#どっかで最悪計算量の入力データを用意する関数を作ろう？
"""
愚直に操作を実装する
"""
#solution:
N=int(input())
S=[input() for i in range(N)]
import collections as cl
#print(S)
a=cl.Counter(S)
b=(a.most_common())
#print(b)
maxvalue=b[0][1]
ans=[]
for i in range(len(b)):
    if b[i][1] == maxvalue:
        ans.append(b[i][0])
for w in sorted(ans):
    print(w)
#print([["NA","YYMM"],["MMYY","AMBIGUOUS"]][cMMYY][cYYMM])



Measured memory_bytes: 51628
# AGC028
from fractions import gcd


def main():
    n, m = tuple(map(int, input().rstrip().split()))
    S, T = tuple(input().rstrip() for _ in range(2))
    l = n // gcd(n, m) * m
    x = {}
    for i in range(n):  # place S in x
        j = (l // n) * i
        x[j] = S[i]
    for i in range(m):  # check T adapts to x or not
        j = (l // m) * i
        if j in x and x[j] != T[i]:
            print(-1)
            break
    else:
        print(l)


if __name__ == "__main__":
    main()

Measured memory_bytes: 17488
fun main(args: Array<String>) {
    solve()
}

fun solve() {
    val input = readLine()!!.split(" ").map { it.toInt() }
    for (i in 1 .. 1000) {
        if (i * 8 / 100 == input[0] && i * 10 / 100 == input[1]) {
            println(i)
            return
        }
    }
    println(-1)
}

Measured memory_bytes: 37904
#include<bits/stdc++.h>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0;re char v=getchar();
	while(v<'0')v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return t;
}
int n,m,ans;
signed main(){
	n=read();m=100;
	while(m<n)++ans,m=1.01*m;
	printf("%lld",ans);
}


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

#define ll long long
#define N 100005
#define mod 1000000007

int dp[N][2], n, u, v;  // 0: white 1 : black
vector<vector<int> > g(100005, vector<int> (0));

int solve(int u, int tight, int par) {
	if (dp[u][tight] != -1) {
		return dp[u][tight];
	}
	dp[u][tight] = 0;
	ll prod1 = 1, prod2 = 1;

	for (auto it : g[u]) {
		if (it != par) {
			prod1 *= solve(it, 0, u);
			prod1 %= mod;
			if (!tight) {
				prod2 *= solve(it, 1, u);
				prod2 %= mod;
			}
		}
	}

	dp[u][tight] += prod1;
	//dp[u][tight] %= mod;
	if (!tight) {
		dp[u][tight] += prod2;
	}

	return dp[u][tight] % mod;
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;

	for (int i = 0; i < n - 1; i++) {
		cin >> u >> v;
		g[u].push_back(v);
		g[v].push_back(u);
	}

	if (n == 1) {
		cout << 2 << "\n";
		return 0;
	}

	memset(dp, -1, sizeof dp);
	cout << solve(1, 0, -1);
}

Measured memory_bytes: 14848
import java.util.*;
import java.io.*;
public class Main
{
    public static void main(String []args) throws IOException {
    	FastScanner in  = new FastScanner(System.in);
    	PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)), false);
    	solve(in, out);
    	in.close();
    	out.close();
    }
    static long gcd(long a, long b){ return (b==0) ? a : gcd(b, a%b); }
    static int gcd(int a, int b){ return (b==0) ? a : gcd(b, a%b); }
    static class FastScanner{
	BufferedReader reader;
	StringTokenizer st;
	FastScanner(InputStream stream){reader=new BufferedReader(new InputStreamReader(stream));st=null;}
	String next(){while(st == null || !st.hasMoreTokens()){try{String line = reader.readLine();if(line == null){return null;}
	     st = new StringTokenizer(line);}catch (Exception e){throw new RuntimeException();}}return st.nextToken();}
	String nextLine()  {String s=null;try{s=reader.readLine();}catch(IOException e){e.printStackTrace();}return s;}
	int    nextInt()   {return Integer.parseInt(next());}
	long   nextLong()  {return Long.parseLong(next());}
	double nextDouble(){return Double.parseDouble(next());}
	char   nextChar()  {return next().charAt(0);}
	int[]  nextIntArray(int n)         {int[] arr= new int[n];   int i=0;while(i<n){arr[i++]=nextInt();}  return arr;}
	long[] nextLongArray(int n)        {long[]arr= new long[n];  int i=0;while(i<n){arr[i++]=nextLong();} return arr;}
	int[]  nextIntArrayOneBased(int n) {int[] arr= new int[n+1]; int i=1;while(i<=n){arr[i++]=nextInt();} return arr;}
	long[] nextLongArrayOneBased(int n){long[]arr= new long[n+1];int i=1;while(i<=n){arr[i++]=nextLong();}return arr;}
	void   close(){try{reader.close();}catch(IOException e){e.printStackTrace();}}
    }
    
    /********* SOLUTION STARTS HERE ************/
    
    private static void solve(FastScanner in, PrintWriter out){
        int n = in.nextInt();
        int w[] = new int[n];
        int sum = 0;
        for(int i=0;i<n;i++){
            w[i] = in.nextInt();
            sum+=w[i];
        }
        int w1[] = new int[n];
        int w2[] = new int[n];
        w1[0] = w[0];
        sum-=w[0];
        w2[0] = sum;
        for(int i=1;i<n;i++){
            w1[i] = w1[i-1]+w[i];
            sum-=w[i];
            w2[i] = sum;
        }
        int ans = 1000000000;
        for(int i=0;i<n;i++){
            int d = Math.abs(w1[i] - w2[i]);
            ans = Math.min(d,ans);
        }
        out.println(ans);
    }
    
    /************* SOLUTION ENDS HERE **********/
}

Measured memory_bytes: 22228
#include <iostream>
#include <cstdio>
#include <cstdlib>

struct Node {
  struct Node *right;
  struct Node *left;
  struct Node *parent;
  int key;
};

struct Node *insertNode(struct Node *root, int k){
  struct Node *y = NULL;
  struct Node *x = root;
  struct Node *newNode;

  newNode = (struct Node *) std::malloc(sizeof(struct Node));
  
  newNode->right = NULL;
  newNode->left = NULL;
  newNode->parent = NULL;
  newNode->key = k;

  while (x != NULL) {
    y = x;
    
    if (newNode->key < x->key) {
      x = x->left;
    } else {
      x = x->right;
    }
  }

  newNode->parent = y;

  if (y == NULL) {
    root = newNode;
  } else if (newNode->key < y->key) {
    y->left = newNode;
  } else {
    y->right = newNode;
  }

  return root;
}

void printByInorder(struct Node *root) {
  if (root == NULL) {
    return;
  }

  if ((root->left == NULL) && (root->right == NULL)) {
    std::cout << " " << root->key;
    return;
  }

  printByInorder(root->left);
  std::cout << " " << root->key;
  printByInorder(root->right);
}

void printByPreorder(struct Node *root) {
  if (root == NULL) {
    return;
  }

  if ((root->left == NULL) && (root->right == NULL)) {
    std::cout << " " << root->key;
    return;
  }
  
  std::cout << " " << root->key;
  printByPreorder(root->left);
  printByPreorder(root->right);
}

bool find_value(struct Node* root, int v) {
  if (root == NULL) {
    return false;
  }

  struct Node *node = root;

  while (node != NULL) {
    if (node->key == v) {
      return true;
    }
    
    if (node->key < v) {
      node = node->right;
    } else {
      node = node->left;
    }
  }

  return false;
}

int main(){
  int n = 0;
  struct Node *root = NULL;

  std::cin >> n;

  for (int i = 0; i < n; i++) {
    std::string command;
    
    std::cin >> command;
    
    if (command.at(0) == 'p') {
      printByInorder(root);
      std::cout << std::endl;

      printByPreorder(root);
      std::cout << std::endl;
    } else if (command.at(0) == 'i') {
      int k = 0;

      std::cin >> k;
      
      root = insertNode(root, k);
    } else if (command.at(0) == 'f') {
      int v = 0;

      std::cin >> v;
      
      if (find_value(root, v)) {
	std::cout << "yes";
      } else {
	std::cout << "no";
      }

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

  return 0;
}

Measured memory_bytes: 19952
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <algorithm>
#include <iostream>
#include <vector>
#include <bitset>
#include <queue>
#include <map>
#include <utility>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define MOD 10000000000+7    //10億　= 10^9になってる
#define juu 100000               //10万 10e5
#define hyaku 1000000            //100万　10e6
#define mINF -922337200085470000 //llのmax-1桁の小さい方
#define pINF 922337203600070000  //llのmax-1桁のデカい方
#define uINF 1844674407300000000 //ullのmax-1桁してる
#define pi 3.1415926535897932384
ll factor[300];
ll memory[300];
/*素朴法で計算
factorは必ずmemset(factor,0,sizeof(factor));
グローバルであるmemoryに個数を書き込む
memory配列の走査にはfactorの要素を使う*/
void primefac(ll num)
{
    int i = 0, kosuu = 0;
    while (*(factor + i) != 0)
    {
        while (num % *(factor + i) == 0)
        {
            num /= *(factor + i);
            memory[*(factor + i)] += 1;
        }
        if (num == 1)
            break;
        i++;
    }
}
/*グローバルにあるfactorに素数書き込む.個数を返すので配列は-1しろforは<*/
int elast(ll number)
{
    ll tmp = 0;
    int flag = 0;
    *factor = 2;
    for (int i = 3; i <= number; i++)
    {
        flag = 0;
        for (int j = 0; j <= tmp; j++)
        {
            if (i % (*(factor + j)) == 0)
            {
                flag = 1;
                break;
            }
        }
        if (flag)
            continue;
        tmp += 1;
        *(factor + tmp) = i;
    }
    return tmp + 2;
}
/*整数をqsortする為だけのもの*/
long long compare(const long long *a, const long long *b)
{
    if (*a < *b)
        return -1;
    else if (*a > *b)
        return 1;
    return 0;
}
/*intで収まる範囲であってくれ*/
ll nCr(int n, int r)
{
    ll val = 1;
    int i;
    if (r == 0)
        return 1;
    for (i = 0; i < n - r; i++)
    {
        val *= (n - i);
        val /= (i + 1);
    }
    return val;
}
/*intで収まる範囲であってくれ*/
ll nPr(int n, int r)
{
    ll val = 1;
    int i;
    for (i = 0; i < r; i++)
    {
        val *= (n - i);
    }
    return val;
}

void chmin(ll &a, ll b)
{
    if (a > b)
        a = b;
}
void chmax(ll &a, ll b)
{
    if (a < b)
        a = b;
}

/*
qsort(array,length,sizeof(int),(int(*)(const int*, const int*))compare);
使う時これをコピペ
*/


int main()
{
    string a;
    cin>>a;
    ll b=1;
    sort(a.begin(),a.end());
    for(int i=1;i<a.size();i++)
    {
    	if(a[i-1]==a[i]){
    		b++;
    		}
    	if(a[i-1]!=a[i])
    	{
    		if(b%2==1){
    			cout <<"No";
    			return 0;
    			}
    		b = 1;
    	}
    }
    if(b%2==1){
    			cout <<"No";
    			return 0;
    			}
    cout << "Yes";
        return 0;
}


Measured memory_bytes: 256
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int h,w;
	cin>>h>>w;
	char c[h+1][w+1];
	loop(i,1,h+1){
		loop(j,1,w+1){
			cin>>c[i][j];
		}
	}
	loop(i,1,2*h+1){
		loop(j,1,w+1){
			cout<<c[(i+1)/2][j];
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ','); cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n;
  db x,ans=0;
  cin>>n;
  rep(i,1,n+1)
    {
      cin>>x;
      ans+=1.0/x;
    }
  ans=1.0/ans;
  cout<<setprecision(10)<<fixed<<ans<<endl;
  return 0 ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int m = t.size();
    vector<vector<int>> dp(n+1,vector<int>(m+1)), backi(n+1,vector<int>(m+1)), backj(n+1,vector<int>(m+1));
    rep(i,1,n+1) rep(j,1,m+1) {
        dp[i][j] = dp[i-1][j];
        backi[i][j] = i-1;
        backj[i][j] = j;
        if(dp[i][j-1]>dp[i][j]) {
            dp[i][j] = dp[i][j-1];
            backi[i][j] = i;
            backj[i][j] = j-1;
        }
        if(s[i-1]==t[j-1] && dp[i-1][j-1]+1>dp[i][j]) {
            dp[i][j] = dp[i-1][j-1]+1;
            backi[i][j] = i-1;
            backj[i][j] = j-1;
        }
    }
    int i = n, j = m;
    string acc;
    while(i>0 && j>0) {
        if(backi[i][j] <i && backj[i][j]<j) {
            --i;
            --j;
            acc += s[i];
        }
        else {
            int ii = backi[i][j];
            j = backj[i][j];
            i = ii;
        }
    }
    reverse(all(acc));
    cout<<acc<<"\n";

    
}


Measured memory_bytes: 106112
N = int(input())
Ai = list(map(int, input().split()))
s = 0

for i in range(1, len(Ai)):
  if Ai[i-1] > Ai[i]:
    sa = abs(Ai[i-1] - Ai[i])
    Ai[i] += sa
    s += sa

print(s)

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

#define ll long long
#define INF 99999999
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

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

    if(s == "Sunny") cout << "Cloudy" << endl;
    else if(s == "Cloudy") cout << "Rainy" << endl;
    else cout << "Sunny" << endl;
}


Measured memory_bytes: 256
#include <cstdlib>
#include <iostream>
#include <typeinfo>
//#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>

using namespace std;

int main()
{
  int x;
  cin >> x;
  vector<int> a{3, 5, 7};
  bool b = false;
  for (int i : a)
  {
    if(i==x){
      b = true;
      break;
    }
  }
  if(b){
    cout << "YES" << endl;
  }else{
    cout << "NO" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> pii;
typedef long long lld;
lld n,fin,nt,u;
void update(lld x,lld r){
    lld xt=x,c=0;
    while(xt!=0){
        c+=(xt%10),xt/=10;
    }
    fin=max(fin,c+r);
}
int main(){
    scanf("%lld",&n);
    nt=n;
    while(nt>0){
        update(nt,u);
        if(nt%10==9) u+=9,nt/=10;
        else u+=9,nt/=10,nt-=1;
    }
    if(nt==0) fin=max(fin,u);
    printf("%lld\n",fin);
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
using namespace std;
typedef long long ll;
const ll MOD = 1000000007;
const int MAX_N = 1010;
int N, M;
int Parent[MAX_N];
int Flg[MAX_N];
vector<int>Childs[MAX_N];
ll score[MAX_N];
ll ans = 1;
ll dp(int id){
    if(Childs[id].size()==0)return 2;
    ll tmp = 1;
    for(int i=0;i<Childs[id].size();i++){
        if(Flg[Childs[id][i]] || Childs[id][i]==id)continue;
        tmp = tmp * dp(Childs[id][i]) % MOD;
    }
    return (tmp+1LL)%MOD;
}
int main(void){
    // Your code here!
    cin>>N>>M;
    for(int i=0;i<M;i++){
        int s, d;
        cin>>s>>d;
        Parent[s] = d;
        Childs[d].push_back(s);
    }
    for(int i=1;i<=N;i++){
        int flg = 0;
        for(int tmp = i, cnt=0;Parent[tmp] && cnt < MAX_N;tmp=Parent[tmp], cnt++){
            if(Parent[tmp]==i){
                flg=1;
                break;
            }
        }
        if(flg==0)continue;
        for(int tmp = Parent[i];tmp!=i;tmp=Parent[tmp]){
            Flg[tmp]=1;
            for(int j=0;j<Childs[tmp].size();j++){
                Childs[i].push_back(Childs[tmp][j]);
                Parent[Childs[tmp][j]] = i;
            }
        }
        Parent[i]=0;
    }
    for(int i=1;i<=N;i++){
        if(Parent[i])continue;
        ans = ans * dp(i) % MOD;
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3228
#include <stdio.h>
struct Dice {
  int face1, face2, face3, face4, face5, face6;
};

void roll_for_E(struct Dice *dice);
void roll_for_N(struct Dice *dice);
void roll_for_S(struct Dice *dice);
void roll_for_W(struct Dice *dice);


int main(void)
{
  struct Dice dice;
  char ch;
  scanf("%d%d%d%d%d%d", &(dice.face1), &(dice.face2), &(dice.face3), &(dice.face4), &(dice.face5), &(dice.face6));

  (void)getchar();

  while((ch=getchar())!='\n') {
    if(ch=='E')
      roll_for_E(&dice);
    if(ch=='N')
      roll_for_N(&dice);
    if(ch=='S')
      roll_for_S(&dice);
    if(ch=='W')
      roll_for_W(&dice);
  }
  printf("%d\n", dice.face1);
  return 0;
}

void roll_for_E(struct Dice *dice)
{
  int temp;
  temp = dice->face1;
  dice->face1=dice->face4;
  dice->face4=dice->face6;
  dice->face6=dice->face3;
  dice->face3=temp;
}

void roll_for_N(struct Dice *dice)
{
  int temp;
  temp = dice->face1;
  dice->face1=dice->face2;
  dice->face2=dice->face6;
  dice->face6=dice->face5;
  dice->face5=temp;
}

void roll_for_S(struct Dice *dice)
{
  int temp;
  temp = dice->face1;
  dice->face1=dice->face5;
  dice->face5=dice->face6;
  dice->face6=dice->face2;
  dice->face2=temp;
}

void roll_for_W(struct Dice *dice)
{
  int temp;
  temp = dice->face1;
  dice->face1=dice->face3;
  dice->face3=dice->face6;
  dice->face6=dice->face4;
  dice->face4=temp;
}

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

using namespace std;
#define all(a)a.begin(),a.end()
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod =(1e9)+7;
using P = pair<ll,ll>;

int main(){
    ll h,w;cin>>h>>w;
    vector<vector<ll>>a(h,vector<ll>(w));
    for (int i = 0; i < h; ++i) {
        for (int j = 0; j < w; ++j) {
            cin >>a[i][j];
        }
    }
    ll opt=0;
    vector<vector<ll>>ans(4,vector<ll>());
    for (int i =h-1; i >=0 ; --i) {
        for (int j = 0; j < w; ++j) {
            if(i-1<0)continue;
            if(a[i][j]%2==0)continue;
                a[i-1][j]++;
                a[i][j]--;
                opt++;
                ans[0].push_back(i);
                ans[1].push_back(j);
                ans[2].push_back(i-1);
                ans[3].push_back(j);
        }
    }
    for (int i = 0; i < w; ++i) {
        if(a[0][i]%2==0)continue;
        if(i+1>=w)continue;
        a[0][i+1]++;a[0][i]--;
        opt++;
        ans[0].push_back(0);
        ans[1].push_back(i);
        ans[2].push_back(0);
        ans[3].push_back(i+1);
    }
    cout <<opt<<endl;
    for (int i = 0; i < opt; ++i) {
        cout <<ans[0][i]+1<<" "<<ans[1][i]+1<<" "<<ans[2][i]+1<<" "<<ans[3][i]+1<<endl;
    }
    return 0;
}

Measured memory_bytes: 8152
import java.util.Scanner;
public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] array = new int[m];
		for(int i = 0; i < m; i++){
			array[i] = scan.nextInt();
		}
		int asobi = n;
		for(int i = 0; i < m; i++){
			asobi -= array[i];
		}
		if(asobi < 0){
			asobi = -1;
		}
		System.out.println(asobi);
	}
}

Measured memory_bytes: 39596
import java.util.Scanner;

 class Main{

public static void f(int A[],int N){
int i;
for(i=0;i<N;i++){
	if(i>0)
		System.out.print(" ");
  System.out.print(A[i]);
}
 System.out.println();
}
 
 
   
public static void insertionSort(int A[],int N){
    int i,j,v;
    for(i=1;i<N;i++){
        v=A[i];
        j=i-1;
   while(j>=0 && A[j]>v){
       A[j+1]=A[j];
       j--;
}
   A[j+1]=v;
  f(A,N);
}
}
   


public static void main(String[] args){
         
		 Scanner sc= new Scanner(System.in);
	         int N=sc.nextInt();
             int A[]=new int[100];
             
             int i;
             for(i=0;i<N;i++){
            	 A[i] = sc.nextInt();
             }
	        
	   f(A,N);
       
        insertionSort(A,N);
        sc.close();
}
}

Measured memory_bytes: 34408