akhauriyash/Code-Regression huggingface dataset:
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <numeric>
#include <queue>
#include <stack>
#include <map> 
#include <set>
#include <string>
#include <functional>
#include <list>
#include <random>
#include <time.h>
#include <iomanip>
#include <assert.h>
#include <numeric>
#define int long long
#define ll long long
#define double long double
#define mod 1000000007
#define MAXN (int)1e+5 * 2+1
#define LL_MAX 9223372036854775807	//ない環境用
#define LL_HALFMAX 9223372036854775807 / 2	//ない環境用
#define MIN -(9223372036854775807 / 2)
#define INF 9223372036854775807 / 2
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define mp make_pair


using namespace std;

std::mt19937 mt((int)time(0));

int dx[4] = { 0, 1, 0, -1 }; // x軸方向への変位
int dy[4] = { 1, 0, -1, 0 }; // y軸方向への変位

using Weight = int;
using Flow = int;
struct Edge {
	int src, dst;
	Weight weight;
	Flow cap;
	Edge() : src(0), dst(0), weight(0) {}
	Edge(int s, int d, Weight w) : src(s), dst(d), weight(w) {}
};
using Edges = std::vector<Edge>;
using Graph = std::vector<Edges>;
using Array = std::vector<Weight>;
using Matrix = std::vector<Array>;

void add_edge(Graph &g, int a, int b, Weight w = 1) {
	g[a].emplace_back(a, b, w);
	g[b].emplace_back(b, a, w);
}
void add_arc(Graph &g, int a, int b, Weight w = 1) { g[a].emplace_back(a, b, w); }

struct uf_tree {
	std::vector<int> parent;
	int __size;
	uf_tree(int size_) : parent(size_, -1), __size(size_) {}
	void unite(int x, int y) {
		if ((x = find(x)) != (y = find(y))) {
			if (parent[y] < parent[x]) std::swap(x, y);
			parent[x] += parent[y];
			parent[y] = x;
			__size--;
		}
	}
	bool is_same(int x, int y) { return find(x) == find(y); }
	int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
	int size(int x) { return -parent[find(x)]; }
	int size() { return __size; }
};

//!!!問題をちゃんと読む!!!
//!!!問題をちゃんと読め!!!
//!!!問題は読みましたか？!!!

string sts[100000];
signed main() {
	int N;
	cin >> N;
	rep(i, N) {
		cin >> sts[i];
	}
	int ans = 0, swa = 0,swb = 0, ewa = 0, ewb = 0, ba = 0;
	rep(i, N) {
		rep(j, sts[i].length() - 1) {
			if (sts[i][j] == 'A' && sts[i][j + 1] == 'B') {
				ans++;
			}
			
		}
		if (sts[i][sts[i].length() - 1] == 'A' && sts[i][0] == 'B') {
			ba++;
		}
		else {
			if (sts[i][0] == 'A') {
				swa++;
			}
			if (sts[i][0] == 'B') {
				swb++;
			}
			if (sts[i][sts[i].length() - 1] == 'A') {
				ewa++;
			}
			if (sts[i][sts[i].length() - 1] == 'B') {
				ewb++;
			}
		}


	}
	int baAdd = max(0LL, ba - 1LL);
	ans += baAdd;
	if (ba >= 1) {
		if (ewa >= 1) {
			ans++;
			ewa--;
		}
		if (swb >= 1) {
			ans++;
			swb--;
		}
	}
	
	ans += min(swb, ewa);

	cout << ans << "\n";


	return 0;
}

Measured memory_bytes: 1536
// luogu-judger-enable-o2
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
int a[100000+5];
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    for(int i=1;i<=n;i++)
    {
        ans=ans+a[i]/2;
        a[i]=a[i]%2;
        if(i<n&&a[i]&&a[i+1])
        {
            ++ans;
            --a[i];
            --a[i+1];
        }
    }
    printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 640
import sys
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    H, N = map(int, input().rstrip().split())
    magic_list = []
    for _ in range(N):
        A, B = map(int, input().rstrip().split())
        magic_list.append((A, B))

    # dp[hp] = hpのダメージを与えるための最小魔力
    dp = [100000000] * (H+1)
    # 0のダメージを与えるのに必要な最小魔力は0
    dp[0] = 0
    # 各魔法に関して探索
    for i, magic in enumerate(magic_list):
        damage, mp = magic
        # 各ダメージを与えるのに必要な最小魔力を更新する
        # (与えられないダメージ数の場合は最大値で初期化してあるので、最大値のまま更新されない)
        for hp in range(H+1):
            # 魔法を使用する場合のダメージについて、必要魔力が現在計算されている中での最小値であれば更新
            dp[min(H, hp+damage)] = min(dp[min(H, hp+damage)], dp[hp] + mp)
    print(dp[H])

if __name__ == '__main__':
    main()

Measured memory_bytes: 40688
#include <iostream>
using namespace std;
int main(){
    int n;
    long long a;
    long long MB = 1000000;
    long long ML = -1000000;
    long long sum = 0;
    
    cin >> n;
    for(int i=0;i<n;i++){
        cin >> a;
        if(a>ML)ML=a;
        if(a<MB)MB=a;
        sum+=a;
    }
    cout << MB << " " << ML << " " << sum << endl;
}


Measured memory_bytes: 3096
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
using namespace std;

