akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    static int N;
    static int M;
    static ArrayList<ArrayList<Integer>> edge;
    static int[] ans;

    static int path(int i) {
        if (ans[i]!=-1) return ans[i];
        int tmp = 0;
        for (Integer j : edge.get(i)) {
            tmp = Math.max(tmp, path(j)+1);
        }
        ans[i] = tmp;
        return tmp;
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        N = Integer.parseInt(sc.next());
        M = Integer.parseInt(sc.next());
        edge = new ArrayList<ArrayList<Integer>>();
        for (int i=0;i<N;i++) {
            ArrayList<Integer> add = new ArrayList<Integer>();
            edge.add(add);
        }
        for (int i=0;i<M;i++) {
            int x = Integer.parseInt(sc.next())-1;
            int y = Integer.parseInt(sc.next())-1;
            edge.get(x).add(y);
        }

        ans = new int[N];
        Arrays.fill(ans, -1);
        int max = 0;
        for (int i=0;i<N;i++) {
            max = Math.max(max, path(i));
        }
        System.out.println(max);
    }
}

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


using namespace std;

int main(){
	string s1,s2,s3;
	cin>>s1>>s2>>s3;

	cout<<s1.substr(0,1)<<s2.substr(0,1)<<s3.substr(0,1)<<"\n";
	
	return 0;
}


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

using namespace std;
typedef long long LL;


int main()
{
        LL a,b;
        cin >> a >>b;
        LL x = 2*b;
        if(x >= a)
        {
                cout << 0 << endl;
        }
        else cout << a-x << endl;
        return 0;
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
using Graph = vector<vector<int>>;
const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

vector<int> dp(1e5 + 100, 0);
Graph G(1e5 + 100);

int rec(int v)
{
    if (dp[v] != 0)
        return dp[v];
    int ret = 0;
    for (int i = 0; i < G[v].size(); i++) {
        int pv = G[v][i];
        ret = max(ret, rec(pv) + 1);
    }

    return dp[v] = ret;
}
int main()
{
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int x, y;
        cin >> x >> y;
        x--, y--;
        G[y].push_back(x);
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, rec(i));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 13436
#define MYDEBUG
//
#include <bits/stdc++.h>
#ifdef MYDEBUG
#define dbp(x) cout<<#x<<": "<<x<<endl
#define dbp2(x,y) cout<<#x<<","<<#y<<": "<<x<<","<<y<<endl
#define dbp3(x,y,z) cout<<#x<<","<<#y<<","<<#z<<": "<<x<<","<<y<<","<<z<<endl
#define dbp4(w,x,y,z) cout<<#w<<","<<#x<<","<<#y<<","<<#z<<": "<<w<<","<<x<<","<<y<<","<<z<<endl
#define ifcin(x) std::ifstream cin(x)
#else
#define dbp(x)
#define dbp2(x,y)
#define dbp3(x,y,z)
#define dbp4(w,x,y,z)
#define ifcin(x)
#endif
#define ll long long
#define all(x) x.begin(), x.end()
#define rep(i, from, to) for(int i=from; i<to; ++i)
#define REP(i, from, to) for(int i=from; i<=to; ++i)
using namespace std;
template<typename T>
ostream& operator<<(ostream& out, const vector<T>& v) {
  out << "[";
  size_t last = v.size() - 1;
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i];
    if (i != last) {
      out << ",";
    }
  }
  out << "]";
  return out;
}
template<typename T>
ostream& operator<<(ostream& out, const vector<vector<T> >& v) {
  for (size_t i = 0; i < v.size(); ++i) {
    out << v[i] << endl;
  }
  return out;
}
template<typename T1, typename T2>
ostream& operator<<(ostream& out, const pair<T1, T2>& p) {
  out << "{" << p.first << "," << p.second << "}";
  return out;
}

static const int NMAX = 2000000;
static const int VMAX = 10000;
int n, A[NMAX], B[NMAX], C[VMAX];

void countingSort(int a[], int b[], int n, int k) {
  REP(i,0,k)
  {
    C[i] = 0;
  }
  rep(i,0,n)
  {
    C[A[i]]++;
  }
  REP(i,1,k)
  {
    C[i] += C[i - 1];
  }
  for (int i = n - 1; i >= 0; --i) {
    b[C[a[i]]-- - 1] = a[i];
  }
}

int main() {
  scanf("%d", &n);
  int mx = 0;
  rep(i,0,n)
  {
    scanf("%d", &A[i]);
    mx = max(mx, A[i]);
  }
  countingSort(A, B, n, mx);
  rep(i,0,n)
  {
    if (i > 0) {
      printf(" ");
    }
    printf("%d", B[i]);
  }
  printf("\n");
  return 0;
}



Measured memory_bytes: 18860
#include <stdio.h>
int main()
{
    int mat1[101][101];

    int mat2[101][101];

    double mat3[101][101];

    int na,mb,lc;

    int f,g,h;

    scanf("%d %d %d", &na, &mb, &lc);
    for(f=0; f<na; f++)
    {
        for(g=0; g<mb; g++){
            scanf("%d", &mat1[f][g]);
        }
    }
    for(f=0; f<mb; f++)
    {

        for(g=0; g<lc; g++){
            scanf("%d", &mat2[f][g]);
        }
    }
    for(f=0; f<na; f++)
    {
        for(g=0; g<lc; g++)
        {
            for(h=0; h<mb; h++)
            {
                mat3[f][g] += mat1[f][h] * mat2[h][g];
            }
        }
    }
    for(f=0; f<na; f++)
    {
        for(g=0; g<lc; g++)
        {
            if(g != lc-1) printf("%.0lf ", mat3[f][g]);
            else printf("%.0lf", mat3[f][g]);
        }
        printf("\n");
    }
    return 0;

}




Measured memory_bytes: 2076
#pragma target("avx")
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef unordered_map<ll, ll> U_MAP;
typedef priority_queue<ll> pq;
typedef priority_queue<ll, vector<ll>, greater<ll>> rpq;
const int INF = 1e9, MOD = 1e9 + 7, ohara = 1e6 + 10;
const ll LINF = 1e18;

