akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main(){
    using namespace std;
    size_t n, m;
    while(cin >> n >> m && n && m){
        vector<size_t> z(n), ih(n), v;
        size_t sz{0};
        {
            vector<size_t> h(n);
            copy_n(istream_iterator<size_t>(cin), n, h.begin());
            iota(ih.begin(), ih.end(), 0UL);
            stable_sort(ih.begin(), ih.end(), [&h](auto i, auto j){return h[i] < h[j];});
            for(size_t i = 1, j = 0; i < n; ++i)z[ih[i]] = h[ih[i]] == h[ih[i - 1]] ? z[ih[i - 1]] : ++j;
            sort(h.begin(), h.end());
            h.erase(unique(h.begin(), h.end()), h.end());
            sz = h.size();
            v = vector<size_t>(sz);
            size_t k = 0;
            for(auto& i : v){
                do{
                    ++k;
                    ++i;
                }while(k < n && z[ih[k]] == z[ih[k - 1]]);
            }
        }
        vector<vector<pair<size_t, pair<size_t, size_t>>>> edge(sz);
        vector<pair<size_t, pair<size_t, size_t>>> ie;
        for(size_t i = 0, a, b, c; i < m; ++i){
            cin >> a >> b >> c;
            if(z[--a] < z[--b])swap(a, b);
            edge[z[b]].emplace_back(c, make_pair(a, b));
        }
        for(auto& i : edge)sort(i.begin(), i.end());
        class union_find{
            vector<long> v;
        public:
            union_find(size_t _n) : v(_n, -1) {}
            size_t find(size_t i){return v[i] < 0 ? i : static_cast<size_t>(v[i] = find(v[i]));}
            bool unite(long i, long j){
                i = find(i);
                j = find(j);
                if(i == j)return false;
                if(v[i] > v[j])swap(i, j);
                v[i] += v[j];
                v[j] = i;
                return true;
            }
        };
        auto tm = [&n, &z, &sz, &edge, &ih, &v]{
            union_find uf{n};
            size_t t{0}, ret{sz};
            for(size_t cnt = sz; cnt--;){
                t += v[cnt];
                for(const auto& i : edge[cnt])if(uf.unite(i.second.first, i.second.second))--t;
                if(t > 1)ret = cnt;
            }
            return ret;
        }();
        if(!tm){
            puts("0");
            continue;
        }
        union_find uf{n};
        size_t ans{0}, t{0};
        priority_queue<pair<size_t, pair<size_t, size_t>>, vector<pair<size_t, pair<size_t, size_t>>>, greater<>> pq{};
        for(size_t cnt = sz; cnt--;){
            t += v[cnt];
            for(const auto& i : edge[cnt])pq.push(i);
            if(cnt < tm)while(!pq.empty() && t > 1){
                auto i = pq.top();
                pq.pop();
                if(uf.unite(i.second.first, i.second.second)){
                    ans += i.first;
                    --t;
                }
            }
        }
        cout << ans << endl;
    }
}


Measured memory_bytes: 5052
import numpy as np
N = int(input())
A = np.array(input().split(), dtype=np.int32)

"""
A = [10,4,8,7,3]
left_idx = [0,0,2,2,2]
というものを作る
"""
left_idx = np.arange(N) # [0,1,2,3,4]
left_idx[1:][A[:-1] >= A[1:]] = 0 # [0,0,2,0,0] （自身が左以下ならば0に）
np.maximum.accumulate(left_idx, out=left_idx) # [0,0,2,2,2]

answer = (np.arange(N) - left_idx).max()
print(answer)

Measured memory_bytes: 24256
#include <iostream>
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,m,n) for(int (i)=(m);(i)<(n); i++)
#define REP(i, n) for(int (i)=0;(i)<(n);(i)++)
//------
#define R2(i,in,j,jn) REP(i,in)REP(j,jn)

using namespace std;


int main(void){
	int M1, D1, M2, D2;
	cin>>M1>>D1>>M2>>D2;
	cout << (M1!=M2);
	return 0;
}

Measured memory_bytes: 256
import scala.io.StdIn

object Main extends App {

  var head = 0
  var tail = 0
  
  val Array(n, q) = StdIn.readLine().trim.split(' ').map(_.toInt)
  val max  = n + 1 
  val myqueue: Array[ProceesInfo] = new Array[ProceesInfo](max)

  case class ProceesInfo(name: String, time: Int) 
  
  def isEmpty() = head == tail
  
  def isFull() = head == ((tail + 1) % max)
  
  def enqueue(p: ProceesInfo) = {
    if(isFull()) throw new RuntimeException
    else {
      myqueue(tail) = p
      if(tail + 1 == max){
        tail = 0
      } else {
        tail += 1
      }
    }
  }
  
  def dequeue(): ProceesInfo = {
    if(head == tail) throw new RuntimeException
    else {
      val ret = myqueue(head)
      if(head + 1 == max){
        head = 0
      } else {
        head += 1
      }
      ret
    }
  }
  
  (0 until n).foreach{ _ =>
    val Array(ename, etime) = StdIn.readLine().trim.split(' ')
    enqueue(ProceesInfo(ename, etime.toInt))
  }
  
  var executeTime: Int = 0
  while(head != tail){
    val current = dequeue()
    val remaintime = if((current.time - q) < 0) 0 else current.time - q
    
    executeTime  += (if((current.time - q) < 0) current.time else q)
    
    val executed = ProceesInfo(current.name, remaintime)  
    if(executed.time == 0){
      println(executed.name + " " + executeTime)
    } else {
      enqueue(executed)
    }
  }
  
}