int main(){
  int n;
  cin >> n;
  
  vector<string> v(n);
  vector<string> w(n);
  for(int i = 0; i < n; i++){
    cin >> v[i]; w[i] = v[i];
  }
  bool h = true;
  while(h){
    h = false;
    for(int j = n - 1; j > 0; j--){
      if(w[j][1] < w[j - 1][1]){
        swap(w[j], w[j - 1]);
        h = true;
      }
    }
  }
  for(int i = 0; i < n; i++){
    if(i != n - 1){
      cout << w[i] << " ";
    }
    else{
      cout << w[i] << endl;
    }
  }
  cout << "Stable" << endl;

  bool f = false;
  for(int i = 0; i < n; i++){
    int minj = i;
    for(int j = i; j < n; j++){
      if(v[j][1] < v[minj][1]){
        minj = j;
        f = true;
      }
    }
    swap(v[i], v[minj]);
  }
  
  for(int i = 0; i < n; i++){
    if(i != n - 1){
      cout << v[i] << " ";
    }
    else{
      cout << v[i] << endl;
    }
  }
  bool fin = true;
  for(int i = 0; i < n; i++){
    if(v[i] != w[i]){
      cout << "Not stable" << endl;
      fin = false;
      break;
    }
  }
  if(fin){ cout << "Stable" << endl;}
}


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

using namespace std;

int main(){
  int i, min = 0, mid = 0, max = 0, cost = 0;
  int A[3];



  for(i = 0; i < 3; i++){
    cin >> A[i];
  }

  min = A[0];
  max = A[0];
  for(i = 1; i < 3; i++){
    if( A[i] < min) min = A[i];
    if( max < A[i]) max = A[i];
    if(min != A[i] && max != A[i]) mid = A[i];
  }


  cost = mid - min;
  cost += max - mid;

  cout << cost << endl;

  return 0;

}


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

#define rep(i,n) for(ll i=0,i##_cond=(n);i<i##_cond;++i)
#define FOR(i,a,b) for(ll i=(a),i##_cond=(b);i<i##_cond;++i)
#define ROF(i,a,b) for(ll i=(a)-1,i##_cond=(b);i>=i##_cond;--i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define sz(x) ((ll)(x).size())
#define pb push_back
#define fst first
#define snd second
#define mp make_pair

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<ll,ll> pii;

const ll inf = 1ll<<62;
const ll mod = 1e9+7;

using Cost = ll;
class node {
public:
  ll v;
  Cost d;
  node(ll _a, Cost _b):v(_a),d(_b){}
  bool operator<(const node &n) const { return d > n.d; }
};
class edge {
public:
  ll to;
  Cost d;
  edge(){}
  edge(ll _to, Cost _d):to(_to),d(_d){}
};
class dijkstra{
public:
  vector<vector<edge>> G;
  vector<Cost> dist;
  vector<ll> prev;

  dijkstra(ll s,const vector<vector<edge>> &_G):G(_G){ // sからの最短経路
    dist.resize(G.size(),1ll << 59);
    //prev.resize(G.size(),-1);
  
    priority_queue<node> que;
    que.push(node(s, 0));
    dist[s] = 0;
    
    while(!que.empty()){
      ll v = que.top().v;
      Cost d = que.top().d;
      que.pop();
      
      rep(i, G[v].size()){
	Cost tmp = d + G[v][i].d;
	if(dist[G[v][i].to] > tmp){
	  dist[G[v][i].to] = tmp;
	  //prev[G[v][i].to] = v;
	  que.push(node(G[v][i].to, tmp));
	}
      }
    }
  }

  dijkstra(ll s,ll t,const vector<vector<edge>> &_G):G(_G){ // sからtへの最短経路
    dist.resize(G.size(),1ll << 59);
    //prev.resize(G.size(),-1);
  
    priority_queue<node> que;
    que.push(node(s, 0));
    dist[s] = 0;
    
    while(!que.empty()){
      ll v = que.top().v;
      Cost d = que.top().d;
      que.pop();
      if(v == t) break;
      
      rep(i, G[v].size()){
	Cost tmp = d + G[v][i].d;
	if(dist[G[v][i].to] > tmp){
	  dist[G[v][i].to] = tmp;
	  //prev[G[v][i].to] = v;
	  que.push(node(G[v][i].to, tmp));
	}
      }
    }
  }

  vector<ll> getpath(ll t){ // tへの最短経路を返す
    vector<ll> path;
    while(t != -1){
      path.push_back(t);
      t = prev[t];
    }
    reverse(path.begin(), path.end());
    return path;
  }
};

int main(){
#define int ll
  int k; cin >> k;
  vector<vector<edge>> g(k,vector<edge>(2));
  rep(i,k){
    g[i][0] = edge((i+1)%k,1);
    g[i][1] = edge((i*10)%k,0);
  }
  dijkstra d(1,0,g);
  cout << d.dist[0]+1 << endl;
}

Measured memory_bytes: 16252
//(・ω・)
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, atoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <iomanip> //setprecision
#include <limits>
#include <sstream> //istringstream
using namespace std;