#define rep(i, n) for (ll(i) = 0; (i) < (int)(n); (i)++)
#define rrep(i, a, b) for (ll i = (a); i < (b); i++)
#define rrrep(i, a, b) for (ll i = (a); i >= (b); i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout << (x) << endl
#define doublecout(a) cout << fixed << setprecision(15) << a << endl;
#define fi first
#define se second
#define m_p make_pair
#define p_b push_back
string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string)s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto& x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

//------ Believe yourself as a genius!!!!!! ------

int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
// int dy[]={-1,0,1,-1,1,-1,0,1};int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"), s;
ll n, cnt, ans, a[ohara], b, c, d, tmp, m, h, w, x, y, sum[ohara], k, q;
ld dat[ohara];

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

  cin >> n >> k;
  sum[1] = 1;
  rrep(i, 2, 1000 + 10) { sum[i] += sum[i - 1] + i; }
  rep(i, n) {
    cin >> a[i];
    ld score;
    score = (ld)sum[a[i]] / (ld)a[i];
    dat[i] = score;
  }
  rrep(i, 1, n) { dat[i] += dat[i - 1]; }
  ld tans = -1000000000000000000.0;
  rrep(i, k - 1, n) {
    ld cou;
    cou = dat[i];
    if (i - k >= 0) cou -= dat[i - k];
    tans = max(tans, cou);
  }
  doublecout(tans);
  return 0;
}

Measured memory_bytes: 10496
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine().Trim());
            Dictionary<int, int> dict = new Dictionary<int, int>();
            foreach (int input in Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)))
            {                
                if (dict.ContainsKey(input))
                {
                    dict[input]++;
                }
                else
                {
                    dict.Add(input, 1);
                }
            }

            int m = int.Parse(Console.ReadLine().Trim());

            foreach (int input in Console.ReadLine().Trim().Split(' ').Select(x => int.Parse(x)))
            {
                if (dict.ContainsKey(input))
                {
                    if (dict[input] > 0)
                    {
                        dict[input]--;
                    }
                    else
                    {
                        Console.WriteLine("NO");
#if DEBUG
                        Console.ReadKey();
#endif
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("NO");
#if DEBUG
                    Console.ReadKey();
#endif
                    return;
                }
            }

            Console.WriteLine("YES");
#if DEBUG
            Console.ReadKey();
#endif
        }
    }
}


Measured memory_bytes: 49088
#include <algorithm>  // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>     // bitset
#include <cctype>     // isupper, islower, isdigit, toupper, tolower
#include <cstdint>    // int64_t, int*_t
#include <cstdio>     // printf
#include <deque>      // deque
#include <iomanip>    // fixed, setprecision
#include <iostream>   // cout, endl, cin
#include <map>        // map
#include <numeric>    // accumulate
#include <queue>      // queue, priority_queue
#include <set>        // set
#include <stack>      // stack
#include <string>     // string, to_string, stoi
#include <tuple>      // tuple, make_tuple
#include <unordered_map>  // unordered_map
#include <unordered_set>  // unordered_set
#include <utility>        // pair, make_pair
#include <vector>         // vector
using namespace std;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  string abcd;
  cin >> abcd;
  int a, b, c, d;
  a = stoi(abcd.substr(0, 1));
  b = stoi(abcd.substr(1, 1));
  c = stoi(abcd.substr(2, 1));
  d = stoi(abcd.substr(3, 1));

  int op[2] = {1, -1};

  for (auto op1 : op) {
    for (auto op2 : op) {
      for (auto op3 : op) {
        if (a + op1 * b + op2 * c + op3 * d == 7) {
          cout << a << (op1 == 1 ? "+" : "-") << b << (op2 == 1 ? "+" : "-")
               << c << (op3 == 1 ? "+" : "-") << d << "=7" << endl;
          return 0;
        }
      }
    }
  }
}


Measured memory_bytes: 3152
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const int inf = 1 << 30;
const LL INF = 1LL << 60;

int n;

