Harryxun/sft_time huggingface dataset:
### BUGGY CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

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

def F2_GaussJordan(A, is_extended = False):
    rank = 0
    for col in range(len(A[0])):
        if (is_extended and col == len(A[0])-1):
            break
        pivot = -1
        for row in range(rank,len(A)):
            if A[row][col]:
                pivot = row
                break
        if pivot == -1: 
            continue
        A[pivot],A[rank] = A[rank],A[pivot]
        for row in range(len(A)):
            if (row != rank and A[row][col]):
                A[row] = [A[row][j]^A[rank][j] for j in range(len(A[0]))]
        rank += 1
    return A

N = I()
A = III()

xor = 0
for i in range(N):
    xor ^= A[i]

max_digit = len(format(max(A), 'b'))

use_digit = []
ans = 0
for j in range(max_digit)[::-1]:
    if xor>>j & 1:
        ans += 2**j
    else:
        use_digit.append(j)

a = [[0]*max_digit for _ in range(N)]
k = 0
for k,j in enumerate(use_digit):
    for i in range(N):
        if A[i]>>j & 1:
            a[i][k] = 1
        else:
            a[i][k] = 0

g = F2_GaussJordan(a,False)

s = 0
for i in range(N):
    s = max(s,s^sum([g[i][j]*2**use_digit[j] for j in range(len(use_digit))]))
ans += 2*s

print(ans)

### FIXED CODE ###

import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

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

N = I()
A = III()

xor = 0
for i in range(N):
    xor ^= A[i]

for i in range(N):
    A[i] &= ~xor

max_digit = len(format(max(A), 'b'))
rank = 0
for col in range(max_digit)[::-1]:
    pivot = -1
    for row in range(rank,N):
        if A[row]>>col & 1:
            pivot = row
            break
    if pivot == -1: 
        continue
    A[pivot],A[rank] = A[rank],A[pivot]
    for row in range(rank+1,N):
        if A[row]>>col & 1:
            A[row] ^= A[rank]
    rank += 1

val = 0
for i in range(N):
    val = max(val,val^A[i])

print(2*val + xor)
### BUGGY CODE ###

X = int(input())
c = 0
for i in range(int(X/100)+1):
    for j in range(int(X/101)+1):
        for k in range(int(X/102) +1):
            for l in range(int(X/103) +1):
                for m in range(int(X/104)+1):
                    for n in range(int(X/105)+1):
                        if 100*i + 101*j + 102*k + 103*l + 104*m + 105*n == X:
                            c = 1
                            
print(c)

### FIXED CODE ###

X= int(input())
val = X // 100
diff = X % 100
if diff <= 5*val:
    print(1)
else:
    print(0)
### BUGGY CODE ###

from collections import defaultdict

N, W = map(int, input().split())

dp = defaultdict(int)
dp[0] = 0
idx2check = {0}
for _ in range(N):
    w, v = map(int, input().split())
    new_idx2check = set()
    for k in idx2check:
        dp[k + w] = max(dp[k + w], dp[k] + v)
        new_idx2check.add(k+w)

    idx2check |= new_idx2check

ans = 0
for k, v in dp.items():
    if k <= W:
        ans = max(ans, v)

print(ans)


### FIXED CODE ###

from collections import defaultdict

N, W = map(int, input().split())

dp = defaultdict(lambda: 1e9)
dp[0] = 0
ans = 0
for _ in range(N):
    w, v = map(int, input().split())
    keys = sorted(dp.keys(), reverse=True)
    for k in keys:
        dp[k + v] = min(dp[k + v], dp[k] + w)
        if dp[k + v] <= W:
            ans = max(ans, k + v)


print(ans)
### BUGGY CODE ###


N,W = map(int, input().split())

w = [0 for i in range(N+1)]
v = [0 for i in range(N+1)]

for i in range(N):
    w[i+1],v[i+1] = map(int, input().split())

#i番目の品物まで含み制約W2のナップサック問題の最適解
def nap(i,W2):
    #品物0個のときはもちろん価値は0
    if i == 0:
        return 0
    #w[i]がW2を超えるときはi番目の品物は不必要
    if W2 < w[i]:
        return nap(i-1,W2)
    W3 = 0
    for j in range(i):
        W3 = W3 + w[j+1]
    if W3 < W2:
        V3 = 0
        for j in range(i):
            V3 = V3 + v[j+1]
        return V3
    #品物１つで制約OK→品物一つの価値がnapの価値        
    if i == 1:
        return v[i]

    return max( nap(i-1,W2-w[i])+v[i] , nap(i-1,W2) )
    
            
