akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
template<class T> ostream& operator<<(ostream &os, vector<T> V) {
	os << "[ "; for(auto v : V) os << v << " "; return os << "]";
}
template<class L, class R> ostream& operator<<(ostream &os, pair<L,R> P) {
	return os << "(" << P.first << "," << P.second << ")";
}
#define TRACE
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1> void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << 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(...) 1
#endif
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define mems(x, y) memset(x, y, sizeof(x))
#define rep(i, n) for (int i = 0; i < n; ++i)
#define irep(i, n) for (int i = 1; i <= n; ++i)
#define print(x) cout << x << '\n'
#define err(x) clog << x << '\n'
typedef long long ll;
#define int ll
typedef long double ld;
#define double ld
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
const int INF = 0x3f3f3f3f;
const int LINF = 0x3f3f3f3f3f3f3f3f;
const int mod = (119<<23)+1;
const int M = 1e9+7;
const int N = 1e5+5;

signed main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cout << fixed << setprecision(15);
	
	int a, b; cin >> a >> b;
	if (a == 1 && b == 2) print(3);
	else if (a == 2 && b == 3) print(1);
	else if (a == 3 && b == 1) print(2);
	else if (a == 2 && b == 1) print(3);
	else if (a == 3 && b == 2) print(1);
	else if (a == 1 && b == 3) print(2);
}


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

// TYPEDEF
// ----------------------------------------
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> Pair;
typedef vector<ll> vll;
typedef vector<vector<ll>> Graph;
typedef vector<string> vs;
typedef vector<pair<ll, ll>> Pll;
typedef queue<ll> qll;

// REPEAT
// ----------------------------------------
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define REPA(i,a) for(ll i=0;i<(ll)(a.size());i++);
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define COUT(a) cout << (a) << endl;
#define ENDL(a) cout << endl;
#define COUTA(i,a) for(ll i=0;i<(ll)(a.size());i++) {cout << (a)[i] << " ";} cout << endl;

// UTIL
// ----------------------------------------
#define pb push_back
#define paired make_pair
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort((a).begin(),(a).end())
#define RSORT(a) sort((a).rbegin(), (a).rend())

// DEBUG
// ----------------------------------------
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

// BIT FLAG
// ----------------------------------------
const unsigned int BIT_FLAG_0 = (1 << 0); // 0000 0000 0000 0001
const unsigned int BIT_FLAG_1 = (1 << 1); // 0000 0000 0000 0010
const unsigned int BIT_FLAG_2 = (1 << 2); // 0000 0000 0000 0100
const unsigned int BIT_FLAG_3 = (1 << 3); // 0000 0000 0000 1000
const unsigned int BIT_FLAG_4 = (1 << 4); // 0000 0000 0001 0000
const unsigned int BIT_FLAG_5 = (1 << 5); // 0000 0000 0010 0000
const unsigned int BIT_FLAG_6 = (1 << 6); // 0000 0000 0100 0000
const unsigned int BIT_FLAG_7 = (1 << 7); // 0000 0000 1000 0000
const unsigned int BIT_FLAG_8 = (1 << 8); // 0000 0001 0000 0000
const unsigned int BIT_FLAG_9 = (1 << 9); // 0000 0010 0000 0000
const unsigned int BIT_FLAG_10 = (1 << 10); // 0000 0100 0000 0000
const unsigned int BIT_FLAG_11 = (1 << 11); // 0000 1000 0000 0000

// CONST
// ----------------------------------------
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI=3.14159265358979323846; // or M_PI
constexpr int MOD = 1000000007;


void Main() {
    ll r, d, x2000;
    cin >> r >> d >> x2000;

    ll x = x2000;
    REP(i, 10) {
      x = r * x - d;
      COUT(x);
    }


}



int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
}

/*
2 10 20
*/


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

using namespace std;
typedef long long ll;

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

  bool from1[200000] = {}, to2[200000] = {};

  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    if (a == 1) {
      from1[b] = true;
    }
    if (b == N) {
      to2[a] = true;
    }
  }

  for (int i = 1; i < N; i++){
    if (from1[i] && to2[i]) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
  }
  cout << "IMPOSSIBLE" << endl;
  return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
//#define int long long
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
using namespace std;
#define endl '\n'
#define fori(s,n) for(int i=s;i<n;i++) 
#define forj(s,n) for(int j=s;j<n;j++) 
int OO = 1e9 + 9;
#define vii vector<int>
int n;
vii v;
int maxi = 1061109567;
int dp[100000 + 9];
int solve(int x) {
	
	if (x == n)
		return 0;
	if (x > n)
		return OO;
	int& ret = dp[x];
	if (ret!=maxi) return ret;
	int r1 = abs(v[x] - v[x + 1]) + solve(x + 1);
	int r2 = abs(v[x] - v[x + 2]) + solve(x + 2);
	return ret=min(r1, r2);
}
signed main()
{
	fast;
	memset(dp, '?', sizeof(dp));
	
	cin >> n;
	v = vii(n + 9);
	fori(1, n + 1) cin >> v[i];
	cout << solve(1) << endl;
}