int main()
{
    while(scanf("%d", &n) != EOF)
    {
        LL MIN = INF;
        LL sum = 0;
        bool f = 1;
        for(int i = 1; i <= n; i++) {
            LL a, b;
            scanf("%lld %lld", &a, &b);
            sum += a;
            if(a != b) f = 0;
            if(a > b) MIN = min(MIN, b);
        }
        if(f == 1) printf("0\n");
        else printf("%lld\n", sum - MIN);
    }
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(){
  char s[100001];
  int i,cnt=0;
  char t[]="abcdefghijklmnopqrstuvwxyz";
  scanf("%s",s);
  for(i=0; i<=25; i++){
    if(strchr(s,t[i])==NULL){
      printf("%c\n",t[i]);
      break;
    }
    if(strchr(s,t[i])!=NULL){
      cnt++;
    }

  }
  if(cnt==26){
    printf("None\n");
  }
  return 0;
}


Measured memory_bytes: 256
N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

a, b = [0], [0]
for i in range(N):
    a.append(a[i] + A[i])
for i in range(M):
    b.append(b[i] + B[i])

ans, j = 0, M

for i in range(N + 1):
    if a[i] > K:
        break
    while b[j] > K - a[i]:
        j -= 1
    ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 47316
#include <ios>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <atcoder/all>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repR(i, n) for(int i = (n) - 1; i > -1; i--)
#define rep1(i, n) for(int i = 1; i < (int)(n + 1); i++)
#define rep1R(i, n) for(int i = (n); i > 0; i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using namespace atcoder;

using mint = modint998244353;

struct S {
  mint v;
  ll len;
};

S op(S a, S b) {
  return {a.v * mint(10).pow(b.len) + b.v, a.len + b.len};
}

S e() {
  return {0, 0};
}

using F = int;

mint inv_9 = mint(9).inv();

S mapping(F f, S x) {
  if (f != 0) {
    return {(mint(10).pow(x.len) - 1) * inv_9 * f, x.len};
  } else {
    return x;
  }
}

F composition(F f, F g) {
  if (f == 0) {
    return g;
  } else {
    return f;
  }
}

F id() {
  return 0;
}

int main() {
  int N, Q;
  cin >> N >> Q;
  vector<S> v(N);
  rep(i, N) {
    v[i] = S {1, 1};
  }
  lazy_segtree<S, op, e, F, mapping, composition, id> seg(v);
  rep(i, Q) {
    int L, R, D;
    scanf("%d %d %d", &L, &R, &D);
    L -= 1;
    seg.apply(L, R, D);
    printf("%d\n", seg.all_prod().v.val());
  }
  return 0;
}


Measured memory_bytes: 15196
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main(void)
{

    char S[3];
    scanf("%s", S);
    if (strcmp(S,"SUN")==0)
    {
        printf("7");
    }
    else if (strcmp(S,"MON")==0)
    {
        printf("6");
    }
    else if (strcmp(S,"TUE")==0)
    {
        printf("5");
    }
    else if (strcmp(S,"WED")==0)
    {
        printf("4");
    }
    else if (strcmp(S,"THU")==0)
    {
        printf("3");
    }
    else if (strcmp(S,"FRI")==0)
    {
        printf("2");
    }
    else if (strcmp(S,"SAT")==0)
    {
        printf("1");
    }
    return 0;
}

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

#define REP(i, a, b) for (int i = (a); i < (b); i++)

using namespace std;

int num[4] = {};

int decode(string &s, int &ind) {
  if (s[ind] == '[') {
    ind++;
    int t = decode(s, ind);
    ind++;
    return t;
  } else if (s[ind] == '+') {
    ind++;
    int a = decode(s, ind);
    int b = decode(s, ind);
    return a | b;
  } else if (s[ind] == '*') {
    ind++;
    int a = decode(s, ind);
    int b = decode(s, ind);
    return a & b;
  } else if (s[ind] == '^') {
    ind++;
    int a = decode(s, ind);
    int b = decode(s, ind);
    return a ^ b;
  } else if(s[ind] == ']') {
    ind++;
    return decode(s, ind);
  } else {
    int n = num[s[ind] - 'a'];
    ind++;
    return n;
  }
}

int main() {
  string S;
  while (cin >> S, S != ".") {
    string P;
    cin >> P;
    REP (i, 0, 4) {
      num[i] = P[i] - '0';
    }
    int dummy = 0;
    int hsh = decode(S, dummy);
    cout <<  hsh << " ";
    int ans = 0;
    REP (i, 0, 10000) {
      int n = i;
      for (int j = 3; j >= 0; j--) {
	num[j] = n % 10;
	n /= 10;
      }
      dummy = 0;
      if (hsh == decode(S, dummy)) {
	ans++;
      }
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3192
n=int(input())
l=list(map(int,input().split()))
l1=sorted(l)
m=l1[-1]
if l[0]!=0:
  print(0)
else:
  ld=[0 for i in range(m+1)]
  b=False
  for i in range(n):
    ld[l[i]]+=1
  for i in range(1+m):
    if ld[i]==0:
      b=True
  if ld[0]!=1:
    print(0)
  elif b:
    print(0)
  else:
    ans=1
    for i in range(1,m+1):
      num=ld[i-1]**ld[i]
      ans=(ans*num)%(998244353)
    print(ans%(998244353))

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

typedef long long ll;
const int maxn=8e3+10;
int x,y,dpx[maxn<<1],dpy[maxn<<1],tmp[maxn<<1];
char s[maxn];

int main(){
	cin>>s>>x>>y;
	int now=0,type=0;
	{
		int pos=0;
		while(s[now]=='F')
			++now,++pos;
		dpx[pos+maxn]=dpy[maxn]=true;
	}
	while(s[now]){
		++now;
		int len=0;
		while(s[now]=='F')
			++now,++len;
		memset(tmp,0,sizeof(tmp));
		if(type){
			for(int i=0;i+len<(maxn<<1);++i)
				if(dpx[i])
					tmp[i+len]=true;
			for(int i=len;i<(maxn<<1);++i)
				if(dpx[i])
					tmp[i-len]=true;
			memcpy(dpx,tmp,sizeof(dpx));
		}
		else{
			for(int i=0;i+len<(maxn<<1);++i)
				if(dpy[i])
					tmp[i+len]=true;
			for(int i=len;i<(maxn<<1);++i)
				if(dpy[i])
					tmp[i-len]=true;
			memcpy(dpy,tmp,sizeof(dpy));
		}
		type^=1;
	}
	puts(dpx[x+maxn]&&dpy[y+maxn]?"Yes":"No");
	return 0;
}

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

int main(){
  double A,B,C,D,E,F,maxN,yoshitsu,yobai;
  cin >>A>>B>>C>>D>>E>>F;
  maxN=0;
  yoshitsu=0;
  yobai=0;
  for(int m1=0;m1<(F/(A*100)+1);m1++){
    for(int m2=0;m2<(F/(B*100)+1);m2++){
      for(int m3=0;m3<(F/C+1);m3++){
        for(int m4=0;m4<(F/D+1);m4++){
          //cout<<m1<<m2<<m3<<m4<<endl;
          if(m1*A*100+m2*B*100+m3*C+m4*D==0) continue;
          if(m1*A*100+m2*B*100+m3*C+m4*D>F) continue;
          if((C*m3+D*m4)/(m1*A*100+m2*B*100+m3*C+m4*D)>E/(100+E)) continue;
          if((C*m3+D*m4)/(m1*A*100+m2*B*100+m3*C+m4*D)>maxN){
            maxN=(C*m3+D*m4)/(m1*A*100+m2*B*100+m3*C+m4*D);
            yoshitsu=C*m3+D*m4;
            yobai=m1*A*100+m2*B*100+C*m3+D*m4;
            //cout<<maxN<<" "<<yoshitsu<<" "<<yobai<<endl;
          }
        }
      }
    }
  }
  cout<<max(yobai,100*A)<<" "<<yoshitsu<<endl;
  return 0;
}

          
    

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

int main(){
	int i,k,u,p,c;
	string s;
	
	cin >> s;
	for(k=u=p=c=i=0 ; i < (int)s.size() ; i++ ){
		if( s[i] == 'K' ) k++;
		if( s[i] == 'U' ) u++;
		if( s[i] == 'P' ) p++;
		if( s[i] == 'C' ) c++;
	}
	cout << min( k , min( u , min(p,c) ) ) << endl;
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>


void trace(std::vector<int> v) {
	std::string s;
	for (std::vector<int>::iterator i = v.begin(); i != v.end(); ++i) {
		if (i != v.end() - 1)
			std::cout << *i << " ";
		else
			std::cout << *i;
	}
	std::cout << std::endl;
}

int main() {
	
	{
		using namespace std;
		int n;

		cin >> n;

		vector<int> a;
		a.resize(n, 0);
		for (int i = 0; i < n; i++)
			cin >> a[i];

		int c = 0;

		for (int i = 0; i < n; i++) {
			for (int j = n-1; j > i; j--) {
				if (a[j] < a[j - 1]) {
					int t = a[j];
					a[j] = a[j - 1];
					a[j - 1] = t;
					c++;
				}
			}
		}
		trace(a);
		cout << c << endl;

	}



	return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int r, d, x;
    scanf("%d%d%d", &r, &d, &x);
    rep(i, 10){
        x = r*x-d;
        printf("%d\n", x);
    }
}

Measured memory_bytes: 256
s = list(input())
s_len = len(s)
cnt_w = 0
cnt_b = 0

white = []
black = []

for i in range(len(s)):
    if i%2 == 0:
        white.append("1")
        black.append("0")
    else:
        white.append("0")
        black.append("1")
        
for i in range(len(s)):
    if white[i] != s[i]:
        cnt_w += 1
    if black[i] != s[i]:
        cnt_b += 1

print(min(cnt_w, cnt_b))

Measured memory_bytes: 5544
N,M=map(int,input().split(' '))
X=sorted(list(map(int,input().split(' '))))
X_dif = []
for i in range(M-1):
    X_dif.append(X[i+1]-X[i])
X_dif=sorted(X_dif,reverse=True)
print(max(X)-min(X)-sum(X_dif[:N-1]))

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

int main(){
  int a, b, k;
  cin >> a >> b >> k;
  vector<int>ans;
  for(int i = 1; i < 120; i++){
    if(a % i == 0 && b % i == 0){
      //cout << i << endl;
      ans.push_back(i);
    }
  }
  reverse(ans.begin(), ans.end());
  cout << ans[k-1] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b){if(a < b){ a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b){if(a > b){ a = b; return 1;} return 0;}

const int INF = 100000; 

int main(){
    string s, t, u;
    cin >> s >> t >> u;

    char x = t[0];

    cout << 'A' << x << 'C' << endl;

    return 0;
}


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

int main() {

  int n, a, b;
  cin >> n >> a >> b;

  if (n >= a + b) {
    if (a <= b) {
      cout << a << " " << 0 << endl;
      return 0;
    } else {
      cout << b << " " << 0 << endl;
      return 0;

    }
  } else {
    if (a <= b) {
      cout << a << " " << a+b-n << " " << endl;
      return 0;
    } else {
      cout << b << " " << a+b-n << " " << endl;
      return 0;
    }
  }
  return 0;
}

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

#pragma warning(disable : 4996)

using namespace std;

int N, X, Y; vector<int> x, y;

int minx, miny, maxx, maxy;

bool check(int d)
{
	for (int i = 0; i < N; i++)
	{
		if ((x[i] - minx > d || y[i] - miny > d) && (maxx - x[i] > d || maxy - y[i] > d))
		{
			return false;
		}
	}

	return true;
}

int main()
{
	scanf("%d", &N);

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &X);
		scanf("%d", &Y);

		x.push_back(X + Y);
		y.push_back(X - Y);
	}

	minx = *min_element(x.begin(), x.end());
	miny = *min_element(y.begin(), y.end());
	maxx = *max_element(x.begin(), x.end());
	maxy = *max_element(y.begin(), y.end());

	vector<int> c1, c2;

	for (int i = 0; i < N; i++)
	{
		c1.push_back(min(max(x[i] - minx, y[i] - miny), max(maxx - x[i], maxy - y[i])));
		c2.push_back(min(max(maxx - x[i], y[i] - miny), max(x[i] - minx, maxy - y[i])));
	}

	printf("%d\n", min(*max_element(c1.begin(), c1.end()), *max_element(c2.begin(), c2.end())));

	return 0;
}

Measured memory_bytes: 4712
using System;
class main
{
    static void Main(string[] args)
    {
        for (int a = 1; a <= 9; ++a)
        {
            for (int b = 1; b <= 9; ++b)
            {
                Console.WriteLine(a + "x" + b + "=" + (a*b));
            }
        }
        Console.ReadKey();
    }
}

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

ll x;

int main() {
    cin>>x;
    ll l=0, r=1e9,m;
    while (l<r){
        m=(l+r)/2;
        if (m*(m+1)/2>=x) r=m;
        else l=m+1;
    }
    cout<<r<<"\n";
    return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
INF = 10**18

MAX = max(A)
MIN = min(A)

res = INF
for s in range(MIN,MAX+1):
    t = 0
    for i in range(N):
        t += (s - A[i])**2
    #print(s,t)
    if t < res:
        res = t
print(res)

Measured memory_bytes: 38640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    char s;
    cin>>s;
    if(s>='a' && s<='z')
    {
        cout<<"a"<<endl;
    }
    else if(s>='A' && s<='Z')
    {
        cout<<"A"<<endl;
    }

    return 0;




}


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

using namespace std;

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

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

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

    if(s[0]!='A'){
        cout << "WA" << endl;
        return 0;
    }

    int cpos = -1;
    FOR(i,1,s.size()){
        //if(  !(((int)s[i]>=65 && (int)s[i]<=90) || ((int)s[i]>=97 && (int)s[i]<=122))){
        if(s[i]=='C'){
            if(i>=2&&i<s.size()-1){
                if(cpos!=-1){
                    cout << "WA" << endl;
                    return 0;
                }else{
                    cpos=i;
                }
            }else{
                cout << "WA" << endl;
                return 0;
            }
        } else if( !((int)s[i]>=97 && (int)s[i]<=122) ){
            cout << "WA" << endl;
            return 0;
        }

    }

    if(cpos==-1){
        cout << "WA" << endl;
        return 0;
    }
    cout << "AC" << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REP(a, b, m) for (ll a = (ll)(b); a < (ll)(m); a++)

string abc = "abcdefghijklmnopqrstuvwxyz";

int sabc(string s, string t)
{
    int ans;
    for (char abc = 'a'; abc <= 'z'; abc++)
    {
        bool fs = false;
        bool ft = false;
        for (int i = 0; i < s.length(); i++)
        {
            if (s[i] == abc)
            {
                fs = true;
            }
        }
        for (int i = 0; i < t.length(); i++)
        {
            if (t[i] == abc)
            {
                ft = true;
            }
        }
        if (fs && ft)
            ans++;
    }
    return ans;
}
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    REP(i, 0, n + 1)
    {
        int memo = sabc(s.substr(0, i), s.substr(i));
        ans = max(ans, memo);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
from itertools import accumulate

def length(S):
    cnt = 1
    A = []
    for i in range(len(S)-1):
        if S[i] == S[i+1]:
            cnt += 1
        else:
            A.append(cnt)
            cnt = 1
    else:
        A.append(cnt)

    return A

def main():
    N, K = map(int, input().split())
    S = input()
    lens = length(S)
    A = [0] + list(accumulate(lens))
    ans = 0
    if S[0] == '0':
        A = [0] + A
        for i in range(1,len(A)+1,2):
            right = i + 2 * K
            if right >= len(A):
                right = len(A) - 1
            tmp = A[right] - A[i-1]
            ans = max(ans, tmp)
    else:
        for i in range(1,len(A)+1,2):
            right = i + 2 * K
            if right >= len(A):
                right = len(A) - 1
            tmp = A[right] - A[i-1]
            ans = max(ans, tmp)

    print(ans)



if __name__ == "__main__":
    main()

Measured memory_bytes: 48608
# https://abc076.contest.atcoder.jp/tasks/abc076_c
#

S = input()
T = input()

candidates = []
for i in range(len(S) - len(T) + 1):
    yn = all(S[i + k] == "?" or S[i + k] == T[k] for k in range(len(T)))
    if yn:
        s = S[:i] + T + S[i + len(T) :]
        candidates.append(s)

if candidates:
    candidates = ["".join("a" if c == "?" else c for c in s) for s in candidates]
    print(min(candidates))
else:
    print("UNRESTORABLE")


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

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

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
typedef pair<ll, int> PLI;
const ll mod = 1e9 + 7;

ll r, c;
int n;

// Returns the relative position on the perimeter of the given rectangle.
// -1 if (x, y) is not on the perimeter.
// counter-clockwise
ll on_edge(ll x, ll y) {
  if (y == 0) {
    return x;
  }
  if (x == r) {
    return r + y;
  }
  if (y == c) {
    return r + c + r - x;
  }
  if (x == 0) {
    return 2 * (r + c) - y;
  }
  return -1;
}

int main(void){
  cin >> r >> c >> n;
  vector<PLI> pool;
  REP(i, 0, n) {
    ll x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    ll pos1 = on_edge(x1, y1);
    ll pos2 = on_edge(x2, y2);
    if (pos1 >= 0 && pos2 >= 0) {
      pool.push_back(PLI(pos1, i));
      pool.push_back(PLI(pos2, i));
    }
  }
  sort(pool.begin(), pool.end());
  if (0) {
    REP(i, 0, pool.size()) {
      cerr << "pool[" << i << "]:" << pool[i].first
	   << " (" << pool[i].second << ")" << endl;
    }
  }
  vector<int> st;
  REP(i, 0, pool.size()) {
    int t = pool[i].second;
    if (st.size() == 0 || st.back() != t) {
      st.push_back(t);
    } else {
      st.pop_back();
    }
  }
  cout << (st.empty() ? "YES" : "NO") << endl;
}


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

using namespace std;
using ll = long long;

int main() {
    int n,m,x;
    cin>>n>>m>>x;
    vector<vector<int>> books(n,vector<int>(m));
    vector<int> pr(n);
    for(int i = 0;i < n;++i) {
        cin>>pr[i];
        for(int j = 0;j < m;++j) {
            cin>>books[i][j];
        }
    }
    int ans=100000000;
    for(int bit = 0;bit < 1<<n;++bit) {
        vector<int> chisi(m,0);
        int tans=0;
        for(int i = 0;i < n;++i) {
            if((bit&(1<<i))==0)continue;
            tans+=pr[i];
            for(int j = 0;j < m;++j) {
                chisi[j]+=books[i][j];
            }
        }
        bool ok=true;
        for(int i = 0;i < m;++i) {
            if(chisi[i]<x) {
                ok=false;
                break;
            }
        }
        if(ok)ans=min(ans,tans);
    }

    if(ans==100000000)cout<<-1<<endl;
    else cout<<ans<<endl;

    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
int n,x;
double tot;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>x;
        tot+=1.0/x;
    }
    tot=1/tot;
    printf("%.6f\n",tot);
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int m1,d1;
	int m2,d2;
	cin>>m1>>d1>>m2>>d2;
	if(m1>m2||(m1==m2&&d1<d2))
	{
		cout<<0<<endl;
		return 0;
	}
	if(m1==1||m1==3||m1==5||m1==7||m1==8||m1==10||m1==12)
	{
		if(d1==31)
		{
			cout<<"1"<<endl;
		}
		else 
		{
			cout<<"0"<<endl;
		}
	}
	else if(m1==4||m1==6||m1==9||m1==11)
	{
		if(d1==30)
		{
			cout<<"1"<<endl;
		}
		else 
		{
			cout<<"0"<<endl;
		}
	}
	else
	{
		if(2019%4==0&&2019%100||2019%400==0)
		{
			if(m1==2&&d1==29)
			{
				cout<<"1"<<endl;
			}
			else
			{
				cout<<"0"<<endl;
			}
		}
		else
		{
			if(m1==2&&d1==28)
			{
				cout<<"1"<<endl;
			}
			else
			{
				cout<<"0"<<endl;
			}
		}
	}
	return 0;
}

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

using namespace std;

int main(){
	int n,a,b;
	cin >>n>>a>>b;
	int x=0,y=0,z=0;
	for(int i=0;i<n;i++){
		int temp;
		cin >>temp;
		if(temp<a+1){
			x++;
		}else if(temp>b){
			z++;
		}else{
			y++;
		}
	}
	cout <<min(min(x,y),z)<<endl;
	
	return 0;
}

Measured memory_bytes: 3636
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Queue;

public class Main {

	public static void main(String args[]) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] firstRow = br.readLine().split("\\s");

		// ????卒???属
		int elementNum = Integer.parseInt(firstRow[0]);
		// ???????????????
		int quantum = Integer.parseInt(firstRow[1]);

		// ????????\??????????????????????????????????????????FIFO
		// ?????????stack,dequeue??則?????贈????????則?????????queue??則???????????????????????贈???????????????????????????
		Queue<Process> que = new LinkedList<Process>();
		for (int i = 0; i < elementNum; i++) {
			String[] stringArray = br.readLine().split("\\s");
			// ???p1 150?????????????????蔵?????則stringArray????????????????????????
			// p1?????????????????????,150???????????????????????????????????????????????即??????????????????
			// ????????贈??即??????????????????????????????????????????
			Process process = new Process(stringArray[0],
					Integer.parseInt(stringArray[1]));
			que.offer(process);
		}

		// ??????????即???????
		int resultTime = 0;
		while (que.size() > 0) {
			// ???????????????????????????
			Process process = que.poll();
			resultTime += quantum;
			if ((process.processTime = process.processTime - quantum) > 0) {
				// ??????????????????????????????????????????????????????????????卒??????
				// ???????属?????????????????????即??????????????????
				que.offer(process);
				continue;
			}
			// processTime???(-20)??????????????贈???????????属????????????????????????
			// ??????????即??????????????????????
			resultTime += process.processTime;
			// ?????????????????????????????????????????卒???????????????????????即??????????????則???????????贈?????????
			// ??即???????????????????????????
			System.out.println(process.name + " " + resultTime);
		}

	}

	/**
	 * Process???????????????
	 */
	private final static class Process {
		// ??????????????????public????????????
		public String name = null;
		public int processTime = 0;

		public Process(String name, int processTime) {
			this.name = name;
			this.processTime = processTime;
		}
	}
}

Measured memory_bytes: 60568
import numpy as np
n,k = map(int,input().split())

arr = list(map(int,input().split()))
s = [0 for i in range(n)]
temp = 0
ans = 0

for i in range(1,k+1):
    upper = min(n,i)
    for j in range(upper+1):
        v = 0
        a = []
        for l in range(j):
            v += arr[l]
            a.append(arr[l])
        for l in range(1,upper+1-j):
            v+= arr[-l]
            a.append(arr[-l])
        a.sort()
        # print(a,v)
        up = min(k-upper,i)
        for l in range(up):
            if a[l] < 0:
                v -= a[l]
            else:
                break
        if v > ans:
            ans = v

print(ans)




Measured memory_bytes: 12500
#include<stdio.h>
int main()//错误
{
   int co[256]={0};
   char ch;

   while((ch = getchar())!=EOF)
   {
       co[ch]++;
   }
   for(int i=97;i<=122;i++)
   {
         printf("%c : %d\n",i,co[i]+co[i-32]);

   }
 }



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

lli n, p;

map<lli, lli> factorization(lli x){
	map<lli, lli> f;
	for(lli i = 2; i*i <= x; i++){
		while(x%i == 0){
			x/=i;
			f[i]++;
		}
	}
	if(x != 1) f[x] = 1;
	return f;
}

lli pow(lli a, lli x){
	lli ret = 1;
	while(x > 0){
		if(x&1){
			ret *= a;
			x--;
		}else{
			a *= a;
			x >>= 1;
		}
	}
	return ret;
}

int main(void){
	cin >> n >> p;
	auto f = factorization(p);
	lli g = 1;
	for(auto i : f){
		g *= pow(i.first, (i.second/n));
	}
	cout << g << endl;
	return 0;
}


Measured memory_bytes: 3596
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<cstdio>
using namespace std;
int n;
double r;
int t[100];
vector<int> x,y;
int main(){
  while(1){
    cin>>r>>n;
    if(r==0&&n==0)break;
    for(int i=0;i<100;i++)t[i]=0;
    for(int i=0;i<n;i++){
      int lx,rx,h;
      cin>>lx>>rx>>h;
      lx+=30,rx+=30;
      for(int j=lx;j<rx;j++)t[j]=max(t[j],h);
    }
    x.clear(),y.clear();
    for(int i=0;i<30;i++){
      x.push_back(30-i-1);
      y.push_back(t[i]);
    }
    for(int i=30;i<60;i++){
      x.push_back(i-30);
      y.push_back(t[i]);
    }
    double ans=10000000;
    for(int i=0;i<(int)x.size();i++){
if(r-0.00000001<x[i])continue;
      double d=y[i]+r-sqrt(r*r-x[i]*x[i]);
      ans=min(d,ans);
    }
    printf("%.8f\n",ans);
  }
  return 0;
}


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

int main()
{
	int n, m, x; cin >> n >> m >> x;
	vector<int> prices(n);
	vector<vector<int>> mat(n, vector<int>(m,0));
	for(int i = 0; i < n; ++i)
	{
		cin >> prices[i];
		for(int j = 0; j < m; ++j)
			cin >> mat[i][j];
	}

	bool found = false;
	int ans = -1;

	for(int i = 1; i < (1 << n); ++i)
	{
		vector<int> understanding(m, 0);

		int num = i;
		int pos = 0;
		int totalCost = 0;
		while(num)
		{
			int bit = (num & 1);
			if(bit)
			{
				int index = n - pos - 1;
				totalCost += (prices[index]);
				for(int j = 0; j < m; ++j)
				{
					understanding[j] += mat[index][j];
				}
			}
			num = num >> 1;
			++pos;
		}

		bool valid = true;
		for(int j = 0; j < m; ++j) valid = valid and (understanding[j] >= x);
		if(valid)
		{
			if(!found)
			{
				found = true;
				ans = totalCost;
			}
			else
			{
				ans = min(ans, totalCost);
			}
		}
	}

	cout << ans ;

	return 0;
}

Measured memory_bytes: 3636
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double n = Double.parseDouble(sc.next());
        double k = Double.parseDouble(sc.next());
        int a[] = new int[(int) n];
        for (int i = 0; i < n; i++) {
            a[1] = Integer.parseInt(sc.next());
        }
        sc.close();
        System.out.println((1 + (int) Math.ceil((n - k) / (k - 1))));
    }
}

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