print(nap(N,W))


### FIXED CODE ###


N,W = map(int, input().split())

w = [0 for i in range(N)]
v = [0 for i in range(N)]
Wsum = [0 for i in range(N+1)]
Vsum = [0 for i in range(N+1)]

for i in range(N):
    w[i],v[i] = map(int, input().split())
Wmin = min(w)

w.insert(0,"0")
v.insert(0,"0")


for i in range(N):
    Wsum[i+1] = Wsum[i] + w[i+1]
    Vsum[i+1] = Vsum[i] + v[i+1]


nap_memo = {}

#i番目の品物まで含み制約W2のナップサック問題の最適解
def nap(i,W2):
    #重複計算を避けるためnap(i,W2)を保持
    key = str(i) + ':' + str(W2)
    if key in nap_memo:
        return nap_memo[key]
    #品物0個のときは価値は0
    elif i == 0:
        r = 0
    #制約0のときも価値は0
    elif W2 < Wmin:
        r = 0
    #w[i]がW2を超えるときはi番目の品物は不必要
    elif W2 < w[i]:
        r = nap(i-1,W2)
    #品物の重さ全部足して制約以下なら全部足したものが価値で良い
    elif Wsum[i] <= W2:
        r = Vsum[i]
    #i番目の品物をナップサックに入れるか入れないか
    else:
        r = max( nap(i-1,W2-w[i])+v[i] , nap(i-1,W2) )
    
    nap_memo[key] = r
    return r
    
            
print(nap(N,W))
### BUGGY CODE ###

def main(N,h,K):
    inf = 2**31 - 1
    dp = [inf] * N
    dp[0] = 0
    for i in range(N-1):
        for k in range(1, K+1):
            if i+k < N:
                dp[i+k] = min(dp[i+k], dp[i] + abs(h[i] - h[i+k]))
    return dp[N-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))

print(main(N,h,K))

### FIXED CODE ###