int main(){
   unsigned long long h,w,a,b,ans;
   cin >> h >> w;
   if(h==1 || w==1) ans=1;
   else{
      a=(w+1)/2;
      b=(h+1)/2;
      ans=a*b+(h-b)*(w-a);
   }
   cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <utility>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <iomanip>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val
 
using namespace std;
using namespace __gnu_pbds;
 	// find_by_order()  // order_of_key
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
#define f(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) f(i,0,n)
#define fd(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mp make_pair
#define vi vector< int >
#define vl vector< ll >
#define ss second
#define ff first
#define ll long long
#define pii pair< int,int >
#define pll pair< ll,ll >
#define sz(a) a.size()
#define inff (1000*1000*1000+5)
#define all(a) a.begin(),a.end()
#define tri pair<int,pii>
#define vii vector<pii>
#define vll vector<pll>
#define viii vector<tri>
#define pqueue priority_queue< int >
#define pdqueue priority_queue< int,vi ,greater< int > >
#define flush fflush(stdout) 
#define primeDEN 727999983
#define SPEED ios_base::sync_with_stdio(false) ;cin.tie(NULL) ;cout.tie(NULL) ;
#define fp(i,a,n) for(ll i=n-1; i>a ;i--)
#define deb(x) cout << #x << " ---> " << x << endl;
#define X first
#define Y second
#define pia 3.1415926536
#define mod 1000000007 
#define N 300050
#define ml map<ll,ll>
#define mll map<pair<ll,ll> ,ll>
#define letsh(a,b) a<<b
#define rigsh(a,b) a>>b 
#define vvl vector<vl>
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count()) ;
		ll lcm(ll a, ll b)
		{
               return a / __gcd(a, b) * b;
       	}
       ll power(ll a,ll n,ll m=mod)
	   {
        ll ans=1;
        while(n)
		{
        if(n&1) ans=(ans*a)%mod;
        a=(a*a)%mod ;
        n=n>>1;
   		 }
   		 return ans;
      }
      ll n,m ;
      vll dir({{1, 0}, {-1, 0}, {0, 1}, {0, -1}});
    
      void solve()
      {
       ll n ;cin>>n ;
       vl a(n) ;f(i,0,n) cin>>a[i] ;
       sort(all(a)) ;
       ll ans =0 ;
       f(i,0,n)
       {
       	f(j,i+1,n)
       	{
       		if(a[i] == a[j]) continue ;
       	  f(k,j+1,n)
			 {
			 	if(a[k] == a[j]) continue ;
			 	if(a[i]+a[j] >a[k]) ans++ ;
				 else break ;
		    }	
		}
	   }
	   cout<<ans<<endl ;
	  }
      
    int main() 
	  {
	  	SPEED
      ll t =1 ;
       while(t--) solve() ; 
	  }

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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a) {
    out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
    out<<'[';
    for(const T &i: a) out<<i<<',';
    out<<']';
    return out;
}
template<class T>
ostream &operator <<(ostream& out, const set<T>& a) {
    out<<'{';
    for(const T &i: a) out<<i<<',';
    out<<'}';
    return out;
}
template<class T, class S>
ostream &operator <<(ostream& out, const map<T,S>& a) {
    out<<'{';
    for(auto &i: a) out<<i<<',';
    out<<'}';
    return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n);
    REP(i, m) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        g[a].push_back(b);
    }
    ll s, t;
    cin >> s >> t;
    s--, t--;

    struct node {
        ll cost, vertex, idx;
        bool operator<(node r) const {
            return cost > r.cost;
        }
    };
    vector<vector<ll>> dist(n, vector<ll>(3, LLINF));
    priority_queue<node> que;
    for(auto i: g[s]) {
        dist[i][0] = 1;
        que.push({dist[i][0], i, 0});
    }
    while(que.size()) {
        node nd = que.top(); que.pop();
        // cout << nd.cost << " " << nd.vertex << " " << nd.idx << endl;
        if(dist[nd.vertex][nd.idx] < nd.cost) continue;
        for(auto to: g[nd.vertex]) {
            if(dist[to][(nd.idx+1)%3] > dist[nd.vertex][nd.idx] + (nd.idx==2)) {
                dist[to][(nd.idx+1)%3] = dist[nd.vertex][nd.idx] + (nd.idx==2);
                que.push({dist[to][(nd.idx+1)%3], to, (nd.idx+1)%3});
            }
        }
    }

    // REP(i, n) cout << dist[i] << endl;

    if(dist[t][2] == LLINF) cout << -1 << endl;
    else cout << dist[t][2] << endl;

    return 0;
}


Measured memory_bytes: 11264
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;

/// <summary>
/// https://atcoder.jp/contests/dp/tasks/dp_a
/// </summary>
internal static class CR
{
    public static string GetText() { return Console.ReadLine(); }
    public static List<string> GetTexts() { return Console.ReadLine().Split(' ').ToList(); }
    public static long GetLong() { return long.Parse(Console.ReadLine()); }
    public static List<long> GetLongs() { return Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList(); }
}

namespace AtCoder.A
{
    public class Program
    {
        public static long N { get; private set; }
        public static List<long> H { get; private set; }

        public static void Main() { var r = GetResult(); Debug.WriteLine(r); Console.Write(r); }

        private static object GetResult()
        {
            N = CR.GetLong();
            H = CR.GetLongs();

            var dp = new List<long>
            {
                0,
                Math.Abs(H[0]- H[1]),
            };

            for (int i = 2; i < N; i++)
            {
                var rootA = Math.Abs(H[i] - H[i - 1]) + dp[i - 1];
                var rootB = Math.Abs(H[i] - H[i - 2]) + dp[i - 2];
                dp.Add(Math.Min(rootA, rootB));
            }

            return dp.Last();
        }
    }
}


Measured memory_bytes: 19936
#include <bits/stdc++.h>
using namespace std;
long long factorial(long long n){
  if(n==0){
    n=1;
  }else{
    n=n*factorial(n-1);
  }
  return n;
}

int main(){
  long long n,k;
  cin>>n>>k;

  int ans=k*pow((k-1),n-1);
  cout<<ans<<endl;
  return 0;
}



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

using namespace std;

//ifstream cin ("test.in");
//ofstream cout ("test.out");

string s;
int ans = 0x3f3f3f3f;
int lng[26];