N,M =  list(map(int,input().split()))
A = sorted(list(map(int,input().split())))
q = [tuple(map(int,input().split())) for i in range(M)]
q.sort(key= lambda x:-x[1])
#print(q)  

mask = []
for num,cost in q:
  mask += [cost]*num
  
  if len(mask) >=N:
    break
  if A[len(mask)-1] >= cost:
    break
    
res = 0
for idx,cost in enumerate(mask):
  if idx >= N:
    break
  if cost > A[idx]:
    res += cost
  else:
    break
else:
  idx+=1
    
for i in range(idx,len(A)):
  #print(i)
  res += A[i]
  
print(res)
  

Measured memory_bytes: 78572
'use strict'

function main(s) {

  s = s.split('\n')[0].split(' ').map(n => Number(n));
  s.sort((a, b) => a - b);

  const ans = s[0] + s[1];

  console.log(ans);
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ui = unsigned int;

string A, B;
int memo[4002][4002];
int prev_bin[4002][4002];

int next_A[2][4002];
int next_B[2][4002];

int dfs(ui i, ui j) {
	i = min(ui(A.size()), i);
	j = min(ui(B.size()), j);
	if (memo[i][j] != -1) return memo[i][j];
	{
		// use 0
		ui ni = i, nj = j;
		if (ni < A.size()) ni = next_A[0][ni];
		if (nj < B.size()) nj = next_B[0][nj];
		if(A.size() <= ni && B.size() <= nj) {
			memo[i][j] = 1;
			prev_bin[i][j] = 0;
		}else {
			memo[i][j] = 1 + dfs(ni + 1, nj + 1);
			prev_bin[i][j] = 0;
		}
	}
	{
		// use 1
		ui ni = i, nj = j;
		if (ni < A.size()) ni = next_A[1][ni];
		if (nj < B.size()) nj = next_B[1][nj];
		if (A.size() <= ni && B.size() <= nj) {
			if(memo[i][j] > 1) {
				memo[i][j] = 1;
				prev_bin[i][j] = 1;
			}
		} else {
			int res = 1 + dfs(ni + 1, nj + 1);
			if (memo[i][j] > res) {
				memo[i][j] = res;
				prev_bin[i][j] = 1;
			}
		}
	}
	return memo[i][j];
}

int main() {
	cin >> A >> B;
	memset(memo, -1, sizeof(memo));

	for(int i=0;i<A.size();i++) {
		{
			int ni = i;
			while (ni < A.size() && A[ni] != '0') ni++;
			next_A[0][i] = ni;
		}
		{
			int ni = i;
			while (ni < A.size() && A[ni] != '1') ni++;
			next_A[1][i] = ni;
		}
	}

	for (int j = 0; j<B.size(); j++) {
		{
			int nj = j;
			while (nj < B.size() && B[nj] != '0') nj++;
			next_B[0][j] = nj;
		}
		{
			int nj = j;
			while (nj < B.size() && B[nj] != '1') nj++;
			next_B[1][j] = nj;
		}
	}

	int n = dfs(0, 0);

	ui i = 0, j = 0;
	for(int k=0;k<n;k++) {
		int c = prev_bin[i][j];
		cout << prev_bin[i][j];
		if (i < A.size()) i = next_A[c][i];
		if (j < B.size()) j = next_B[c][j];
		i = min(i + 1, ui(A.size()));
		j = min(j + 1, ui(B.size()));
	}
	cout << endl;

	return 0;
}



Measured memory_bytes: 113888
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int A[10001];
int main() {
    ll N;
    cin >> N;
    ll ans = 0;
    reps(a, 1, N){
        ans += (ll)(N - 1)/(ll)a;
    }
    cout << ans;
    return 0;
}



Measured memory_bytes: 3620
use std::io::*;

fn main() {
    let i = stdin();
    solve(&mut i.lock(), &mut stdout());
}

fn solve(i: &mut BufRead, o: &mut Write) {
    let n_str = read_line(i);
    let ns: Vec<usize> = n_str
        .chars()
        .map(|c| c.to_string().parse().unwrap())
        .collect();

    let mut r = ns[0] + 9 * (ns.len() - 1);
    let has_non9 = ns.iter().skip(1).position(|&x| x != 9).is_some();
    if has_non9 {
        r -= 1;
    }

    writeln!(o, "{}", r).unwrap();
}

fn read_line(i: &mut BufRead) -> String {
    let mut line = String::new();
    i.read_line(&mut line).unwrap();
    line.trim().to_string()
}


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

public class Main {

	public static void main(String[] args) {
		Scanner in=new Scanner(System.in);
		PrintWriter out=new PrintWriter(System.out);
		while(true) {
			String str=in.next(); char[] num=str.toCharArray();
			if(num[0]=='0')break;
			int sum=0;
			for(int i=0;i<num.length;i++)sum+=num[i]-48;
			out.println(sum);
		}
		out.flush();
	}

}



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

int main(){
  string s;
  cin >> s;
  
  if(s=="SSS")cout << 0;
  if(s=="SSR")cout << 1;
  if(s=="SRS")cout << 1;
  if(s=="SRR")cout << 2;
  if(s=="RSS")cout << 1;
  if(s=="RSR")cout << 1;
  if(s=="RRS")cout << 2;
  if(s=="RRR")cout << 3;
  return 0;
}


Measured memory_bytes: 3616
<?php
 
$input = trim(fgets(STDIN));
 
$nums = explode(" ", $input);
 
$a = $nums[0];
 
$b = $nums[1];
 
if ($a > $b){
echo "a > b",PHP_EOL;
} else if ($a < $b){
echo "a < b",PHP_EOL;
} else {
echo "a == b" , PHP_EOL;
}

Measured memory_bytes: 15376
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for(int i = 0; i < n; ++i)
#define repr(i,n) for(int i = n - 1; i >= 0; --i)
#define Rep(i, a, n) for(int i = (a); i <=(n); ++i)
#define repst(i, n) for(auto it = n.begin(); it != n.end(); ++it)
#define Repr(i, a, n) for(int i = (n); i >= (a); --i)
typedef long long ll;

const int inf = int(1e9);
const int mod = inf + 7;
using namespace std;
const int N = 5e5 + 555;

void solve()
{
	int n, c, k;
	cin >> n >> c >> k;
	int t[n];
	for(int i = 0; i < n; ++i)
	{
		cin >> t[i];
	}
	sort(t, t + n);
	int all = 1;
	int cnt = 1;
	int cur = t[0] + k;
	for(int i = 1; i < n; ++i){
		if(cnt == c){
			all++;
			cur = t[i] + k;
			cnt = 1;
		}
		else{
			if(t[i] <= cur){			
				cnt++;
			}else{
				cnt = 1;
				all++;
				cur = t[i] + k;
			}
		}
	}
	cout << all;
}	

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

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

//これはすぬけくんのかっこいい解説動画をみたはずだ・・・

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


	int N, K;
	cin >> N >> K;

	ll mod = 1e9 + 7;
	ll dp[51][51][2501] = {};
	dp[0][0][0] = 1;

	rep(i, N) {
		rep(j, i + 1) {
			rep(k, (i + 1) * (i + 1)) {
				if (dp[i][j][k]) {
					dp[i][j][k] %= mod;
					dp[i + 1][j + 1][k + 2 * (j + 1)] += dp[i][j][k];
					dp[i + 1][j][k + 2 * j] += dp[i][j][k];
					if (j) dp[i + 1][j][k + 2 * j] += dp[i][j][k] * j * 2;
					if (j) dp[i + 1][j - 1][k + 2 * (j - 1)] += dp[i][j][k] * j * j;
				}
			}
		}
	}
	co(dp[N][0][K] % mod);

	Would you please return 0;
}

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