def main2(N,h,K):
    dp = [0] * N
    for i in range(1,N):
        dp[i] = min([dp[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
    return dp[-1]

N, K = map(int, input().split())
h = list(map(int, input().split()))
print(main2(N,h,K))
### BUGGY CODE ###

from collections import defaultdict, Counter, namedtuple, deque
from bisect import bisect_left
from functools import reduce
import math

NN = 2020202
MOD = 10**9+7
INF = float("inf")


class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = []
        for i in range(self.n+1):
            self.bit.append(defaultdict(int))
        self.s = ["*"]*self.n

    def _sum(self, i):
        s = defaultdict(int)
        while i > 0:
            for k, v in self.bit[i].items():
                s[k] += v
            i -= i & -i
        return s

    def add(self, i, val):
        old = self.s[i-1]
        self.s[i - 1] = val
        # print(old, val)
        if old == val:
            return

        while i <= self.n:
            # print(i)
            self.bit[i][val] += 1
            self.bit[i][old] -= 1
            if self.bit[i][old] <= 0:
                del self.bit[i][old]

            i += i & -i

    def get_sum(self, l, r):
        A = self._sum(r)
        B = self._sum(l-1)
        # print(A, B)
        for k,v in B.items():
            A[k] -= v
            if A[k] <= 0:
                del A[k]

        return len(A)
        # return self._sum(r) - self._sum(l)


N = int(input())
S = input()
Q = int(input())
query = [list(input().split()) for i in range(Q)]

tree = BIT(N)
for i in range(N):
    tree.add(i+1, S[i])
# print(tree.bit)

for i in range(Q):
    if query[i][0] == "1":
        tree.add(int(query[i][1]), query[i][2])
        # print(tree.bit)
    if query[i][0] == "2":
        print(tree.get_sum(int(query[i][1]), int(query[i][2])))


### FIXED CODE ###

NN = 2020202
MOD = 10**9+7
INF = float("inf")


class BIT():
    def __init__(self, n):
        self.n = n
        self.bit = [[0]*26 for _ in range(self.n+1)]
        self.s = ["*"]*self.n

    def _sum(self, i):
        s = [0]*26
        while i > 0:
            for idx, v in enumerate(self.bit[i]):
                s[idx] += v
            i -= i & -i
        return s

    def add(self, i, val):
        """i番目にvalを加える"""
        old = self.s[i-1]
        self.s[i - 1] = val
        # print(old, val)
        if old == val:
            return

        while i <= self.n:
            # print(i)
            self.bit[i][ord(val) - ord("a")] += 1
            if 0 <= ord(old) - ord("a") < 26:
                self.bit[i][ord(old) - ord("a")] -= 1

            i += i & -i

    def get_sum(self, l, r):
        """区間[l, r)の和を求める"""
        A = self._sum(r)
        B = self._sum(l-1)
        # print(A, B)
        ans = 0
        for idx in range(26):
            if A[idx] > B[idx]:
                ans += 1

        return ans
        # return self._sum(r) - self._sum(l)


N = int(input())
S = input()
Q = int(input())
query = [list(input().split()) for i in range(Q)]

tree = BIT(N)
for i in range(N):
    tree.add(i+1, S[i])
# print(tree.bit)

for i in range(Q):
    if query[i][0] == "1":
        tree.add(int(query[i][1]), query[i][2])
        # print(tree.bit)
    if query[i][0] == "2":
        print(tree.get_sum(int(query[i][1]), int(query[i][2])))
### BUGGY CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[22]:


import collections
import math


# In[31]:


N = int(input())
A = list(map(int, input().split()))


# In[32]:


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


# In[33]:


for i in range(N):
    mylist = list(collections.Counter(A[:i] + A[i+1:]).items())
    ans = 0
    for x,cnt in mylist:
        if cnt > 1:
            ans += combinations_count(cnt, 2)
    print(ans)


# In[ ]:






### FIXED CODE ###

#!/usr/bin/env python
# coding: utf-8

# In[35]:


import collections


# In[31]:


N = int(input())
A = list(map(int, input().split()))


# In[36]:


count = collections.Counter(A)
numsum = 0
for i in count.values():
    numsum += i*(i-1)//2

for i in A:
    print(numsum - (count[i]-1))


# In[ ]:
### BUGGY CODE ###

# -*- coding: utf-8 -*-
# 整数の入力
import sys
n = int(input())
li = list(map(int, input().split()))

count = 0

for i in range(len(li)) :
  sum = 0
  for j in range(len(li)) :
    sum = sum + li[i+j]
    if sum == 0:
      count = count + 1
    if i + j >= len(li) - 1:
      break

print(count)


### FIXED CODE ###

def tri(n):
  return n * (n+1) // 2

N = int(input())
A = list(map(int, input().split()))

SA = [0] * (N+1)
for i in range(N):
  SA[i+1] = SA[i] + A[i]
  
SA.sort()

ans = 0
cnt = 0

for i in range(N+1):
  if i == 0:
    now = SA[i]
    continue
  
  if now == SA[i]:
    cnt += 1
    continue
  elif cnt > 0:
    ans += tri(cnt)
    cnt = 0
  else:
    pass
  now = SA[i]

if cnt > 0:
    ans += tri(cnt)
    
print(ans)
### BUGGY CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

bimi = []
cnt = -100000000

def roop():
        global cnt
        for a in range(X):
                for b in range(Y):
                        for c in range(Z):
                                bimi.append(A[a] + B[b] + C[c])
                                cnt += 1

                                if cnt == K:
                                        return

roop()
bimi.sort(reverse=True)

for x in range(K):
        print(bimi[x])



### FIXED CODE ###

# coding: utf-8

import sys
input = sys.stdin.readline

X, Y, Z, K = map(int, input().split())
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

bimi = []

for a in range(X):
        for b in range(Y):
                if (a + 1) * (b + 1) > K:
                                break

                for c in range(Z):
                        if (a + 1) * (b + 1) * (c + 1) > K:
                                break

                        bimi.append(A[a] + B[b] + C[c])

bimi.sort(reverse=True)

for i in range(K):
        print(bimi[i])
### BUGGY CODE ###

n = int(input())
a = [0] + [int(input()) for _ in range(n)]
i = 1
c = 0
while True:
  if i == 2:
    print(c)
    quit(0)
  if a[i] == i:
    print(-1)
    quit(0)
  c += 1
  tmp = i
  i = a[tmp]
  a[tmp] = i

### FIXED CODE ###

n = int(input())
a = [0] + [int(input()) for _ in range(n)]
i = 1
c = 0
while True:
  if i == 2:
    print(c)
    quit(0)
  if a[i] == i:
    print(-1)
    quit(0)
  c += 1
  tmp = a[i]
  a[i] = i
  i = tmp
### BUGGY CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))

ans_i = 0
ans_max = 0
ans = 0

for i in range(0, n-k+1):
    x = sum(p[i:i+k])
    if x > ans_max:
        ans_max = x
        ans_i = i
        
for j in range(ans_i, ans_i+k):
    ans += (p[j]+1)/2
print(ans)

### FIXED CODE ###

n, k = map(int, input().split())
p = list(map(int, input().split()))

x = sum(p[0:k])
ans_i = 0
ans_max = x
ans = 0

for i in range(1, n-k+1):
    x = x - p[i-1] + p[i+k-1]
    if x > ans_max:
        ans_max = x
        ans_i = i
        
for j in range(ans_i, ans_i+k):
    ans += (p[j]+1)/2
print(ans)
### BUGGY CODE ###

s = ' ' + input()
t = ' ' + input()

dp = [0] * len(t)
lcs = [''] * len(t)
for i in range(1, len(s)) :
    dp_ = [0] * len(t)
    lcs_ = [''] * len(t)
    
    for j in range(1, len(t)) :            
        if s[i] == t[j] :
            dp_[j] = dp[j-1] + 1
            lcs_[j] = lcs[j-1] + s[i]
        else :
            if dp[j] >= dp_[j-1] :
                dp_[j] = dp[j]
                lcs_[j] = lcs[j]
            else :
                dp_[j] = dp_[j-1]
                lcs_[j] = lcs_[j-1]
    dp = dp_
    lcs = lcs_

print(lcs[-1])

### FIXED CODE ###

s = 'S' + input()
t = 'T' + input()

dp = [[0] * len(t) for _ in range(len(s))]
for i in range(len(s)) :
    for j in range(len(t)) :
        if i == 0 or j == 0 :
            continue
            
        if s[i] == t[j] :
            dp[i][j] = dp[i-1][j-1] + 1
        else :
            dp[i][j] = max(dp[i-1][j], dp[i][j-1])
ret = ''
i, j = len(s)-1, len(t)-1
while i >= 1 and j >= 1 :
    if dp[i][j] == dp[i-1][j] :
        i -= 1
    elif dp[i][j] == dp[i][j-1] :
        j -= 1
    else :
        ret += s[i]
        i -= 1
        j -= 1
        
print(ret[::-1])
### BUGGY CODE ###

N, M = map(int, input().split())


L_list = []
R_list = []

for i in range(M):
    A, B = map(int, input().split())
    L_list.append(A)
    R_list.append(B)

counter = 0
for j in range(min(L_list),(max(R_list) + 1)):
    if j >= max(L_list) and j <= min(R_list):
        counter += 1

print(counter)

### FIXED CODE ###

N, M = map(int, input().split())

L_list = []
R_list = []

for i in range(M):
    A, B = map(int, input().split())
    L_list.append(A)
    R_list.append(B)

if max(L_list) > min(R_list):
    print(0)
else:
    print(min(R_list) - max(L_list) + 1)
### BUGGY CODE ###

def divisor(n):  # nの約数を全て求める
    i = 1
    table = set()
    while i * i <= n:
        if n % i == 0:
            table.add(i)
            table.add(n // i)
        i += 1
    
    return len(table)
n = int(input().strip())

ans=0
for i in range(1,n+1):
    ans+=i*divisor(i)
print(ans)

### FIXED CODE ###

n = int(input().strip())

ans=0
for divisor in range(1,n+1):
    ans+=divisor*(n//divisor*(n//divisor+1)//2)

print(ans)
### BUGGY CODE ###

import collections
mod = 10**9+7
n=int(input())
kaijou = []
kaijou.append(1)
for i in range(1,n+3):
    kaijou.append(kaijou[i-1]*i)


def conb(p,r):
    return kaijou[p]//(kaijou[r]*kaijou[p-r])

def tyoufuku(i,a,b):
    global n
    ret = 0
    if i == 1:
        return 1
    else:
        for j in range(i):
            if a < j or n-b <i-j-1:
                continue
            else:
                ret += conb(a,j)*conb(n-b,i-j-1)
        return ret


def main():
    global n
    a=list(map(int,input().split()))

    ca= collections.Counter(a)
    tyo= ca.most_common()[0][0]

    kaburi=[i for i, x in enumerate(a) if x == tyo]

    for i in range(1,n+2):
        print((conb(n+1,i)-tyoufuku(i,kaburi[0],kaburi[1]))%mod)

main()

### FIXED CODE ###

import collections
mod = 10**9+7
fac = [1]
caf = [1]
n=int(input())

def pow(n,p):
    res=1
    while p >0:
        if p%2==0:
            n = n**2 % mod
            p //= 2
        else:
            res = res * n % mod
            p -= 1
    return res % mod

for i in range(1,n+2):
    fac.append((fac[i-1]*i)%mod)
    caf.append(pow(fac[i],mod-2)%mod)

def ncr(n,r):
    if n < r: return 0
    return fac[n]*caf[r]*caf[n-r]

def main():
    global n
    a=list(map(int,input().split()))

    ca= collections.Counter(a)
    tyo= ca.most_common()[0][0]
    kaburi=[i for i, x in enumerate(a) if x == tyo]

    for i in range(1,n+2):
        print((ncr(n+1,i)-ncr(n+1-(kaburi[1]-kaburi[0]+1),i-1))%mod)

main()
### BUGGY CODE ###

import sys
sys.setrecursionlimit(10**9)

n, a, b, k = map(int, input().split())

nmemo = [0 for i in range(n+1)]
def permutation(n):
    if nmemo[n] != 0:
        return nmemo[n]
    if n == 0:
        return 1
    nmemo[n] = n * permutation(n-1)
    return nmemo[n]


memo = []
ans = 0

for i in range(n + 1):
    knum = k - b * i
    if k < 0:
        break
    if knum % a == 0:
        if knum//a + i <= 2 * n:
            memo.append([knum // a, i])

for i in memo:
    nmin = min(i[0], i[1])
    jmin = 0
    if i[0] + i[1] > n:
        jmin = i[0] + i[1] - n
    for j in range(jmin, nmin+1):
        if (i[0] + i[1] - j) <= n:
            ans += permutation(n) // (permutation(i[0] - j) * permutation(i[1] - j)
                                      * permutation(j) * (permutation(n - (i[0] - j + i[1]))))

if k == 0:
    print(1)
else:
    print(ans % 998244353)

### FIXED CODE ###

n, a, b, k = map(int, input().split())

mod = 998244353

# combination---
# nとmodは適宜変える

fac = [1, 1]
inv = [1, 1]
finv = [1, 1]
for i in range(2, n+5):
    fac.append(fac[i-1] * i % mod)
    inv.append(mod - inv[mod%i] * (mod//i) % mod)
    finv.append(finv[i-1] * inv[i] % mod)

def nck(n, k):
    if n < k:
        return 0
    if n < 0 or k < 0:
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

ans = 0
for ca in range(n+1):
    cb = (k - a * ca) // b
    if (k - a * ca) % b != 0:
        continue
    ans += nck(n, ca) * nck(n, cb)
    ans %= mod

print(ans)
### BUGGY CODE ###

import sys
readline = sys.stdin.readline
from collections import deque
directions = ((-1, 0), (1, 0), (0, -1), (0, 1))


def main():
    H, W = map(int, readline().rstrip().split())
    mat = [list(readline().rstrip()) for _ in range(H)]

    start = []
    for h in range(H):
        for w in range(W):
            if mat[h][w] == '#':
                start.append((h, w))
    
    res = 0
    que = deque(start)
    while que:
        flg = False
        next_que = deque()
        while que:
            h, w = que.popleft()
            for dh, dw in directions:
                if not (0 <= h+dh < H and 0 <= w+dw < W):
                    continue
                if mat[h+dh][w+dw] == '#':
                    continue
                flg = True
                mat[h+dh][w+dw] = '#'
                next_que.append((h+dh, w+dw))

        if flg:
            res += 1
        que = next_que

    print(res)


if __name__ == '__main__':
    main()

### FIXED CODE ###

import sys
readline = sys.stdin.readline
from collections import deque
directions = ((-1, 0), (1, 0), (0, -1), (0, 1))


def main():
    H, W = map(int, readline().rstrip().split())
    mat = [list(readline().rstrip()) for _ in range(H)]

    start = []
    for h in range(H):
        for w in range(W):
            if mat[h][w] == '#':
                start.append((h, w))
    
    res = 0
    que = deque(start)
    while que:
        flg = False
        next_que = deque()
        while que:
            h, w = que.popleft()
            for dh, dw in directions:
                if not (0 <= h+dh < H and 0 <= w+dw < W):
                    continue
                if mat[h+dh][w+dw] == '#':
                    continue
                flg = True
                mat[h+dh][w+dw] = '#'
                next_que.append((h+dh, w+dw))

        if flg:
            res += 1
        que = next_que

    print(res)


if __name__ == '__main__':
    main()
### BUGGY CODE ###

N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        lis.append(i)
for i in range(Q):
    ans = 0
    for j in lis:
        if LR[i][0]-1 <= j and j+1 <= LR[i][1]-1:
            ans += 1
        if LR[i][1]-1<j+1:
            break
    print(ans)

### FIXED CODE ###

import sys
input = sys.stdin.readline
N,Q = map(int,input().split())
S = list(input())
LR = [list(map(int,input().split())) for _ in range(Q)]
lis = []
s = [0]*N
for i in range(N-1):
    if S[i] == "A" and S[i+1] == "C":
        s[i] = 1

L = [0]*(N+1)
R = [0]*N

tmp = 0
for ind,i in enumerate(s):
    if i == 1:
        tmp += 1
    L[ind+1] = tmp

tmp = 0
for i in range(N-2,-2,-1):
    if s[i] == 1:
        tmp += 1
    R[i+1] = tmp

R.append(0)
sums =sum(s)
for i in range(Q):
    ans = sums-L[LR[i][0]-1]-R[LR[i][1]]
    print(ans)
### BUGGY CODE ###

n=int(input())
ans=0
while n!=0:
    tmp=n%100
    x=tmp%10
    y=(tmp-x)//10

    if x<5 or (x==5 and y<5):
        ans+=x
    else:
        ans+=10-x
        n+=10-x

    n=n//10
print(ans)

### FIXED CODE ###

def f(i):
    while True:
        a[i]=(a[i]+1)%10
        if a[i]==0: i+=1
        else: break

s=input()
a=[]
for i in range(len(s)-1,-1,-1):
    a.append(int(s[i]))
a.append(0)

ans=0
for i in range(len(a)-1):
    if a[i]<5: ans+=a[i]
    elif a[i]==5:
        if a[i+1]<5: ans+=5
        else:
            ans+=5
            f(i+1)

    else:
        ans+=10-a[i]
        f(i+1)

if a[-1]!=0: ans+=1

print(ans)
### BUGGY CODE ###


n=int(input())
a=list(map(lambda x:int(x)-1,list(input())))
def slv(n,a):
    v=a[0]
    if all(v==x for x in a):return 0
    # 答えの偶奇を求める
    chk=0
    tmp=1
    tmpmod=1
    for i in range(n):
        x=a[i]%2
        chk+=a[i]*tmp
        chk%=2
        tmp*=n-1-i
        tmp//=i+1
    if chk:return 1
    if 1 in a:return 0
    a=[x//2 for x in a]
    return slv(n,a)*2

#n=pow(10,5)
#a=[i%3 for i in range(n)]
print(slv(n,a))

### FIXED CODE ###


n=int(input())
a=list(map(lambda x:int(x)-1,list(input())))
memo=[-1]*(n+1)
def log(x):
    if memo[x]!=-1:return memo[x]
    ret=0
    xx=x
    while x and x%2==0:
        x//=2
        ret+=1
    memo[xx]=ret
    return ret

def slv(n,a):
    v=a[0]
    if all(v==x for x in a):return 0
    # 答えの偶奇を求める
    chk=0
    tmppl=0
    tmpmi=0
    for i in range(n):
        x=a[i]%2
        if tmppl>tmpmi:
            pass
        else:
            chk+=a[i]
            chk%=2
        tmppl+=log(n-i-1)
        tmpmi+=log(i+1)
    if chk:return 1
    if 1 in a:return 0
    a=[x//2 for x in a]
    return slv(n,a)*2
print(slv(n,a))
### BUGGY CODE ###

N = int(input())
P = list(map(int, input().split()))
cnt = 0
for n in range(N):
    if n == 0:
        cnt += 1
    else:
        L = P[:n]
        L = sorted(L)
        if P[n] <= min(L):
            cnt += 1
print(cnt)


### FIXED CODE ###

N = int(input())
P = list(map(int, input().split()))
cnt = 0
res = float('Inf')
for n in range(N):
    if P[n] < res:
        res = P[n]
        cnt += 1
print(cnt)