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

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		//????????¶????????\???
		if(a < b){
			System.out.println("a < b");
		}
		if(a > b){
			System.out.println("a > b");
		}
		if(a == b){
			System.out.println("a == b");
		}
	}
}

Measured memory_bytes: 26332
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=list(map(int,input().split()))
res=0
res+=b[a[0]-1]
#print(res)
for i in range(1,n):
  res+=b[a[i]-1]
#  print("1",res,i)
  if i>=1 and a[i]==a[i-1]+1:
    res+=c[a[i-1]-1]
#    print("2",res,i)
print(res)

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

using i64 = int64_t;

constexpr i64 INF = 1e9;

struct Edge{
    int from, to;
    i64 cost;
};

using Graph = vector<vector<Edge>>;

int main(){
    int v, e, r;
    cin >> v >> e >> r;
    Graph graph(v, vector<Edge>());
    for(int i=0;i<e;++i){
        int s, t;
        i64 d;
        cin >> s >> t >> d;
        graph[s].push_back({s, t, d});
    }
    vector<i64> mini(v, INF);
    mini[r] = 0;
    priority_queue<pair<int, i64>> que;
    que.push({r, 0});
    while(!que.empty()){
        auto cur = que.top(); que.pop();
        for(auto e: graph[cur.first]){
            i64 cost = cur.second + e.cost;
            if(mini[e.to] < cost)continue;
            mini[e.to] = cost;
            que.push({e.to, cost});
        }
    }
    for(int i=0;i<v;++i){
        if(mini[i] >= INF){
            cout << "INF";
        }else{
            cout << mini[i];
        }
        cout << endl;
    }

    return 0;
}



Measured memory_bytes: 33848
#include<bits/stdc++.h>
using namespace std;
#define INF (1LL<<60)
#define DEKAI 1000000007
#define lp(i,n) for(int i=0;i<n;i++)
#define int long long

#define N 100