int main() {
  cin >> s;
  for (int i = 0; i < 26; ++i) {
    int cnt = 0;
    for (char it: s) {
      if (it == i + 'a') {
        cnt = 0;
      }
      else {
        ++cnt;
      }

      lng[i] = max(lng[i], cnt);
    }

    ans = min(lng[i], ans);
  }

  cout << ans << '\n';
  return 0;
}

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

using namespace std;

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

  int N; cin>>N;
  vector<pair<double, double>> dot(N);
  for (auto& p : dot) {
    cin>>p.first>>p.second;
  }

  auto min_range = [&](double x, double y) {
    double r = 0;
    for (auto d : dot) {
      auto cr = sqrt(pow(d.first-x, 2) + pow(d.second-y, 2));
      r = max(cr, r);
    }
    return r;
  };

  const double phi = (sqrt(5)+1)/2;
  auto min_range_x = [&](double x) {
    double l = 0, h = 1000;
    while (h-l > 0.0000001) {
      auto cl = (l*phi+h)/(phi+1);
      auto ch = (l+h*phi)/(phi+1);
      auto rl = min_range(x, cl);
      auto rh = min_range(x, ch);
      if (rl > rh) {
        l = cl;
      } else {
        h = ch;
      }
    }
    return min_range(x, (l+h)/2);
  };
  double l = 0, r = 1000;
  double ans;
  while (r-l > 0.0000001) {
    auto cl = (l*phi+r)/(phi+1);
    auto cr = (l+r*phi)/(phi+1);
    auto rl = min_range_x(cl);
    auto rh = min_range_x(cr);
    if (rl > rh) {
      l = cl;
      ans = rh;
    } else {
      r = cr;
      ans = rl;
    }
  }
  cout << fixed << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define int long long
#define ld long double
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pll pair<long long ,long long >
#define ppll pair < pll , pll >
#define endl "\n"
#define mod 1000000007
unsigned int bp(int n) // built_in_pop_count // 
{ 
    unsigned int count = 0; 
    while (n) { 
        n &= (n - 1); 
        count++; 
    } 
    return count; 
} 
int32_t main(){
    SPEED;
    char c;
    cin >> c;
    if(c >= 65 && c <= 91) cout << 'A' ;
    else cout << 'a';
}

Measured memory_bytes: 3636
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <cctype>

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<long, long>;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
#define rep(i, n) for(int i = 0; i<n; i++)
#define rep_s(i, start, n) for(int i= start;  i<n; i++)
#define rep_down(i, n) for(int i = n-1; i>=0; i--)
#define rep_down_s(i, n, start) for(int i = n-1; i>=start; i--)
#define ALL(a) (a).begin(), (a).end()
#define ALL_str(a) (a).cbegin(), (a).cend()

string alphabet_upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
string alphabet_lower  = "abcdefghijklmnopqrstuvwxyz";
string numbers = "0123456789";

/*
using edge = struct {int to; ll cost;};
vector<edge> tree[limit];
ll depth[limit];

void dfs(int v, int p, ll d){
  depth[v] = d;
  //cout <<"v: " << v << endl;
  for (auto &e: tree[v]){
    //cout << "e.to: " << e.to << endl;
    if (e.to == p) continue;
    dfs(e.to, v, d+e.cost);
  }
}
*/
int keta_sum(int num){
  int dig, sum = 0;
  while(num){
    dig = num % 10;
    sum = sum + dig;
    num = num / 10;
  }
  return sum;
}

ll binary_search(ll left_key, ll border, ll low, ll high) {
     // 配列 a の左端と右端
    ll mid = (low+high)/2;
    while (high > low+1) {
       mid = (low+high)/2;
        if (left_key*mid>border) high = mid;
        else if (left_key*mid<border) low = mid;
        else {
          mid =mid-1;
          break;
        }
    }
    return mid;
}

bool IsPrime(ll a){
  ll b = sqrt(a);
  b++;
  while(b-->=2){
    if (a%b==0) return false;
  }
  return true;
}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

int main(void){
  ll N, M, A, B, C, D, K,W, H, Q, X, Y;
  ll ans;
  string S, T;
  cin >> N;
  cin >> S;
  ll west_count =0, east_count = 0;
  rep(i, S.length()){
    if (S[i] =='W') west_count++;
    //else east_count++;
  }
  ans = 0; east_count=0;
  rep(i, S.length()){
    if (S[i] == 'W'){
      west_count--;
      ans = max(ans, west_count+east_count);
    }
    else {
      ans = max(ans, west_count+east_count);
      east_count++;
    }
    //cout <<"ans: " << ans << endl;
  }
  cout << N - ans -1 << endl;

}