Measured memory_bytes: 115624
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<string>
 
using namespace std;
 
 
const int MAX_N = int(1e6) + 10;
long long int MOD=1e9+7;
const long long int INF=1e18;
 
typedef long long int ll;
typedef unsigned long long int llu;
 
 
 
inline ll mul(ll a,ll b){
 
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll c=a*b;
    c=(c+MOD)%MOD;
    return c;
}
inline ll add(ll a,ll b){
    a=(a+MOD)%MOD;
    b=(b+MOD)%MOD;
    ll ans=(a+b);
    ans=(ans+MOD)%MOD;
    return ans;
}
ll power(ll a,ll b,ll c=0){
    ll ans=1;
    while(b){
        if(b&1){
            ans=mul(ans,a);
        }
        a=mul(a,a);
        b=b/2;
    }
    return ans;
}
 
  
 
 
#define all(x) (x).begin(),(x).end()
 
 
 
 
//s.reserve(32768); //updated !
//s.max_load_factor(0.25);



int main(){
    


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

    while(b<=a){
        b=b*2;
        k--;
    }

    while(c<=b){
        c=c*2;
        k--;
    }

    if(k>=0)cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";
}
 
    
 
 
 
    
 
 
 
    
    
    
 
 
 
 
    
 
 
    
 
    
 
 
 
 
 
 
    
    
 
    
 
    
 
 
 
 
    
 


Measured memory_bytes: 3624
# include <bits/stdc++.h>
# define INF 1e9
using namespace std;

int main(){

  int N;
  cin >> N;
  vector<string> v;
  v.push_back("");
  int ans = 0;
  vector<char> digit = {'3','5','7'};
  while(v.size() > 0){
    vector<string> temp;
    for(int i=0; i< v.size(); i++){
      for(int j=0; j< digit.size(); j++){
        string s = v[i] + digit[j];
        if(stol(s) <= N){
          temp.push_back(s);
          bool flag = true;
          for(int k=0; k < digit.size(); k++){
            if(s.find(digit[k]) == string::npos){
              flag = false;
              break;
            }
          }
          if(flag) ans++;
        }
      }
    }
    v = temp;
  }
  cout << ans << endl;

}

Measured memory_bytes: 2172
import sys
read = sys.stdin.read
from math import sqrt, floor
def main():
    n = int(input())
    if n == 1:
        print(1)
        sys.exit()
    # nd:num of div
    nd = [2] * (n + 1)

    for i1 in range(2, floor(n / 2) + 1):
        for i2 in range(i1 * 2, n + 1, i1):
            nd[i2] += 1

    r = 1
    for j1 in range(2, n + 1):
        r += nd[j1] * j1
    print(r)

if __name__ == '__main__':
    main()

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

using namespace std;

int main() {
  int h, w;
  cin>>h>>w;
  char a[h][w];
  vector<vector<long int>> dp(h+1, vector<long int>(w+1, 0));
  
  for (int i=0;i<h;i++) {
    for (int j=0;j<w;j++) {
      cin>>a[i][j];
    }
  }
  dp[1][1] = 1;
  for (int i=1;i<=h;i++) {
    for (int j=1;j<=w;j++) {
      if (i == 1 && j == 1)
        continue;
      dp[i][j] = (dp[i-1][j] + dp[i][j-1]) % 1000000007;
      if (a[i-1][j-1] == '#')
        dp[i][j] = 0;
      
    }
  }
  cout<<dp[h][w]<<endl;
}

Measured memory_bytes: 10368
#include <cstring>
#include <iostream>
using namespace std;
int n, m, sum;
int main()
{
    cin >> n >> m >> sum;
    for (int i = 1; i <= m; i++)
    {
        cout << sum << " ";
    }
    int temp = n - m;
    for (int i = 1; i <= temp; i++)
    {
        if (sum == 1e9)
        {
            cout << sum - 1 << " ";
        }
        else
            cout << sum + 1 << " ";
    }
    return 0;
}

Measured memory_bytes: 3604
#include <cstdio>
#include <iostream>

using namespace std;

const int MAXN = 100005;

int n;
long long a[MAXN], b[MAXN];

long long compute(long long x, long long y) {
    if (x % y == 0) {
        return 0;
    }

    return y - (x % y);
}

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

    for (int i = 0; i < n; ++i) {
        scanf("%lld %lld", a + i, b + i);
    }

    long long steps = 0;
    for (int i = n - 1; i >= 0; --i) {
        steps += compute(a[i] + steps, b[i]);
    }

    printf("%lld\n", steps);

    return 0;
}


Measured memory_bytes: 1792
s = input()
K = int(input())
ans = []
for i in set(s):
    ans.append(i)

if K == 1:
    print(sorted(ans)[0])
else:
    for i in range(2, 6):
        for j in range(len(s) - i + 1):
            ans.append(s[j:j+i])
    ans = list(set(ans))
    ans.sort()
    print(ans[K - 1])

Measured memory_bytes: 4980
import sys,os
import math
from fractions import Fraction 
from collections import defaultdict
from random import randint

# sys.stderr=open('err.txt','w')
# sys.stdout=open('output.txt','w')
# sys.stdin=open('input.txt','r')

def linput():
    return list(minput())

def minput():
    return map(int, sys.stdin.readline().strip().split())

###############################################################

d,t,s=minput()
if d/s>t:
    print("No")
else:
    print("Yes")