signed main(){
	int x,a;
	cin>>x>>a;
	if(x<a)cout<<0<<endl;
	else cout<<10<<endl;
  	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
const int inf=1145141919810893;
const int mod=1000000007;
using namespace std;
template<class T>bool chmin(T &a,const T &b){
	if(a>b){
		a=b;
		return true;
	}
	return false;
}
template<class T>bool chmax(T &a,const T &b){
	if(a<b){
		a=b;
		return true;
	}
	return false;
}
template<class T>void debug(T *a,int l,int r,const char *name){
	for(int i=l;i<r;i++)
		cout<<name<<"["<<i<<"]="<<a[i]<<endl;
}
int p[50];
int N,A,B;
signed main(){
	int i,j;
	cin>>N>>A>>B;
	if((B-A)%2==0)
		cout<<"Alice"<<endl;
	else
		cout<<"Borys"<<endl;
	return 0;
}

Measured memory_bytes: 256
n,m = map(int, input().split())
l = sorted([list(map(int, input().split())) for i in range(n)], key = lambda x: (x[0],-x[1]))
ans = 0
for i in l:
    if m - i[1]>=0:
        ans+= i[0]*i[1]
        m-=i[1]
    else:
        ans+= i[0]*m
        break
print(ans)

Measured memory_bytes: 39264
import copy as cp
#INPUT
D = int(input())
c = [int(i) for i in input().split()]
s = []
for i in range(D):
    new = [int(i) for i in input().split()]
    s.append(new)

#Utilitiy
def score(ans):
    if len(ans) != D:
        print("wrong length")
        return 0
    else:
        p = 0
        last = [-1]*26
        for i in range(D):
            contest = ans[i]-1
            p += s[i][contest]
            last[contest] = i
            for j in range(26):
                p -= c[j]*(i-last[j])
        return p

def greedy(ahead=0):
    ans = []
    p = 0
    last = [-1]*26
    for i in range(D):
        decay = 0
        for j in range(26):
            decay -= c[j]*(i-last[j])
            
        max_j = -1
        max_plus_mod = decay
        max_plus = decay
        for j in range(26):
            plus = s[i][j] + c[j]*(i-last[j])
            modify = c[j]*(ahead*(i-last[j])+ahead*(ahead+1)//2)
            if (plus+modify) > max_plus_mod:
                max_plus = plus
                max_plus_mod = plus+modify
                max_j = j
        ans.append(max_j+1)
        last[max_j]=i
        p += max_plus + decay
    return ans, p
        
#MAIN
max_points = -10000000
for k in range(20):
    ans_temp, points = greedy(ahead = k)
    #print(k, points, ans_temp)
    if points > max_points:
        max_points = points
        ans = cp.copy(ans_temp)

for i in range(D):
    print(ans[i])

Measured memory_bytes: 9544
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  using P = pair<Int, Int>;
  vector<P> ans;
  vector<vector<Int> > G(n+1);
  for(Int i=1;i<=n;i++){
    for(Int j=1;j<i;j++){
      if(n&1){
        if(i+j==n) continue;
      }else{
        if(i+j==n+1) continue;
      }
      ans.emplace_back(i,j);
      G[i].emplace_back(j);
      G[j].emplace_back(i);
    }
  }
  {
    set<Int> ss;
    for(Int v=1;v<=n;v++){
      Int res=0;
      for(Int u:G[v]) res+=u;
      ss.emplace(res);
    }
    assert(ss.size()==1u);
  }
  cout<<ans.size()<<endl;
  for(auto p:ans) cout<<p.first<<" "<<p.second<<endl;
  return 0;
}


Measured memory_bytes: 512
'''
.append(要素) リストに要素を追加 
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前

sort()
sorted(reverse=true)

配列の初期化
配列名=[a]*n+[b]*m

Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
import itertools
from functools import reduce
from operator import mul


Num = int(stdin.readline().rstrip())
data = [int(s) for s in stdin.readline().rstrip().split()]
check = True
for el in data:
    if el % 2 == 0:
        if el % 3 != 0 and el % 5 != 0:
            check = False
if check:
    print('APPROVED')
else:
    print('DENIED')


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


























int main() {
    string s;
    cin >> s;
    if (*(s.end() - 1) == 's') {
        cout << s << "es" << endl;
    }
    else cout << s << 's' << endl;
}

Measured memory_bytes: 3632
#include"iostream"
using namespace std;

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

	if (k % 2 == 1)
	{
		long a = 1;
		for (int i = 0; i < 3; i++)a *= n / k;
		cout << a << endl;
	}
	else if (n < k / 2)	cout << 0 << endl;

	else
	{
		long a = 1;
		for (int i = 0; i < 3; i++)a *= n / k;
		long b = 1;
		for (int i = 0; i < 3; i++)b *= (n - (k / 2)) / k + 1;
		cout << a + b << endl;
	}
}

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

int main(){
    int n;
    string s;
    cin >> n >> s;
    vector<int> v[10];
    for(int i = 0; i < n; i++){
        v[s[i]-'0'].push_back(i);
    }
    int ans = 0;
    for(int i = 0; i < 10; i++){
        for(int j = 0; j < 10; j++){
            for(int k = 0; k < 10; k++){
                int pos = 0;
                pos = lower_bound(v[i].begin(), v[i].end(), pos)-v[i].begin();
                if(pos == v[i].size())  continue;
                pos = v[i][pos]+1;
                pos = lower_bound(v[j].begin(), v[j].end(), pos)-v[j].begin();
                if(pos == v[j].size())  continue;
                pos = v[j][pos]+1;
                pos = lower_bound(v[k].begin(), v[k].end(), pos)-v[k].begin();
                if(pos == v[k].size())  continue;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
// ABC.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main()
{
	string n;
	cin >> n;
	if (n[0] == n[2]) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define mod 1000000007
using namespace std;
typedef long long ll;
bool chmax(ll &a,ll b){
    if(a>b)return 0;
    a=b; return 1;
}
bool chmin(ll &a,ll b){
    if(a<b)return 0;
    a=b; return 1;
}
#define mad(a,b) a=(a+b)%mod
#define mul(a,b) a=(a*b)%mod
ll po(ll x,ll y){
    ll res=1;   
    for(;y;y>>=1){
	if(y&1)mul(res,x);
	mul(x,x);
    }
    return res;
}
ll dp[410][410];
ll rui[410][410];
ll n,c,l[410],r[410];
int main(){
    for(ll i=0;i<410;i++){
	rui[i][0]=0;
	for(ll j=1;j<410;j++){
	    rui[i][j]=(rui[i][j-1]+po(j,i))%mod;
	}
    }
    cin>>n>>c;
    for(int i=0;i<n;i++){
	cin>>l[i];
    }
    for(int i=0;i<n;i++){
	cin>>r[i];
    }
    for(int i=0;i<=n;i++)for(int j=0;j<=c;j++)dp[i][j]=0;
    dp[0][0]=1;
    for(int i=0;i<n;i++)for(int j=0;j<=c;j++){
	for(int a=0;a+j<=c;a++){
	    mad(dp[i+1][j+a],dp[i][j]*(rui[a][r[i]]-rui[a][l[i]-1]));
	}
    }
    ll ans=dp[n][c];
    if(ans<0)ans+=mod;
    cout<<ans<<endl;
}



Measured memory_bytes: 2816
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define double long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define pii pair<int,int>
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   1000000007 // 1e9 + 7
using namespace std;
inline int mod(int n, int m){ int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int lcm(int a,int b){return (a*b)/gcd(a,b);}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}
struct matrix{
    int n,m;
    vector<vector<int>> mat;
    matrix(){}
    matrix(int l,int c){
        n = l;
        m = c;
        mat.resize(n, vector<int>(m));
    }
    void nsize(int l,int c){
        n = l;
        m = c;
        mat.resize(n, vector<int>(m));
    }
};
matrix operator*(const matrix& A,const matrix& B){
    matrix ret(A.n,B.m);
    for(int i=0;i<A.n;i++)
        for(int j=0;j<B.m;j++)
            for(int k=0;k<A.m;k++){
                ret.mat[i][j] += (A.mat[i][k] * B.mat[k][j])%M;
                ret.mat[i][j]%=M;
            }
    return ret;
}
matrix def; // def = matriz Identidade
matrix expo(matrix a,int b){
    if(b==0) return def;
    if(b==1){
        return a;
    }
    matrix now = expo(a,b/2);
    if(b&1){
        return a*now*now;
    }
    else return now*now;
}
int32_t main(){
    fastio;
    int n,k;
    cin >> n >> k;
    matrix edges(n,n);
    frr(i,n) frr(j,n) cin >> edges.mat[i][j];
    matrix dp(n,1);
    def.nsize(n,n);
    for(int i=0;i<n;i++){
        dp.mat[i][0] = 1;
        def.mat[i][i] = 1;
    }
    matrix res = expo(edges,k) * dp;
    int ans = 0;
    for(int i=0;i<n;i++){
        ans = mod(ans+res.mat[i][0],M);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1664
"use strict";
    
const main = arg => {
    arg = arg.trim().split("\n");
    const N = parseInt(arg[0]);
    const P = arg[1].split(" ").map(n=>parseInt(n));
    
    let cnt = 0;
    
    for(let i=0; i<N-1; i++) {
        if(P[i] !== parseInt(i) + 1) {
            cnt++;
        }
    }

    console.log(cnt > 2 ? "NO" : "YES")
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 11468
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>

typedef long long LL;

const int N=100005;

int n;
LL m,v[N],mx[N],x[N];

int main()
{
	scanf("%d%lld",&n,&m);LL ans=0;
	for (int i=1;i<=n;i++) scanf("%lld%lld",&x[i],&v[i]),v[i]+=v[i-1];
	for (int i=1;i<=n;i++) ans=std::max(ans,v[i]-x[i]),ans=std::max(ans,v[n]-v[i-1]-m+x[i]);
	for (int i=n;i>=1;i--) mx[i]=std::max(mx[i+1],v[n]-v[i-1]-m+x[i]);
	for (int i=1;i<=n;i++) ans=std::max(ans,v[i]-x[i]*2+mx[i+1]);
	for (int i=1;i<=n;i++) mx[i]=std::max(mx[i-1],v[i]-x[i]);
	for (int i=n;i>=1;i--) ans=std::max(ans,v[n]-v[i-1]-(m-x[i])*2+mx[i-1]);
	printf("%lld",ans);
	return 0;
}

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

#define ASC(vec) vec.begin(), vec.end() 
#define DESC(vec) vec.rbegin(), vec.rend()
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, vec.size()) cin>>vec[i]; 
#define ANS(s) cout << s << endl;
#define inc(a, b) cin >> a >> b;

int main(){
	ios::sync_with_stdio(0); cin.tie(0);
	int n,k,q;
	cin>>n>>k>>q;
	vector<int> tamesi (n,0);
	vector<int> tamesi1 (q);
	In(tamesi1);

	for(auto v : tamesi1){
			tamesi[v-1] = tamesi[v-1]+1;
 	}

	for(auto v: tamesi){
			if(k-q+v>=1) cout<<"Yes"<<"\n";
			else cout<<"No"<<"\n";
	}
	return 0;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

ll Pow(ll A, ll N){
  if (N == 0) return 1;
  else if (N % 2 == 0) return Pow(A*A%MOD, N/2);
  else return A * Pow(A*A%MOD, N/2)%MOD;
}

int N, a[int(1e5+5)];
int mark = 0, cnt = 0;
bool visited[int(1e5+5)];
ll A, B, C;
ll abc[int(1e5+5)], ac[int(1e5+5)], bc[int(1e5+5)], cc[int(1e5+5)];

int main(){
  cin >> N;
  for (int i = 0; i <= N; i++){
    cin >> a[i];
    if (visited[a[i]]) mark = a[i];
    visited[a[i]] = true;
  }

  for (int i = 0; i <= N; i++){
    if (a[i] == mark){
      cnt++; continue;
    }
    if (cnt == 0) A++;
    if (cnt == 1) B++;
    if (cnt == 2) C++;
  }

  abc[0] = 1; 
  for (ll i = 1; i <= A+B+C; i++){
    abc[i] = abc[i-1] * (A+B+C+1-i) % MOD;
    abc[i] *= Pow(i, MOD-2); abc[i] %= MOD;
  }

  ac[0] = 1;
  for (ll i = 1; i <= A; i++){
    ac[i] = ac[i-1] * (A+1-i) % MOD;
    ac[i] *= Pow(i, MOD-2); ac[i] %= MOD;
  }

  bc[0] = 1;
  for (ll i = 1; i <= A + C; i++){
    bc[i] = bc[i-1] * (A+C+1-i) % MOD;
    bc[i] *= Pow(i, MOD-2); bc[i] %= MOD;
  }

  cc[0] = 1;
  for (ll i = 1; i <= C; i++){
    cc[i] = cc[i-1] * (C+1-i) % MOD;
    cc[i] *= Pow(i, MOD-2); cc[i] %= MOD;
  }

  for (int i = 1; i <= N + 1; i++){
    ll ans = abc[i];
    ans += 2 * abc[i-1] - bc[i-1];
    if (i > 1) ans += abc[i-2];

    ans %= MOD;
    if (ans < 0) ans += MOD;
    cout << ans << endl;
  }

  return 0;
}


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

#define PI 4*atan(1)
#define INF 1e8

int dx[4] = {1,0,-1,0};
int dy[4] = {0,1,0,-1};

int main(){
  int R0, W0, C, R;
  while(cin >> R0 >> W0 >> C >> R, R0||W0||C||R){
    if(R0/W0>=C){
      cout << 0 << endl;
      continue;
    }else{
      int ans = 1;
      while(1){
        if((R0 + ans*R)/W0 >= C)break;
        ans++;
      }
      cout << ans << endl;
    }
  }
}

Measured memory_bytes: 3084
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int d1, d10;
		int cnt = 0;
		for(int i = 1; i <= a; i++){
			for(int j = 1; j <= b; j++){
				d1 = j%10;
				d10 = j/10;
				if(d1 >= 2 && d10 >= 2 && i ==  d1 * d10){
					cnt++;
				}
			}
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 22228
# coding: utf-8
# Your code here!

count = int(input())
num = []
num = input().split()

hantei = 0
for i in range(count):
    if int(num[i]) == 0:
        hantei = 1
        total = 0
    else:
        continue
      #print("z")
      
if hantei == 0:
    total = 1
    for i in range(count):
        total = int(num[i])*total
        if total > 10**18:
            total = -1
            break
    
print(total)


Measured memory_bytes: 19392
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
int main(){
    int n;
  while(1){
   cin>>n;
   if(n==0)return 0;
   V<ll> a(n);
   ll sum=0;
   for(int i=0;i<n;i++){cin>>a[i];sum+=a[i];}
   sort(all(a));
   sum-=(a[0]+a[n-1]);
   cout<<sum/(n-2)<<endl;

  }
 
}


Measured memory_bytes: 3192
#include <stdio.h>

int main(void) {
        int x;
        int i, size = 5;

        for (i = 0; i < size; i++) {
                scanf("%d", &x);
                if (x == 0) {
                        break;
                }
        }

        printf("%d\n", i+1);
        return 0;
}

Measured memory_bytes: 1732
from math import sqrt
from collections import deque
M = 10**6
prime = [1]*(M+1)
prime[0] = prime[1] = 0
for i in xrange(2, int(sqrt(M))+1):
    if prime[i]:
        for j in xrange(i*i, M+1, i):
            prime[j] = 0
def calc(x):
    k = int(sqrt(x))
    if k % 2:
        p = k/2
        if x <= k**2 + k:
            i = x-k**2
            return (p+1, p-i)
        else:
            i = x-(k**2 + k)
            return (p+1-i, -p-1)
    else:
        p = k/2
        if x <= k**2 + k:
            i = x-k**2
            return (-p, -p+i)
        else:
            i = x-(k**2+k)
            return (-p+i, p)
C = map(calc, xrange(M+1))
dic = {x: i+1 for i, x in enumerate(C)}
while 1:
    m, n = map(int, raw_input().split())
    if m == n == 0:
        break
    used = {}
    deq = deque()
    deq.append(n)
    used[n] = prime[n]
    u = set()
    while deq:
        c = deq.popleft()
        if c in u:
            continue
        u.add(c)
        x, y = C[c-1]
        for dx in [-1, 0, 1]:
            v = dic.get((x+dx, y+1), M+1)
            if v <= m:
                deq.append(v)
                used[v] = max(used[c]+prime[v], used.get(v, 0))
    cnt = 0; num = 0
    for k in used:
        if prime[k]:
            if cnt < used[k]:
                cnt = used[k]
                num = k
            elif cnt == used[k] and num < k:
                num = k
    print cnt, num

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

int main() {
	int N;
	cin >> N;
	vector<ll> H(N, 0);
	ll result = 0;

	repeat(i, N) {
		cin >> H[i];
	}

	int count = 0;
	for(int i = 1;i < N; i++) {
		if (H[i-1] >= H[i]) {
			count++;
			if (count > result) result = count;
			continue;
		}
		count = 0;
	}

	cout << result << endl;
	return 0;
}


Measured memory_bytes: 1024
import itertools,sys
def I(): return int(sys.stdin.readline().rstrip())
N = I()
dp = [float('INF')]*(N+1)
dp[0] = 0
for i in range(N+1):
    if i+1<=N:
        dp[i+1] = min(dp[i+1],dp[i]+1)
    num6,num9 = 6,9
    while i+num6<=N:
        dp[i+num6] = min(dp[i+num6],dp[i]+1)
        num6 *= 6
    while i+num9<=N:
        dp[i+num9] = min(dp[i+num9],dp[i]+1)
        num9 *=9
print(dp[-1])


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

int main(){
    int m,d,ans=0;
    cin >> m >> d;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            if(j<=19)continue;
            else{
                if(j%10>=2)
                {
                    if(i==(j/10)*(j%10))ans++;
                }
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import numpy as np
even = np.zeros(100001, dtype='i')
odd = np.zeros(100001, dtype='i')

n = int(input())
v = list(map(int, input().split()))

for i in range(n):
    if i % 2 == 0:
        even[v[i]] += 1
    else:
        odd[v[i]] += 1

e1 = even.argmax()
e1n = even.max()
o1 = odd.argmax()
o1n = odd.max()

# print(e1, e1n, o1, o1n)
if e1 == o1:
    e2n = np.sort(even)[-2]
    o2n = np.sort(odd)[-2]
    # print(e2n, o2n)
    print(min(n - e1n - o2n, n - e2n - o1n))
else:
    print(n - e1n - o1n)


Measured memory_bytes: 23368
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define ll long long
using namespace std;
const int inf=1e9;
const int mod=1e9+7;
const int maxn=1e5+10;
ll dp[maxn];
ll a[maxn],b[maxn],f[maxn];
char s[maxn];
ll ksm(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1) ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}
int main(){
	//ios::sync_with_stdio(false);
	//freopen("in","r",stdin);
	cin>>s+1;
	f[0]=1;
	for(int i=1;i<maxn;i++) f[i]=f[i-1]*i%mod;
	int n=strlen(s+1);
	for(int i=n;i>=1;i--) a[n-i+1]=s[i]-'0';
	ll ans=0;
	for(int i=n;i>=1;i--){
		b[i]=b[i+1]+(a[i]==1);
	}
	for(int i=1;i<=n;i++){
		if(a[i]==1){
			ans+=ksm(2,b[i+1])*ksm(3,i-1)%mod;
			ans%=mod;
		}
	}
	ans=(ans+ksm(2,b[1]))%mod;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <string>
#include <vector>
#include <algorithm> // sort
#include <map> // pair
#include <queue>
#include<iomanip>
#include <cmath>
#include <set>
#include <unordered_set>

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

#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

#define INF 1000000000

using namespace std;
typedef long long ll;

ll newton(long long int a, long long int  b)
{
	if(a==b)
		return a;
	while(a != 0 && b != 0)
	{
		if(a > b)
		{
			b += a;
			a = b-a;
			b -= a;
		}
		b %= a;
	}
	return a;
}

struct UnionFind {
	vector<int> p;
	UnionFind(int N):p(N)
	{
		for(int i=0; i< N; i++)
		{
			p[i] = i;
		}
	}
	int root(int x)
	{
		if(p[x] == x)
			return x;
		return p[x] = root(p[x]);
	}
	void unite(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		if(rx == ry) return;
		p[rx] = ry;
	}
	bool issame(int x, int y)
	{
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
};

//大きな数に対する割り算をするとき、MODを指定することで掛け算の値に変換できる

ll div2mul_calc(ll a, ll b, ll m)
{
	if (b == 0) {
        return 1;
    } else if (b % 2 == 0) {
        ll d = div2mul_calc(a, b / 2, m);
        return (d * d) % m;
    } else {
        return (a * div2mul_calc(a, b - 1, m)) % m;
    }
}
ll div2mul(ll n, ll mod)
{
	return div2mul_calc(n, mod-2, mod);
}

ll twoRow(ll a, ll b, ll mod)
{
	ll ret = 1;
	for(ll i = 1 ;i <= a+b;++i)
	{
		ret *= i;
		ret %= mod;
	}
	for(ll i = 1 ;i <= a;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	for(ll i = 1 ;i <= b;++i)
	{
		ret *= div2mul(i,mod);
		ret %= mod;
	}
	return ret;
}

struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};

vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      if(i * i != n) ret.push_back(n / i);
    }
  }
  sort(ret.begin(), ret.end());
  return (ret);
}
/*
小数の桁数を指定する
	cout << setprecision(8)<< mp[0]-mx << endl;
*/

int main()
{
	ll i,j,k,a,b,ans = 0;
	ll N,M,T;
	// vector<ll> mp;
	ll mp[100010];
	ll mx = 0;
	ll mod = 1000000007;
	cin >> N>>M;
	T=N+M;
	if(T%3==0)
	{
		N -= T/3;
		M -= T/3;
		if(N>=0 && M >=0)
		{
			T = N+M;
			N = min(N,M);
			ans = 1;
			for(i=0;i<N;++i)
			{
				ans *= (T-i);
				ans %= mod;
				ans *= div2mul(i+1, mod);
				ans %= mod;
			}
		}
	}
	cout << ans << endl;
	return 0;
}




















Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define max_v(v) *max_element(all(v));
#define min_v(v) *min_element(all(v));
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl
template <typename T> istream& operator >> (istream& is, vector<T>& vec) {
    for(T& x : vec) is >> x;
    return is;
}
template<typename T> ostream& operator << (ostream& os, vector<T>& vec) {
    for(int i = 0; i < vec.size(); i++) {
        os << vec.at(i) << (i + 1 == vec.size() ? "" : " ");
    }
    return os;
}

int main() {
    int A, B, M;
    cin >> A >> B >> M;
    vector<int> R(A);
    vector<int> H(B);
    cin >> R >> H;
    vector<vector<int>> D(M, vector<int>(3));
    cin >> D;

    int mr = min_v(R);
    int mh = min_v(H);
    int min_sum = mr + mh;
    rep(i, M) {
        int tmp = R.at(D.at(i).at(0) - 1) + H.at(D.at(i).at(1) - 1) - D.at(i).at(2);
        min_sum = min(min_sum, tmp);
    }

    cout << min_sum << endl;
}

Measured memory_bytes: 6528
import java.util.*;
public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
        int[] a = new int[N+2];
        a[0] = 0;
        a[N+1] = 0;
        int cnt = 0;
        for (int i = 1; i < N+1; i++) {
            a[i] = sc.nextInt();
            cnt += Math.abs(a[i] - a[i-1]); 
        }
        cnt += Math.abs(a[N+1] - a[N]);
        for (int i = 1; i < N+1; i++) {
            int tmp = cnt - Math.abs(a[i+1] - a[i]) - Math.abs(a[i]- a[i-1]) + Math.abs(a[i+1]- a[i-1]);
            System.out.println(tmp);
        }
    }

}

Measured memory_bytes: 72872
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		string s,t;
		cin >> s >> t;
		int n = sz(s), m = sz(t);
		int dp[n+1][m+1];
		rep(i,0,n+1){
			rep(j,0,m+1){
				if(i==0 || j==0) dp[i][j] = 1;
				else dp[i][j] = 0;
			}
		}
		int par[n+1][m+1];
		rep(i,1,n+1){
			rep(j,1,m+1){
				if(dp[i][j]<dp[i-1][j]){
					dp[i][j] = dp[i-1][j];
					par[i][j] = 1;
				}
				if(dp[i][j]<dp[i][j-1]){
					dp[i][j] = dp[i][j-1];
					par[i][j] = 2;
				}
				if(dp[i][j]<dp[i-1][j-1]+(s[i-1]==t[j-1])){
					dp[i][j] = dp[i-1][j-1]+1;
					par[i][j] = 3;
				}
			}
		}
		int curi = n, curj = m;
		string p;
		// trace(dp[2][4]);
		while(curi || curj){
			// trace(curi, curj, par[curi][curj]);
			if(par[curi][curj]==3){
				p.pb(s[curi-1]);
				curi--;
				curj--;
			}
			else if(par[curi][curj]==2) curj--;
			else if(par[curi][curj]==1) curi--;
			else break;
		}
		// if(curi==1 && curj==1 && par[curi][curj]==3) p.pb(s[curi-1]);
		reverse(all(p));
		cout<<p;
	}
}

Measured memory_bytes: 140928
#include<bits/stdc++.h>
#define INF 0x3f3f3f3f
const int MOD=1e9+7;
const double eps=1e-8;
typedef long long ll;
//orz yht
using namespace std;
string s;
bool is(string str)
{
    string st = str;
    std::reverse(str.begin(), str.end());
    return (st == str);
}
int main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>s;
	int n=s.size();
	if(is(s) && is(s.substr(0,(n-1)/2)) && is(s.substr((n+3)/2-1,(n-(n+3)/2+1))))
	cout<<"Yes";
	else
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string debug_string(const string& s) {
	return '"' + s + '"';
}
string debug_string(bool b) {
	return (b ? "true" : "false");
}
string debug_string(const char* s) {
	return debug_string((string)s);
}
template<class T, class U>
string debug_string(const pair<T, U>& p);
template<class U>
struct can_be_string {
	template<typename...>
	static int f(...) {
		return 0;
	}
	template<typename T>
	static char f(decltype(to_string(T()), char())) { 
		return 'a';
	}
	static const bool value = sizeof(f<U>(char())) == sizeof(char);
};
template<class T> 
typename enable_if<can_be_string<T>::value, string>::type debug_string(const T& a) {
	string s = to_string(a);
	return s;
}
template<class T>
typename enable_if<!can_be_string<T>::value, string>::type debug_string(const T& a) {
	bool first = true;
	string s = "{";
	for (const auto& x : a) {
		if(!first){
			s += ", ";
		}
		first = false;
		s += debug_string(x);
	}
	s += "}";
	return s;
}
template<class T, class U>
string debug_string(const pair<T, U>& p) {
	string s = "(";
	s += debug_string(p.first);
	s += ", ";
	s += debug_string(p.second);
	s += ")";
	return s;
}
void debug_out() {cerr << '\n';}
template<class Head, class... Tail>
void debug_out(Head head, Tail... tail) {
	cerr << ' ' << debug_string(head);
	debug_out(tail...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "] = ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif
using ll = long long;
using ld = long double;
const int mod = 1e9 + 7;
const int mod2 = 1e9 + 9;
const int inf = 1e9 + 100;
const ll inf64 = 1e18l + 100;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(20);
	int n;
	cin >> n;
	ld odd = 0;
	if (n % 2 == 0) {
		odd = n / 2;
	}
	else {
		odd = n / 2 + 1;
	}
	cout << odd / n << '\n';
	return 0;
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout << "Case #" <<qqq+1<<": "
#define res resize
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout << a<<" "<<b <<" "<< c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
 
typedef long long ll;
typedef pair<int,int> P;
//typedef long long T;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;

int main(){
    int n;
    std::cin >> n;
    int ans=0;
    rep(i,n){
        int l,r;
        std::cin >> l>>r;
        ans+=r-l+1;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int k;
    int a, b;
    cin >> k >> a >> b;

    for (int i = a; i <= b; ++i) {
        if (i % k == 0) {
            cout << "OK\n";
            return 0;
        }
    }

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

Measured memory_bytes: 3584
n = gets.to_i
ab = n.times.map {gets.split.map(&:to_i)}

if n.odd?
    ab.sort_by!{|a,b| a}
    x = ab[n/2][0]
    ab.sort_by!{|a,b| b}
    y = ab[n/2][1]
    p y - x + 1
else
    ab.sort_by!{|a,b| a}
    x1, x2 = ab[n/2-1][0], ab[n/2][0]
    ab.sort_by!{|a,b| b}
    y1, y2 = ab[n/2-1][1], ab[n/2][1]

    p (y1 + y2) - (x1 + x2) + 1
end

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

const int maxn = 2e5 + 10;

int cnt[2], ans[maxn];
vector<int> g[maxn], p[2];

void dfs(int o,int d,int pa = 0) {
	cnt[d&1] += 1;
	p[d&1].push_back(o);
	for(auto u : g[o]) if(u != pa) dfs(u, d + 1, o);
}
int main() {
	int n;
	scanf("%d", &n);
	for(int i = 1;i < n;++i) {
		int a , b;
		scanf("%d%d", &a, &b);
		g[a].push_back(b);
		g[b].push_back(a);
	}
	dfs(1, 0);
	int a = 0,b = 1;
	if(cnt[a] > cnt[b]) swap(a, b);
	int o = 1, t = 2, z = 3;
	if(cnt[a] <= (n / 3)) {
		for(auto u : p[a]) {
			if(z <= n) ans[u] = z, z += 3;
		}
		for(auto u : p[b]) {
			if(z <= n) ans[u] = z, z += 3;
			else if(o <= n) ans[u] = o, o += 3;
			else ans[u] = t,t += 3;
		}
	}
	else {
		for(auto u : p[a]) {
			if(o <= n) ans[u] = o, o += 3;
			else if(z <= n) ans[u] = z, z += 3;
		}
		for(auto u : p[b]) {
			if(t <= n) ans[u] = t,t += 3;
			else if(z <= n) ans[u] = z, z += 3;
			// else ans[u] = o,o += 3;
		}
	}

	for(int i = 1;i <= n;++i) printf("%d%c", ans[i], i == n ?'\n' :' ');
}

Measured memory_bytes: 21620
#include <bits/stdc++.h>
#define REP(i, n) for (int (i) = 0; (i) < (int)(n); i++) 
#define FOR(i, a, b) for(int (i) = a; (i) < (int)b; i++)
#define RREP(i, n) for(int (i)=((int)(n)-1); (i)>=0; i--)
#define RFOR(i, a, b) for(int (i) =((int)(b)-1); (i)>=0; i--)
#define ALL(v) (v).begin(),(v).end()
#define MOD 1000000007
#define F first
#define S second

using namespace std ;
typedef long long ll;
typedef vector<int> vint;
typedef vector<vint> vvint;
typedef pair<int, int> pint;

int main()
{
  int n ;
  cin >> n ;
  vector<int> pri(n) ;
  int sum = 0 ;
  
  REP(i,n){
    cin >> pri.at(i) ;
  }
  
  sort(ALL(pri)) ;
  reverse(ALL(pri)) ;
  
  pri.at(0) = pri.at(0)/2 ;
  
  REP(i,n){
    sum += pri.at(i) ;
  }
  
  cout << sum <<endl ;

  return 0 ;
}


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

int main()
{
  int a;
  int b;
  int c;
  int d;
  int e;
  int f;
  int g;
  
  cin >> a;
  cin >> b;
 
  if(a >= b){
    cout<<10<<endl;
  }else{
    cout<<0<<endl;
  }
}





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

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

    ll sign = 1;
    ll x0 = 0;
    rep(i,n) {
        x0 += sign * a[i];
        sign *= -1;
    }

    ll x[n];
    x[0] = x0;
    for (int i=1; i<n; i++) {
        x[i] = 2* (a[i-1] - x[i-1]/2);
    }

    rep(i,n) printf("%lld%c", x[i], i==n-1? '\n' : ' ');


    return 0;
}


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

int main() {
	int n, m;
	cin >> n >> m;
	if (n == m) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array
-- import Data.Array.Unboxed
import Control.Monad.ST
import Data.Array.ST

main :: IO ()
main = do
  n <- readLn :: IO Int
  (s:t:_) <- words <$> getLine :: IO [String]
  putStrLn $ solve s t

solve :: String -> String -> String
solve s t = foldl' (\acc (s, t) -> acc ++ [s, t]) [] $ zip s t

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

int main(){
    
    while(1){
    
    int h,w;
    
    cin>>h>>w;
    
    if(h==0&&w==0) break;
    
    for(int i=0; i<h; i++){
        for(int j=0; j<w; j++){
            
            cout<<"#";
        }
        cout<<endl;
        }
    
        cout<<endl;
    }   

    return 0;
}



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

typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<vector<int>> vvi;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'

struct custom_hash {    // anti-hack for unordered_map. To declare: unordered_map<long long, int, custom_hash> safe_map;
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        x ^= FIXED_RANDOM;
        return x ^ (x >> 16);
    }
};

ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//

int dfs(vector<vi>&adj, vector<int>&maxpath, vector<bool>&visited, int v)
{
    visited[v] = true;
    int total = 1;
    for(auto i: adj[v])
    {
        if(!visited[i])
        {
            dfs(adj,maxpath,visited,i);
        }
        total = max(total, maxpath[i]+1);
    }
    maxpath[v] = total;
    return total+1;
}


void solve()
{
    int n, m;
    cin >> n >> m;
    vector<vi>adj(n+1);
    for(int i=0; i<m; i++)
    {
        int u, v;
        cin >> u >> v;
        adj[u].pb(v);
    }
    vector<bool>visited(n+1,false);
    vector<int>maxpath(n+1,0);
    int res = 0;
    for(int i=1;i<=n;i++)
    {
        if(!visited[i])
            dfs(adj,maxpath,visited,i);
        res = max(maxpath[i],res);
    }
    // cout<<"--------\n";
    // for(int i=1;i<=n;i++)cout<<i<<' '<<maxpath[i]<<'\n';
    cout<<res-1<<'\n';
}

int main()
{
	fastio;
    int T;
    // cin>>T;
    // while(T--)
        solve();
	return 0;
}

Measured memory_bytes: 12336
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 998244353;

int main(){
  ll n,m;
  cin >> n >> m;
  
  vector<vector<ll>>rl(m,vector<ll>(2));
  for(int i=0; i<m; i++){
    cin >> rl[i][1] >> rl[i][0];
  }
  
  sort(rl.begin(),rl.end());
  
  ll count = 1;
  ll cut = rl[0][0]-1;
  for(int i=0; i<m; i++){
    if(rl[i][1]>cut){
      count++; 
      cut = rl[i][0]-1;
    }
  }
  cout << count << endl;
  
}
  
  
  
  


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

using namespace std;
using p=pair<int,int>;
typedef long long ll;

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

 cout<<min(n%k,k-(n%k))<<endl;




    return 0;
}



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

using namespace std;

#define MP make_pair
#define PB push_back
#define f first
#define s second

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

//int dr1[] = {-1, 0, 1, 0};
//int dc1[] = {0, 1, 0, -1};
//int dr3[] = {0, 1, 2, 3, 2, 1, 0, -1, -2, -3, -2, -1, -1, 1, 0, 0};
//int dc3[] = {3, 2, 1, 0, -1, -2, -3, -2, -1, 0, 1, 2, 0, 0, -1, 1};
const int MOD = 1000000007;
const int INF = 1000000007;

ll modx(ll a)
{
    return (a%MOD+MOD)%MOD;
}

ll times(ll a, ll b)
{
    return modx(modx(a)*modx(b));
}

ll add(ll a, ll b)
{
    return modx(modx(a)+modx(b));
}

ll sub(ll a, ll b)
{
    return modx(MOD+modx(a)-modx(b));
}

ll fastExp(ll base, ll exp)
{
    if(exp == 0LL)
    {
        return 1LL;
    }

    if(exp%2==0)
    {
        return fastExp(times(base, base), exp/2);
    }
    else
    {
        return times(exp, fastExp(times(base, base), exp/2));
    }
}


const int MAXN = (int)1e5+1;
int N;


int main()
{
    //freopen("input.in","r",stdin);
    //freopen("output.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    if(s == "Sunny")
    {
        cout << "Cloudy";
    }
    if(s == "Cloudy")
    {
        cout << "Rainy";
    }
    if(s == "Rainy")
    {
        cout << "Sunny";
    }
    return 0;
}


Measured memory_bytes: 256
from collections import Counter

N, M = map(int, input().split())
numbers = Counter(int(n) for n in input().split())

# (数, 出現回数)
q = []

for k, v in numbers.items():
  q.append((k, v))

for _ in range(M):
  b, c = map(int, input().split())
  q.append((c, b))
  
q.sort(reverse=True)

bigger = []

for k, v in q:
  if len(bigger) >= N:
    break
  for _ in range(v):
    bigger.append(k)
    if len(bigger) >= N:
      break

print(sum(bigger))

Measured memory_bytes: 93720
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    string s;
	cin >> s;
    int n = s.size();
    int ans=0;
    string a,b;
    fr(i,n){
      a = s.substr(i, 1);
      if(a==b){
        i++;
        if(i>=n)break;
        a+=s.substr(i, 1);
      }
      ans++;
      b=a;
    }
      cout << ans << endl;
}

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

const long long MOD = 1000000007;
const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int H, W;
  string S;
  cin >> S;
  bool can = true;
  reverse(S.begin(), S.end());
  cerr << S << endl;
  vector<string> candidate{"dream", "dreamer", "erase", "eraser"};
  for (auto &s : candidate)
    reverse(s.begin(), s.end()), cerr << s << endl;

  int i = 0;
  while (i < S.size())
  {
    if (S[i] == 'm')
    {
      if (S.substr(i, 5) == candidate[0])
        i += 5;
      else
      {
        can = false;
        break;
      }
    }
    else if (S[i] == 'e')
    {
      if (S.substr(i, 5) == candidate[2])
        i += 5;
      else
      {
        can = false;
        break;
      }
    }
    else if (S[i] == 'r')
    {
      cerr << "a" << endl;
      if (S[i + 1] != 'e')
      {
        cerr << "b" << endl;
        can = false;
        break;
      }
      else
      {
        if (S[i + 2] == 'm')
        {
          if (S.substr(i, 7) == candidate[1])
            i += 7;
          else
          {
            cerr << "c" << endl;
            can = false;
            break;
          }
        }
        else if (S[i + 2] == 's')
        {
          cerr << S.substr(i, 6) << " " << candidate[3] << endl;
          if (S.substr(i, 6) == candidate[3])
            i += 6;
          else
          {
            cerr << "d" << endl;
            can = false;
            break;
          }
        }
        else
        {
          cerr << "e" << endl;
          can = false;
          break;
        }
      }
    }
  }
  if (can)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 512
import java.util.*

fun main(args : Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    val p = mutableListOf<Pair<Int, Int>>()
    (0 until N).forEach {
        val (a, b) = readLine()!!.split(" ").map { it.toInt() }
        p.add(Pair(a, b))
    }
    p.sortBy {
        it.first
    }

    var anser = 0L
    val queue = PriorityQueue<Int>()
    var pointer = 0
    (M -1 downTo  0).forEach {
       val a = M - it
       while (pointer < N && p[pointer].first <= a) {
           queue.offer(-1 * p[pointer].second)
           pointer++
       }
        if (!queue.isEmpty()) {
            val value = queue.poll()
            anser += -1 * value
        }
    }
    println(anser)
}

Measured memory_bytes: 77840
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define vsort(v) sort(v.begin(), v.end());
#define rvisort(v) sort(v.begin(), v.end(), greater<int>());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
// #define int long long
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())
 
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using ul = unsigned long;
 
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
 
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
ll LCM(ll a, ll b) { return a / GCD(a, b)* b; }
 
const int dy[] = {0, 1, 0, -1, -1, 1, 1, -1};
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
 
inline bool inside(int y, int x, int H, int W) {
    return (y >= 0 && x >= 0 && y < H && x < W);
}
 
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  
  int n; cin>>n;
  string p="", q="";
  rep(_,n){
    char c; cin>>c; p+=c;
  }
  rep(_,n){
    char c; cin>>c; q+=c;
  }
  // cout<<p<<" "<<q<<endl;
  string s="";
  reps(i,n) s+=to_string(i);
  int cnt=0;
  map<string,int> m;
  do{
    // cout<<s<<endl;
    m[s]=cnt;
    cnt++;
  }while(next_permutation(s.begin(),s.end()));
  
  cout<<abs(m[p]-m[q])<<endl;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int S, W;
    cin >> S >> W;
    cout << (W >= S ? "unsafe" : "safe") << endl;
    
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  int A, B;
  cin >> A >> B;
  int sum = B - A + 1;
  int count = 0;
  for(int i = 0; i < sum; i++){
    int n1 = (A + i) % 10;
    int n10 = (A + i) % 100;
    int n100 = (A + i) % 1000;
    int n1000 = (A + i) % 10000;
    int n2 = n10 / 10;
    int n3 = n100 / 100;
    int n4 = n1000 / 1000;
    int n5 = (A + i) / 10000;
    if(n1 == n5){
      if(n2 == n4){
        count++;
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256