akhauriyash/Code-Regression huggingface dataset:
class SkewHeap
  def push(t, d)
    @root = meld(@root, Node.new(t, d))
  end
  def empty?
    @root == nil
  end
  def pop
    res = [@root.t, @root.d]
    @root = meld(@root.lchild, @root.rchild)
    res
  end
  def meld(lhs, rhs)
    return lhs unless rhs
    return rhs unless lhs
    lhs, rhs = rhs, lhs unless lhs.d < rhs.d
    lhs.rchild = meld(lhs.rchild, rhs)
    lhs.lchild, lhs.rchild = lhs.lchild, lhs.rchild
    lhs
  end
  class Node
    attr_accessor :t, :d, :lchild, :rchild
    def initialize(t, d)
      @t, @d = t,d
    end
  end
end

N,K=gets.split.map(&:to_i)
S=N.times.map{gets.split.map(&:to_i)}
H=Hash.new{|h,k|h[k]=0}
Q=SkewHeap.new
ans=s=k=x=0
S.sort{|l,r|r[1]<=>l[1]}.each do |t, d|
  if k<K
    Q.push(t,d)
    s+=d
    s-=x*x
    k+=1
    x+=1 if H[t].zero?
    s+=x*x
    H[t]+=1
  else
    until Q.empty?
      qt,qd=Q.pop
      next if H[qt]==1
      next if qt==t
      H[qt]-=1
      s-=qd
      Q.push(t,d)
      s+=d
      s-=x*x
      x+=1 if H[t].zero?
      s+=x*x
      H[t]+=1
      break
    end
  end
  ans=[ans,s].max
end
p ans


Measured memory_bytes: 24808
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<map>
#include <algorithm>
#include<cstdlib>
#include<cmath>
#include<deque>
#include <numeric>
typedef unsigned long long ll;

int main() {
	std::vector<ll> A(4);
	ll flgA = 0;
	for (int i = 0; i < 3; i++)
	{
		ll X , Y;
		std::cin >> X >> Y;
		if (X == Y) { flgA = 1; }
		A[X-1]++;
		A[Y-1]++;

	}
	for (int i = 0; i < 4; i++)
	{
		if (A[i] > 2)flgA = 1;
	}

	if (flgA == 0)
	{
		std::cout << "YES" << std::endl;

	}
	else
	{
		std::cout << "NO" << std::endl;
	}
	return 0;
}

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