Measured memory_bytes: 10796
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		prepareFact();
		int n = sc.nextInt();
		int m = sc.nextInt();
		int sum = m * 3;
		long ans = H(n, sum);
		for(int i = m * 2 + 1; i <= sum; i ++) {
			long tmp = H(n - 1, sum - i);
			tmp = mod(tmp * (long)n);
			ans = mod(ans - tmp);
		}

		long minus = 0;
		for(int i = m + 2; i <= n; i += 2) {
			long tmp = H(n, (sum - i) / 2);
			tmp = mod(tmp * C(n, i));
			minus = mod(minus + tmp);
		}
		ans = mod(ans - minus);
		System.out.println(ans);
	}

	static long MOD = 998244353;
	public static long mod(long i) {
		return i % MOD + ((i % MOD) < 0 ? MOD : 0);
	}
	
	static long pow(long x, long y) {
		if (y == 0) {
			return 1;
		} else if (y == 1) {
			return x;
		} else if (y % 2 == 0) {
			long tmp = pow(x, y / 2);
			return mod(tmp * tmp);
		} else {
			long tmp = pow(x, y / 2);
			return mod(mod(tmp * tmp) * x);
		}
	}
	
	static long inv(long x) {
		return pow(x, MOD - 2);
	}
	
	static int MAX_FACT = 2_500_100;
	static long fact[] = new long[MAX_FACT];
	static long invFact[] = new long[MAX_FACT];
	static void prepareFact() {
		fact[0] = 1;
		for(int i = 1; i < MAX_FACT; i ++) {
			fact[i] = mod(fact[i - 1] * i);
		}
		invFact[MAX_FACT - 1] = inv(fact[MAX_FACT - 1]);
		for(int i = MAX_FACT - 1; i > 0; i --) {
			invFact[i - 1] = mod(invFact[i] * i);
		}
	}

	static long P(int n, int r) {
		if(n < 0 || r < 0 || n < r) { return 0; }
		return mod(fact[n] * invFact[n - r]);
	}
	static long C(int n, int r) {
		if(n < 0 || r < 0 || n < r) { return 0; }
		return mod(P(n, r) * invFact[r]);
	}
	static long H(int n, int r) {
		return C((n - 1) + r, r);
	}
}

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

signed main(){
    int n;
    long long a[100005] , ans = 1 , tem = 1 , inf = 1000000000000000000;
    bool of = true;
    
    cin >> n;
    for(int i=0 ;i<n ;i++ ){
        cin >> a[i];
    }
    sort(a , a+n);
    
    for(int i=0 ;i<n ;i++ ){
        ans *= a[i];
        if( (tem > ans && a[i] != 0) || ans > inf){
            of = false;
        }
        tem = ans;
    }
    
    if(of){
        cout << ans << endl;
    } else {
        cout << "-1\n";
    }
    return(0);
}

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

int main(){
    int N;
    cin>>N;
    vector<int>V(N);
    vector<int>C(N);
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    for(int i=0;i<N;i++){
        cin>>C[i];
    }
    int sub=0;
    for(int i=0;i<N;i++){
        if(V[i]-C[i]>0){
            sub+=V[i]-C[i];
        }
    }
    cout<<sub<<endl;
}

Measured memory_bytes: 256
from functools import reduce
from fractions import gcd
import math
import bisect
import itertools
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
INF = float("inf")


def main():
    S = input()

    cnt = 0
    ans = 0
    for i in range(len(S)):
        if S[i] == "W":
            ans += i - cnt
            cnt += 1
    
    print(ans)


if __name__ == '__main__':
    main()

Measured memory_bytes: 5440
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
#define rrep(i,n) for(int (i) = (n) - 1; (i) >= 0; --(i)) //Reversi rep
#define nfor(i,a,b) for(int (i) = (a); (i) < (b); ++(i)) //Natural for
#define rfor(i,a,b) for(int (i) = (b); (i) >= (a); --(i)) //Reversi for
#define mod (1000000007)
#define YES cout << "YES" << endl;
#define Yes cout << "Yes" << endl;
#define NO cout << "NO" << endl;
#define No cout << "No" << endl;

int asc(const void *a, const void *b) {
    return *(int *)a - *(int *)b;
}

int desc(const void *a, const void *b) {
    return *(int *)b - *(int *)a;
}