int main(void){
    int n,x;
    cin>>n>>x;
    vector<int> L(n);
    int di = 0;
    int i;
    for(i=0;i<n;i++){
        cin>>L[i];
        di += L[i];
        if(di>x) break;
    }
    cout<<i+1<<endl;
    return 0;
}

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

int main() {
  int K;
  cin >> K;
  if(K%2 == 0){
    cout << (K/2)*(K/2) << endl;
    return 0;
  }
  cout << (K/2)*(K/2+1) << endl;
} 


Measured memory_bytes: 3644
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;

int main() {
    int N;
    int d[110] = {0};

    cin >> N;
    for(int i = 0; i < N; i++) cin >>d[i];

    sort(d, d+N, greater<int>());

    int prev_val = d[0];
    int count = 1;
    for(int i = 0; i < N; i++) {
        if(prev_val != d[i]) count++;
        prev_val = d[i];
    }

    cout << count << endl;

    return 0;

}

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

int main()
{
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	int ans = 0;
	for (int i = 0; i < n; i++)
	{
		set<char> st;
		st.emplace(a[i]);
		st.emplace(b[i]);
		st.emplace(c[i]);
		ans += st.size() - 1;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
using namespace std;
int calculator(int, string, int);
int main() {
  int a, b;
  string op;
  cin >> a >> op >> b;
  while (op != "?") {
    cout << calculator(a, op, b) << endl;
    cin >> a >> op >> b;
  }
  //cout << calculator(calculator(3,"*",10),"+",7) << endl;
  //cout << calculator(3, "*", calculator(10,"+",7)) << endl;
}
int calculator(int a, string op, int b) {
  if (op == "+")
    return a + b;
  else if (op == "-")
    return a - b;
  else if (op == "*")
    return a * b;
  else // op == "/"
    return a / b;
}

Measured memory_bytes: 1208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    string n;
    cin >> n;
    REP(i, n.size()) {
        if (n[i]=='1') cout << 9;
        else cout << 1;
    }
    cout << "\n";
}


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

int main() {
	int N;
	cin >> N;
	int L[101];
	int max = 0;

	for (int i = 0; i < N; i++) {
		cin >> L[i];
		if (max < L[i]) {
			max = L[i];
		}
	}
	int sum = 0;

	for (int i = 0; i < N; i++) {
		sum += L[i];
	}
	if (max < sum - max) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
};


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#define ll long long
using namespace std;
int main(){
    ll x;
    cin>>x;
    ll m=100;
    ll cnt=0;
    while(m<x){
        m*=1.01;
        cnt++;
    }
    cout<<cnt<<endl;
    return 0;
}

Measured memory_bytes: 3596
import sys
sys.setrecursionlimit(10**9)
k=int(input())
ansl=[1,2,3,4,5,6,7,8,9]
l=["0","1","2","3","4","5","6","7","8","9"]
def f(x,p):
    if int(x+p)>3234566668:
        return
    x+=p
    ansl.append(int(x))
    if p=="0":
        f(x,"0")
        f(x,"1")
    elif p=="9":
        f(x,"9")
        f(x,"8")
    else:
        y=int(p)
        f(x,l[y-1])
        f(x,l[y])
        f(x,l[y+1])

for i in range(1,10):
    x=str(i)
    if x=="0":
        f(x,"0")
        f(x,"1")
    elif x=="9":
        f(x,"9")
        f(x,"8")
    else:
        y=int(x)
        f(x,l[y-1])
        f(x,l[y])
        f(x,l[y+1])
ansl.sort()
print(ansl[k-1])


Measured memory_bytes: 49368