int main(void) {
  int N, K, R, S, P;
  cin >> N >> K >> R >> S >> P;
  string T;
  cin >> T;

  

  ll ans = 0;
  vector<int> vc(N, 0);
  int now = 1;
  for (int i = 0; i < N - K; i++) {
    if (T[i] == T[i + K]) {
      if (vc[i] == 0) {
        vc[i] = now;
        vc[i + K] = now;
        now++;
      }
      else {
        vc[i + K] = vc[i];
      }
    }
  }

  map<pair<int, char>, int> mp;

  rep (i, N) {
    if (vc[i] == 0) {
      if (T[i] == 's') ans += R;
      if (T[i] == 'r') ans += P;
      if (T[i] == 'p') ans += S;
    }
    else {
      mp[make_pair(vc[i], T[i])]++;
    }
    //cout << vc[i];
    
  }

  for (auto x: mp) {
    int num, cnt; char c;
    tie(num, c) = x.first;
    cnt = x.second;
    if (c == 'r') {
      if (cnt % 2 == 0) {
        ans += (cnt / 2) * P;
      }
      else {
        ans += (cnt / 2 + 1) * P;
      }
    }
    if (c == 's') {
      if (cnt % 2 == 0) {
        ans += (cnt / 2) * R;
      }
      else {
        ans += (cnt / 2 + 1) * R;
      }
    }
    if (c == 'p') {
      if (cnt % 2 == 0) {
        ans += (cnt / 2) * S;
      }
      else {
        ans += (cnt / 2 + 1) * S;
      }
    }
  }

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


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

using namespace std;
#define ll long long
int main(){
    int ans=0;
    int a[3];
    cin >>a[0] >> a[1]>>a[2];
    sort(a,a+3);
    ans=abs(a[0]-a[2]);
    cout <<ans<<endl;
    return 0;
}

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

using namespace std;


int main() {
    int A, B, C, X;
    int cnt = 0;
    cin >> A >> B >> C >> X;
    for (int a=0; a<=A; a++) {
        for (int b=0; b<=B; b++) {
            for (int c=0; c<=C; c++) {
                if (500*a+100*b+50*c == X) cnt++;
            }
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <cassert>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

vector<string> split(string s, string t) {
	vector<string> ret;
	for(int i=0, n; i<=s.length(); i=n+1) {
		n = s.find_first_of(t, i);
		if(n == -1) n = s.length();
		string tmp = s.substr(i, n-i);
		ret.push_back(tmp);
	}
	return ret;
}

set<vector<string> > se;
set<vector<string> > dir;
set<vector<string> > file;

bool func(string &s) {
  vector<string> vs = split(s, "/");
  vector<string> res;
  //cout << s << endl;
  REP(i, vs.size()) {
    if (i && vs[i] == "") break;
    //cout << vs[i] << ":";
    if (vs[i] == ".") ;
    else if (vs[i] == "..") {
      if (dir.count(res) == 0) return 1;
      res.pop_back();
    }
    else res.push_back(vs[i]);
    if (se.count(res) == 0) return 1;
  }
  //cout << "OK" << endl;
  //cout << endl;
  if (vs[vs.size()-1]=="" || dir.count(res)) {
    res.push_back("index.html");
    //if (se.count(res) == 0) return 1;
  }
  if (file.count(res) == 0) return 1;
  s.clear();
  REP(i, res.size()) {
    if (i) s += "/";
    s += res[i];
  }
  // cout << s << endl;
  return 0;
}

int main() {
  int n,m;
  while(cin>>n>>m,n||m) {
    se.clear();
    dir.clear();
    file.clear();
    REP(i, n) {
      string s;
      cin >> s;
      vector<string> vs = split(s, "/");
      vector<string> tmp;
      REP(i, vs.size()) {
        tmp.push_back(vs[i]);
        se.insert(tmp);
        if (i != vs.size()-1)
          dir.insert(tmp);
        else
          file.insert(tmp);
      }
    }
    REP(i, m) {
      string s, t;
      cin >> s >> t;

      if (func(s) || func(t)) {
        cout << "not found" << endl;
      } else {
        if (s==t)
          cout << "yes" << endl;
        else
          cout << "no" << endl;
      }
    }
  }
}

Measured memory_bytes: 0
//                             In The Name Of Allah                                           
//                             	Mohammad Hosseini
#include <bits/stdc++.h>
#define	ss second
#define ff first
#define use_fast ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ret(n) return cout << n, 0
#define se(n) cout << setprecision(n) << fixed
#define pb push_back
#define int long long
#define ld long double
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC optimize("no-stack-protector,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std; 

const int N = 1e5 + 100, OO = 1e9, T = 4500 + 100, M = 924844033, P = 6151, SQ = 280, lg = 30;
typedef pair <int, int> pii;
bool is[N];
int cnt[N];

int32_t main() {
	use_fast;
	int a, b;
	cin >> a >> b;
	if(a <= 0 && b >= 0)
		return cout << "Zero" << endl, 0;
	if(a > 0) 
		return cout << "Positive" << endl, 0;
	a *= -1, b *= -1;
	if((a - b) % 2 == 1)
		cout << "Positive" << endl;
	else
		cout << "Negative" << endl;
	return 0;
}
/*
be carefull :
1- if not solve after 20 min, read again twice
2- after submit read the code again
3- fun with contest
4- uploaded by ubuntu 20.04 
5- ...
*/



Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; (i) < ((int)(n)); ++(i))
const ll INF = 1e10;
const ll MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<vector<int>> D(N, vector<int>(2));
    rep(i, N) cin >> D[i][0] >> D[i][1];
    int Count = 0;
    rep(i, N) {
        if(D[i][0] == D[i][1])
            Count++;
        else
            Count = 0;

        if(Count >= 3) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}

Measured memory_bytes: 3620
// Gaurav Aggarwal
 
#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 vector<pii > vii;
typedef vector<pll > vll;
#define pb push_back
#define mp make_pair 
#define mod 1000000007
#define F first
#define S second
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define debug_arr(a,n) {{for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}cout<<"\n";}}
 
ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    ll n;
    cin>>n;
    // cout<<n<<"\n";
    if(n&1 or n < 10) cout<<0<<"\n";
    else {
        ll ans = 0;
        ll x = 10;
        ll y = 50;
        while(x <= n) {
            ans += n/x;
            // cout<<n/x<<"\n";
            x*=10;
        }
        ll z = 100;
        // cout<<ans<<"\n";
        while(y <= n) {
            ans += n/y;
            // cout<<n/y<<" "<<y<<" ";
            y*=5;
            ans -= n/z;
            if(n/z != 0) {
                // cout<<n/z<<" "<<z<<"\n";
                z*=10;
            }
            
        }
        // ans += n/100;
        cout<<ans<<"\n";
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define sz 300009
#define mod 998244353
ll m,aa,bb,cc,d,n,arr[sz],i,k,j,x,y,l;
ll brr[sz],vis[sz];
long long binpow(long long a,long long b){
  if(b<=0)
    return 1;
  long long res=binpow(a,b/2)%mod;
if(b%2){
    return ((((res%mod)*(res%mod))%mod)*a)%mod;
}
else
    return (res*res)%mod;
}
int main()
{
scanf("%lld %lld %lld",&n,&m,&k);
bb=1;
j=1;
for(i=n;i>=n-k;i--)
{
cc=binpow(m-1,i-1)*m;
cc%=mod;
cc*=bb;
cc%=mod;
bb*=(i-1);
bb%=mod;
bb*=binpow(j,mod-2);
bb%=mod;
aa+=cc;
aa%=mod;
j++;
}
printf("%lld\n",aa);
return 0;
}


Measured memory_bytes: 3832
function Main(input){
var tmp = input.split(' ');
var a = parseInt(tmp[0],10);
var b = parseInt(tmp[1],10);


console.log(parseInt((a*3 + b)/2));
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

#define SIZE 300005
#define MOD 1000000007LL
#define INF 1 << 30
#define LLINF 1LL << 60
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define FORALL(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define FOREACH(i,c) for(auto (i) : (c))
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef long long ll;
typedef valarray<int> Array;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cout<<a[i];if(i==a.size()-1)cout<<endl;else cout<<" ";}}
int gcd(int a,int b){int c=max(a,b);int d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
int lcm(int a,int b){return a==0||b==0?0:a*b/gcd(a,b);}

int W, N;
int v[1010];
int w[1010];

void solve()
{
  int dp[1010];
  fill_n(dp,1010,0);
  REP(i,N) DOWN(j,W,w[i])
    dp[j] = max(dp[j],dp[j-w[i]]+v[i]);
  int ans1 = 0, ans2 = 0;
  DOWN(i,W,0) if(ans1 <= dp[i])
  {
    ans1 = dp[i];
    ans2 = i;
  }
  printf("%d\n%d\n",ans1,ans2);
}

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

  for(int c = 1; scanf("%d",&W), W; c++)
  {
    scanf("%d",&N);
    REP(i,N) scanf("%d,%d",&v[i],&w[i]);
    printf("Case %d:\n",c);
    solve();
  }
  return 0;
}

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

using namespace std;

class StronglyConnectedComponentDecomposition
{
private:
	int V; // ????????°
	vector<vector<int>> G; // ??°???????????£??\???????????¨???
	vector<vector<int>> rG; // ?????????????????????????????°??????
	vector<int> vs; // ??°?????????????????????
	vector<bool> used; // ?????§???????????????

	void dfs( int v ) {
		used[v] = true;
		for( int i = 0; i < G[v].size(); i++ ) {
			if( !used[G[v][i]] ) dfs( G[v][i] );
		}
		vs.push_back( v );
	}
	void rdfs( int v, int k ) {
		used[v] = true;
		cmp[v] = k;
		for( int i = 0; i < rG[v].size(); i++ ) {
			if( !used[rG[v][i]] ) rdfs( rG[v][i], k );
		}
	}

public:
	vector<int> cmp; // ?±????????????£????????????????????????????????????
	StronglyConnectedComponentDecomposition( int N = 0 ) {
		V = N;
		G = vector<vector<int>>( V );
		rG = vector<vector<int>>( V );
		used = vector<bool>( V );
		cmp = vector<int>( V );
	}
	void add_edge( int from, int to ) {
		G[from].push_back( to );
		rG[to].push_back( from );
	}
	
	int scc() {
		used = vector<bool>( V );
		vs.clear();
		for( int v = 0; v < V; v++ ) {
			if( !used[v] ) dfs( v );
		}
		used = vector<bool>( V );
		int k = 0;
		for( int i = vs.size() - 1; i >= 0; i-- ) {
			if( !used[vs[i]] ) rdfs( vs[i], k++ );
		}
		return k;
	}
};

int main() {
	long long int V, E;
	cin >> V >> E;
	StronglyConnectedComponentDecomposition SCCD( V );
	for( size_t i = 0; i < E; i++ ) {
		int s, t;
		cin >> s >> t;
		SCCD.add_edge( s, t );
	}
	SCCD.scc();
	long long int N;
	cin >> N;
	for( size_t i = 0; i < N; i++ ) {
		int u, v;
		cin >> u >> v;
		cout << (SCCD.cmp[u] == SCCD.cmp[v]) << endl;
	}
	return 0;
}

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007LL

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll A, B;
    cin >> A >> B;
    if(B % A == 0) cout << A + B;
    else cout << B - A;
    cout << endl;
    return 0;
}


Measured memory_bytes: 3604
#!/usr/bin/env python3
import sys


def solve(N: int, R: int):
    if N >= 10:
        print(R)
    if N < 10:
        print(R + 100*(10-N))
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    R = int(next(tokens))  # type: int
    solve(N, R)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    S = list(map(int, input().split()))

    ans = 0
    # C = A - B
    for C in range(1, N//2):
        n = (N-1) // C
        point = 0
        for k in range(1, n):
            A = N-1 - k*C

            # Check A and B are positive integer, and S_i is not used twice.
            #
            # B = A - C and B >= 0, so A must be over C (A > C).
            #
            # If C is aliquot of N-1 (N-1 % C = 0), A is also aliquot of N-1
            # (N-1 % A = 0) because A + kC = N-1. Therefore when A is less than
            # or equal kC, the A's value is already used by kC.
            if A < C or ((N-1) % C == 0 and A <= k*C):
                break

            point += S[A] + S[k*C]
            ans = max(ans, point)

    return ans


if __name__ == '__main__':
    print(main())


Measured memory_bytes: 14388
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vin=vector<int>;
using vll=vector<long long>;
using vstr=vector<string>;
#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++)
#define _GLIBCXX_DEBUG
int main()
{
    int n;
    cin>>n;
    string s;
    cin>>s;
    int d=s.size();
    bool can=true;
    if(d%2==0){
        rep(i,d/2){
            if(s[i]!=s[i+d/2]){
                can=false;
                break;
            }
        }
    }
    else can=false;
    if(can)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.buffer.readline

class UnionFind:
    __slots__ = ["data"]
    
    def __init__(self, n=0):
        self.data = [-1]*(n+1)
    
    def root(self, x):
        if self.data[x] < 0:
            return x
        self.data[x] = self.root(self.data[x])
        return self.data[x]
    
    def unite(self, x, y):
        x = self.root(x)
        y = self.root(y)
        if x != y:
            if self.data[x] < self.data[y]:
                self.data[x] += self.data[y]
                self.data[y] = x
            else:
                self.data[y] += self.data[x]
                self.data[x] = y
    
    def same(self, x, y):
        return self.root(x) == self.root(y)
    
    def size(self, x):
        return -self.data[self.root(x)]
                


def main():
    n, m, k = map(int, input().split())
    fb = [0]*(n+1)
    uf = UnionFind(n)
    for _ in range(m):
        a, b = map(int, input().split())
        fb[a] += 1
        fb[b] += 1
        uf.unite(a, b)
    for _ in range(k):
        c, d = map(int, input().split())
        if uf.same(c, d):
            fb[c] += 1
            fb[d] += 1
    ans = [uf.size(i)-1-nfb for i, nfb in enumerate(fb[1:], 1)]
    print(" ".join(list(map(str, ans))))


if __name__ == "__main__":
    main()

Measured memory_bytes: 15480
#include<iostream>
using namespace std;
int main(){

	int a,b,c;
	
	
	cin>>a>>b>>c;
	
	if(a==b && b==c){
	cout<<1<<endl;
	}else if(a!=b && b!=c && c!=a){
	cout<<3<<endl;
	}else{
	cout<<2<<endl;
	}
	
	
return 0;

}



Measured memory_bytes: 256
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    O=STR()
    E=STR()
    ans=[]
    ol=len(O)
    el=len(E)
    if ol-el==0:
        for i in range(ol):
            ans.append(O[i])
            ans.append(E[i])
    else:
        for i in range(el):
            ans.append(O[i])
            ans.append(E[i])
        ans.append(O[-1])
    print(*ans,sep='')
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define lc 2 * v
#define rc 2 * v + 1
#define mid (s + e) / 2
#define ll long long
#define ld long double
#define pii pair <int , int>
#define pll pair <long long , long long>
#define FAST ios::sync_with_stdio(false);cin.tie(0);
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")

const ll maxn = 1e5 + 10 , N = 1e5 , mod = 1e9 + 7 , INF = 1e13 , MAAX = 1e18 , lg = 18;

int n;
string s , t;

inline bool check(int k) {
    int currK = 0 , currN = 0 , nxt = 0 , p = 9 * k , sum = 0;
    for (int i = n - 1; i >= 0; --i) {
        currN = s[i] - '0';
        currK = p % 10;
        // cout << currN << ' ' << currK << ' ' << nxt << endl;
        if(currN + currK + nxt > 9) {
            sum += (currN + currK + nxt) % 10;
            nxt = (currN + currK + nxt) / 10;
        }
        else {
            sum += (currN + currK + nxt);
            nxt = 0;
        }
        p /= 10;
    }
    return (sum <= 9 * k);
}

inline void convert_N_to_9N() {
    int nxt = 0;
    for (int i = n - 1; i >= 0; --i) {
        int currN = s[i] - '0';
        currN *= 9; currN += nxt;
        nxt = currN / 10; currN %= 10;
        t += (char)('0' + currN);
    }
    if(nxt) {t += (char)('0' + nxt);}
    reverse(t.begin() , t.end());
    s = t; n = s.size();
}

int main() {
    FAST
    cin >> s; n = s.size();
    convert_N_to_9N();
    
    int l = 0 , r = n;
    while(l < r - 1) {
        int m = (l + r) / 2;
        if(check(m)) {
            r = m;
        }
        else {
            l = m;
        }
    }
    cout << r << endl;
}


Measured memory_bytes: 4688
#include <iostream>
#include <cmath>
#include <algorithm>

using namespace std;

int P[1010];
int F[1010];

void init(int N){
	for (int i = 0; i < N; ++i) P[i] = i;
}

int root(int a){
	if(P[a] == a) return a;
	return (P[a] = root(P[a]));
}

bool IsSameSet(int a, int b){
	return root(a) == root(b);
}

void unite(int a, int b){
	P[root(a)] = root(b);
}

int main (){
	F[0] = 1, F[1] = 2;
	for(int i = 2; i < 1010; i++) F[i] = (F[i-1] + F[i-2]) % 1001;
	int V, D;
	while(cin >> V >> D){
		init(V+1);
		for (int i = 1; i <= V; ++i){
			for(int j = i + 1; j <= V; ++j){
				if(abs(F[i]-F[j])<D) unite(i,j);
			}			
		}
		int n = 0;
		for (int i = 1; i <= V; ++i){
			// cout << P[i];
			if(root(i) == i) n++;
		}
		cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 1168
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
object Main extends App {
  solve()
  @tailrec def solve(): Unit = {
    val Array(n, m) = readLine.trim.split(' ').map(_.toInt)
    if (n == 0) return
    val relations = Array.tabulate(m){_ ⇒
      val Array(u, v) = readLine.trim.split(' ').map(_.toInt - 1)
      (u, v)
    }
    val (min, max) = pushFlow(makeNetwork(relations, n), n, m, n + m)
    println(s"$min $max")
    solve()
  }
  case class Edge(to: Int, pair: Int, var flow: Int)
  def pushFlow(nodes: Array[ArrayBuffer[Edge]], person: Int, relation: Int, goal: Int): (Int, Int) = {
    val prev = Array.fill(nodes.length){Nil: List[Edge]}
    for (from ← person until person + relation) {
      var maxFlow = 0
      prev.indices.foreach(i ⇒ prev(i) = Nil)
      val queue = mutable.Queue(from)
      while (queue.nonEmpty) {
        val current = queue.dequeue()
        for (next ← nodes(current) if next.flow > 0) {
          if (next.to == goal) {
            if (next.flow > maxFlow) {
              maxFlow = next.flow
              prev(goal) = next::prev(current)
            }
          }else if (prev(next.to).isEmpty) {
            prev(next.to) = next::prev(current)
            queue.enqueue(next.to)
          }
        }
      }
      for (e ← prev(goal)) {
        e.flow -= 1
        nodes(e.to)(e.pair).flow += 1
      }
    }
    val sorted = nodes(goal).sortBy(_.flow)
    (sorted.head.flow, sorted.last.flow)
  }
  def makeNetwork(relations: Array[(Int, Int)], personCount: Int): Array[ArrayBuffer[Edge]] = {
    val result = Array.fill(personCount + relations.length + 1){ArrayBuffer[Edge]()}
    val goal = result.length - 1
    for (p ← 0 until personCount) {
      result(p).append(Edge(goal, result(goal).length, relations.length))
      result(goal).append(Edge(p, 0, 0))
    }
    for (r ← relations.indices) {
      val (a, b) = relations(r)
      result(r + personCount).append(Edge(a, result(a).length, 1))
      result(a).append(Edge(r + personCount, result(r + personCount).length - 1, 0))
      result(r + personCount).append(Edge(b, result(b).length, 1))
      result(b).append(Edge(r + personCount, result(r + personCount).length - 1, 0))
    }
    result
  }
}



Measured memory_bytes: 452992
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <stdio.h>
#include <queue>

using namespace std;

long long N;
int main() {
	cin >> N;
	vector<int> A;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		A.push_back(tmp);
	}
	sort(A.begin(), A.end());
	long long x=0, y=0;
	for (int i = A.size() - 1; i >0; i--) {
		if (x == 0 && A[i] == A[i - 1]) {
			x = A[i];
			i--;
		}
		else if (A[i] == A[i - 1]) {
			y = A[i];
			cout << x * y;
			return 0;
		}
	}
	cout << 0;
	return 0;
}


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

int main(){
    int N, K;
    cin >> N >> K;
    //200000個の箱を用意
    int A[200000] = {};
    int num;
    for(int i=0;i<N;i++){
        cin >> num;
        A[num-1]++;
    }
    //昇順ソート
    sort(A, A + N);
    //最初何種類？
    int d = 0;
    for(int i=0;i<N;i++){
        if(0 < A[i])
            d++;
    }
    //K種類以下なら終了
    int count = 0; //書き換えるボールの数
    if(d <= K){
        cout << count << endl;
        return 0;
    }
    //数が少ないものから書き換える
    for(int i=0;i<N;i++){
        if(0 < A[i]){
            count += A[i];
            d--;
        }
        if(d <= K)
            break;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
#define fst first
#define snd second
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;

int main(){
    ll n; cin >> n;
    vll ans(10000000, 0);
    rep(i, 1, 101){
        rep(j, 1, 101){
            rep(k, 1, 101){
                ll x = i*i + j*j + k*k + i*j + j*k + k*i;
                ans[x]++;
            }
        }
    }
    rep(i, 1, n+1){
        prtl(ans[i]);
    }
}


Measured memory_bytes: 81348
using System;
using System.Collections.Generic;
using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            int R = int.Parse(Console.ReadLine());
            if(R<1200){
                Console.WriteLine("ABC");
            }else if(R<2800){
                Console.WriteLine("ARC");
            }else{
                Console.WriteLine("AGC");
            }
        }   
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}


Measured memory_bytes: 11092
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Arrays.sort(a);
        for (int i = 0; i < n - 1; i++) {
            if (a[i] == a[i + 1]) {
                System.out.println("NO");
                return;
            }
        }
        System.out.println("YES");
    }

}


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

using namespace std;

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

    int res = 0;

    for(int i = 1; i <= N; ++i){
        int sum = 0;
        int tmp = i;

        while(tmp != 0){
            sum += tmp % 10;
            tmp /= 10;
        }

        if(A <= sum and sum <= B) res += i;
    }
    cout << res << endl;
}

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

int main(){
    int n;
    cin>>n;
    int a[n-1];
    for(int i=0;i<n-1;i++) cin>>a[i];
    int ans[n];
    for(int i=0;i<n;i++){
        ans[i]=0;
    }
    for(int i=0;i<n-1;i++){
        int num=a[i];
        ans[num-1]++;
    }
    for(int i=0;i<n;i++){
        cout<<ans[i]<<endl;
    }
    return 0;
}

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

int main(){
  int n,k;
  cin >> n >> k;
  int a = 0;
  for (int i =0;i<n;i++){
    int b;
    cin >> b;
    if (k-b > b)
      a += 2*b;
    else
      a += 2*(k-b);
  }
  cout << a << endl;
}

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

int main(){
	stack<int> S1;                                          // ?°´?????????????????¢???????¨???????????????????????????????
	stack<pair<int, int> > S2;                              // ????°´??????????????¢???????¨??????????????????????????????????1???????????´??°??????????°´????????????????????????/????????????2???????????´??°??????????°´??????????????????????????§?????¢???
	char ch;                                                // ??\?????????
	int sum = 0;                                            // ?°´??????????????¢??????????¨? 
	for(int i=0;cin >> ch; i++){
		if(ch == '\\') S1.push(i);                      // \?????\????????????????????????????????????????????\??????
		else if(ch == '/' && S1.size() > 0){            // /?????\????????????????????????????????????????????£??????\????????¨??????????????°???
			int j=S1.top(); S1.pop();               // j?????????\???????????¨????????????????????????
			sum += i-j;                             // i?????????????????¨??????/??¨???j?????????????????¨??????\??¨??????????????¢???????????????
			int a = i-j;
			while(S2.size()>0 && S2.top().first>j){
			a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j,a));
		}
	}

	vector<int> ans;
	while(S2.size()>0) {ans.push_back(S2.top().second); S2.pop();}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for(int i=0;i<ans.size();i++){
		cout << " ";
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

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

using namespace std;

int main() {
    size_t n;
    cin >> n;
    size_t c = 0;
    for (size_t i = 1; i <= n; ++i) {
        auto j = i;
        size_t d = 0;
        do {
            if (j > 0)
                ++d;
        } while (j /= 10);
        if (d % 2 == 1)
            ++c;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include <iostream>
#include <fstream>

#include <iostream>
#include "bits/stdc++.h"

using namespace std;

typedef unsigned long long ll;
typedef int                     integer;
#define int                     long long
#define ii                      pair<int,int>
#define vii                     vector<pair<int,int>>
#define vi                      vector<int>
#define vvi                     vector<vector<int>>
#define f(a,b,c)                for(int a=b;a<c;a++)
#define s(x)                    in>>x
#define s2(x,y)                 in>>x>>y
#define s3(x,y,z)               in>>x>>y>>z
#define s4(x,y,z,w)             in>>x>>y>>z>>w
#define p(x)                    out<<x<<endl
#define p2(x,y)                 out<<x<<" "<<y<<endl
#define pl(x)                   out<<x
#define p2l(x,y)                out<<x<<" "<<y
#define p1d(a,n)                for(int ix=0;ix<n;ix++) out<<a[ix]<<" "; out<<endl
#define p2d(a,n,m)              for(int ix=0;ix<n;ix++){ for(int jx=0;jx<m;jx++) out<<a[ix][jx]<<" "; out<<endl;}
#define range(v)                v.begin(),v.end()
#define w(x)                    while(x--)
#define rst(x)                  memset(x, -1, sizeof(x))
#define UNVISITED               -1
#define VISITED                 0
#define EXPLORED                2
int dr[] = {-1, 0};
int dc[] = {0,-1};

int dpp(int i, int j, vector<vector<bool>>&grid, vvi &dp){
    if(i == 0 && j == 0) return !grid[0][0]?1:0;
    if(dp[i][j]!=-1) return dp[i][j];

        int m = 1e9;
        f(k,0,2){
            int nx = i+dr[k];
            int ny = j +dc[k];
            if(nx>=0 && nx<grid.size() && ny>=0 && ny<grid[0].size()){
                int v = dpp(nx,ny, grid, dp);
                if(!grid[i][j] && grid[nx][ny]) v++;
                m = min(m, v);
            }
        }
        dp[i][j] = m;
        return m;

}

void ssolve(std::istream& in, std::ostream& out){
    int h,w;
    s2(h,w);
    vector<vector<bool>> grid;
    vvi dp;
    dp.assign(h,vector<int>(w, -1));
    grid.assign(h,vector<bool>(w));
    f(i,0,h)f(j,0,w){
        char x;
        s(x);

        grid[i][j] = x =='.';
    }
    out<<dpp(h-1,w-1,grid,dp)<<endl;

}

class ARangeFlipFindRoute {
public:
	void solve(std::istream& in, std::ostream& out) {
        ios_base::sync_with_stdio(false);
        in.tie(0);out.tie(0);
        int t;
        int READ = 0;
        if(READ) s(t);
        else t = 1;
        while(t--){
            ssolve(in, out);
        }
	}
};


integer main() {
	ARangeFlipFindRoute solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
}


Measured memory_bytes: 384
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn gcd(a: u64, b: u64) -> u64 {
    assert!(a != 0 || b != 0);
    if a == 0 {
        b
    } else {
        gcd(b % a, a)
    }
}

fn lcm(a: u64, b: u64) -> u64 {
    a / gcd(a, b) * b
}

fn main() {
    input!{
        a: usize,
        b: usize,
        c: usize,
        d: usize,
    }
    let mut cnt = b - a + 1;
    cnt -= (b / c - a / c) + if a % c == 0 {1} else {0};
    cnt -= (b / d - a / d) + if a % d == 0 {1} else {0};

    let div = lcm(c as u64,  d as u64) as usize;
    cnt += (b / div - a / div + if a % div == 0 {1} else {0});
    println!("{}", cnt);
}


Measured memory_bytes: 4352
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    string a, b;
    scan(a, b);
    long n = (a ~ b).to!long();
    foreach (i; 1 .. 400)
        if (i * i == n)
        {
            writeln("Yes");
            return;
        }
    writeln("No");
}


Measured memory_bytes: 256
#include <iostream>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
 
using namespace std;
typedef long long int ll;
typedef pair <int,int> pii;
typedef pair<ll,ll> pll;
 
 
/*bool compare_function(const pair<int, int> a, const pair<int, int> b)
{
    return a.first < b.first;
}*/
// use case
//sort(V.begin(), V.end(), compare_function);
 
/*struct compare
{
    bool operator ()(const pair<int, int> &a, const pair<int, int> &b) {
    if (a.second-a.first==b.second-b.first)
    {
        return a.first>b.first;
    }
    return a.second-a.first < b.second-b.first;}
};
priority_queue <pair<int,int>, vector <pair<int,int>>, compare> Q;*/
 
/*void print1(vector <int> X)
{
    for (int i=0; i<X.size(); i++)
    {
        cout<<X[i]<<" ";
    }
    cout<<endl;
    return;
}
 
void print2(vector <vector <int>> X)
{
    for (int i=0; i<X.size(); i++)
    {
    for (int j=0;j<X[i].size();j++) {
        cout<<X[i][j]<<" ";}
    cout<<endl;}
    return;
}*/

 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll a,b,c,d;
    cin>>a>>b>>c>>d;
    ll x=max(a*d,a*c);
    ll y=max(b*c,b*d);
    cout<<max(x,y)<<endl;
    return 0;
}


Measured memory_bytes: 3652
from collections import Counter
n,m=map(int,input().split())
a=list(map(int,input().split()))
s,x=[0],0
for i in a:
    x=(x+i)%m
    s.append(x)
cs=Counter(s).most_common()
ans=0
for i,j in cs:ans+=j*(j-1)//2
print(ans)

Measured memory_bytes: 19496
m, d = map(int, input().split())

ans = 0
for mi in range(1, m + 1):
    for di in range(1, d + 1):
        d10, d1 = divmod(di, 10)
        if d1 >= 2 and d10 >= 2 and mi == d10 * d1:
            ans += 1

print(ans)


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

int main()
{
	int N,Q;
	cin >> N >> Q;
	fenwick_tree<long long> fw(N);
	rep(i,N)
	{
		ll a;
		cin >> a;
		fw.add(i,a);
	}
	rep(i,Q)
	{
		ll a,b,c;
		cin >> a >> b >> c;
		if (a == 1)
		{
			cout << fw.sum(b,c) << endl;
		}
		else
		{
			fw.add(b,c);
		}
	}
	return 0;
}

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

string S;
int K;
int sz;

int select_free(void) {
	int cnt = 0;
	if (K == 1)
		cnt = (sz - 1) * 9;
	else if (K == 2)
		cnt = (sz - 1) * (sz - 2) / 2 * (9 * 9);
	else
		cnt = (sz - 1) * (sz - 2) * (sz - 3) / 6 * (9 * 9 * 9);
	return cnt;
}

int check_upper(void) {
	int m = sz;
	for (int i = 1; i < sz; ++i) {
		if (S[i] != '0') {
			m = i;
			break;
		}
	}
	return m;
}

bool check_upper2(int x, int y) {
	for (int i = x + 1; i < y; ++i) {
		if (S[i] != '0')
			return true;
	}
	return false;
}

int select_large(void) {
	int cnt = 0;
	if (K == 1)
		cnt = (int)(S[0] - '0');
	if (K == 2) {
		cnt = ((int)(S[0] - '0') - 1) * (sz - 1) * 9;
		int nxt = check_upper();
		for (int i = 1; i < sz; ++i) {
			if (nxt < i)
				cnt += 9;
			else if (nxt == i)
				cnt += (int)(S[i] - '0');
		}
	}
	if (K == 3) {
		cnt = ((int)(S[0] - '0') - 1) * (sz - 1) * (sz - 2) / 2 * 9 * 9;
		int nxt = check_upper();
		for (int i = 1; i < sz - 1; ++i) {
			for (int j = i + 1; j < sz; ++j) {
				if (nxt < i)
					cnt += 9 * 9;
				else if (nxt == i) {
					if (check_upper2(i, j))
						cnt += (int)(S[i] - '0') * 9;
					else {
						if (S[i] != '0') {
							cnt += ((int)(S[i] - '0') - 1) * 9;
							cnt += (int)(S[j] - '0');
						}
						else
							cnt += (int)(S[j] - '0');
					}
				}
			}
		}
	}
	return cnt;
}

int solve(void) {
	int cnt_1 = select_free();
	int cnt_2 = select_large();
	int cnt = cnt_1 + cnt_2;
	return cnt;
}

int main(void) {
	cin >> S >> K;
	sz = S.length();
	int ans = 0;
	if (sz >= K)
		ans = solve();
	cout << ans << '\n';
	return 0;
}


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

int func(int p,int x){
    return p*(100+x)/100;
}
int main(){
    int x,y,s;
    while(true){
        cin >> x >> y >> s;
        if(x==0 and y==0 and s==0)
            break;
        int res = 0;
        for(int i=1; i<s; i++){
            for(int j=i; j<s; j++){
                if(func(i,x)+func(j,x)==s)
                    res = max(res, func(i,y) + func(j,y));
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include<stdio.h>
int main()
{
  int n,m,q;
  int i,j;
  int date[100];
  int p;
  int result;
  while(1)
    {
      scanf("%d %d",&n,&q);
      if(n==0) break;
      for(i=0;i<100;i++) date[i]=0;
      for(i=0;i<n;i++)
	{
	  scanf("%d",&m);
	  for(j=0;j<m;j++)
	    {
	      scanf("%d",&p);
	      date[p-1]++;
	    }
	}
      result=0;
      for(i=1;i<100;i++)
	{
	  if(date[result]<date[i]) result=i;
	}
      if(date[result]>=q) printf("%d\n",result+1);
      else printf("0\n");
    }
  return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
const int MAXN1 = 50000;
const int MAXN2 = 50000;
const int MAXM = 150000;

int n1, n2, edges, last[MAXN1], previous[MAXM], head[MAXM];
int matching[MAXN2], dist[MAXN1], Q[MAXN1];
bool used[MAXN1], vis[MAXN1];

void init(int _n1, int _n2) {
    n1 = _n1;
    n2 = _n2;
    edges = 0;
    fill(last, last + n1, -1);
}

void addEdge(int u, int v) {
    head[edges] = v;
    previous[edges] = last[u];
    last[u] = edges++;
}

void bfs() {
    fill(dist, dist + n1, -1);
    int sizeQ = 0;
    for (int u = 0; u < n1; ++u) {
        if (!used[u]) {
            Q[sizeQ++] = u;
            dist[u] = 0;
        }
    }
    for (int i = 0; i < sizeQ; i++) {
        int u1 = Q[i];
        for (int e = last[u1]; e >= 0; e = previous[e]) {
            int u2 = matching[head[e]];
            if (u2 >= 0 && dist[u2] < 0) {
                dist[u2] = dist[u1] + 1;
                Q[sizeQ++] = u2;
            }
        }
    }
}

bool dfs(int u1) {
    vis[u1] = true;
    for (int e = last[u1]; e >= 0; e = previous[e]) {
        int v = head[e];
        int u2 = matching[v];
        if (u2 < 0 || !vis[u2] && dist[u2] == dist[u1] + 1 && dfs(u2)) {
            matching[v] = u1;
            used[u1] = true;
            return true;
        }
    }
    return false;
}

int maxMatching() {
    fill(used, used + n1, false);
    fill(matching, matching + n2, -1);
    for (int res = 0;;) {
        bfs();
        fill(vis, vis + n1, false);
        int f = 0;
        for (int u = 0; u < n1; ++u)
            if (!used[u] && dfs(u))
                ++f;
        if (!f)
            return res;
        res += f;
    }
}

int main() {
  int N;
  cin >> N;
  init(N,N);
  int a[N],b[N],c,d;
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i];
  }
  for (int i = 0; i < N; i++) {
    cin >> c >> d;
    for (int j = 0; j < N; j++) {
      if (a[j] < c && b[j] < d) {
        addEdge(j,i);
      }
    }
  }
  cout << maxMatching();
}

Measured memory_bytes: 3616
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define MAX 10000000
#define SENTINEL 2e10


int main(){
    string s; cin >> s;
    map<char, int> mp;
    bool exist = true;
    for(int i = 0; i < 4; i++){
        mp[s[i]]++;
    }
    if(mp.size() != 2){
        exist = false;
    }
    for(int i = 0; i < 4; i++){
        if(mp[s[i]] != 2){
            exist = false;
            break;
        }
    }
    if(exist) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#%%
import sys
def input():
    return sys.stdin.readline().rstrip()

def main():
    N, L = map(int, input().split())
    
    s = (N-1)*N//2 + L * N
    if L > 0:
        s = s - L
    else:
        s = s - min(L+N-1, 0)
    print(s)


# %%
if __name__ == '__main__':
    main()

# %%
# from atcoder_test import doTest
# doTest("abc131","b",main)

Measured memory_bytes: 3060
n, h = list(map(int, input().split()))
aa = []
bb = []
for _ in range(n):
    a, b = list(map(int, input().split()))
    aa.append(a)
    bb.append(b)

amax = max(aa)
bb = [b for b in bb if b > amax]
bb.sort(reverse=True)
ans = 0
for b in bb:
    ans += 1
    h -= b
    if h <= 0:
        break
if h > 0:
    ans += -(-h // amax)

print(ans)

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

int main() {
    int one=0, zero=0;
    std::string s;
    std::cin >> s;
    for (int i=0; i<s.size(); ++i) {
        if (s[i] == '0') ++zero;
        else ++one;
    }
    std::cout << 2 * std::min(one, zero) << std::endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
inline void solve(){
	int a,b;cin>>a>>b;
	if(a==b)cout<<"Yes\n";
	else cout<<"No\n";
	return;
}

signed main()
{

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	solve();
	return 0;
}

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

int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a <= b && b <= c){
        cout << a << " " << b << " " << c << endl;
        return 0;
    }else if(a <= c && c <= b){
        cout << a << " " << c << " " << b << endl;
        return 0;
    }else if(b <= a && a <= c){
        cout << b << " " << a << " " << c << endl;
        return 0;
    }else if(b <= c && c <= a){
        cout << b << " " << c << " " << a << endl;
        return 0;
    }else if(c <= a && a <= b){
        cout << c << " " << a << " " << b << endl;
        return 0;
    }else if(c <= b && b <= a){
        cout << c << " " << b << " " << a << endl;
        return 0;
    }

    return 0; 
}


Measured memory_bytes: 3084