int main()
{
    string s;
    bool a = false,b = false;
    cin >> s;
    rep(i, s.size())if(s[i] == 'C') a = true; else if(s[i] == 'F' && a)b =true;
    if (a && b) {
        Yes;
    }else{
        No;
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <iomanip>
#include <functional>
#include <bitset>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cassert>
#include <random>

#ifdef DEBUG
#include "library/Utility/debug.cpp"
#else
#define debug(...)
#endif

#define rep(i,n) for(int i=0;i<(n);++i)
#define EL '\n'
#define print(i) std::cout << (i) << '\n'
#define all(v) (v).begin(), (v).end()
using lnt = long long;
struct FIO{FIO(){std::cin.tie(0);std::cout.tie(0);std::ios_base::sync_with_stdio(0);std::cout<<std::fixed<<std::setprecision(15);}}fIO;
/*-*/

int main() {
	std::string s;
	std::cin >> s;
	char curr = 'A';
	int ans=0;
	for(auto c:s) {
		if(curr<c) curr=c;
		else {
			ans++;
			curr=c;
		}
	}
	print(ans);
}



Measured memory_bytes: 3224
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
	int a,a1,a2,a3,i,sum=0,avg=0;
	while(1){
		cin>>a;
		if(a==0) break;
		for(i=0;i<a;i++){
			cin>>a1>>a2>>a3;
			sum=a1+a2+a3;
			avg=sum/3;
			if(a1==100||a2==100||a3==100||avg>=80||(a1+a2)/2>=90)
				printf("A\n");
			else if(avg>=70||
				avg>=50&&a1>=80||
				avg>=50&&a2>=80)
				printf("B\n");
			else
				printf("C\n");
		}
	}
	return 0;
}

Measured memory_bytes: 1116
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007


ll findpow(ll a,ll b){
    ll cnt=0,i,j;
    while(a>1){
        a=a/b;
        cnt++;
    }
    return cnt;
}


int main(){
    ll i,j,k,sum=0,n,sum1=0,t,ans=1000000000,p,max1=0,l=0,m;
    string c;
    cin>>n>>m;
    cout<<(n*(n-1)/2)+(m*(m-1)/2)<<endl;
    
    
    
   
   
   
    
    
	return 0;
}

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

using namespace std;

typedef long long LL;
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int main(){
	int N; cin >> N;
	const LL mod = 1e9+7;
	LL ans = 1;
	vector<LL> x(2e5+1,0);
	int b = 0;
	repp(i,0,N){
		int c; cin >> c;
		if(b != c){
			x[b] = ans;
			b = c;
			(ans += x[c]) %= mod;
		}
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int n,k,m=1,a;
int main()
{
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	{
		a=m;
		if(k<=a)	m=m+k;
		else
			m=m*2;
	}
	printf("%d\n",m);
	return 0;
}

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

string s;
int p,a,b,c,d,now=0,pp;

int solve();


int main(){
  int i,j,k,l,ansc;
  while(1){
    cin >> s;
    if(s==".")break;
    ansc=0;
    cin >> p;
    d=p%10;
    p/=10;
    c=p%10;
    p/=10;
    b=p%10;
    p/=10;
    a=p%10;
    now=0;
    pp = solve();
    for(i=0;i<10;i++)for(j=0;j<10;j++)for(k=0;k<10;k++)for(l=0;l<10;l++){
	    a = i;
	    b = j;
	    c = k;
	    d = l;
	    now = 0;
	    if(pp==solve())ansc++;
	  }
    cout << pp << ' '<< ansc << endl;
  }
  return 0;
}

int solve(){
  int ans1=0,ans2=0;
  char x;
  if(s[now]=='['){
    now++;
    x=s[now];
    now++;
    ans1 = solve();
    ans2 = solve();
    now++;
    //cout << ans1<< " " << ans2 <<" "<< x<< endl;
    if(x=='+')return ans1|ans2;
    else if(x=='*')return ans1&ans2;
    else if(x=='^')return ans1^ans2;
  }
  if(s[now]>='a'||s[now]<='d'){
    now++;
    //cout << s[now-1] << endl;
    if(s[now-1]=='a')return a;
    if(s[now-1]=='b')return b;
    if(s[now-1]=='c')return c;
    if(s[now-1]=='d')return d;
  }
}



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

int main()
{
  int a, b;
  cin >> a >> b;
  if (a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0) cout << "Possible" << endl;
  else cout << "Impossible" << endl;
}


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

#define rep(i, n) for ( ll i = 0; i < (n); ++i )
#define reps(i, n) for ( ll i = 1; i <= (n); ++i )
#define _rep(i, n) for ( ll i = (n) - 1; i >= 0; --i )
#define _reps(i, n) for ( ll i = n; i > 0; --i )
#define all(x) (x).begin(), (x).end()
#define _all(x) (x).rbegin(), (x).rend()

using namespace std;
using ll =  long long;
using P = pair<ll, ll>;

int main( void )
{
	ll n;
	cin >> n;

	switch( n % 10 ) {
		case 2:
		case 4:
		case 5:
		case 7:
		case 9:
			cout << "hon" << endl;
			return 0;

		case 0:
		case 1:
		case 6:
		case 8:
			cout << "pon" << endl;
			return 0;

		default:
			cout << "bon" << endl;
			break;
	}

	return 0;
}


Measured memory_bytes: 3636
#include<iostream>//c++的基本输入
#include<cstdio>//相当于stdio.h
#include<algorithm>//sort 的头文件
using namespace std;//命名空间
int main(){
  long long int m,n,k,l,sum=0,temp;
  scanf("%lld %lld",&m,&n);
  long long int a[m];
  if(n>=m){
    printf("0");
  }else{
        for(k=0;k<m;k++){
          scanf("%lld",&a[k]);
        }
        if(n==0){
            l=m-n;
            for(k=0;k<l;k++){
                sum+=a[k];
            }
            printf("%lld",sum);
        }else{
            
            l=m-n;
            sort(a,a+m);
            for(k=0;k<m-n;k++){
              sum+=a[k];
            }
            printf("%lld",sum);
              }
      }
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
 
int main(void)
{
 double x,y,r;
 double x1,x2,x3,y1,y2,y3;
 double ecm[3][2];
 double a,b,A;
 int i;
 int n;
 
 scanf("%d",&n);
 for(i = 0; i < n; i++)
 {
  scanf("%lf %lf %lf %lf %lf %lf",&x1,&y1,&x2,&y2,&x3,&y3);
  ecm[0][0] = x1 - x2;
  ecm[0][1] = y1 - y2;
  ecm[0][2] = (x2*x2 + y2*y2) - (x1*x1 + y1*y1);
  ecm[1][0] = x1 - x3;
  ecm[1][1] = y1 - y3;
  ecm[1][2] = (x3*x3 + y3*y3) - (x1*x1 + y1*y1);
  A = (ecm[0][0]*ecm[1][1])-(ecm[0][1]*ecm[1][0]); 
  a = ((ecm[0][2]*ecm[1][1])-(ecm[0][1]*ecm[1][2]))/A+0;
  b = ((ecm[0][0]*ecm[1][2])-(ecm[0][2]*ecm[1][0]))/A+0;
  x = (a/-2.0);
  y = (b/-2.0);
  r = sqrt(pow(x1-x,2)+pow(y1-y,2));
  printf("%.3f %.3f %.3f\n",x,y,r); 
 }
 return 0;
}
 

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

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

    for(int i = 10; i >=0; i--){
        if(pow(2,i)<=n){
            cout << pow(2,i) << endl;
            break;
        }
    }
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF = LL(1e18) + 1;
long double eps = 1.0E-14;
#define pow10(n) int(1e##n + n)

void solve()
{
    LL N;
    cin >> N;
    if (N % 2 == 1)
    {
        cout << 0 << endl;
        return;
    }
    LL ans = 0;
    LL d = 10;
    while (N >= d)
    {
        ans += (N / d);
        d *= 5;
    }

    cout << ans << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 256
/*
--------------              |   /
      |                     |  /
      |                     | /
      |             *       |/          |    |         ------            *
      |                     |           |    |        /      \
      |             |       |\          |    |       |       |\          |
   \  |             |       | \         |    |       |       | \         |
    \ |             |       |  \        |    |        \     /   \        |
     V              |       |   \        \__/|         -----     \       |
*/
#include <bits/stdc++.h>
using namespace std;

#define EmiliaMyWife ios::sync_with_stdio(0); cin.tie(NULL);
#define mem(i,j) memset(i,j,sizeof (i));
#define F first
#define S second
#define lowbit(x) ((x)&(-(x)))
#define siz(v) (long long)(v).size()
typedef int64_t ll;
typedef uint64_t ull;
const double EPS  = 1e-8;
const int INF     = 0x3F3F3F3F;
const ll LINF     = 4611686018427387903;
const int MOD     = 1e9+7;
/*-----------------------------------------------------------------------------------------------------*/
#define int ll
int dp[1001];

signed main() {
	EmiliaMyWife

    int d, nd;
    cin >> d >> nd;

    for(int i = 0, a, b; i < d; i++) {
        cin >> a >> b;
        for(int j = 1000; j; j--) {
            for(int k = min(a, j); k; k--) {
                dp[j] = max(dp[j], dp[j-k]+((i+1)*100*k)+(a==k)*b);
            }
        }
    }
    for(int i = 0; i <= 1000; i++)
        if(dp[i] >= nd)
            return cout << i, 0;

	return 0;
}


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

int main() {
  ll a, b, c;
  cin >> a >> b >> c;

  long double x = sqrt((long double)(4 * a * b));
  bool yes = x < (long double)(c - a - b);

  if (yes)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define desync ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define endl '\n'
#define pb push_back

int main(){
   desync;
   int n; cin >> n;
   n = n%1000;
   if(n == 0) cout << "0\n";
   else
      cout << (1000 - n) << endl;
   
}

Measured memory_bytes: 3616
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#define popcount __builtin_popcount
using namespace std;

/***/
//#include <iomanip>
//#include <cmath>
//#include <bits/stdc++.h>

#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define rrep(i,x) for(long long i=x-1;i>=0;i--)
#define rrepn(i,x) for(long long i=x;i>1;i--)

#define pr printf
#define re return
#define mod 1000000007
#define fi first
#define se second
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
/***/

typedef long long int ll;
typedef pair<int, int> P;
int n;
//vector<int> g[200020];
vector<pair<int,int>> g[200020];
ll s[200020];
bool used[200020];
int ans;

int main()
{
	ll wk;
	wk=0;
    cin.tie(0);
    ios::sync_with_stdio(false);
    
	string s;
	cin >> s;

	//bool dp[100005];
	
	bool dp[s.size()+1];
	rep(i,s.size()+1){
		dp[i]=0;
	}
	s.insert(0, " ");
	s[0]=' ';
	dp[0]=1;
	repn(i,s.size()){
		if(5<=i && s.substr(i-4,5)=="dream" && dp[i-5]==1){
			dp[i]=1;
		}
		if(7<=i && s.substr(i-6,7)=="dreamer" && dp[i-7]==1){
			dp[i]=1;
		}
		if(5<=i && s.substr(i-4,5)=="erase" && dp[i-5]==1){
			dp[i]=1;
		}
		if(6<=i && s.substr(i-5,6)=="eraser" && dp[i-6]==1){
			dp[i]=1;
		}
	}
	if(dp[s.size()-1]==1){
		puts("YES");
	}
	else{
		puts("NO");
	}
	re 0;
	return 0;
}


Measured memory_bytes: 5456
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{ return firstElof.second < secondElof.second; }
//**Snippetリスト**//
//rep, vin, all//
//gcdlcm, isPrime, eratos, modinv, bitSearch, bitList, dfs, bfs, dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; 
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; vl D;
//***********//
int main() {
	string S;
	cin >> S;
	ans = 1;
	if (S[0] != 'A') ans = 0;
	ll count = 0;
	for (i = 2; i < S.length()-1; i++) {
		count += (S[i] == 'C');
	}
	if (count != 1) ans = 0;
	for (i = 0; i < S.length(); i++) {
		if (S[i] != 'A' && S[i] != 'C' && (S[i] >= 'A' && S[i] <= 'Z')) ans = 0;
	}
	if (ans) cout << "AC";
	else cout << "WA";
}
	


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <queue>
#include <tuple>
#include <bitset>
#include <map>
#include <math.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
typedef pair<int,int> P;
const int inf = 1012345678;
int dx[] = {1,-1,0,0};
int dy[] = {0,0,1,-1};

int gcd(int a, int b)
{
  if (a%b==0){
    return(b);
  }
  else{
    return(gcd(b,a%b));
  }
}



int a[6];
int M = 10;
int mod;
int main(){
  string s;
  cin >> s;
  if(s == "Sunny") cout << "Cloudy" << endl;
  if(s == "Cloudy") cout << "Rainy" << endl;
  if(s == "Rainy") cout << "Sunny" << endl;
  


  return 0;
}


Measured memory_bytes: 256
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace C_test_For_Atcorder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var N = cin.ReadInt;
            var has = new HashSet<int>();
            for (int i = 0; i < N;i++)
                has.Add(cin.ReadInt);
            WriteLine(has.Count);
        }
    }


    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue inputStream;

        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return (string)inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return (string)inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
int main()
{
	long long int a,b,c,mix,tq;
	double sp;
	scanf("%lld %lld %lld",&a,&b,&c);
	
	sp = 2*sqrt(a*b);
	tq = c-a-b;
	if(tq<0)
	{
		printf("No");
	}
	else
	{
		if(4*a*b<tq*tq)
		printf("Yes");
		else
		{
			printf("No");
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll mod = 1e9+7;

int main(void){
  ll t1,t2;
  ll a1,a2;
  ll b1,b2;
  cin >> t1 >> t2;
  cin >> a1 >> a2;
  cin >> b1 >> b2;
  if(b1 > a1){
    swap(a1,b1);
    swap(a2,b2);
  }
  ll A = (a1 - b1) * t1;
  ll B = (b2 - a2) * t2;
  if(A == B){
    puts("infinity");
    return 0;
  }
  if(A > B){
    puts("0");
    return 0;
  }
  ll cnt = A / (B-A);
  if(A % (B-A) == 0){
    cout << 2 * cnt << endl;
  } else {
    cout <<  2 * cnt + 1 << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int main(int argc, char const *argv[])
{
  int n, m, answer[50];
  long a[50], b[50], c[50], d[50];
  int i, j, mindex;
  long min, temp;
  scanf("%d%d", &n, &m);
  for(i=0;i<n;i++) {
    scanf("%ld%ld", a+i, b+i);
  }
  for(i=0;i<m;i++) {
    scanf("%ld%ld", c+i, d+i);
  }
  for(i=0;i<n;i++) {
    j = 0;
    min = abs(a[i]-c[j]) + abs(b[i]-d[j]);
    mindex = 0;
    for(j=1;j<m;j++) {
      temp = abs(a[i]-c[j]) + abs(b[i]-d[j]);
      if(min > temp) {
        min = temp;
        mindex = j;
      }
    }
    answer[i] = mindex + 1;
  }
  for(i=0;i<n;i++) {
    printf("%d\n", answer[i]);
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 500005
using namespace std;
typedef long long ll;
struct P{
	long double t;
	ll v;
}a[N],q[N];
int n,L;
int main(){
	scanf("%d%d",&n,&L);
	for(int i=1;i<=n;i++) scanf("%Lf%lld",&a[i].t,&a[i].v);
	int tou=1,wei=1;
	ll sum=a[1].v;
	long double T=a[1].t*a[1].v;
	q[1]=a[1];
	printf("%.8Lf\n",a[1].t);
	for(int i=2;i<=n;i++){
		sum+=a[i].v;T+=a[i].t*a[i].v;
		while(sum>L){
			if(q[tou].v>sum-L) q[tou].v-=sum-L,T-=q[tou].t*(sum-L),sum=L;
			else sum-=q[tou].v,T-=q[tou].t*q[tou].v,tou++;
		}
		ll v=a[i].v;long double t=a[i].t;
		while(tou<=wei&&t<q[wei].t){
			t=(t*v+q[wei].t*q[wei].v)/(v+q[wei].v);
			v+=q[wei].v;
			wei--;
		}
		q[++wei].t=t;q[wei].v=v;
		printf("%.8Lf\n",T/sum);
	}
	return 0;
}

Measured memory_bytes: 40832
import itertools

N = int(input())
PER = []
for i in range(N):
    PER.append(i+1)

P = list(map(int,input().split()))
Q = list(map(int,input().split()))
a = 0
b = 0
tmp = 1

for x in itertools.permutations(PER):
     
    flag_a = 0
    flag_b = 0
 
    for i in range(N):
        if x[i] == P[i]:
            flag_a += 1   
        if x[i] == Q[i]:
            flag_b += 1
    if flag_b == N:
        b = tmp
    if flag_a == N:
        a = tmp
    tmp += 1

ans = a - b
if ans < 0:
    ans = - ans

print(ans)
        

Measured memory_bytes: 3064
class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		u.parent = v.root
		v.size += u.size
	end

	def same?(x, y)
		return false unless u = @obj_to_node[x]
		return false unless v = @obj_to_node[y]
		u.root == v.root
	end

	def root_of(x)
		u = @obj_to_node[x]
		u ? u.root : nil
	end
end

require 'set'
loop {
	w, h = gets.split.map &:to_i
	break if w == 0
	a = (1..h).map{ gets.chomp.split("") }
	color = (1..h).map{ (1..w).map{ Set.new } }
	uf = UnionFind.new
	(0..h-1).each{|i|
		(0..w-1).each{|j|
			uf.add([i,j])
			if i < h-1
				color[i][j] << :w if a[i][j] == ?. && a[i+1][j] == ?W
				color[i][j] << :b if a[i][j] == ?. && a[i+1][j] == ?B
				color[i+1][j] << :w if a[i+1][j] == ?. && a[i][j] == ?W
				color[i+1][j] << :b if a[i+1][j] == ?. && a[i][j] == ?B
				uf.union([i,j], [i+1, j]) if a[i][j] == ?. && a[i+1][j] == ?.
			end
			if j < w-1
				color[i][j] << :w if a[i][j] == ?. && a[i][j+1] == ?W
				color[i][j] << :b if a[i][j] == ?. && a[i][j+1] == ?B
				color[i][j+1] << :w if a[i][j+1] == ?. && a[i][j] == ?W
				color[i][j+1] << :b if a[i][j+1] == ?. && a[i][j] == ?B
				uf.union([i,j], [i, j+1]) if a[i][j] == ?. && a[i][j+1] == ?.
			end
		}
	}

	hash = {}
	(0..h-1).each{|i|
		(0..w-1).each{|j|
			r = uf.root_of([i,j])
			hash[r] ||= Set.new
			hash[r] += color[i][j]
		}
	}
	white = black = 0
	hash.each{|r, cs|
		next unless r
		white += r.size if cs.to_a == [:w]
		black += r.size if cs.to_a == [:b]
	}
	puts "#{black} #{white}"
}

Measured memory_bytes: 8532
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  
  //あんま理解はしていないが...
  int n;
  cin>>n;
  long long a[n];
  REP(i,n){
    cin>>a[i];
  }
  long long s=0;
  long long ans=0;
  REP(i,n){
    if(i%2==0){
      s += a[i];
      if(s>0)continue;
      ans += 1-s;
      s = 1;
    }else{
      s += a[i];
      if(s<0)continue;
      ans += s+1;
      s = -1;
    }
  }
  
  s = 0;
  long long temp=0;
  REP(i,n){
    if(i%2==0){
      s += a[i];
      if(s<0)continue;
      temp += s+1;
      s = -1;
    }else{
      s += a[i];
      if(s>0)continue;
      temp += 1-s;
      s = 1;
    }
  }
  
  ans = min(ans, temp);
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 1024
# coding: utf-8

import math

def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

N, M = map(int, input().split())
# print(N, M)
c_N = 0
c_M = 0

if N >= 2:
    c_N = comb(N, 2)
if M >= 2:
    c_M = comb(M, 2)
print(c_N + c_M)

Measured memory_bytes: 3060
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

K, N = MAP()
A = LIST()
diff = abs(K-A[-1]+A[0])
d = abs(K-A[-1]+A[0])
if N == 2:
	print(min(d, A[1]-A[0]))
	exit()
for i in range(1, N):
	d += abs(A[i]-A[i-1])
	diff = max(diff, abs(A[i]-A[i-1]))
print(d-diff)


Measured memory_bytes: 27812
while True:
    n = int(input())
    if n > 0:
        l = []
        for i in range(n):
            s = int(input())
        
            l.append(s)
        l.remove(max(l))
        l.remove(min(l))
        x = sum(l)
        y = len(l)
        print(int(x/y))
    if n == 0:
        break


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

int N, K;
vector<int> A;
int main() {
  cin >> N >> K;

  A.resize(N);
  vector<int> B(N);

  rep(i, N) {
    cin >> A[i];
    B[i] = (A[i] - 1 + K) % K;
  }

  ll ans = 0;

  vector<int> S(N + 1, 0);
  rep(i, N) S[i + 1] = (S[i] + B[i]) % K;

  map<int, vector<int>> m;
  rep(i, N + 1) m[S[i]].push_back(i);

  rep(i, N + 1) {
    auto it = lower_bound(all(m[S[i]]), i);
    auto it2 = lower_bound(all(m[S[i]]), i + K);
    ans += distance(it, it2) - 1;
  }

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


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

int main() {
  int64_t L0 = 2;
  int64_t L1 = 1;
  int N; cin >> N;
  vector<int64_t> l(N+1);
  l.at(0) = L0; l.at(1) = L1;
  for (int i=0; i<N-1; i++){
    l.at(i+2) = l.at(i) + l.at(i+1);
  }
  
  cout << l.at(N) <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  string s; 
  cin >> s;
  s = '0'+s;

  int N = s.size();

  vector<vector<int>> dp(N+1, vector<int>(2, INF));
  dp[0][0] = 0;
  REP(i, N){
    int d = s[i]-'0';
    chmin(dp[i+1][0], dp[i][0]+d);
    chmin(dp[i+1][1], dp[i][0]+d+1);
    chmin(dp[i+1][0], dp[i][1]+10-d);
    chmin(dp[i+1][1], dp[i][1]+9-d);
  }

  cout << dp[N][0] << "\n";

  return 0;
}

Measured memory_bytes: 55880
#include<bits/stdc++.h>
#define N 200005
#define Ms(a,b) memset(a,b,sizeof a);
#define db(x) cout<<#x<<"="<<x<<endl;
using namespace std;
int n,a[N],v[N],cnt,f;
int main() {
	scanf("%d",&n);
	for(int i=1; i<=n; i++)scanf("%d",&a[i]);
	for(int i=n; i>=1; i--) {
		int k=0;
		for(int j=i; j<=n; j+=i)k^=v[j];
		v[i]=k^a[i];
		cnt+=v[i];
	}
	printf("%d\n",cnt);
	for(int i=1; i<=n; i++)if(v[i]) {
			if(f)putchar(' ');
			else f=1;
			printf("%d",i);
		}
	return 0;
}


Measured memory_bytes: 2432
#include<iostream>
#include<cstdio>
using namespace std;
typedef long long ll;
const int Maxn=2e5+10;
int n,l,r,val[Maxn];
ll ans=0,cnt=0;
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;++i)
	  scanf("%d",&val[i]);
	ans=val[0];
	l=0,r=1;
	while(l<n){
		if(r<n&&(ans&val[r])==0){
			ans+=val[r];
			r++;
		}
		else{
		    ans-=val[l];
		    cnt+=r-l;
		    l++;
		    if(l>=r){
		    	r=l+1;
		    	ans=val[l];
			}
		}
	}
	printf("%lld",cnt);
	return 0;
}

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

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

    if(s==1) cout<<"1"<<endl;
    else if(s==2) cout<<"1"<<endl;
    else if(s==3) cout<<"1"<<endl;
    else if(s==4) cout<<"2"<<endl;
    else if(s==5) cout<<"1"<<endl;
    else if(s==6) cout<<"2"<<endl;
    else if(s==7) cout<<"1"<<endl;
    else if(s==8) cout<<"5"<<endl;
    else if(s==9) cout<<"2"<<endl;
    else if(s==10) cout<<"2"<<endl;
    else if(s==11) cout<<"1"<<endl;
    else if(s==12) cout<<"5"<<endl;
    else if(s==13) cout<<"1"<<endl;
    else if(s==14) cout<<"2"<<endl;
    else if(s==15) cout<<"1"<<endl;
    else if(s==16) cout<<"14"<<endl;
    else if(s==17) cout<<"1"<<endl;
    else if(s==18) cout<<"5"<<endl;
    else if(s==19) cout<<"1"<<endl;
    else if(s==20) cout<<"5"<<endl;
    else if(s==21) cout<<"2"<<endl;
    else if(s==22) cout<<"2"<<endl;
    else if(s==23) cout<<"1"<<endl;
    else if(s==24) cout<<"15"<<endl;
    else if(s==25) cout<<"2"<<endl;
    else if(s==26) cout<<"2"<<endl;
    else if(s==27) cout<<"5"<<endl;
    else if(s==28) cout<<"4"<<endl;
    else if(s==29) cout<<"1"<<endl;
    else if(s==30) cout<<"4"<<endl;
    else if(s==31) cout<<"1"<<endl;
    else if(s==32) cout<<"51"<<endl;


}


Measured memory_bytes: 3620
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int n;
long long a[300010],A[100010],B[100010],sum;
priority_queue<long long> BQ;
priority_queue<long long,vector<long long>,greater<long long> >AQ;
int main(){
	cin>>n;
	for(int i=0;i<3*n;i++)cin>>a[i];
	
	sum=0;
	for(int i=0;i<n;i++){
		AQ.push(a[i]);
		sum+=a[i];
	}A[0]=sum;
	for(int i=n;i<2*n;i++){
		if(a[i]>AQ.top()){
			sum-=AQ.top();
			sum+=a[i];
			AQ.pop();
			AQ.push(a[i]);
		}
		A[i-n+1]=sum;
	}
	
	sum=0;
	for(int i=2*n;i<3*n;i++){
		BQ.push(a[i]);
		sum+=a[i];
	}B[n]=sum;
	for(int i=2*n-1;i>=n;i--){
		if(a[i]<BQ.top()){
			sum-=BQ.top();
			sum+=a[i];
			BQ.pop();
			BQ.push(a[i]);
		}
		B[i-n]=sum;
	}
	
	long long ans=-114514114514810;
	for(int i=0;i<=n;i++){
		ans=max(ans,A[i]-B[i]);
		//cout<<"#"<<A[i]<<" "<<B[i]<<endl;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 5876
// #define _GLIBCXX_DEBUG // for STL debug (optional)
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;
using ll = long long int;
using int64 = long long int;
 
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
 
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
 
int main() {
    int N, W, H; scanf("%d%d%d", &N, &W, &H);
    H <<= 1, W <<= 1;
    
    const int P = 200010;
    vector<int> X(P+1), Y(P+1);
    for(int i=0; i<N; i++) {
        int x, y, w; scanf("%d%d%d", &x, &y, &w);
        x <<= 1, y <<= 1, w <<= 1;
        X[max(0, x-w)]++;
        X[min(W+1, x+w+1)]--;
        Y[max(0, y-w)]++;
        Y[min(H+1, y+w+1)]--;
    }

    bool ok1 = true, ok2 = true;
    for(int i=0; i<=W; i++) {
        if(i > 0) X[i] += X[i-1];
        ok1 &= (X[i] > 0);
    }
    for(int i=0; i<=H; i++) {
        if(i > 0) Y[i] += Y[i-1];
        ok2 &= (Y[i] > 0);
    }
    printf("%s\n", (ok1 || ok2) ? "Yes" : "No");
    return 0;
}




Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = a; i < b; ++i)
#define all(c) c.begin(), c.end() 
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
using namespace std;

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int k,x;
	cin >> k >> x;
	cout << (k * 500 >= x?"Yes":"No") << '\n';
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG

#include<bits/stdc++.h>
using namespace std;

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>
bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>
bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};
vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>&p){
  return os << p.first << " " << p.second;
}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll a,v,b,w,t;cin>>a>>v>>b>>w>>t;
  if(v<=w){
    cout<<"NO"<<endl;
    return 0;
  }
  ans2(abs(a-b)<=t*(v-w));
  return 0;
}

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

typedef long long LL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e4 + 10;

LL gcd(LL a, LL b)
{
	return b == 0 ? a : gcd(b, a % b);
}

LL qp(LL a, LL b)
{
	LL ans;
	for (ans = 1; b; b >>= 1, a = a * a % MOD)
		if (b & 1)
			ans = ans * a % MOD;
	return ans;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200)
		cout << s;
	else
		cout << "red";
	return 0;
}

Measured memory_bytes: 256