Measured memory_bytes: 10220
sub f{my($u,$p)=@_;push@{--$|?b:c},$u;$_-$p&&f($_,$u)for@$u;--$|}<>;map{push@$_,$u-$_+$;for($u,$;)=split}<>;@a=($,=$",(f 1)x$.);@b>$./3&@c>$./3?(map$a[$_]=$#x+=3,@b)+map$a[$_]=++$y*3-2,@c:map$a[$_]=$#x+=$#x%3,@b>@c?@b:@c;print map$_<=$.&&$_||3*++$z,@a

Measured memory_bytes: 271736
#pragma region
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define double long double
#define vi vector<int>
#define vd vector<double>
#define vs vector<string>
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define revi(i, m, n) for(int i=(int)(m-1);i>=(int)(n);i--)
#define rev(i, n) revi(i, n, 0)
#define each(i, n) for(auto&& i: n)
#define sz(v) ((int)(v).size()) 
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define uniq(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
#define dump(x) cerr << #x << " = " << x << endl
#define gcd __gcd
int lcm(int a, int b){return a / gcd(a, b) * b;}
const int INF = 1e18;
const int MOD = 1e9 + 7;
const double EPS = 1e-15;
const double PI = acos(-1);
int dig(int n){return (int)(log10(n) + 1);}
int abc(char x){return (int)(x)-(int)('a');} // 0~25
char abc(int x){return (char)(x+(int)('a'));} 
int ABC(char x){return (int)(x)-(int)('A');}
char ABC(int x){return (char)(x+(int)('A'));}
void solve();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(20);
	solve();
}
#pragma endregion

void solve() {
	int N; cin >> N;
	vd A(N);
	rep(i, N) cin >> A[i];
	double ans = 0;
	rep(i, N) ans += 1 / A[i];
	cout << 1 / ans << endl;
}

Measured memory_bytes: 256
#include <stdio.h>          // printf(), scanf()
#define MAX_N 500000

typedef struct node_tbl
{
	int key;
	int parent;
	int left;
	int right;
} node;

const int nil = -1;
node t[MAX_N + 1];
int root;
int ix;

void
insert(int k)
{
	int y = nil;
	int x = root;
	int z = ix++;

	t[z].key = k;
	t[z].left = nil;
	t[z].right = nil;

	while (x != nil)
	{
		y = x;
		if (t[z].key < t[x].key)
			x = t[x].left;
		else
			x = t[x].right;
	}

	t[z].parent = y;
	if (y == nil)
		root = z;
	else
	{
		if (t[z].key < t[y].key)
			t[y].left = z;
		else
			t[y].right = z;
	}
}

void
inorder(int u)
{
	if (u == nil)
		return;

	inorder(t[u].left);
	printf(" %d", t[u].key);
	inorder(t[u].right);
}

void
preorder(int u)
{
	if (u == nil)
		return;

	printf(" %d", t[u].key);
	preorder(t[u].left);
	preorder(t[u].right);
}

int
main(int argc, char** argv)
{
	char command[8];
	int n;
	int x;
	int i;

	root = nil;
	ix = 0;
	scanf("%d", &n);
	for (i = 0; i < n; ++i)
	{
		scanf("%s", command);
		switch (command[0])
		{
		case 'i':
			scanf("%d", &x);
			insert(x);
			break;

		case 'p':
		default:
			inorder(root);
			printf("\n");

			preorder(root);
			printf("\n");
			break;
		}
	}

	return 0;
}



Measured memory_bytes: 9504
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF (1<<29)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()
#define uniq(v) v.erase(unique(all(v)),v.end())


int n;
long long a[200000];


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

	cin >> n;
	rep(i, n)cin >> a[i];

	long long ans = 1LL << 60;

	long long h = 0, t = 0;
	rep(i, n)t += a[i];
	rep(i, n - 1) {
		h += a[i];
		t -= a[i];
		ans = min(ans, abs(h - t));
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 1792
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        var nmvp = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var n = nmvp[0];
        var m = nmvp[1];
        var v = nmvp[2];
        var p = nmvp[3];
        var a = Console.ReadLine().Split().Select(long.Parse).OrderByDescending(x => x).ToArray();
        //m回v個 +1 最終的にtop p
        //単調性があるため二分探索可能
        var valid = 0;
        var invalid = n;
        while (invalid - valid > 1)
        {
            var mid = (valid + invalid) / 2;
            if (mid.CanAdopt(a, m, v, p)) valid = mid;
            else invalid = mid;
        }
        Console.WriteLine(invalid);
    }
    static bool CanAdopt(this int ind, long[] problems, long m, long v, long p)
    {
        long maxScore = problems[ind] + m;
        v--;

        int i = 0;
        //targetより大きいのがp個以上あったら
        for (; i < problems.Length; i++)
            if (problems[i] <= maxScore) break;

        int largeProblemCount = i;
        if (p <= largeProblemCount) return false;
        //target以上のには投票して構わない=投票回数を個数分減らせる
        v -= largeProblemCount;

        //問題はp以下の雑魚 とりあえず最初の複数個は全部埋める 上がp-1個になった瞬間終わり
        for (; i < problems.Length && largeProblemCount < p - 1 && 0 < v; i++)
        {
            if (ind == i) continue;
            if (maxScore < problems[i] + m) largeProblemCount++;
            v--;
        }
        long votes = 0;
        //pに揃える
        for (; i < problems.Length; i++)
        {
            if (ind == i) continue;
            votes += Min(m, Max(0, maxScore - problems[i]));
        }
        return m * v <= votes;
    }
}


Measured memory_bytes: 26080
#include <bits/stdc++.h>
#include <complex>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
#define mp make_pair
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,K,Q,A,B,C,L,R;
string S,T;
const ll MOD = (1e+9) + 7;
const ll INF = 1LL << 60;
const long double EPS = 1e-9;
typedef pair<ll,ll> P;

typedef vector<P> vp;
typedef vector<vp> matP;