Measured memory_bytes: 900
#include<vector>
#include<list>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i;
  int n;
  vector<int> c;
  list<int> l;
  for(;;){
    cin>>n;
    if(n==0)
      break;
    l.clear();
    for(i=1;i<n;i++){
      l.remove(i*i%n);
      l.push_back(i*i%n);
    }
    c.assign(n/2+1,0);
    list<int>::iterator it=l.begin();
    for(;it!=l.end();it++){
      list<int>::iterator jt=l.begin();
      for(;jt!=l.end();jt++){
	if(*it!=*jt){
	  int a;
	  a=*it-*jt;
	  if(a<0)
	    a+=n;
	  if(a>n/2)
	    a=n-a;
	  c[a]++;
	}
      }
    }
    for(i=1;i<n/2+1;i++)
      cout<<c[i]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1004
#include <stdio.h>
#include <string.h>
#include <math.h>
int main(void){
  int n;
  scanf("%d",&n);
  char s[n];
  int ans=0;
  int i;
  
    scanf("%s",s);
  
  for(i=0;i<=n-3;i++){
    if(s[i]=='A' &&s[i+1]=='B' &&s[i+2]=='C'){
      ans++;
    }
  }
  printf("%d",ans);
  return 0;
}

Measured memory_bytes: 1704
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int a,b,c,x;
    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&x);
    int ans=0;
    for(int i=0;i<=40;i++)
    {
        for(int j=0;j<=200;j++)
        {
            for(int k=0;k<=400;k++)
            {
                if(i*500+j*100+k*50==x && i<=a && j<=b && k<=c)
                    ans++;
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

int gcd(int x, int y)
{
    if (x < y) swap(x, y);
    if (y == 0) return x;
    return gcd(y, x % y);
}

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

    int A, B, K;
    cin >> A >> B >> K;

    int C = gcd(A, B);
    int ans;
    for (int div = C; div >= 1 && K > 0; --div)
    {
        if (C % div == 0)
        {
            --K;
            if (K == 0) ans = div;
        }
    }

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



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define P pair<int,int>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define pb push_back
template<class T>void chmax(T &a,T b){if(a<b)a=b;}
template<class T>void chmin(T &a,T b){if(a>b)a=b;}
constexpr int INF=1000000000000000000;
constexpr int mod=1000000007;
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};
int kaijo[2000010];
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int lcm(int a,int b){
    return a/gcd(a,b)*b;
}
bool prime(int a){
    if(a==1)return false;
    for(int i=2;i*i<=a;i++){
        if(a%i==0)return false;
    }
    return true;
}
void init_fact(){
    kaijo[0]=1;
    for(int i=1;i<=2000000;i++){
        kaijo[i]=kaijo[i-1]*i;
        kaijo[i]%=mod;
    }
}
int modpow(int a,int b){
    if(b==0)return 1;
    if(b%2)return modpow(a,b-1)*a%mod;
    int memo=modpow(a,b/2);
    return memo*memo%mod;
}
int comb(int a,int b){
    if(!kaijo[0])init_fact();
    return kaijo[a]*modpow(kaijo[a-b],mod-2)%mod*modpow(kaijo[b],mod-2)%mod;
}
int inv(int x){
    x=modpow(x,mod-2);
    return x;
}
bool kosa(double ax,double ay,double bx,double by,double cx,double cy,double dx,double dy){
    double ta=(cx-dx)*(ay-cy)+(cy-dy)*(cx-ax);
    double tb=(cx-dx)*(by-cy)+(cy-dy)*(cx-bx);
    double tc=(ax-bx)*(cy-ay)+(ay-by)*(ax-cx);
    double td=(ax-bx)*(dy-ay)+(ay-by)*(ax-dx);
    return tc*td<0&&ta*tb<0;
}
int n,m,dp[1010][1010];
char c[1010][1010];
signed main(){
    cin>>n>>m;
    rep(i,n)rep(j,m)cin>>c[i][j];
    dp[0][0]=1;
    rep(i,n){
        rep(j,m){
            if(c[i+1][j]=='.'){
                dp[i+1][j]+=dp[i][j];
                dp[i+1][j]%=mod;
            }
            if(c[i][j+1]=='.'){
                dp[i][j+1]+=dp[i][j];
                dp[i][j+1]%=mod;
            }
        }
    }
    cout<<dp[n-1][m-1]<<endl;
    return 0;
}

Measured memory_bytes: 10496
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <iostream>
using namespace std;
const int MAXN = 1e5 + 5;
typedef long long LL;
LL cnt[MAXN];
LL n,k,a,b,sum;
int main()
{
    int flag = 0;
    cin >> n >> k;
    for(int i = 1; i <= n; i++){
        scanf("%lld%lld",&a,&b);
        cnt[a] += b;
    }
    LL ans = 0;
    for(int i = 1; i <= 100000; i++){
        ans += cnt[i];
        if(ans >= k) {
            sum = i;
            flag = 1;
            break;
        }
    }
    cout << sum;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

int main(){
    int n, a, b;    cin >> n >> a >> b;
    cout << min(a,b) << " " << max(a+b-n,0) << endl;
    return 0;
}

Measured memory_bytes: 3588
#include <stdio.h>
#include <ctype.h>
#include <string.h>
 
int main(void){
    char W[11],T[1000];
    int i,count=0;
     
    scanf("%s",W);
    while(scanf("%s",T),strcmp(T,"END_OF_TEXT")){
        for(i=0;T[i]!='\0';i++){
            T[i]=tolower(T[i]);
        }
         
        if(strcmp(W,T)==0) count+=1;
    }
     
    printf("%d\n",count);
     
    return 0;
}


Measured memory_bytes: 2108
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

ll DP[4005][4005];
ll w[4005];
ll KDP[4005][4005];

int main() {
    int N;
    cin>>N;
    for(int i=1;i<=N;++i){
        cin>>w[i];
    }
    for(int i=1;i<=N;++i){
        w[i] += w[i-1];
    }
    for(int i=0;i<N-1;++i){
        KDP[i][i+2] = i+1;
        DP[i][i+2] = w[i+2]-w[i];
    }
    int r;
    int k;
    for(int i=3;i<=N;++i){
        for(int l=0;l<=N-i;++l){
            r = l + i;
            DP[l][r] = big;
            for(int j=KDP[l][r-1];j<=KDP[l+1][r];++j){
                if(DP[l][r]>w[r]-w[l]+DP[l][j]+DP[j][r]) {
                    DP[l][r] = w[r]-w[l]+DP[l][j]+DP[j][r];
                    KDP[l][r] = j;
                }
            }
        }
    }
    cout<<DP[0][N]<<endl;
}




Measured memory_bytes: 158008
#include <cstdio>

int H, W, d;
char c[4] = {'R', 'Y', 'G', 'B'};

int main() {
  scanf("%d %d %d", &H, &W, &d);
  for (int i = 1; i <= H; i++) {
    for (int j = 1; j <= W; j++) {
      int x = (i + j + W) / d % 2;
      int y = (i - j + W) / d % 2;
      putchar(c[x * 2 + y]);
    }
    puts("");
  }
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a = 0, un = 0;
    bool ok = true;
    for(int i=0;i<n;++i){
        string s;
        cin >> s;
        if(s == "A")a++;
        else un++;
        if(a < un) ok = false;
    }
    if(ok && a == un) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

#define ll long long
#define ld long double
#define pq priority_queue
#define ff first
#define ss second
#define pb push_back
#define pb push_back
#define all(c) (c).begin(), (c).end()
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define MOD1 998244353
#define MOD2 1000000007

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<vii> vvii;


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

    ll n;
    cin>>n;
    ll a[n],b[n],c[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }

    int dp[3][n];
    dp[0][0] = a[0];
    dp[1][0] = b[0];
    dp[2][0] = c[0];

    for(int i=1;i<n;i++)
    {
        dp[0][i] = a[i]+max(dp[1][i-1],dp[2][i-1]);
        dp[1][i] = b[i]+max(dp[0][i-1],dp[2][i-1]);
        dp[2][i] = c[i]+max(dp[0][i-1],dp[1][i-1]);
    }

    cout<<max(max(dp[0][n-1],dp[1][n-1]),max(dp[1][n-1],dp[2][n-1]))<<endl;

}


Measured memory_bytes: 3840
def solve():
    N = int(input())
    counter = [0] * 5
    for _ in range(N):
        S = input()
        if S[0] == 'M':
            counter[0] += 1
        elif S[0] == 'A':
            counter[1] += 1
        elif S[0] == 'R':
            counter[2] += 1
        elif S[0] == 'C':
            counter[3] += 1
        elif S[0] == 'H':
            counter[4] += 1
    
    ans = 0
    for i in range(3):
        for j in range(i + 1, 4):
            for k in range(j + 1, 5):
                ans += counter[i] * counter[j] * counter[k]
    print(ans)


if __name__ == '__main__':
    solve()


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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()

string res[6] = {"abcde", "fghij", "klmno", "pqrst", "uvwxy", "z.?! "};

const char OFS = '1';
int main()
{
    string s;
    while(getline(cin, s))
    {
        bool na = false;
        int l = s.size();

        if(l%2) na = true;
        s = s + "z";
        REP(l/2)
        {
            if(s[i * 2] >= '7' || s[i*2] == '0') na = true;
            if(s[i * 2 + 1] >= '6' || s[i*2] == '0') na = true;
        }
        if(na){ cout << "NA" << endl; continue;}
        
        REP(l/2) cout << res[(char)(s[i*2] - OFS)][(char)(s[i*2+1] - OFS)];
        cout << endl;

    }
    return 0;
}

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

#define FASTIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
using ll = long long;

int main(){
	FASTIO
	ll n, d;
	cin >> n >> d;
	d = d * d;
	ll c = 0;
	for (int i= 0 ; i < n ; i++){
		ll a, b;
		cin >> a >> b;
		a = a * a + b * b;
		if(a <= d)
			c++;
	}
	cout << c << endl;
}

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

namespace Atcoder
{
    class Atcoderrrrrrr
    {
        static void Main(string[] args)
        {
            int[] s = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            if(s[0]+s[1]>=10){
                Console.WriteLine("error");
            }else{
                Console.WriteLine(s[0]+s[1]);
            }
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#define MOD 1000000007
#define mkp make_pair
typedef long long ll;
using namespace std;

int main(){
  int A,B,C;
  cin>>A>>B>>C;

  if(A-B>=C) cout<<0<<endl;
  else cout<<C-(A-B)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
vector<int> A(20);
bool solve(int i, int r){
    if(r == 0)
    return true;
    if(i < 0)
    return false;
    bool res = solve(i - 1, r) || solve(i - 1, r - A[i]);
    return res;
 }

int main(){
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }
    int q,r;
    cin >> q;

    for(int i = 0; i < q; i++){
        cin >> r;
        if(solve(n - 1, r))
            cout << "yes" << endl;
        else
        {
            cout << "no" << endl;
        }
    }

}



Measured memory_bytes: 3076
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
using namespace std;
typedef long long ll;
int INF = (1LL << 30) - 1;
int MOD = 1e9+7;
main(){
    int N,M,Q;
    cin >> N >> M >> Q;
    int cnt[N+1][N+1];
    rep(i,0,N+1)rep(j,0,N+1)cnt[i][j] = 0;
    rep(i,0,M){
        int l,r;
        cin >> l >> r;
        cnt[l-1][r-1]++;
    }
    rep(i,0,N)rep(j,1,N)cnt[i][j] += cnt[i][j-1];
    rep(j,0,N)for(int i = N-2;i >= 0;i--)cnt[i][j] += cnt[i+1][j];
    rep(i,0,Q){
        int sum = 0;
        int l,r;
        cin >> l >> r;
        l--,r--;
        cout << cnt[l][r] << endl;
    }
}

Measured memory_bytes: 1920
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define ll unsigned long long
using namespace std;
int main(){
    int N,D,ans=0;cin>>N>>D;
    for(;;){
        if(N<=ans*(2*D+1))break;
        ans++;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<bitset>
#include<iomanip>
using namespace std;
const int inf = 1001001000;

void print(vector<vector<int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

int main(){
	long long int a,b,k; cin >> a >> b >> k;
	long long int taka = a - k;
	long long int ao = b + ((0 > taka) ? taka : 0);
	cout << ((0 < taka) ? taka : 0) << " " << ((0 < ao) ? ao : 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <complex>
#include <vector>
#include <limits>
#include <iomanip>
#include <cassert>

using namespace std;

typedef long long ll;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;

#define debug(x) cout << #x << " = " << (x) << endl;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n-1;i >= 0;i--)
#define pb push_back
#define mp make_pair
#define F first
#define S second

const long double pi = 3.141592653589793;
const int mod = 1e9 + 7;


int main() {

 // freopen("input.in","r",stdin);
 // freopen("output.out","w",stdout);

 ios_base::sync_with_stdio(false);
 cin.tie(NULL);

  int X;cin>>X;
  cout<<(2000-X-1)/200 + 1<<endl;













 return 0;
}


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

#define full(x,n) x,x+n+1
#define full(x) x.begin(),x.end()
#define finish return 0

#define putb push_back
#define f first
#define s second

#define putf push_front
#define gainb pop_back

#define gainf pop_front
#define len(x) x.size()

// 1/b%mod=b^(m-2)%mod

typedef double db;
typedef long long ll;

const ll ary=5e5+5;
const ll inf=1e18;

using namespace std;
ll n;
int main(){
	cin>>n;
	double c=0;
	for(int i=1;i<=n;i++){
		if(i%2){
			c++;
		}
	}
	cout<<fixed<<setprecision(10)<<double(c/n);
}

Measured memory_bytes: 256
using System;
using System.Linq;

class E
{
	static long[] Read() => Console.ReadLine().Split().Select(long.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int x = (int)h[0], y = (int)h[1];
		var a = Read();
		var b = Read();
		var c = Read();

		var rg = a.OrderBy(v => -v).Take(x).Concat(b.OrderBy(v => -v).Take(y)).OrderBy(v => -v).ToArray();
		var w = c.OrderBy(v => -v).Take(x + y).Concat(new long[Math.Max(0, x + y - h[4])]).Reverse().ToArray();
		Console.WriteLine(Enumerable.Range(0, x + y).Sum(i => Math.Max(rg[i], w[i])));
	}
}


Measured memory_bytes: 54052
#include <cstdio>
#include <algorithm>
#define INF -1000000001
using namespace std;
int N, F[100][5][2], P[100][11], s[10] = {0};
int rec(int p) {
  if(p > 10) {
    int sum = 0, m[100] = {0};
    for(int i = 0; i < N; i++) {
      for(int j = 0; j < 10; j++) {
        if(!s[j]) continue;
        m[i] += F[i][j/2][j%2];
      }
      sum += P[i][m[i]];
    }
    int t = 0;
    for(int i = 0; i < 10; i++) t += s[i];
    if(!t) return INF;
    return sum;
  }
  s[p] = 0; int sum0 = rec(p+1);
  s[p] = 1; int sum1 = rec(p+1);
  return max(sum0, sum1);
}
int main() {
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 10; j++) scanf("%d", &F[i][j/2][j%2]);
  }
  for(int i = 0; i < N; i++) {
    for(int j = 0; j < 11; j++) scanf("%d", &P[i][j]);
  }
  printf("%d", rec(0));
}

Measured memory_bytes: 128
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author anand.oza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        ADigitSum2 solver = new ADigitSum2();
        solver.solve(1, in, out);
        out.close();
    }

    static class ADigitSum2 {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            long n = in.nextLong();

            long ans = 0;
            boolean subtractOne = false;
            while (n >= 10) {
                if (n % 10 != 9) {
                    subtractOne = true;
                }
                ans += 9;
                n /= 10;
            }
            ans += n;
            if (subtractOne) {
                ans--;
            }

            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



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

int main() {
  int P,Q,R;
  int A,B,C,ans;
  cin >> P >> Q >> R;
  A=P+Q;
  B=Q+R;
  C=R+P;
  ans = A;
  if(B < ans)
    ans = B;
  if(C < ans)
    ans = C;
   cout << ans << endl;
}

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

int main(){
  string S;
  cin >>S;
  int a=0,b=1,c=0;
  if(S[0]=='A'){
    a=1;
  }
  for(int i=1;i<S.size();i++){
    if(islower(S[i])){
    }
    else if(S[i]=='C'){
      if(i<S.size()-1 && i>1)
      c++;
      else{
      c=0;
      }
    }
    else{
      b=0;
    }
  }
  if(a==1 && b==1 && c==1){
    cout << "AC" <<endl;
  }
  else{
    cout << "WA" <<endl;
  }
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
const int INF=1001001001;


//
vector<ll> a(105);
ll dp[100005];

int n;
int dfs(int x){
  if (dp[x]!=-1)return dp[x];
  ll now=-1;
  rep(i,n){
    if (x-a[i]<0)continue;
    if (dfs(x-a[i])==0) now=1;
  }
  if (now==1)dp[x]=1;
  else dp[x]=0;
  //cout<<dp[x]<<"x"<<x<<endl;
  return dp[x];
}

int main(){
  ll k;
  cin>>n>>k;
  rep(i,n){
    cin>>a[i];
  }
  rep(i,100005)dp[i]=-1;
  rep(i,a[0])dp[i]=0;
  ll ans=dfs(k);

  if (ans==1)cout<<"First";
  else cout<<"Second";
  return 0;

}


Measured memory_bytes: 10596
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include<limits.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define RALL(v) v.rbegin(),v.rend()
#define check(v) rep(i,v.size()) cout << v[i] << " ";\
cout << endl
#define INF 1e8
typedef long long ll;
using namespace std;
//オーバーフローに気をつけろよおおおおおお
//確認忘れるなよおおおおおお

int main() {
    int a,b; cin >> a >> b;
    cout << max(a+b,max(a-b,a*b)) << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		if(a < b) {
			System.out.println("a < b");
		}
		else if(a > b){
			System.out.println("a > b");
		}else {
			System.out.println("a == b");
		}
	}
}



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

static constexpr uint64_t D = 1000000007;

uint64_t fact(uint64_t a) {
    if (a == 0 || a == 1) {
        return 1;
    } else {
        return (a % D) * (fact(a - 1) % D) % D;
    }
}

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

    if (std::abs(N - M) > 1) {
        std::cout << 0 << std::endl;
        return 0;
    }

    uint64_t ans = (fact((uint64_t)(N)) % D) * (fact((uint64_t)(M)) % D) % D;
    if (N == M) {
        ans *= 2;
        ans %= D;
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

int main(void)
{
	int a, b, c, count;
	
	scanf("%d%d%d", &a, &b, &c);
	
	if((a == b && a == c) && b == c) {
		count = 1;
	}
	else if(a == b && a != c) {
		count = 2;
	}
	else if(a != b && a == c) {
		count = 2;
	}
	else if(a != b && b == c) {
		count = 2;
	}
	else {
		count = 3;
	}
	printf("%d", count);
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> b(n-1);
  rep(i, n-1) cin >> b[i];

  vector<int> a(n);
  rep(i, n) {
    if (i==0) {
      a[i] = b[i];
      continue;
    }
    a[i] = min(b[i-1], b[i]);
  }
  a[n-1] = b[n-2];
  int ans = 0;
  rep(i, n) ans += a[i];
  cout << ans << endl;
}


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

#define fastio 			ios::sync_with_stdio(0);	cin.tie(0); cout.tie(0);  cout<<fixed;  cout<<setprecision(12);
#define randomINT 		mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
#define	newl 			cout<<"\n"
#define DISP(as)		for(auto it : as) cout<<it<<" ";newl;
#define DISP1(as)		for(auto it : as) cout<<it.f<<" "<<it.s<<") ";newl;
#define all(x)         	(x).begin(),(x).end()
#define mset(x,val)    	memset(x,val,sizeof(x))
#define newl           	cout<<"\n"
#define pb             	push_back
#define mp             	make_pair
#define f 				first
#define s 				second
#define dline          cerr<<"///REACHED///\n";
#define deb1(x)        cerr<<#x<<" = "<<x<<'\n';
#define deb2(x,y)      cerr<<'['<<#x<<','<<#y<<"] = "<<'['<<x<<','<<y<<']'<<'\n';
#define deb3(x,y,z)    cerr<<'['<<#x<<','<<#y<<','<<#z<<"] = "<<'['<<x<<','<<y<<','<<z<<']'<<'\n';

typedef long long 				ll;
typedef long double 			ld;
typedef vector<ll> 				vll;
typedef pair<ll , ll> 			pll;
typedef pair<ld, ld> 			pld;
typedef unordered_map<ll, ll> 	um;
typedef vector<pll> 			vpll;

const ll 	MAX5 	= 	2e+5 + 99;
const ll 	MAX7 	= 	1e+7 + 7;
const ll 	MAXN 	= 	MAX7;
const ll   	INF   	=  	0x7f7f7f7f7f7f7f7f;
const int  	INFi 	=  	0x7f7f7f7f;
const ll 	MOD		=  	1e+9 + 7;

// <------------- Declare Variables Here ------------> //

ll T = 1;
ll n, k, l, q, x;
string s;

// <---------------------- > //



// <------------- Start of main() -------------------> //

void MAIN() {
	cin>>n;
	vll a(n+1);
	for(ll i=1;i<=n;i++) cin>>a[i];
	
	ll mini = INF;

	for(ll i=-100;i<=100;i++) {
		ll val = 0;
		for(ll j=1;j<=n;j++) val += (a[j]-i)*(a[j]-i);
		mini = min(mini,val);
		//cout<<i<<" "<<mini;newl;
	}

	cout<<mini;
}


int main() {
	fastio; randomINT;
	//cin >> T;
	while (T--) {

		MAIN();
	}
	return 0;
}


Measured memory_bytes: 3596
using System;

namespace ITP1_1_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int count = int.Parse(Console.ReadLine());
            string[] num = Console.ReadLine().Split();
            int min = int.Parse(num[0]), max = int.Parse(num[0]);
            long sum = long.Parse(num[0]);

            for (int i = 1; i < count; i++)
            {
                if (min >= int.Parse(num[i]))
                {
                    min = int.Parse(num[i]);
                }

                if (max <= int.Parse(num[i]))
                {
                    max = int.Parse(num[i]);
                }

                sum += int.Parse(num[i]);
            }
            Console.WriteLine(min + " " + max + " " + sum);
        }
    }
}



Measured memory_bytes: 16132
#include<stdio.h>

void temp(int *a, int *b);

int main()
{
	int a, b, c, d;
	scanf("%d%d%d%d", &a, &b, &c, &d);

	if (b > d)
	{
		temp(&a, &c);
		temp(&b, &d);
	}

	if (b < c)
		printf("0\n");
	else if (b >= c&&a <= c)
		printf("%d\n", b - c);
	else if (c < a)
		printf("%d\n", b - a);

	return 0;
}

void temp(int *a, int *b)
{
	int temp = *a;
	*a = *b;
	*b = temp;
}

Measured memory_bytes: 128