int main() {
    cin>>H>>W;
    if(H%3 == 0 || W%3 == 0) {
        cout<<0<<endl;
        return 0;
    }
    ll ans = min(H,W);
    reps(i,1,H){
        if(ans > max({abs(W*i - (W/2) * (H-i)), abs(W*i - ((1 + W)/2) * (H-i)), (W%2)*(H-i)})){
            ans = max({abs(W*i - (W/2) * (H-i)), abs(W*i - ((1 + W)/2) * (H-i)), (W%2)*(H-i)});
        }
    }
    swap(H,W);
    reps(i,1,H){
        if(ans > max({abs(W*i - (W/2) * (H-i)), abs(W*i - ((1 + W)/2) * (H-i)), (W%2)*(H-i)})){
            ans = max({abs(W*i - (W/2) * (H-i)), abs(W*i - ((1 + W)/2) * (H-i)), (W%2)*(H-i)});
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val grouping = (i: Int) => i match {
    case 1 | 3 | 5 | 7 | 8 | 10 | 12 => "A"
    case 2 => "B"
    case _ => "C"
  }
  val x, y = sc.nextInt()
  println(if (grouping(x) == grouping(y)) "Yes" else "No")
}


Measured memory_bytes: 55340
#include <algorithm>
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;
typedef long long int ll;

int main()
{
	int n;
	cin>>n;
	vector<vector<int>> storeList(n);
	for(int i = 0; i < n; i++){
		storeList[i] = vector<int>(10);
		for(int j = 0; j < 10; j++){
			cin>>storeList[i][j];
		}
	}
	
	vector<vector<int>> P(n);
	for(int i = 0; i < n; i++){
		P[i] = vector<int>(11);
		for(int j = 0; j <= 10; j++){
			cin>>P[i][j];
		}
	}
	ll ans = -1000000000;
	for(int bit = 1; bit < (1<<10); bit++){
		vector<int> c(n,0);
		for(int i = 0; i < n; i++){
			for(int j = 0; j < 10; j++){
				if( bit & (1<<j) && storeList[i][j] == 1){
					c[i]++;
				}
			}
		}
		ll localAns = 0;
		for(int i = 0; i < n; i++){
			localAns += P[i][c[i]];
		}
		ans = max(ans,localAns);
	}
	cout<<ans<<endl;
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  if(n%10 == 2 || n%10 == 4 || n%10 == 5 || n%10 == 7 || n%10 == 9) {
    cout << "hon" << endl;
  } else
  if(n%10 == 0 || n%10 == 1 || n%10 == 6 || n%10 == 8) {
    cout << "pon" << endl;
  } else
  if(n%10 == 3 ) {
    cout << "bon" << endl;
  }
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;


int main(){

    int N, K, temp;
    cin >> N >> K;
    vector<int> Ps(N);

    for(int i=0;i<N;++i){
        cin >> temp;
        Ps[i] = temp;
    }

    long long max_E = 0;
    long long temp_E = 0;

    for(int j=0;j<K;++j){
        temp_E += ( Ps[j] + 1 );
    }
    max_E = temp_E;
    
    for(int i=K;i<N;++i){
        temp_E = temp_E + Ps[i] - Ps[i-K];
        max_E = max( max_E, temp_E );
    }
   
    printf("%.12f\n", static_cast<double> (max_E) / 2.0 );

    
    return 0;
}


Measured memory_bytes: 1024
from collections import deque
n,q=map(int, input().split())
edges = [[]for _ in range(n)]
counter = [0]*n
visited=[-1]*n
que=deque()

for i in range(n-1):
    a,b=map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)



for i in range(q):
    a,b=map(int, input().split())
    counter[a-1]+=b


que.append(0)
while que:
    v=que.popleft()
    visited[v]=1
    for next_v in edges[v]:
        if visited[next_v]!=-1:continue
        counter[next_v]+=counter[v]
        que.append(next_v)
print(*counter)


Measured memory_bytes: 56084
#include <string>
#include <vector>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <map>
#include <list>
#include <set>
#include <numeric>
#include <queue>
#include <stack>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <climits>
#include <cfloat>
#include <ctime>
#include <complex>
#include <cassert>
#include <array>
#include <bitset> 
#include <unordered_map>

using namespace std;
typedef long long LL;
typedef pair<int,int> P;

const int L=2e5+1;
LL R[L];
int main() {
	int N,K;
	cin >> N >> K;
	map<LL,int> cs;
	LL s=0;
	LL ret=0;
	R[0]=0;
	cs[R[0]]++;
	for(int i=1;i<=N;i++){
		LL a;
		cin >> a;
		if(i-K>=0){
			cs[R[i-K]]--;
		}
		s+=a-1;
		s%=K;
		R[i]=s;
		//cerr << i << ", " << R[i] << ": " << cs[s] << endl;
		ret+=cs[s];
		cs[s]++;
	}
	//cerr << endl;
	cout << ret << endl;


	return 0;
}



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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl




typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 110;







int n, m, c;
int a[maxn*maxn];
int g[maxn][maxn];

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

    cin>>n>>m>>c;


    for (int i=1; i<=c; i++) {
	cin>>a[i];
    }

    
    for (int i=0; i<n; i++) {
	if (i%2==0) {
	    for (int j=0; j<m; j++) {
		g[i][j]=c;
		if (--a[c] == 0) c--;
	    }
	} else {
	    for (int j=m-1; j>=0; j--) {
		g[i][j]=c;
		if (--a[c] == 0) c--;
	    }
	}
    }


    for (int i=0; i<n; i++) {
	for (int j=0; j<m; j++) {
	    cout<<g[i][j]<<" ";
	}
	cout<<"\n";
    }

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <set>

int main()
{
    std::string str;
    std::cin >> str;
    int k;
    std::cin >> k;

    std::set<std::string> s;
    for (int i = 0; i < 26 && s.size() <= k; ++i)
    {
        for (int j = 1; j <= 5 && j <= str.size(); ++j)
        {
            for (int l = 0; j + l <= str.length(); ++l)
            {
                //std::cout << i << j << l << std::endl;
                if (str[l] == 'a' + i && l+j <= str.length()) 
                {
                    s.insert(str.substr(l, j));
                }
            }
        }
    }
    auto itr = s.begin();
    for(int i = 1; i < k; ++i)
    {
        itr++;
    }

    std::cout << *itr << std::endl;
    return 0;
}


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

typedef pair<int, int> Pi;
typedef tuple<int, int, int> Ti;
typedef vector<int> vint;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

int lcm(int a, int b) {
  return a / __gcd(a, b) * b;
}

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int N;
  cin >> N;
  int LCM = 1;
  rep(i, N) {
    int T;
    cin >> T;
    LCM = lcm(LCM, T);
  }
  cout << LCM << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll a7=1000000007;
ll inf=1000000000000000;

ll min(ll a,ll b){
    if(a<b)return a;
    return b;
}
ll max(ll a,ll b){
    if(a>b)return a;
    return b;
}

vector<vector<pair<ll,ll>>> g(400);
ll cc;
bool bo[400][400];
pair<ll,ll> mini[400][400];
ll n,m,l;

void ki(ll i,ll x){//iからの最短経路を求める　xに着目
    ll mi=inf*10;
    ll ff,ss;
    for(ll j=0;j<g[x].size();j++){
        if(bo[i][g[x][j].first]==false){
            if(g[x][j].second>mini[i][x].second){
                ff=mini[i][x].first+1;
                ss=l-g[x][j].second;
            }else{
                ff=mini[i][x].first;
                ss=mini[i][x].second-g[x][j].second;
            }
            if(mini[i][g[x][j].first].first>ff || (mini[i][g[x][j].first].first==ff && mini[i][g[x][j].first].second<ss)){
                mini[i][g[x][j].first].first=ff;
                mini[i][g[x][j].first].second=ss;
            }
        }
    }
    ll mf=inf;
    ll ms=0;
    ll mj=0;
    for(ll j=1;j<=n;j++){
        if(bo[i][j]==false){
            if(mf>mini[i][j].first || (mf==mini[i][j].first && ms<mini[i][j].second)){
                mf=mini[i][j].first;
                ms=mini[i][j].second;
                mj=j;
            }
        }
    }
    if(mj!=0){
        cc++;
        bo[i][mj]=true;
        if(cc<n){
            ki(i,mj);
        }
    }
    
}

int main(){
    cin>>n>>m>>l;
    ll a[m],b[m],c[m];
    
    for(ll i=0;i<m;i++){
        cin>>a[i]>>b[i]>>c[i];
        if(c[i]<=l){
            g[a[i]].push_back(make_pair(b[i],c[i]));
            g[b[i]].push_back(make_pair(a[i],c[i]));
        }
    }
    ll q;cin>>q;
    ll s[q],t[q];
    
    for(ll i=1;i<=n;i++){
        for(ll j=1;j<=n;j++){
            mini[i][j]=make_pair(inf,0);
        }
        mini[i][i]=make_pair(0,l);
        bo[i][i]=true;
        cc=1;
        ki(i,i);
    }
    for(ll i=0;i<q;i++){
        cin>>s[i]>>t[i];
    }
    for(ll i=0;i<q;i++){
        if(mini[s[i]][t[i]].first!=inf){
            cout<<mini[s[i]][t[i]].first<<endl;
        }else{
            cout<<-1<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 7424
import sys
num_bill, y = map(int, input().split())
bills = [1000, 5000, 10000]

num_1000, num_5000, num_10000 = 0, 0, 0

for num_10000 in range(y // 10000 + 1):
    if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
        print(num_10000, num_5000, num_1000)
        sys.exit()
        
    iter_num = min(((y - num_10000 * 10000) // 5000 + 1), (num_bill - num_10000 + 1))
    for num_5000 in range(iter_num):
        if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
            print(num_10000, num_5000, num_1000)
            sys.exit()
        
        num_1000 = num_bill - num_10000 - num_5000
        if (num_1000 * 1000 + num_5000 * 5000 + num_10000 * 10000 == y) & (num_10000 + num_5000 + num_1000 == num_bill):
            print(num_10000, num_5000, num_1000)
            sys.exit()

print('-1 -1 -1')

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

int main(){
  int A[200], B[200];
  int N;
  int sum=0;
  cin >> N;
  for(int i=0; i<N-1; i++){
    cin >> B[i];}
  A[0]=B[0];
  for(int i=1; i<N-1; i++){
    A[i]=min(B[i-1], B[i]);}
  A[N-1]=B[N-2];
   for(int i=0; i<N; i++){
     sum += A[i];}
  cout << sum << endl;
  
    
 }
  

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 MAX_C 1000000001
#define MOD 1000000007

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<ll> a(n), b(n), c(n);
  for (int i = 0; i < n; i++) { cin >> a[i]; }
  for (int i = 0; i < n; i++) { cin >> b[i]; }
  for (int i = 0; i < n; i++) { cin >> c[i]; }

  sort(a.begin(), a.end());
  sort(c.begin(), c.end());

  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    ll bi = b[i];
    ll p = lower_bound(a.begin(), a.end(), bi) - a.begin();
    ll q = c.end() - upper_bound(c.begin(), c.end(), bi);
    cnt += p * q;
  }

  cout << cnt << endl;
}


Measured memory_bytes: 2560
import sys
input = sys.stdin.readline


n = int(input())
routes = []
dic = [{}] * n
edges = [[]for _ in range(n)]
used = [0]*n

for i in range(n-1):
    a, b = map(int, input().split())
    routes.append([a-1, b-1])
    edges[a-1].append(b-1)

for node in range(n):
    unanle = used[node]
    count = 1
    if count == unanle:
        count += 1
    for to in edges[node]:
        dic[node][to] = count
        used[to] = count
        count += 1
        if count == unanle:
            count += 1

print(max(used))
for _from, to in routes:
    print(dic[_from][to])


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

int main()
{
   int k,s,z;
   cin >> k >> s;
   int count = 0;
   for(int i = 0; i<= k;i++){
      for(int j = 0;j<=k;j++){
         z = s-i-j;
         if(z <= k && z >=0)count++;         
      }
   }
   cout << count << endl;

   return 0;
}


Measured memory_bytes: 3608
<?php

$N = trim(fgets(STDIN));

$ans = 0;
$r = 0;
for($i = 1;$i <= $N;$i++){
fscanf(STDIN,"%d",$a);
if($r == 1){
$a -= 1;
$r = 0;
if($a >= 0){
$ans += 1;
}
}
if($a > 0){
$ans += floor($a / 2);
$r = $a % 2;
}
}

echo $ans;

Measured memory_bytes: 3704
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        for(int i = 0; i < n; i++){
            int a = scan.nextInt();
            int b = scan.nextInt();
            if(a > b){
                int temp = a;
                a = b;
                b = temp;
            }
            int c = scan.nextInt();
            if(b > c){
                int temp = c;
                c = b;
                b = temp;
            }
            if(a * a + b * b == c * c){
                System.out.println("YES");
            } else {
                System.out.println("NO");
            }
        }
    }
}



Measured memory_bytes: 33428
#!/usr/bin/env python

import sys

def search(s):
    prev=""
    n=1
    j=-1
    for i,c in enumerate(s):
        if prev==c:
            if j<0: j=i-1
            n+=1
        else:
            if n>1: break
        prev=c
    #
    return j,n

s= sys.stdin.readline().strip()
n= len(s)

i= 0
c= 0
while i<n:
    j,m= search(s[i:])
    if j<0:
        c+= n-i
        break
    #
    mod= m%3
    if mod==0: c+= ( m//3 ) * 2
    elif mod==1: c+= ( (m-1)//3  ) * 2 + 1
    else: c+= ( (m+1)//3 ) * 2
    c+= j
    i+= (j+m)
    if i==n:
        if mod==2: c-=1
    else:
        if mod==2: i+=1
print( c )


Measured memory_bytes: 3500
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int c = s.nextInt();

		int men = ((a+b)*c)/2;

		System.out.println(men);

	}

}

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, k;
	cin >> n >> k;
	string s;
	cin >> s;
	int a = 0;
	for (int i = 0; i < n - 1; i++)
		if (s[i] == s[i + 1])
			a ++;
	cout << min(n - 1, a + 2 * k);
}


Measured memory_bytes: 512
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <queue>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int INF = 1e8;

void compress(VI& xs, map<int,int>& comp, VI& decomp){
  int MX = 0;
  REP(i,SZ(xs))
	if(!comp.count(xs[i])){
	  comp[xs[i]] = MX++;
	  decomp[MX-1] = xs[i];
	}
}

void dfs(int x, int y, vector<vector<LL>>& reg, int W, int H, LL fr){
  if(x < 0 || y < 0 || W <= x || H <= y || reg[y][x] != fr) return;
  reg[y][x] = -1;
  dfs(x+1,y,reg,W,H,fr);
  dfs(x,y+1,reg,W,H,fr);
  dfs(x-1,y,reg,W,H,fr);
  dfs(x,y-1,reg,W,H,fr);
}


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

  int N;
  while(cin>>N,N){
	vector<PII> lt(N), rb(N);
	VI xs, ys;
	REP(i,N){
	  cin >> lt[i].first >> rb[i].second >> rb[i].first >> lt[i].second;
	  xs.PB(lt[i].first); xs.PB(rb[i].first);
	  ys.PB(lt[i].second); ys.PB(rb[i].second);
	}
	xs.PB(-1); xs.PB(INF);
	ys.PB(-1); ys.PB(INF);
	SORT(xs); xs.erase(unique(ALL(xs)), xs.end());
	SORT(ys); ys.erase(unique(ALL(ys)), ys.end());

	map<int,int> compX, compY;
	VI decompX(SZ(xs)), decompY(SZ(ys));
	compress(xs, compX, decompX);
	compress(ys, compY, decompY);

	REP(i,N){
	  lt[i].first = compX[lt[i].first];
	  rb[i].first = compX[rb[i].first];
	  lt[i].second = compY[lt[i].second];
	  rb[i].second = compY[rb[i].second];
	}

	int H = SZ(ys), W = SZ(xs);
	vector<vector<LL>> reg(H, vector<LL>(W, 0));
	REP(y,H) REP(x,W){
	  REP(i,N){
		if(lt[i].first <= x && x < rb[i].first
		   && lt[i].second <= y && y < rb[i].second)
		  reg[y][x] |= 1LL<<i;
	  }
	}

	int ans = 0;
	REP(y,H) REP(x,W){
	  if(reg[y][x] >= 0){
		dfs(x,y,reg,W,H,reg[y][x]);
		++ans;
	  }
	}
	cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 2116
/* kadai4_1
   Saikyo_Kazune
*/
#include <stdio.h>


int main(void){
   //int型　apple_tree_num,monitor_range,monitor_num宣言
   int apple_tree_num,monitor_range,monitor_num;
   //標準入力から受け取り
   scanf("%d %d",&apple_tree_num,&monitor_range);
   //重ならないように配置していけばよい
   //ただし、リンゴの木の数が監視員の監視範囲の整数倍の場合は+1しなくてよいので場合分け
   if(apple_tree_num%(2*monitor_range +1)==0) printf("%d\n",apple_tree_num/(2*monitor_range +1) );
   else printf("%d\n",apple_tree_num/(2*monitor_range +1) +1);
   return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n';

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	string f, s;
	cin >> f >> s;
	int r = 1e9;
	for (int i = 0; i < (int)f.size() - (int)s.size() + 1; i++) {
		int k = 0;
		for (int j = 0; j < (int)s.size(); j++)
			if (f[i + j] != s[j]) k++;
		r = min(r, k);
	}
	cout << r << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
  int abc[3];
  
  for (int i = 0; i < 3; i++)
    cin >> abc[i];
  
  sort(abc, abc + 3);
  
  cout << abc[2] * 10 + abc[1] + abc[0] << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
  int N;
  cin >> N;
  int a[200];
  for(int i = 0;i < N;++i) cin >> a[i];
  
  int res = 0;
  while(true){
   bool f = true;
    for(int i = 0;i < N;++i){
      if(a[i]%2 != 0) f = false;
    }
    if(!f) break;
    for(int i = 0;i < N;++i) a[i]/=2;
    ++res;
  }
  
  cout << res << endl;
}

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

using namespace std;

string s;

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

    cin>>s;
    int n=s.size();
    int tekt=0,prett=0;
    int tek1=1, pret1=1;
    for(int i=0;i<n;i++)
    {
        pret1=tek1;
        prett=tekt;
        tekt=min(prett+(s[i]-'0'), pret1+10-(s[i]-'0'));
        if(s[i]=='9')
            tek1=pret1;
        else
            tek1=min(prett+(s[i]-'0')+1,pret1+10-(s[i]-'0')-1);
    }
    cout<<tekt;

	return 0;
}


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

using weight = int;
using P = std::pair<int, int>;

constexpr int INF = 1e9;

struct edge {
    int to, cap;
    weight cost;
    int rev;
};

using edges = std::vector<edge>;
using graph = std::vector<edges>;

void add_edge(graph& g, int from, int to, int cap, weight cost) {
    g[from].push_back(edge{to, cap, cost, (int)g[to].size()});
    g[to].push_back(edge{from, 0, -cost, (int)g[from].size()-1});
}

// verified
weight min_cost_flow(graph& g, int s, int t, weight f) {
    weight res = 0;
    std::vector<weight> h(g.size(), 0);
    std::vector<weight> dist(g.size());
    std::vector<int> prevv(g.size()), preve(g.size());
    std::fill(h.begin(), h.end(), 0);
    while(f > 0) {
        std::priority_queue<P, std::vector<P>, std::greater<P>> que;
        std::fill(dist.begin(), dist.end(), INF);
        dist[s] = 0;
        que.push(P{0, s});
        while(!que.empty()) {
            P p = que.top(); que.pop();
            int v = p.second;
            if(dist[v] < p.first) {
                continue;
            }
            for(int i=0; i<g[v].size(); ++i) {
                edge& e = g[v][i];
                if(e.cap > 0 && dist[e.to] > dist[v] + e.cost + h[v] - h[e.to]) {
                    dist[e.to] = dist[v] + e.cost + h[v] - h[e.to];
                    prevv[e.to] = v;
                    preve[e.to] = i;
                    que.push(P{dist[e.to], e.to});
                }
            }
        }
        if(dist[t] == INF) {
            return -1;
        }
        for(int v=0; v<g.size(); ++v) {
            h[v] += dist[v];
        }

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

int main() {
    int N;
    while(cin >> N, N) {
        int sum = 0;
        vector<vector<int>> v(N, vector<int>(3));
        for(int i = 0; i < N; ++i) {
            cin >> v[i][0] >> v[i][1] >> v[i][2];
            sort(begin(v[i]), end(v[i]));
            sum += v[i][0] * v[i][1] * v[i][2];
        }
        graph g(2 * N + 3);
        const int source = 2 * N;
        const int dummy = source + 1;
        const int dest = dummy + 1;
        for(int i = 0; i < N; ++i) {
            for(int j = 0; j < N; ++j) {
                if(i == j) {
                    continue;
                }
                if(v[i][0] < v[j][0] && v[i][1] < v[j][1] && v[i][2] < v[j][2]) {
                    add_edge(g, j, i + N, 1, -v[i][0] * v[i][1] * v[i][2]);
                }
            }
            add_edge(g, source, i, 1, 0);
            add_edge(g, i + N, dest, 1, 0);
        }
        add_edge(g, source, dummy, INF, 0);
        add_edge(g, dummy, dest, INF, 0);

        cout << sum + min_cost_flow(g, source, dest, N) << endl;
    }
}


Measured memory_bytes: 3192
#include<cstdio>
int a[]={0,0,1,2,2,3,3,4,3,4,4,5,4,5,5,5,4,5,5,6,5,6,6,6,5,6,6,6,6,7,6,6,5,6,6,7,6,7,7,7,6,7,7,7,7,7,7,7,6,7,7,7,7,8,7,8,7,8,8,8,7,8,7,7,6,7,7,8,7,8,8,8,7,8,8,8,8,8,8,8,7,8,8,8,8,8,8,9,8,9,8,9,8,8,8,8,7,8,8,8,8,9,8,9,8,9,9,9,8,9,9,9,8,9,9,9,9,9,9,9,8,9,9,9,8,9,8,8,7,8,8,9,8,9,9,9,8,9,9,9,9,9,9,9,8,9,9,9,9,9,9,10,9,9,9,9,9,9,9,9,8,9,9,9,9,9,9,10,9,10,9,10,9,10,10,10,9,10,10,10,9,10,10,10,9,10,9,10,9,9,9,9,8,9,9,9,9,10,9,10,9,10,10,10,9,10,10,10,9,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,10,9,10,10,10,9,10,9,9,8,9,9,10,9,10,10,10,9,10,10,11,10,11,10,10,9,10,10,11,10,11,10,10,10,10,10,10,10,10,10,10,9,10,10,10,10,10,10,11,10,10,10,11,10,11,11,11,10,11,10,11,10,11,10,11,10,11,10,10,10,10,10,10,9,10,10,10,10,10,10,11,10,11,10,11,10,11,11,11,10,11,11,11,10,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,10,11,11,11,10,11,10,11,10,10,10,10,9,10,10,10,10,11,10,11,10,11,11,11,10,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,12,11,11,11,12,11,12,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,11,12,11,12,11,11,10,11,11,12,11,12,11,11,10,11,11,11,10,11,10,10,9,10,10,11,10,11,11,11,10,11,11,12,11,12,11,11,10,11,11,12,11,12,12,11,11,12,12,12,11,12,11,11,10,11,11,12,11,12,12,12,11,11,12,12,11,12,11,12,11,11,11,12,11,12,11,11,11,12,11,11,11,11,11,11,10,11,11,11,11,11,11,12,11,11,11,12,11,12,12,12,11,12,11,12,11,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,11,12,11,12,11,11,11,11,11,11,10,11,11,11,11,11,11,12,11,12,11,12,11,12,12,12,11,12,12,12,11,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,11,12,12,12,11,12,11,12,11,11,11,11,10,11,11,11,11,12,11,12,11,12,12,12,11,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,13,12,12,12,12,11,12,12,12,12,13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,13,12,12,12,13,12,13,12,12,12,13,12,12,12,12,12,12,11,12,12,12,12,12,12,13,12,12,12,13,12,13,12,12,12,13,12,13,12,13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,13,12,13,12,13,12,13,12,13,12,13,12,13,12,13,13,13,12,13,13,13,12,13,12,13,12,13,13,13,12,13,13,13,12,13,12,13,12,12,12,13,12,13,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,12,13,12,13,12,12,12,12,12,13,12,13,13,13,12,13,13,13,12,13,12,12,11,12,12,13,12,13,13,13,12};
int main()
{
     int r;
     while(scanf("%d",&r),r) printf("%d\n",a[r]);
     return 0;
}

Measured memory_bytes: 1032
from math import sqrt, ceil, log2
n, p = map(int, input().split())
if n == 1:
    print(p)
elif n >= 40:
    print(1)
else:
    ret = 1
    for i in range(2, ceil(sqrt(p)) + 1):
        if p % (i ** n) == 0:
            ret = i
    print(ret)


Measured memory_bytes: 3064
#include <stdio.h>

int main(){
	int n;
	int house[4][3][10] = {0};
	int b,f,r,v;
	int i,j,k;


	scanf("%d",&n);
	for(i=0; i<n; i++){
		scanf("%d %d %d %d", &b,&f,&r,&v);
		house[b-1][f-1][r-1] += v;
	}
	for(i=0; i<4; i++){
		for(j=0; j<3; j++){
			for(k=0; k<10; k++){
				printf(" %d",house[i][j][k]);
			}
			printf("\n");
		}
		if(i!=3)
		printf("####################\n");
	}

	return 0;
}

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

void disp_array(int *array, int size)
{
		int i;

		for(i = 0; i < size - 1; i++)
				printf("%d ", array[i]);
		printf("%d", array[i]);
}

void sort(int *array, int size) 
{
		int i, j;

		for(i = 1; i < size; i++) {
				int target_value;
				target_value = array[i];
				j = i - 1;
				while(j >= 0 && array[j] > target_value) {
						array[j + 1] = array[j];
						j--;
				}
				array[j + 1] = target_value;
				disp_array(array, size);
				printf("\n");
		}

}

int main(void) {
		int *array, array_size = 0;
		int i;

		scanf("%d", &array_size);
		array = malloc(sizeof(int) * array_size);
		for(i = 0; i < array_size; i++)
				scanf("%d", &array[i]);
		disp_array(array, array_size);
		printf("\n");
		sort(array, array_size);

		return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>
#include <typeinfo>

using namespace std;

int main()
{
    long long n;
    cin >> n;
    bool flag = true;

    if (n < 10) {
        cout << n << endl;
    } else {
        string n_str = to_string(n);

        for (int i = 1; i < n_str.size(); ++i) {
            if (n_str[i] != '9') {
                flag = false;
            }
        }
        if (flag) {
            cout << (n_str.size() - 1) * 9 + int(n_str[0] - '0') << endl;
        } else {
            int term1 = (n_str.size() - 1) * 9;
            int term2 = int(n_str[0] - '0') - 1;
            cout << term1 + term2 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

func main() {
	sc := NewScanner(os.Stdin)
	N := sc.NextInt()
	A := sc.NextInt()
	B := sc.NextInt()
	if A*N > B {
		fmt.Println(B)
	} else {
		fmt.Println(A * N)
	}
}

func lcm(x, y int) int {
	x, y = max(x, y), min(x, y)
	if y == 0 {
		return x
	}
	return lcm(y, x%y)
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

// scanner
type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner(r io.Reader) *Scanner {
	rdr := bufio.NewReaderSize(r, 1024)
	return &Scanner{r: rdr}
}

func (s *Scanner) ReadLine() {
	s.buf = make([]byte, 0)
	for {
		line, isp, err := s.r.ReadLine()
		if err != nil {
			os.Exit(1)
		}
		s.buf = append(s.buf, line...)
		if !isp {
			break
		}
	}
}

func (s *Scanner) NextInt() int {
	i, err := strconv.Atoi(s.Next())
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) NextFloat64() float64 {
	i, err := strconv.ParseFloat(s.Next(), 64)
	if err != nil {
		os.Exit(1)
	}
	return i
}

func (s *Scanner) Next() string {
	s.Pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	next := string(s.buf[start:s.p])
	s.p++
	return next
}

func (s *Scanner) Pre() {
	if s.p >= len(s.buf) {
		s.ReadLine()
		s.p = 0
	}
}


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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort(ALL(x))

const int IINF = 1e9 + 10;
const lint LLINF = (lint)1e18 + 10;
const lint MOD = (lint)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};

int main(){
    const int shichigosan[] = {3, 5, 7};
    vector<int> v;
    REP(i, 1, 8){
        REP(j, 1, 9 - i){
            REP(k, 1, 10 - i - j){
                vector<int> tmp;
                int cnt = 0;
                while(cnt < i){
                    tmp.push_back(shichigosan[0]);
                    ++cnt;
                }
                cnt = 0;
                while(cnt < j){
                    tmp.push_back(shichigosan[1]);
                    ++cnt;
                }
                cnt = 0;
                while(cnt < k){
                    tmp.push_back(shichigosan[2]);
                    ++cnt;
                }
                do{
                    int now = 0;
                    rep(l, tmp.size()){
                        now *= 10;
                        now += tmp[l];
                    }
                    v.push_back(now);
                }while(next_permutation(ALL(tmp)));
            }
        }
    }
    SORT(v);
    int n;
    cin >> n;
    int ans = upper_bound(ALL(v), n) - v.begin();
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
/*I MAY NOT GET THE SUCCESS IMMEDIATELY BUT I WILL GET IT FOR SURE*/
#include<bits/stdc++.h>
#define opt std::ios_base::sync_with_stdio(false)
#define I int
#define li      int32_t
#define lli     long long
#define ulli unsigned long long
 
#define pn          printf("\n")
#define nl          cout<<'\n'
#define sf(N)       scanf("%lld",&N)
#define pf(N)       printf("%lld",N)
#define sl          cout<<' '
#define ps          printf(" ")
 
#define rep(i,a,b)  for(i=a;i<b;i++)
#define repr(i,a,b) for(i=a;i>b;i--)
#define elif        else if
#define mset(a,b)   memset(a,b,sizeof(a))
 
#define pb      push_back
#define pob     pop_back
#define itr     iterator
#define sz()    size()
#define szof    sizeof
#define lb      lower_bound
#define ub      upper_bound
#define mp      make_pair
#define vlli    vector<lli>
#define plli    pair<lli,lli>
#define vplli   vector<plli >
#define F       first
#define S       second
#define Dup erase(unique(V.begin(),V.end()),V.end())
 
#define TC int test; cin>>test; test++; while(--test)
 
#define Inf     1000000000000000
#define mod     1000000007
#define M1      1000000007
#define M2      1000000009
using namespace std;

char ch[105][105];

lli Power(lli a,lli b)
{
    lli result=1;
 
    while(b)
    {
        if(b%2)
        {
            result=(result*a)%mod;
        }
 
        b=b>>1;
        a=(a*a)%mod;
    }
 
 return result;
}
 
int main()
{
    opt;
 
    /*#ifndef ONLINE_JUDGE
    freopen("double_squares.txt","r",stdin);
    freopen("double_squares_out.txt","w",stdout);
    #endif // ONLINE_JUDGE*/
    
    memset(ch,'#',szof(ch));
    
    lli N,M,i,j;
    cin>>N>>M;
    
    rep(i,1,N+1)
    {
        rep(j,1,M+1)
        {
            cin>>ch[i][j];
        }
    }
    
    rep(i,0,N+2)
    {
        rep(j,0,M+2)
        {
            cout<<ch[i][j];
        }
        nl;
    }
 
 
 
 return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
int a,b;
char op;

for(int i=0;i<20000;i++){
    
   cin >> a >> op >> b;
   
    if(op=='?'){
        break;
    }
    else if(op=='+'){
        cout<<a+b<<endl;
    }
   else if(op=='-'){
        cout<<a-b<<endl;
    }
    else if(op=='*'){
        cout<<a*b<<endl;
    }
   else if(op=='/'){
        cout<<a/b<<endl;
    }
    
    }
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define im imag()
#define re real()
#define r(I, N) for(int I=0;I<N;I++)
#define f(I, A, B) for(int I=A;I<B;I++)
#define fd(I, A, B) for(int I=A;I>=B;I--)
#define ite(x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define sz(x) ((int)(x).size())
#define clr(x) memset(x, 0, sizeof(x))

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef complex<ld> Point;
typedef Point Vector;

const ld pi = acos(-1.0);
const ld eps = 1e-12;

int n, m;
int pos1[1234], pos2[1234];
int f[567], t[567];

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

      r(i, m)
      {
            int a, b;
            cin >> a >> b;
            pos1[a]++, pos2[b]++;
            f[i] = a, t[i] = b;
      }

      int ans = 0, cnt = 0;
      int mn = -1;

      f(i, 1, n + 1)
      {
            if(pos2[i])
            {
                  cnt-=pos2[i];
                  if(cnt == 0)
                  {
                        ans += 2 * (i - mn);
                        mn = -1;
                  }
            }
            if(pos1[i])
            {
                  cnt+=pos1[i];
                  if(mn == -1) mn = i;
            }
            ans++;
      }
      cout << ans + 1 << endl;
      return 0;
}

Measured memory_bytes: 1176
import sys
I = lambda:int(sys.stdin.readline())
LI = lambda:[int(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]

N,A,B = LI()
H = IR(N)

def isOK(c):
    cnt = 0
    for enc in H:
        if enc - B*c > 0:
            cnt += ((enc - B*c)+(A-B)-1)//(A-B)
            if cnt > c:
                return False
    return True

OK = (max(H)+B-1)//B
NG = 0

while(OK-NG>1):
    mid = (OK+NG)//2
    if isOK(mid):
        OK = mid
    else:
        NG = mid

print(OK)




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

int main() {
#ifdef LOCAL_DEFINE
  //freopen("data.in", "rt", stdin);
  //freopen("data.out", "w", stdout);
  auto _start = chrono::high_resolution_clock::now();
#endif
	
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cout << fixed << setprecision(15);
	string s;
	cin >> s;
	int n = s.length();
	bool ok = s[0] == '1' && s[n - 1] == '0';
	for(int i = 0; i <= n - 2; i++) {
		ok &= s[i] == s[n - 2 - i];
	}
	if(!ok) {
		cout << "-1\n";
	} else {
		vector<int> body;
		for(int i = 0; i < n; i++) {
			if(s[i] == '1') {
				body.push_back(i);
			}
		}
		int k = body.size();
		for(int i = 1; i <= k; i++) {
			cout << i << ' ' << i + 1 << '\n';
		}
		for(int i = 1, x = k + 2; i < k; i++) {
			for(int j = 0; j < body[i] - body[i - 1] - 1; j++) {
				cout << i + 1 << ' ' << x++ << '\n';
			}
		}
	}

#ifdef LOCAL_DEFINE
  auto _end = chrono::high_resolution_clock::now();
  cerr << "elapsed time: " << chrono::duration<double, milli>(_end - _start).count() << " ms\n";
#endif
	return 0;
}

Measured memory_bytes: 1992
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,K;cin>>N>>K;
    int ans=1;
    if(N==K){
        cout<<ans<<endl;
        return 0;
    }
    ans+=(N-K)/(K-1);
    if((N-K)%(K-1)>=1){
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3628
a, b, c, d = map(int, input().split())
if a * c < a * d:
  temp1 = a * d
else:
  temp1 = a * c
if b * c < b * d:
  temp2 = b * d
else:
  temp2 = b * c
if temp1 < temp2:
  print(temp2)
else:
  print(temp1)

Measured memory_bytes: 9172